work on VIVO-60 application ontology code for class/property combination configuration
This commit is contained in:
parent
3ce6a224a3
commit
b26922242a
14 changed files with 195 additions and 58 deletions
|
@ -8,6 +8,7 @@ import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.beans.EditProcessObject;
|
import edu.cornell.mannlib.vedit.beans.EditProcessObject;
|
||||||
import edu.cornell.mannlib.vedit.listener.ChangeListener;
|
import edu.cornell.mannlib.vedit.listener.ChangeListener;
|
||||||
|
@ -92,8 +93,9 @@ public class PropertyRestrictionListener implements ChangeListener {
|
||||||
|
|
||||||
private void createAndSetBean() {
|
private void createAndSetBean() {
|
||||||
OntModel model = ModelAccess.on(ctx).getJenaOntModel();
|
OntModel model = ModelAccess.on(ctx).getJenaOntModel();
|
||||||
|
Model displayModel = ModelAccess.on(ctx).getDisplayModel();
|
||||||
PropertyRestrictionPolicyHelper bean = PropertyRestrictionPolicyHelper
|
PropertyRestrictionPolicyHelper bean = PropertyRestrictionPolicyHelper
|
||||||
.createBean(model);
|
.createBean(model, displayModel);
|
||||||
PropertyRestrictionPolicyHelper.setBean(ctx, bean);
|
PropertyRestrictionPolicyHelper.setBean(ctx, bean);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,13 @@ import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
import com.hp.hpl.jena.query.Query;
|
||||||
|
import com.hp.hpl.jena.query.QueryExecution;
|
||||||
|
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||||
|
import com.hp.hpl.jena.query.QueryFactory;
|
||||||
|
import com.hp.hpl.jena.query.QuerySolution;
|
||||||
|
import com.hp.hpl.jena.query.ResultSet;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.Property;
|
import com.hp.hpl.jena.rdf.model.Property;
|
||||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
import com.hp.hpl.jena.rdf.model.Resource;
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
@ -97,7 +104,10 @@ public class PropertyRestrictionPolicyHelper {
|
||||||
* Initialize the bean with the standard prohibitions and exceptions, and
|
* Initialize the bean with the standard prohibitions and exceptions, and
|
||||||
* with the thresholds obtained from the model.
|
* with the thresholds obtained from the model.
|
||||||
*/
|
*/
|
||||||
public static PropertyRestrictionPolicyHelper createBean(OntModel model) {
|
public static PropertyRestrictionPolicyHelper createBean(OntModel model,
|
||||||
|
Model displayModel) {
|
||||||
|
|
||||||
|
|
||||||
Map<String, RoleLevel> displayThresholdMap = new HashMap<String, RoleLevel>();
|
Map<String, RoleLevel> displayThresholdMap = new HashMap<String, RoleLevel>();
|
||||||
Map<String, RoleLevel> modifyThresholdMap = new HashMap<String, RoleLevel>();
|
Map<String, RoleLevel> modifyThresholdMap = new HashMap<String, RoleLevel>();
|
||||||
|
|
||||||
|
@ -112,7 +122,7 @@ public class PropertyRestrictionPolicyHelper {
|
||||||
|
|
||||||
PropertyRestrictionPolicyHelper bean = new PropertyRestrictionPolicyHelper(
|
PropertyRestrictionPolicyHelper bean = new PropertyRestrictionPolicyHelper(
|
||||||
PROHIBITED_NAMESPACES, PERMITTED_EXCEPTIONS,
|
PROHIBITED_NAMESPACES, PERMITTED_EXCEPTIONS,
|
||||||
displayThresholdMap, modifyThresholdMap);
|
displayThresholdMap, modifyThresholdMap, displayModel);
|
||||||
|
|
||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
|
@ -173,6 +183,8 @@ public class PropertyRestrictionPolicyHelper {
|
||||||
*/
|
*/
|
||||||
private final Map<String, RoleLevel> modifyThresholdMap;
|
private final Map<String, RoleLevel> modifyThresholdMap;
|
||||||
|
|
||||||
|
private final Model displayModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store unmodifiable versions of the inputs.
|
* Store unmodifiable versions of the inputs.
|
||||||
*
|
*
|
||||||
|
@ -183,11 +195,13 @@ public class PropertyRestrictionPolicyHelper {
|
||||||
Collection<String> modifyProhibitedNamespaces,
|
Collection<String> modifyProhibitedNamespaces,
|
||||||
Collection<String> modifyExceptionsAllowedUris,
|
Collection<String> modifyExceptionsAllowedUris,
|
||||||
Map<String, RoleLevel> displayThresholdMap,
|
Map<String, RoleLevel> displayThresholdMap,
|
||||||
Map<String, RoleLevel> modifyThresholdMap) {
|
Map<String, RoleLevel> modifyThresholdMap,
|
||||||
|
Model displayModel) {
|
||||||
this.modifyProhibitedNamespaces = unmodifiable(modifyProhibitedNamespaces);
|
this.modifyProhibitedNamespaces = unmodifiable(modifyProhibitedNamespaces);
|
||||||
this.modifyExceptionsAllowedUris = unmodifiable(modifyExceptionsAllowedUris);
|
this.modifyExceptionsAllowedUris = unmodifiable(modifyExceptionsAllowedUris);
|
||||||
this.displayThresholdMap = unmodifiable(displayThresholdMap);
|
this.displayThresholdMap = unmodifiable(displayThresholdMap);
|
||||||
this.modifyThresholdMap = unmodifiable(modifyThresholdMap);
|
this.modifyThresholdMap = unmodifiable(modifyThresholdMap);
|
||||||
|
this.displayModel = displayModel;
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("prohibited: " + this.modifyProhibitedNamespaces);
|
log.debug("prohibited: " + this.modifyProhibitedNamespaces);
|
||||||
|
@ -272,9 +286,18 @@ public class PropertyRestrictionPolicyHelper {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO insert combo logic here
|
RoleLevel displayThreshold = RoleLevel.NOBODY;
|
||||||
|
if (rangeUri == null) {
|
||||||
|
displayThreshold = displayThresholdMap.get(predicateUri);
|
||||||
|
} else {
|
||||||
|
log.debug("Getting display threshold for " + predicateUri + " " + rangeUri);
|
||||||
|
displayThreshold = getDisplayThreshold(predicateUri, rangeUri);
|
||||||
|
if (displayThreshold == null) {
|
||||||
|
displayThreshold = displayThresholdMap.get(predicateUri);
|
||||||
|
}
|
||||||
|
log.debug(displayThreshold);
|
||||||
|
}
|
||||||
|
|
||||||
RoleLevel displayThreshold = displayThresholdMap.get(predicateUri);
|
|
||||||
if (isAuthorized(userRole, displayThreshold)) {
|
if (isAuthorized(userRole, displayThreshold)) {
|
||||||
log.debug("can display predicate: '" + predicateUri
|
log.debug("can display predicate: '" + predicateUri
|
||||||
+ "', userRole=" + userRole + ", thresholdRole="
|
+ "', userRole=" + userRole + ", thresholdRole="
|
||||||
|
@ -287,6 +310,44 @@ public class PropertyRestrictionPolicyHelper {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the role level threshold for displaying a predicate with a particular
|
||||||
|
* object class
|
||||||
|
* @param predicateUri
|
||||||
|
* @param rangeUri
|
||||||
|
* @return RoleLevel threshold
|
||||||
|
*/
|
||||||
|
private RoleLevel getDisplayThreshold(String predicateUri, String rangeUri) {
|
||||||
|
String query = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" +
|
||||||
|
"PREFIX config: <http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationConfiguration#> \n" +
|
||||||
|
"PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n" +
|
||||||
|
"SELECT ?level WHERE { \n" +
|
||||||
|
// " ?p rdfs:subPropertyOf ?property . \n" +
|
||||||
|
" ?context config:configContextFor ?p . \n" +
|
||||||
|
" ?context config:qualifiedBy ?range . \n" +
|
||||||
|
" ?context config:hasConfiguration ?configuration . \n" +
|
||||||
|
" ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?level \n" +
|
||||||
|
"}";
|
||||||
|
Query q = QueryFactory.create(query);
|
||||||
|
QueryExecution qe = QueryExecutionFactory.create(q, displayModel);
|
||||||
|
try {
|
||||||
|
ResultSet rs = qe.execSelect();
|
||||||
|
if (!rs.hasNext()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
while(rs.hasNext()) {
|
||||||
|
QuerySolution qsoln = rs.nextSolution();
|
||||||
|
Resource levelRes = qsoln.getResource("level");
|
||||||
|
if (levelRes != null) {
|
||||||
|
return RoleLevel.getRoleByUri(levelRes.getURI());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
qe.close();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A predicate cannot be modified if its namespace is in the prohibited list
|
* A predicate cannot be modified if its namespace is in the prohibited list
|
||||||
* (some exceptions are allowed).
|
* (some exceptions are allowed).
|
||||||
|
@ -356,9 +417,14 @@ public class PropertyRestrictionPolicyHelper {
|
||||||
throw new NullPointerException(
|
throw new NullPointerException(
|
||||||
"jenaOntModel has not been initialized.");
|
"jenaOntModel has not been initialized.");
|
||||||
}
|
}
|
||||||
|
Model displayModel = ModelAccess.on(ctx).getDisplayModel();
|
||||||
|
if (displayModel == null) {
|
||||||
|
throw new NullPointerException(
|
||||||
|
"display model has not been initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
PropertyRestrictionPolicyHelper bean = PropertyRestrictionPolicyHelper
|
PropertyRestrictionPolicyHelper bean = PropertyRestrictionPolicyHelper
|
||||||
.createBean(model);
|
.createBean(model, displayModel);
|
||||||
PropertyRestrictionPolicyHelper.setBean(ctx, bean);
|
PropertyRestrictionPolicyHelper.setBean(ctx, bean);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ss.fatal(this, "could not set up PropertyRestrictionPolicyHelper", e);
|
ss.fatal(this, "could not set up PropertyRestrictionPolicyHelper", e);
|
||||||
|
|
|
@ -15,6 +15,8 @@ import java.util.Map;
|
||||||
|
|
||||||
import net.sf.jga.algorithms.Filter;
|
import net.sf.jga.algorithms.Filter;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
@ -29,7 +31,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Individual object that will delegate to an inner Individual
|
* A Individual object that will delegate to an inner Individual
|
||||||
|
@ -43,6 +44,8 @@ public class IndividualFiltering implements Individual {
|
||||||
private final Individual _innerIndividual;
|
private final Individual _innerIndividual;
|
||||||
private final VitroFilters _filters;
|
private final VitroFilters _filters;
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(IndividualFiltering.class);
|
||||||
|
|
||||||
public IndividualFiltering(Individual individual, VitroFilters filters) {
|
public IndividualFiltering(Individual individual, VitroFilters filters) {
|
||||||
super();
|
super();
|
||||||
this._innerIndividual = individual;
|
this._innerIndividual = individual;
|
||||||
|
@ -143,10 +146,18 @@ public class IndividualFiltering implements Individual {
|
||||||
// I'd rather filter on the actual ObjectPropertyStatements here, but
|
// I'd rather filter on the actual ObjectPropertyStatements here, but
|
||||||
// Individual.getPopulatedObjectPropertyList doesn't actually populate
|
// Individual.getPopulatedObjectPropertyList doesn't actually populate
|
||||||
// the ObjectProperty with statements. - jblake
|
// the ObjectProperty with statements. - jblake
|
||||||
|
|
||||||
|
// bjl23: disabling this filtering because the individual statements are
|
||||||
|
// filtered later, and we need to allow for the possibility that a particular
|
||||||
|
// predicate + range class combination is allowed even if the predicate is
|
||||||
|
// hidden on its own.
|
||||||
|
|
||||||
|
// Will revisit filtering at this level if it turns out to be truly necessary.
|
||||||
|
|
||||||
List<ObjectProperty> outOProps = new ArrayList<ObjectProperty>();
|
List<ObjectProperty> outOProps = new ArrayList<ObjectProperty>();
|
||||||
List<ObjectProperty> oProps = _innerIndividual.getPopulatedObjectPropertyList();
|
List<ObjectProperty> oProps = _innerIndividual.getPopulatedObjectPropertyList();
|
||||||
for (ObjectProperty op: oProps) {
|
for (ObjectProperty op: oProps) {
|
||||||
if (_filters.getObjectPropertyStatementFilter().fn(
|
if (true || _filters.getObjectPropertyStatementFilter().fn(
|
||||||
new ObjectPropertyStatementImpl(this._innerIndividual.getURI(), op.getURI(), SOME_LITERAL))) {
|
new ObjectPropertyStatementImpl(this._innerIndividual.getURI(), op.getURI(), SOME_LITERAL))) {
|
||||||
outOProps.add(op);
|
outOProps.add(op);
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,12 +232,6 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String stripItalics(String in) {
|
|
||||||
String out = in.replaceAll("\\<i\\>","");
|
|
||||||
out = out.replaceAll("\\<\\/i\\>","");
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List getAllObjectProperties() {
|
public List getAllObjectProperties() {
|
||||||
getOntModel().enterCriticalSection(Lock.READ);
|
getOntModel().enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
|
@ -800,7 +794,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
||||||
PREFIXES + "\n" +
|
PREFIXES + "\n" +
|
||||||
"SELECT DISTINCT ?property WHERE { \n" +
|
"SELECT DISTINCT ?property WHERE { \n" +
|
||||||
" ?subject ?property ?object . \n" +
|
" ?subject ?property ?object . \n" +
|
||||||
" ?property a owl:ObjectProperty . \n" +
|
// " ?property a owl:ObjectProperty . \n" +
|
||||||
" FILTER ( \n" +
|
" FILTER ( \n" +
|
||||||
" isURI(?object) && \n" +
|
" isURI(?object) && \n" +
|
||||||
PROPERTY_FILTERS + "\n" +
|
PROPERTY_FILTERS + "\n" +
|
||||||
|
@ -846,9 +840,17 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static final String LIST_VIEW_CONFIG_FILE_QUERY_STRING =
|
protected static final String LIST_VIEW_CONFIG_FILE_QUERY_STRING =
|
||||||
"PREFIX display: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#>" +
|
"PREFIX display: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#> \n" +
|
||||||
"SELECT ?property ?filename WHERE { \n" +
|
"PREFIX config: <http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationConfiguration#> \n" +
|
||||||
" ?property display:listViewConfigFile ?filename . \n" +
|
"SELECT ?property ?range ?filename WHERE { \n" +
|
||||||
|
" { ?property display:listViewConfigFile ?filename \n" +
|
||||||
|
" } UNION { \n" +
|
||||||
|
" ?lv config:listViewConfigFile ?filename . \n " +
|
||||||
|
" ?configuration config:hasListView ?lv . " +
|
||||||
|
" ?context config:hasConfiguration ?configuration . \n" +
|
||||||
|
" ?context config:configContextFor ?property . \n" +
|
||||||
|
" ?context config:qualifiedBy ?range . \n" +
|
||||||
|
" } \n" +
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
protected static Query listViewConfigFileQuery = null;
|
protected static Query listViewConfigFileQuery = null;
|
||||||
|
@ -879,6 +881,10 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
||||||
while (results.hasNext()) {
|
while (results.hasNext()) {
|
||||||
QuerySolution soln = results.next();
|
QuerySolution soln = results.next();
|
||||||
String propertyUri = soln.getResource("property").getURI();
|
String propertyUri = soln.getResource("property").getURI();
|
||||||
|
RDFNode rangeNode = soln.get("range");
|
||||||
|
String rangeUri = (rangeNode != null)
|
||||||
|
? ((Resource) rangeNode).getURI()
|
||||||
|
: OWL.Thing.getURI();
|
||||||
ObjectProperty prop = getObjectPropertyByURI(propertyUri);
|
ObjectProperty prop = getObjectPropertyByURI(propertyUri);
|
||||||
if (prop == null) {
|
if (prop == null) {
|
||||||
//This is a warning only if this property is the one for which we're searching
|
//This is a warning only if this property is the one for which we're searching
|
||||||
|
@ -889,7 +895,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String filename = soln.getLiteral("filename").getLexicalForm();
|
String filename = soln.getLiteral("filename").getLexicalForm();
|
||||||
customListViewConfigFileMap.put(new Pair<ObjectProperty, String>(prop, OWL.Thing.getURI()), filename);
|
customListViewConfigFileMap.put(new Pair<ObjectProperty, String>(prop, rangeUri), filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qexec.close();
|
qexec.close();
|
||||||
|
|
|
@ -53,6 +53,10 @@ public class EditConfigurationUtils {
|
||||||
return vreq.getParameter("objectUri");
|
return vreq.getParameter("objectUri");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getRangeUri(VitroRequest vreq) {
|
||||||
|
return vreq.getParameter("rangeUri");
|
||||||
|
}
|
||||||
|
|
||||||
//get individual
|
//get individual
|
||||||
|
|
||||||
public static Individual getSubjectIndividual(VitroRequest vreq) {
|
public static Individual getSubjectIndividual(VitroRequest vreq) {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields;
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields;
|
||||||
|
|
||||||
import java.text.Collator;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -15,22 +14,25 @@ import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
|
||||||
public class IndividualsViaObjectPropetyOptions implements FieldOptions {
|
public class IndividualsViaObjectPropetyOptions implements FieldOptions {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(IndividualsViaObjectPropetyOptions.class);
|
||||||
|
|
||||||
private static final String LEFT_BLANK = "";
|
private static final String LEFT_BLANK = "";
|
||||||
private String subjectUri;
|
private String subjectUri;
|
||||||
private String predicateUri;
|
private String predicateUri;
|
||||||
|
private String rangeUri;
|
||||||
private String objectUri;
|
private String objectUri;
|
||||||
|
|
||||||
private String defaultOptionLabel;
|
private String defaultOptionLabel;
|
||||||
|
|
||||||
public IndividualsViaObjectPropetyOptions(String subjectUri,
|
public IndividualsViaObjectPropetyOptions(String subjectUri,
|
||||||
String predicateUri, String objectUri) throws Exception {
|
String predicateUri, String rangeUri, String objectUri) throws Exception {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
if (subjectUri == null || subjectUri.equals("")) {
|
if (subjectUri == null || subjectUri.equals("")) {
|
||||||
|
@ -42,9 +44,15 @@ public class IndividualsViaObjectPropetyOptions implements FieldOptions {
|
||||||
|
|
||||||
this.subjectUri = subjectUri;
|
this.subjectUri = subjectUri;
|
||||||
this.predicateUri = predicateUri;
|
this.predicateUri = predicateUri;
|
||||||
|
this.rangeUri = rangeUri;
|
||||||
this.objectUri = objectUri;
|
this.objectUri = objectUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IndividualsViaObjectPropetyOptions(String subjectUri,
|
||||||
|
String predicateUri, String objectUri) throws Exception {
|
||||||
|
this (subjectUri, predicateUri, null, objectUri);
|
||||||
|
}
|
||||||
|
|
||||||
public IndividualsViaObjectPropetyOptions setDefaultOptionLabel(String label){
|
public IndividualsViaObjectPropetyOptions setDefaultOptionLabel(String label){
|
||||||
this.defaultOptionLabel = label;
|
this.defaultOptionLabel = label;
|
||||||
return this;
|
return this;
|
||||||
|
@ -65,21 +73,9 @@ public class IndividualsViaObjectPropetyOptions implements FieldOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
Individual subject = wDaoFact.getIndividualDao().getIndividualByURI(subjectUri);
|
Individual subject = wDaoFact.getIndividualDao().getIndividualByURI(subjectUri);
|
||||||
ObjectProperty objProp = wDaoFact.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
|
|
||||||
//get all vclasses applicable to the individual subject
|
//get all vclasses applicable to the individual subject
|
||||||
List<VClass> subjectVClasses = subject.getVClasses();
|
HashSet<String> vclassesURIs = getApplicableVClassURIs(subject, wDaoFact);
|
||||||
//using hashset to prevent duplicates
|
|
||||||
HashSet<String> vclassesURIs = new HashSet<String>();
|
|
||||||
//Get the range vclasses applicable for the property and each vclass for the subject
|
|
||||||
for(VClass subjectVClass: subjectVClasses) {
|
|
||||||
List<VClass> vclasses = wDaoFact.getVClassDao().getVClassesForProperty(subjectVClass.getURI(), predicateUri);
|
|
||||||
//add range vclass to hash
|
|
||||||
if(vclasses != null) {
|
|
||||||
for(VClass v: vclasses) {
|
|
||||||
vclassesURIs.add(v.getURI());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vclassesURIs.size() == 0) {
|
if (vclassesURIs.size() == 0) {
|
||||||
return optionsMap;
|
return optionsMap;
|
||||||
|
@ -114,6 +110,33 @@ public class IndividualsViaObjectPropetyOptions implements FieldOptions {
|
||||||
return optionsMap;
|
return optionsMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HashSet<String> getApplicableVClassURIs(Individual subject, WebappDaoFactory wDaoFact) {
|
||||||
|
HashSet<String> vclassesURIs = new HashSet<String>();
|
||||||
|
if (rangeUri != null) {
|
||||||
|
log.debug("individualsViaObjectProperty using rangeUri " + rangeUri);
|
||||||
|
vclassesURIs.add(rangeUri);
|
||||||
|
return vclassesURIs;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("individualsViaObjectProperty not using any rangeUri");
|
||||||
|
|
||||||
|
List<VClass> subjectVClasses = subject.getVClasses();
|
||||||
|
|
||||||
|
//using hashset to prevent duplicates
|
||||||
|
|
||||||
|
//Get the range vclasses applicable for the property and each vclass for the subject
|
||||||
|
for(VClass subjectVClass: subjectVClasses) {
|
||||||
|
List<VClass> vclasses = wDaoFact.getVClassDao().getVClassesForProperty(subjectVClass.getURI(), predicateUri);
|
||||||
|
//add range vclass to hash
|
||||||
|
if(vclasses != null) {
|
||||||
|
for(VClass v: vclasses) {
|
||||||
|
vclassesURIs.add(v.getURI());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return vclassesURIs;
|
||||||
|
}
|
||||||
|
|
||||||
// copied from OptionsForPropertyTag.java in the thought that class may be deprecated
|
// copied from OptionsForPropertyTag.java in the thought that class may be deprecated
|
||||||
private static List<Individual> removeIndividualsAlreadyInRange(List<Individual> individuals,
|
private static List<Individual> removeIndividualsAlreadyInRange(List<Individual> individuals,
|
||||||
|
|
|
@ -100,10 +100,15 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<String> getRangeTypes(VitroRequest vreq) {
|
protected List<String> getRangeTypes(VitroRequest vreq) {
|
||||||
|
WebappDaoFactory wDaoFact = vreq.getWebappDaoFactory();
|
||||||
|
List<String> types = new ArrayList<String>();
|
||||||
Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
|
Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
|
||||||
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
||||||
WebappDaoFactory wDaoFact = vreq.getWebappDaoFactory();
|
String rangeUri = EditConfigurationUtils.getRangeUri(vreq);
|
||||||
List<String> types = new ArrayList<String>();
|
if (rangeUri != null) {
|
||||||
|
types.add(rangeUri);
|
||||||
|
return types;
|
||||||
|
}
|
||||||
//Get all vclasses applicable to subject
|
//Get all vclasses applicable to subject
|
||||||
List<VClass> vClasses = subject.getVClasses();
|
List<VClass> vClasses = subject.getVClasses();
|
||||||
HashSet<String> typesHash = new HashSet<String>();
|
HashSet<String> typesHash = new HashSet<String>();
|
||||||
|
@ -180,7 +185,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
||||||
this.setSparqlQueries(editConfiguration);
|
this.setSparqlQueries(editConfiguration);
|
||||||
|
|
||||||
//set fields
|
//set fields
|
||||||
setFields(editConfiguration, vreq, EditConfigurationUtils.getPredicateUri(vreq));
|
setFields(editConfiguration, vreq, EditConfigurationUtils.getPredicateUri(vreq), EditConfigurationUtils.getRangeUri(vreq));
|
||||||
|
|
||||||
// No need to put in session here b/c put in session within edit request dispatch controller instead
|
// No need to put in session here b/c put in session within edit request dispatch controller instead
|
||||||
//placing in session depends on having edit key which is handled in edit request dispatch controller
|
//placing in session depends on having edit key which is handled in edit request dispatch controller
|
||||||
|
@ -351,6 +356,10 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setFields(EditConfigurationVTwo editConfiguration, VitroRequest vreq, String predicateUri) throws Exception {
|
protected void setFields(EditConfigurationVTwo editConfiguration, VitroRequest vreq, String predicateUri) throws Exception {
|
||||||
|
setFields(editConfiguration, vreq, predicateUri, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setFields(EditConfigurationVTwo editConfiguration, VitroRequest vreq, String predicateUri, String rangeUri) throws Exception {
|
||||||
FieldVTwo field = new FieldVTwo();
|
FieldVTwo field = new FieldVTwo();
|
||||||
field.setName("objectVar");
|
field.setName("objectVar");
|
||||||
|
|
||||||
|
@ -362,6 +371,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
||||||
field.setOptions( new IndividualsViaObjectPropetyOptions(
|
field.setOptions( new IndividualsViaObjectPropetyOptions(
|
||||||
subjectUri,
|
subjectUri,
|
||||||
predicateUri,
|
predicateUri,
|
||||||
|
rangeUri,
|
||||||
objectUri));
|
objectUri));
|
||||||
}else{
|
}else{
|
||||||
field.setOptions(null);
|
field.setOptions(null);
|
||||||
|
|
|
@ -199,6 +199,7 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
String editConfGeneratorName = null;
|
String editConfGeneratorName = null;
|
||||||
|
|
||||||
String predicateUri = getPredicateUri(vreq);
|
String predicateUri = getPredicateUri(vreq);
|
||||||
|
String rangeUri = EditConfigurationUtils.getRangeUri(vreq);
|
||||||
|
|
||||||
// *** handle the case where the form is specified as a request parameter ***
|
// *** handle the case where the form is specified as a request parameter ***
|
||||||
String formParam = getFormParam(vreq);
|
String formParam = getFormParam(vreq);
|
||||||
|
@ -215,7 +216,9 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
// *** check for a predicate URI in the request
|
// *** check for a predicate URI in the request
|
||||||
}else if( predicateUri != null && !predicateUri.isEmpty() ){
|
}else if( predicateUri != null && !predicateUri.isEmpty() ){
|
||||||
Property prop = getProperty( predicateUri, vreq);
|
Property prop = getProperty( predicateUri, vreq);
|
||||||
if( prop != null && prop.getCustomEntryForm() != null ){
|
if (prop != null && rangeUri != null) {
|
||||||
|
// get the custom form out of the application ontology data
|
||||||
|
} else if( prop != null && prop.getCustomEntryForm() != null ){
|
||||||
//there is a custom form, great! let's use it.
|
//there is a custom form, great! let's use it.
|
||||||
editConfGeneratorName = prop.getCustomEntryForm();
|
editConfGeneratorName = prop.getCustomEntryForm();
|
||||||
|
|
||||||
|
|
|
@ -44,14 +44,15 @@ public class ApplicationConfigurationOntologyUtils {
|
||||||
Model union = ModelFactory.createUnion(displayModel, tboxModel);
|
Model union = ModelFactory.createUnion(displayModel, tboxModel);
|
||||||
String propQuery = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" +
|
String propQuery = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" +
|
||||||
"PREFIX config: <http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationConfiguration#> \n" +
|
"PREFIX config: <http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationConfiguration#> \n" +
|
||||||
"SELECT ?range ?label ?listView ?group WHERE { \n" +
|
"PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n" +
|
||||||
|
"SELECT ?range ?label ?group ?customForm WHERE { \n" +
|
||||||
" ?p rdfs:subPropertyOf ?property . \n" +
|
" ?p rdfs:subPropertyOf ?property . \n" +
|
||||||
" ?context config:configContextFor ?p . \n" +
|
" ?context config:configContextFor ?p . \n" +
|
||||||
" ?context config:qualifiedBy ?range . \n" +
|
" ?context config:qualifiedBy ?range . \n" +
|
||||||
" ?context config:hasConfiguration ?configuration . \n" +
|
" ?context config:hasConfiguration ?configuration . \n" +
|
||||||
" OPTIONAL { ?configuration config:propertyGroup ?group } \n" +
|
" OPTIONAL { ?configuration config:propertyGroup ?group } \n" +
|
||||||
" OPTIONAL { ?configuration config:displayName ?label } \n" +
|
" OPTIONAL { ?configuration config:displayName ?label } \n" +
|
||||||
" OPTIONAL { ?configuration config:hasListView ?lv . ?lv config:listViewConfigFile ?listView } \n" +
|
" OPTIONAL { ?configuration vitro:customEntryFormAnnot ?customForm } \n" +
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
for (ObjectProperty op : propList) {
|
for (ObjectProperty op : propList) {
|
||||||
|
@ -85,11 +86,11 @@ public class ApplicationConfigurationOntologyUtils {
|
||||||
} else {
|
} else {
|
||||||
newProp.setDomainPublic(op.getDomainPublic());
|
newProp.setDomainPublic(op.getDomainPublic());
|
||||||
}
|
}
|
||||||
Literal listViewLit = qsoln.getLiteral("listView");
|
Literal customFormLit = qsoln.getLiteral("customForm");
|
||||||
if (listViewLit != null) {
|
if (customFormLit != null) {
|
||||||
// TODO where do we get the list views from?
|
newProp.setCustomEntryForm(customFormLit.getLexicalForm());
|
||||||
} else {
|
} else {
|
||||||
// newProp.set
|
newProp.setCustomEntryForm(op.getCustomEntryForm());
|
||||||
}
|
}
|
||||||
additionalProps.add(newProp);
|
additionalProps.add(newProp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,6 +175,7 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
||||||
|
|
||||||
//Also used above and can be used in object auto complete form
|
//Also used above and can be used in object auto complete form
|
||||||
public String getObjectPropertyNameForDisplay() {
|
public String getObjectPropertyNameForDisplay() {
|
||||||
|
// TODO modify this to get prop/class combo
|
||||||
String propertyTitle = null;
|
String propertyTitle = null;
|
||||||
Individual objectIndividual = EditConfigurationUtils.getObjectIndividual(vreq);
|
Individual objectIndividual = EditConfigurationUtils.getObjectIndividual(vreq);
|
||||||
ObjectProperty prop = EditConfigurationUtils.getObjectProperty(vreq);
|
ObjectProperty prop = EditConfigurationUtils.getObjectProperty(vreq);
|
||||||
|
@ -546,7 +547,6 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
||||||
|
|
||||||
HashMap<String,String> types = new HashMap<String, String>();
|
HashMap<String,String> types = new HashMap<String, String>();
|
||||||
for( VClass vclass : vclasses ){
|
for( VClass vclass : vclasses ){
|
||||||
|
|
||||||
String name = null;
|
String name = null;
|
||||||
if( vclass.getPickListName() != null && vclass.getPickListName().length() > 0){
|
if( vclass.getPickListName() != null && vclass.getPickListName().length() > 0){
|
||||||
name = vclass.getPickListName();
|
name = vclass.getPickListName();
|
||||||
|
|
|
@ -122,6 +122,10 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String rangeUri = (property instanceof ObjectProperty)
|
||||||
|
? ((ObjectProperty) property).getRangeVClassURI()
|
||||||
|
: "data";
|
||||||
|
|
||||||
if (propertyUri.equals(VitroVocabulary.IND_MAIN_IMAGE)) {
|
if (propertyUri.equals(VitroVocabulary.IND_MAIN_IMAGE)) {
|
||||||
addUrl = getImageUploadUrl(subjectUri, "add");
|
addUrl = getImageUploadUrl(subjectUri, "add");
|
||||||
} else {
|
} else {
|
||||||
|
@ -129,6 +133,10 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
"subjectUri", subjectUri,
|
"subjectUri", subjectUri,
|
||||||
"predicateUri", propertyUri);
|
"predicateUri", propertyUri);
|
||||||
|
|
||||||
|
if (rangeUri != null) {
|
||||||
|
params.put("rangeUri", rangeUri);
|
||||||
|
}
|
||||||
|
|
||||||
params.putAll(UrlBuilder.getModelParams(vreq));
|
params.putAll(UrlBuilder.getModelParams(vreq));
|
||||||
|
|
||||||
addUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
addUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
|
||||||
bean = new PropertyRestrictionPolicyHelper(
|
bean = new PropertyRestrictionPolicyHelper(
|
||||||
Arrays.asList(PROHIBITED_NAMESPACES),
|
Arrays.asList(PROHIBITED_NAMESPACES),
|
||||||
Arrays.asList(PERMITTED_EXCEPTIONS), displayLevels,
|
Arrays.asList(PERMITTED_EXCEPTIONS), displayLevels,
|
||||||
modifyLevels);
|
modifyLevels, ModelFactory.createDefaultModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
|
|
@ -8,6 +8,9 @@ import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper;
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
||||||
|
|
||||||
|
@ -57,7 +60,7 @@ public class PropertyRestrictionPolicyHelperStub extends
|
||||||
Map<String, RoleLevel> displayThresholds,
|
Map<String, RoleLevel> displayThresholds,
|
||||||
Map<String, RoleLevel> modifyThresholds) {
|
Map<String, RoleLevel> modifyThresholds) {
|
||||||
super(modifyRestrictedNamespaces, modifyPermittedExceptions,
|
super(modifyRestrictedNamespaces, modifyPermittedExceptions,
|
||||||
displayThresholds, modifyThresholds);
|
displayThresholds, modifyThresholds, ModelFactory.createDefaultModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue