NIHVIVO 3778 vitro components for data prop list views
This commit is contained in:
parent
4d5aea69d2
commit
dfb955f39f
12 changed files with 521 additions and 15 deletions
|
@ -39,4 +39,6 @@ public interface DataPropertyDao extends PropertyDao {
|
||||||
public List<DataProperty> getDataPropertyList(Individual subject);
|
public List<DataProperty> getDataPropertyList(Individual subject);
|
||||||
|
|
||||||
public List<DataProperty> getDataPropertyList(String subjectUri);
|
public List<DataProperty> getDataPropertyList(String subjectUri);
|
||||||
|
|
||||||
|
public String getCustomListViewConfigFileName(DataProperty dataProperty);
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.dao;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
|
|
||||||
|
@ -44,5 +45,9 @@ public interface DataPropertyStatementDao {
|
||||||
|
|
||||||
List<Literal> getDataPropertyValuesForIndividualByProperty(String subjectUri, String propertyUri);
|
List<Literal> getDataPropertyValuesForIndividualByProperty(String subjectUri, String propertyUri);
|
||||||
|
|
||||||
|
List<Literal> getDataPropertyValuesForIndividualByProperty(Individual subject, DataProperty property, String queryString, Set<String> constructQueryStrings);
|
||||||
|
|
||||||
|
List<Literal> getDataPropertyValuesForIndividualByProperty(String subjectUri, String propertyUri, String queryString, Set<String> constructQueryStrings);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -213,4 +213,9 @@ class DataPropertyDaoFiltering extends BaseFiltering implements DataPropertyDao{
|
||||||
return innerDataPropertyDao.getDataPropertyList(subjectUri);
|
return innerDataPropertyDao.getDataPropertyList(subjectUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCustomListViewConfigFileName(DataProperty dataProperty) {
|
||||||
|
return innerDataPropertyDao.getCustomListViewConfigFileName(dataProperty);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -7,6 +7,7 @@ import java.util.Collection;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
|
|
||||||
|
@ -18,6 +19,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||||
|
|
||||||
class DataPropertyStatementDaoFiltering extends BaseFiltering implements DataPropertyStatementDao{
|
class DataPropertyStatementDaoFiltering extends BaseFiltering implements DataPropertyStatementDao{
|
||||||
|
|
||||||
final DataPropertyStatementDao innerDataPropertyStatementDao;
|
final DataPropertyStatementDao innerDataPropertyStatementDao;
|
||||||
final VitroFilters filters;
|
final VitroFilters filters;
|
||||||
|
|
||||||
|
@ -141,4 +143,48 @@ class DataPropertyStatementDaoFiltering extends BaseFiltering implements DataPro
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Literal> getDataPropertyValuesForIndividualByProperty(Individual subject, DataProperty property, String queryString, Set<String> constructQueryStrings) {
|
||||||
|
return getDataPropertyValuesForIndividualByProperty(subject.getURI(), property.getURI(), queryString, constructQueryStrings);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Literal> getDataPropertyValuesForIndividualByProperty(String subjectUri, String propertyUri, String queryString, Set<String> constructQueryStrings) {
|
||||||
|
List<Literal> literals = innerDataPropertyStatementDao.getDataPropertyValuesForIndividualByProperty(subjectUri, propertyUri, queryString, constructQueryStrings);
|
||||||
|
/* Filter the data
|
||||||
|
*
|
||||||
|
* Filtering is applied to a list of DataPropertyStatement. Create these statements, mapped
|
||||||
|
* to the literal that they are built from, apply filtering to the statements, then get
|
||||||
|
* the associated literals out of the original list. Use a LinkedHashMap to preserve the ordering.
|
||||||
|
*/
|
||||||
|
Map<DataPropertyStatement, Literal> stmtsToLiterals =
|
||||||
|
new LinkedHashMap<DataPropertyStatement, Literal>(literals.size());
|
||||||
|
|
||||||
|
for (Literal literal : literals) {
|
||||||
|
String value = literal.getLexicalForm();
|
||||||
|
DataPropertyStatement statement = new DataPropertyStatementImpl(subjectUri, propertyUri, value);
|
||||||
|
statement.setDatatypeURI(literal.getDatatypeURI());
|
||||||
|
statement.setLanguage(literal.getLanguage());
|
||||||
|
stmtsToLiterals.put(statement, literal);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<DataPropertyStatement> stmtList = new ArrayList<DataPropertyStatement>(stmtsToLiterals.keySet());
|
||||||
|
|
||||||
|
// Apply the filters to the list of statements
|
||||||
|
List<DataPropertyStatement> filteredStatements = filter(stmtList, filters.getDataPropertyStatementFilter());
|
||||||
|
|
||||||
|
// Get the literals associated with the filtered statements out of the original list
|
||||||
|
List<Literal> filteredLiterals = new ArrayList<Literal>(filteredStatements.size());
|
||||||
|
for (DataPropertyStatement dps : filteredStatements) {
|
||||||
|
if (dps instanceof DataPropertyStatementFiltering) {
|
||||||
|
dps = ((DataPropertyStatementFiltering)dps).innerStmt;
|
||||||
|
}
|
||||||
|
filteredLiterals.add(stmtsToLiterals.get(dps));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the filtered list of literals
|
||||||
|
return filteredLiterals;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -11,6 +11,7 @@ import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -25,6 +26,8 @@ import com.hp.hpl.jena.ontology.ProfileException;
|
||||||
import com.hp.hpl.jena.ontology.Restriction;
|
import com.hp.hpl.jena.ontology.Restriction;
|
||||||
import com.hp.hpl.jena.ontology.SomeValuesFromRestriction;
|
import com.hp.hpl.jena.ontology.SomeValuesFromRestriction;
|
||||||
import com.hp.hpl.jena.query.Query;
|
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.QueryFactory;
|
||||||
import com.hp.hpl.jena.query.QuerySolution;
|
import com.hp.hpl.jena.query.QuerySolution;
|
||||||
import com.hp.hpl.jena.query.ResultSet;
|
import com.hp.hpl.jena.query.ResultSet;
|
||||||
|
@ -729,5 +732,52 @@ public class DataPropertyDaoJena extends PropertyDaoJena implements
|
||||||
}
|
}
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
protected static final String LIST_VIEW_CONFIG_FILE_QUERY_STRING =
|
||||||
|
"PREFIX display: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#>" +
|
||||||
|
"SELECT ?property ?filename WHERE { \n" +
|
||||||
|
" ?property display:listViewConfigFile ?filename . \n" +
|
||||||
|
"}";
|
||||||
|
|
||||||
|
protected static Query listViewConfigFileQuery = null;
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
listViewConfigFileQuery = QueryFactory.create(LIST_VIEW_CONFIG_FILE_QUERY_STRING);
|
||||||
|
} catch(Throwable th){
|
||||||
|
log.error("could not create SPARQL query for LIST_VIEW_CONFIG_FILE_QUERY_STRING " + th.getMessage());
|
||||||
|
log.error(LIST_VIEW_CONFIG_FILE_QUERY_STRING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<DataProperty, String> customListViewConfigFileMap = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCustomListViewConfigFileName(DataProperty dp) {
|
||||||
|
if (customListViewConfigFileMap == null) {
|
||||||
|
customListViewConfigFileMap = new HashMap<DataProperty, String>();
|
||||||
|
OntModel displayModel = getOntModelSelector().getDisplayModel();
|
||||||
|
//Get all property to list view config file mappings in the system
|
||||||
|
QueryExecution qexec = QueryExecutionFactory.create(listViewConfigFileQuery, displayModel);
|
||||||
|
ResultSet results = qexec.execSelect();
|
||||||
|
//Iterate through mappings looking for the current property and setting up a hashmap for subsequent retrieval
|
||||||
|
while (results.hasNext()) {
|
||||||
|
QuerySolution soln = results.next();
|
||||||
|
String propertyUri = soln.getResource("property").getURI();
|
||||||
|
DataProperty prop = getDataPropertyByURI(propertyUri);
|
||||||
|
if (prop == null) {
|
||||||
|
//This is a warning only if this property is the one for which we're searching
|
||||||
|
if(dp.getURI().equals(propertyUri)){
|
||||||
|
log.warn("Can't find property for uri " + propertyUri);
|
||||||
|
} else {
|
||||||
|
log.debug("Can't find property for uri " + propertyUri);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String filename = soln.getLiteral("filename").getLexicalForm();
|
||||||
|
customListViewConfigFileMap.put(prop, filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qexec.close();
|
||||||
|
}
|
||||||
|
return customListViewConfigFileMap.get(dp);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import com.hp.hpl.jena.datatypes.TypeMapper;
|
import com.hp.hpl.jena.datatypes.TypeMapper;
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
@ -18,10 +19,15 @@ import com.hp.hpl.jena.query.QueryExecution;
|
||||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||||
import com.hp.hpl.jena.query.QueryFactory;
|
import com.hp.hpl.jena.query.QueryFactory;
|
||||||
import com.hp.hpl.jena.query.QuerySolution;
|
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.query.ResultSet;
|
||||||
|
import com.hp.hpl.jena.query.Syntax;
|
||||||
import com.hp.hpl.jena.rdf.model.AnonId;
|
import com.hp.hpl.jena.rdf.model.AnonId;
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.Property;
|
import com.hp.hpl.jena.rdf.model.Property;
|
||||||
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
import com.hp.hpl.jena.rdf.model.Resource;
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.Statement;
|
import com.hp.hpl.jena.rdf.model.Statement;
|
||||||
|
@ -38,6 +44,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.edit.ReorderController;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualUpdateEvent;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualUpdateEvent;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.ObjectPropertyStatementDaoJena;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -190,6 +197,7 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
|
||||||
Resource res = ResourceFactory.createResource(entity.getURI());
|
Resource res = ResourceFactory.createResource(entity.getURI());
|
||||||
if (!VitroVocabulary.PSEUDO_BNODE_NS.equals(entity.getNamespace())) {
|
if (!VitroVocabulary.PSEUDO_BNODE_NS.equals(entity.getNamespace())) {
|
||||||
for (Literal lit : this.getDataPropertyValuesForIndividualByProperty(res.getURI(), datapropURI)) {
|
for (Literal lit : this.getDataPropertyValuesForIndividualByProperty(res.getURI(), datapropURI)) {
|
||||||
|
log.debug("Literal lit = " + lit);
|
||||||
DataPropertyStatement ed = new DataPropertyStatementImpl();
|
DataPropertyStatement ed = new DataPropertyStatementImpl();
|
||||||
fillDataPropertyStatementWithJenaLiteral(ed, lit);
|
fillDataPropertyStatementWithJenaLiteral(ed, lit);
|
||||||
ed.setIndividualURI(entity.getURI());
|
ed.setIndividualURI(entity.getURI());
|
||||||
|
@ -390,4 +398,126 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Literal> getDataPropertyValuesForIndividualByProperty(
|
||||||
|
Individual subject,
|
||||||
|
DataProperty property,
|
||||||
|
String queryString, Set<String> constructQueryStrings ) {
|
||||||
|
return getDataPropertyValuesForIndividualByProperty(subject.getURI(), property.getURI(), queryString, constructQueryStrings );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Literal> getDataPropertyValuesForIndividualByProperty(
|
||||||
|
String subjectUri,
|
||||||
|
String propertyUri,
|
||||||
|
String queryString, Set<String> constructQueryStrings ) {
|
||||||
|
|
||||||
|
Model constructedModel = constructModelForSelectQueries(
|
||||||
|
subjectUri, propertyUri, constructQueryStrings);
|
||||||
|
|
||||||
|
log.debug("Query string for data property " + propertyUri + ": " + queryString);
|
||||||
|
|
||||||
|
Query query = null;
|
||||||
|
try {
|
||||||
|
query = QueryFactory.create(queryString, Syntax.syntaxARQ);
|
||||||
|
} catch(Throwable th){
|
||||||
|
log.error("Could not create SPARQL query for query string. " + th.getMessage());
|
||||||
|
log.error(queryString);
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
QuerySolutionMap initialBindings = new QuerySolutionMap();
|
||||||
|
initialBindings.add("subject", ResourceFactory.createResource(subjectUri));
|
||||||
|
initialBindings.add("property", ResourceFactory.createResource(propertyUri));
|
||||||
|
|
||||||
|
// Run the SPARQL query to get the properties
|
||||||
|
List<Literal> values = new ArrayList<Literal>();
|
||||||
|
DatasetWrapper w = dwf.getDatasetWrapper();
|
||||||
|
Dataset dataset = w.getDataset();
|
||||||
|
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||||
|
QueryExecution qexec = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
qexec = (constructedModel == null)
|
||||||
|
? QueryExecutionFactory.create(
|
||||||
|
query, dataset, initialBindings)
|
||||||
|
: QueryExecutionFactory.create(
|
||||||
|
query, constructedModel, initialBindings);
|
||||||
|
|
||||||
|
ResultSet results = qexec.execSelect();
|
||||||
|
|
||||||
|
while (results.hasNext()) {
|
||||||
|
QuerySolution sol = results.next();
|
||||||
|
Literal value = sol.getLiteral("value");
|
||||||
|
values.add(value);
|
||||||
|
}
|
||||||
|
log.debug("values = " + values);
|
||||||
|
return values;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error getting data property values for subject " + subjectUri + " and property " + propertyUri);
|
||||||
|
return Collections.emptyList();
|
||||||
|
} finally {
|
||||||
|
dataset.getLock().leaveCriticalSection();
|
||||||
|
w.close();
|
||||||
|
if (qexec != null) {
|
||||||
|
qexec.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
private Model constructModelForSelectQueries(String subjectUri,
|
||||||
|
String propertyUri,
|
||||||
|
Set<String> constructQueries) {
|
||||||
|
|
||||||
|
if (constructQueries == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Model constructedModel = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
|
for (String queryString : constructQueries) {
|
||||||
|
|
||||||
|
log.debug("CONSTRUCT query string for object property " +
|
||||||
|
propertyUri + ": " + queryString);
|
||||||
|
|
||||||
|
Query query = null;
|
||||||
|
try {
|
||||||
|
query = QueryFactory.create(queryString, Syntax.syntaxARQ);
|
||||||
|
} catch(Throwable th){
|
||||||
|
log.error("Could not create CONSTRUCT SPARQL query for query " +
|
||||||
|
"string. " + th.getMessage());
|
||||||
|
log.error(queryString);
|
||||||
|
return constructedModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
QuerySolutionMap initialBindings = new QuerySolutionMap();
|
||||||
|
initialBindings.add(
|
||||||
|
"subject", ResourceFactory.createResource(subjectUri));
|
||||||
|
initialBindings.add(
|
||||||
|
"property", ResourceFactory.createResource(propertyUri));
|
||||||
|
|
||||||
|
DatasetWrapper w = dwf.getDatasetWrapper();
|
||||||
|
Dataset dataset = w.getDataset();
|
||||||
|
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||||
|
QueryExecution qe = null;
|
||||||
|
try {
|
||||||
|
qe = QueryExecutionFactory.create(
|
||||||
|
query, dataset, initialBindings);
|
||||||
|
qe.execConstruct(constructedModel);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error getting constructed model for subject " + subjectUri + " and property " + propertyUri);
|
||||||
|
} finally {
|
||||||
|
if (qe != null) {
|
||||||
|
qe.close();
|
||||||
|
}
|
||||||
|
dataset.getLock().leaveCriticalSection();
|
||||||
|
w.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return constructedModel;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,159 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.DataPropertyTemplateModel;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.DataPropertyTemplateModel.ConfigError;
|
||||||
|
import freemarker.cache.TemplateLoader;
|
||||||
|
import freemarker.template.Configuration;
|
||||||
|
|
||||||
|
public class DataPropertyListConfig {
|
||||||
|
private static final Log log = LogFactory.getLog(DataPropertyListConfig.class);
|
||||||
|
|
||||||
|
|
||||||
|
private static final String CONFIG_FILE_PATH = "/config/";
|
||||||
|
private static final String DEFAULT_CONFIG_FILE_NAME = "listViewConfig-dataDefault.xml";
|
||||||
|
|
||||||
|
/* NB The default post-processor is not the same as the post-processor for the default view. The latter
|
||||||
|
* actually defines its own post-processor, whereas the default post-processor is used for custom views
|
||||||
|
* that don't define a post-processor, to ensure that the standard post-processing applies.
|
||||||
|
*
|
||||||
|
* edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.DefaultObjectPropertyDataPostProcessor
|
||||||
|
*/
|
||||||
|
|
||||||
|
// TODO Lump these together into the PropertyListConfigContext
|
||||||
|
private final DataPropertyTemplateModel dptm;
|
||||||
|
private final VitroRequest vreq;
|
||||||
|
private final TemplateLoader templateLoader;
|
||||||
|
|
||||||
|
private boolean isDefaultConfig;
|
||||||
|
private Set<String> constructQueries;
|
||||||
|
private String selectQuery;
|
||||||
|
private String templateName;
|
||||||
|
|
||||||
|
public DataPropertyListConfig(DataPropertyTemplateModel dptm, TemplateLoader templateLoader, VitroRequest vreq,
|
||||||
|
DataProperty dp, boolean editing)
|
||||||
|
throws InvalidConfigurationException {
|
||||||
|
|
||||||
|
this.dptm = dptm;
|
||||||
|
this.vreq = vreq;
|
||||||
|
WebappDaoFactory wadf = vreq.getWebappDaoFactory();
|
||||||
|
this.templateLoader = templateLoader;
|
||||||
|
|
||||||
|
// Get the custom config filename
|
||||||
|
String configFileName = wadf.getDataPropertyDao().getCustomListViewConfigFileName(dp);
|
||||||
|
if (configFileName == null) { // no custom config; use default config
|
||||||
|
configFileName = DEFAULT_CONFIG_FILE_NAME;
|
||||||
|
}
|
||||||
|
log.debug("Using list view config file " + configFileName + " for data property " + dp.getURI());
|
||||||
|
|
||||||
|
String configFilePath = getConfigFilePath(configFileName);
|
||||||
|
|
||||||
|
try {
|
||||||
|
File config = new File(configFilePath);
|
||||||
|
if ( ! isDefaultConfig(configFileName) && ! config.exists() ) {
|
||||||
|
log.warn("Can't find config file " + configFilePath + " for data property " + dp.getURI() + "\n" +
|
||||||
|
". Using default config file instead.");
|
||||||
|
configFilePath = getConfigFilePath(DEFAULT_CONFIG_FILE_NAME);
|
||||||
|
// Should we test for the existence of the default, and throw an error if it doesn't exist?
|
||||||
|
}
|
||||||
|
setValuesFromConfigFile(configFilePath, wadf, editing);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error processing config file " + configFilePath + " for data property " + dp.getURI(), e);
|
||||||
|
// What should we do here?
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! isDefaultConfig(configFileName) ) {
|
||||||
|
ConfigError configError = checkConfiguration();
|
||||||
|
if ( configError != null ) { // the configuration contains an error
|
||||||
|
log.warn("Invalid list view config for data property " + dp.getURI() +
|
||||||
|
" in " + configFilePath + ":\n" +
|
||||||
|
configError + " Using default config instead.");
|
||||||
|
configFilePath = getConfigFilePath(DEFAULT_CONFIG_FILE_NAME);
|
||||||
|
setValuesFromConfigFile(configFilePath, wadf, editing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isDefaultConfig = isDefaultConfig(configFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isDefaultConfig(String configFileName) {
|
||||||
|
return configFileName.equals(DEFAULT_CONFIG_FILE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ConfigError checkConfiguration() {
|
||||||
|
|
||||||
|
ConfigError error = dptm.checkQuery(selectQuery);
|
||||||
|
if (error != null) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(selectQuery)) {
|
||||||
|
return ConfigError.NO_SELECT_QUERY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( StringUtils.isBlank(templateName)) {
|
||||||
|
return ConfigError.NO_TEMPLATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if ( templateLoader.findTemplateSource(templateName) == null ) {
|
||||||
|
return ConfigError.TEMPLATE_NOT_FOUND;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Error finding template " + templateName, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setValuesFromConfigFile(String configFilePath, WebappDaoFactory wdf,
|
||||||
|
boolean editing) {
|
||||||
|
try {
|
||||||
|
FileReader reader = new FileReader(configFilePath);
|
||||||
|
CustomListViewConfigFile configFileContents = new CustomListViewConfigFile(reader);
|
||||||
|
|
||||||
|
selectQuery = configFileContents.getSelectQuery(false, editing);
|
||||||
|
templateName = configFileContents.getTemplateName();
|
||||||
|
constructQueries = configFileContents.getConstructQueries();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error processing config file " + configFilePath, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getConfigFilePath(String filename) {
|
||||||
|
return vreq.getSession().getServletContext().getRealPath(CONFIG_FILE_PATH + filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSelectQuery() {
|
||||||
|
return this.selectQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getConstructQueries() {
|
||||||
|
return this.constructQueries;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTemplateName() {
|
||||||
|
return this.templateName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDefaultListView() {
|
||||||
|
return this.isDefaultConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -25,13 +25,15 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat
|
||||||
private final Literal literalValue;
|
private final Literal literalValue;
|
||||||
private final String deleteUrl;
|
private final String deleteUrl;
|
||||||
private final String editUrl;
|
private final String editUrl;
|
||||||
|
private final String templateName;
|
||||||
|
|
||||||
//Extended to include vitro request to check for special parameters
|
//Extended to include vitro request to check for special parameters
|
||||||
public DataPropertyStatementTemplateModel(String subjectUri, String propertyUri,
|
public DataPropertyStatementTemplateModel(String subjectUri, String propertyUri, Literal literal,
|
||||||
Literal literal, VitroRequest vreq) {
|
String templateName, VitroRequest vreq) {
|
||||||
super(subjectUri, propertyUri, vreq);
|
super(subjectUri, propertyUri, vreq);
|
||||||
|
|
||||||
this.literalValue = literal;
|
this.literalValue = literal;
|
||||||
|
this.templateName = templateName;
|
||||||
|
|
||||||
// Do delete url first, since used in building edit url
|
// Do delete url first, since used in building edit url
|
||||||
this.deleteUrl = makeDeleteUrl();
|
this.deleteUrl = makeDeleteUrl();
|
||||||
|
@ -52,6 +54,7 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat
|
||||||
"datapropKey", makeHash(dps),
|
"datapropKey", makeHash(dps),
|
||||||
"cmd", "delete");
|
"cmd", "delete");
|
||||||
|
|
||||||
|
params.put("templateName", templateName);
|
||||||
params.putAll(UrlBuilder.getModelParams(vreq));
|
params.putAll(UrlBuilder.getModelParams(vreq));
|
||||||
|
|
||||||
return UrlBuilder.getUrl(EDIT_PATH, params);
|
return UrlBuilder.getUrl(EDIT_PATH, params);
|
||||||
|
|
|
@ -4,7 +4,11 @@ package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
@ -17,11 +21,15 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfigurationLoader;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.InvalidConfigurationException;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.DataPropertyListConfig;
|
||||||
|
import freemarker.cache.TemplateLoader;
|
||||||
|
|
||||||
public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
|
|
||||||
|
@ -31,6 +39,33 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
private static final String EDIT_PATH = "editRequestDispatch";
|
private static final String EDIT_PATH = "editRequestDispatch";
|
||||||
|
|
||||||
private final List<DataPropertyStatementTemplateModel> statements;
|
private final List<DataPropertyStatementTemplateModel> statements;
|
||||||
|
private static final String KEY_SUBJECT = "subject";
|
||||||
|
private static final String KEY_PROPERTY = "property";
|
||||||
|
|
||||||
|
public static enum ConfigError {
|
||||||
|
NO_SELECT_QUERY("Missing select query specification"),
|
||||||
|
NO_TEMPLATE("Missing template specification"),
|
||||||
|
TEMPLATE_NOT_FOUND("Specified template does not exist");
|
||||||
|
|
||||||
|
String message;
|
||||||
|
|
||||||
|
ConfigError(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private DataPropertyListConfig config;
|
||||||
|
private String objectKey;
|
||||||
|
private String queryString;
|
||||||
|
private Set<String> constructQueries;
|
||||||
|
|
||||||
DataPropertyTemplateModel(DataProperty dp, Individual subject, VitroRequest vreq,
|
DataPropertyTemplateModel(DataProperty dp, Individual subject, VitroRequest vreq,
|
||||||
boolean editing, List<DataProperty> populatedDataPropertyList) {
|
boolean editing, List<DataProperty> populatedDataPropertyList) {
|
||||||
|
@ -38,15 +73,25 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
super(dp, subject, vreq);
|
super(dp, subject, vreq);
|
||||||
setName(dp.getPublicName());
|
setName(dp.getPublicName());
|
||||||
|
|
||||||
|
// Get the config for this data property
|
||||||
|
try {
|
||||||
|
config = new DataPropertyListConfig(this, getFreemarkerTemplateLoader(), vreq, dp, editing);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
queryString = getSelectQuery();
|
||||||
|
constructQueries = getConstructQueries();
|
||||||
|
|
||||||
statements = new ArrayList<DataPropertyStatementTemplateModel>();
|
statements = new ArrayList<DataPropertyStatementTemplateModel>();
|
||||||
|
|
||||||
// If the property is populated, get the data property statements via a sparql query
|
// If the property is populated, get the data property statements via a sparql query
|
||||||
if (populatedDataPropertyList.contains(dp)) {
|
if (populatedDataPropertyList.contains(dp)) {
|
||||||
log.debug("Getting data for populated data property " + getUri());
|
log.debug("Getting data for populated data property " + getUri());
|
||||||
DataPropertyStatementDao dpDao = vreq.getWebappDaoFactory().getDataPropertyStatementDao();
|
DataPropertyStatementDao dpDao = vreq.getWebappDaoFactory().getDataPropertyStatementDao();
|
||||||
List<Literal> values = dpDao.getDataPropertyValuesForIndividualByProperty(subject, dp);
|
List<Literal> values = dpDao.getDataPropertyValuesForIndividualByProperty(subject, dp, queryString, constructQueries);
|
||||||
for (Literal value : values) {
|
for (Literal value : values) {
|
||||||
statements.add(new DataPropertyStatementTemplateModel(subjectUri, propertyUri, value, vreq));
|
statements.add(new DataPropertyStatementTemplateModel(subjectUri, propertyUri, value, getTemplateName(), vreq));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.debug("Data property " + getUri() + " is unpopulated.");
|
log.debug("Data property " + getUri() + " is unpopulated.");
|
||||||
|
@ -57,7 +102,6 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void setAddUrl(Property property) {
|
protected void setAddUrl(Property property) {
|
||||||
|
|
||||||
DataProperty dp = (DataProperty) property;
|
DataProperty dp = (DataProperty) property;
|
||||||
|
@ -91,6 +135,10 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
addUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
addUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected TemplateLoader getFreemarkerTemplateLoader() {
|
||||||
|
return FreemarkerConfigurationLoader.getConfig(vreq).getTemplateLoader();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getPropertyDisplayTier(Property p) {
|
protected int getPropertyDisplayTier(Property p) {
|
||||||
return ((DataProperty)p).getDisplayTier();
|
return ((DataProperty)p).getDisplayTier();
|
||||||
|
@ -101,6 +149,37 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
return Route.DATA_PROPERTY_EDIT;
|
return Route.DATA_PROPERTY_EDIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConfigError checkQuery(String queryString) {
|
||||||
|
if (StringUtils.isBlank(queryString)) {
|
||||||
|
return ConfigError.NO_SELECT_QUERY;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getSelectQuery() {
|
||||||
|
return config.getSelectQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<String> getConstructQueries() {
|
||||||
|
return config.getConstructQueries();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getTemplateName() {
|
||||||
|
return config.getTemplateName();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean hasDefaultListView() {
|
||||||
|
return config.isDefaultListView();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getObjectKey() {
|
||||||
|
return objectKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isEmpty() {
|
||||||
|
return statements.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
/* Template properties */
|
/* Template properties */
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
|
@ -111,6 +190,9 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
return statements;
|
return statements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTemplate() {
|
||||||
|
return getTemplateName();
|
||||||
|
}
|
||||||
|
|
||||||
/* Template methods */
|
/* Template methods */
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ public class DataPropertyDaoStub implements DataPropertyDao {
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
private final Map<String, DataProperty> dpMap = new HashMap<String, DataProperty>();
|
private final Map<String, DataProperty> dpMap = new HashMap<String, DataProperty>();
|
||||||
|
private final Map<String, String> configFilesMap = new HashMap<String, String>();
|
||||||
|
|
||||||
public void addDataProperty(DataProperty dataProperty) {
|
public void addDataProperty(DataProperty dataProperty) {
|
||||||
if (dataProperty == null) {
|
if (dataProperty == null) {
|
||||||
|
@ -40,6 +41,18 @@ public class DataPropertyDaoStub implements DataPropertyDao {
|
||||||
dpMap.put(uri, dataProperty);
|
dpMap.put(uri, dataProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCustomListViewConfigFileName(DataProperty property, String filename) {
|
||||||
|
if (property == null) {
|
||||||
|
throw new NullPointerException("property may not be null.");
|
||||||
|
}
|
||||||
|
|
||||||
|
String uri = property.getURI();
|
||||||
|
if (uri == null) {
|
||||||
|
throw new NullPointerException("uri may not be null.");
|
||||||
|
}
|
||||||
|
|
||||||
|
configFilesMap.put(uri, filename);
|
||||||
|
}
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Stub methods
|
// Stub methods
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
@ -49,6 +62,17 @@ public class DataPropertyDaoStub implements DataPropertyDao {
|
||||||
return dpMap.get(dataPropertyURI);
|
return dpMap.get(dataPropertyURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCustomListViewConfigFileName(DataProperty dataProperty) {
|
||||||
|
if (dataProperty == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String uri = dataProperty.getURI();
|
||||||
|
if (uri == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return configFilesMap.get(uri);
|
||||||
|
}
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Un-implemented methods
|
// Un-implemented methods
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
|
@ -34,9 +34,9 @@
|
||||||
</#if>
|
</#if>
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
||||||
<#macro dataPropertyList property editable>
|
<#macro dataPropertyList property editable template=property.template>
|
||||||
<#list property.statements as statement>
|
<#list property.statements as statement>
|
||||||
<@propertyListItem property statement editable >${statement.value}</@propertyListItem>
|
<@propertyListItem property statement editable ><#include "${template}"></@propertyListItem>
|
||||||
</#list>
|
</#list>
|
||||||
</#macro>
|
</#macro>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue