display permissions for domain-qualified predicates

This commit is contained in:
brianjlowe 2013-09-04 11:56:17 -04:00
parent e75b424c81
commit e3399d161d
8 changed files with 42 additions and 110 deletions

View file

@ -345,26 +345,26 @@ public class PropertyRestrictionPolicyHelper {
* If display of a predicate is restricted, the user's role must be at least * If display of a predicate is restricted, the user's role must be at least
* as high as the restriction level. * as high as the restriction level.
*/ */
public boolean canDisplayPredicate(Property predicate, RoleLevel userRole) { public boolean canDisplayPredicate(Property predicate, RoleLevel userRole) {
//TODO change if (predicate == null) {
String predicateUri = predicate.getURI(); log.debug("can't display predicate: predicate was null");
if (predicateUri == null) {
log.debug("can't display predicate: predicateUri was null");
return false; return false;
} }
RoleLevel displayThreshold = getThreshold(predicate, displayThresholdMap); RoleLevel displayThreshold = getThreshold(predicate, displayThresholdMap);
if (isAuthorized(userRole, displayThreshold)) { if (isAuthorized(userRole, displayThreshold)) {
log.debug("can display predicate: '" + predicateUri log.debug("can display predicate: '" + predicate.getURI() + "', domain="
+ "', userRole=" + userRole + ", thresholdRole=" + predicate.getDomainVClassURI() + ", range="
+ displayThreshold); + predicate.getRangeVClassURI() + ", userRole="
+ userRole + ", thresholdRole=" + displayThreshold);
return true; return true;
} }
log.debug("can't display predicate: '" + predicateUri + "', userRole=" log.debug("can't display predicate: '" + predicate.getURI() + "', domain="
+ userRole + ", thresholdRole=" + displayThreshold); + predicate.getDomainVClassURI() + ", range="
+ predicate.getRangeVClassURI() + ", userRole="
+ userRole + ", thresholdRole=" + displayThreshold);
return false; return false;
} }

View file

