VIVO-774 show list of faux properties on the Property Editing page.
This commit is contained in:
parent
59706a4266
commit
02ac3944e0
8 changed files with 530 additions and 235 deletions
|
@ -0,0 +1,73 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.beans;
|
||||||
|
|
||||||
|
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a specialization on an ObjectProperty, only meaningful for
|
||||||
|
* display.
|
||||||
|
*
|
||||||
|
* Must have a baseURI and a rangeURI. Other fields are optional.
|
||||||
|
*/
|
||||||
|
public class FauxProperty extends BaseResourceBean implements ResourceBean {
|
||||||
|
private final String rangeURI;
|
||||||
|
private final String domainURI;
|
||||||
|
|
||||||
|
private String rangeLabel;
|
||||||
|
private String domainLabel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Arguments are in this order to mimic the relationship: subject ==>
|
||||||
|
* property ==> object
|
||||||
|
*
|
||||||
|
* @param domainURI
|
||||||
|
* URI of the subject class. May be null.
|
||||||
|
* @param baseURI
|
||||||
|
* URI of the property. May not be null.
|
||||||
|
* @param rangeUri
|
||||||
|
* URI of the object class. May not be null.
|
||||||
|
*/
|
||||||
|
public FauxProperty(String domainURI, String baseURI, String rangeURI) {
|
||||||
|
super(Objects.requireNonNull(baseURI, "baseURI may not be null"));
|
||||||
|
this.rangeURI = Objects.requireNonNull(rangeURI,
|
||||||
|
"rangeURI may not be null");
|
||||||
|
this.domainURI = domainURI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRangeURI() {
|
||||||
|
return rangeURI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRangeLabel(String rangeLabel) {
|
||||||
|
this.rangeLabel = rangeLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRangeLabel() {
|
||||||
|
return (rangeLabel == null) ? localName(rangeURI) : rangeLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDomainURI() {
|
||||||
|
return domainURI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDomainLabel(String domainLabel) {
|
||||||
|
this.domainLabel = domainLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDomainLabel() {
|
||||||
|
return (domainLabel == null) ? (domainURI == null ? "null"
|
||||||
|
: localName(domainURI)) : domainLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String localName(String uriString) {
|
||||||
|
try {
|
||||||
|
return createResource(uriString).getLocalName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return uriString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -17,8 +17,10 @@ import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.beans.EditProcessObject;
|
import edu.cornell.mannlib.vedit.beans.EditProcessObject;
|
||||||
import edu.cornell.mannlib.vedit.beans.FormObject;
|
import edu.cornell.mannlib.vedit.beans.FormObject;
|
||||||
|
import edu.cornell.mannlib.vedit.beans.Option;
|
||||||
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.FauxProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
|
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
|
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
|
||||||
|
@ -33,7 +35,8 @@ public class PropertyEditController extends BaseEditController {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(PropertyEditController.class.getName());
|
private static final Log log = LogFactory.getLog(PropertyEditController.class.getName());
|
||||||
|
|
||||||
public void doPost (HttpServletRequest request, HttpServletResponse response) {
|
@Override
|
||||||
|
public void doPost (HttpServletRequest request, HttpServletResponse response) {
|
||||||
if (!isAuthorizedToDisplayPage(request, response,
|
if (!isAuthorizedToDisplayPage(request, response,
|
||||||
SimplePermission.EDIT_ONTOLOGY.ACTION)) {
|
SimplePermission.EDIT_ONTOLOGY.ACTION)) {
|
||||||
return;
|
return;
|
||||||
|
@ -189,11 +192,9 @@ public class PropertyEditController extends BaseEditController {
|
||||||
request.setAttribute("suppressquery","true");
|
request.setAttribute("suppressquery","true");
|
||||||
|
|
||||||
|
|
||||||
boolean FORCE_NEW = true;
|
|
||||||
|
|
||||||
EditProcessObject epo = super.createEpo(request, FORCE_NEW);
|
EditProcessObject epo = super.createEpo(request, FORCE_NEW);
|
||||||
FormObject foo = new FormObject();
|
FormObject foo = new FormObject();
|
||||||
HashMap OptionMap = new HashMap();
|
HashMap<String, List<Option>> OptionMap = new HashMap<>();
|
||||||
foo.setOptionLists(OptionMap);
|
foo.setOptionLists(OptionMap);
|
||||||
epo.setFormObject(foo);
|
epo.setFormObject(foo);
|
||||||
|
|
||||||
|
@ -210,11 +211,18 @@ public class PropertyEditController extends BaseEditController {
|
||||||
sortForPickList(subProps, vreq);
|
sortForPickList(subProps, vreq);
|
||||||
request.setAttribute("subproperties", subProps);
|
request.setAttribute("subproperties", subProps);
|
||||||
|
|
||||||
|
// equivalent properties and faux properties
|
||||||
|
|
||||||
List<ObjectProperty> eqProps = getObjectPropertiesForURIList(
|
List<ObjectProperty> eqProps = getObjectPropertiesForURIList(
|
||||||
opDao.getEquivalentPropertyURIs(p.getURI()), opDao);
|
opDao.getEquivalentPropertyURIs(p.getURI()), opDao);
|
||||||
sortForPickList(eqProps, vreq);
|
sortForPickList(eqProps, vreq);
|
||||||
request.setAttribute("equivalentProperties", eqProps);
|
request.setAttribute("equivalentProperties", eqProps);
|
||||||
|
|
||||||
|
List<FauxProperty> fauxProps = vreq.getUnfilteredAssertionsWebappDaoFactory().getFauxPropertyDao().
|
||||||
|
getFauxPropertiesForBaseUri(p.getURI());
|
||||||
|
sortForPickList(fauxProps, vreq);
|
||||||
|
request.setAttribute("fauxproperties", fauxProps);
|
||||||
|
|
||||||
RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
|
RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
|
||||||
request.setAttribute("epoKey",epo.getKey());
|
request.setAttribute("epoKey",epo.getKey());
|
||||||
request.setAttribute("propertyWebapp", p);
|
request.setAttribute("propertyWebapp", p);
|
||||||
|
@ -232,7 +240,8 @@ public class PropertyEditController extends BaseEditController {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doGet (HttpServletRequest request, HttpServletResponse response) {
|
@Override
|
||||||
|
public void doGet (HttpServletRequest request, HttpServletResponse response) {
|
||||||
doPost(request,response);
|
doPost(request,response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,44 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao;
|
package edu.cornell.mannlib.vitro.webapp.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.FauxProperty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* Utility methods for fetching, storing and manipulating FauxProperty objects.
|
||||||
*/
|
*/
|
||||||
public interface FauxPropertyDao {
|
public interface FauxPropertyDao {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all of the FauxProperties that are based on this URI.
|
||||||
|
*
|
||||||
|
* @return May return an empty list. Never returns null.
|
||||||
|
*/
|
||||||
|
List<FauxProperty> getFauxPropertiesForBaseUri(String uri);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the display model contains a ConfigContext with this URI, get the
|
||||||
|
* FauxProperty that it describes.
|
||||||
|
*
|
||||||
|
* @return May return null.
|
||||||
|
*/
|
||||||
|
FauxProperty getFauxPropertyFromConfigContextUri(String contextUri);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the display model contains a ConfigContext based on these URIs, get
|
||||||
|
* the FauxProperty that it describes. May return null.
|
||||||
|
*
|
||||||
|
* @param domainUri
|
||||||
|
* May be null, but then this will only match a ConfigContext
|
||||||
|
* that has no qualifiedByDomain property.
|
||||||
|
* @param baseUri
|
||||||
|
* Object of configContextFor property. May not be null.
|
||||||
|
* @param rangeUri
|
||||||
|
* Object of qualifiedBy property. May not be null.
|
||||||
|
* @return May return null.
|
||||||
|
*/
|
||||||
|
FauxProperty getFauxPropertyByUris(String domainUri, String baseUri,
|
||||||
|
String rangeUri);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,217 +2,50 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.filtering;
|
package edu.cornell.mannlib.vitro.webapp.dao.filtering;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.FauxProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.FauxPropertyDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.FauxPropertyDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||||
|
|
||||||
class FauxPropertyDaoFiltering extends BaseFiltering implements FauxPropertyDao{
|
/**
|
||||||
final FauxPropertyDao innerFauxPropertyDao;
|
* TODO Find out if this is really necessary. If so, what is filtered?
|
||||||
final VitroFilters filters;
|
*/
|
||||||
|
public class FauxPropertyDaoFiltering extends BaseFiltering implements FauxPropertyDao {
|
||||||
|
final FauxPropertyDao innerFauxPropertyDao;
|
||||||
|
final VitroFilters filters;
|
||||||
|
|
||||||
public FauxPropertyDaoFiltering(FauxPropertyDao fauxPropertyDao,
|
public FauxPropertyDaoFiltering(FauxPropertyDao fauxPropertyDao,
|
||||||
VitroFilters filters) {
|
VitroFilters filters) {
|
||||||
super();
|
super();
|
||||||
this.innerFauxPropertyDao = fauxPropertyDao;
|
this.innerFauxPropertyDao = fauxPropertyDao;
|
||||||
this.filters = filters;
|
this.filters = filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* filtered methods */
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<FauxProperty> getFauxPropertiesForBaseUri(String uri) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new RuntimeException(
|
||||||
|
"FauxPropertyDao.getFauxPropertiesForBaseUri() not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FauxProperty getFauxPropertyFromConfigContextUri(String contextUri) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new RuntimeException(
|
||||||
|
"FauxPropertyDaoFiltering.getFauxPropertyFromConfigContextUri() not implemented.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FauxProperty getFauxPropertyByUris(String domainUri, String baseUri,
|
||||||
|
String rangeUri) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new RuntimeException(
|
||||||
|
"FauxPropertyDaoFiltering.getFauxPropertyByUris() not implemented.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// /* filtered methods */
|
|
||||||
// public List getAllObjectProperties() {
|
|
||||||
// return filterAndWrap(innerFauxPropertyDao.getAllObjectProperties(), filters);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public List getObjectPropertiesForFauxPropertyStatements(List fauxPropertyStatements) {
|
|
||||||
// //assume that the objPropStmts are already filtered
|
|
||||||
// List<FauxProperty> list =
|
|
||||||
// innerFauxPropertyDao
|
|
||||||
// .getObjectPropertiesForFauxPropertyStatements(fauxPropertyStatements);
|
|
||||||
// return filterAndWrap(list, filters);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// public FauxProperty getFauxPropertyByURI(String fauxPropertyURI) {
|
|
||||||
// FauxProperty newOprop=innerFauxPropertyDao.getFauxPropertyByURI(fauxPropertyURI);
|
|
||||||
// return (newOprop == null) ? null : new FauxPropertyFiltering(newOprop, filters);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public FauxProperty getFauxPropertyByURIs(String fauxPropertyURI, String domainURI, String rangeURI) {
|
|
||||||
// FauxProperty newOprop=innerFauxPropertyDao.getFauxPropertyByURIs(fauxPropertyURI, domainURI, rangeURI);
|
|
||||||
// return (newOprop == null) ? null : new FauxPropertyFiltering(newOprop, filters);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public FauxProperty getFauxPropertyByURIs(String fauxPropertyURI, String domainURI, String rangeURI, FauxProperty base) {
|
|
||||||
// FauxProperty newOprop=innerFauxPropertyDao.getFauxPropertyByURIs(fauxPropertyURI, domainURI, rangeURI, base);
|
|
||||||
// return (newOprop == null) ? null : new FauxPropertyFiltering(newOprop, filters);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public List<FauxPropertyStatement> getStatementsUsingFauxProperty(FauxProperty op) {
|
|
||||||
// return FauxPropertyStatementDaoFiltering.filterAndWrapList(innerFauxPropertyDao.getStatementsUsingFauxProperty(op),filters);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public List getRootObjectProperties() {
|
|
||||||
// return filterAndWrap(innerFauxPropertyDao.getRootObjectProperties(),filters);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// /* other methods */
|
|
||||||
// public void deleteFauxProperty(String fauxPropertyURI) {
|
|
||||||
// innerFauxPropertyDao.deleteFauxProperty(fauxPropertyURI);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// public void deleteFauxProperty(FauxProperty fauxProperty) {
|
|
||||||
// innerFauxPropertyDao.deleteFauxProperty(fauxProperty);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// public void fillObjectPropertiesForIndividual(Individual individual) {
|
|
||||||
// innerFauxPropertyDao.fillObjectPropertiesForIndividual(individual);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public int insertFauxProperty(FauxProperty fauxProperty) throws InsertException {
|
|
||||||
// return innerFauxPropertyDao.insertFauxProperty(fauxProperty);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void updateFauxProperty(FauxProperty fauxProperty) {
|
|
||||||
// innerFauxPropertyDao.updateFauxProperty(fauxProperty);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void addSuperproperty(FauxProperty property, FauxProperty superproperty) {
|
|
||||||
// innerFauxPropertyDao.addSuperproperty(property, superproperty);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void addSuperproperty(String propertyURI, String superpropertyURI) {
|
|
||||||
// innerFauxPropertyDao.addSuperproperty(propertyURI, superpropertyURI);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void removeSuperproperty(FauxProperty property, FauxProperty superproperty) {
|
|
||||||
// innerFauxPropertyDao.removeSuperproperty(property, superproperty);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void removeSuperproperty(String propertyURI, String superpropertyURI) {
|
|
||||||
// innerFauxPropertyDao.removeSuperproperty(propertyURI, superpropertyURI);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void addSubproperty(FauxProperty property, FauxProperty subproperty) {
|
|
||||||
// innerFauxPropertyDao.addSubproperty(property, subproperty);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void addSubproperty(String propertyURI, String subpropertyURI) {
|
|
||||||
// innerFauxPropertyDao.addSubproperty(propertyURI, subpropertyURI);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void removeSubproperty(FauxProperty property, FauxProperty subproperty) {
|
|
||||||
// innerFauxPropertyDao.removeSubproperty(property, subproperty);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void removeSubproperty(String propertyURI, String subpropertyURI) {
|
|
||||||
// innerFauxPropertyDao.removeSubproperty(propertyURI, subpropertyURI);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public List <String> getSubPropertyURIs(String propertyURI) {
|
|
||||||
// return innerFauxPropertyDao.getSubPropertyURIs(propertyURI);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public List <String> getAllSubPropertyURIs(String propertyURI) {
|
|
||||||
// return innerFauxPropertyDao.getAllSubPropertyURIs(propertyURI);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public List <String> getSuperPropertyURIs(String propertyURI, boolean direct) {
|
|
||||||
// return innerFauxPropertyDao.getSuperPropertyURIs(propertyURI, direct);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public List <String> getAllSuperPropertyURIs(String propertyURI) {
|
|
||||||
// return innerFauxPropertyDao.getAllSuperPropertyURIs(propertyURI);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public static List<FauxProperty> filterAndWrap(List<FauxProperty> list, VitroFilters filters){
|
|
||||||
// if( list == null ) return null;
|
|
||||||
// if( list.size() ==0 ) return list;
|
|
||||||
//
|
|
||||||
// List<FauxProperty> filtered = new LinkedList<FauxProperty>();
|
|
||||||
// Filter.filter(list,
|
|
||||||
// new AndUnary<FauxProperty>(notNull,filters.getFauxPropertyFilter()),
|
|
||||||
// filtered);
|
|
||||||
//
|
|
||||||
// List<FauxProperty> wrapped = new LinkedList<FauxProperty>();
|
|
||||||
// for( FauxProperty prop : filtered){
|
|
||||||
// if( prop != null){
|
|
||||||
// wrapped.add( new FauxPropertyFiltering(prop, filters));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return wrapped;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private static final UnaryFunctor<FauxProperty,Boolean> notNull =
|
|
||||||
// new UnaryFunctor<FauxProperty,Boolean>(){
|
|
||||||
// @Override
|
|
||||||
// public Boolean fn(FauxProperty arg) {
|
|
||||||
// return arg != null;
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// public void addSubproperty(Property property, Property subproperty) {
|
|
||||||
// innerFauxPropertyDao.addSubproperty(property, subproperty);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void addSuperproperty(Property property, Property superproperty) {
|
|
||||||
// innerFauxPropertyDao.addSuperproperty(property, superproperty);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void removeSubproperty(Property property, Property subproperty) {
|
|
||||||
// innerFauxPropertyDao.removeSubproperty(property, subproperty);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void removeSuperproperty(Property property, Property superproperty) {
|
|
||||||
// innerFauxPropertyDao.removeSuperproperty(property, superproperty);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void addEquivalentProperty(String propertyURI,
|
|
||||||
// String equivalentPropertyURI) {
|
|
||||||
// innerFauxPropertyDao.addEquivalentProperty(propertyURI, equivalentPropertyURI);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void addEquivalentProperty(Property property,
|
|
||||||
// Property equivalentProperty) {
|
|
||||||
// innerFauxPropertyDao.addEquivalentProperty(property, equivalentProperty);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public List<String> getEquivalentPropertyURIs(String propertyURI) {
|
|
||||||
// return innerFauxPropertyDao.getEquivalentPropertyURIs(propertyURI);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void removeEquivalentProperty(String propertyURI,
|
|
||||||
// String equivalentPropertyURI) {
|
|
||||||
// innerFauxPropertyDao.removeEquivalentProperty(propertyURI, equivalentPropertyURI);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void removeEquivalentProperty(Property property,
|
|
||||||
// Property equivalentProperty) {
|
|
||||||
// innerFauxPropertyDao.removeEquivalentProperty(property, equivalentProperty);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public boolean skipEditForm(String predicateURI) {
|
|
||||||
// return innerFauxPropertyDao.skipEditForm(predicateURI);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public List <VClass> getClassesWithRestrictionOnProperty(String propertyURI) {
|
|
||||||
// return innerFauxPropertyDao.getClassesWithRestrictionOnProperty(propertyURI);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// // This may need to be filtered at some point.
|
|
||||||
// public List<FauxProperty> getFauxPropertyList(Individual subject) {
|
|
||||||
// return innerFauxPropertyDao.getFauxPropertyList(subject);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// // This may need to be filtered at some point.
|
|
||||||
// public List<FauxProperty> getFauxPropertyList(String subjectUri) {
|
|
||||||
// return innerFauxPropertyDao.getFauxPropertyList(subjectUri);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public String getCustomListViewConfigFileName(FauxProperty fauxProperty) {
|
|
||||||
// return innerFauxPropertyDao.getCustomListViewConfigFileName(fauxProperty);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,32 +2,330 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
import java.util.Map;
|
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createProperty;
|
||||||
|
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
|
||||||
|
|
||||||
import org.apache.jena.atlas.lib.Pair;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
import com.hp.hpl.jena.query.ResultSet;
|
||||||
|
import com.hp.hpl.jena.query.Syntax;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Property;
|
||||||
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
|
import com.hp.hpl.jena.rdf.model.ResIterator;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
import com.hp.hpl.jena.shared.Lock;
|
||||||
|
import com.hp.hpl.jena.vocabulary.RDF;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.FauxProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.FauxPropertyDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.FauxPropertyDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.adapters.AbstractOntModelDecorator;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.SparqlQueryRunner;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.SparqlQueryRunner.QueryParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* TODO
|
||||||
*/
|
*/
|
||||||
public class FauxPropertyDaoJena implements FauxPropertyDao {
|
public class FauxPropertyDaoJena implements FauxPropertyDao {
|
||||||
|
private static final Log log = LogFactory.getLog(FauxPropertyDaoJena.class);
|
||||||
|
|
||||||
/**
|
// ----------------------------------------------------------------------
|
||||||
* @param rdfService
|
// Constants
|
||||||
* @param dwf
|
// ----------------------------------------------------------------------
|
||||||
* @param customListViewConfigFileMap
|
|
||||||
* @param webappDaoFactoryJena
|
private static final String APPLICATION_CONTEXT_NS = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationConfiguration#";
|
||||||
*/
|
private static final Resource CONFIG_CONTEXT = createResource(APPLICATION_CONTEXT_NS
|
||||||
public FauxPropertyDaoJena(
|
+ "ConfigContext");
|
||||||
RDFService rdfService,
|
private static final Property HAS_CONFIGURATION = createProperty(APPLICATION_CONTEXT_NS
|
||||||
DatasetWrapperFactory dwf,
|
+ "hasConfiguration");
|
||||||
Map<Pair<String, Pair<ObjectProperty, String>>, String> customListViewConfigFileMap,
|
private static final Property CONFIG_CONTEXT_FOR = createProperty(APPLICATION_CONTEXT_NS
|
||||||
WebappDaoFactoryJena webappDaoFactoryJena) {
|
+ "configContextFor");
|
||||||
// TODO Auto-generated constructor stub
|
private static final Property QUALIFIED_BY_RANGE = createProperty(APPLICATION_CONTEXT_NS
|
||||||
throw new RuntimeException("FauxPropertyDaoJena Constructor not implemented.");
|
+ "qualifiedBy");
|
||||||
|
private static final Property QUALIFIED_BY_DOMAIN = createProperty(APPLICATION_CONTEXT_NS
|
||||||
|
+ "qualifiedByDomain");
|
||||||
|
|
||||||
|
private static final Property DISPLAY_NAME = createProperty(APPLICATION_CONTEXT_NS
|
||||||
|
+ "displayName");
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Queries and parsers
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
private static final String QUERY_LOCATE_CONFIG_CONTEXT_WITH_DOMAIN = "" //
|
||||||
|
+ "PREFIX : <http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationConfiguration#> \n" //
|
||||||
|
+ "\n" //
|
||||||
|
+ "SELECT DISTINCT ?context \n" //
|
||||||
|
+ "WHERE { \n" //
|
||||||
|
+ " ?context a :ConfigContext ; \n" //
|
||||||
|
+ " :configContextFor ?baseUri ; \n" //
|
||||||
|
+ " :qualifiedByDomain ?domainUri ; \n" //
|
||||||
|
+ " :qualifiedBy ?rangeUri . \n" //
|
||||||
|
+ "} \n"; //
|
||||||
|
|
||||||
|
// TODO Add a filter that will reject solutions that include qualifiedByDomain
|
||||||
|
private static final String QUERY_LOCATE_CONFIG_CONTEXT_WITH_NO_DOMAIN = "" //
|
||||||
|
+ "PREFIX : <http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationConfiguration#> \n" //
|
||||||
|
+ "\n" //
|
||||||
|
+ "SELECT DISTINCT ?context \n" //
|
||||||
|
+ "WHERE { \n" //
|
||||||
|
+ " ?context a :ConfigContext ; \n" //
|
||||||
|
+ " :configContextFor ?baseUri ; \n" //
|
||||||
|
+ " :qualifiedBy ?rangeUri . \n" //
|
||||||
|
+ "} \n"; //
|
||||||
|
|
||||||
|
private static final QueryParser<String> PARSER_LOCATE_CONFIG_CONTEXT = new QueryParser<String>() {
|
||||||
|
@Override
|
||||||
|
protected String defaultValue() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String parseResults(String queryStr, ResultSet results) {
|
||||||
|
if (results.hasNext()) {
|
||||||
|
return ifResourcePresent(results.next(), "context", null);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// The instance
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
private final LockingOntModelSelector models;
|
||||||
|
|
||||||
|
public FauxPropertyDaoJena(WebappDaoFactoryJena wadf) {
|
||||||
|
this.models = new LockingOntModelSelector(wadf.getOntModelSelector());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<FauxProperty> getFauxPropertiesForBaseUri(String uri) {
|
||||||
|
List<FauxProperty> list = new ArrayList<>();
|
||||||
|
try (LockedOntModel displayModel = models.getDisplayModel().read()) {
|
||||||
|
if (uri != null) {
|
||||||
|
ResIterator contextResources = displayModel
|
||||||
|
.listSubjectsWithProperty(CONFIG_CONTEXT_FOR,
|
||||||
|
createResource(uri));
|
||||||
|
for (Resource context : contextResources.toList()) {
|
||||||
|
if (!context.isURIResource()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
FauxProperty fp = getFauxPropertyFromConfigContextUri(context
|
||||||
|
.getURI());
|
||||||
|
if (fp == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
list.add(fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FauxProperty getFauxPropertyFromConfigContextUri(String contextUri) {
|
||||||
|
try (LockedOntModel displayModel = models.getDisplayModel().read()) {
|
||||||
|
if (contextUri == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Resource context = createResource(contextUri);
|
||||||
|
if (!displayModel.contains(context, RDF.type, CONFIG_CONTEXT)) {
|
||||||
|
log.debug("'" + contextUri + "' is not a CONFIG_CONTEXT");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String baseUri = getUriValue(displayModel, context,
|
||||||
|
CONFIG_CONTEXT_FOR);
|
||||||
|
if (baseUri == null) {
|
||||||
|
log.debug("'" + contextUri + "' has no value for '"
|
||||||
|
+ CONFIG_CONTEXT_FOR + "'");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String rangeUri = getUriValue(displayModel, context,
|
||||||
|
QUALIFIED_BY_RANGE);
|
||||||
|
if (rangeUri == null) {
|
||||||
|
log.debug("'" + contextUri + "' has no value for '"
|
||||||
|
+ QUALIFIED_BY_RANGE + "'");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// domainURI is optional.
|
||||||
|
String domainUri = getUriValue(displayModel, context,
|
||||||
|
QUALIFIED_BY_DOMAIN);
|
||||||
|
|
||||||
|
FauxProperty fp = new FauxProperty(domainUri, baseUri, rangeUri);
|
||||||
|
populateInstance(fp, displayModel, context);
|
||||||
|
return fp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FauxProperty getFauxPropertyByUris(String domainUri, String baseUri,
|
||||||
|
String rangeUri) {
|
||||||
|
try (LockedOntModel displayModel = models.getDisplayModel().read()) {
|
||||||
|
String queryString;
|
||||||
|
if (domainUri == null) {
|
||||||
|
queryString = substituteUri(
|
||||||
|
substituteUri(
|
||||||
|
QUERY_LOCATE_CONFIG_CONTEXT_WITH_NO_DOMAIN,
|
||||||
|
baseUri, "baseUri"), rangeUri, "rangeUri");
|
||||||
|
} else {
|
||||||
|
queryString = substituteUri(
|
||||||
|
substituteUri(
|
||||||
|
substituteUri(
|
||||||
|
QUERY_LOCATE_CONFIG_CONTEXT_WITH_DOMAIN,
|
||||||
|
baseUri, "baseUri"), rangeUri,
|
||||||
|
"rangeUri"), domainUri, "domainUri");
|
||||||
|
}
|
||||||
|
|
||||||
|
String contextUri = new SparqlQueryRunner(displayModel)
|
||||||
|
.executeSelect(PARSER_LOCATE_CONFIG_CONTEXT, queryString);
|
||||||
|
|
||||||
|
if (contextUri == null) {
|
||||||
|
log.debug("Can't find a ContextConfig for '" + domainUri
|
||||||
|
+ "', '" + baseUri + "', '" + rangeUri + "'");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
FauxProperty fp = new FauxProperty(domainUri, baseUri, rangeUri);
|
||||||
|
populateInstance(fp, displayModel, createResource(contextUri));
|
||||||
|
return fp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add labels, annotations, and whatever else we can find on the
|
||||||
|
* ConfigContext.
|
||||||
|
*/
|
||||||
|
private void populateInstance(FauxProperty fp, LockedOntModel model,
|
||||||
|
Resource context) {
|
||||||
|
String configUri = getUriValue(model, context, HAS_CONFIGURATION);
|
||||||
|
if (configUri == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Resource config = createResource(configUri);
|
||||||
|
|
||||||
|
String displayName = getStringValue(model, config, DISPLAY_NAME);
|
||||||
|
if (displayName != null) {
|
||||||
|
fp.setPickListName(displayName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO pull all sorts of things from the configuration.
|
||||||
|
// TODO pull labels for the domain and range classes.
|
||||||
|
}
|
||||||
|
|
||||||
|
private String substituteUri(String queryString, String variableName,
|
||||||
|
String uri) {
|
||||||
|
return queryString.replace("?" + variableName, "<" + uri + ">");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a single URI that is the object of this subject and property.
|
||||||
|
* Returns null if no valid statement is found.
|
||||||
|
*/
|
||||||
|
private String getUriValue(LockedOntModel displayModel, Resource subject,
|
||||||
|
Property property) {
|
||||||
|
List<RDFNode> nodeList = displayModel.listObjectsOfProperty(subject,
|
||||||
|
property).toList();
|
||||||
|
if (nodeList.isEmpty()) {
|
||||||
|
log.warn("'" + subject.getURI() + "' has no value for '"
|
||||||
|
+ property.getURI() + "'.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
RDFNode node = nodeList.get(0);
|
||||||
|
if (nodeList.size() > 1) {
|
||||||
|
log.warn("'" + subject.getURI() + "' has " + nodeList.size()
|
||||||
|
+ " values for ''. Using '" + node + "'");
|
||||||
|
}
|
||||||
|
if (!node.isURIResource()) {
|
||||||
|
log.warn("Value of '" + subject.getURI() + property.getURI()
|
||||||
|
+ "' '' is not a URI resource.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return node.asResource().getURI();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a single String value that is the object of this subject and
|
||||||
|
* property. Returns null if no valid statement is found.
|
||||||
|
*/
|
||||||
|
private String getStringValue(LockedOntModel displayModel,
|
||||||
|
Resource subject, Property property) {
|
||||||
|
List<RDFNode> nodeList = displayModel.listObjectsOfProperty(subject,
|
||||||
|
property).toList();
|
||||||
|
if (nodeList.isEmpty()) {
|
||||||
|
log.warn("'" + subject.getURI() + "' has no value for '"
|
||||||
|
+ property.getURI() + "'.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
RDFNode node = nodeList.get(0);
|
||||||
|
if (nodeList.size() > 1) {
|
||||||
|
log.warn("'" + subject.getURI() + "' has " + nodeList.size()
|
||||||
|
+ " values for ''. Using '" + node + "'");
|
||||||
|
}
|
||||||
|
if (!node.isLiteral()) {
|
||||||
|
log.warn("Value of '" + subject.getURI() + property.getURI()
|
||||||
|
+ "' '' is not a Literal.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return node.asLiteral().getString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Helper classes. Are they worth it, just to use try-with-resources?
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
private static class LockingOntModelSelector {
|
||||||
|
private final OntModelSelector oms;
|
||||||
|
|
||||||
|
public LockingOntModelSelector(OntModelSelector oms) {
|
||||||
|
this.oms = oms;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LockableOntModel getDisplayModel() {
|
||||||
|
return new LockableOntModel(oms.getDisplayModel());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class LockableOntModel {
|
||||||
|
private final OntModel ontModel;
|
||||||
|
|
||||||
|
public LockableOntModel(OntModel ontModel) {
|
||||||
|
this.ontModel = ontModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LockedOntModel read() {
|
||||||
|
ontModel.enterCriticalSection(Lock.READ);
|
||||||
|
return new LockedOntModel(ontModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class LockedOntModel extends AbstractOntModelDecorator
|
||||||
|
implements AutoCloseable {
|
||||||
|
|
||||||
|
protected LockedOntModel(OntModel m) {
|
||||||
|
super(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just unlocks the model. Doesn't actually close it, because we may
|
||||||
|
* want to use it again.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
super.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -379,9 +379,9 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
private FauxPropertyDao fauxPropertyDao = null;
|
private FauxPropertyDao fauxPropertyDao = null;
|
||||||
@Override
|
@Override
|
||||||
public FauxPropertyDao getFauxPropertyDao() {
|
public FauxPropertyDao getFauxPropertyDao() {
|
||||||
if( fauxPropertyDao == null )
|
if( fauxPropertyDao == null ) {
|
||||||
fauxPropertyDao = new FauxPropertyDaoJena(
|
fauxPropertyDao = new FauxPropertyDaoJena(this);
|
||||||
rdfService, dwf, config.customListViewConfigFileMap, this);
|
}
|
||||||
return fauxPropertyDao;
|
return fauxPropertyDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import com.hp.hpl.jena.query.Syntax;
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute SPARQL queries against a model.
|
* Execute SPARQL queries against a model.
|
||||||
|
@ -95,6 +96,15 @@ public class SparqlQueryRunner {
|
||||||
|
|
||||||
protected abstract T defaultValue();
|
protected abstract T defaultValue();
|
||||||
|
|
||||||
|
protected String ifResourcePresent(QuerySolution solution,
|
||||||
|
String variableName, String defaultValue) {
|
||||||
|
RDFNode node = solution.get(variableName);
|
||||||
|
if (node == null || !node.isURIResource()) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
return node.asResource().getURI();
|
||||||
|
}
|
||||||
|
|
||||||
protected String ifLiteralPresent(QuerySolution solution,
|
protected String ifLiteralPresent(QuerySolution solution,
|
||||||
String variableName, String defaultValue) {
|
String variableName, String defaultValue) {
|
||||||
Literal literal = solution.getLiteral(variableName);
|
Literal literal = solution.getLiteral(variableName);
|
||||||
|
|
|
@ -91,6 +91,43 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr><td colspan="3"><hr/></td></tr>
|
||||||
|
<!-- _____________________________________________ faux properties __________________________________________ -->
|
||||||
|
<tr valign="bottom" align="center">
|
||||||
|
<td colspan="2" valign="bottom" align="left">
|
||||||
|
<c:if test="${!empty fauxproperties}">
|
||||||
|
<c:forEach var="fauxproperty" items="${fauxproperties}">
|
||||||
|
<ul style="list-style-type:none;">
|
||||||
|
<c:url var="fauxpropertyURL" value="fauxpropertyEdit">
|
||||||
|
<c:param name="property" value="${property.URI}"/>
|
||||||
|
<c:param name="domain" value="${fauxproperty.domainURI}" />
|
||||||
|
<c:param name="range" value="${fauxproperty.rangeURI}" />
|
||||||
|
</c:url>
|
||||||
|
<li>
|
||||||
|
<a href="${fauxpropertyURL}">${fauxproperty.pickListName}</a>
|
||||||
|
<c:choose>
|
||||||
|
<c:when test="${empty fauxproperty.domainLabel}">
|
||||||
|
no domain,
|
||||||
|
</c:when>
|
||||||
|
<c:otherwise>
|
||||||
|
domain: ${fauxproperty.domainLabel},
|
||||||
|
</c:otherwise>
|
||||||
|
</c:choose>
|
||||||
|
range: ${fauxproperty.rangeLabel}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</c:forEach>
|
||||||
|
</c:if>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<form action="editForm" method="get">
|
||||||
|
<input type="hidden" name="basepropertyURI" value="${property.URI}"/>
|
||||||
|
<input type="hidden" name="controller" value="FauxProperty"/>
|
||||||
|
<input type="submit" class="form-button" value="Create New Faux Property"/>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr><td colspan="3"><hr/></td></tr>
|
<tr><td colspan="3"><hr/></td></tr>
|
||||||
<!-- _____________________________________________ superproperties __________________________________________ -->
|
<!-- _____________________________________________ superproperties __________________________________________ -->
|
||||||
<tr valign="bottom" align="center">
|
<tr valign="bottom" align="center">
|
||||||
|
|
Loading…
Add table
Reference in a new issue