NIHVIVO-1333 Moved dao methods for constructing lists of data properties and object properties for an individual into their own dao classes
This commit is contained in:
parent
2fe2a52256
commit
5cc801ee2c
22 changed files with 331 additions and 194 deletions
|
@ -46,6 +46,12 @@ public interface Individual extends ResourceBean, VitroTimeWindowedResource, Com
|
|||
List<ObjectProperty> getObjectPropertyList();
|
||||
void setPropertyList(List<ObjectProperty> propertyList);
|
||||
|
||||
/*
|
||||
* RY These duplicate the functionality of getObjectPropertyList(),
|
||||
* but get data through a sparql query rather than dao methods. They
|
||||
* use a different field so as not to disrupt any code that depends on
|
||||
* the propertyList field. The two approaches should be integrated at a later point.
|
||||
*/
|
||||
List<ObjectProperty> getPopulatedObjectPropertyList();
|
||||
void setPopulatedObjectPropertyList(List<ObjectProperty> propertyList);
|
||||
|
||||
|
@ -55,6 +61,12 @@ public interface Individual extends ResourceBean, VitroTimeWindowedResource, Com
|
|||
List<DataProperty> getDataPropertyList();
|
||||
void setDatatypePropertyList(List<DataProperty> datatypePropertyList);
|
||||
|
||||
/*
|
||||
* RY These duplicate the functionality of getDataPropertyList(),
|
||||
* but get data through a sparql query rather than dao methods. They
|
||||
* use a different field so as not to disrupt any code that depends on
|
||||
* the datatypePropertyList field. The two approaches should be integrated at a later point.
|
||||
*/
|
||||
List<DataProperty> getPopulatedDataPropertyList();
|
||||
void setPopulatedDataPropertyList(List<DataProperty> dataPropertyList);
|
||||
|
||||
|
|
|
@ -35,8 +35,5 @@ public interface DataPropertyDao extends PropertyDao {
|
|||
List<DataProperty> getRootDataProperties();
|
||||
|
||||
boolean annotateDataPropertyAsExternalIdentifier(String dataPropertyURI);
|
||||
|
||||
public List<DataProperty> getDataPropertyList(Individual subject);
|
||||
|
||||
public List<DataProperty> getDataPropertyList(String subjectUri);
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
|
||||
public interface DataPropertyListDao extends PropertyListDao {
|
||||
|
||||
public List<DataProperty> getDataPropertyList(Individual subject);
|
||||
|
||||
public List<DataProperty> getDataPropertyList(String subjectUri);
|
||||
|
||||
}
|
|
@ -51,8 +51,5 @@ public interface ObjectPropertyDao extends PropertyDao {
|
|||
// List /* of ObjectProperty */ getAllObjectProperties();
|
||||
|
||||
List <ObjectProperty> getRootObjectProperties();
|
||||
|
||||
public List<ObjectProperty> getObjectPropertyList(Individual subject);
|
||||
|
||||
public List<ObjectProperty> getObjectPropertyList(String subjectUri);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
|
||||
public interface ObjectPropertyListDao extends PropertyListDao {
|
||||
|
||||
public List<ObjectProperty> getObjectPropertyList(Individual subject);
|
||||
|
||||
public List<ObjectProperty> getObjectPropertyList(String subjectUri);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao;
|
||||
|
||||
public interface PropertyListDao {
|
||||
|
||||
// Get rid of this interface if it doesn't declare any methods
|
||||
}
|
|
@ -132,4 +132,8 @@ public interface WebappDaoFactory {
|
|||
public NamespaceDao getNamespaceDao();
|
||||
|
||||
public PropertyInstanceDao getPropertyInstanceDao();
|
||||
|
||||
public ObjectPropertyListDao getObjectPropertyListDao();
|
||||
|
||||
public DataPropertyListDao getDataPropertyListDao();
|
||||
}
|
||||
|
|
|
@ -192,16 +192,4 @@ class DataPropertyDaoFiltering extends BaseFiltering implements DataPropertyDao{
|
|||
return innerDataPropertyDao.getClassesWithRestrictionOnProperty(propertyURI);
|
||||
}
|
||||
|
||||
@Override
|
||||
// This may need to be filtered at some point.
|
||||
public List<DataProperty> getDataPropertyList(Individual subject) {
|
||||
return innerDataPropertyDao.getDataPropertyList(subject);
|
||||
}
|
||||
|
||||
@Override
|
||||
// This may need to be filtered at some point.
|
||||
public List<DataProperty> getDataPropertyList(String subjectUri) {
|
||||
return innerDataPropertyDao.getDataPropertyList(subjectUri);
|
||||
}
|
||||
|
||||
}
|
|
@ -13,6 +13,8 @@ import java.util.Map;
|
|||
|
||||
import net.sf.jga.algorithms.Filter;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
@ -27,6 +29,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.ObjectPropertyListDaoJena;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||
|
||||
/**
|
||||
|
@ -38,6 +41,9 @@ import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
|||
*
|
||||
*/
|
||||
public class IndividualFiltering implements Individual {
|
||||
|
||||
protected static final Log log = LogFactory.getLog(IndividualFiltering.class);
|
||||
|
||||
private final Individual _innerIndividual;
|
||||
private final VitroFilters _filters;
|
||||
|
||||
|
@ -74,20 +80,6 @@ public class IndividualFiltering implements Individual {
|
|||
List<DataProperty> dprops = _innerIndividual.getPopulatedDataPropertyList();
|
||||
LinkedList<DataProperty> outdProps = new LinkedList<DataProperty>();
|
||||
Filter.filter(dprops,_filters.getDataPropertyFilter(), outdProps);
|
||||
|
||||
ListIterator<DataProperty> it = outdProps.listIterator();
|
||||
while(it.hasNext()){
|
||||
DataProperty dp = it.next();
|
||||
List<DataPropertyStatement> filteredStmts =
|
||||
new LinkedList<DataPropertyStatement>();
|
||||
Filter.filter(dp.getDataPropertyStatements(),
|
||||
_filters.getDataPropertyStatementFilter(),filteredStmts);
|
||||
if( filteredStmts == null || filteredStmts.size() == 0 ){
|
||||
it.remove();
|
||||
}else{
|
||||
dp.setDataPropertyStatements(filteredStmts);
|
||||
}
|
||||
}
|
||||
return outdProps;
|
||||
}
|
||||
|
||||
|
|
|
@ -203,15 +203,4 @@ class ObjectPropertyDaoFiltering extends BaseFiltering implements ObjectProperty
|
|||
return innerObjectPropertyDao.getClassesWithRestrictionOnProperty(propertyURI);
|
||||
}
|
||||
|
||||
@Override
|
||||
// This may need to be filtered at some point.
|
||||
public List<ObjectProperty> getObjectPropertyList(Individual subject) {
|
||||
return innerObjectPropertyDao.getObjectPropertyList(subject);
|
||||
}
|
||||
|
||||
@Override
|
||||
// This may need to be filtered at some point.
|
||||
public List<ObjectProperty> getObjectPropertyList(String subjectUri) {
|
||||
return innerObjectPropertyDao.getObjectPropertyList(subjectUri);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Set;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.ApplicationDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.Classes2ClassesDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyListDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DatatypeDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.FlagDao;
|
||||
|
@ -19,6 +20,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.LinksDao;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.LinktypeDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.NamespaceDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyListDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.PortalDao;
|
||||
|
@ -213,6 +215,14 @@ public class WebappDaoFactoryFiltering implements WebappDaoFactory {
|
|||
public PortalDao getPortalDao() {
|
||||
return innerWebappDaoFactory.getPortalDao();
|
||||
}
|
||||
|
||||
public ObjectPropertyListDao getObjectPropertyListDao() {
|
||||
return innerWebappDaoFactory.getObjectPropertyListDao();
|
||||
}
|
||||
|
||||
public DataPropertyListDao getDataPropertyListDao() {
|
||||
return innerWebappDaoFactory.getDataPropertyListDao();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
|
@ -61,27 +61,6 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
|
|||
|
||||
protected static final Log log = LogFactory.getLog(DataPropertyDaoJena.class.getName());
|
||||
|
||||
protected static final String dataPropertyQueryString =
|
||||
PREFIXES + "\n" +
|
||||
"SELECT DISTINCT ?predicate WHERE { \n" +
|
||||
//" GRAPH ?g {\n" +
|
||||
" ?subject ?predicate ?object . \n" +
|
||||
" ?predicate rdf:type owl:DatatypeProperty . \n" +
|
||||
//" OPTIONAL { ?predicate vitro:inPropertyGroupAnnot ?group } . \n" +
|
||||
//" }\n" +
|
||||
"}" +
|
||||
"ORDER BY ?predicate\n";
|
||||
|
||||
static protected Query dataPropertyQuery;
|
||||
static {
|
||||
try {
|
||||
dataPropertyQuery = QueryFactory.create(dataPropertyQueryString);
|
||||
} catch(Throwable th){
|
||||
log.error("could not create SPARQL query for dataPropertyQueryString " + th.getMessage());
|
||||
log.error(dataPropertyQueryString);
|
||||
}
|
||||
}
|
||||
|
||||
private class DataPropertyRanker implements Comparator {
|
||||
public int compare (Object o1, Object o2) {
|
||||
DataProperty dp1 = (DataProperty) o1;
|
||||
|
@ -709,30 +688,4 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
|
|||
return rootProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataProperty> getDataPropertyList(Individual subject) {
|
||||
return getDataPropertyList(subject.getURI());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataProperty> getDataPropertyList(String subjectUri) {
|
||||
log.debug("dataPropertyQuery:\n" + dataPropertyQuery);
|
||||
ResultSet results = getPropertyQueryResults(subjectUri, dataPropertyQuery);
|
||||
List<DataProperty> properties = new ArrayList<DataProperty>();
|
||||
while (results.hasNext()) {
|
||||
QuerySolution sol = results.next();
|
||||
Resource resource = sol.getResource("predicate");
|
||||
// This is a hack to throw out properties in the vitro, rdf, rdfs, and owl namespaces.
|
||||
// It will be implemented in a better way in v1.3 (Editing and Display Configuration).
|
||||
// It must be done here rather than in PropertyList or PropertyListBuilder, because
|
||||
// those properties must be removed for the IndividualFiltering object.
|
||||
if ( ! EXCLUDED_NAMESPACES.contains(resource.getNameSpace())) {
|
||||
String uri = resource.getURI();
|
||||
DataProperty property = getDataPropertyByURI(uri);
|
||||
properties.add(property);
|
||||
}
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.query.Query;
|
||||
import com.hp.hpl.jena.query.QueryFactory;
|
||||
import com.hp.hpl.jena.query.QuerySolution;
|
||||
import com.hp.hpl.jena.query.ResultSet;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyListDao;
|
||||
|
||||
public class DataPropertyListDaoJena extends PropertyListDaoJena implements
|
||||
DataPropertyListDao {
|
||||
|
||||
protected static final Log log = LogFactory.getLog(DataPropertyListDaoJena.class);
|
||||
|
||||
protected static final String dataPropertyQueryString =
|
||||
PREFIXES + "\n" +
|
||||
"SELECT DISTINCT ?predicate WHERE { \n" +
|
||||
//" GRAPH ?g {\n" +
|
||||
" ?subject ?predicate ?object . \n" +
|
||||
" ?predicate rdf:type owl:DatatypeProperty . \n" +
|
||||
//" }\n" +
|
||||
"}" +
|
||||
"ORDER BY ?predicate\n";
|
||||
|
||||
static protected Query dataPropertyQuery;
|
||||
static {
|
||||
try {
|
||||
dataPropertyQuery = QueryFactory.create(dataPropertyQueryString);
|
||||
} catch(Throwable th){
|
||||
log.error("could not create SPARQL query for dataPropertyQueryString " + th.getMessage());
|
||||
log.error(dataPropertyQueryString);
|
||||
}
|
||||
}
|
||||
|
||||
public DataPropertyListDaoJena(WebappDaoFactoryJena wadf) {
|
||||
super(wadf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataProperty> getDataPropertyList(Individual subject) {
|
||||
return getDataPropertyList(subject.getURI());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataProperty> getDataPropertyList(String subjectUri) {
|
||||
log.debug("dataPropertyQuery:\n" + dataPropertyQuery);
|
||||
ResultSet results = getPropertyQueryResults(subjectUri, dataPropertyQuery);
|
||||
List<DataProperty> properties = new ArrayList<DataProperty>();
|
||||
while (results.hasNext()) {
|
||||
QuerySolution sol = results.next();
|
||||
Resource resource = sol.getResource("predicate");
|
||||
// This is a hack to throw out properties in the vitro, rdf, rdfs, and owl namespaces.
|
||||
// It will be implemented in a better way in v1.3 (Editing and Display Configuration).
|
||||
// It must be done here rather than in PropertyList or PropertyListBuilder, because
|
||||
// those properties must be removed for the IndividualFiltering object.
|
||||
if ( ! EXCLUDED_NAMESPACES.contains(resource.getNameSpace())) {
|
||||
String uri = resource.getURI();
|
||||
DataPropertyDao dpDao = getWebappDaoFactory().getDataPropertyDao();
|
||||
DataProperty property = dpDao.getDataPropertyByURI(uri);
|
||||
properties.add(property);
|
||||
}
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
|
@ -740,7 +740,7 @@ public class IndividualJena extends IndividualImpl implements Individual {
|
|||
@Override
|
||||
public List<ObjectProperty> getPopulatedObjectPropertyList() {
|
||||
if (populatedObjectPropertyList == null) {
|
||||
populatedObjectPropertyList = webappDaoFactory.getObjectPropertyDao().getObjectPropertyList(this);
|
||||
populatedObjectPropertyList = webappDaoFactory.getObjectPropertyListDao().getObjectPropertyList(this);
|
||||
}
|
||||
return populatedObjectPropertyList;
|
||||
}
|
||||
|
@ -794,7 +794,7 @@ public class IndividualJena extends IndividualImpl implements Individual {
|
|||
@Override
|
||||
public List<DataProperty> getPopulatedDataPropertyList() {
|
||||
if (populatedDataPropertyList == null) {
|
||||
populatedDataPropertyList = webappDaoFactory.getDataPropertyDao().getDataPropertyList(this);
|
||||
populatedDataPropertyList = webappDaoFactory.getDataPropertyListDao().getDataPropertyList(this);
|
||||
}
|
||||
return populatedDataPropertyList;
|
||||
}
|
||||
|
|
|
@ -884,7 +884,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
@Override
|
||||
public List<ObjectProperty> getPopulatedObjectPropertyList() {
|
||||
if (populatedObjectPropertyList == null) {
|
||||
populatedObjectPropertyList = webappDaoFactory.getObjectPropertyDao().getObjectPropertyList(this);
|
||||
populatedObjectPropertyList = webappDaoFactory.getObjectPropertyListDao().getObjectPropertyList(this);
|
||||
}
|
||||
return populatedObjectPropertyList;
|
||||
}
|
||||
|
@ -938,7 +938,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
@Override
|
||||
public List<DataProperty> getPopulatedDataPropertyList() {
|
||||
if (populatedDataPropertyList == null) {
|
||||
populatedDataPropertyList = webappDaoFactory.getDataPropertyDao().getDataPropertyList(this);
|
||||
populatedDataPropertyList = webappDaoFactory.getDataPropertyListDao().getDataPropertyList(this);
|
||||
}
|
||||
return populatedDataPropertyList;
|
||||
}
|
||||
|
|
|
@ -872,7 +872,7 @@ public class IndividualSDB2 extends IndividualImpl implements Individual {
|
|||
@Override
|
||||
public List<ObjectProperty> getPopulatedObjectPropertyList() {
|
||||
if (populatedObjectPropertyList == null) {
|
||||
populatedObjectPropertyList = webappDaoFactory.getObjectPropertyDao().getObjectPropertyList(this);
|
||||
populatedObjectPropertyList = webappDaoFactory.getObjectPropertyListDao().getObjectPropertyList(this);
|
||||
}
|
||||
return populatedObjectPropertyList;
|
||||
}
|
||||
|
@ -922,6 +922,14 @@ public class IndividualSDB2 extends IndividualImpl implements Individual {
|
|||
return this.datatypePropertyList;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataProperty> getPopulatedDataPropertyList() {
|
||||
if (populatedDataPropertyList == null) {
|
||||
populatedDataPropertyList = webappDaoFactory.getDataPropertyListDao().getDataPropertyList(this);
|
||||
}
|
||||
return populatedDataPropertyList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String,DataProperty> getDataPropertyMap() {
|
||||
|
|
|
@ -47,27 +47,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
|||
|
||||
public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectPropertyDao {
|
||||
private static final Log log = LogFactory.getLog(ObjectPropertyDaoJena.class.getName());
|
||||
|
||||
protected static final String objectPropertyQueryString =
|
||||
PREFIXES + "\n" +
|
||||
"SELECT DISTINCT ?predicate WHERE { \n" +
|
||||
//" GRAPH ?g {\n" +
|
||||
" ?subject ?predicate ?object . \n" +
|
||||
" ?predicate rdf:type owl:ObjectProperty . \n" +
|
||||
//" OPTIONAL { ?predicate vitro:inPropertyGroupAnnot ?group } . \n" +
|
||||
//" }\n" +
|
||||
"}" +
|
||||
"ORDER BY ?predicate\n";
|
||||
|
||||
static protected Query objectPropertyQuery;
|
||||
static {
|
||||
try {
|
||||
objectPropertyQuery = QueryFactory.create(objectPropertyQueryString);
|
||||
} catch(Throwable th){
|
||||
log.error("could not create SPARQL query for objectPropertyQueryString " + th.getMessage());
|
||||
log.error(objectPropertyQueryString);
|
||||
}
|
||||
}
|
||||
|
||||
public ObjectPropertyDaoJena(WebappDaoFactoryJena wadf) {
|
||||
super(wadf);
|
||||
|
@ -825,31 +804,4 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ObjectProperty> getObjectPropertyList(Individual subject) {
|
||||
return getObjectPropertyList(subject.getURI());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ObjectProperty> getObjectPropertyList(String subjectUri) {
|
||||
log.debug("objectPropertyQuery:\n" + objectPropertyQuery);
|
||||
ResultSet results = getPropertyQueryResults(subjectUri, objectPropertyQuery);
|
||||
List<ObjectProperty> properties = new ArrayList<ObjectProperty>();
|
||||
while (results.hasNext()) {
|
||||
QuerySolution sol = results.next();
|
||||
Resource resource = sol.getResource("predicate");
|
||||
// This is a hack to throw out properties in the vitro, rdf, rdfs, and owl namespaces.
|
||||
// It will be implemented in a better way in v1.3 (Editing and Display Configuration).
|
||||
// It must be done here rather than in PropertyList or PropertyListBuilder, because
|
||||
// those properties must be removed for the IndividualFiltering object.
|
||||
if ( ! EXCLUDED_NAMESPACES.contains(resource.getNameSpace())) {
|
||||
String uri = resource.getURI();
|
||||
ObjectProperty property = getObjectPropertyByURI(uri);
|
||||
properties.add(property);
|
||||
}
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.query.Query;
|
||||
import com.hp.hpl.jena.query.QueryFactory;
|
||||
import com.hp.hpl.jena.query.QuerySolution;
|
||||
import com.hp.hpl.jena.query.ResultSet;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyListDao;
|
||||
|
||||
public class ObjectPropertyListDaoJena extends PropertyListDaoJena implements
|
||||
ObjectPropertyListDao {
|
||||
|
||||
protected static final Log log = LogFactory.getLog(ObjectPropertyListDaoJena.class);
|
||||
|
||||
protected static final String objectPropertyQueryString =
|
||||
PREFIXES + "\n" +
|
||||
"SELECT DISTINCT ?predicate WHERE { \n" +
|
||||
//" GRAPH ?g {\n" +
|
||||
" ?subject ?predicate ?object . \n" +
|
||||
" ?predicate rdf:type owl:ObjectProperty . \n" +
|
||||
//" }\n" +
|
||||
"}" +
|
||||
"ORDER BY ?predicate\n";
|
||||
|
||||
protected static Query objectPropertyQuery;
|
||||
static {
|
||||
try {
|
||||
objectPropertyQuery = QueryFactory.create(objectPropertyQueryString);
|
||||
} catch(Throwable th){
|
||||
log.error("could not create SPARQL query for objectPropertyQueryString " + th.getMessage());
|
||||
log.error(objectPropertyQueryString);
|
||||
}
|
||||
}
|
||||
|
||||
public ObjectPropertyListDaoJena(WebappDaoFactoryJena wadf) {
|
||||
super(wadf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ObjectProperty> getObjectPropertyList(Individual subject) {
|
||||
return getObjectPropertyList(subject.getURI());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ObjectProperty> getObjectPropertyList(String subjectUri) {
|
||||
log.debug("objectPropertyQuery:\n" + objectPropertyQuery);
|
||||
ResultSet results = getPropertyQueryResults(subjectUri, objectPropertyQuery);
|
||||
List<ObjectProperty> properties = new ArrayList<ObjectProperty>();
|
||||
while (results.hasNext()) {
|
||||
QuerySolution sol = results.next();
|
||||
Resource resource = sol.getResource("predicate");
|
||||
// This is a hack to throw out properties in the vitro, rdf, rdfs, and owl namespaces.
|
||||
// It will be implemented in a better way in v1.3 (Editing and Display Configuration).
|
||||
// It must be done here rather than in PropertyList or PropertyListBuilder, because
|
||||
// those properties must be removed for the IndividualFiltering object.
|
||||
if ( ! EXCLUDED_NAMESPACES.contains(resource.getNameSpace())) {
|
||||
String uri = resource.getURI();
|
||||
ObjectPropertyDao opDao = getWebappDaoFactory().getObjectPropertyDao();
|
||||
ObjectProperty property = opDao.getObjectPropertyByURI(uri);
|
||||
properties.add(property);
|
||||
}
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
|
@ -40,19 +40,6 @@ 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 PREFIXES =
|
||||
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" +
|
||||
"PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n" +
|
||||
"PREFIX owl: <http://www.w3.org/2002/07/owl#> \n";
|
||||
|
||||
protected static final List<String> EXCLUDED_NAMESPACES = Arrays.asList(
|
||||
"http://vitro.mannlib.cornell.edu/ns/vitro/0.7#",
|
||||
"http://vitro.mannlib.cornell.edu/ns/vitro/public#",
|
||||
"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
|
||||
"http://www.w3.org/2000/01/rdf-schema#",
|
||||
"http://www.w3.org/2002/07/owl#"
|
||||
);
|
||||
|
||||
public PropertyDaoJena(WebappDaoFactoryJena wadf) {
|
||||
super(wadf);
|
||||
|
@ -390,15 +377,5 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
|
|||
|
||||
return classSet;
|
||||
}
|
||||
|
||||
protected ResultSet getPropertyQueryResults(String subjectUri, Query query) {
|
||||
log.debug("SPARQL query:\n" + query.toString());
|
||||
// Bind the subject's uri to the ?subject query term
|
||||
QuerySolutionMap subjectBinding = new QuerySolutionMap();
|
||||
subjectBinding.add("subject", ResourceFactory.createResource(subjectUri));
|
||||
|
||||
// Run the SPARQL query to get the properties
|
||||
QueryExecution qexec = QueryExecutionFactory.create(query, getOntModelSelector().getFullModel(), subjectBinding);
|
||||
return qexec.execSelect();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
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.Query;
|
||||
import com.hp.hpl.jena.query.QueryExecution;
|
||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||
import com.hp.hpl.jena.query.QueryFactory;
|
||||
import com.hp.hpl.jena.query.QuerySolution;
|
||||
import com.hp.hpl.jena.query.QuerySolutionMap;
|
||||
import com.hp.hpl.jena.query.ResultSet;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.PropertyListDao;
|
||||
|
||||
public class PropertyListDaoJena extends JenaBaseDao implements PropertyListDao {
|
||||
|
||||
protected static final Log log = LogFactory.getLog(PropertyListDaoJena.class);
|
||||
|
||||
protected static final String PREFIXES =
|
||||
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" +
|
||||
"PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n" +
|
||||
"PREFIX owl: <http://www.w3.org/2002/07/owl#> \n" +
|
||||
"PREFIX afn: <http://jena.hp1.hp.com/ARQ/function#>";
|
||||
|
||||
/* This may be the intent behind JenaBaseDao.NONUSER_NAMESPACES, but that
|
||||
* value does not contain all of these namespaces.
|
||||
*/
|
||||
protected static final List<String> EXCLUDED_NAMESPACES = Arrays.asList(
|
||||
"http://vitro.mannlib.cornell.edu/ns/vitro/0.7#",
|
||||
"http://vitro.mannlib.cornell.edu/ns/vitro/public#",
|
||||
"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
|
||||
"http://www.w3.org/2000/01/rdf-schema#",
|
||||
"http://www.w3.org/2002/07/owl#"
|
||||
);
|
||||
|
||||
public PropertyListDaoJena(WebappDaoFactoryJena wadf) {
|
||||
super(wadf);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OntModel getOntModel() {
|
||||
return getOntModelSelector().getFullModel();
|
||||
}
|
||||
|
||||
protected ResultSet getPropertyQueryResults(String subjectUri, Query query) {
|
||||
log.debug("SPARQL query:\n" + query.toString());
|
||||
// Bind the subject's uri to the ?subject query term
|
||||
QuerySolutionMap subjectBinding = new QuerySolutionMap();
|
||||
subjectBinding.add("subject", ResourceFactory.createResource(subjectUri));
|
||||
|
||||
// Run the SPARQL query to get the properties
|
||||
QueryExecution qexec = QueryExecutionFactory.create(query, getOntModelSelector().getFullModel(), subjectBinding);
|
||||
return qexec.execSelect();
|
||||
}
|
||||
}
|
|
@ -9,7 +9,6 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import com.hp.hpl.jena.iri.IRI;
|
||||
import com.hp.hpl.jena.iri.IRIFactory;
|
||||
|
@ -30,10 +29,10 @@ import com.hp.hpl.jena.vocabulary.OWL;
|
|||
import com.hp.hpl.jena.vocabulary.RDF;
|
||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ApplicationDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.Classes2ClassesDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyListDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DatatypeDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.FlagDao;
|
||||
|
@ -44,6 +43,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.LinksDao;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.LinktypeDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.NamespaceDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyListDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.PortalDao;
|
||||
|
@ -548,7 +548,23 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
|||
propertyInstanceDao = new PropertyInstanceDaoJena(this);
|
||||
return propertyInstanceDao;
|
||||
}
|
||||
|
||||
private ObjectPropertyListDao objectPropertyListDao = null;
|
||||
public ObjectPropertyListDao getObjectPropertyListDao() {
|
||||
if (objectPropertyListDao == null) {
|
||||
objectPropertyListDao = new ObjectPropertyListDaoJena(this);
|
||||
}
|
||||
return objectPropertyListDao;
|
||||
}
|
||||
|
||||
private DataPropertyListDao DataPropertyListDao = null;
|
||||
public DataPropertyListDao getDataPropertyListDao() {
|
||||
if (DataPropertyListDao == null) {
|
||||
DataPropertyListDao = new DataPropertyListDaoJena(this);
|
||||
}
|
||||
return DataPropertyListDao;
|
||||
}
|
||||
|
||||
protected VClassDao vClassDao = null;
|
||||
public VClassDao getVClassDao() {
|
||||
if( vClassDao == null )
|
||||
|
|
|
@ -35,16 +35,10 @@ public class PropertyList extends BaseTemplateModel {
|
|||
PropertyList() {
|
||||
propertyList = new ArrayList<PropertyTemplateModel>();
|
||||
}
|
||||
|
||||
|
||||
protected void addObjectProperties(List<ObjectProperty> propertyList) {
|
||||
for (ObjectProperty op : propertyList) {
|
||||
// This is a hack to throw out properties in the vitro, rdf, rdfs, and owl namespaces.
|
||||
// It will be implemented in a better way in v1.3 (Editing and Display Configuration).
|
||||
//if (! EXCLUDED_NAMESPACES.contains(op.getNamespace())) {
|
||||
add(op);
|
||||
//} else {
|
||||
// log.debug("Excluded " + op.getURI() + " from displayed property list on the basis of namespace");
|
||||
//}
|
||||
for (ObjectProperty op : propertyList) {
|
||||
add(op);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,7 +48,7 @@ public class PropertyList extends BaseTemplateModel {
|
|||
|
||||
protected void addDataProperties(List<DataProperty> propertyList) {
|
||||
for (DataProperty dp : propertyList) {
|
||||
add(dp);
|
||||
add(dp);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,20 +130,6 @@ public class PropertyList extends BaseTemplateModel {
|
|||
}
|
||||
}
|
||||
|
||||
// private void addUnique(Property p) {
|
||||
// if (! contains(p)) {
|
||||
// add(p);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// protected void add(Property p) {
|
||||
// if (p instanceof ObjectProperty) {
|
||||
// add((ObjectProperty) p);
|
||||
// } else if (p instanceof DataProperty) {
|
||||
// add((DataProperty) p);
|
||||
// }
|
||||
// }
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void sort(VitroRequest vreq) {
|
||||
try {
|
||||
|
|
Loading…
Add table
Reference in a new issue