VIVO-782 Create PropertyDao.FullPropertyKey class.

Replaces Pair<String,Pair<String, String>> when building maps of Properties and FauxProperties.
This commit is contained in:
Jim Blake 2014-10-27 14:20:22 -04:00
parent 4a2321db41
commit 3b4e2bc012
5 changed files with 215 additions and 135 deletions

View file

@ -28,13 +28,12 @@ import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.rdf.model.impl.Util; import com.hp.hpl.jena.rdf.model.impl.Util;
import com.hp.hpl.jena.sdb.util.Pair;
import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.vocabulary.OWL;
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel; import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.beans.Property; import edu.cornell.mannlib.vitro.webapp.beans.Property;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyDao.FullPropertyKey;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess; import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
@ -111,12 +110,12 @@ public class PropertyRestrictionPolicyHelper {
Model displayModel) { Model displayModel) {
Map<Pair<String, Pair<String,String>>, RoleLevel> displayThresholdMap = Map<FullPropertyKey, RoleLevel> displayThresholdMap =
new HashMap<Pair<String, Pair<String,String>>, RoleLevel>(); new HashMap<FullPropertyKey, RoleLevel>();
Map<Pair<String, Pair<String,String>>, RoleLevel> modifyThresholdMap = Map<FullPropertyKey, RoleLevel> modifyThresholdMap =
new HashMap<Pair<String, Pair<String,String>>, RoleLevel>(); new HashMap<FullPropertyKey, RoleLevel>();
Map<Pair<String, Pair<String,String>>, RoleLevel> publishThresholdMap = Map<FullPropertyKey, RoleLevel> publishThresholdMap =
new HashMap<Pair<String, Pair<String,String>>, RoleLevel>(); new HashMap<FullPropertyKey, RoleLevel>();
OntModel union = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, OntModel union = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
ModelFactory.createUnion(displayModel, model)); ModelFactory.createUnion(displayModel, model));
@ -141,39 +140,24 @@ public class PropertyRestrictionPolicyHelper {
} }
private RoleLevel getThreshold(Property property, private RoleLevel getThreshold(Property property,
Map<Pair<String, Pair<String,String>>, RoleLevel> Map<FullPropertyKey, RoleLevel> thresholdMap) {
thresholdMap) {
if (property.getURI() == null) { if (property.getURI() == null) {
return RoleLevel.NOBODY; return RoleLevel.NOBODY;
} }
RoleLevel roleLevel = getRoleLevelFromMap( RoleLevel roleLevel = thresholdMap.get(new FullPropertyKey(property));
property.getDomainVClassURI(), property.getURI(), if (roleLevel == null) {
property.getRangeVClassURI(), thresholdMap); roleLevel = thresholdMap
if (roleLevel == null) { .get(new FullPropertyKey(property.getURI()));
roleLevel = getRoleLevelFromMap( }
OWL.Thing.getURI(), property.getURI(), OWL.Thing.getURI(),
thresholdMap);
}
return roleLevel; return roleLevel;
} }
private RoleLevel getRoleLevelFromMap(String domainURI,
String predicateURI,
String rangeURI,
Map<Pair<String, Pair<String,String>>,
RoleLevel> map) {
return map.get(
new Pair<String, Pair<String,String>>(
domainURI, new Pair<String,String>(
predicateURI, rangeURI)));
}
/** /**
* Find all the resources that possess this property, and map the resource * Find all the resources that possess this property, and map the resource
* URI to the required RoleLevel. * URI to the required RoleLevel.
*/ */
private static void populateThresholdMap(OntModel model, private static void populateThresholdMap(OntModel model,
Map<Pair<String,Pair<String,String>>, RoleLevel> map, String propertyUri) { Map<FullPropertyKey, RoleLevel> map, String propertyUri) {
model.enterCriticalSection(Lock.READ); model.enterCriticalSection(Lock.READ);
try { try {
com.hp.hpl.jena.rdf.model.Property property = model.getProperty(propertyUri); com.hp.hpl.jena.rdf.model.Property property = model.getProperty(propertyUri);
@ -189,9 +173,7 @@ public class PropertyRestrictionPolicyHelper {
} }
Resource object = (Resource) objectNode; Resource object = (Resource) objectNode;
RoleLevel role = RoleLevel.getRoleByUri(object.getURI()); RoleLevel role = RoleLevel.getRoleByUri(object.getURI());
map.put(new Pair<String,Pair<String,String>>( map.put(new FullPropertyKey(subject.getURI()), role);
OWL.Thing.getURI(), new Pair<String,String>(
subject.getURI(), OWL.Thing.getURI())), role);
} }
} finally { } finally {
stmts.close(); stmts.close();
@ -211,12 +193,9 @@ public class PropertyRestrictionPolicyHelper {
role = faux.getHiddenFromPublishBelowRoleLevel(); role = faux.getHiddenFromPublishBelowRoleLevel();
} }
if (role != null) { if (role != null) {
log.debug("Putting D:" + faux.getDomainVClassURI() + " P:" FullPropertyKey key = new FullPropertyKey(faux);
+ faux.getURI() + " R:" + faux.getRangeVClassURI() map.put(key, role);
+ " ==> L:" + role); log.debug("Putting key: " + key + " ==> L:" + role);
map.put(new Pair<String,Pair<String,String>>(
faux.getDomainVClassURI(), new Pair<String,String>(
faux.getURI(), faux.getRangeVClassURI())), role);
} }
} }
@ -245,19 +224,19 @@ public class PropertyRestrictionPolicyHelper {
* These URIs can be displayed only if the user's role is at least as high * These URIs can be displayed only if the user's role is at least as high
* as the threshold role. * as the threshold role.
*/ */
private final Map<Pair<String, Pair<String,String>>, RoleLevel> displayThresholdMap; private final Map<FullPropertyKey, RoleLevel> displayThresholdMap;
/** /**
* These URIs can be modified only if the user's role is at least as high as * These URIs can be modified only if the user's role is at least as high as
* the threshold role. * the threshold role.
*/ */
private final Map<Pair<String, Pair<String,String>>, RoleLevel> modifyThresholdMap; private final Map<FullPropertyKey, RoleLevel> modifyThresholdMap;
/** /**
* These URIs can be published only if the user's role is at least as high as * These URIs can be published only if the user's role is at least as high as
* the threshold role. * the threshold role.
*/ */
private final Map<Pair<String, Pair<String,String>>, RoleLevel> publishThresholdMap; private final Map<FullPropertyKey, RoleLevel> publishThresholdMap;
/** /**
@ -269,9 +248,9 @@ public class PropertyRestrictionPolicyHelper {
protected PropertyRestrictionPolicyHelper( protected PropertyRestrictionPolicyHelper(
Collection<String> modifyProhibitedNamespaces, Collection<String> modifyProhibitedNamespaces,
Collection<String> modifyExceptionsAllowedUris, Collection<String> modifyExceptionsAllowedUris,
Map<Pair<String, Pair<String,String>>, RoleLevel> displayThresholdMap, Map<FullPropertyKey, RoleLevel> displayThresholdMap,
Map<Pair<String, Pair<String,String>>, RoleLevel> modifyThresholdMap, Map<FullPropertyKey, RoleLevel> modifyThresholdMap,
Map<Pair<String, Pair<String,String>>, RoleLevel> publishThresholdMap) { Map<FullPropertyKey, RoleLevel> publishThresholdMap) {
this.modifyProhibitedNamespaces = unmodifiable(modifyProhibitedNamespaces); this.modifyProhibitedNamespaces = unmodifiable(modifyProhibitedNamespaces);
this.modifyExceptionsAllowedUris = unmodifiable(modifyExceptionsAllowedUris); this.modifyExceptionsAllowedUris = unmodifiable(modifyExceptionsAllowedUris);
this.displayThresholdMap = displayThresholdMap; this.displayThresholdMap = displayThresholdMap;

View file

@ -3,46 +3,140 @@
package edu.cornell.mannlib.vitro.webapp.dao; package edu.cornell.mannlib.vitro.webapp.dao;
import java.util.List; import java.util.List;
import java.util.Objects;
import com.hp.hpl.jena.vocabulary.OWL;
import edu.cornell.mannlib.vitro.webapp.beans.Property; import edu.cornell.mannlib.vitro.webapp.beans.Property;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
public interface PropertyDao { public interface PropertyDao {
void addSuperproperty(Property property, Property superproperty); void addSuperproperty(Property property, Property superproperty);
void addSuperproperty(String propertyURI, String superpropertyURI); void addSuperproperty(String propertyURI, String superpropertyURI);
void removeSuperproperty(Property property, Property superproperty); void removeSuperproperty(Property property, Property superproperty);
void removeSuperproperty(String propertyURI, String superpropertyURI); void removeSuperproperty(String propertyURI, String superpropertyURI);
void addSubproperty(Property property, Property subproperty); void addSubproperty(Property property, Property subproperty);
void addSubproperty(String propertyURI, String subpropertyURI); void addSubproperty(String propertyURI, String subpropertyURI);
void removeSubproperty(Property property, Property subproperty); void removeSubproperty(Property property, Property subproperty);
void removeSubproperty(String propertyURI, String subpropertyURI); void removeSubproperty(String propertyURI, String subpropertyURI);
void addEquivalentProperty(String propertyURI, String equivalentPropertyURI); void addEquivalentProperty(String propertyURI, String equivalentPropertyURI);
void addEquivalentProperty(Property property, Property equivalentProperty); void addEquivalentProperty(Property property, Property equivalentProperty);
void removeEquivalentProperty(String propertyURI, String equivalentPropertyURI); void removeEquivalentProperty(String propertyURI,
String equivalentPropertyURI);
void removeEquivalentProperty(Property property, Property equivalentProperty); void removeEquivalentProperty(Property property, Property equivalentProperty);
List <String> getSubPropertyURIs(String propertyURI); List<String> getSubPropertyURIs(String propertyURI);
List <String> getAllSubPropertyURIs(String propertyURI); List<String> getAllSubPropertyURIs(String propertyURI);
List <String> getSuperPropertyURIs(String propertyURI, boolean direct); List<String> getSuperPropertyURIs(String propertyURI, boolean direct);
List <String> getAllSuperPropertyURIs(String propertyURI); List<String> getAllSuperPropertyURIs(String propertyURI);
List <String> getEquivalentPropertyURIs(String propertyURI); List<String> getEquivalentPropertyURIs(String propertyURI);
List <VClass> getClassesWithRestrictionOnProperty(String propertyURI); List<VClass> getClassesWithRestrictionOnProperty(String propertyURI);
/**
* An immutable key class for making maps of properties and faux properties.
*
* The property URI is a significant part of the key, of course, but the
* range and domain URIs are significant also.
*
* If the range or domain URI is not provided, it is assumed to be
* OWL:Thing.
*/
public static class FullPropertyKey {
private static final String OWL_THING = OWL.Thing.getURI();
private final String domainUri;
private final String propertyUri;
private final String rangeUri;
private final int hash;
private final String string;
public FullPropertyKey(String uri) {
this(OWL_THING, uri, OWL_THING);
}
public FullPropertyKey(Property prop) {
this(prop.getDomainVClassURI(), prop.getURI(), prop
.getRangeVClassURI());
}
public FullPropertyKey(String domainUri, String propertyUri,
String rangeUri) {
this.propertyUri = Objects.requireNonNull(propertyUri,
"propertyUri may not be null.");
this.domainUri = (domainUri == null) ? OWL_THING : domainUri;
this.rangeUri = (rangeUri == null) ? OWL_THING : rangeUri;
this.hash = calculateHash();
this.string = calculateString();
}
private int calculateHash() {
return Objects
.hash(this.domainUri, this.propertyUri, this.rangeUri);
}
private String calculateString() {
return "FullPropertyKey[domainUri=" + this.domainUri
+ ", propertyUri=" + this.propertyUri + ", rangeUri="
+ this.rangeUri + "]";
}
public String getDomainUri() {
return domainUri;
}
public String getPropertyUri() {
return propertyUri;
}
public String getRangeUri() {
return rangeUri;
}
@Override
public int hashCode() {
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
FullPropertyKey that = (FullPropertyKey) obj;
return Objects.equals(this.domainUri, that.domainUri)
&& Objects.equals(this.propertyUri, that.propertyUri)
&& Objects.equals(this.rangeUri, that.rangeUri);
}
@Override
public String toString() {
return string;
}
}
} }

View file

@ -34,7 +34,6 @@ 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.rdf.model.Statement; import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.sdb.util.Pair;
import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.RDFS;
@ -100,7 +99,8 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
addSuperproperty(property.getURI(),superproperty.getURI()); addSuperproperty(property.getURI(),superproperty.getURI());
} }
public void addSuperproperty(String propertyURI, String superpropertyURI) { @Override
public void addSuperproperty(String propertyURI, String superpropertyURI) {
getOntModel().enterCriticalSection(Lock.WRITE); getOntModel().enterCriticalSection(Lock.WRITE);
try { try {
getOntModel().add(getOntModel().getResource(propertyURI),RDFS.subPropertyOf,getOntModel().getResource(superpropertyURI)); getOntModel().add(getOntModel().getResource(propertyURI),RDFS.subPropertyOf,getOntModel().getResource(superpropertyURI));
@ -113,6 +113,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
removeSuperproperty(property.getURI(),superproperty.getURI()); removeSuperproperty(property.getURI(),superproperty.getURI());
} }
@Override
public void removeSuperproperty(String propertyURI, String superpropertyURI) { public void removeSuperproperty(String propertyURI, String superpropertyURI) {
getOntModel().enterCriticalSection(Lock.WRITE); getOntModel().enterCriticalSection(Lock.WRITE);
try { try {
@ -128,6 +129,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
addSuperproperty(subproperty, property); addSuperproperty(subproperty, property);
} }
@Override
public void addSubproperty(String propertyURI, String subpropertyURI) { public void addSubproperty(String propertyURI, String subpropertyURI) {
addSuperproperty(subpropertyURI, propertyURI); addSuperproperty(subpropertyURI, propertyURI);
} }
@ -136,10 +138,12 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
removeSuperproperty(subproperty, property); removeSuperproperty(subproperty, property);
} }
@Override
public void removeSubproperty(String propertyURI, String subpropertyURI) { public void removeSubproperty(String propertyURI, String subpropertyURI) {
removeSuperproperty(subpropertyURI,propertyURI); removeSuperproperty(subpropertyURI,propertyURI);
} }
@Override
public List <String> getSubPropertyURIs(String propertyURI) { public List <String> getSubPropertyURIs(String propertyURI) {
List<String> subURIs = new LinkedList<String>(); List<String> subURIs = new LinkedList<String>();
getOntModel().enterCriticalSection(Lock.READ); getOntModel().enterCriticalSection(Lock.READ);
@ -171,6 +175,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
} }
} }
@Override
public List<String> getAllSubPropertyURIs(String propertyURI) { public List<String> getAllSubPropertyURIs(String propertyURI) {
HashSet<String> nodeSet = new HashSet<String>(); HashSet<String> nodeSet = new HashSet<String>();
nodeSet.add(propertyURI); nodeSet.add(propertyURI);
@ -181,6 +186,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
return outputList; return outputList;
} }
@Override
public List <String> getSuperPropertyURIs(String propertyURI, boolean direct) { public List <String> getSuperPropertyURIs(String propertyURI, boolean direct) {
List<String> supURIs = new LinkedList<String>(); List<String> supURIs = new LinkedList<String>();
getOntModel().enterCriticalSection(Lock.READ); getOntModel().enterCriticalSection(Lock.READ);
@ -212,6 +218,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
} }
} }
@Override
public List<String> getAllSuperPropertyURIs(String propertyURI) { public List<String> getAllSuperPropertyURIs(String propertyURI) {
HashSet<String> nodeSet = new HashSet<String>(); HashSet<String> nodeSet = new HashSet<String>();
nodeSet.add(propertyURI); nodeSet.add(propertyURI);
@ -222,22 +229,27 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
return outputList; return outputList;
} }
@Override
public void addSubproperty(Property property, Property subproperty) { public void addSubproperty(Property property, Property subproperty) {
addSubproperty(property.getURI(), subproperty.getURI()); addSubproperty(property.getURI(), subproperty.getURI());
} }
@Override
public void addSuperproperty(Property property, Property superproperty) { public void addSuperproperty(Property property, Property superproperty) {
addSuperproperty(property.getURI(), superproperty.getURI()); addSuperproperty(property.getURI(), superproperty.getURI());
} }
@Override
public void removeSubproperty(Property property, Property subproperty) { public void removeSubproperty(Property property, Property subproperty) {
removeSubproperty(property.getURI(), subproperty.getURI()); removeSubproperty(property.getURI(), subproperty.getURI());
} }
@Override
public void removeSuperproperty(Property property, Property superproperty) { public void removeSuperproperty(Property property, Property superproperty) {
removeSuperproperty(property.getURI(), superproperty.getURI()); removeSuperproperty(property.getURI(), superproperty.getURI());
} }
@Override
public void addEquivalentProperty(String propertyURI, public void addEquivalentProperty(String propertyURI,
String equivalentPropertyURI) { String equivalentPropertyURI) {
if (propertyURI == null || equivalentPropertyURI == null) { if (propertyURI == null || equivalentPropertyURI == null) {
@ -255,11 +267,13 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
} }
} }
@Override
public void addEquivalentProperty(Property property, public void addEquivalentProperty(Property property,
Property equivalentProperty) { Property equivalentProperty) {
addEquivalentProperty(property.getURI(), equivalentProperty.getURI()); addEquivalentProperty(property.getURI(), equivalentProperty.getURI());
} }
@Override
public List<String> getEquivalentPropertyURIs(String propertyURI) { public List<String> getEquivalentPropertyURIs(String propertyURI) {
List<String> equivURIs = new LinkedList<String>(); List<String> equivURIs = new LinkedList<String>();
getOntModel().enterCriticalSection(Lock.READ); getOntModel().enterCriticalSection(Lock.READ);
@ -280,6 +294,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
return equivURIs; return equivURIs;
} }
@Override
public void removeEquivalentProperty(String propertyURI, String equivalentPropertyURI) { public void removeEquivalentProperty(String propertyURI, String equivalentPropertyURI) {
if (propertyURI == null || equivalentPropertyURI == null) { if (propertyURI == null || equivalentPropertyURI == null) {
throw new RuntimeException("cannot remove equivalence axiom about anonymous properties"); throw new RuntimeException("cannot remove equivalence axiom about anonymous properties");
@ -296,6 +311,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
} }
} }
@Override
public void removeEquivalentProperty(Property property, public void removeEquivalentProperty(Property property,
Property equivalentProperty) { Property equivalentProperty) {
removeEquivalentProperty(property, equivalentProperty); removeEquivalentProperty(property, equivalentProperty);
@ -337,7 +353,8 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
* definitions involving a restriction on the given property. * definitions involving a restriction on the given property.
*/ */
public List <VClass> getClassesWithRestrictionOnProperty(String propertyURI) { @Override
public List<VClass> getClassesWithRestrictionOnProperty(String propertyURI) {
if (propertyURI == null) { if (propertyURI == null) {
log.warn("getClassesWithRestrictionOnProperty: called with null propertyURI"); log.warn("getClassesWithRestrictionOnProperty: called with null propertyURI");
@ -555,6 +572,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
public VClassHierarchyRanker(VClassDao vcDao) { public VClassHierarchyRanker(VClassDao vcDao) {
this.vcDao = vcDao; this.vcDao = vcDao;
} }
@Override
public int compare(VClass vc1, VClass vc2) { public int compare(VClass vc1, VClass vc2) {
if (vcDao.isSubClassOf(vc1, vc2)) { if (vcDao.isSubClassOf(vc1, vc2)) {
return -1; return -1;
@ -779,21 +797,19 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
: op.getRange(); : op.getRange();
Resource domainRes = op.getDomain(); Resource domainRes = op.getDomain();
propInsts.add(getPropInst(op, domainRes, rangeRes)); propInsts.add(getPropInst(op, domainRes, rangeRes));
List<Pair<String,String>> additionalFauxSubpropertyDomainAndRangeURIs = List<FullPropertyKey> additionalFauxSubpropertyKeys =
getAdditionalFauxSubpropertyDomainAndRangeURIsForPropertyURI( getAdditionalFauxSubpropertyKeysForPropertyURI(propertyURI);
propertyURI); for (FullPropertyKey fauxSubpropertyKey : additionalFauxSubpropertyKeys) {
for (Pair<String,String> domainAndRangeURIs :
additionalFauxSubpropertyDomainAndRangeURIs) {
boolean applicablePropInst = false; boolean applicablePropInst = false;
if (rangeRes == null || if (rangeRes == null ||
!getWebappDaoFactory().getVClassDao().isSubClassOf( !getWebappDaoFactory().getVClassDao().isSubClassOf(
rangeRes.getURI(), domainAndRangeURIs.getRight())) { rangeRes.getURI(), fauxSubpropertyKey.getRangeUri())) {
if (domainAndRangeURIs.getLeft() == null) { if (fauxSubpropertyKey.getDomainUri() == null) {
applicablePropInst = true; applicablePropInst = true;
} else { } else {
for(VClass vclass : vclasses) { for(VClass vclass : vclasses) {
if (vclass.getURI() != null && vclass.getURI().equals( if (vclass.getURI() != null && vclass.getURI().equals(
domainAndRangeURIs.getLeft())) { fauxSubpropertyKey.getDomainUri())) {
applicablePropInst = true; applicablePropInst = true;
break; break;
} }
@ -802,8 +818,8 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
if (applicablePropInst) { if (applicablePropInst) {
propInsts.add(getPropInst( propInsts.add(getPropInst(
op, op,
ResourceFactory.createResource(domainAndRangeURIs.getLeft()), ResourceFactory.createResource(fauxSubpropertyKey.getDomainUri()),
ResourceFactory.createResource(domainAndRangeURIs.getRight()) ResourceFactory.createResource(fauxSubpropertyKey.getRangeUri())
)); ));
} }
} }
@ -938,8 +954,8 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
return opList; return opList;
} }
private List<Pair<String,String>> getAdditionalFauxSubpropertyDomainAndRangeURIsForPropertyURI(String propertyURI) { private List<FullPropertyKey> getAdditionalFauxSubpropertyKeysForPropertyURI(String propertyURI) {
List<Pair<String,String>> domainAndRangeURIs = new ArrayList<Pair<String,String>>(); List<FullPropertyKey> keys = new ArrayList<>();
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" +
@ -962,12 +978,12 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
if (domainRes != null && !domainRes.isAnon()) { if (domainRes != null && !domainRes.isAnon()) {
domainURI = domainRes.getURI(); domainURI = domainRes.getURI();
} }
domainAndRangeURIs.add(new Pair<String,String>(domainURI, rangeURI)); keys.add(new FullPropertyKey(domainURI, propertyURI, rangeURI));
} }
} finally { } finally {
qe.close(); qe.close();
} }
return domainAndRangeURIs; return keys;
} }

View file

@ -26,12 +26,11 @@ import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.sdb.util.Pair;
import com.hp.hpl.jena.vocabulary.OWL;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean; import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean;
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel; import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyDao.FullPropertyKey;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
/** /**
@ -60,27 +59,24 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
// setLoggerLevel(PropertyRestrictionPolicyHelper.class, Level.DEBUG); // setLoggerLevel(PropertyRestrictionPolicyHelper.class, Level.DEBUG);
} }
private void mapPut(String predicateURI, RoleLevel roleLevel, private FullPropertyKey key(String predicateURI) {
Map<Pair<String, Pair<String, String>>, RoleLevel> map) { return new FullPropertyKey(predicateURI);
map.put(new Pair<String, Pair<String, String>>(OWL.Thing.getURI(),
new Pair<String, String>(predicateURI, OWL.Thing.getURI())),
roleLevel);
} }
@Before @Before
public void createTheBean() { public void createTheBean() {
Map<Pair<String, Pair<String, String>>, RoleLevel> displayLevels = new HashMap<>(); Map<FullPropertyKey, RoleLevel> displayLevels = new HashMap<>();
mapPut("http://predicates#display_curator", CURATOR, displayLevels); displayLevels.put(key("http://predicates#display_curator"), CURATOR);
mapPut("http://predicates#display_hidden", NOBODY, displayLevels); displayLevels.put(key("http://predicates#display_hidden"), NOBODY);
Map<Pair<String, Pair<String, String>>, RoleLevel> modifyLevels = new HashMap<>(); Map<FullPropertyKey, RoleLevel> modifyLevels = new HashMap<>();
mapPut("http://predicates#modify_self", SELF, modifyLevels); modifyLevels.put(key("http://predicates#modify_self"), SELF);
mapPut("http://predicates#modify_curator", CURATOR, modifyLevels); modifyLevels.put(key("http://predicates#modify_curator"), CURATOR);
mapPut("http://predicates#modify_hidden", NOBODY, modifyLevels); modifyLevels.put(key("http://predicates#modify_hidden"), NOBODY);
Map<Pair<String, Pair<String, String>>, RoleLevel> publishLevels = new HashMap<>(); Map<FullPropertyKey, RoleLevel> publishLevels = new HashMap<>();
mapPut("http://predicates#publish_curator", CURATOR, publishLevels); publishLevels.put(key("http://predicates#publish_curator"), CURATOR);
mapPut("http://predicates#publish_hidden", NOBODY, publishLevels); publishLevels.put(key("http://predicates#publish_hidden"), NOBODY);
bean = new PropertyRestrictionPolicyHelper( bean = new PropertyRestrictionPolicyHelper(
Arrays.asList(PROHIBITED_NAMESPACES), Arrays.asList(PROHIBITED_NAMESPACES),
@ -268,9 +264,9 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
@Test @Test
public void buildDisplayThresholds() { public void buildDisplayThresholds() {
Map<Pair<String, Pair<String, String>>, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>(); Map<FullPropertyKey, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>();
mapPut("http://thresholds#display_public", PUBLIC, expectedMap); expectedMap.put(key("http://thresholds#display_public"), PUBLIC);
mapPut("http://thresholds#display_hidden", NOBODY, expectedMap); expectedMap.put(key("http://thresholds#display_hidden"), NOBODY);
Map<String, RoleLevel> actualMap = populateThresholdMap(PROPERTY_DISPLAY_THRESHOLD); Map<String, RoleLevel> actualMap = populateThresholdMap(PROPERTY_DISPLAY_THRESHOLD);
assertEquals("display thresholds", expectedMap, actualMap); assertEquals("display thresholds", expectedMap, actualMap);
@ -278,9 +274,9 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
@Test @Test
public void buildModifyThresholds() { public void buildModifyThresholds() {
Map<Pair<String, Pair<String, String>>, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>(); Map<FullPropertyKey, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>();
mapPut("http://thresholds#modify_editor", EDITOR, expectedMap); expectedMap.put(key("http://thresholds#modify_editor"), EDITOR);
mapPut("http://thresholds#modify_curator", CURATOR, expectedMap); expectedMap.put(key("http://thresholds#modify_curator"), CURATOR);
Map<String, RoleLevel> actualMap = populateThresholdMap(PROPERTY_MODIFY_THRESHOLD); Map<String, RoleLevel> actualMap = populateThresholdMap(PROPERTY_MODIFY_THRESHOLD);
assertEquals("modify thresholds", expectedMap, actualMap); assertEquals("modify thresholds", expectedMap, actualMap);
@ -288,9 +284,9 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
@Test @Test
public void buildPublishThresholds() { public void buildPublishThresholds() {
Map<Pair<String, Pair<String, String>>, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>(); Map<FullPropertyKey, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>();
mapPut("http://thresholds#publish_public", PUBLIC, expectedMap); expectedMap.put(key("http://thresholds#publish_public"), PUBLIC);
mapPut("http://thresholds#publish_hidden", NOBODY, expectedMap); expectedMap.put(key("http://thresholds#publish_hidden"), NOBODY);
Map<String, RoleLevel> actualMap = populateThresholdMap(PROPERTY_PUBLISH_THRESHOLD); Map<String, RoleLevel> actualMap = populateThresholdMap(PROPERTY_PUBLISH_THRESHOLD);
assertEquals("publish thresholds", expectedMap, actualMap); assertEquals("publish thresholds", expectedMap, actualMap);

View file

@ -8,11 +8,9 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import com.hp.hpl.jena.sdb.util.Pair;
import com.hp.hpl.jena.vocabulary.OWL;
import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper; import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper;
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel; import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyDao.FullPropertyKey;
/** /**
* Allow the unit test to specify a variety of restrictions * Allow the unit test to specify a variety of restrictions
@ -42,12 +40,10 @@ public class PropertyRestrictionPolicyHelperStub extends
namespaceSet.addAll(Arrays.asList(restrictedNamespaces)); namespaceSet.addAll(Arrays.asList(restrictedNamespaces));
} }
Map<Pair<String, Pair<String, String>>, RoleLevel> thresholdMap = new HashMap<>(); Map<FullPropertyKey, RoleLevel> thresholdMap = new HashMap<>();
if (restrictedProperties != null) { if (restrictedProperties != null) {
for (String prop : restrictedProperties) { for (String prop : restrictedProperties) {
thresholdMap.put(new Pair<String, Pair<String, String>>( thresholdMap.put(new FullPropertyKey(prop), RoleLevel.NOBODY);
OWL.Thing.getURI(), new Pair<String, String>(prop,
OWL.Thing.getURI())), RoleLevel.NOBODY);
} }
} }
@ -58,11 +54,10 @@ public class PropertyRestrictionPolicyHelperStub extends
private PropertyRestrictionPolicyHelperStub( private PropertyRestrictionPolicyHelperStub(
Set<String> modifyRestrictedNamespaces, Set<String> modifyRestrictedNamespaces,
Set<String> modifyPermittedExceptions, Set<String> modifyPermittedExceptions,
Map<Pair<String, Pair<String, String>>, RoleLevel> displayThresholds, Map<FullPropertyKey, RoleLevel> displayThresholds,
Map<Pair<String, Pair<String, String>>, RoleLevel> modifyThresholds, Map<FullPropertyKey, RoleLevel> modifyThresholds,
Map<Pair<String, Pair<String, String>>, RoleLevel> publishThresholds) { Map<FullPropertyKey, RoleLevel> publishThresholds) {
super(modifyRestrictedNamespaces, modifyPermittedExceptions, super(modifyRestrictedNamespaces, modifyPermittedExceptions,
displayThresholds, modifyThresholds, publishThresholds); displayThresholds, modifyThresholds, publishThresholds);
} }
} }