Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rsmd compliance #1

Open
wants to merge 3 commits into
base: feature/rsmd-compliance
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
/* $This file is distributed under the terms of the license in LICENSE$ */
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 edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
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.FieldOptions;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode;
import edu.cornell.mannlib.vitro.webapp.utils.generators.EditModeUtils;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.sparql.resultset.ResultSetMem;
import org.apache.jena.vocabulary.RDF;
import org.apache.jena.vocabulary.XSD;

public class AddMaintainershipToPersonGenerator extends VivoBaseGenerator implements
EditConfigurationGenerator {

public AddMaintainershipToPersonGenerator() {
}

@Override
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) throws Exception {

if (EditConfigurationUtils.getObjectUri(vreq) == null) {
return doAddNew(vreq, session);
} else {
return doSkipToSoftware(vreq);
}
}

private EditConfigurationVTwo doSkipToSoftware(VitroRequest vreq) {
Individual maintainershipNode = EditConfigurationUtils.getObjectIndividual(vreq);

//try to get the software
String softwareQueryStr = "SELECT ?obj \n" +
"WHERE { <" + maintainershipNode.getURI() + "> <http://vivoweb.org/ontology/core#relates> ?obj . \n" +
" ?obj a <http://purl.obolibrary.org/obo/ERO_0000071> . } \n";
Query softwareQuery = QueryFactory.create(softwareQueryStr);
QueryExecution qe = QueryExecutionFactory.create(softwareQuery, ModelAccess.on(vreq).getOntModel());
try {
ResultSetMem rs = new ResultSetMem(qe.execSelect());
if (!rs.hasNext()) {
return doBadMaintainershipNoSoftware(vreq);
} else if (rs.size() > 1) {
return doBadMaintainershipMultipleSoftware(vreq);
} else {
//skip to software
RDFNode objNode = rs.next().get("obj");
if (!objNode.isResource() || objNode.isAnon()) {
return doBadMaintainershipNoSoftware(vreq);
}
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
editConfiguration.setSkipToUrl(UrlBuilder.getIndividualProfileUrl(((Resource) objNode).getURI(), vreq));
return editConfiguration;
}
} finally {
qe.close();
}
}

protected EditConfigurationVTwo doAddNew(VitroRequest vreq,
HttpSession session) throws Exception {

EditConfigurationVTwo conf = new EditConfigurationVTwo();

initBasics(conf, vreq);
initPropertyParameters(vreq, session, conf);
initObjectPropForm(conf, vreq);

conf.setTemplate("addMaintainershipToPerson.ftl");

conf.setVarNameForSubject("person");
conf.setVarNameForPredicate("predicate");
conf.setVarNameForObject("maintainership");

conf.setN3Required(Arrays.asList(n3ForNewMaintainership));
conf.setN3Optional(Arrays.asList(n3ForNewSoftwareAssertion,
n3ForExistingSoftwareAssertion));

conf.addNewResource("maintainership", DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("newSoftware", DEFAULT_NS_FOR_NEW_RESOURCE);

conf.setUrisOnform(Arrays.asList("existingSoftware", "softwareType"));
conf.setLiteralsOnForm(Arrays.asList("softwareLabel", "softwareLabelDisplay"));

conf.addSparqlForExistingLiteral("softwareLabel", softwareLabelQuery);

conf.addSparqlForExistingUris("softwareType", softwareTypeQuery);
conf.addSparqlForExistingUris("existingSoftware", existingSoftwareQuery);

conf.addField(new FieldVTwo().
setName("softwareType").
setValidators(list("nonempty")).
setOptions(getSoftwareTypeLiteralOptions(vreq)));

conf.addField(new FieldVTwo().
setName("softwareLabel").
setRangeDatatypeUri(RDF.dtLangString.getURI()).
setValidators(list("datatype:" + RDF.dtLangString.getURI()))
);

conf.addField(new FieldVTwo().
setName("softwareLabelDisplay").
setRangeDatatypeUri(XSD.xstring.toString()));

conf.addValidator(new AntiXssValidation());
addFormSpecificData(conf, vreq);

prepare(vreq, conf);
return conf;
}

/* N3 assertions */

final static String n3ForNewMaintainership =
"@prefix vivo: <" + vivoCore + "> . \n" +
"?person ?predicate ?maintainership . \n" +
"?maintainership a vivo:Maintainership . \n" +
"?maintainership vivo:relates ?person . ";

final static String n3ForNewSoftwareAssertion =
"@prefix vivo: <" + vivoCore + "> . \n" +
"?maintainership vivo:relates ?newSoftware . \n" +
"?newSoftware a ?softwareType . \n" +
"?newSoftware <" + label + "> ?softwareLabel. ";

final static String n3ForExistingSoftwareAssertion =
"@prefix vivo: <" + vivoCore + "> . \n" +
"?maintainership vivo:relates ?existingSoftware . \n" +
"?existingSoftware a ?softwareType . ";

/* Queries for editing an existing entry */

final static String softwareTypeQuery =
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
"PREFIX vivo: <" + vivoCore + "> . \n" +
"PREFIX bibo: <http://purl.org/ontology/bibo/> . \n" +
"SELECT ?softwareType WHERE { \n" +
" ?maintainership vivo:relates ?existingSoftware . \n" +
" ?existingSoftware a <http://purl.obolibrary.org/obo/ERO_0000071> . \n" +
" ?existingSoftware vitro:mostSpecificType ?softwareType . \n" +
"}";

final static String softwareLabelQuery =
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
"PREFIX vivo: <" + vivoCore + "> . \n" +
"PREFIX bibo: <http://purl.org/ontology/bibo/> . \n" +
"SELECT ?softwareLabel WHERE { \n" +
" ?maintainership vivo:relates ?existingSoftware . \n" +
" ?existingSoftware a <http://purl.obolibrary.org/obo/ERO_0000071> . \n" +
" ?existingSoftware <" + label + "> ?softwareLabel . \n" +
"}";

final static String existingSoftwareQuery =
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
"PREFIX vivo: <" + vivoCore + "> . \n" +
"PREFIX bibo: <http://purl.org/ontology/bibo/> . \n" +
"SELECT ?existingSoftware WHERE { \n" +
" ?maintainership vivo:relates ?existingSoftware . \n" +
" ?existingSoftware a <http://purl.obolibrary.org/obo/ERO_0000071> . \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 EditConfigurationVTwo doBadMaintainershipMultipleSoftware(VitroRequest vreq) {
return null;
}

private EditConfigurationVTwo doBadMaintainershipNoSoftware(VitroRequest vreq) {
return null;
}

private FieldOptions getSoftwareTypeLiteralOptions(VitroRequest vreq) throws Exception {
return GeneratorUtil.buildResourceAndLabelFieldOptions(
vreq.getRDFService(), vreq.getWebappDaoFactory(), "",
I18n.bundle(vreq).text("select_type"),
"http://purl.obolibrary.org/obo/ERO_0000071");
}

}
83 changes: 83 additions & 0 deletions home/src/main/resources/rdf/display/firsttime/PropertyConfig.n3
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,22 @@ local:informationResourceInAuthorshipConfig a :ObjectPropertyDisplayConfig ;
vitro:customEntryFormAnnot "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddAuthorsToInformationResourceGenerator"^^<http://www.w3.org/2001/XMLSchema#string> ;
:propertyGroup <http://vivoweb.org/ontology#vitroPropertyGroupoverview> .

local:softwareInAuthorshipContext a :ConfigContext ;
:hasConfiguration local:informationResourceInAuthorshipConfig ;
:configContextFor <http://vivoweb.org/ontology/core#relatedBy> ;
:qualifiedByDomain <http://purl.obolibrary.org/obo/ERO_0000071> ; # Software
:qualifiedBy <http://vivoweb.org/ontology/core#Authorship> .

local:softwareInAuthorshipConfig a :ObjectPropertyDisplayConfig ;
:listViewConfigFile "listViewConfig-informationResourceInAuthorship.xml"^^xsd:string ;
rdfs:label "informationResourceInAuthorship"@en-US;
:displayName "authors" ;
vitro:displayRankAnnot 10;
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:public ;
vitro:prohibitedFromUpdateBelowRoleLevelAnnot role:public ;
vitro:customEntryFormAnnot "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddAuthorsToInformationResourceGenerator"^^<http://www.w3.org/2001/XMLSchema#string> ;
:propertyGroup <http://vivoweb.org/ontology#vitroPropertyGroupoverview> .

local:informationResourceInEditorshipContext a :ConfigContext ;
:hasConfiguration local:informationResourceInEditorshipConfig ;
:configContextFor <http://vivoweb.org/ontology/core#relatedBy> ;
Expand Down Expand Up @@ -680,6 +696,39 @@ local:editorOfConfig a :ObjectPropertyDisplayConfig ;
vitro:customEntryFormAnnot "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddEditorshipToPersonGenerator"^^<http://www.w3.org/2001/XMLSchema#string> ;
:propertyGroup <http://vivoweb.org/ontology#vitroPropertyGroupbibliographic> .

local:softwareInMaintainershipContext a :ConfigContext ;
:hasConfiguration local:softwareInMaintainershipConfig ;
:configContextFor <http://vivoweb.org/ontology/core#relatedBy> ;
:qualifiedByDomain <http://purl.obolibrary.org/obo/ERO_0000071> ; # Software Entity
:qualifiedBy <http://vivoweb.org/ontology/core#Maintainership> .

local:softwareInMaintainershipConfig a :ObjectPropertyDisplayConfig ;
:listViewConfigFile "listViewConfig-softwareInMaintainership.xml"^^xsd:string ;
rdfs:label "softwareInMaintainership"@en-US;
:displayName "maintainers" ;
vitro:displayRankAnnot 12;
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:public ;
vitro:prohibitedFromUpdateBelowRoleLevelAnnot role:public ;
vitro:customEntryFormAnnot "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddMaintainersToSoftwareGenerator"^^<http://www.w3.org/2001/XMLSchema#string> ;
:propertyGroup <http://vivoweb.org/ontology#vitroPropertyGroupoverview> .

local:maintainerOfContext a :ConfigContext ;
:hasConfiguration local:maintainerOfConfig ;
:configContextFor <http://vivoweb.org/ontology/core#relatedBy> ;
:qualifiedByDomain <http://xmlns.com/foaf/0.1/Person> ;
:qualifiedBy <http://vivoweb.org/ontology/core#Maintainership> .

local:maintainerOfConfig a :ObjectPropertyDisplayConfig ;
:listViewConfigFile "listViewConfig-maintainership.xml"^^xsd:string ;
rdfs:label "maintainerOf"@en-US;
:displayName "maintainer of" ;
vitro:displayRankAnnot 21;
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:public ;
vitro:prohibitedFromUpdateBelowRoleLevelAnnot role:public ;
vitro:customEntryFormAnnot "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddMaintainershipToPersonGenerator"^^<http://www.w3.org/2001/XMLSchema#string> ;
:propertyGroup <http://vivoweb.org/ontology#vitroPropertyGroupoutreach> .


local:issuedCredentialContext a :ConfigContext ;
:hasConfiguration local:issuedCredentialConfig ;
:configContextFor <http://vivoweb.org/ontology/core#relatedBy> ;
Expand Down Expand Up @@ -1211,6 +1260,40 @@ local:documentPartOfConfig a :ObjectPropertyDisplayConfig ;
vitro:offerCreateNewOptionAnnot "true"^^xsd:boolean ;
:propertyGroup <http://vivoweb.org/ontology#vitroPropertyGroupoverview> .

local:softwareHasPartContext a :ConfigContext ;
:hasConfiguration local:softwareHasPartConfig ;
:configContextFor <http://purl.obolibrary.org/obo/BFO_0000051> ;
:qualifiedByDomain <http://purl.obolibrary.org/obo/ERO_0000071> ;
:qualifiedBy <http://purl.obolibrary.org/obo/ERO_0000071> .

local:softwareHasPartConfig a :ObjectPropertyDisplayConfig ;
:listViewConfigFile "listViewConfig-fauxPropertyDefault.xml"^^xsd:string ;
rdfs:label "softwareHasPart"@en-US;
:displayName "has software part" ;
vitro:displayRankAnnot 51;
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:public ;
vitro:prohibitedFromUpdateBelowRoleLevelAnnot role:public ;
vitro:selectFromExistingAnnot "true"^^xsd:boolean ;
vitro:offerCreateNewOptionAnnot "true"^^xsd:boolean ;
:propertyGroup <http://vivoweb.org/ontology#vitroPropertyGroupoverview> .

local:softwarePartOfContext a :ConfigContext ;
:hasConfiguration local:softwarePartOfConfig ;
:configContextFor <http://purl.obolibrary.org/obo/BFO_0000050> ;
:qualifiedByDomain <http://purl.obolibrary.org/obo/ERO_0000071> ;
:qualifiedBy <http://purl.obolibrary.org/obo/ERO_0000071> .

local:softwarePartOfConfig a :ObjectPropertyDisplayConfig ;
:listViewConfigFile "listViewConfig-fauxPropertyDefault.xml"^^xsd:string ;
rdfs:label "softwarePartOf"@en-US;
:displayName "part of other software" ;
vitro:displayRankAnnot 52;
vitro:hiddenFromDisplayBelowRoleLevelAnnot role:public ;
vitro:prohibitedFromUpdateBelowRoleLevelAnnot role:public ;
vitro:selectFromExistingAnnot "true"^^xsd:boolean ;
vitro:offerCreateNewOptionAnnot "true"^^xsd:boolean ;
:propertyGroup <http://vivoweb.org/ontology#vitroPropertyGroupoverview> .

local:geographicLocationContainsLocationContext a :ConfigContext ;
:hasConfiguration local:geographicLocationContainsLocationConfig ;
:configContextFor <http://purl.obolibrary.org/obo/BFO_0000051> ;
Expand Down
Loading