edit permissions for qualified properties and VIVO-277

This commit is contained in:
brianjlowe 2013-09-03 11:24:05 -04:00
parent abefa1615c
commit 355b9e2070
5 changed files with 74 additions and 55 deletions

View file

@ -149,12 +149,9 @@ public class PropertyRestrictionPolicyHelper {
if (property.getURI() == null) { if (property.getURI() == null) {
return RoleLevel.NOBODY; 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( RoleLevel roleLevel = getRoleLevelFromMap(
domainURI, property.getURI(), rangeURI, thresholdMap); property.getDomainVClassURI(), property.getURI(),
property.getRangeVClassURI(), thresholdMap);
if (roleLevel == null) { if (roleLevel == null) {
roleLevel = getRoleLevelFromMap( roleLevel = getRoleLevelFromMap(
OWL.Thing.getURI(), property.getURI(), OWL.Thing.getURI(), OWL.Thing.getURI(), property.getURI(), OWL.Thing.getURI(),
@ -166,7 +163,8 @@ public class PropertyRestrictionPolicyHelper {
private RoleLevel getRoleLevelFromMap(String domainURI, private RoleLevel getRoleLevelFromMap(String domainURI,
String predicateURI, String predicateURI,
String rangeURI, String rangeURI,
Map<Pair<String, Pair<String,String>>, RoleLevel> map) { Map<Pair<String, Pair<String,String>>,
RoleLevel> map) {
return map.get( return map.get(
new Pair<String, Pair<String,String>>( new Pair<String, Pair<String,String>>(
domainURI, new Pair<String,String>( domainURI, new Pair<String,String>(
@ -184,40 +182,42 @@ public class PropertyRestrictionPolicyHelper {
com.hp.hpl.jena.rdf.model.Property property = model.getProperty(propertyUri); com.hp.hpl.jena.rdf.model.Property property = model.getProperty(propertyUri);
StmtIterator stmts = model.listStatements((Resource) null, StmtIterator stmts = model.listStatements((Resource) null,
property, (Resource) null); property, (Resource) null);
while (stmts.hasNext()) { try {
Statement stmt = stmts.next(); while (stmts.hasNext()) {
Resource subject = stmt.getSubject(); Statement stmt = stmts.next();
RDFNode objectNode = stmt.getObject(); Resource subject = stmt.getSubject();
if ((subject == null) || (!(objectNode instanceof Resource))) { RDFNode objectNode = stmt.getObject();
continue; if ((subject == null) || (!(objectNode instanceof Resource))) {
} continue;
Resource object = (Resource) objectNode; }
RoleLevel role = RoleLevel.getRoleByUri(object.getURI()); Resource object = (Resource) objectNode;
map.put(new Pair<String,Pair<String,String>>( RoleLevel role = RoleLevel.getRoleByUri(object.getURI());
OWL.Thing.getURI(), new Pair<String,String>( map.put(new Pair<String,Pair<String,String>>(
subject.getURI(), OWL.Thing.getURI())), role); OWL.Thing.getURI(), new Pair<String,String>(
ObjectProperty op = new ObjectProperty(); subject.getURI(), OWL.Thing.getURI())), role);
op.setURI(subject.getURI()); }
List<ObjectProperty> fauxOps = ApplicationConfigurationOntologyUtils } finally {
.getAdditionalFauxSubproperties(op, null, model, model); stmts.close();
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<String,Pair<String,String>>(
faux.getDomainVClassURI(), new Pair<String,String>(
subject.getURI(), faux.getRangeVClassURI())), role);
}
}
} }
stmts.close(); List<ObjectProperty> 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<String,Pair<String,String>>(
faux.getDomainVClassURI(), new Pair<String,String>(
faux.getURI(), faux.getRangeVClassURI())), role);
}
}
} finally { } finally {
model.leaveCriticalSection(); model.leaveCriticalSection();
} }

View file

@ -297,7 +297,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
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" +
"PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n" + "PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \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"; " ?context config:configContextFor <" + propertyURI + "> . \n";
if (domainURI != null) { if (domainURI != null) {
propQuery += " ?context config:qualifiedByDomain <" + domainURI + "> . \n"; propQuery += " ?context config:qualifiedByDomain <" + domainURI + "> . \n";
@ -310,6 +310,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
propQuery += " ?context config:hasConfiguration ?configuration . \n" + propQuery += " ?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 vitro:displayRankAnnot ?displayRank } \n" +
" OPTIONAL { ?configuration vitro:customEntryFormAnnot ?customForm } \n" + " OPTIONAL { ?configuration vitro:customEntryFormAnnot ?customForm } \n" +
" OPTIONAL { ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel } \n" + " OPTIONAL { ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel } \n" +
" OPTIONAL { ?configuration vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel } \n" + " OPTIONAL { ?configuration vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel } \n" +
@ -325,6 +326,11 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
if (groupRes != null) { if (groupRes != null) {
op.setGroupURI(groupRes.getURI()); op.setGroupURI(groupRes.getURI());
} }
Literal displayRankLit = qsoln.getLiteral("displayRank");
if(displayRankLit != null) {
op.setDomainDisplayTier(
Integer.parseInt(displayRankLit.getLexicalForm()));
}
Resource displayLevelRes = qsoln.getResource("displayLevel"); Resource displayLevelRes = qsoln.getResource("displayLevel");
if (displayLevelRes != null) { if (displayLevelRes != null) {
op.setHiddenFromDisplayBelowRoleLevel( op.setHiddenFromDisplayBelowRoleLevel(

View file

@ -10,6 +10,8 @@ import javax.servlet.ServletContext;
import org.apache.commons.logging.Log; 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.OntModelSpec;
import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory; 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.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID; 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 { public class ApplicationConfigurationOntologyUtils {
@ -42,16 +46,16 @@ public class ApplicationConfigurationOntologyUtils {
return getAdditionalFauxSubpropertiesForList(propList, subject, displayModel, tboxModel); return getAdditionalFauxSubpropertiesForList(propList, subject, displayModel, tboxModel);
} }
public static List<ObjectProperty> getAdditionalFauxSubproperties(ObjectProperty op, public static List<ObjectProperty> getAdditionalFauxSubproperties(ObjectProperty prop,
Individual subject, Individual subject,
Model tboxModel, Model tboxModel,
Model union) { Model union) {
List<ObjectProperty> additionalProps = new ArrayList<ObjectProperty>(); List<ObjectProperty> additionalProps = new ArrayList<ObjectProperty>();
String propQuery = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + String queryStr = "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" +
"PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n" + "PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \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" + // " ?p rdfs:subPropertyOf ?property . \n" +
" ?context config:configContextFor ?property . \n" + " ?context config:configContextFor ?property . \n" +
" ?context config:qualifiedBy ?range . \n" + " ?context config:qualifiedBy ?range . \n" +
@ -64,19 +68,30 @@ public class ApplicationConfigurationOntologyUtils {
" OPTIONAL { ?configuration vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel } \n" + " OPTIONAL { ?configuration vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel } \n" +
"}"; "}";
if(prop != null) {
log.debug("Checking " + op.getURI() + " for additional properties"); log.debug("Checking " + prop.getURI() + " for additional properties");
String queryStr = propQuery.replaceAll("\\?property", "<" + op.getURI() + ">"); queryStr = queryStr.replaceAll("\\?property", "<" + prop.getURI() + ">");
}
log.debug(queryStr); log.debug(queryStr);
Query q = QueryFactory.create(queryStr); Query q = QueryFactory.create(queryStr);
QueryExecution qe = QueryExecutionFactory.create(q, union); QueryExecution qe = QueryExecutionFactory.create(q, union);
try { try {
ResultSet rs = qe.execSelect(); ResultSet rs = qe.execSelect();
while (rs.hasNext()) { while (rs.hasNext()) {
ObjectProperty newProp = new ObjectProperty();
newProp.setURI(op.getURI());
QuerySolution qsoln = rs.nextSolution(); QuerySolution qsoln = rs.nextSolution();
log.debug(qsoln); 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"); Resource domainRes = qsoln.getResource("domain");
if(domainRes != null) { if(domainRes != null) {
if(!appropriateDomain( if(!appropriateDomain(
@ -85,9 +100,7 @@ public class ApplicationConfigurationOntologyUtils {
} else { } else {
newProp.setDomainVClassURI(domainRes.getURI()); newProp.setDomainVClassURI(domainRes.getURI());
} }
} else { }
newProp.setDomainVClassURI(op.getDomainVClassURI());
}
Resource rangeRes = qsoln.getResource("range"); Resource rangeRes = qsoln.getResource("range");
if (rangeRes != null) { if (rangeRes != null) {
newProp.setRangeVClassURI(rangeRes.getURI()); newProp.setRangeVClassURI(rangeRes.getURI());

View file

@ -63,12 +63,12 @@ public class EditLinkSuppressor {
/** /**
* Should we suppress the Add link on this property? * Should we suppress the Add link on this property?
*/ */
public boolean isAddLinkSuppressed(String propertyUri) { public boolean isAddLinkSuppressed(Property property) {
if (propertyUri == null) { if (property == null) {
log.error("Suppressing the add link on a null property."); log.error("Suppressing the add link on a null property.");
return true; return true;
} }
return suppressAddLinksForThese.contains(propertyUri); return suppressAddLinksForThese.contains(property.getURI());
} }
/** /**

View file

@ -110,7 +110,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
protected void setAddUrl(Property property) { protected void setAddUrl(Property property) {
// Is the add link suppressed for this property? // Is the add link suppressed for this property?
if (new EditLinkSuppressor(vreq).isAddLinkSuppressed(propertyUri)) { if (new EditLinkSuppressor(vreq).isAddLinkSuppressed(property)) {
return; return;
} }