Merge branch 'develop' of https://github.com/vivo-project/VIVO into develop

This commit is contained in:
hudajkhan 2013-10-02 14:58:19 -04:00
commit 0896b37c3c
18 changed files with 2147 additions and 31 deletions

View file

@ -0,0 +1,100 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
import java.lang.String;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import com.hp.hpl.jena.rdf.model.Literal;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.N3ValidatorVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.MultiValueEditSubmission;
public class PublicationHasEditorValidator implements N3ValidatorVTwo {
private static String MISSING_FIRST_NAME_ERROR = "Must specify the editor's first name.";
private static String MISSING_LAST_NAME_ERROR = "Must specify the editor's last name.";
private static String MALFORMED_LAST_NAME_ERROR = "Last name may not contain a comma. Please enter first name in first name field.";
;
@Override
public Map<String, String> validate(EditConfigurationVTwo editConfig,
MultiValueEditSubmission editSub) {
Map<String,List<String>> urisFromForm = editSub.getUrisFromForm();
Map<String,List<Literal>> literalsFromForm = editSub.getLiteralsFromForm();
Map<String,String> errors = new HashMap<String,String>();
List<String> personUri = urisFromForm.get("personUri");
if (allListElementsEmpty(personUri)) {
personUri = null;
}
// If there's a personUri, then we're done. The firstName and lastName fields are
// disabled and so don't get submitted.
if (personUri != null ) {
return null;
}
//Expecting only one first name in this case
//To Do: update logic if multiple first names considered
Literal firstName = null;
List<Literal> firstNameList = literalsFromForm.get("firstName");
if(firstNameList != null && firstNameList.size() > 0) {
firstName = firstNameList.get(0);
}
if( firstName != null &&
firstName.getLexicalForm() != null &&
"".equals(firstName.getLexicalForm()) )
firstName = null;
List<Literal> lastNameList = literalsFromForm.get("lastName");
Literal lastName = null;
if(lastNameList != null && lastNameList.size() > 0) {
lastName = lastNameList.get(0);
}
String lastNameValue = "";
if (lastName != null) {
lastNameValue = lastName.getLexicalForm();
if( "".equals(lastNameValue) ) {
lastName = null;
}
}
if (lastName == null) {
errors.put("lastName", MISSING_LAST_NAME_ERROR);
// Don't reject space in the last name: de Vries, etc.
} else if (lastNameValue.contains(",")) {
errors.put("lastName", MALFORMED_LAST_NAME_ERROR);
}
if (firstName == null) {
errors.put("firstName", MISSING_FIRST_NAME_ERROR);
}
return errors.size() != 0 ? errors : null;
}
private boolean allListElementsEmpty(List<String> checkList) {
if(checkList == null)
return true;
if(checkList.isEmpty()) {
return true;
}
boolean allEmpty = true;
for(String s: checkList) {
if(s.length() != 0){
allEmpty = false;
break;
}
}
return allEmpty;
}
}

View file

@ -0,0 +1,464 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.vocabulary.RDFS;
import com.hp.hpl.jena.vocabulary.XSD;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyComparator;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.PublicationHasEditorValidator;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeIntervalValidationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
/**
* This is a slightly unusual generator that is used by Manage Editors on
* information resources.
*
* It is intended to always be an add, and never an update.
*/
public class AddEditorsToInformationResourceGenerator extends VivoBaseGenerator implements EditConfigurationGenerator {
public static Log log = LogFactory.getLog(AddEditorsToInformationResourceGenerator.class);
@Override
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
HttpSession session) {
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
initBasics(editConfiguration, vreq);
initPropertyParameters(vreq, session, editConfiguration);
//Overriding URL to return to
setUrlToReturnTo(editConfiguration, vreq);
//set variable names
editConfiguration.setVarNameForSubject("infoResource");
editConfiguration.setVarNameForPredicate("predicate");
editConfiguration.setVarNameForObject("editorshipUri");
// Required N3
editConfiguration.setN3Required( list( getN3NewEditorship() ) );
// Optional N3
editConfiguration.setN3Optional( generateN3Optional());
editConfiguration.addNewResource("editorshipUri", DEFAULT_NS_TOKEN);
editConfiguration.addNewResource("newPerson", DEFAULT_NS_TOKEN);
editConfiguration.addNewResource("vcardPerson", DEFAULT_NS_TOKEN);
editConfiguration.addNewResource("vcardName", DEFAULT_NS_TOKEN);
//In scope
setUrisAndLiteralsInScope(editConfiguration, vreq);
//on Form
setUrisAndLiteralsOnForm(editConfiguration, vreq);
//Sparql queries
setSparqlQueries(editConfiguration, vreq);
//set fields
setFields(editConfiguration, vreq, EditConfigurationUtils.getPredicateUri(vreq));
//template file
editConfiguration.setTemplate("addEditorsToInformationResource.ftl");
//add validators
editConfiguration.addValidator(new PublicationHasEditorValidator());
//Adding additional data, specifically edit mode
addFormSpecificData(editConfiguration, vreq);
editConfiguration.addValidator(new AntiXssValidation());
//NOITCE this generator does not run prepare() since it
//is never an update and has no SPARQL for existing
return editConfiguration;
}
private void setUrlToReturnTo(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
editConfiguration.setUrlPatternToReturnTo(EditConfigurationUtils.getFormUrlWithoutContext(vreq));
}
/***N3 strings both required and optional***/
public String getN3PrefixString() {
return "@prefix core: <" + vivoCore + "> .\n" +
"@prefix foaf: <" + foaf + "> . \n" ;
}
private String getN3NewEditorship() {
return getN3PrefixString() +
"?editorshipUri a core:Editorship ;\n" +
" core:relates ?infoResource .\n" +
"?infoResource core:relatedBy ?editorshipUri .";
}
private String getN3EditorshipRank() {
return getN3PrefixString() +
"?editorshipUri core:editorRank ?rank .";
}
//first name, middle name, last name, and new perseon for new editor being created, and n3 for existing person
//if existing person selected as editor
public List<String> generateN3Optional() {
return list(
getN3NewPersonFirstName() ,
getN3NewPersonMiddleName(),
getN3NewPersonLastName(),
getN3NewPerson(),
getN3EditorshipRank(),
getN3ForExistingPerson());
}
private String getN3NewPersonFirstName() {
return getN3PrefixString() +
"@prefix vcard: <http://www.w3.org/2006/vcard/ns#> . \n" +
"?newPerson <http://purl.obolibrary.org/obo/ARG_2000028> ?vcardPerson . \n" +
"?vcardPerson <http://purl.obolibrary.org/obo/ARG_2000029> ?newPerson . \n" +
"?vcardPerson a <http://www.w3.org/2006/vcard/ns#Individual> . \n" +
"?vcardPerson vcard:hasName ?vcardName . \n" +
"?vcardName a <http://www.w3.org/2006/vcard/ns#Name> . \n" +
"?vcardName vcard:givenName ?firstName .";
}
private String getN3NewPersonMiddleName() {
return getN3PrefixString() +
"@prefix vcard: <http://www.w3.org/2006/vcard/ns#> . \n" +
"?newPerson <http://purl.obolibrary.org/obo/ARG_2000028> ?vcardPerson . \n" +
"?vcardPerson <http://purl.obolibrary.org/obo/ARG_2000029> ?newPerson . \n" +
"?vcardPerson a <http://www.w3.org/2006/vcard/ns#Individual> . \n" +
"?vcardPerson vcard:hasName ?vcardName . \n" +
"?vcardName a <http://www.w3.org/2006/vcard/ns#Name> . \n" +
"?vcardName vcard:middleName ?middleName .";
}
private String getN3NewPersonLastName() {
return getN3PrefixString() +
"@prefix vcard: <http://www.w3.org/2006/vcard/ns#> . \n" +
"?newPerson <http://purl.obolibrary.org/obo/ARG_2000028> ?vcardPerson . \n" +
"?vcardPerson <http://purl.obolibrary.org/obo/ARG_2000029> ?newPerson . \n" +
"?vcardPerson a <http://www.w3.org/2006/vcard/ns#Individual> . \n" +
"?vcardPerson vcard:hasName ?vcardName . \n" +
"?vcardName a <http://www.w3.org/2006/vcard/ns#Name> . \n" +
"?vcardName vcard:familyName ?lastName .";
}
private String getN3NewPerson() {
return getN3PrefixString() +
"?newPerson a foaf:Person ;\n" +
"<" + RDFS.label.getURI() + "> ?label .\n" +
"?editorshipUri core:relates ?newPerson .\n" +
"?newPerson core:relatedBy ?editorshipUri . ";
}
private String getN3ForExistingPerson() {
return getN3PrefixString() +
"?editorshipUri core:relates ?personUri .\n" +
"?personUri core:relatedBy ?editorshipUri .";
}
/** Get new resources */
//A new editorship uri will always be created when an editor is added
//A new person may be added if a person not in the system will be added as editor
private Map<String, String> generateNewResources(VitroRequest vreq) {
HashMap<String, String> newResources = new HashMap<String, String>();
newResources.put("editorshipUri", DEFAULT_NS_TOKEN);
newResources.put("newPerson", DEFAULT_NS_TOKEN);
newResources.put("vcardPerson", DEFAULT_NS_TOKEN);
newResources.put("vcardName", DEFAULT_NS_TOKEN);
return newResources;
}
/** Set URIS and Literals In Scope and on form and supporting methods */
private void setUrisAndLiteralsInScope(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
//Uris in scope always contain subject and predicate
HashMap<String, List<String>> urisInScope = new HashMap<String, List<String>>();
urisInScope.put(editConfiguration.getVarNameForSubject(),
Arrays.asList(new String[]{editConfiguration.getSubjectUri()}));
urisInScope.put(editConfiguration.getVarNameForPredicate(),
Arrays.asList(new String[]{editConfiguration.getPredicateUri()}));
editConfiguration.setUrisInScope(urisInScope);
//no literals in scope
}
public void setUrisAndLiteralsOnForm(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
List<String> urisOnForm = new ArrayList<String>();
//If an existing person is being used as an editor, need to get the person uri
urisOnForm.add("personUri");
editConfiguration.setUrisOnform(urisOnForm);
//for person who is not in system, need to add first name, last name and middle name
//Also need to store editorship rank and label of editor
List<String> literalsOnForm = list("firstName",
"middleName",
"lastName",
"rank",
"label");
editConfiguration.setLiteralsOnForm(literalsOnForm);
}
/** Set SPARQL Queries and supporting methods. */
private void setSparqlQueries(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
//Sparql queries are all empty for existing values
//This form is different from the others that it gets multiple editors on the same page
//and that information will be queried and stored in the additional form specific data
HashMap<String, String> map = new HashMap<String, String>();
editConfiguration.setSparqlForExistingUris(new HashMap<String, String>());
editConfiguration.setSparqlForExistingLiterals(new HashMap<String, String>());
editConfiguration.setSparqlForAdditionalUrisInScope(new HashMap<String, String>());
editConfiguration.setSparqlForAdditionalLiteralsInScope(new HashMap<String, String>());
}
/**
*
* Set Fields and supporting methods
*/
public void setFields(EditConfigurationVTwo editConfiguration, VitroRequest vreq, String predicateUri) {
setLabelField(editConfiguration);
setFirstNameField(editConfiguration);
setMiddleNameField(editConfiguration);
setLastNameField(editConfiguration);
setRankField(editConfiguration);
setPersonUriField(editConfiguration);
}
private void setLabelField(EditConfigurationVTwo editConfiguration) {
editConfiguration.addField(new FieldVTwo().
setName("label").
setValidators(list("datatype:" + XSD.xstring.toString())).
setRangeDatatypeUri(XSD.xstring.toString())
);
}
private void setFirstNameField(EditConfigurationVTwo editConfiguration) {
editConfiguration.addField(new FieldVTwo().
setName("firstName").
setValidators(list("datatype:" + XSD.xstring.toString())).
setRangeDatatypeUri(XSD.xstring.toString())
);
}
private void setMiddleNameField(EditConfigurationVTwo editConfiguration) {
editConfiguration.addField(new FieldVTwo().
setName("middleName").
setValidators(list("datatype:" + XSD.xstring.toString())).
setRangeDatatypeUri(XSD.xstring.toString())
);
}
private void setLastNameField(EditConfigurationVTwo editConfiguration) {
editConfiguration.addField(new FieldVTwo().
setName("lastName").
setValidators(list("datatype:" + XSD.xstring.toString())).
setRangeDatatypeUri(XSD.xstring.toString())
);
}
private void setRankField(EditConfigurationVTwo editConfiguration) {
editConfiguration.addField(new FieldVTwo().
setName("rank").
setValidators(list("nonempty")).
setRangeDatatypeUri(XSD.xint.toString())
);
}
private void setPersonUriField(EditConfigurationVTwo editConfiguration) {
editConfiguration.addField(new FieldVTwo().
setName("personUri")
//.setObjectClassUri(personClass)
);
}
//Form specific data
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
//Get the existing editorships
formSpecificData.put("existingEditorInfo", getExistingEditorships(editConfiguration.getSubjectUri(), vreq));
formSpecificData.put("newRank", getMaxRank(editConfiguration.getSubjectUri(), vreq) + 1);
formSpecificData.put("rankPredicate", "http://vivoweb.org/ontology/core#rank");
editConfiguration.setFormSpecificData(formSpecificData);
}
private static String EDITORSHIPS_QUERY = ""
+ "PREFIX core: <http://vivoweb.org/ontology/core#> \n"
+ "PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#> \n"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
+ "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n"
+ "SELECT ?editorshipURI (afn:localname(?editorshipURI) AS ?editorshipName) ?editorURI ?editorName ?rank \n"
+ "WHERE { \n"
+ "?subject core:relatedBy ?editorshipURI . \n"
+ "?editorshipURI a core:Editorship . \n"
+ "?editorshipURI core:relates ?editorURI . \n"
+ "?editorURI a foaf:Person . \n"
+ "OPTIONAL { ?editorURI rdfs:label ?editorName } \n"
+ "OPTIONAL { ?editorshipURI core:rank ?rank } \n"
+ "} ORDER BY ?rank";
private List<EditorshipInfo> getExistingEditorships(String subjectUri, VitroRequest vreq) {
String queryStr = QueryUtils.subUriForQueryVar(this.getEditorshipsQuery(), "subject", subjectUri);
log.debug("Query string is: " + queryStr);
List<Map<String, String>> editorships = new ArrayList<Map<String, String>>();
try {
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
while (results.hasNext()) {
QuerySolution soln = results.nextSolution();
RDFNode node = soln.get("editorshipURI");
if (node.isURIResource()) {
editorships.add(QueryUtils.querySolutionToStringValueMap(soln));
}
}
} catch (Exception e) {
log.error(e, e);
}
log.debug("editorships = " + editorships);
return getEditorshipInfo(editorships);
}
private static String MAX_RANK_QUERY = ""
+ "PREFIX core: <http://vivoweb.org/ontology/core#> \n"
+ "SELECT DISTINCT ?rank WHERE { \n"
+ " ?subject core:relatedBy ?editorship . \n"
+ " ?editorship a core:Editorship . \n"
+ " ?editorship core:rank ?rank .\n"
+ "} ORDER BY DESC(?rank) LIMIT 1";
private int getMaxRank(String subjectUri, VitroRequest vreq) {
int maxRank = 0; // default value
String queryStr = QueryUtils.subUriForQueryVar(this.getMaxRankQueryStr(), "subject", subjectUri);
log.debug("maxRank query string is: " + queryStr);
try {
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
if (results != null && results.hasNext()) { // there is at most one result
QuerySolution soln = results.next();
RDFNode node = soln.get("rank");
if (node != null && node.isLiteral()) {
// node.asLiteral().getInt() won't return an xsd:string that
// can be parsed as an int.
int rank = Integer.parseInt(node.asLiteral().getLexicalForm());
if (rank > maxRank) {
log.debug("setting maxRank to " + rank);
maxRank = rank;
}
}
}
} catch (NumberFormatException e) {
log.error("Invalid rank returned from query: not an integer value.");
} catch (Exception e) {
log.error(e, e);
}
log.debug("maxRank is: " + maxRank);
return maxRank;
}
private List<EditorshipInfo> getEditorshipInfo(
List<Map<String, String>> editorships) {
List<EditorshipInfo> info = new ArrayList<EditorshipInfo>();
String editorshipUri = "";
String editorshipName = "";
String editorUri = "";
String editorName = "";
for ( Map<String, String> editorship : editorships ) {
for (Entry<String, String> entry : editorship.entrySet() ) {
if ( entry.getKey().equals("editorshipURI") ) {
editorshipUri = entry.getValue();
}
else if ( entry.getKey().equals("editorshipName") ) {
editorshipName = entry.getValue();
}
else if ( entry.getKey().equals("editorURI") ) {
editorUri = entry.getValue();
}
else if ( entry.getKey().equals("editorName") ) {
editorName = entry.getValue();
}
}
EditorshipInfo aaInfo = new EditorshipInfo(editorshipUri, editorshipName, editorUri, editorName);
info.add(aaInfo);
}
log.debug("info = " + info);
return info;
}
//This is the information about editors the form will require
public class EditorshipInfo {
//This is the editorship node information
private String editorshipUri;
private String editorshipName;
//Editor information for editorship node
private String editorUri;
private String editorName;
public EditorshipInfo(String inputEditorshipUri,
String inputEditorshipName,
String inputEditorUri,
String inputEditorName) {
editorshipUri = inputEditorshipUri;
editorshipName = inputEditorshipName;
editorUri = inputEditorUri;
editorName = inputEditorName;
}
//Getters - specifically required for Freemarker template's access to POJO
public String getEditorshipUri() {
return editorshipUri;
}
public String getEditorshipName() {
return editorshipName;
}
public String getEditorUri() {
return editorUri;
}
public String getEditorName() {
return editorName;
}
}
static final String DEFAULT_NS_TOKEN=null; //null forces the default NS
protected String getMaxRankQueryStr() {
return MAX_RANK_QUERY;
}
protected String getEditorshipsQuery() {
return EDITORSHIPS_QUERY;
}
}

