diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelper.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelper.java index f7ecddc47..6e8d5637a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelper.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelper.java @@ -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>, RoleLevel> displayThresholdMap = - new HashMap>, RoleLevel>(); - Map>, RoleLevel> modifyThresholdMap = - new HashMap>, RoleLevel>(); - Map>, RoleLevel> publishThresholdMap = - new HashMap>, RoleLevel>(); + Map displayThresholdMap = + new HashMap(); + Map modifyThresholdMap = + new HashMap(); + Map publishThresholdMap = + new HashMap(); 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>, RoleLevel> - thresholdMap) { + private RoleLevel getThreshold(Property property, + Map 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>, - RoleLevel> map) { - return map.get( - new Pair>( - domainURI, new Pair( - 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>, RoleLevel> map, String propertyUri) { + Map 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>( - OWL.Thing.getURI(), new Pair( - 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>( - faux.getDomainVClassURI(), new Pair( - 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>, RoleLevel> displayThresholdMap; + private final Map displayThresholdMap; /** * These URIs can be modified only if the user's role is at least as high as * the threshold role. */ - private final Map>, RoleLevel> modifyThresholdMap; + private final Map modifyThresholdMap; /** * These URIs can be published only if the user's role is at least as high as * the threshold role. */ - private final Map>, RoleLevel> publishThresholdMap; + private final Map publishThresholdMap; /** @@ -269,9 +248,9 @@ public class PropertyRestrictionPolicyHelper { protected PropertyRestrictionPolicyHelper( Collection modifyProhibitedNamespaces, Collection modifyExceptionsAllowedUris, - Map>, RoleLevel> displayThresholdMap, - Map>, RoleLevel> modifyThresholdMap, - Map>, RoleLevel> publishThresholdMap) { + Map displayThresholdMap, + Map modifyThresholdMap, + Map publishThresholdMap) { this.modifyProhibitedNamespaces = unmodifiable(modifyProhibitedNamespaces); this.modifyExceptionsAllowedUris = unmodifiable(modifyExceptionsAllowedUris); this.displayThresholdMap = displayThresholdMap; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/PropertyDao.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/PropertyDao.java index 4b05657e9..378aac5dd 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/PropertyDao.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/PropertyDao.java @@ -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 getSubPropertyURIs(String propertyURI); - List getAllSubPropertyURIs(String propertyURI); + void addSuperproperty(Property property, Property superproperty); - List getSuperPropertyURIs(String propertyURI, boolean direct); + void addSuperproperty(String propertyURI, String superpropertyURI); - List getAllSuperPropertyURIs(String propertyURI); - - List getEquivalentPropertyURIs(String propertyURI); - - List 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 getSubPropertyURIs(String propertyURI); + + List getAllSubPropertyURIs(String propertyURI); + + List getSuperPropertyURIs(String propertyURI, boolean direct); + + List getAllSuperPropertyURIs(String propertyURI); + + List getEquivalentPropertyURIs(String propertyURI); + + List 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; + } + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyDaoJena.java index f342bef33..086d16f30 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyDaoJena.java @@ -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 getSubPropertyURIs(String propertyURI) { List subURIs = new LinkedList(); getOntModel().enterCriticalSection(Lock.READ); @@ -171,6 +175,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao { } } + @Override public List getAllSubPropertyURIs(String propertyURI) { HashSet nodeSet = new HashSet(); nodeSet.add(propertyURI); @@ -181,6 +186,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao { return outputList; } + @Override public List getSuperPropertyURIs(String propertyURI, boolean direct) { List supURIs = new LinkedList(); getOntModel().enterCriticalSection(Lock.READ); @@ -212,6 +218,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao { } } + @Override public List getAllSuperPropertyURIs(String propertyURI) { HashSet nodeSet = new HashSet(); 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 getEquivalentPropertyURIs(String propertyURI) { List equivURIs = new LinkedList(); 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 getClassesWithRestrictionOnProperty(String propertyURI) { + @Override + public List 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> additionalFauxSubpropertyDomainAndRangeURIs = - getAdditionalFauxSubpropertyDomainAndRangeURIsForPropertyURI( - propertyURI); - for (Pair domainAndRangeURIs : - additionalFauxSubpropertyDomainAndRangeURIs) { + List 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> getAdditionalFauxSubpropertyDomainAndRangeURIsForPropertyURI(String propertyURI) { - List> domainAndRangeURIs = new ArrayList>(); + private List getAdditionalFauxSubpropertyKeysForPropertyURI(String propertyURI) { + List keys = new ArrayList<>(); String propQuery = "PREFIX rdfs: \n" + "PREFIX config: \n" + "PREFIX vitro: \n" + @@ -962,12 +978,12 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao { if (domainRes != null && !domainRes.isAnon()) { domainURI = domainRes.getURI(); } - domainAndRangeURIs.add(new Pair(domainURI, rangeURI)); + keys.add(new FullPropertyKey(domainURI, propertyURI, rangeURI)); } } finally { qe.close(); } - return domainAndRangeURIs; + return keys; } diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelperTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelperTest.java index 1384c29e2..0ad53df91 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelperTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelperTest.java @@ -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>, RoleLevel> map) { - map.put(new Pair>(OWL.Thing.getURI(), - new Pair(predicateURI, OWL.Thing.getURI())), - roleLevel); + private FullPropertyKey key(String predicateURI) { + return new FullPropertyKey(predicateURI); } @Before public void createTheBean() { - Map>, RoleLevel> displayLevels = new HashMap<>(); - mapPut("http://predicates#display_curator", CURATOR, displayLevels); - mapPut("http://predicates#display_hidden", NOBODY, displayLevels); + Map displayLevels = new HashMap<>(); + displayLevels.put(key("http://predicates#display_curator"), CURATOR); + displayLevels.put(key("http://predicates#display_hidden"), NOBODY); - Map>, 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 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>, RoleLevel> publishLevels = new HashMap<>(); - mapPut("http://predicates#publish_curator", CURATOR, publishLevels); - mapPut("http://predicates#publish_hidden", NOBODY, publishLevels); + Map 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>, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>(); - mapPut("http://thresholds#display_public", PUBLIC, expectedMap); - mapPut("http://thresholds#display_hidden", NOBODY, expectedMap); + Map expectedMap = new HashMap<>(); + expectedMap.put(key("http://thresholds#display_public"), PUBLIC); + expectedMap.put(key("http://thresholds#display_hidden"), NOBODY); Map actualMap = populateThresholdMap(PROPERTY_DISPLAY_THRESHOLD); assertEquals("display thresholds", expectedMap, actualMap); @@ -278,9 +274,9 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass { @Test public void buildModifyThresholds() { - Map>, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>(); - mapPut("http://thresholds#modify_editor", EDITOR, expectedMap); - mapPut("http://thresholds#modify_curator", CURATOR, expectedMap); + Map expectedMap = new HashMap<>(); + expectedMap.put(key("http://thresholds#modify_editor"), EDITOR); + expectedMap.put(key("http://thresholds#modify_curator"), CURATOR); Map actualMap = populateThresholdMap(PROPERTY_MODIFY_THRESHOLD); assertEquals("modify thresholds", expectedMap, actualMap); @@ -288,9 +284,9 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass { @Test public void buildPublishThresholds() { - Map>, BaseResourceBean.RoleLevel> expectedMap = new HashMap<>(); - mapPut("http://thresholds#publish_public", PUBLIC, expectedMap); - mapPut("http://thresholds#publish_hidden", NOBODY, expectedMap); + Map expectedMap = new HashMap<>(); + expectedMap.put(key("http://thresholds#publish_public"), PUBLIC); + expectedMap.put(key("http://thresholds#publish_hidden"), NOBODY); Map actualMap = populateThresholdMap(PROPERTY_PUBLISH_THRESHOLD); assertEquals("publish thresholds", expectedMap, actualMap); diff --git a/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelperStub.java b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelperStub.java index 383cab17c..5c98a2909 100644 --- a/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelperStub.java +++ b/webapp/test/stubs/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelperStub.java @@ -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>, RoleLevel> thresholdMap = new HashMap<>(); + Map thresholdMap = new HashMap<>(); if (restrictedProperties != null) { for (String prop : restrictedProperties) { - thresholdMap.put(new Pair>( - OWL.Thing.getURI(), new Pair(prop, - OWL.Thing.getURI())), RoleLevel.NOBODY); + thresholdMap.put(new FullPropertyKey(prop), RoleLevel.NOBODY); } } @@ -58,11 +54,10 @@ public class PropertyRestrictionPolicyHelperStub extends private PropertyRestrictionPolicyHelperStub( Set modifyRestrictedNamespaces, Set modifyPermittedExceptions, - Map>, RoleLevel> displayThresholds, - Map>, RoleLevel> modifyThresholds, - Map>, RoleLevel> publishThresholds) { + Map displayThresholds, + Map modifyThresholds, + Map publishThresholds) { super(modifyRestrictedNamespaces, modifyPermittedExceptions, displayThresholds, modifyThresholds, publishThresholds); } - }