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..acd42f18f --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/PropertyListDao.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.Property; + +public interface PropertyListDao { + + public List getPropertyListForSubject(Individual subject); + + public List getPropertyListForSubject(String subjectUri); +} 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..9fc952828 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,6 @@ public interface WebappDaoFactory { public NamespaceDao getNamespaceDao(); public PropertyInstanceDao getPropertyInstanceDao(); + + public PropertyListDao getPropertyListDao(); } 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..d3f13613a 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 @@ -24,6 +24,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao; import edu.cornell.mannlib.vitro.webapp.dao.PortalDao; import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao; +import edu.cornell.mannlib.vitro.webapp.dao.PropertyListDao; import edu.cornell.mannlib.vitro.webapp.dao.TabDao; import edu.cornell.mannlib.vitro.webapp.dao.TabIndividualRelationDao; import edu.cornell.mannlib.vitro.webapp.dao.TabVClassRelationDao; @@ -214,11 +215,6 @@ public class WebappDaoFactoryFiltering implements WebappDaoFactory { return innerWebappDaoFactory.getPortalDao(); } -/////////////////////////////////////////////////////////////////// - - - /* ******************* non-filtering DAOs *************************** */ - public Classes2ClassesDao getClasses2ClassesDao() { return innerWebappDaoFactory.getClasses2ClassesDao(); } @@ -234,6 +230,11 @@ public class WebappDaoFactoryFiltering implements WebappDaoFactory { public OntologyDao getOntologyDao() { return innerWebappDaoFactory.getOntologyDao(); } + + // rjy7 This may actually need to be filtered... + public PropertyListDao getPropertyListDao() { + return innerWebappDaoFactory.getPropertyListDao(); + } /* ******************* filtering DAOs *************************** */ 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..a9d503796 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyListDaoJena.java @@ -0,0 +1,74 @@ +/* $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.List; + +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.QuerySolutionMap; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.ResourceFactory; + +import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.beans.Property; +import edu.cornell.mannlib.vitro.webapp.dao.PropertyListDao; + +public class PropertyListDaoJena extends JenaBaseDao implements PropertyListDao { + + static final protected String propertyQueryString = + "PREFIX vitro: \n" + + "SELECT ?group ?predicate WHERE {\n" + + " GRAPH ?g {\n" + + " ?subject ?predicate ?object . \n" + + " OPTIONAL { ?predicate vitro:inPropertyGroupAnnot ?group . \n" + + " }\n" + + " }\n" + + "}" + + "ORDER BY DESC(?group) ?predicate\n"; + + + static protected Query propertyQuery; + static { + try { + propertyQuery = QueryFactory.create(propertyQueryString); + } catch(Throwable th){ + log.error("could not create SPARQL query for propertyQueryString " + th.getMessage()); + log.error(propertyQueryString); + } + } + public PropertyListDaoJena(WebappDaoFactoryJena wadf) { + super(wadf); + } + + @Override + protected OntModel getOntModel() { + return getOntModelSelector().getABoxModel(); + } + + @Override + public List getPropertyListForSubject(Individual subject) { + return getPropertyListForSubject(subject.getURI()); + } + + @Override + public List getPropertyListForSubject(String subjectUri) { + + // First get all the properties that occur in statements with this subject as subject. We must get these + // from a db query because they may include properties that are not defined as "possible properties" + // for a subject of this class. + + // 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(propertyQuery, getOntModel()); + ResultSet results = qexec.execSelect(); + return null; + } + +} 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..2b7c9a85d 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,7 +29,6 @@ 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; @@ -49,6 +47,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao; import edu.cornell.mannlib.vitro.webapp.dao.PortalDao; import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao; +import edu.cornell.mannlib.vitro.webapp.dao.PropertyListDao; import edu.cornell.mannlib.vitro.webapp.dao.TabDao; import edu.cornell.mannlib.vitro.webapp.dao.TabIndividualRelationDao; import edu.cornell.mannlib.vitro.webapp.dao.TabVClassRelationDao; @@ -548,6 +547,14 @@ public class WebappDaoFactoryJena implements WebappDaoFactory { propertyInstanceDao = new PropertyInstanceDaoJena(this); return propertyInstanceDao; } + + private PropertyListDao propertyListDao = null; + public PropertyListDao getPropertyListDao() { + if (propertyListDao == null) { + propertyListDao = new PropertyListDaoJena(this); + } + return propertyListDao; + } protected VClassDao vClassDao = null; public VClassDao getVClassDao() { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java index 8b76fffdd..8d040028d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java @@ -13,9 +13,11 @@ import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.beans.Property; import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao; +import edu.cornell.mannlib.vitro.webapp.dao.PropertyListDao; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep; @@ -36,7 +38,7 @@ public class GroupedPropertyList extends BaseTemplateModel { private static final Collection SUPPRESSED_OBJECT_PROPERTIES = Collections .unmodifiableCollection(Arrays .asList(new String[] { VitroVocabulary.IND_MAIN_IMAGE })); - + // RY Do we really want to store subject and vreq as members? Could just pass around. private Individual subject; private VitroRequest vreq; @@ -65,6 +67,14 @@ public class GroupedPropertyList extends BaseTemplateModel { if (groups.isEmpty()) { groups.add(new DummyPropertyGroupTemplateModel(null)); } + + // Create the property list for the subject. The properties will be put into groups later. + + // First get all the properties that occur in statements in the db with this subject as subject. + // This may include properties that are not defined as "possible properties" for a subject of this class. + PropertyListDao plDao = wdf.getPropertyListDao(); + List propertyList = plDao.getPropertyListForSubject(subject); + } /** diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyListBuilder.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyListBuilder.java new file mode 100644 index 000000000..9426ca92a --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/PropertyListBuilder.java @@ -0,0 +1,80 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import edu.cornell.mannlib.vedit.beans.LoginStatusBean; +import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; +import edu.cornell.mannlib.vitro.webapp.beans.Property; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; +import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep; + +/** + * Build the list of ontology properties for display on an individual profile page. + * @author rjy7 + * + */ + +// RY We may not need this class. Logic for building the list can be moved to GroupedPropertyList.java. +// Wait and see how much code remains here - if little, just put in IndividualTemplateModel. +public class PropertyListBuilder { + + private static final Log log = LogFactory.getLog(PropertyListBuilder.class); + private static final int MAX_GROUP_DISPLAY_RANK = 99; + + /** Don't include these properties in the list. */ + // RY This should perhaps be moved to ObjectPropertyTemplateModel + private static final Collection SUPPRESSED_OBJECT_PROPERTIES = Collections + .unmodifiableCollection(Arrays + .asList(new String[] { VitroVocabulary.IND_MAIN_IMAGE })); + + protected Individual subject; + protected VitroRequest vreq; + + PropertyListBuilder(Individual individual, VitroRequest vreq) { + this.subject = individual; + this.vreq = vreq; + } + + protected GroupedPropertyList getPropertyList() { + + // Determine whether we're editing or not. + boolean isEditing = getEditingStatus(); + + // Assemble the property list + List mergedPropertyList = new ArrayList(); + // First get the properties this entity actually has, presumably populated with statements + List objectPropertyList = subject.getObjectPropertyList(); + + for (ObjectProperty op : objectPropertyList) { + if (!SUPPRESSED_OBJECT_PROPERTIES.contains(op)) { + op.setEditLabel(op.getDomainPublic()); + mergedPropertyList.add(op); + }else{ + log.debug("suppressed " + op.getURI()); + } + } + + return null; + } + + /** + * Return true iff the user is editing. + */ + private boolean getEditingStatus() { + // These tests may change once self-editing issues are straightened out. + boolean isSelfEditing = VitroRequestPrep.isSelfEditing(vreq); + boolean isCurator = LoginStatusBean.getBean(vreq).isLoggedInAtLeast(LoginStatusBean.CURATOR); + return isSelfEditing || isCurator; + } +} diff --git a/webapp/web/templates/freemarker/body/individual/individual-properties.ftl b/webapp/web/templates/freemarker/body/individual/individual-properties.ftl index 358d91a97..50eaec361 100644 --- a/webapp/web/templates/freemarker/body/individual/individual-properties.ftl +++ b/webapp/web/templates/freemarker/body/individual/individual-properties.ftl @@ -2,6 +2,4 @@ <#-- Template for property listing on individual profile page --> -<#-- <#assign properties = individual.propertyList> ---> \ No newline at end of file