NIHVIVO-1333 More work on property display on individual page
This commit is contained in:
parent
30fa59cf5e
commit
42dca90027
8 changed files with 197 additions and 10 deletions
|
@ -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<Property> getPropertyListForSubject(Individual subject);
|
||||
|
||||
public List<Property> getPropertyListForSubject(String subjectUri);
|
||||
}
|
|
@ -132,4 +132,6 @@ public interface WebappDaoFactory {
|
|||
public NamespaceDao getNamespaceDao();
|
||||
|
||||
public PropertyInstanceDao getPropertyInstanceDao();
|
||||
|
||||
public PropertyListDao getPropertyListDao();
|
||||
}
|
||||
|
|
|
@ -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 *************************** */
|
||||
|
||||
|
|
|
@ -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: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#>\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<Property> getPropertyListForSubject(Individual subject) {
|
||||
return getPropertyListForSubject(subject.getURI());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Property> 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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() {
|
||||
|
|
|
@ -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<String> 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<Property> propertyList = plDao.getPropertyListForSubject(subject);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<String> 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<Property> mergedPropertyList = new ArrayList<Property>();
|
||||
// First get the properties this entity actually has, presumably populated with statements
|
||||
List<ObjectProperty> 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;
|
||||
}
|
||||
}
|
|
@ -2,6 +2,4 @@
|
|||
|
||||
<#-- Template for property listing on individual profile page -->
|
||||
|
||||
<#--
|
||||
<#assign properties = individual.propertyList>
|
||||
-->
|
Loading…
Add table
Reference in a new issue