diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Individual.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Individual.java index 3a0825523..bc299f87d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Individual.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Individual.java @@ -46,12 +46,6 @@ public interface Individual extends ResourceBean, VitroTimeWindowedResource, Com List getObjectPropertyList(); void setPropertyList(List 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 getPopulatedObjectPropertyList(); void setPopulatedObjectPropertyList(List propertyList); @@ -61,12 +55,6 @@ public interface Individual extends ResourceBean, VitroTimeWindowedResource, Com List getDataPropertyList(); void setDatatypePropertyList(List 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 getPopulatedDataPropertyList(); void setPopulatedDataPropertyList(List dataPropertyList); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DataPropertyDao.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DataPropertyDao.java index 5c2588de6..02f1c7360 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DataPropertyDao.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DataPropertyDao.java @@ -35,5 +35,8 @@ public interface DataPropertyDao extends PropertyDao { List getRootDataProperties(); boolean annotateDataPropertyAsExternalIdentifier(String dataPropertyURI); - + + public List getDataPropertyList(Individual subject); + + public List getDataPropertyList(String subjectUri); } \ No newline at end of file diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DataPropertyListDao.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DataPropertyListDao.java deleted file mode 100644 index 857fca7ba..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DataPropertyListDao.java +++ /dev/null @@ -1,16 +0,0 @@ -/* $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 getDataPropertyList(Individual subject); - - public List getDataPropertyList(String subjectUri); - -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyDao.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyDao.java index 2347aa386..9a966351b 100755 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyDao.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyDao.java @@ -51,5 +51,8 @@ public interface ObjectPropertyDao extends PropertyDao { // List /* of ObjectProperty */ getAllObjectProperties(); List getRootObjectProperties(); - + + public List getObjectPropertyList(Individual subject); + + public List getObjectPropertyList(String subjectUri); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyListDao.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyListDao.java deleted file mode 100644 index d42b6a0b3..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyListDao.java +++ /dev/null @@ -1,15 +0,0 @@ -/* $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 getObjectPropertyList(Individual subject); - - public List getObjectPropertyList(String subjectUri); -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/PropertyListDao.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/PropertyListDao.java deleted file mode 100644 index c1ced8f61..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/PropertyListDao.java +++ /dev/null @@ -1,8 +0,0 @@ -/* $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 -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactory.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactory.java index b7d8c81f3..897ca9ef8 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactory.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactory.java @@ -132,8 +132,4 @@ public interface WebappDaoFactory { public NamespaceDao getNamespaceDao(); public PropertyInstanceDao getPropertyInstanceDao(); - - public ObjectPropertyListDao getObjectPropertyListDao(); - - public DataPropertyListDao getDataPropertyListDao(); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/DataPropertyDaoFiltering.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/DataPropertyDaoFiltering.java index 628ad4ee3..311fde3d6 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/DataPropertyDaoFiltering.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/DataPropertyDaoFiltering.java @@ -192,4 +192,16 @@ class DataPropertyDaoFiltering extends BaseFiltering implements DataPropertyDao{ return innerDataPropertyDao.getClassesWithRestrictionOnProperty(propertyURI); } + @Override + // This may need to be filtered at some point. + public List getDataPropertyList(Individual subject) { + return innerDataPropertyDao.getDataPropertyList(subject); + } + + @Override + // This may need to be filtered at some point. + public List getDataPropertyList(String subjectUri) { + return innerDataPropertyDao.getDataPropertyList(subjectUri); + } + } \ No newline at end of file diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/IndividualFiltering.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/IndividualFiltering.java index 66c7f974d..537dd9e9f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/IndividualFiltering.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/IndividualFiltering.java @@ -13,8 +13,6 @@ 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; @@ -29,7 +27,6 @@ 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; /** @@ -41,9 +38,6 @@ 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; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/ObjectPropertyDaoFiltering.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/ObjectPropertyDaoFiltering.java index b437a3688..2db06994f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/ObjectPropertyDaoFiltering.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/ObjectPropertyDaoFiltering.java @@ -203,4 +203,15 @@ class ObjectPropertyDaoFiltering extends BaseFiltering implements ObjectProperty return innerObjectPropertyDao.getClassesWithRestrictionOnProperty(propertyURI); } + @Override + // This may need to be filtered at some point. + public List getObjectPropertyList(Individual subject) { + return innerObjectPropertyDao.getObjectPropertyList(subject); + } + + @Override + // This may need to be filtered at some point. + public List getObjectPropertyList(String subjectUri) { + return innerObjectPropertyDao.getObjectPropertyList(subjectUri); + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/WebappDaoFactoryFiltering.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/WebappDaoFactoryFiltering.java index 31896fa59..22144b3a3 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/WebappDaoFactoryFiltering.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/WebappDaoFactoryFiltering.java @@ -9,7 +9,6 @@ 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; @@ -20,7 +19,6 @@ 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; @@ -215,14 +213,6 @@ public class WebappDaoFactoryFiltering implements WebappDaoFactory { public PortalDao getPortalDao() { return innerWebappDaoFactory.getPortalDao(); } - - public ObjectPropertyListDao getObjectPropertyListDao() { - return innerWebappDaoFactory.getObjectPropertyListDao(); - } - - public DataPropertyListDao getDataPropertyListDao() { - return innerWebappDaoFactory.getDataPropertyListDao(); - } /////////////////////////////////////////////////////////////////// diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyDaoJena.java index b89233944..6bb4e1572 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyDaoJena.java @@ -61,6 +61,26 @@ 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 ?property WHERE { \n" + + //" GRAPH ?g {\n" + + " ?subject ?property ?object . \n" + + " ?property rdf:type owl:DatatypeProperty . \n" + + propertyFilters + + //" }\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; @@ -688,4 +708,32 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements return rootProperties; } + @Override + public List getDataPropertyList(Individual subject) { + return getDataPropertyList(subject.getURI()); + } + + @Override + /* + * SPARQL-based method for getting the individual's data properties. + * Ideally this implementation should replace the existing way of getting + * the data property list, but the consequences of this may be far-reaching, + * so we are implementing a new method now and will merge the old approach + * into the new one in a future release. + */ + public List getDataPropertyList(String subjectUri) { + log.debug("dataPropertyQueryString:\n" + dataPropertyQueryString); + log.debug("dataPropertyQuery:\n" + dataPropertyQuery); + ResultSet results = getPropertyQueryResults(subjectUri, dataPropertyQuery); + List properties = new ArrayList(); + while (results.hasNext()) { + QuerySolution sol = results.next(); + Resource resource = sol.getResource("property"); + String uri = resource.getURI(); + DataProperty property = getDataPropertyByURI(uri); + properties.add(property); + } + return properties; + } + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyListDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyListDaoJena.java deleted file mode 100644 index 02d3203e7..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyListDaoJena.java +++ /dev/null @@ -1,78 +0,0 @@ -/* $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 getDataPropertyList(Individual subject) { - return getDataPropertyList(subject.getURI()); - } - - @Override - public List getDataPropertyList(String subjectUri) { - log.debug("dataPropertyQuery:\n" + dataPropertyQuery); - ResultSet results = getPropertyQueryResults(subjectUri, dataPropertyQuery); - List properties = new ArrayList(); - 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; - } - -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualJena.java index eaa60723b..56eaf5fc1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualJena.java @@ -740,7 +740,7 @@ public class IndividualJena extends IndividualImpl implements Individual { @Override public List getPopulatedObjectPropertyList() { if (populatedObjectPropertyList == null) { - populatedObjectPropertyList = webappDaoFactory.getObjectPropertyListDao().getObjectPropertyList(this); + populatedObjectPropertyList = webappDaoFactory.getObjectPropertyDao().getObjectPropertyList(this); } return populatedObjectPropertyList; } @@ -794,7 +794,7 @@ public class IndividualJena extends IndividualImpl implements Individual { @Override public List getPopulatedDataPropertyList() { if (populatedDataPropertyList == null) { - populatedDataPropertyList = webappDaoFactory.getDataPropertyListDao().getDataPropertyList(this); + populatedDataPropertyList = webappDaoFactory.getDataPropertyDao().getDataPropertyList(this); } return populatedDataPropertyList; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java index 58fa89018..94cc70211 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java @@ -884,7 +884,7 @@ public class IndividualSDB extends IndividualImpl implements Individual { @Override public List getPopulatedObjectPropertyList() { if (populatedObjectPropertyList == null) { - populatedObjectPropertyList = webappDaoFactory.getObjectPropertyListDao().getObjectPropertyList(this); + populatedObjectPropertyList = webappDaoFactory.getObjectPropertyDao().getObjectPropertyList(this); } return populatedObjectPropertyList; } @@ -938,7 +938,7 @@ public class IndividualSDB extends IndividualImpl implements Individual { @Override public List getPopulatedDataPropertyList() { if (populatedDataPropertyList == null) { - populatedDataPropertyList = webappDaoFactory.getDataPropertyListDao().getDataPropertyList(this); + populatedDataPropertyList = webappDaoFactory.getDataPropertyDao().getDataPropertyList(this); } return populatedDataPropertyList; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB2.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB2.java index 105291ac2..44cd40986 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB2.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB2.java @@ -872,7 +872,7 @@ public class IndividualSDB2 extends IndividualImpl implements Individual { @Override public List getPopulatedObjectPropertyList() { if (populatedObjectPropertyList == null) { - populatedObjectPropertyList = webappDaoFactory.getObjectPropertyListDao().getObjectPropertyList(this); + populatedObjectPropertyList = webappDaoFactory.getObjectPropertyDao().getObjectPropertyList(this); } return populatedObjectPropertyList; } @@ -922,14 +922,6 @@ public class IndividualSDB2 extends IndividualImpl implements Individual { return this.datatypePropertyList; } } - - @Override - public List getPopulatedDataPropertyList() { - if (populatedDataPropertyList == null) { - populatedDataPropertyList = webappDaoFactory.getDataPropertyListDao().getDataPropertyList(this); - } - return populatedDataPropertyList; - } @Override public Map getDataPropertyMap() { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java index 35fe380d4..c0744511a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java @@ -47,6 +47,26 @@ 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 ?property WHERE { \n" + + //" GRAPH ?g {\n" + + " ?subject ?property ?object . \n" + + " ?property rdf:type owl:ObjectProperty . \n" + + propertyFilters + + //" }\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); @@ -804,4 +824,33 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp return false; } + @Override + public List getObjectPropertyList(Individual subject) { + return getObjectPropertyList(subject.getURI()); + } + + @Override + /* + * SPARQL-based method for getting the individual's object properties. + * Ideally this implementation should replace the existing way of getting + * the object property list, but the consequences of this may be far-reaching, + * so we are implementing a new method now and will merge the old approach + * into the new one in a future release. + */ + public List getObjectPropertyList(String subjectUri) { + log.debug("objectPropertyQueryString:\n" + objectPropertyQueryString); + log.debug("objectPropertyQuery:\n" + objectPropertyQuery); + ResultSet results = getPropertyQueryResults(subjectUri, objectPropertyQuery); + List properties = new ArrayList(); + while (results.hasNext()) { + QuerySolution sol = results.next(); + Resource resource = sol.getResource("property"); + String uri = resource.getURI(); + ObjectProperty property = getObjectPropertyByURI(uri); + properties.add(property); + } + return properties; + } + + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyListDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyListDaoJena.java deleted file mode 100644 index 5fbce2c50..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyListDaoJena.java +++ /dev/null @@ -1,78 +0,0 @@ -/* $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 getObjectPropertyList(Individual subject) { - return getObjectPropertyList(subject.getURI()); - } - - @Override - public List getObjectPropertyList(String subjectUri) { - log.debug("objectPropertyQuery:\n" + objectPropertyQuery); - ResultSet results = getPropertyQueryResults(subjectUri, objectPropertyQuery); - List properties = new ArrayList(); - 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; - } - -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyDaoJena.java index 3f143dfb3..1dfb1e40a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyDaoJena.java @@ -40,6 +40,34 @@ 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: \n" + + "PREFIX vitro: \n" + + "PREFIX owl: \n" + + "PREFIX afn: "; + + /* This may be the intent behind JenaBaseDao.NONUSER_NAMESPACES, but that + * value does not contain all of these namespaces. + */ + protected static final List 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#" + ); + + /* + * 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). + */ + protected static String propertyFilters = ""; + static { + for (String s : EXCLUDED_NAMESPACES) { + propertyFilters += "FILTER (afn:namespace(?property) != \"" + s + "\") \n"; + } + } public PropertyDaoJena(WebappDaoFactoryJena wadf) { super(wadf); @@ -377,5 +405,15 @@ 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(); + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyListDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyListDaoJena.java deleted file mode 100644 index 6ef294d2d..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyListDaoJena.java +++ /dev/null @@ -1,67 +0,0 @@ -/* $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: \n" + - "PREFIX vitro: \n" + - "PREFIX owl: \n" + - "PREFIX afn: "; - - /* This may be the intent behind JenaBaseDao.NONUSER_NAMESPACES, but that - * value does not contain all of these namespaces. - */ - protected static final List 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(); - } -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactoryJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactoryJena.java index 693ca2dc1..e29ca6b16 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactoryJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactoryJena.java @@ -9,6 +9,7 @@ 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; @@ -29,10 +30,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; @@ -43,7 +44,6 @@ 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,23 +548,7 @@ 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 ) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyList.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyList.java index 2f3f759c3..7f53f756b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyList.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyList.java @@ -35,10 +35,16 @@ public class PropertyList extends BaseTemplateModel { PropertyList() { propertyList = new ArrayList(); } - + protected void addObjectProperties(List propertyList) { - for (ObjectProperty op : propertyList) { - add(op); + 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"); + //} } } @@ -48,7 +54,7 @@ public class PropertyList extends BaseTemplateModel { protected void addDataProperties(List propertyList) { for (DataProperty dp : propertyList) { - add(dp); + add(dp); } } @@ -130,6 +136,20 @@ 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 {