edit permissions for qualified properties and VIVO-277
This commit is contained in:
parent
abefa1615c
commit
355b9e2070
5 changed files with 74 additions and 55 deletions
|
@ -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<Pair<String, Pair<String,String>>, RoleLevel> map) {
|
||||
Map<Pair<String, Pair<String,String>>,
|
||||
RoleLevel> map) {
|
||||
return map.get(
|
||||
new Pair<String, Pair<String,String>>(
|
||||
domainURI, new Pair<String,String>(
|
||||
|
@ -184,6 +182,7 @@ public class PropertyRestrictionPolicyHelper {
|
|||
com.hp.hpl.jena.rdf.model.Property property = model.getProperty(propertyUri);
|
||||
StmtIterator stmts = model.listStatements((Resource) null,
|
||||
property, (Resource) null);
|
||||
try {
|
||||
while (stmts.hasNext()) {
|
||||
Statement stmt = stmts.next();
|
||||
Resource subject = stmt.getSubject();
|
||||
|
@ -196,12 +195,14 @@ public class PropertyRestrictionPolicyHelper {
|
|||
map.put(new Pair<String,Pair<String,String>>(
|
||||
OWL.Thing.getURI(), new Pair<String,String>(
|
||||
subject.getURI(), OWL.Thing.getURI())), role);
|
||||
ObjectProperty op = new ObjectProperty();
|
||||
op.setURI(subject.getURI());
|
||||
}
|
||||
} finally {
|
||||
stmts.close();
|
||||
}
|
||||
List<ObjectProperty> fauxOps = ApplicationConfigurationOntologyUtils
|
||||
.getAdditionalFauxSubproperties(op, null, model, model);
|
||||
.getAdditionalFauxSubproperties(null, null, model, model);
|
||||
for (ObjectProperty faux : fauxOps) {
|
||||
role = null;
|
||||
RoleLevel role = null;
|
||||
if(VitroVocabulary.PROHIBITED_FROM_UPDATE_BELOW_ROLE_LEVEL_ANNOT
|
||||
.equals(propertyUri)) {
|
||||
role = faux.getProhibitedFromUpdateBelowRoleLevel();
|
||||
|
@ -210,14 +211,13 @@ public class PropertyRestrictionPolicyHelper {
|
|||
role = faux.getHiddenFromDisplayBelowRoleLevel();
|
||||
}
|
||||
if (role != null) {
|
||||
log.info("Putting D:" + faux.getDomainVClassURI() + " P:" + subject.getURI() + " R:" + faux.getRangeVClassURI() + " ==> L:" + role);
|
||||
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>(
|
||||
subject.getURI(), faux.getRangeVClassURI())), role);
|
||||
faux.getURI(), faux.getRangeVClassURI())), role);
|
||||
}
|
||||
}
|
||||
}
|
||||
stmts.close();
|
||||
|
||||
} finally {
|
||||
model.leaveCriticalSection();
|
||||
}
|
||||
|
|
|
@ -297,7 +297,7 @@ 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 ?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(
|
||||
|
|
|
@ -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<ObjectProperty> getAdditionalFauxSubproperties(ObjectProperty op,
|
||||
public static List<ObjectProperty> getAdditionalFauxSubproperties(ObjectProperty prop,
|
||||
Individual subject,
|
||||
Model tboxModel,
|
||||
Model union) {
|
||||
|
||||
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 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" +
|
||||
" ?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,8 +100,6 @@ public class ApplicationConfigurationOntologyUtils {
|
|||
} else {
|
||||
newProp.setDomainVClassURI(domainRes.getURI());
|
||||
}
|
||||
} else {
|
||||
newProp.setDomainVClassURI(op.getDomainVClassURI());
|
||||
}
|
||||
Resource rangeRes = qsoln.getResource("range");
|
||||
if (rangeRes != null) {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue