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.StmtIterator;
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.vocabulary.OWL;
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
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.modelaccess.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
@ -111,12 +110,12 @@ public class PropertyRestrictionPolicyHelper {
Model displayModel) {
Map<Pair<String, Pair<String,String>>, RoleLevel> displayThresholdMap =
new HashMap<Pair<String, Pair<String,String>>, RoleLevel>();
Map<Pair<String, Pair<String,String>>, RoleLevel> modifyThresholdMap =
new HashMap<Pair<String, Pair<String,String>>, RoleLevel>();
Map<Pair<String, Pair<String,String>>, RoleLevel> publishThresholdMap =
new HashMap<Pair<String, Pair<String,String>>, RoleLevel>();
Map<FullPropertyKey, RoleLevel> displayThresholdMap =
new HashMap<FullPropertyKey, RoleLevel>();
Map<FullPropertyKey, RoleLevel> modifyThresholdMap =
new HashMap<FullPropertyKey, RoleLevel>();
Map<FullPropertyKey, RoleLevel> publishThresholdMap =
new HashMap<FullPropertyKey, RoleLevel>();
OntModel union = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
ModelFactory.createUnion(displayModel, model));
@ -140,40 +139,25 @@ public class PropertyRestrictionPolicyHelper {
return getThreshold(property, modifyThresholdMap);
}
private RoleLevel getThreshold(Property property,
Map<Pair<String, Pair<String,String>>, RoleLevel>
thresholdMap) {
private RoleLevel getThreshold(Property property,
Map<FullPropertyKey, RoleLevel> thresholdMap) {
if (property.getURI() == null) {
return RoleLevel.NOBODY;
}
RoleLevel roleLevel = getRoleLevelFromMap(
property.getDomainVClassURI(), property.getURI(),
property.getRangeVClassURI(), thresholdMap);
if (roleLevel == null) {
roleLevel = getRoleLevelFromMap(
OWL.Thing.getURI(), property.getURI(), OWL.Thing.getURI(),
thresholdMap);
}
RoleLevel roleLevel = thresholdMap.get(new FullPropertyKey(property));
if (roleLevel == null) {
roleLevel = thresholdMap
.get(new FullPropertyKey(property.getURI()));
}
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
* URI to the required RoleLevel.
*/
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);
try {
com.hp.hpl.jena.rdf.model.Property property = model.getProperty(propertyUri);
@ -189,9 +173,7 @@ public class PropertyRestrictionPolicyHelper {
}
Resource object = (Resource) objectNode;
RoleLevel role = RoleLevel.getRoleByUri(object.getURI());
map.put(new Pair<String,Pair<String,String>>(
OWL.Thing.getURI(), new Pair<String,String>(
subject.getURI(), OWL.Thing.getURI())), role);
map.put(new FullPropertyKey(subject.getURI()), role);
}
} finally {
stmts.close();
@ -211,12 +193,9 @@ public class PropertyRestrictionPolicyHelper {
role = faux.getHiddenFromPublishBelowRoleLevel();
}
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);
FullPropertyKey key = new FullPropertyKey(faux);
map.put(key, role);
log.debug("Putting key: " + key + " ==> L:" + role);
}
}
@ -245,19 +224,19 @@ public class PropertyRestrictionPolicyHelper {
* These URIs can be displayed only if the user's role is at least as high
* 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
* 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
* 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(
Collection<String> modifyProhibitedNamespaces,
Collection<String> modifyExceptionsAllowedUris,
Map<Pair<String, Pair<String,String>>, RoleLevel> displayThresholdMap,
Map<Pair<String, Pair<String,String>>, RoleLevel> modifyThresholdMap,
Map<Pair<String, Pair<String,String>>, RoleLevel> publishThresholdMap) {
Map<FullPropertyKey, RoleLevel> displayThresholdMap,
Map<FullPropertyKey, RoleLevel> modifyThresholdMap,
Map<FullPropertyKey, RoleLevel> publishThresholdMap) {
this.modifyProhibitedNamespaces = unmodifiable(modifyProhibitedNamespaces);
this.modifyExceptionsAllowedUris = unmodifiable(modifyExceptionsAllowedUris);
this.displayThresholdMap = displayThresholdMap;

View file

@ -3,46 +3,140 @@
package edu.cornell.mannlib.vitro.webapp.dao;
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.VClass;
public interface PropertyDao {
void addSuperproperty(Property property, Property superproperty);
void addSuperproperty(String propertyURI, String superpropertyURI);
void removeSuperproperty(Property property, Property superproperty);
void removeSuperproperty(String propertyURI, String superpropertyURI);
void addSubproperty(Property property, Property subproperty);
void addSubproperty(String propertyURI, String subpropertyURI);
void removeSubproperty(Property property, Property subproperty);
void removeSubproperty(String propertyURI, String subpropertyURI);
void addEquivalentProperty(String propertyURI, String equivalentPropertyURI);
void addEquivalentProperty(Property property, Property equivalentProperty);
void removeEquivalentProperty(String propertyURI, String equivalentPropertyURI);
void removeEquivalentProperty(Property property, Property equivalentProperty);
List <String> getSubPropertyURIs(String propertyURI);
List <String> getAllSubPropertyURIs(String propertyURI);
void addSuperproperty(Property property, Property superproperty);
List <String> getSuperPropertyURIs(String propertyURI, boolean direct);
void addSuperproperty(String propertyURI, String superpropertyURI);
List <String> getAllSuperPropertyURIs(String propertyURI);
List <String> getEquivalentPropertyURIs(String propertyURI);
List <VClass> getClassesWithRestrictionOnProperty(String propertyURI);
void removeSuperproperty(Property property, Property superproperty);
void removeSuperproperty(String propertyURI, String superpropertyURI);
void addSubproperty(Property property, Property subproperty);
void addSubproperty(String propertyURI, String subpropertyURI);
void removeSubproperty(Property property, Property subproperty);
void removeSubproperty(String propertyURI, String subpropertyURI);
void addEquivalentProperty(String propertyURI, String equivalentPropertyURI);
void addEquivalentProperty(Property property, Property equivalentProperty);
void removeEquivalentProperty(String propertyURI,
String equivalentPropertyURI);
void removeEquivalentProperty(Property property, Property equivalentProperty);
List<String> getSubPropertyURIs(String propertyURI);
List<String> getAllSubPropertyURIs(String propertyURI);
List<String> getSuperPropertyURIs(String propertyURI, boolean direct);
List<String> getAllSuperPropertyURIs(String propertyURI);
List<String> getEquivalentPropertyURIs(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.Statement;
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.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDFS;
@ -100,7 +99,8 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
addSuperproperty(property.getURI(),superproperty.getURI());
}
public void addSuperproperty(String propertyURI, String superpropertyURI) {
@Override
public void addSuperproperty(String propertyURI, String superpropertyURI) {
getOntModel().enterCriticalSection(Lock.WRITE);
try {
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());
}
@Override
public void removeSuperproperty(String propertyURI, String superpropertyURI) {
getOntModel().enterCriticalSection(Lock.WRITE);
try {
@ -128,6 +129,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
addSuperproperty(subproperty, property);
}
@Override
public void addSubproperty(String propertyURI, String subpropertyURI) {
addSuperproperty(subpropertyURI, propertyURI);
}
@ -136,10 +138,12 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
removeSuperproperty(subproperty, property);
}
@Override
public void removeSubproperty(String propertyURI, String subpropertyURI) {
removeSuperproperty(subpropertyURI,propertyURI);
}
@Override
public List <String> getSubPropertyURIs(String propertyURI) {
List<String> subURIs = new LinkedList<String>();
getOntModel().enterCriticalSection(Lock.READ);
@ -171,6 +175,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
}
}
@Override
public List<String> getAllSubPropertyURIs(String propertyURI) {
HashSet<String> nodeSet = new HashSet<String>();
nodeSet.add(propertyURI);
@ -181,6 +186,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
return outputList;
}
@Override
public List <String> getSuperPropertyURIs(String propertyURI, boolean direct) {
List<String> supURIs = new LinkedList<String>();
getOntModel().enterCriticalSection(Lock.READ);
@ -212,6 +218,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
}
}
@Override
public List<String> getAllSuperPropertyURIs(String propertyURI) {
HashSet<String> nodeSet = new HashSet<String>();
nodeSet.add(propertyURI);
@ -222,22 +229,27 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
return outputList;
}
@Override
public void addSubproperty(Property property, Property subproperty) {
addSubproperty(property.getURI(), subproperty.getURI());
}
@Override
public void addSuperproperty(Property property, Property superproperty) {
addSuperproperty(property.getURI(), superproperty.getURI());
}
@Override
public void removeSubproperty(Property property, Property subproperty) {
removeSubproperty(property.getURI(), subproperty.getURI());
}
@Override
public void removeSuperproperty(Property property, Property superproperty) {
removeSuperproperty(property.getURI(), superproperty.getURI());
}
@Override
public void addEquivalentProperty(String propertyURI,
String equivalentPropertyURI) {
if (propertyURI == null || equivalentPropertyURI == null) {
@ -255,11 +267,13 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
}
}
@Override
public void addEquivalentProperty(Property property,
Property equivalentProperty) {
addEquivalentProperty(property.getURI(), equivalentProperty.getURI());
}
@Override
public List<String> getEquivalentPropertyURIs(String propertyURI) {
List<String> equivURIs = new LinkedList<String>();
getOntModel().enterCriticalSection(Lock.READ);
@ -280,6 +294,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
return equivURIs;
}
@Override
public void removeEquivalentProperty(String propertyURI, String equivalentPropertyURI) {
if (propertyURI == null || equivalentPropertyURI == null) {
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,
Property equivalentProperty) {
removeEquivalentProperty(property, equivalentProperty);
@ -337,7 +353,8 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
* definitions involving a restriction on the given property.
*/
public List <VClass> getClassesWithRestrictionOnProperty(String propertyURI) {
@Override
public List<VClass> getClassesWithRestrictionOnProperty(String propertyURI) {
if (propertyURI == null) {
log.warn("getClassesWithRestrictionOnProperty: called with null propertyURI");
@ -555,6 +572,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
public VClassHierarchyRanker(VClassDao vcDao) {
this.vcDao = vcDao;
}
@Override
public int compare(VClass vc1, VClass vc2) {
if (vcDao.isSubClassOf(vc1, vc2)) {
return -1;
@ -779,21 +797,19 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
: op.getRange();
Resource domainRes = op.getDomain();
propInsts.add(getPropInst(op, domainRes, rangeRes));
List<Pair<String,String>> additionalFauxSubpropertyDomainAndRangeURIs =
getAdditionalFauxSubpropertyDomainAndRangeURIsForPropertyURI(
propertyURI);
for (Pair<String,String> domainAndRangeURIs :
additionalFauxSubpropertyDomainAndRangeURIs) {
List<FullPropertyKey> additionalFauxSubpropertyKeys =
getAdditionalFauxSubpropertyKeysForPropertyURI(propertyURI);
for (FullPropertyKey fauxSubpropertyKey : additionalFauxSubpropertyKeys) {
boolean applicablePropInst = false;
if (rangeRes == null ||
!getWebappDaoFactory().getVClassDao().isSubClassOf(
rangeRes.getURI(), domainAndRangeURIs.getRight())) {
if (domainAndRangeURIs.getLeft() == null) {
rangeRes.getURI(), fauxSubpropertyKey.getRangeUri())) {
if (fauxSubpropertyKey.getDomainUri() == null) {
applicablePropInst = true;
} else {
for(VClass vclass : vclasses) {
if (vclass.getURI() != null && vclass.getURI().equals(
domainAndRangeURIs.getLeft())) {
fauxSubpropertyKey.getDomainUri())) {
applicablePropInst = true;
break;
}
@ -802,8 +818,8 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
if (applicablePropInst) {
propInsts.add(getPropInst(
op,
ResourceFactory.createResource(domainAndRangeURIs.getLeft()),
ResourceFactory.createResource(domainAndRangeURIs.getRight())
ResourceFactory.createResource(fauxSubpropertyKey.getDomainUri()),
ResourceFactory.createResource(fauxSubpropertyKey.getRangeUri())
));
}
}
@ -938,8 +954,8 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
return opList;
}
private List<Pair<String,String>> getAdditionalFauxSubpropertyDomainAndRangeURIsForPropertyURI(String propertyURI) {
List<Pair<String,String>> domainAndRangeURIs = new ArrayList<Pair<String,String>>();
private List<FullPropertyKey> getAdditionalFauxSubpropertyKeysForPropertyURI(String propertyURI) {
List<FullPropertyKey> keys = new ArrayList<>();
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" +
@ -962,12 +978,12 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
if (domainRes != null && !domainRes.isAnon()) {
domainURI = domainRes.getURI();
}
domainAndRangeURIs.add(new Pair<String,String>(domainURI, rangeURI));
keys.add(new FullPropertyKey(domainURI, propertyURI, rangeURI));
}
} finally {
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.Property;
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.webapp.beans.BaseResourceBean;
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;
/**
@ -60,27 +59,24 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
// setLoggerLevel(PropertyRestrictionPolicyHelper.class, Level.DEBUG);
}
private void mapPut(String predicateURI, RoleLevel roleLevel,
Map<Pair<String, Pair<String, String>>, RoleLevel> map) {
map.put(new Pair<String, Pair<String, String>>(OWL.Thing.getURI(),
new Pair<String, String>(predicateURI, OWL.Thing.getURI())),
roleLevel);
private FullPropertyKey key(String predicateURI) {
return new FullPropertyKey(predicateURI);
}
@Before
public void createTheBean() {
Map<Pair<String, Pair<String, String>>, RoleLevel> displayLevels = new HashMap<>();
mapPut("http://predicates#display_curator", CURATOR, displayLevels);
mapPut("http://predicates#display_hidden", NOBODY, displayLevels);
Map<FullPropertyKey, RoleLevel> displayLevels = new HashMap<>();
displayLevels.put(key("http://predicates#display_curator"), CURATOR);
displayLevels.put(key("http://predicates#display_hidden"), NOBODY);
Map<Pair<String, Pair<String, String>>, RoleLevel> modifyLevels = new HashMap<>();
mapPut("http://predicates#modify_self", SELF, modifyLevels);
mapPut("http://predicates#modify_curator", CURATOR, modifyLevels);
mapPut("http://predicates#modify_hidden", NOBODY, modifyLevels);
Map<FullPropertyKey, RoleLevel> modifyLevels = new HashMap<>();
modifyLevels.put(key("http://predicates#modify_self"), SELF);
modifyLevels.put(key("http://predicates#modify_curator"), CURATOR);
modifyLevels.put(key("http://predicates#modify_hidden"), NOBODY);
Map<Pair<String, Pair<String, String>>, RoleLevel> publishLevels = new HashMap<>();
mapPut("http://predicates#publish_curator", CURATOR, publishLevels);
mapPut("http://predicates#publish_hidden", NOBODY, publishLevels);
Map<FullPropertyKey, RoleLevel> publishLevels = new HashMap<>();
publishLevels.put(key("http://predicates#publish_curator"), CURATOR);
publishLevels.put(key("http://predicates#publish_hidden"), NOBODY);
bean = new PropertyRestrictionPolicyHelper(
Arrays.asList(PROHIBITED_NAMESPACES),
@ -103,7 +99,7 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
PROPERTY_MODIFY_THRESHOLD, EDITOR.getURI());
wrapper.add("http://thresholds#modify_curator",
PROPERTY_MODIFY_THRESHOLD, CURATOR.getURI());
wrapper.add("http://thresholds#publish_public",
PROPERTY_PUBLISH_THRESHOLD, PUBLIC.getURI());
wrapper.add("http://thresholds#publish_hidden",
@ -268,9 +264,9 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
@Test
public void buildDisplayThresholds() {
Map<Pair<String, Pair<String, String>>, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>();
mapPut("http://thresholds#display_public", PUBLIC, expectedMap);
mapPut("http://thresholds#display_hidden", NOBODY, expectedMap);
Map<FullPropertyKey, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>();
expectedMap.put(key("http://thresholds#display_public"), PUBLIC);
expectedMap.put(key("http://thresholds#display_hidden"), NOBODY);
Map<String, RoleLevel> actualMap = populateThresholdMap(PROPERTY_DISPLAY_THRESHOLD);
assertEquals("display thresholds", expectedMap, actualMap);
@ -278,9 +274,9 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
@Test
public void buildModifyThresholds() {
Map<Pair<String, Pair<String, String>>, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>();
mapPut("http://thresholds#modify_editor", EDITOR, expectedMap);
mapPut("http://thresholds#modify_curator", CURATOR, expectedMap);
Map<FullPropertyKey, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>();
expectedMap.put(key("http://thresholds#modify_editor"), EDITOR);
expectedMap.put(key("http://thresholds#modify_curator"), CURATOR);
Map<String, RoleLevel> actualMap = populateThresholdMap(PROPERTY_MODIFY_THRESHOLD);
assertEquals("modify thresholds", expectedMap, actualMap);
@ -288,9 +284,9 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
@Test
public void buildPublishThresholds() {
Map<Pair<String, Pair<String, String>>, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>();
mapPut("http://thresholds#publish_public", PUBLIC, expectedMap);
mapPut("http://thresholds#publish_hidden", NOBODY, expectedMap);
Map<FullPropertyKey, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>();
expectedMap.put(key("http://thresholds#publish_public"), PUBLIC);
expectedMap.put(key("http://thresholds#publish_hidden"), NOBODY);
Map<String, RoleLevel> actualMap = populateThresholdMap(PROPERTY_PUBLISH_THRESHOLD);
assertEquals("publish thresholds", expectedMap, actualMap);

View file

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