support for domain qualification in property config

This commit is contained in:
brianjlowe 2013-08-29 10:58:34 -04:00
parent 43c47d0a55
commit e3d6e37ab9
14 changed files with 129 additions and 57 deletions

View file

@ -15,7 +15,7 @@ public interface ObjectPropertyDao extends PropertyDao {
public ObjectProperty getObjectPropertyByURI(String objectPropertyURI);
public ObjectProperty getObjectPropertyByURIAndRangeURI(String objectPropertyURI, String rangeURI);
public ObjectProperty getObjectPropertyByURIs(String objectPropertyURI, String domainURI, String rangeURI);
public List <ObjectProperty> getObjectPropertiesForObjectPropertyStatements(List /*of ObjectPropertyStatement */ objectPropertyStatements);

View file

@ -49,8 +49,8 @@ class ObjectPropertyDaoFiltering extends BaseFiltering implements ObjectProperty
return (newOprop == null) ? null : new ObjectPropertyFiltering(newOprop, filters);
}
public ObjectProperty getObjectPropertyByURIAndRangeURI(String objectPropertyURI, String rangeURI) {
ObjectProperty newOprop=innerObjectPropertyDao.getObjectPropertyByURIAndRangeURI(objectPropertyURI, rangeURI);
public ObjectProperty getObjectPropertyByURIs(String objectPropertyURI, String domainURI, String rangeURI) {
ObjectProperty newOprop=innerObjectPropertyDao.getObjectPropertyByURIs(objectPropertyURI, domainURI, rangeURI);
return (newOprop == null) ? null : new ObjectPropertyFiltering(newOprop, filters);
}

View file

@ -284,19 +284,28 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
}
}
public ObjectProperty getObjectPropertyByURIAndRangeURI(String propertyURI, String rangeURI) {
public ObjectProperty getObjectPropertyByURIs(String propertyURI, String domainURI, String rangeURI) {
if(log.isDebugEnabled()) {
log.debug("Getting " + propertyURI + " with domain " + domainURI + " and range " + rangeURI);
}
ObjectProperty op = getObjectPropertyByURI(propertyURI);
if (op == null || rangeURI == null) {
return op;
}
op.setDomainVClassURI(domainURI);
op.setRangeVClassURI(rangeURI);
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" +
"SELECT ?range ?label ?group ?customForm ?displayLevel ?updateLevel WHERE { \n" +
" ?context config:configContextFor <" + propertyURI + "> . \n" +
" ?context config:qualifiedBy <" + rangeURI + "> . \n" +
" ?context config:hasConfiguration ?configuration . \n" +
" ?context config:configContextFor <" + propertyURI + "> . \n";
if (domainURI != null) {
propQuery += " ?context config:qualifiedByDomain <" + domainURI + "> . \n";
};
if (rangeURI != null) {
propQuery += " ?context config:qualifiedBy <" + rangeURI + "> . \n";
};
propQuery += " ?context config:hasConfiguration ?configuration . \n" +
" OPTIONAL { ?configuration config:propertyGroup ?group } \n" +
" OPTIONAL { ?configuration config:displayName ?label } \n" +
" OPTIONAL { ?configuration vitro:customEntryFormAnnot ?customForm } \n" +

View file

@ -34,6 +34,7 @@ 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.sparql.resultset.ResultSetMem;
import com.hp.hpl.jena.vocabulary.OWL;
@ -52,6 +53,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
protected static final Log log = LogFactory.getLog(PropertyDaoJena.class.getName());
protected static final String FAUX_PROPERTY_FLAG = "FAUX";
private static final Map<String, String> NAMESPACES = new HashMap<String, String>() {{
put("afn", VitroVocabulary.AFN);
@ -329,7 +331,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
public List <VClass> getClassesWithRestrictionOnProperty(String propertyURI) {
if (propertyURI == null) {
log.info("getClassesWithRestrictionOnProperty: called with null propertyURI");
log.warn("getClassesWithRestrictionOnProperty: called with null propertyURI");
return null;
}
@ -524,15 +526,8 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
}
}
List<PropertyInstance> piList = getAllPropInstByVClasses(vclasses);
return getAllPropInstByVClasses(vclasses);
for (PropertyInstance pi : piList) {
pi.setDomainClassURI(ind.getVClassURI());
// TODO: improve. This is so the DWR property editing passes the
// individual's VClass to get the right restrictions
}
return piList;
}
/*
@ -737,12 +732,36 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
: (op.getRange() == null && foundRanges[1] != null)
? foundRanges[1]
: op.getRange();
propInsts.add(getPropInstForPropertyAndRange(op, rangeRes, applicableProperties));
List<String> additionalFauxSubpropertyRangeURIs = getAdditionalFauxSubpropertyRangeURIsForPropertyURI(propertyURI);
for (String rangeURI : additionalFauxSubpropertyRangeURIs) {
if (rangeRes == null || getWebappDaoFactory().getVClassDao().isSubClassOf(rangeURI, rangeRes.getURI())) {
propInsts.add(getPropInstForPropertyAndRange(
op, ResourceFactory.createResource(rangeURI), applicableProperties));
Resource domainRes = op.getDomain();
propInsts.add(getPropInst(
op, domainRes, rangeRes, applicableProperties));
List<Pair<String,String>> additionalFauxSubpropertyDomainAndRangeURIs =
getAdditionalFauxSubpropertyDomainAndRangeURIsForPropertyURI(
propertyURI);
for (Pair<String,String> domainAndRangeURIs :
additionalFauxSubpropertyDomainAndRangeURIs) {
boolean applicablePropInst = false;
if (rangeRes == null ||
!getWebappDaoFactory().getVClassDao().isSubClassOf(
rangeRes.getURI(), domainAndRangeURIs.getRight())) {
if (domainAndRangeURIs.getLeft() == null) {
applicablePropInst = true;
} else {
for(VClass vclass : vclasses) {
if (vclass.getURI() != null && vclass.getURI().equals(
domainAndRangeURIs.getLeft())) {
applicablePropInst = true;
break;
}
}
}
if (applicablePropInst) {
propInsts.add(getPropInst(
op,
ResourceFactory.createResource(domainAndRangeURIs.getLeft()),
ResourceFactory.createResource(domainAndRangeURIs.getRight()),
applicableProperties));
}
}
}
}
@ -755,10 +774,16 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
}
private PropertyInstance getPropInstForPropertyAndRange(OntProperty op, Resource rangeRes,
private PropertyInstance getPropInst(OntProperty op, Resource domainRes, Resource rangeRes,
Map<String, Resource[]> applicableProperties) {
if (log.isDebugEnabled() && domainRes != null && rangeRes != null) {
log.debug("getPropInst() op: " + op.getURI() + " domain: " +
domainRes.getURI() + " range: " + rangeRes.getURI());
}
PropertyInstance pi = new PropertyInstance();
String domainURIStr = getURIStr(op.getDomain());
String domainURIStr = (domainRes != null && !domainRes.isAnon()) ?
domainURIStr = domainRes.getURI()
: null;
if (rangeRes == null) {
pi.setRangeClassURI(OWL.Thing.getURI()); // TODO see above
} else {
@ -780,14 +805,16 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
pi.setRangeClassName(range.getName());
}
pi.setDomainClassURI(domainURIStr);
VClass domain = getWebappDaoFactory().getVClassDao()
.getVClassByURI(domainURIStr);
if (domain == null) {
domain = new VClass();
domain.setURI(domainURIStr);
domain.setName(domain.getLocalName());
if (domainURIStr != null) {
VClass domain = getWebappDaoFactory().getVClassDao()
.getVClassByURI(domainURIStr);
if (domain == null) {
domain = new VClass();
domain.setURI(domainURIStr);
domain.setName(domain.getLocalName());
}
pi.setDomainClassName(domain.getName());
}
pi.setDomainClassName(domain.getName());
pi.setSubjectSide(true);
pi.setPropertyURI(op.getURI());
pi.setPropertyName(getLabelOrId(op)); // TODO
@ -796,14 +823,15 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
return pi;
}
private List<String> getAdditionalFauxSubpropertyRangeURIsForPropertyURI(String propertyURI) {
List<String> rangeURIs = new ArrayList<String>();
private List<Pair<String,String>> getAdditionalFauxSubpropertyDomainAndRangeURIsForPropertyURI(String propertyURI) {
List<Pair<String,String>> domainAndRangeURIs = new ArrayList<Pair<String,String>>();
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" +
"SELECT ?range WHERE { \n" +
"SELECT ?domain ?range WHERE { \n" +
" ?context config:configContextFor <" + propertyURI + "> . \n" +
" ?context config:qualifiedBy ?range . \n" +
" OPTIONAL { ?context config:qualifiedByDomain ?domain } \n" +
"}";
Query q = QueryFactory.create(propQuery);
@ -813,12 +841,18 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
while (rs.hasNext()) {
QuerySolution qsoln = rs.nextSolution();
Resource rangeRes = qsoln.getResource("range");
rangeURIs.add(rangeRes.getURI());
String rangeURI = rangeRes.getURI();
Resource domainRes = qsoln.getResource("domain");
String domainURI = null;
if (domainRes != null && !domainRes.isAnon()) {
domainURI = domainRes.getURI();
}
domainAndRangeURIs.add(new Pair<String,String>(domainURI, rangeURI));
}
} finally {
qe.close();
}
return rangeURIs;
return domainAndRangeURIs;
}
private String getURIStr(Resource res) {

View file

@ -1093,11 +1093,8 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
OntModel ontModel = getOntModel();
try {
ontModel.enterCriticalSection(Lock.READ);
OntClass oc1 = getOntClass(ontModel, vclassURI1);
OntClass oc2 = getOntClass(ontModel, vclassURI2);
if (oc1 == null || oc2 == null) {
return false;
}
Resource oc1 = ontModel.getResource(vclassURI1);
Resource oc2 = ontModel.getResource(vclassURI2);
return ontModel.contains(oc1, RDFS.subClassOf, oc2);
} finally {
ontModel.leaveCriticalSection();

View file

@ -53,6 +53,10 @@ public class EditConfigurationUtils {
return vreq.getParameter("objectUri");
}
public static String getDomainUri(VitroRequest vreq) {
return vreq.getParameter("domainUri");
}
public static String getRangeUri(VitroRequest vreq) {
return vreq.getParameter("rangeUri");
}

View file

@ -202,6 +202,7 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
String editConfGeneratorName = null;
String predicateUri = getPredicateUri(vreq);
String domainUri = EditConfigurationUtils.getDomainUri(vreq);
String rangeUri = EditConfigurationUtils.getRangeUri(vreq);
// *** handle the case where the form is specified as a request parameter ***
@ -218,7 +219,7 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
// *** check for a predicate URI in the request
}else if( predicateUri != null && !predicateUri.isEmpty() ){
Property prop = getProperty( predicateUri, rangeUri, vreq);
Property prop = getProperty( predicateUri, domainUri, rangeUri, vreq);
if (prop != null && rangeUri != null) {
editConfGeneratorName = getCustomEntryForm(prop);
} else if( prop != null && prop.getCustomEntryForm() != null ){
@ -258,11 +259,11 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
}
}
private Property getProperty(String predicateUri, String rangeUri, VitroRequest vreq) {
private Property getProperty(String predicateUri, String domainUri, String rangeUri, VitroRequest vreq) {
Property p = null;
try{
p = vreq.getWebappDaoFactory().getObjectPropertyDao().getObjectPropertyByURIAndRangeURI(
predicateUri, rangeUri);
p = vreq.getWebappDaoFactory().getObjectPropertyDao().getObjectPropertyByURIs(
predicateUri, domainUri, rangeUri);
if(p == null) {
p = vreq.getWebappDaoFactory().getDataPropertyDao().getDataPropertyByURI(predicateUri);
}

View file

@ -459,6 +459,7 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
predicateUri,
objectKey,
null,
null,
statementDisplay,
null, vreq);
ReadOnlyBeansWrapper wrapper = new ReadOnlyBeansWrapper();

View file

@ -218,7 +218,7 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
}
listForThisSubclass.add(new ObjectPropertyStatementTemplateModel(subjectUri,
propertyUri, rangeUri, objectKey, map, getTemplateName(), vreq));
propertyUri, domainUri, rangeUri, objectKey, map, getTemplateName(), vreq));
}

View file

@ -190,7 +190,7 @@ public class GroupedPropertyList extends BaseTemplateModel {
if (pi != null) {
if (!alreadyOnObjectPropertyList(
populatedObjectPropertyList, pi)) {
addObjectPropertyToPropertyList(pi.getPropertyURI(), pi.getRangeClassURI(),
addObjectPropertyToPropertyList(pi.getPropertyURI(), pi.getDomainClassURI(), pi.getRangeClassURI(),
propertyList);
}
} else {
@ -206,7 +206,7 @@ public class GroupedPropertyList extends BaseTemplateModel {
// constitute a special case (i.e., included in piDao.getAllPossiblePropInstForIndividual()).
for (String propertyUri : VITRO_PROPS_TO_ADD_TO_LIST) {
if (!alreadyOnPropertyList(propertyList, propertyUri)) {
addObjectPropertyToPropertyList(propertyUri, null, propertyList);
addObjectPropertyToPropertyList(propertyUri, null, null, propertyList);
}
}
}
@ -218,16 +218,29 @@ public class GroupedPropertyList extends BaseTemplateModel {
}
for (ObjectProperty op : opList) {
if (op.getURI() != null && op.getURI().equals(pi.getPropertyURI())) {
return true;
if(op.getDomainVClassURI() == null) {
if(pi.getDomainClassURI() == null) {
return true;
}
} else if (op.getDomainVClassURI().equals(pi.getDomainClassURI())) {
return true;
}
if(op.getRangeVClassURI() == null) {
if (pi.getDomainClassURI() == null) {
return true;
}
} else if (op.getRangeVClassURI().equals(pi.getRangeClassURI())) {
return true;
}
}
}
return false;
}
private void addObjectPropertyToPropertyList(String propertyUri, String rangeUri,
private void addObjectPropertyToPropertyList(String propertyUri, String domainUri, String rangeUri,
List<Property> propertyList) {
ObjectPropertyDao opDao = wdf.getObjectPropertyDao();
ObjectProperty op = opDao.getObjectPropertyByURIAndRangeURI(propertyUri, rangeUri);
ObjectProperty op = opDao.getObjectPropertyByURIs(propertyUri, domainUri, rangeUri);
if (op == null) {
log.error("ObjectProperty op returned null from opDao.getObjectPropertyByURI(" + propertyUri + ")");
} else if (op.getURI() == null) {

View file

@ -33,6 +33,11 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
public ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri, String rangeUri, String objectKey,
Map<String, String> data, String templateName, VitroRequest vreq) {
this (subjectUri, propertyUri, null, rangeUri, objectKey, data, templateName, vreq);
}
public ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri, String domainUri, String rangeUri, String objectKey,
Map<String, String> data, String templateName, VitroRequest vreq) {
super(subjectUri, propertyUri, vreq);
this.data = Collections.unmodifiableMap(new HashMap<String, String>(data));
@ -45,7 +50,7 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
// Do delete url first, since it is used in building edit url
this.deleteUrl = makeDeleteUrl();
this.editUrl = makeEditUrl(ops, rangeUri);
this.editUrl = makeEditUrl(ops, domainUri, rangeUri);
}
private String makeDeleteUrl() {
@ -90,7 +95,7 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
return UrlBuilder.getUrl(EDIT_PATH, params);
}
private String makeEditUrl(ObjectPropertyStatement ops, String rangeUri) {
private String makeEditUrl(ObjectPropertyStatement ops, String domainUri, String rangeUri) {
// Is the edit link suppressed for this property?
if (new EditLinkSuppressor(vreq).isEditLinkSuppressed(propertyUri)) {
return "";
@ -115,6 +120,9 @@ public class ObjectPropertyStatementTemplateModel extends PropertyStatementTempl
params.put("deleteProhibited", "prohibited");
}
if (domainUri != null) {
params.put("domainUri", rangeUri);
}
if (rangeUri != null) {
params.put("rangeUri", rangeUri);
}

View file

@ -89,6 +89,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
setName(op.getDomainPublic());
sortDirection = op.getDomainEntitySortDirection();
domainUri = op.getDomainVClassURI();
rangeUri = op.getRangeVClassURI();
// Get the config for this object property
@ -132,6 +133,9 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
"subjectUri", subjectUri,
"predicateUri", propertyUri);
if (domainUri != null) {
params.put("domainUri", domainUri);
}
if (rangeUri != null) {
params.put("rangeUri", rangeUri);
}

View file

@ -29,6 +29,7 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
protected final VitroRequest vreq;
protected final String subjectUri;
protected final String propertyUri;
protected String domainUri;
protected String rangeUri;
private final String localName;

View file

@ -67,7 +67,7 @@ public class ObjectPropertyDaoStub implements ObjectPropertyDao {
}
@Override
public ObjectProperty getObjectPropertyByURIAndRangeURI(String objectPropertyURI, String rangeURI) {
public ObjectProperty getObjectPropertyByURIs(String objectPropertyURI, String domainURI, String rangeURI) {
return getObjectPropertyByURI(objectPropertyURI);
}