@ -41,8 +41,8 @@ public interface ObjectPropertyStatementDao {
public Map<String, String> getMostSpecificTypesInClassgroupsForIndividual(String subjectUri); public Map<String, String> getMostSpecificTypesInClassgroupsForIndividual(String subjectUri);
List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty( List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(
String subjectUri, String propertyUri, String objectKey, String rangeUri, String subjectUri, String propertyUri, String objectKey, String domainUri,
String queryString, Set<String> constructQueryStrings, String rangeUri, String queryString, Set<String> constructQueryStrings,
String sortDirection); String sortDirection);

View file

@ -86,12 +86,13 @@ class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements Objec
@Override @Override
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty( public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(
String subjectUri, String propertyUri, String objectKey, String rangeUri, String subjectUri, String propertyUri, String objectKey, String domainUri,
String query, Set<String> queryStrings, String sortDirection) { String rangeUri, String query, Set<String> queryStrings, String sortDirection) {
List<Map<String, String>> data = List<Map<String, String>> data =
innerObjectPropertyStatementDao.getObjectPropertyStatementsForIndividualByProperty( innerObjectPropertyStatementDao.getObjectPropertyStatementsForIndividualByProperty(
subjectUri, propertyUri, objectKey, rangeUri, query, queryStrings,sortDirection); subjectUri, propertyUri, objectKey, domainUri, rangeUri, query,
queryStrings,sortDirection);
/* Filter the data /* Filter the data
* *
@ -107,6 +108,7 @@ class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements Objec
ObjectPropertyStatement statement = new ObjectPropertyStatementImpl(subjectUri, propertyUri, objectUri); ObjectPropertyStatement statement = new ObjectPropertyStatementImpl(subjectUri, propertyUri, objectUri);
ObjectProperty op = new ObjectProperty(); ObjectProperty op = new ObjectProperty();
op.setURI(propertyUri); op.setURI(propertyUri);
op.setDomainVClassURI(domainUri);
op.setRangeVClassURI(rangeUri); op.setRangeVClassURI(rangeUri);
statement.setProperty(op); statement.setProperty(op);
stmtsToData.put(statement, map); stmtsToData.put(statement, map);

View file

@ -305,7 +305,9 @@ 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 ?displayRank ?displayLevel ?updateLevel ?editLinkSuppressed ?addLinkSuppressed ?deleteLinkSuppressed WHERE { \n" + "SELECT ?range ?label ?group ?customForm ?displayRank ?displayLevel " +
" ?updateLevel ?editLinkSuppressed ?addLinkSuppressed ?deleteLinkSuppressed \n" +
" 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";
@ -316,6 +318,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
propQuery += " ?context config:qualifiedBy <" + rangeURI + "> . \n"; propQuery += " ?context config:qualifiedBy <" + rangeURI + "> . \n";
}; };
propQuery += " ?context config:hasConfiguration ?configuration . \n" + propQuery += " ?context config:hasConfiguration ?configuration . \n" +
" ?configuration a config:ObjectPropertyDisplayConfig . \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:editLinkSuppressed ?editLinkSuppressed } \n" + " OPTIONAL { ?configuration config:editLinkSuppressed ?editLinkSuppressed } \n" +

View file

@ -270,8 +270,7 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty( public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(
String subjectUri, String subjectUri,
String propertyUri, String propertyUri,
String objectKey, String objectKey, String domainUri, String rangeUri,
String rangeUri,
String queryString, String queryString,
Set<String> constructQueryStrings, Set<String> constructQueryStrings,
String sortDirection) { String sortDirection) {
@ -299,6 +298,9 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
QuerySolutionMap initialBindings = new QuerySolutionMap(); QuerySolutionMap initialBindings = new QuerySolutionMap();
initialBindings.add("subject", ResourceFactory.createResource(subjectUri)); initialBindings.add("subject", ResourceFactory.createResource(subjectUri));
initialBindings.add("property", ResourceFactory.createResource(propertyUri)); initialBindings.add("property", ResourceFactory.createResource(propertyUri));
if (domainUri != null && !domainUri.startsWith(VitroVocabulary.PSEUDO_BNODE_NS)) {
initialBindings.add("subjectType", ResourceFactory.createResource(domainUri));
}
if (rangeUri != null && !rangeUri.startsWith(VitroVocabulary.PSEUDO_BNODE_NS)) { if (rangeUri != null && !rangeUri.startsWith(VitroVocabulary.PSEUDO_BNODE_NS)) {
initialBindings.add("objectType", ResourceFactory.createResource(rangeUri)); initialBindings.add("objectType", ResourceFactory.createResource(rangeUri));
} }

View file

@ -10,7 +10,6 @@ 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.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;
@ -18,21 +17,19 @@ import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.sparql.expr.NodeValue;
import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.RDFS;
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean;
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.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; 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.ObjectPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena; import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
@ -56,21 +53,12 @@ public class ApplicationConfigurationOntologyUtils {
String queryStr = "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 ?displayRank ?displayLevel ?updateLevel ?editLinkSuppressed ?addLinkSuppressed ?deleteLinkSuppressed ?property WHERE { \n" + "SELECT DISTINCT ?range ?domain ?property WHERE { \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" +
" ?context config:hasConfiguration ?configuration . \n" + " ?context config:hasConfiguration ?configuration . \n" +
" ?configuration a config:ObjectPropertyDisplayConfig . \n" +
" OPTIONAL { ?context config:qualifiedByDomain ?domain } \n" + " OPTIONAL { ?context config:qualifiedByDomain ?domain } \n" +
" OPTIONAL { ?configuration config:propertyGroup ?group } \n" +
" OPTIONAL { ?configuration config:displayName ?label } \n" +
" OPTIONAL { ?configuration vitro:displayRankAnnot ?displayRank } \n" +
" OPTIONAL { ?configuration config:editLinkSuppressed ?editLinkSuppressed } \n" +
" OPTIONAL { ?configuration config:addLinkSuppressed ?addLinkSuppressed } \n" +
" OPTIONAL { ?configuration config:deleteLinkSuppressed ?deleteLinkSuppressed } \n" +
" OPTIONAL { ?configuration vitro:customEntryFormAnnot ?customForm } \n" +
" OPTIONAL { ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel } \n" +
" OPTIONAL { ?configuration vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel } \n" +
"}"; "}";
if(prop != null) { if(prop != null) {
@ -80,86 +68,23 @@ public class ApplicationConfigurationOntologyUtils {
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);
WebappDaoFactory wadf = new WebappDaoFactoryJena(
ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, union));
ObjectPropertyDao opDao = wadf.getObjectPropertyDao();
try { try {
ResultSet rs = qe.execSelect(); ResultSet rs = qe.execSelect();
while (rs.hasNext()) { while (rs.hasNext()) {
QuerySolution qsoln = rs.nextSolution(); QuerySolution qsoln = rs.nextSolution();
log.debug(qsoln); log.debug(qsoln);
ObjectProperty op = null; String opURI = (prop != null) ? prop.getURI() : qsoln.getResource(
if (prop == null) { "property").getURI();
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) { String domainURI = (domainRes != null) ? domainRes.getURI() : null;
if(!appropriateDomain( String rangeURI = qsoln.getResource("range").getURI();
domainRes, subject, tboxModel)) { if (appropriateDomain(domainRes, subject, tboxModel)) {
continue; additionalProps.add(opDao.getObjectPropertyByURIs(
} else { opURI, domainURI, rangeURI));
newProp.setDomainVClassURI(domainRes.getURI());
}
}
Resource rangeRes = qsoln.getResource("range");
if (rangeRes != null) {
newProp.setRangeVClassURI(rangeRes.getURI());
} else {
newProp.setRangeVClassURI(op.getRangeVClassURI());
} }
Resource groupRes = qsoln.getResource("group");
if (groupRes != null) {
newProp.setGroupURI(groupRes.getURI());
} else {
newProp.setGroupURI(op.getURI());
}
Literal labelLit = qsoln.getLiteral("label");
if (labelLit != null) {
newProp.setDomainPublic(labelLit.getLexicalForm());
} else {
newProp.setDomainPublic(op.getDomainPublic());
}
Literal customFormLit = qsoln.getLiteral("customForm");
if (customFormLit != null) {
newProp.setCustomEntryForm(customFormLit.getLexicalForm());
} else {
newProp.setCustomEntryForm(op.getCustomEntryForm());
}
Literal displayRankLit = qsoln.getLiteral("displayRank");
if(displayRankLit != null) {
op.setDomainDisplayTier(
Integer.parseInt(displayRankLit.getLexicalForm()));
}
Resource displayLevelRes = qsoln.getResource("displayLevel");
if (displayLevelRes != null) {
newProp.setHiddenFromDisplayBelowRoleLevel(
BaseResourceBean.RoleLevel.getRoleByUri(
displayLevelRes.getURI()));
}
Resource updateLevelRes = qsoln.getResource("updateLevel");
if (updateLevelRes != null) {
newProp.setProhibitedFromUpdateBelowRoleLevel(
BaseResourceBean.RoleLevel.getRoleByUri(
updateLevelRes.getURI()));
}
Literal editLinkSuppressedLit = qsoln.getLiteral("editLinkSuppressed");
if (editLinkSuppressedLit != null ) {
op.setEditLinkSuppressed(editLinkSuppressedLit.getBoolean());
}
Literal addLinkSuppressedLit = qsoln.getLiteral("addLinkSuppressed");
if (addLinkSuppressedLit != null ) {
op.setAddLinkSuppressed(addLinkSuppressedLit.getBoolean());
}
Literal deleteLinkSuppressedLit = qsoln.getLiteral("deleteLinkSuppressed");
if (deleteLinkSuppressedLit != null ) {
op.setDeleteLinkSuppressed(deleteLinkSuppressedLit.getBoolean());
}
additionalProps.add(newProp);
} }
} finally { } finally {
qe.close(); qe.close();
@ -185,7 +110,7 @@ public class ApplicationConfigurationOntologyUtils {
} }
private static boolean appropriateDomain(Resource domainRes, Individual subject, Model tboxModel) { private static boolean appropriateDomain(Resource domainRes, Individual subject, Model tboxModel) {
if (subject == null) { if (subject == null || domainRes == null) {
return true; return true;
} }
for (VClass vclass : subject.getVClasses()) { for (VClass vclass : subject.getVClasses()) {

View file

@ -160,7 +160,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
protected List<Map<String, String>> getStatementData() { protected List<Map<String, String>> getStatementData() {
ObjectPropertyStatementDao opDao = vreq.getWebappDaoFactory().getObjectPropertyStatementDao(); ObjectPropertyStatementDao opDao = vreq.getWebappDaoFactory().getObjectPropertyStatementDao();
return opDao.getObjectPropertyStatementsForIndividualByProperty(subjectUri, propertyUri, objectKey, rangeUri, getSelectQuery(), getConstructQueries(), sortDirection); return opDao.getObjectPropertyStatementsForIndividualByProperty(subjectUri, propertyUri, objectKey, domainUri, rangeUri, getSelectQuery(), getConstructQueries(), sortDirection);
} }
protected abstract boolean isEmpty(); protected abstract boolean isEmpty();

View file

@ -216,7 +216,7 @@ public class ObjectPropertyStatementDaoStub implements
@Override @Override
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty( public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(
String subjectUri, String propertyUri, String objectKey, String rangeUri, String subjectUri, String propertyUri, String objectKey, String domainUri, String rangeUri,
String query, Set<String> constructQueries, String sortDir) { String query, Set<String> constructQueries, String sortDir) {
throw new RuntimeException( throw new RuntimeException(
"ObjectPropertyStatementDaoStub.getObjectPropertyStatementsForIndividualByProperty() not implemented."); "ObjectPropertyStatementDaoStub.getObjectPropertyStatementsForIndividualByProperty() not implemented.");