View file

@ -0,0 +1,167 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpSession;
import com.hp.hpl.jena.vocabulary.XSD;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.PersonHasAdviseesValidator;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeIntervalValidationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeWithPrecisionVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.ChildVClassesWithParent;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.ConstantFieldOptions;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.IndividualsViaVClassOptions;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode;
import edu.cornell.mannlib.vitro.webapp.utils.generators.EditModeUtils;
public class AddEditorshipToPersonGenerator extends VivoBaseGenerator implements
EditConfigurationGenerator {
public AddEditorshipToPersonGenerator() {}
@Override
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
HttpSession session) throws Exception {
EditConfigurationVTwo conf = new EditConfigurationVTwo();
initBasics(conf, vreq);
initPropertyParameters(vreq, session, conf);
initObjectPropForm(conf, vreq);
conf.setTemplate("addEditorshipToPerson.ftl");
conf.setVarNameForSubject("person");
conf.setVarNameForPredicate("predicate");
conf.setVarNameForObject("editorship");
conf.setN3Required( Arrays.asList( n3ForNewEditorship ) );
conf.setN3Optional( Arrays.asList( n3ForNewDocumentAssertion,
n3ForExistingDocumentAssertion ) );
conf.addNewResource("editorship", DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("newDocument", DEFAULT_NS_FOR_NEW_RESOURCE);
conf.setUrisOnform(Arrays.asList("existingDocument", "documentType"));
conf.setLiteralsOnForm(Arrays.asList("documentLabel", "documentLabelDisplay" ));
conf.addSparqlForExistingLiteral("documentLabel", documentLabelQuery);
conf.addSparqlForExistingUris("documentType", documentTypeQuery);
conf.addSparqlForExistingUris("existingDocument", existingDocumentQuery);
conf.addField( new FieldVTwo().
setName("documentType").
setValidators( list("nonempty") ).
setOptions( new ConstantFieldOptions("documentType", getDocumentTypeLiteralOptions() ))
);
conf.addField( new FieldVTwo().
setName("documentLabel").
setRangeDatatypeUri(XSD.xstring.toString() ).
setValidators( list("datatype:" + XSD.xstring.toString()) )
);
conf.addValidator(new AntiXssValidation());
addFormSpecificData(conf, vreq);
prepare(vreq, conf);
return conf;
}
/* N3 assertions */
final static String n3ForNewEditorship =
"@prefix vivo: <" + vivoCore + "> . \n" +
"?person ?predicate ?editorship . \n" +
"?editorship a vivo:Editorship . \n" +
"?editorship vivo:relates ?person . " ;
final static String n3ForNewDocumentAssertion =
"@prefix vivo: <" + vivoCore + "> . \n" +
"?editorship vivo:relates ?newDocument . \n" +
"?newDocument vivo:editedBy ?editorship . \n" +
"?newDocument a ?documentType . \n" +
"?newDocument <" + label + "> ?documentLabel. " ;
final static String n3ForExistingDocumentAssertion =
"@prefix vivo: <" + vivoCore + "> . \n" +
"?editorship vivo:relates ?existingDocument . \n" +
"?existingDocument vivo:editedBy ?editorship . \n" +
"?existingDocument a ?documentType . " ;
/* Queries for editing an existing entry */
final static String documentTypeQuery =
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
"PREFIX vivo: <" + vivoCore + "> . \n" +
"PREFIX bibo: <http://purl.org/ontology/bibo/> . \n" +
"SELECT ?documentType WHERE { \n" +
" ?editorship vivo:relates ?existingDocument . \n" +
" ?existingDocument a bibo:Document . \n" +
" ?existingDocument vitro:mostSpecificType ?documentType . \n" +
"}";
final static String documentLabelQuery =
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
"PREFIX vivo: <" + vivoCore + "> . \n" +
"PREFIX bibo: <http://purl.org/ontology/bibo/> . \n" +
"SELECT ?documentLabel WHERE { \n" +
" ?editorship vivo:relates ?existingDocument . \n" +
" ?existingDocument a bibo:Document . \n" +
" ?existingDocument <" + label + "> ?documentLabel . \n" +
"}";
final static String existingDocumentQuery =
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
"PREFIX vivo: <" + vivoCore + "> . \n" +
"PREFIX bibo: <http://purl.org/ontology/bibo/> . \n" +
"SELECT existingDocument WHERE { \n" +
" ?editorship vivo:relates ?existingDocument . \n" +
" ?existingDocument a bibo:Document . \n" +
"}";
//Adding form specific data such as edit mode
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
formSpecificData.put("editMode", getEditMode(vreq).name().toLowerCase());
editConfiguration.setFormSpecificData(formSpecificData);
}
public EditMode getEditMode(VitroRequest vreq) {
List<String> predicates = new ArrayList<String>();
predicates.add("http://vivoweb.org/ontology/core#relates");
return EditModeUtils.getEditMode(vreq, predicates);
}
private List<List<String>> getDocumentTypeLiteralOptions() {
List<List<String>> literalOptions = new ArrayList<List<String>>();
literalOptions.add(list("http://purl.org/ontology/bibo/Book", "Book"));
literalOptions.add(list("http://purl.org/ontology/bibo/Chapter", "Chapter"));
literalOptions.add(list("http://purl.org/ontology/bibo/Collection", "Collection"));
literalOptions.add(list("http://purl.org/ontology/bibo/EditedBook", "Edited Book"));
literalOptions.add(list("http://purl.org/ontology/bibo/Film", "Film"));
literalOptions.add(list("http://purl.org/ontology/bibo/Magazine", "Magazine"));
literalOptions.add(list("http://vivoweb.org/ontology/core#Newsletter", "Newsletter"));
literalOptions.add(list("http://purl.org/ontology/bibo/Newspaper", "Newspaper"));
literalOptions.add(list("http://vivoweb.org/ontology/core#NewsRelease", "News Release"));
literalOptions.add(list("http://purl.org/ontology/bibo/Periodical", "Periodical"));
literalOptions.add(list("http://purl.org/ontology/bibo/Report", "Report"));
literalOptions.add(list("http://vivoweb.org/ontology/core#Video", "Video"));
literalOptions.add(list("http://purl.org/ontology/bibo/Webpage", "Webpage"));
literalOptions.add(list("http://purl.org/ontology/bibo/Website", "Website"));
return literalOptions;
}
}