From 5cc801ee2cbe50a9863d58f507609be4faec8a1d Mon Sep 17 00:00:00 2001 From: rjy7 Date: Thu, 2 Dec 2010 18:57:58 +0000 Subject: [PATCH] NIHVIVO-1333 Moved dao methods for constructing lists of data properties and object properties for an individual into their own dao classes --- .../vitro/webapp/beans/Individual.java | 12 +++ .../vitro/webapp/dao/DataPropertyDao.java | 5 +- .../vitro/webapp/dao/DataPropertyListDao.java | 16 ++++ .../vitro/webapp/dao/ObjectPropertyDao.java | 5 +- .../webapp/dao/ObjectPropertyListDao.java | 15 ++++ .../vitro/webapp/dao/PropertyListDao.java | 8 ++ .../vitro/webapp/dao/WebappDaoFactory.java | 4 + .../filtering/DataPropertyDaoFiltering.java | 12 --- .../dao/filtering/IndividualFiltering.java | 20 ++--- .../filtering/ObjectPropertyDaoFiltering.java | 11 --- .../filtering/WebappDaoFactoryFiltering.java | 10 +++ .../webapp/dao/jena/DataPropertyDaoJena.java | 47 ----------- .../dao/jena/DataPropertyListDaoJena.java | 78 +++++++++++++++++++ .../vitro/webapp/dao/jena/IndividualJena.java | 4 +- .../vitro/webapp/dao/jena/IndividualSDB.java | 4 +- .../vitro/webapp/dao/jena/IndividualSDB2.java | 10 ++- .../dao/jena/ObjectPropertyDaoJena.java | 48 ------------ .../dao/jena/ObjectPropertyListDaoJena.java | 78 +++++++++++++++++++ .../webapp/dao/jena/PropertyDaoJena.java | 23 ------ .../webapp/dao/jena/PropertyListDaoJena.java | 67 ++++++++++++++++ .../webapp/dao/jena/WebappDaoFactoryJena.java | 20 ++++- .../individual/PropertyList.java | 28 +------ 22 files changed, 331 insertions(+), 194 deletions(-) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DataPropertyListDao.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyListDao.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/dao/PropertyListDao.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyListDaoJena.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyListDaoJena.java create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyListDaoJena.java 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 bc299f87d..3a0825523 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Individual.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/Individual.java @@ -46,6 +46,12 @@ 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); @@ -55,6 +61,12 @@ 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 02f1c7360..5c2588de6 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DataPropertyDao.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DataPropertyDao.java @@ -35,8 +35,5 @@ 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 new file mode 100644 index 000000000..857fca7ba --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DataPropertyListDao.java @@ -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 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 9a966351b..2347aa386 100755 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyDao.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyDao.java @@ -51,8 +51,5 @@ 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 new file mode 100644 index 000000000..d42b6a0b3 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyListDao.java @@ -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 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 new file mode 100644 index 000000000..c1ced8f61 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/PropertyListDao.java @@ -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 +} 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 897ca9ef8..b7d8c81f3 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactory.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactory.java @@ -132,4 +132,8 @@ 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 311fde3d6..628ad4ee3 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,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 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 dca2263d8..66c7f974d 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,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 dprops = _innerIndividual.getPopulatedDataPropertyList(); LinkedList outdProps = new LinkedList(); Filter.filter(dprops,_filters.getDataPropertyFilter(), outdProps); - - ListIterator it = outdProps.listIterator(); - while(it.hasNext()){ - DataProperty dp = it.next(); - List filteredStmts = - new LinkedList(); - Filter.filter(dp.getDataPropertyStatements(), - _filters.getDataPropertyStatementFilter(),filteredStmts); - if( filteredStmts == null || filteredStmts.size() == 0 ){ - it.remove(); - }else{ - dp.setDataPropertyStatements(filteredStmts); - } - } return outdProps; } 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 2db06994f..b437a3688 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,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 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 22144b3a3..31896fa59 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,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(); + } /////////////////////////////////////////////////////////////////// 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 cf71dc431..b89233944 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,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 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(); - 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 new file mode 100644 index 000000000..02d3203e7 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyListDaoJena.java @@ -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 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 56eaf5fc1..eaa60723b 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.getObjectPropertyDao().getObjectPropertyList(this); + populatedObjectPropertyList = webappDaoFactory.getObjectPropertyListDao().getObjectPropertyList(this); } return populatedObjectPropertyList; } @@ -794,7 +794,7 @@ public class IndividualJena extends IndividualImpl implements Individual { @Override public List getPopulatedDataPropertyList() { if (populatedDataPropertyList == null) { - populatedDataPropertyList = webappDaoFactory.getDataPropertyDao().getDataPropertyList(this); + populatedDataPropertyList = webappDaoFactory.getDataPropertyListDao().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 94cc70211..58fa89018 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.getObjectPropertyDao().getObjectPropertyList(this); + populatedObjectPropertyList = webappDaoFactory.getObjectPropertyListDao().getObjectPropertyList(this); } return populatedObjectPropertyList; } @@ -938,7 +938,7 @@ public class IndividualSDB extends IndividualImpl implements Individual { @Override public List getPopulatedDataPropertyList() { if (populatedDataPropertyList == null) { - populatedDataPropertyList = webappDaoFactory.getDataPropertyDao().getDataPropertyList(this); + populatedDataPropertyList = webappDaoFactory.getDataPropertyListDao().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 44cd40986..105291ac2 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.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 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 a450b0837..35fe380d4 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,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 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(); - 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 new file mode 100644 index 000000000..5fbce2c50 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyListDaoJena.java @@ -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 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 b1133e1c1..3f143dfb3 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,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: \n" + - "PREFIX vitro: \n" + - "PREFIX owl: \n"; - - 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 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(); - } } 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 new file mode 100644 index 000000000..6ef294d2d --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyListDaoJena.java @@ -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: \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 e29ca6b16..693ca2dc1 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,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 ) 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 7f53f756b..2f3f759c3 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,16 +35,10 @@ public class PropertyList extends BaseTemplateModel { PropertyList() { propertyList = new ArrayList(); } - + protected void addObjectProperties(List 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 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 {