display permissions for domain-qualified predicates
This commit is contained in:
parent
e75b424c81
commit
e3399d161d
8 changed files with 42 additions and 110 deletions
|
@ -346,24 +346,24 @@ public class PropertyRestrictionPolicyHelper {
|
|||
* as high as the restriction level.
|
||||
*/
|
||||
public boolean canDisplayPredicate(Property predicate, RoleLevel userRole) {
|
||||
//TODO change
|
||||
String predicateUri = predicate.getURI();
|
||||
|
||||
if (predicateUri == null) {
|
||||
log.debug("can't display predicate: predicateUri was null");
|
||||
if (predicate == null) {
|
||||
log.debug("can't display predicate: predicate was null");
|
||||
return false;
|
||||
}
|
||||
|
||||
RoleLevel displayThreshold = getThreshold(predicate, displayThresholdMap);
|
||||
|
||||
if (isAuthorized(userRole, displayThreshold)) {
|
||||
log.debug("can display predicate: '" + predicateUri
|
||||
+ "', userRole=" + userRole + ", thresholdRole="
|
||||
+ displayThreshold);
|
||||
log.debug("can display predicate: '" + predicate.getURI() + "', domain="
|
||||
+ predicate.getDomainVClassURI() + ", range="
|
||||
+ predicate.getRangeVClassURI() + ", userRole="
|
||||
+ userRole + ", thresholdRole=" + displayThreshold);
|
||||
return true;
|
||||
}
|
||||
|
||||
log.debug("can't display predicate: '" + predicateUri + "', userRole="
|
||||
log.debug("can't display predicate: '" + predicate.getURI() + "', domain="
|
||||
+ predicate.getDomainVClassURI() + ", range="
|
||||
+ predicate.getRangeVClassURI() + ", userRole="
|
||||
+ userRole + ", thresholdRole=" + displayThreshold);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -41,8 +41,8 @@ public interface ObjectPropertyStatementDao {
|
|||
public Map<String, String> getMostSpecificTypesInClassgroupsForIndividual(String subjectUri);
|
||||
|
||||
List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(
|
||||
String subjectUri, String propertyUri, String objectKey, String rangeUri,
|
||||
String queryString, Set<String> constructQueryStrings,
|
||||
String subjectUri, String propertyUri, String objectKey, String domainUri,
|
||||
String rangeUri, String queryString, Set<String> constructQueryStrings,
|
||||
String sortDirection);
|
||||
|
||||
|
||||
|
|
|
@ -86,12 +86,13 @@ class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements Objec
|
|||
|
||||
@Override
|
||||
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(
|
||||
String subjectUri, String propertyUri, String objectKey, String rangeUri,
|
||||
String query, Set<String> queryStrings, String sortDirection) {
|
||||
String subjectUri, String propertyUri, String objectKey, String domainUri,
|
||||
String rangeUri, String query, Set<String> queryStrings, String sortDirection) {
|
||||
|
||||
List<Map<String, String>> data =
|
||||
innerObjectPropertyStatementDao.getObjectPropertyStatementsForIndividualByProperty(
|
||||
subjectUri, propertyUri, objectKey, rangeUri, query, queryStrings,sortDirection);
|
||||
subjectUri, propertyUri, objectKey, domainUri, rangeUri, query,
|
||||
queryStrings,sortDirection);
|
||||
|
||||
/* Filter the data
|
||||
*
|
||||
|
@ -107,6 +108,7 @@ class ObjectPropertyStatementDaoFiltering extends BaseFiltering implements Objec
|
|||
ObjectPropertyStatement statement = new ObjectPropertyStatementImpl(subjectUri, propertyUri, objectUri);
|
||||
ObjectProperty op = new ObjectProperty();
|
||||
op.setURI(propertyUri);
|
||||
op.setDomainVClassURI(domainUri);
|
||||
op.setRangeVClassURI(rangeUri);
|
||||
statement.setProperty(op);
|
||||
stmtsToData.put(statement, map);
|
||||
|
|
|
@ -305,7 +305,9 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
|||
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 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";
|
||||
if (domainURI != null) {
|
||||
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:hasConfiguration ?configuration . \n" +
|
||||
" ?configuration a config:ObjectPropertyDisplayConfig . \n" +
|
||||
" OPTIONAL { ?configuration config:propertyGroup ?group } \n" +
|
||||
" OPTIONAL { ?configuration config:displayName ?label } \n" +
|
||||
" OPTIONAL { ?configuration config:editLinkSuppressed ?editLinkSuppressed } \n" +
|
||||
|
|
|
@ -270,8 +270,7 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
|
|||
public List<Map<String, String>> getObjectPropertyStatementsForIndividualByProperty(
|
||||
String subjectUri,
|
||||
String propertyUri,
|
||||
String objectKey,
|
||||
String rangeUri,
|
||||
String objectKey, String domainUri, String rangeUri,
|
||||
String queryString,
|
||||
Set<String> constructQueryStrings,
|
||||
String sortDirection) {
|
||||
|
@ -299,6 +298,9 @@ public class ObjectPropertyStatementDaoJena extends JenaBaseDao implements Objec
|
|||
QuerySolutionMap initialBindings = new QuerySolutionMap();
|
||||
initialBindings.add("subject", ResourceFactory.createResource(subjectUri));
|
||||
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)) {
|
||||
initialBindings.add("objectType", ResourceFactory.createResource(rangeUri));
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ 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;
|
||||
|
@ -18,21 +17,19 @@ 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.Literal;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
import com.hp.hpl.jena.sparql.expr.NodeValue;
|
||||
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.ObjectProperty;
|
||||
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.ObjectPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
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" +
|
||||
"PREFIX config: <http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationConfiguration#> \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" +
|
||||
// " ?p rdfs:subPropertyOf ?property . \n" +
|
||||
"SELECT DISTINCT ?range ?domain ?property WHERE { \n" +
|
||||
" ?context config:configContextFor ?property . \n" +
|
||||
" ?context config:qualifiedBy ?range . \n" +
|
||||
" ?context config:hasConfiguration ?configuration . \n" +
|
||||
" ?configuration a config:ObjectPropertyDisplayConfig . \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) {
|
||||
|
@ -80,87 +68,24 @@ public class ApplicationConfigurationOntologyUtils {
|
|||
log.debug(queryStr);
|
||||
Query q = QueryFactory.create(queryStr);
|
||||
QueryExecution qe = QueryExecutionFactory.create(q, union);
|
||||
WebappDaoFactory wadf = new WebappDaoFactoryJena(
|
||||
ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, union));
|
||||
ObjectPropertyDao opDao = wadf.getObjectPropertyDao();
|
||||
try {
|
||||
ResultSet rs = qe.execSelect();
|
||||
while (rs.hasNext()) {
|
||||
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());
|
||||
String opURI = (prop != null) ? prop.getURI() : qsoln.getResource(
|
||||
"property").getURI();
|
||||
Resource domainRes = qsoln.getResource("domain");
|
||||
if(domainRes != null) {
|
||||
if(!appropriateDomain(
|
||||
domainRes, subject, tboxModel)) {
|
||||
continue;
|
||||
} else {
|
||||
newProp.setDomainVClassURI(domainRes.getURI());
|
||||
String domainURI = (domainRes != null) ? domainRes.getURI() : null;
|
||||
String rangeURI = qsoln.getResource("range").getURI();
|
||||
if (appropriateDomain(domainRes, subject, tboxModel)) {
|
||||
additionalProps.add(opDao.getObjectPropertyByURIs(
|
||||
opURI, domainURI, rangeURI));
|
||||
}
|
||||
}
|
||||
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 {
|
||||
qe.close();
|
||||
}
|
||||
|
@ -185,7 +110,7 @@ public class ApplicationConfigurationOntologyUtils {
|
|||
}
|
||||
|
||||
private static boolean appropriateDomain(Resource domainRes, Individual subject, Model tboxModel) {
|
||||
if (subject == null) {
|
||||
if (subject == null || domainRes == null) {
|
||||
return true;
|
||||
}
|
||||
for (VClass vclass : subject.getVClasses()) {
|
||||
|
|
|
@ -160,7 +160,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
|
||||
protected List<Map<String, String>> getStatementData() {
|
||||
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();
|
||||
|
|
|
@ -216,7 +216,7 @@ public class ObjectPropertyStatementDaoStub implements
|
|||
|
||||
@Override
|
||||
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) {
|
||||
throw new RuntimeException(
|
||||
"ObjectPropertyStatementDaoStub.getObjectPropertyStatementsForIndividualByProperty() not implemented.");
|
||||
|
|
Loading…
Add table
Reference in a new issue