Merge branch 'develop' into feature/fauxEditing

This commit is contained in:
Jim Blake 2014-10-27 14:20:56 -04:00
commit 681219da72
8 changed files with 280 additions and 164 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));
@ -140,40 +139,25 @@ public class PropertyRestrictionPolicyHelper {
return getThreshold(property, modifyThresholdMap); return getThreshold(property, modifyThresholdMap);
} }
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(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); void removeSuperproperty(Property property, Property superproperty);
List <String> getEquivalentPropertyURIs(String propertyURI); void removeSuperproperty(String propertyURI, String superpropertyURI);
List <VClass> getClassesWithRestrictionOnProperty(String propertyURI); 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.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

@ -84,6 +84,10 @@ public class AutocompleteController extends VitroAjaxController {
hasMultipleTypes = true; hasMultipleTypes = true;
} }
} }
} else {
//if the type parameter is null, no range is specified and individuals of any class might be returned
//in this case, it would be useful to show the most specific type of the individual
hasMultipleTypes = true;
} }
SearchQuery query = getQuery(qtxt, vreq); SearchQuery query = getQuery(qtxt, vreq);

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),
@ -103,7 +99,7 @@ public class PropertyRestrictionPolicyHelperTest extends AbstractTestClass {
PROPERTY_MODIFY_THRESHOLD, EDITOR.getURI()); PROPERTY_MODIFY_THRESHOLD, EDITOR.getURI());
wrapper.add("http://thresholds#modify_curator", wrapper.add("http://thresholds#modify_curator",
PROPERTY_MODIFY_THRESHOLD, CURATOR.getURI()); PROPERTY_MODIFY_THRESHOLD, CURATOR.getURI());
wrapper.add("http://thresholds#publish_public", wrapper.add("http://thresholds#publish_public",
PROPERTY_PUBLISH_THRESHOLD, PUBLIC.getURI()); PROPERTY_PUBLISH_THRESHOLD, PUBLIC.getURI());
wrapper.add("http://thresholds#publish_hidden", wrapper.add("http://thresholds#publish_hidden",
@ -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);
} }
} }

View file

@ -3,7 +3,9 @@
var customForm = { var customForm = {
/* *** Initial page setup *** */ /* *** Initial page setup *** */
//Setting the default Concept class here
//This would need to change if we update the ontology, etc.
conceptClassURI: "http://www.w3.org/2004/02/skos/core#Concept",
onLoad: function() { onLoad: function() {
if (this.disableFormInUnsupportedBrowsers()) { if (this.disableFormInUnsupportedBrowsers()) {
@ -323,9 +325,12 @@ var customForm = {
// Not sure why, but we need an explicit json parse here. // Not sure why, but we need an explicit json parse here.
var results = $.parseJSON(xhr.responseText); var results = $.parseJSON(xhr.responseText);
var filteredResults = customForm.filterAcResults(results); var filteredResults = customForm.filterAcResults(results);
/*
if ( customForm.acTypes[$(selectedObj).attr('acGroupName')] == "http://www.w3.org/2004/02/skos/core#Concept" ) { if ( customForm.acTypes[$(selectedObj).attr('acGroupName')] == customForm.conceptClassURI ) {
filteredResults = customForm.removeConceptSubclasses(filteredResults); filteredResults = customForm.removeConceptSubclasses(filteredResults);
}*/
if(customForm.doRemoveConceptSubclasses()) {
filteredResults = customForm.removeConceptSubclasses(filteredResults);
} }
customForm.acCache[request.term] = filteredResults; customForm.acCache[request.term] = filteredResults;
@ -342,6 +347,15 @@ var customForm = {
}); });
}, },
//Method to check whether we need to filter to individuals with a most specific type = Concept or other allowed subclasses
doRemoveConceptSubclasses:function() {
//if this array of allowable subclasses was declared annd there is at least one element in it
if(customForm.limitToConceptClasses && customForm.limitToConceptClasses.length) {
return true;
}
return false;
},
// Store original or base text with elements that will have text substitutions. // Store original or base text with elements that will have text substitutions.
// Generally the substitution cannot be made on the current value, since that value // Generally the substitution cannot be made on the current value, since that value
// may have changed from the original. So we store the original text with the element to // may have changed from the original. So we store the original text with the element to
@ -426,34 +440,52 @@ var customForm = {
customForm.acFilter = customForm.acFilter.concat(this.acFilterForIndividuals); customForm.acFilter = customForm.acFilter.concat(this.acFilterForIndividuals);
}, },
//Updating this code to utilize an array to
removeConceptSubclasses: function(array) { removeConceptSubclasses: function(array) {
$(array).each(function(i) { //Using map because the resulting array might be different from the original
var allMsTypes = this["allMsTypes"]; array = jQuery.map(array, function(arrayValue, i) {
var removeElement = false; var allMsTypes = arrayValue["allMsTypes"];
if(allMsTypes.length == 1 && this["msType"] != "http://www.w3.org/2004/02/skos/core#Concept") { var removeElement = false;
//Remove from array if(allMsTypes.length == 1 && !customForm.isAllowedConceptSubclass(arrayValue["msType"])) {
removeElement = true; //Remove from array
} else if(allMsTypes.length > 1) { removeElement = true;
//If there are multiple most specific types returned, check if none of them equals concept } else if(allMsTypes.length > 1) {
removeElement = true; //If there are multiple most specific types returned, check if none of them equals concept
var j; removeElement = true;
for(j = 0; j < allMsTypes.length; j++) { var j;
//this refers to the element itself
if(allMsTypes[j] == "http://www.w3.org/2004/02/skos/core#Concept") { for(j = 0; j < allMsTypes.length; j++) {
//don't remove this element if one of the most specific types is a concept //this refers to the element itself
removeElement = false; if(customForm.isAllowedConceptSubclass(allMsTypes[j])) {
break; //don't remove this element if one of the most specific types is a concept
} removeElement = false;
} break;
} }
}
if(removeElement) { }
array.splice(i, 1);
} if(removeElement)
}); return null;
else
return arrayValue;
});
return array; return array;
}, },
isAllowedConceptSubclass:function(classURI) {
if(customForm.limitToConceptClasses && customForm.limitToConceptClasses.length) {
var len = customForm.limitToConceptClasses.length;
var i;
for(i = 0; i < len; i++) {
if(classURI == customForm.limitToConceptClasses[i]) {
return true;
}
}
}
return false;
},
showAutocompleteSelection: function(label, uri, selectedObj) { showAutocompleteSelection: function(label, uri, selectedObj) {
// hide the acSelector field and set it's value to the selected ac item // hide the acSelector field and set it's value to the selected ac item

View file

@ -57,7 +57,7 @@
<select name="selectClassGroup" id="selectClassGroup" role="combobox"> <select name="selectClassGroup" id="selectClassGroup" role="combobox">
<option value="-1" role="option">${i18n().select_one}</option> <option value="-1" role="option">${i18n().select_one}</option>
<#list classGroups as aClassGroup> <#list classGroups as aClassGroup>
<option value="${aClassGroup.URI}" <#if aClassGroup.URI = associatedPageURI!"">selected</#if> role="option">${aClassGroup.publicName}</option> <option value="${aClassGroup.URI}" <#if aClassGroup.URI = associatedPageURI>selected</#if> role="option">${aClassGroup.publicName}</option>
</#list> </#list>
</select> </select>
</section> </section>