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.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

@ -84,6 +84,10 @@ public class AutocompleteController extends VitroAjaxController {
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);