VIVO-112: ISF changes relating to vcard classes
This commit is contained in:
parent
80ff85385e
commit
c5d0bc21e8
39 changed files with 1611 additions and 831 deletions
|
@ -11,6 +11,9 @@ import java.util.Map;
|
|||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||
import com.hp.hpl.jena.vocabulary.XSD;
|
||||
|
@ -33,6 +36,7 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.
|
|||
* It is intended to always be an add, and never an update.
|
||||
*/
|
||||
public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator implements EditConfigurationGenerator {
|
||||
public static Log log = LogFactory.getLog(AddAuthorsToInformationResourceGenerator.class);
|
||||
|
||||
@Override
|
||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
|
||||
|
@ -58,6 +62,8 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
|
|||
editConfiguration.addNewResource("authorshipUri", DEFAULT_NS_TOKEN);
|
||||
editConfiguration.addNewResource("newPerson", DEFAULT_NS_TOKEN);
|
||||
editConfiguration.addNewResource("newOrg", DEFAULT_NS_TOKEN);
|
||||
editConfiguration.addNewResource("vcardPerson", DEFAULT_NS_TOKEN);
|
||||
editConfiguration.addNewResource("vcardName", DEFAULT_NS_TOKEN);
|
||||
|
||||
//In scope
|
||||
setUrisAndLiteralsInScope(editConfiguration, vreq);
|
||||
|
@ -128,17 +134,35 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
|
|||
|
||||
private String getN3NewPersonFirstName() {
|
||||
return getN3PrefixString() +
|
||||
"?newPerson foaf:firstName ?firstName .";
|
||||
"@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() +
|
||||
"?newPerson core:middleName ?middleName .";
|
||||
"@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() +
|
||||
"?newPerson foaf:lastName ?lastName .";
|
||||
"@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() {
|
||||
|
@ -177,6 +201,8 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
|
|||
HashMap<String, String> newResources = new HashMap<String, String>();
|
||||
newResources.put("authorshipUri", DEFAULT_NS_TOKEN);
|
||||
newResources.put("newPerson", DEFAULT_NS_TOKEN);
|
||||
newResources.put("vcardPerson", DEFAULT_NS_TOKEN);
|
||||
newResources.put("vcardName", DEFAULT_NS_TOKEN);
|
||||
newResources.put("newOrg", DEFAULT_NS_TOKEN);
|
||||
return newResources;
|
||||
}
|
||||
|
@ -245,7 +271,6 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
|
|||
setValidators(list("datatype:" + XSD.xstring.toString())).
|
||||
setRangeDatatypeUri(XSD.xstring.toString())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -255,7 +280,6 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
|
|||
setValidators(list("datatype:" + XSD.xstring.toString())).
|
||||
setRangeDatatypeUri(XSD.xstring.toString())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -265,20 +289,14 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
|
|||
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) {
|
||||
|
@ -287,7 +305,6 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
|
|||
setValidators(list("nonempty")).
|
||||
setRangeDatatypeUri(XSD.xint.toString())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -296,7 +313,6 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
|
|||
setName("personUri")
|
||||
//.setObjectClassUri(personClass)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private void setOrgUriField(EditConfigurationVTwo editConfiguration) {
|
||||
|
@ -304,16 +320,16 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
|
|||
setName("orgUri")
|
||||
//.setObjectClassUri(personClass)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private void setOrgNameField(EditConfigurationVTwo editConfiguration) {
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
setName("orgName").
|
||||
setValidators(list("datatype:" + XSD.xstring.toString())).
|
||||
setRangeDatatypeUri(XSD.xstring.toString())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
//Form specific data
|
||||
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
|
||||
|
@ -329,11 +345,49 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
|
|||
List<Individual> authorships = infoResource.getRelatedIndividuals(
|
||||
EditConfigurationUtils.getPredicateUri(vreq));
|
||||
//TODO: Check if sorted correctly
|
||||
|
||||
log.debug("authorships = " + authorships);
|
||||
|
||||
sortAuthorshipIndividuals(authorships);
|
||||
|
||||
return getAuthorshipInfo(authorships);
|
||||
}
|
||||
|
||||
/*
|
||||
private static String AUTHORSHIPS_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 ?authorshipURI (afn:localname(?authorshipURI) AS ?authorshipName) ?authorURI ?authorName \n"
|
||||
+ "WHERE { \n"
|
||||
+ "?subject core:relatedBy ?authorshipURI . \n"
|
||||
+ "?authorshipURI core:relates ?authorURI . \n"
|
||||
+ "?authorURI a foaf:Person . \n"
|
||||
+ "?authorURI rdfs:label ?authorName \n"
|
||||
+ "}";
|
||||
|
||||
|
||||
private List<Map<String, String>> getExistingAuthorships(String subjectUri, VitroRequest vreq) {
|
||||
|
||||
String queryStr = QueryUtils.subUriForQueryVar(this.getAuthorshipsQuery(), "subject", subjectUri);
|
||||
log.debug("Query string is: " + queryStr);
|
||||
List<Map<String, String>> authorshipss = new ArrayList<Map<String, String>>();
|
||||
try {
|
||||
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
|
||||
while (results.hasNext()) {
|
||||
QuerySolution soln = results.nextSolution();
|
||||
RDFNode node = soln.get("link");
|
||||
if (node.isURIResource()) {
|
||||
webpages.add(QueryUtils.querySolutionToStringValueMap(soln));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e, e);
|
||||
}
|
||||
log.debug("webpages = " + webpages);
|
||||
return webpages;
|
||||
}
|
||||
*/
|
||||
private List<AuthorshipInfo> getAuthorshipInfo(
|
||||
List<Individual> authorships) {
|
||||
List<AuthorshipInfo> info = new ArrayList<AuthorshipInfo>();
|
||||
|
@ -368,9 +422,6 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
|
|||
return maxRank;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void sortAuthorshipIndividuals(List<Individual> authorships) {
|
||||
DataPropertyComparator comp = new DataPropertyComparator(authorRankPredicate);
|
||||
Collections.sort(authorships, comp);
|
||||
|
@ -416,4 +467,8 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
|
|||
|
||||
static final String DEFAULT_NS_TOKEN=null; //null forces the default NS
|
||||
|
||||
// protected String getAuthorshipsQuery() {
|
||||
// return AUTHORSHIPS_QUERY;
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ Class:
|
|||
core:URLLink - the link to be added to the individual
|
||||
|
||||
Data properties of core:URLLink:
|
||||
core:linkURI
|
||||
core:linkUrlPredicate
|
||||
core:linkAnchorText
|
||||
core:rank
|
||||
|
||||
|
@ -68,27 +68,32 @@ public class AddEditWebpageFormGenerator extends BaseEditConfigurationGenerator
|
|||
initBasics(config, vreq);
|
||||
initPropertyParameters(vreq, session, config);
|
||||
initObjectPropForm(config, vreq);
|
||||
String linkUri = getLinkUri(vreq);
|
||||
|
||||
config.setVarNameForSubject("subject");
|
||||
config.setVarNameForObject("link");
|
||||
config.setVarNameForObject("vcard");
|
||||
|
||||
config.addNewResource("vcard", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
config.addNewResource("link", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
|
||||
config.setN3Required(list( this.getN3ForWebpage(), N3_FOR_URLTYPE ));
|
||||
config.setN3Optional(list( N3_FOR_ANCHOR, N3_FOR_RANK));
|
||||
|
||||
config.addUrisInScope("webpageProperty", list( this.getWebpageProperty()));
|
||||
config.addUrisInScope("inverseProperty", list( this.getWebpageOfProperty()));
|
||||
config.addUrisInScope("linkClass", list( this.getURLLinkClass()));
|
||||
config.addUrisInScope("linkURI", list( core + "linkURI" ));
|
||||
config.addUrisInScope("linkAnchorPredicate", list( core + "linkAnchorText" ));
|
||||
config.addUrisInScope("webpageProperty", list( "http://purl.obolibrary.org/obo/ARG_2000028" ));
|
||||
config.addUrisInScope("inverseProperty", list( "http://purl.obolibrary.org/obo/ARG_2000029" ));
|
||||
config.addUrisInScope("linkUrlPredicate", list( "http://www.w3.org/2006/vcard/ns#url" ));
|
||||
config.addUrisInScope("linkLabelPredicate", list( "http://www.w3.org/2000/01/rdf-schema#label" ));
|
||||
config.addUrisInScope("rankPredicate", list( core + "rank"));
|
||||
config.addSparqlForAdditionalUrisInScope("vcard", individualVcardQuery);
|
||||
|
||||
if ( config.isUpdate() ) {
|
||||
config.addUrisInScope("link", list( linkUri ));
|
||||
}
|
||||
config.setUrisOnForm("urlType");
|
||||
config.setLiteralsOnForm(list("url","anchor","rank"));
|
||||
config.setLiteralsOnForm(list("url","label","rank"));
|
||||
|
||||
config.addSparqlForExistingLiteral("url", URL_QUERY);
|
||||
config.addSparqlForExistingLiteral("anchor", ANCHOR_QUERY);
|
||||
config.addSparqlForExistingLiteral("label", ANCHOR_QUERY);
|
||||
config.addSparqlForExistingLiteral("rank", MAX_RANK_QUERY);
|
||||
config.addSparqlForExistingUris("urlType", URLTYPE_QUERY);
|
||||
|
||||
|
@ -101,10 +106,10 @@ public class AddEditWebpageFormGenerator extends BaseEditConfigurationGenerator
|
|||
setName("urlType").
|
||||
setValidators( list("nonempty") ).
|
||||
setOptions(
|
||||
new ChildVClassesWithParent(this.getURLLinkClass())));
|
||||
new ChildVClassesWithParent("http://www.w3.org/2006/vcard/ns#URL")));
|
||||
|
||||
config.addField(new FieldVTwo().
|
||||
setName("anchor"));
|
||||
setName("label"));
|
||||
|
||||
config.addField(new FieldVTwo().
|
||||
setName("rank").
|
||||
|
@ -133,16 +138,17 @@ public class AddEditWebpageFormGenerator extends BaseEditConfigurationGenerator
|
|||
|
||||
/* ********* N3 Assertions *********** */
|
||||
static String N3_FOR_WEBPAGE =
|
||||
"?subject ?webpageProperty ?link . \n"+
|
||||
"?link ?inverseProperty ?subject . \n"+
|
||||
"?link a ?linkClass . \n" +
|
||||
"?link ?linkURI ?url .";
|
||||
"?subject ?webpageProperty ?vcard . \n"+
|
||||
"?vcard ?inverseProperty ?subject . \n"+
|
||||
"?vcard <http://www.w3.org/2006/vcard/ns#hasURL> ?link ."+
|
||||
"?link a <http://www.w3.org/2006/vcard/ns#URL> . \n" +
|
||||
"?link ?linkUrlPredicate ?url .";
|
||||
|
||||
static String N3_FOR_URLTYPE =
|
||||
"?link a ?urlType .";
|
||||
|
||||
static String N3_FOR_ANCHOR =
|
||||
"?link ?linkAnchorPredicate ?anchor .";
|
||||
"?link ?linkLabelPredicate ?label .";
|
||||
|
||||
static String N3_FOR_RANK =
|
||||
"?link ?rankPredicate ?rank .";
|
||||
|
@ -150,28 +156,35 @@ public class AddEditWebpageFormGenerator extends BaseEditConfigurationGenerator
|
|||
/* *********** SPARQL queries for existing values ************** */
|
||||
|
||||
static String URL_QUERY =
|
||||
"SELECT ?urlExisting WHERE { ?link ?linkURI ?urlExisting }";
|
||||
"SELECT ?urlExisting WHERE { ?link ?linkUrlPredicate ?urlExisting }";
|
||||
|
||||
static String URLTYPE_QUERY =
|
||||
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
|
||||
"SELECT ?linkClassExisting WHERE { ?link vitro:mostSpecificType ?linkClassExisting }";
|
||||
|
||||
static String ANCHOR_QUERY =
|
||||
"SELECT ?anchorExisting WHERE { ?link ?linkAnchorPredicate ?anchorExisting }";
|
||||
"SELECT ?labelExisting WHERE { ?link ?linkLabelPredicate ?labelExisting }";
|
||||
|
||||
static String RANK_QUERY =
|
||||
"SELECT ?rankExisting WHERE { ?link ?rankPredicate ?rankExisting }";
|
||||
|
||||
static String core = "http://vivoweb.org/ontology/core#";
|
||||
|
||||
static String individualVcardQuery =
|
||||
"SELECT ?existingVcard WHERE { \n" +
|
||||
"?subject <http://purl.obolibrary.org/obo/ARG_2000028> ?existingVcard . \n" +
|
||||
"}";
|
||||
|
||||
/* Note on ordering by rank in sparql: if there is a non-integer value on a link, that will be returned,
|
||||
* since it's ranked highest. Preventing that would require getting all the ranks and sorting in Java,
|
||||
* throwing out non-int values.
|
||||
*/
|
||||
private static String MAX_RANK_QUERY = ""
|
||||
+ "PREFIX core: <http://vivoweb.org/ontology/core#> \n"
|
||||
+ "PREFIX vcard: <http://www.w3.org/2006/vcard/ns#> \n"
|
||||
+ "SELECT DISTINCT ?rank WHERE { \n"
|
||||
+ " ?subject core:webpage ?link . \n"
|
||||
+ " ?subject <http://purl.obolibrary.org/obo/ARG_2000028> ?vcard . \n"
|
||||
+ " ?vcard vcard:hasURL ?link . \n"
|
||||
+ " ?link core:rank ?rank .\n"
|
||||
+ "} ORDER BY DESC(?rank) LIMIT 1";
|
||||
|
||||
|
@ -209,23 +222,10 @@ public class AddEditWebpageFormGenerator extends BaseEditConfigurationGenerator
|
|||
return formTemplate;
|
||||
}
|
||||
|
||||
protected String getWebpageProperty() {
|
||||
return core + "webpage";
|
||||
}
|
||||
|
||||
protected String getWebpageOfProperty() {
|
||||
return core + "webpageOf";
|
||||
}
|
||||
|
||||
protected String getMaxRankQueryStr() {
|
||||
return MAX_RANK_QUERY;
|
||||
}
|
||||
|
||||
|
||||
protected String getURLLinkClass() {
|
||||
return core + "URLLink";
|
||||
}
|
||||
|
||||
protected String getN3ForWebpage() {
|
||||
return N3_FOR_WEBPAGE;
|
||||
}
|
||||
|
@ -240,5 +240,9 @@ public class AddEditWebpageFormGenerator extends BaseEditConfigurationGenerator
|
|||
"&editForm=" + UrlBuilder.urlEncode(generatorName);
|
||||
}
|
||||
|
||||
|
||||
private String getLinkUri(VitroRequest vreq) {
|
||||
String linkUri = vreq.getParameter("linkUri");
|
||||
|
||||
return linkUri;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,130 @@
|
|||
/* $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 javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
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.VTwo.EditConfigurationUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.ChildVClassesOptions;
|
||||
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;
|
||||
|
||||
public class AddFullNameToPersonGenerator extends VivoBaseGenerator implements
|
||||
EditConfigurationGenerator {
|
||||
private Log log = LogFactory.getLog(AddFullNameToPersonGenerator.class);
|
||||
|
||||
@Override
|
||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
|
||||
HttpSession session) throws Exception {
|
||||
|
||||
EditConfigurationVTwo conf = new EditConfigurationVTwo();
|
||||
|
||||
initBasics(conf, vreq);
|
||||
initPropertyParameters(vreq, session, conf);
|
||||
initObjectPropForm(conf, vreq);
|
||||
String fullNameUri = getFullNameUri(vreq);
|
||||
|
||||
conf.setTemplate("addFullNameToPerson.ftl");
|
||||
|
||||
conf.setVarNameForSubject("person");
|
||||
conf.setVarNameForPredicate("predicate");
|
||||
conf.setVarNameForObject("individualVcard");
|
||||
|
||||
conf.setN3Required( Arrays.asList( n3ForNewName ) );
|
||||
conf.setN3Optional( Arrays.asList( firstNameAssertion, middleNameAssertion, lastNameAssertion ) );
|
||||
|
||||
conf.addNewResource("fullName", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
conf.addNewResource("individualVcard", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
|
||||
conf.setLiteralsOnForm(Arrays.asList("firstName", "middleName", "lastName" ));
|
||||
|
||||
conf.addSparqlForExistingLiteral("firstName", firstNameQuery);
|
||||
conf.addSparqlForExistingLiteral("middleName", middleNameQuery);
|
||||
conf.addSparqlForExistingLiteral("lastName", lastNameQuery);
|
||||
conf.addSparqlForAdditionalUrisInScope("individualVcard", individualVcardQuery);
|
||||
|
||||
if ( conf.isUpdate() ) {
|
||||
HashMap<String, List<String>> urisInScope = new HashMap<String, List<String>>();
|
||||
urisInScope.put("fullName", Arrays.asList(new String[]{fullNameUri}));
|
||||
conf.addUrisInScope(urisInScope);
|
||||
}
|
||||
|
||||
conf.addField( new FieldVTwo().
|
||||
setName("firstName")
|
||||
.setRangeDatatypeUri( XSD.xstring.toString() ).
|
||||
setValidators( list("nonempty") ));
|
||||
|
||||
conf.addField( new FieldVTwo().
|
||||
setName("middleName")
|
||||
.setRangeDatatypeUri( XSD.xstring.toString()) );
|
||||
|
||||
conf.addField( new FieldVTwo().
|
||||
setName("lastName")
|
||||
.setRangeDatatypeUri( XSD.xstring.toString() ).
|
||||
setValidators( list("nonempty") ));
|
||||
|
||||
conf.addValidator(new AntiXssValidation());
|
||||
|
||||
prepare(vreq, conf);
|
||||
return conf;
|
||||
}
|
||||
|
||||
/* N3 assertions */
|
||||
|
||||
final static String n3ForNewName =
|
||||
"?person <http://purl.obolibrary.org/obo/ARG_2000028> ?individualVcard . \n" +
|
||||
"?individualVcard a <http://www.w3.org/2006/vcard/ns#Individual> . \n" +
|
||||
"?individualVcard <http://purl.obolibrary.org/obo/ARG_2000029> ?person . \n" +
|
||||
"?individualVcard <http://www.w3.org/2006/vcard/ns#hasName> ?fullName . \n" +
|
||||
"?fullName a <http://www.w3.org/2006/vcard/ns#Name> . " ;
|
||||
|
||||
final static String firstNameAssertion =
|
||||
"?fullName <http://www.w3.org/2006/vcard/ns#givenName> ?firstName .";
|
||||
|
||||
final static String middleNameAssertion =
|
||||
"?fullName <http://www.w3.org/2006/vcard/ns#middleName> ?middleName .";
|
||||
|
||||
final static String lastNameAssertion =
|
||||
"?fullName <http://www.w3.org/2006/vcard/ns#familyName> ?lastName .";
|
||||
|
||||
/* Queries for editing an existing entry */
|
||||
|
||||
final static String individualVcardQuery =
|
||||
"SELECT ?existingIndividualVcard WHERE { \n" +
|
||||
"?person <http://purl.obolibrary.org/obo/ARG_2000028> ?existingIndividualVcard . \n" +
|
||||
"}";
|
||||
|
||||
final static String firstNameQuery =
|
||||
"SELECT ?existingFirstName WHERE {\n"+
|
||||
"?fullName <http://www.w3.org/2006/vcard/ns#givenName> ?existingFirstName . }";
|
||||
|
||||
final static String middleNameQuery =
|
||||
"SELECT ?existingMiddleName WHERE {\n"+
|
||||
"?fullName <http://www.w3.org/2006/vcard/ns#middleName> ?existingMiddleName . }";
|
||||
|
||||
final static String lastNameQuery =
|
||||
"SELECT ?existingLastName WHERE {\n"+
|
||||
"?fullName <http://www.w3.org/2006/vcard/ns#familyName> ?existingLastName . }";
|
||||
|
||||
private String getFullNameUri(VitroRequest vreq) {
|
||||
String fullNameUri = vreq.getParameter("fullNameUri");
|
||||
|
||||
return fullNameUri;
|
||||
}
|
||||
}
|
|
@ -451,13 +451,23 @@ public class AddPublicationToPersonGenerator extends VivoBaseGenerator implement
|
|||
}
|
||||
|
||||
private String getN3FirstNameAssertion() {
|
||||
return "@prefix foaf: <" + foaf + "> . \n" +
|
||||
"?newEditor foaf:firstName ?firstName .";
|
||||
return "@prefix vcard: <http://www.w3.org/2006/vcard/ns#> . \n" +
|
||||
"?newEditor <http://purl.obolibrary.org/obo/ARG_2000028> ?vcardEditor . \n" +
|
||||
"?vcardEditor <http://purl.obolibrary.org/obo/ARG_2000029> ?newEditor . \n" +
|
||||
"?vcardEditor a <http://www.w3.org/2006/vcard/ns#Individual> . \n" +
|
||||
"?vcardEditor vcard:hasName ?vcardName . \n" +
|
||||
"?vcardName a <http://www.w3.org/2006/vcard/ns#Name> . \n" +
|
||||
"?vcardName vcard:givenName ?firstName .";
|
||||
}
|
||||
|
||||
private String getN3LastNameAssertion() {
|
||||
return "@prefix foaf: <" + foaf + "> . \n" +
|
||||
"?newEditor foaf:lastName ?lastName .";
|
||||
return "@prefix vcard: <http://www.w3.org/2006/vcard/ns#> . \n" +
|
||||
"?newEditor <http://purl.obolibrary.org/obo/ARG_2000028> ?vcardEditor . \n" +
|
||||
"?vcardEditor <http://purl.obolibrary.org/obo/ARG_2000029> ?newEditor . \n" +
|
||||
"?vcardEditor a <http://www.w3.org/2006/vcard/ns#Individual> . \n" +
|
||||
"?vcardEditor vcard:hasName ?vcardName . \n" +
|
||||
"?vcardName a <http://www.w3.org/2006/vcard/ns#Name> . \n" +
|
||||
"?vcardName vcard:familyName ?lastName .";
|
||||
}
|
||||
|
||||
private String getN3ForLocaleAssertion() {
|
||||
|
@ -515,6 +525,8 @@ public class AddPublicationToPersonGenerator extends VivoBaseGenerator implement
|
|||
newResources.put("newConference", DEFAULT_NS_TOKEN);
|
||||
newResources.put("newEvent", DEFAULT_NS_TOKEN);
|
||||
newResources.put("newEditor", DEFAULT_NS_TOKEN);
|
||||
newResources.put("vcardEditor", DEFAULT_NS_TOKEN);
|
||||
newResources.put("vcardName", DEFAULT_NS_TOKEN);
|
||||
newResources.put("newPublisher", DEFAULT_NS_TOKEN);
|
||||
newResources.put("dateTimeNode", DEFAULT_NS_TOKEN);
|
||||
return newResources;
|
||||
|
|
|
@ -83,10 +83,14 @@ public class ManageWebpagesForIndividualGenerator extends BaseEditConfigurationG
|
|||
|
||||
private static String WEBPAGE_QUERY = ""
|
||||
+ "PREFIX core: <http://vivoweb.org/ontology/core#> \n"
|
||||
+ "SELECT DISTINCT ?link ?url ?anchor ?rank WHERE { \n"
|
||||
+ " ?subject core:webpage ?link . \n"
|
||||
+ " OPTIONAL { ?link core:linkURI ?url } \n"
|
||||
+ " OPTIONAL { ?link core:linkAnchorText ?anchor } \n"
|
||||
+ "PREFIX vcard: <http://www.w3.org/2006/vcard/ns#> \n"
|
||||
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
|
||||
+ "SELECT DISTINCT ?vcard ?link ?url ?label ?rank WHERE { \n"
|
||||
+ " ?subject <http://purl.obolibrary.org/obo/ARG_2000028> ?vcard . \n"
|
||||
+ " ?vcard vcard:hasURL ?link . \n"
|
||||
+ " ?link a vcard:URL \n"
|
||||
+ " OPTIONAL { ?link vcard:url ?url } \n"
|
||||
+ " OPTIONAL { ?link rdfs:label ?label } \n"
|
||||
+ " OPTIONAL { ?link core:rank ?rank } \n"
|
||||
+ "} ORDER BY ?rank";
|
||||
|
||||
|
@ -108,7 +112,7 @@ public class ManageWebpagesForIndividualGenerator extends BaseEditConfigurationG
|
|||
} catch (Exception e) {
|
||||
log.error(e, e);
|
||||
}
|
||||
|
||||
log.debug("webpages = " + webpages);
|
||||
return webpages;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,177 +1,188 @@
|
|||
/* $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.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||
import com.hp.hpl.jena.vocabulary.XSD;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
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.preprocessors.FoafNameToRdfsLabelPreprocessor;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
||||
|
||||
/**
|
||||
* Generates the edit configuration for a default property form.
|
||||
* ModelChangePreprocessor creates the rdfs:label statement.
|
||||
*/
|
||||
public class NewIndividualFormGenerator extends BaseEditConfigurationGenerator implements EditConfigurationGenerator {
|
||||
|
||||
@Override
|
||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) {
|
||||
|
||||
EditConfigurationVTwo config = new EditConfigurationVTwo();
|
||||
|
||||
config.setTemplate( "newIndividualForm.ftl" );
|
||||
|
||||
config.setN3Required( list(
|
||||
"?newInd <" + VitroVocabulary.RDF_TYPE + "> <" + getTypeOfNew(vreq) + "> ."
|
||||
));
|
||||
//Optional because user may have selected either person or individual of another kind
|
||||
//Person uses first name and last name whereas individual of other class would use label
|
||||
config.setN3Optional(list(
|
||||
N3_PREFIX + "?newInd foaf:firstName ?firstName ; foaf:lastName ?lastName .",
|
||||
N3_PREFIX + "?newInd <" + RDFS.label.getURI() + "> ?label ."
|
||||
));
|
||||
|
||||
config.addNewResource("newInd", vreq.getWebappDaoFactory().getDefaultNamespace());
|
||||
|
||||
config.setUrisOnform(list ());
|
||||
config.setLiteralsOnForm( list( "label", "firstName", "lastName" ));
|
||||
setUrisAndLiteralsInScope(config);
|
||||
//No SPARQL queries for existing since this is only used to create new, never for edit
|
||||
|
||||
config.addField(new FieldVTwo().
|
||||
setName("firstName").
|
||||
setRangeDatatypeUri(XSD.xstring.getURI()).
|
||||
setValidators(getFirstNameValidators(vreq)));
|
||||
|
||||
config.addField(new FieldVTwo().
|
||||
setName("lastName").
|
||||
setRangeDatatypeUri(XSD.xstring.getURI()).
|
||||
setValidators(getLastNameValidators(vreq)));
|
||||
|
||||
config.addField(new FieldVTwo().
|
||||
setName("label").
|
||||
setRangeDatatypeUri(XSD.xstring.getURI()).
|
||||
setValidators(getLabelValidators(vreq)));
|
||||
|
||||
addFormSpecificData(config, vreq);
|
||||
|
||||
config.addValidator(new AntiXssValidation());
|
||||
|
||||
//This combines the first and last name into the rdfs:label
|
||||
config.addModelChangePreprocessor(new FoafNameToRdfsLabelPreprocessor());
|
||||
|
||||
String formUrl = EditConfigurationUtils.getFormUrlWithoutContext(vreq);
|
||||
config.setFormUrl(formUrl);
|
||||
|
||||
//Note, the spaces are important - they were added by ProcessRdfFormController earlier
|
||||
//as a means of ensuring the substitution worked correctly - as the regex expects spaces
|
||||
config.setEntityToReturnTo(" ?newInd ");
|
||||
prepare(vreq, config);
|
||||
return config;
|
||||
}
|
||||
|
||||
//first and last name have validators if is person is true
|
||||
private List<String> getFirstNameValidators(VitroRequest vreq) {
|
||||
List<String> validators = new ArrayList<String>();
|
||||
if(isPersonType(vreq)) {
|
||||
validators.add("nonempty");
|
||||
}
|
||||
return validators;
|
||||
}
|
||||
|
||||
private List<String> getLastNameValidators(VitroRequest vreq) {
|
||||
List<String> validators = new ArrayList<String>();
|
||||
if(isPersonType(vreq)) {
|
||||
validators.add("nonempty");
|
||||
}
|
||||
return validators;
|
||||
}
|
||||
|
||||
//validate label if person is not true
|
||||
private List<String> getLabelValidators(VitroRequest vreq) {
|
||||
List<String> validators = new ArrayList<String>();
|
||||
if(!isPersonType(vreq)) {
|
||||
validators.add("nonempty");
|
||||
}
|
||||
return validators;
|
||||
}
|
||||
|
||||
//Get parameter from HTTP request for type of new individual
|
||||
private String getTypeOfNew(VitroRequest vreq) {
|
||||
String typeUri = vreq.getParameter("typeOfNew");
|
||||
if( typeUri == null || typeUri.trim().isEmpty() )
|
||||
return getFOAFPersonClassURI();
|
||||
else
|
||||
return typeUri;
|
||||
}
|
||||
|
||||
//Form specific data
|
||||
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
|
||||
formSpecificData.put("typeName", getTypeName(vreq));
|
||||
//Put in whether or not person type
|
||||
if(isPersonType(vreq)) {
|
||||
//Doing this b/c unsure how freemarker will handle boolean value from JAVA
|
||||
formSpecificData.put("isPersonType", "true");
|
||||
} else {
|
||||
formSpecificData.put("isPersonType", "false");
|
||||
|
||||
}
|
||||
editConfiguration.setFormSpecificData(formSpecificData);
|
||||
}
|
||||
|
||||
private String getTypeName(VitroRequest vreq) {
|
||||
String typeOfNew = getTypeOfNew(vreq);
|
||||
VClass type = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(typeOfNew);
|
||||
return type.getName();
|
||||
}
|
||||
|
||||
public String getFOAFPersonClassURI() {
|
||||
return "http://xmlns.com/foaf/0.1/Person";
|
||||
}
|
||||
|
||||
public boolean isPersonType(VitroRequest vreq) {
|
||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||
Boolean isPersonType = Boolean.FALSE;
|
||||
String foafPersonType = getFOAFPersonClassURI();
|
||||
List<String> superTypes = wdf.getVClassDao().getAllSuperClassURIs(getTypeOfNew(vreq));
|
||||
if( superTypes != null ){
|
||||
for( String typeUri : superTypes){
|
||||
if( foafPersonType.equals(typeUri)) {
|
||||
isPersonType = Boolean.TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isPersonType;
|
||||
}
|
||||
private void setUrisAndLiteralsInScope(EditConfigurationVTwo editConfiguration) {
|
||||
HashMap<String, List<String>> urisInScope = new HashMap<String, List<String>>();
|
||||
//note that at this point the subject, predicate, and object var parameters have already been processed
|
||||
urisInScope.put(editConfiguration.getVarNameForSubject(),
|
||||
Arrays.asList(new String[]{editConfiguration.getSubjectUri()}));
|
||||
urisInScope.put(editConfiguration.getVarNameForPredicate(),
|
||||
Arrays.asList(new String[]{editConfiguration.getPredicateUri()}));
|
||||
editConfiguration.setUrisInScope(urisInScope);
|
||||
//Uris in scope include subject, predicate, and object var
|
||||
|
||||
editConfiguration.setLiteralsInScope(new HashMap<String, List<Literal>>());
|
||||
}
|
||||
|
||||
private String N3_PREFIX = "@prefix foaf:<http://xmlns.com/foaf/0.1/> .\n";
|
||||
}
|
||||
/* $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.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||
import com.hp.hpl.jena.vocabulary.XSD;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
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.preprocessors.FoafNameToRdfsLabelPreprocessor;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
||||
|
||||
/**
|
||||
* Generates the edit configuration for a default property form.
|
||||
* ModelChangePreprocessor creates the rdfs:label statement.
|
||||
*/
|
||||
public class NewIndividualFormGenerator extends BaseEditConfigurationGenerator implements EditConfigurationGenerator {
|
||||
|
||||
@Override
|
||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) {
|
||||
|
||||
EditConfigurationVTwo config = new EditConfigurationVTwo();
|
||||
|
||||
config.setTemplate( "newIndividualForm.ftl" );
|
||||
|
||||
config.setN3Required( list(
|
||||
"?newInd <" + VitroVocabulary.RDF_TYPE + "> <" + getTypeOfNew(vreq) + "> ."
|
||||
));
|
||||
//Optional because user may have selected either person or individual of another kind
|
||||
//Person uses first name and last name whereas individual of other class would use label
|
||||
config.setN3Optional(list(
|
||||
N3_PREFIX + "@prefix vcard:<http://www.w3.org/2006/vcard/ns#> .\n"
|
||||
+ " ?newInd <http://purl.obolibrary.org/obo/ARG_2000028> ?newVcardInd . \n"
|
||||
+ " ?newVcardInd <http://purl.obolibrary.org/obo/ARG_2000029> ?newInd . \n"
|
||||
+ " ?newVcardInd a <http://www.w3.org/2006/vcard/ns#Individual> . \n"
|
||||
+ " ?newVcardInd vcard:hasName ?newVcardName . \n"
|
||||
+ " ?newVcardName a <http://www.w3.org/2006/vcard/ns#Name> . \n"
|
||||
+ " ?newVcardName vcard:givenName ?firstName . \n"
|
||||
+ " ?newVcardName vcard:familyName ?lastName .",
|
||||
N3_PREFIX + " ?newInd <" + RDFS.label.getURI() + "> ?label ."
|
||||
));
|
||||
|
||||
config.addNewResource("newInd", vreq.getWebappDaoFactory().getDefaultNamespace());
|
||||
config.addNewResource("newVcardInd", vreq.getWebappDaoFactory().getDefaultNamespace());
|
||||
config.addNewResource("newVcardName", vreq.getWebappDaoFactory().getDefaultNamespace());
|
||||
|
||||
config.setUrisOnform(list ());
|
||||
config.setLiteralsOnForm( list( "label", "firstName", "lastName" ));
|
||||
setUrisAndLiteralsInScope(config);
|
||||
//No SPARQL queries for existing since this is only used to create new, never for edit
|
||||
|
||||
config.addField(new FieldVTwo().
|
||||
setName("firstName").
|
||||
setRangeDatatypeUri(XSD.xstring.getURI()).
|
||||
setValidators(getFirstNameValidators(vreq)));
|
||||
|
||||
config.addField(new FieldVTwo().
|
||||
setName("lastName").
|
||||
setRangeDatatypeUri(XSD.xstring.getURI()).
|
||||
setValidators(getLastNameValidators(vreq)));
|
||||
|
||||
config.addField(new FieldVTwo().
|
||||
setName("label").
|
||||
setRangeDatatypeUri(XSD.xstring.getURI()).
|
||||
setValidators(getLabelValidators(vreq)));
|
||||
|
||||
addFormSpecificData(config, vreq);
|
||||
|
||||
config.addValidator(new AntiXssValidation());
|
||||
|
||||
//This combines the first and last name into the rdfs:label
|
||||
// currently being done via javascript in the template. May use this again
|
||||
// when/if updated to IFS ontology. tlw72
|
||||
// config.addModelChangePreprocessor(new FoafNameToRdfsLabelPreprocessor());
|
||||
|
||||
String formUrl = EditConfigurationUtils.getFormUrlWithoutContext(vreq);
|
||||
config.setFormUrl(formUrl);
|
||||
|
||||
//Note, the spaces are important - they were added by ProcessRdfFormController earlier
|
||||
//as a means of ensuring the substitution worked correctly - as the regex expects spaces
|
||||
config.setEntityToReturnTo(" ?newInd ");
|
||||
prepare(vreq, config);
|
||||
return config;
|
||||
}
|
||||
|
||||
//first and last name have validators if is person is true
|
||||
private List<String> getFirstNameValidators(VitroRequest vreq) {
|
||||
List<String> validators = new ArrayList<String>();
|
||||
if(isPersonType(vreq)) {
|
||||
validators.add("nonempty");
|
||||
}
|
||||
return validators;
|
||||
}
|
||||
|
||||
private List<String> getLastNameValidators(VitroRequest vreq) {
|
||||
List<String> validators = new ArrayList<String>();
|
||||
if(isPersonType(vreq)) {
|
||||
validators.add("nonempty");
|
||||
}
|
||||
return validators;
|
||||
}
|
||||
|
||||
//validate label if person is not true
|
||||
private List<String> getLabelValidators(VitroRequest vreq) {
|
||||
List<String> validators = new ArrayList<String>();
|
||||
if(!isPersonType(vreq)) {
|
||||
validators.add("nonempty");
|
||||
}
|
||||
return validators;
|
||||
}
|
||||
|
||||
//Get parameter from HTTP request for type of new individual
|
||||
private String getTypeOfNew(VitroRequest vreq) {
|
||||
String typeUri = vreq.getParameter("typeOfNew");
|
||||
if( typeUri == null || typeUri.trim().isEmpty() )
|
||||
return getFOAFPersonClassURI();
|
||||
else
|
||||
return typeUri;
|
||||
}
|
||||
|
||||
//Form specific data
|
||||
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
|
||||
formSpecificData.put("typeName", getTypeName(vreq));
|
||||
//Put in whether or not person type
|
||||
if(isPersonType(vreq)) {
|
||||
//Doing this b/c unsure how freemarker will handle boolean value from JAVA
|
||||
formSpecificData.put("isPersonType", "true");
|
||||
} else {
|
||||
formSpecificData.put("isPersonType", "false");
|
||||
|
||||
}
|
||||
editConfiguration.setFormSpecificData(formSpecificData);
|
||||
}
|
||||
|
||||
private String getTypeName(VitroRequest vreq) {
|
||||
String typeOfNew = getTypeOfNew(vreq);
|
||||
VClass type = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(typeOfNew);
|
||||
return type.getName();
|
||||
}
|
||||
|
||||
public String getFOAFPersonClassURI() {
|
||||
return "http://xmlns.com/foaf/0.1/Person";
|
||||
}
|
||||
|
||||
public boolean isPersonType(VitroRequest vreq) {
|
||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||
Boolean isPersonType = Boolean.FALSE;
|
||||
String foafPersonType = getFOAFPersonClassURI();
|
||||
List<String> superTypes = wdf.getVClassDao().getAllSuperClassURIs(getTypeOfNew(vreq));
|
||||
if( superTypes != null ){
|
||||
for( String typeUri : superTypes){
|
||||
if( foafPersonType.equals(typeUri)) {
|
||||
isPersonType = Boolean.TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isPersonType;
|
||||
}
|
||||
private void setUrisAndLiteralsInScope(EditConfigurationVTwo editConfiguration) {
|
||||
HashMap<String, List<String>> urisInScope = new HashMap<String, List<String>>();
|
||||
//note that at this point the subject, predicate, and object var parameters have already been processed
|
||||
urisInScope.put(editConfiguration.getVarNameForSubject(),
|
||||
Arrays.asList(new String[]{editConfiguration.getSubjectUri()}));
|
||||
urisInScope.put(editConfiguration.getVarNameForPredicate(),
|
||||
Arrays.asList(new String[]{editConfiguration.getPredicateUri()}));
|
||||
editConfiguration.setUrisInScope(urisInScope);
|
||||
//Uris in scope include subject, predicate, and object var
|
||||
|
||||
editConfiguration.setLiteralsInScope(new HashMap<String, List<Literal>>());
|
||||
}
|
||||
|
||||
private String N3_PREFIX = "@prefix foaf:<http://xmlns.com/foaf/0.1/> .\n";
|
||||
}
|
||||
|
|
|
@ -71,6 +71,8 @@ public class PersonHasAdvisingRelationshipGenerator extends VivoBaseGenerator im
|
|||
|
||||
conf.addNewResource("advisingRelationship", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
conf.addNewResource("newAdvisee", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
conf.addNewResource("vcardAdvisee", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
conf.addNewResource("vcardName", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
conf.addNewResource("advisorRole", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
conf.addNewResource("adviseeRole", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
conf.addNewResource("newSubjArea", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
|
@ -229,12 +231,22 @@ public class PersonHasAdvisingRelationshipGenerator extends VivoBaseGenerator im
|
|||
"?adviseeRole <http://vivoweb.org/ontology/core#relatedBy> ?advisingRelationship . ";
|
||||
|
||||
final static String firstNameAssertion =
|
||||
"@prefix foaf: <" + foaf + "> . \n" +
|
||||
"?newAdvisee foaf:firstName ?firstName .";
|
||||
"@prefix vcard: <http://www.w3.org/2006/vcard/ns#> . \n" +
|
||||
"?newAdvisee <http://purl.obolibrary.org/obo/ARG_2000028> ?vcardAdvisee . \n" +
|
||||
"?vcardAdvisee <http://purl.obolibrary.org/obo/ARG_2000029> ?newAdvisee . \n" +
|
||||
"?vcardAdvisee a <http://www.w3.org/2006/vcard/ns#Individual> . \n" +
|
||||
"?vcardAdvisee vcard:hasName ?vcardName . \n" +
|
||||
"?vcardName a <http://www.w3.org/2006/vcard/ns#Name> . \n" +
|
||||
"?vcardName vcard:givenName ?firstName .";
|
||||
|
||||
final static String lastNameAssertion =
|
||||
"@prefix foaf: <" + foaf + "> . \n" +
|
||||
"?newAdvisee foaf:lastName ?lastName .";
|
||||
"@prefix vcard: <http://www.w3.org/2006/vcard/ns#> . \n" +
|
||||
"?newAdvisee <http://purl.obolibrary.org/obo/ARG_2000028> ?vcardAdvisee . \n" +
|
||||
"?vcardAdvisee <http://purl.obolibrary.org/obo/ARG_2000029> ?newAdvisee . \n" +
|
||||
"?vcardAdvisee a <http://www.w3.org/2006/vcard/ns#Individual> . \n" +
|
||||
"?vcardAdvisee vcard:hasName ?vcardName . \n" +
|
||||
"?vcardName a <http://www.w3.org/2006/vcard/ns#Name> . \n" +
|
||||
"?vcardName vcard:familyName ?lastName .";
|
||||
|
||||
final static String degreeAssertion =
|
||||
"?advisingRelationship <http://vivoweb.org/ontology/core#relates> ?degree . \n" +
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
/* $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 javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
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.VTwo.EditConfigurationUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.ChildVClassesOptions;
|
||||
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;
|
||||
|
||||
public class PersonHasEmailGenerator extends VivoBaseGenerator implements
|
||||
EditConfigurationGenerator {
|
||||
private Log log = LogFactory.getLog(PersonHasEmailGenerator.class);
|
||||
|
||||
@Override
|
||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
|
||||
HttpSession session) throws Exception {
|
||||
|
||||
EditConfigurationVTwo conf = new EditConfigurationVTwo();
|
||||
|
||||
initBasics(conf, vreq);
|
||||
initPropertyParameters(vreq, session, conf);
|
||||
initObjectPropForm(conf, vreq);
|
||||
String emailUri = getEmailUri(vreq);
|
||||
String rangeUri = getRangeUri(vreq);
|
||||
|
||||
conf.setTemplate("personHasEmailAddress.ftl");
|
||||
|
||||
conf.setVarNameForSubject("person");
|
||||
conf.setVarNameForPredicate("predicate");
|
||||
conf.setVarNameForObject("individualVcard");
|
||||
|
||||
if ( rangeUri.equals("http://www.w3.org/2006/vcard/ns#Work") ) {
|
||||
conf.setN3Required( Arrays.asList( n3ForNewPrimaryEmail ) );
|
||||
}
|
||||
else {
|
||||
conf.setN3Required( Arrays.asList( n3ForNewEmail ) );
|
||||
}
|
||||
|
||||
conf.setN3Optional( Arrays.asList( emailAddressAssertion ) );
|
||||
|
||||
conf.addNewResource("email", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
conf.addNewResource("individualVcard", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
|
||||
conf.setLiteralsOnForm(Arrays.asList("emailAddress" ));
|
||||
|
||||
conf.addSparqlForExistingLiteral("emailAddress", emailAddressQuery);
|
||||
conf.addSparqlForAdditionalUrisInScope("individualVcard", individualVcardQuery);
|
||||
|
||||
if ( conf.isUpdate() ) {
|
||||
HashMap<String, List<String>> urisInScope = new HashMap<String, List<String>>();
|
||||
urisInScope.put("email", Arrays.asList(new String[]{emailUri}));
|
||||
conf.addUrisInScope(urisInScope);
|
||||
}
|
||||
|
||||
conf.addField( new FieldVTwo().
|
||||
setName("emailAddress")
|
||||
.setRangeDatatypeUri( XSD.xstring.toString() ).
|
||||
setValidators( list("nonempty") ));
|
||||
|
||||
conf.addValidator(new AntiXssValidation());
|
||||
|
||||
prepare(vreq, conf);
|
||||
return conf;
|
||||
}
|
||||
|
||||
/* N3 assertions */
|
||||
|
||||
final static String n3ForNewEmail =
|
||||
"?person <http://purl.obolibrary.org/obo/ARG_2000028> ?individualVcard . \n" +
|
||||
"?individualVcard a <http://www.w3.org/2006/vcard/ns#Individual> . \n" +
|
||||
"?individualVcard <http://purl.obolibrary.org/obo/ARG_2000029> ?person . \n" +
|
||||
"?individualVcard <http://www.w3.org/2006/vcard/ns#hasEmail> ?email . \n" +
|
||||
"?email a <http://www.w3.org/2006/vcard/ns#Email> . " ;
|
||||
|
||||
final static String n3ForNewPrimaryEmail =
|
||||
"?person <http://purl.obolibrary.org/obo/ARG_2000028> ?individualVcard . \n" +
|
||||
"?individualVcard a <http://www.w3.org/2006/vcard/ns#Individual> . \n" +
|
||||
"?individualVcard <http://purl.obolibrary.org/obo/ARG_2000029> ?person . \n" +
|
||||
"?individualVcard <http://www.w3.org/2006/vcard/ns#hasEmail> ?email . \n" +
|
||||
"?email a <http://www.w3.org/2006/vcard/ns#Email> . \n" +
|
||||
"?email a <http://www.w3.org/2006/vcard/ns#Work> ." ;
|
||||
|
||||
final static String emailAddressAssertion =
|
||||
"?email <http://www.w3.org/2006/vcard/ns#email> ?emailAddress .";
|
||||
|
||||
/* Queries for editing an existing entry */
|
||||
|
||||
final static String individualVcardQuery =
|
||||
"SELECT ?existingIndividualVcard WHERE { \n" +
|
||||
"?person <http://purl.obolibrary.org/obo/ARG_2000028> ?existingIndividualVcard . \n" +
|
||||
"}";
|
||||
|
||||
final static String emailAddressQuery =
|
||||
"SELECT ?existingEmailAddress WHERE {\n"+
|
||||
"?email <http://www.w3.org/2006/vcard/ns#email> ?existingEmailAddress . }";
|
||||
|
||||
private String getRangeUri(VitroRequest vreq) {
|
||||
String rangeUri = vreq.getParameter("rangeUri");
|
||||
|
||||
return rangeUri;
|
||||
}
|
||||
private String getEmailUri(VitroRequest vreq) {
|
||||
String emailUri = vreq.getParameter("emailUri");
|
||||
|
||||
return emailUri;
|
||||
}
|
||||
}
|
|
@ -2,14 +2,23 @@
|
|||
|
||||
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 javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
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.VTwo.EditConfigurationUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.ChildVClassesOptions;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||
|
@ -18,20 +27,8 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.
|
|||
|
||||
public class PersonHasMailingAddressGenerator extends VivoBaseGenerator implements
|
||||
EditConfigurationGenerator {
|
||||
|
||||
final static String addressClass = vivoCore + "Address";
|
||||
final static String countryPred = vivoCore + "addressCountry";
|
||||
final static String countryClass = vivoCore + "Country";
|
||||
final static String addrLine1Pred =vivoCore+"address1" ;
|
||||
final static String addrLine2Pred =vivoCore+"address2" ;
|
||||
final static String addrLine3Pred =vivoCore+"address3" ;
|
||||
final static String cityPred =vivoCore+"addressCity" ;
|
||||
final static String statePred =vivoCore+"addressState" ;
|
||||
final static String postalCodePred =vivoCore+"addressPostalCode" ;
|
||||
final static String mailingAddressPred =vivoCore+"mailingAddress" ;
|
||||
|
||||
public PersonHasMailingAddressGenerator() {}
|
||||
|
||||
private Log log = LogFactory.getLog(PersonHasMailingAddressGenerator.class);
|
||||
|
||||
@Override
|
||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
|
||||
HttpSession session) throws Exception {
|
||||
|
@ -40,59 +37,51 @@ public class PersonHasMailingAddressGenerator extends VivoBaseGenerator implemen
|
|||
|
||||
initBasics(conf, vreq);
|
||||
initPropertyParameters(vreq, session, conf);
|
||||
initObjectPropForm(conf, vreq);
|
||||
initObjectPropForm(conf, vreq);
|
||||
String addressUri = vreq.getParameter("addressUri");
|
||||
|
||||
conf.setTemplate("personHasMailingAddress.ftl");
|
||||
|
||||
conf.setVarNameForSubject("person");
|
||||
conf.setVarNameForPredicate("predicate");
|
||||
conf.setVarNameForObject("address");
|
||||
conf.setVarNameForObject("individualVcard");
|
||||
|
||||
conf.setN3Required( Arrays.asList( n3ForNewAddress,
|
||||
addrLabelAssertion,
|
||||
addressTypeAssertion ) );
|
||||
conf.setN3Optional( Arrays.asList( addrLineOneAssertion, addrLineTwoAssertion, addrLineThreeAssertion, cityAssertion, stateAssertion, countryAssertion, postalCodeAssertion ) );
|
||||
conf.setN3Required( Arrays.asList( n3ForNewAddress ) );
|
||||
conf.setN3Optional( Arrays.asList( streetAddressAssertion,
|
||||
localityAssertion,
|
||||
regionAssertion,
|
||||
countryAssertion,
|
||||
postalCodeAssertion ) );
|
||||
|
||||
conf.addNewResource("address", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
conf.addNewResource("individualVcard", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
|
||||
conf.setLiteralsOnForm(Arrays.asList("streetAddress", "locality", "postalCode", "country", "region" ));
|
||||
|
||||
//uris in scope: none
|
||||
//literals in scope: none
|
||||
|
||||
conf.setUrisOnform(Arrays.asList("addressType"));
|
||||
conf.setLiteralsOnForm(Arrays.asList("addrLineOne", "addrLineTwo", "addrLineThree", "city", "postalCode", "addrLabel","country", "state" ));
|
||||
|
||||
conf.addSparqlForExistingLiteral("addrLabel", addrLabelQuery);
|
||||
conf.addSparqlForExistingLiteral("addrLineOne", addrLineOneQuery);
|
||||
conf.addSparqlForExistingLiteral("addrLineTwo", addrLineTwoQuery);
|
||||
conf.addSparqlForExistingLiteral("addrLineThree", addrLineThreeQuery);
|
||||
conf.addSparqlForExistingLiteral("city", cityQuery);
|
||||
conf.addSparqlForExistingLiteral("streetAddress", streetAddressQuery);
|
||||
conf.addSparqlForExistingLiteral("locality", localityQuery);
|
||||
conf.addSparqlForExistingLiteral("postalCode", postalCodeQuery);
|
||||
conf.addSparqlForExistingLiteral("state", stateQuery);
|
||||
conf.addSparqlForExistingLiteral("country", countryQuery);
|
||||
conf.addSparqlForExistingLiteral("region", regionQuery);
|
||||
conf.addSparqlForExistingLiteral("country", countryQuery);
|
||||
|
||||
conf.addSparqlForExistingUris("addressType", addressTypeQuery);
|
||||
|
||||
conf.addField( new FieldVTwo().
|
||||
setName("country").
|
||||
setValidators( list("nonempty") ).
|
||||
setOptions(
|
||||
new IndividualsViaVClassOptions(
|
||||
countryClass)));
|
||||
if ( conf.isUpdate() ) {
|
||||
HashMap<String, List<String>> urisInScope = new HashMap<String, List<String>>();
|
||||
urisInScope.put("address", Arrays.asList(new String[]{addressUri}));
|
||||
conf.addUrisInScope(urisInScope);
|
||||
}
|
||||
else {
|
||||
conf.addSparqlForAdditionalUrisInScope("individualVcard", individualVcardQuery);
|
||||
}
|
||||
|
||||
conf.addField( new FieldVTwo().
|
||||
setName("addrLineOne")
|
||||
setName("streetAddress")
|
||||
.setRangeDatatypeUri( XSD.xstring.toString() ).
|
||||
setValidators( list("nonempty") ));
|
||||
|
||||
conf.addField( new FieldVTwo().
|
||||
setName("addrLineTwo")
|
||||
setName("country")
|
||||
.setRangeDatatypeUri( XSD.xstring.toString() ).
|
||||
setValidators( list("datatype:" + XSD.xstring.toString()) ));
|
||||
|
||||
conf.addField( new FieldVTwo().
|
||||
setName("addrLineThree")
|
||||
.setRangeDatatypeUri( XSD.xstring.toString() ).
|
||||
setValidators( list("datatype:" + XSD.xstring.toString()) ));
|
||||
setValidators( list("nonempty") ));
|
||||
|
||||
conf.addField( new FieldVTwo().
|
||||
setName("postalCode")
|
||||
|
@ -100,25 +89,15 @@ public class PersonHasMailingAddressGenerator extends VivoBaseGenerator implemen
|
|||
setValidators( list("nonempty") ));
|
||||
|
||||
conf.addField( new FieldVTwo().
|
||||
setName("city")
|
||||
setName("locality")
|
||||
.setRangeDatatypeUri( XSD.xstring.toString() ).
|
||||
setValidators( list("nonempty") ) );
|
||||
|
||||
conf.addField( new FieldVTwo().
|
||||
setName("state")
|
||||
setName("region")
|
||||
.setRangeDatatypeUri( XSD.xstring.toString() ).
|
||||
setValidators( list("datatype:" + XSD.xstring.toString()) ) );
|
||||
|
||||
conf.addField( new FieldVTwo().
|
||||
setName("addrLabel")
|
||||
.setRangeDatatypeUri( XSD.xstring.toString() ).
|
||||
setValidators( list("datatype:" + XSD.xstring.toString()) ) );
|
||||
|
||||
conf.addField( new FieldVTwo().
|
||||
setName("addressType").
|
||||
setOptions(new ChildVClassesOptions(
|
||||
addressClass)) );
|
||||
|
||||
conf.addValidator(new AntiXssValidation());
|
||||
|
||||
prepare(vreq, conf);
|
||||
|
@ -128,77 +107,53 @@ public class PersonHasMailingAddressGenerator extends VivoBaseGenerator implemen
|
|||
/* N3 assertions */
|
||||
|
||||
final static String n3ForNewAddress =
|
||||
"@prefix vivo: <" + vivoCore + "> . \n\n" +
|
||||
"?person vivo:mailingAddress ?address . \n" +
|
||||
"?address a vivo:Address . \n" +
|
||||
"?address vivo:mailingAddressFor ?person . \n" ;
|
||||
"?person <http://purl.obolibrary.org/obo/ARG_2000028> ?individualVcard . \n" +
|
||||
"?individualVcard a <http://www.w3.org/2006/vcard/ns#Individual> . \n" +
|
||||
"?individualVcard <http://purl.obolibrary.org/obo/ARG_2000029> ?person . \n" +
|
||||
"?individualVcard <http://www.w3.org/2006/vcard/ns#hasAddress> ?address . \n" +
|
||||
"?address a <http://www.w3.org/2006/vcard/ns#Address> . " ;
|
||||
|
||||
final static String addrLineOneAssertion =
|
||||
"?address <"+ addrLine1Pred +"> ?addrLineOne .";
|
||||
final static String streetAddressAssertion =
|
||||
"?address <http://www.w3.org/2006/vcard/ns#streetAddress> ?streetAddress .";
|
||||
|
||||
final static String addrLineTwoAssertion =
|
||||
"?address <"+ addrLine2Pred +"> ?addrLineTwo .";
|
||||
|
||||
final static String addrLineThreeAssertion =
|
||||
"?address <"+ addrLine3Pred +"> ?addrLineThree .";
|
||||
|
||||
final static String cityAssertion =
|
||||
"?address <"+ cityPred +"> ?city .";
|
||||
final static String localityAssertion =
|
||||
"?address <http://www.w3.org/2006/vcard/ns#locality> ?locality .";
|
||||
|
||||
final static String postalCodeAssertion =
|
||||
"?address <"+ postalCodePred +"> ?postalCode .";
|
||||
"?address <http://www.w3.org/2006/vcard/ns#postalCode> ?postalCode .";
|
||||
|
||||
final static String stateAssertion =
|
||||
"?address <"+ statePred +"> ?state .";
|
||||
final static String regionAssertion =
|
||||
"?address <http://www.w3.org/2006/vcard/ns#region> ?region .";
|
||||
|
||||
final static String countryAssertion =
|
||||
"?address <" + countryPred + "> ?country .";
|
||||
|
||||
final static String addrLabelAssertion =
|
||||
"?address <" + label + "> ?addrLabel .";
|
||||
|
||||
final static String addressTypeAssertion =
|
||||
"?address a ?addressType .";
|
||||
"?address <http://www.w3.org/2006/vcard/ns#country> ?country .";
|
||||
|
||||
|
||||
/* Queries for editing an existing entry */
|
||||
|
||||
final static String addrLabelQuery =
|
||||
"SELECT ?existingAddrLabel WHERE { \n" +
|
||||
" ?address <" + label + "> ?existingAddrLabel . \n" +
|
||||
final static String individualVcardQuery =
|
||||
"SELECT ?individualVcard WHERE { \n" +
|
||||
"?person <http://purl.obolibrary.org/obo/ARG_2000028> ?individualVcard . \n" +
|
||||
"}";
|
||||
|
||||
final static String addrLineOneQuery =
|
||||
"SELECT ?existingaddrLineOne WHERE {\n"+
|
||||
"?address <"+ addrLine1Pred +"> ?existingaddrLineOne . }";
|
||||
final static String streetAddressQuery =
|
||||
"SELECT ?existingStreetAddress WHERE {\n"+
|
||||
"?address <http://www.w3.org/2006/vcard/ns#streetAddress> ?existingStreetAddress . }";
|
||||
|
||||
final static String addrLineTwoQuery =
|
||||
"SELECT ?existingaddrLineTwo WHERE {\n"+
|
||||
"?address <"+ addrLine2Pred +"> ?existingaddrLineTwo . }";
|
||||
final static String localityQuery =
|
||||
"SELECT ?existingLocality WHERE {\n"+
|
||||
"?address <http://www.w3.org/2006/vcard/ns#locality> ?existingLocality . }";
|
||||
|
||||
final static String addrLineThreeQuery =
|
||||
"SELECT ?existingaddrLineThree WHERE {\n"+
|
||||
"?address <"+ addrLine3Pred +"> ?existingaddrLineThree . }";
|
||||
|
||||
final static String cityQuery =
|
||||
"SELECT ?existingCity WHERE {\n"+
|
||||
"?address <"+ cityPred +"> ?existingCity . }";
|
||||
|
||||
final static String stateQuery =
|
||||
"SELECT ?existingState WHERE {\n"+
|
||||
"?address <"+ statePred +"> ?existingState . }";
|
||||
final static String regionQuery =
|
||||
"SELECT ?existingRegion WHERE {\n"+
|
||||
"?address <http://www.w3.org/2006/vcard/ns#region> ?existingRegion . }";
|
||||
|
||||
final static String postalCodeQuery =
|
||||
"SELECT ?existingPostalCode WHERE {\n"+
|
||||
"?address <"+ postalCodePred +"> ?existingPostalCode . }";
|
||||
"?address <http://www.w3.org/2006/vcard/ns#postalCode> ?existingPostalCode . }";
|
||||
|
||||
final static String countryQuery =
|
||||
"SELECT ?existingCountry WHERE {\n"+
|
||||
"?address <"+ countryPred +"> ?existingCountry . }";
|
||||
|
||||
final static String addressTypeQuery =
|
||||
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
|
||||
"SELECT ?existingAddressType WHERE { \n" +
|
||||
"?address vitro:mostSpecificType ?existingAddressType . }";
|
||||
"?address <http://www.w3.org/2006/vcard/ns#country> ?existingCountry . }";
|
||||
|
||||
}
|
||||
|
|
|
@ -203,6 +203,7 @@ public class PersonHasPositionHistoryGenerator extends VivoBaseGenerator impleme
|
|||
"?endNode <" + dateTimeValue + "> ?endField-value . \n" +
|
||||
"?endNode <" + dateTimePrecision + "> ?endField-precision . \n";
|
||||
|
||||
// Queries for existing values
|
||||
final static String orgLabelQuery =
|
||||
"SELECT ?existingOrgLabel WHERE { \n" +
|
||||
" ?position <" + positionInOrgPred + "> ?existingOrg . \n" +
|
||||
|
@ -232,7 +233,8 @@ public class PersonHasPositionHistoryGenerator extends VivoBaseGenerator impleme
|
|||
|
||||
final static String existingOrgQuery =
|
||||
"SELECT ?existingOrg WHERE { \n" +
|
||||
" ?position <" + positionInOrgPred + "> ?existingOrg . }";
|
||||
" ?position <" + positionInOrgPred + "> ?existingOrg . \n" +
|
||||
" ?existingOrg a <" + orgClass + "> }";
|
||||
|
||||
final static String orgTypeQuery =
|
||||
"PREFIX rdfs: <" + rdfs + "> \n" +
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
/* $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 javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
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.VTwo.EditConfigurationUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.ChildVClassesOptions;
|
||||
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;
|
||||
|
||||
public class PersonHasTelephoneNumberGenerator extends VivoBaseGenerator implements
|
||||
EditConfigurationGenerator {
|
||||
private Log log = LogFactory.getLog(PersonHasTelephoneNumberGenerator.class);
|
||||
|
||||
@Override
|
||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
|
||||
HttpSession session) throws Exception {
|
||||
|
||||
EditConfigurationVTwo conf = new EditConfigurationVTwo();
|
||||
|
||||
initBasics(conf, vreq);
|
||||
initPropertyParameters(vreq, session, conf);
|
||||
initObjectPropForm(conf, vreq);
|
||||
String phoneUri = getPhoneUri(vreq);
|
||||
|
||||
conf.setTemplate("personHasTelephoneNumber.ftl");
|
||||
|
||||
conf.setVarNameForSubject("person");
|
||||
conf.setVarNameForPredicate("predicate");
|
||||
conf.setVarNameForObject("individualVcard");
|
||||
|
||||
conf.setN3Required( Arrays.asList( n3ForNewPhone ) );
|
||||
conf.setN3Optional( Arrays.asList( telephoneNumberAssertion ) );
|
||||
|
||||
conf.addNewResource("phone", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
conf.addNewResource("individualVcard", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
|
||||
conf.setLiteralsOnForm(Arrays.asList("telephoneNumber" ));
|
||||
|
||||
conf.addSparqlForExistingLiteral("telephoneNumber", telephoneNumberQuery);
|
||||
conf.addSparqlForAdditionalUrisInScope("individualVcard", individualVcardQuery);
|
||||
|
||||
if ( conf.isUpdate() ) {
|
||||
HashMap<String, List<String>> urisInScope = new HashMap<String, List<String>>();
|
||||
urisInScope.put("phone", Arrays.asList(new String[]{phoneUri}));
|
||||
conf.addUrisInScope(urisInScope);
|
||||
}
|
||||
|
||||
conf.addField( new FieldVTwo().
|
||||
setName("telephoneNumber")
|
||||
.setRangeDatatypeUri( XSD.xstring.toString() ).
|
||||
setValidators( list("nonempty") ));
|
||||
|
||||
conf.addValidator(new AntiXssValidation());
|
||||
|
||||
prepare(vreq, conf);
|
||||
return conf;
|
||||
}
|
||||
|
||||
/* N3 assertions */
|
||||
|
||||
final static String n3ForNewPhone =
|
||||
"?person <http://purl.obolibrary.org/obo/ARG_2000028> ?individualVcard . \n" +
|
||||
"?individualVcard a <http://www.w3.org/2006/vcard/ns#Individual> . \n" +
|
||||
"?individualVcard <http://purl.obolibrary.org/obo/ARG_2000029> ?person . \n" +
|
||||
"?individualVcard <http://www.w3.org/2006/vcard/ns#hasTelephone> ?phone . \n" +
|
||||
"?phone a <http://www.w3.org/2006/vcard/ns#Telephone> . " ;
|
||||
|
||||
final static String telephoneNumberAssertion =
|
||||
"?phone <http://www.w3.org/2006/vcard/ns#telephone> ?telephoneNumber .";
|
||||
|
||||
/* Queries for editing an existing entry */
|
||||
|
||||
final static String individualVcardQuery =
|
||||
"SELECT ?existingIndividualVcard WHERE { \n" +
|
||||
"?person <http://purl.obolibrary.org/obo/ARG_2000028> ?existingIndividualVcard . \n" +
|
||||
"}";
|
||||
|
||||
final static String telephoneNumberQuery =
|
||||
"SELECT ?existingTelephoneNumber WHERE {\n"+
|
||||
"?phone <http://www.w3.org/2006/vcard/ns#telephone> ?existingTelephoneNumber . }";
|
||||
|
||||
private String getPhoneUri(VitroRequest vreq) {
|
||||
String phoneUri = vreq.getParameter("phoneUri");
|
||||
|
||||
return phoneUri;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue