diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelper.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelper.java index c64006f31..5d94cde73 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelper.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelper.java @@ -149,12 +149,9 @@ public class PropertyRestrictionPolicyHelper { if (property.getURI() == null) { return RoleLevel.NOBODY; } - String domainURI = (false && property.getDomainVClassURI() == null) - ? OWL.Thing.getURI() : property.getDomainVClassURI(); - String rangeURI = (false && property.getRangeVClassURI() == null) - ? OWL.Thing.getURI() : property.getRangeVClassURI(); RoleLevel roleLevel = getRoleLevelFromMap( - domainURI, property.getURI(), rangeURI, thresholdMap); + property.getDomainVClassURI(), property.getURI(), + property.getRangeVClassURI(), thresholdMap); if (roleLevel == null) { roleLevel = getRoleLevelFromMap( OWL.Thing.getURI(), property.getURI(), OWL.Thing.getURI(), @@ -166,7 +163,8 @@ public class PropertyRestrictionPolicyHelper { private RoleLevel getRoleLevelFromMap(String domainURI, String predicateURI, String rangeURI, - Map>, RoleLevel> map) { + Map>, + RoleLevel> map) { return map.get( new Pair>( domainURI, new Pair( @@ -184,40 +182,42 @@ public class PropertyRestrictionPolicyHelper { com.hp.hpl.jena.rdf.model.Property property = model.getProperty(propertyUri); StmtIterator stmts = model.listStatements((Resource) null, property, (Resource) null); - while (stmts.hasNext()) { - Statement stmt = stmts.next(); - Resource subject = stmt.getSubject(); - RDFNode objectNode = stmt.getObject(); - if ((subject == null) || (!(objectNode instanceof Resource))) { - continue; - } - Resource object = (Resource) objectNode; - RoleLevel role = RoleLevel.getRoleByUri(object.getURI()); - map.put(new Pair>( - OWL.Thing.getURI(), new Pair( - subject.getURI(), OWL.Thing.getURI())), role); - ObjectProperty op = new ObjectProperty(); - op.setURI(subject.getURI()); - List fauxOps = ApplicationConfigurationOntologyUtils - .getAdditionalFauxSubproperties(op, null, model, model); - for (ObjectProperty faux : fauxOps) { - role = null; - if(VitroVocabulary.PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT - .equals(propertyUri)) { - role = faux.getProhibitedFromUpdateBelowRoleLevel(); - } else if (VitroVocabulary.HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT - .equals(propertyUri)) { - role = faux.getHiddenFromDisplayBelowRoleLevel(); - } - if (role != null) { - log.info("Putting D:" + faux.getDomainVClassURI() + " P:" + subject.getURI() + " R:" + faux.getRangeVClassURI() + " ==> L:" + role); - map.put(new Pair>( - faux.getDomainVClassURI(), new Pair( - subject.getURI(), faux.getRangeVClassURI())), role); - } - } + try { + while (stmts.hasNext()) { + Statement stmt = stmts.next(); + Resource subject = stmt.getSubject(); + RDFNode objectNode = stmt.getObject(); + if ((subject == null) || (!(objectNode instanceof Resource))) { + continue; + } + Resource object = (Resource) objectNode; + RoleLevel role = RoleLevel.getRoleByUri(object.getURI()); + map.put(new Pair>( + OWL.Thing.getURI(), new Pair( + subject.getURI(), OWL.Thing.getURI())), role); + } + } finally { + stmts.close(); } - stmts.close(); + List fauxOps = ApplicationConfigurationOntologyUtils + .getAdditionalFauxSubproperties(null, null, model, model); + for (ObjectProperty faux : fauxOps) { + RoleLevel role = null; + if(VitroVocabulary.PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT + .equals(propertyUri)) { + role = faux.getProhibitedFromUpdateBelowRoleLevel(); + } else if (VitroVocabulary.HIDDEN_FROM_DISPLAY_BELOW_ROLE_LEVEL_ANNOT + .equals(propertyUri)) { + role = faux.getHiddenFromDisplayBelowRoleLevel(); + } + if (role != null) { + log.debug("Putting D:" + faux.getDomainVClassURI() + " P:" + faux.getURI() + " R:" + faux.getRangeVClassURI() + " ==> L:" + role); + map.put(new Pair>( + faux.getDomainVClassURI(), new Pair( + faux.getURI(), faux.getRangeVClassURI())), role); + } + } + } finally { model.leaveCriticalSection(); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java index 0079e8737..0f0be8bf4 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java @@ -297,7 +297,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp String propQuery = "PREFIX rdfs: \n" + "PREFIX config: \n" + "PREFIX vitro: \n" + - "SELECT ?range ?label ?group ?customForm ?displayLevel ?updateLevel WHERE { \n" + + "SELECT ?range ?label ?group ?customForm ?displayRank ?displayLevel ?updateLevel WHERE { \n" + " ?context config:configContextFor <" + propertyURI + "> . \n"; if (domainURI != null) { propQuery += " ?context config:qualifiedByDomain <" + domainURI + "> . \n"; @@ -310,6 +310,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp propQuery += " ?context config:hasConfiguration ?configuration . \n" + " OPTIONAL { ?configuration config:propertyGroup ?group } \n" + " OPTIONAL { ?configuration config:displayName ?label } \n" + + " OPTIONAL { ?configuration vitro:displayRankAnnot ?displayRank } \n" + " OPTIONAL { ?configuration vitro:customEntryFormAnnot ?customForm } \n" + " OPTIONAL { ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel } \n" + " OPTIONAL { ?configuration vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel } \n" + @@ -325,6 +326,11 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp if (groupRes != null) { op.setGroupURI(groupRes.getURI()); } + Literal displayRankLit = qsoln.getLiteral("displayRank"); + if(displayRankLit != null) { + op.setDomainDisplayTier( + Integer.parseInt(displayRankLit.getLexicalForm())); + } Resource displayLevelRes = qsoln.getResource("displayLevel"); if (displayLevelRes != null) { op.setHiddenFromDisplayBelowRoleLevel( diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/ApplicationConfigurationOntologyUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/ApplicationConfigurationOntologyUtils.java index 22849fb86..5ad1fcec2 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/ApplicationConfigurationOntologyUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/ApplicationConfigurationOntologyUtils.java @@ -10,6 +10,8 @@ import javax.servlet.ServletContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; @@ -30,6 +32,8 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID; +import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; +import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena; public class ApplicationConfigurationOntologyUtils { @@ -42,16 +46,16 @@ public class ApplicationConfigurationOntologyUtils { return getAdditionalFauxSubpropertiesForList(propList, subject, displayModel, tboxModel); } - public static List getAdditionalFauxSubproperties(ObjectProperty op, + public static List getAdditionalFauxSubproperties(ObjectProperty prop, Individual subject, Model tboxModel, Model union) { List additionalProps = new ArrayList(); - String propQuery = "PREFIX rdfs: \n" + + String queryStr = "PREFIX rdfs: \n" + "PREFIX config: \n" + "PREFIX vitro: \n" + - "SELECT DISTINCT ?range ?domain ?label ?group ?customForm ?displayLevel ?updateLevel WHERE { \n" + + "SELECT DISTINCT ?range ?domain ?label ?group ?customForm ?displayLevel ?updateLevel ?property WHERE { \n" + // " ?p rdfs:subPropertyOf ?property . \n" + " ?context config:configContextFor ?property . \n" + " ?context config:qualifiedBy ?range . \n" + @@ -64,19 +68,30 @@ public class ApplicationConfigurationOntologyUtils { " OPTIONAL { ?configuration vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel } \n" + "}"; - - log.debug("Checking " + op.getURI() + " for additional properties"); - String queryStr = propQuery.replaceAll("\\?property", "<" + op.getURI() + ">"); + if(prop != null) { + log.debug("Checking " + prop.getURI() + " for additional properties"); + queryStr = queryStr.replaceAll("\\?property", "<" + prop.getURI() + ">"); + } log.debug(queryStr); Query q = QueryFactory.create(queryStr); QueryExecution qe = QueryExecutionFactory.create(q, union); try { ResultSet rs = qe.execSelect(); while (rs.hasNext()) { - ObjectProperty newProp = new ObjectProperty(); - newProp.setURI(op.getURI()); QuerySolution qsoln = rs.nextSolution(); log.debug(qsoln); + ObjectProperty op = null; + if (prop == null) { + String opURI = qsoln.getResource("property").getURI(); + OntModel tboxOntModel = ModelFactory.createOntologyModel( + OntModelSpec.OWL_MEM, tboxModel); + WebappDaoFactory wadf = new WebappDaoFactoryJena(tboxOntModel); + op = wadf.getObjectPropertyDao().getObjectPropertyByURI(opURI); + } else { + op = prop; + } + ObjectProperty newProp = new ObjectProperty(); + newProp.setURI(op.getURI()); Resource domainRes = qsoln.getResource("domain"); if(domainRes != null) { if(!appropriateDomain( @@ -85,9 +100,7 @@ public class ApplicationConfigurationOntologyUtils { } else { newProp.setDomainVClassURI(domainRes.getURI()); } - } else { - newProp.setDomainVClassURI(op.getDomainVClassURI()); - } + } Resource rangeRes = qsoln.getResource("range"); if (rangeRes != null) { newProp.setRangeVClassURI(rangeRes.getURI()); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/EditLinkSuppressor.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/EditLinkSuppressor.java index f87635b5e..773d913a5 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/EditLinkSuppressor.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/EditLinkSuppressor.java @@ -63,12 +63,12 @@ public class EditLinkSuppressor { /** * Should we suppress the Add link on this property? */ - public boolean isAddLinkSuppressed(String propertyUri) { - if (propertyUri == null) { + public boolean isAddLinkSuppressed(Property property) { + if (property == null) { log.error("Suppressing the add link on a null property."); return true; } - return suppressAddLinksForThese.contains(propertyUri); + return suppressAddLinksForThese.contains(property.getURI()); } /** diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java index 2edc5a1b3..9392de857 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java @@ -110,7 +110,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel protected void setAddUrl(Property property) { // Is the add link suppressed for this property? - if (new EditLinkSuppressor(vreq).isAddLinkSuppressed(propertyUri)) { + if (new EditLinkSuppressor(vreq).isAddLinkSuppressed(property)) { return; }