NIHVIVO-1333 Output property names within each property group
This commit is contained in:
parent
f9a02c5218
commit
5b0a4eb03c
16 changed files with 222 additions and 381 deletions
|
@ -38,5 +38,7 @@ public interface DataPropertyStatementDao {
|
||||||
|
|
||||||
int insertNewDataPropertyStatement(DataPropertyStatement dataPropertyStatement );
|
int insertNewDataPropertyStatement(DataPropertyStatement dataPropertyStatement );
|
||||||
|
|
||||||
|
List<DataPropertyStatement> getDataPropertyStatementsForIndividualByProperty(Individual subject, DataProperty property);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,5 +90,10 @@ class DataPropertyStatementDaoFiltering extends BaseFiltering implements DataPro
|
||||||
return innerDataPropertyStatementDao.insertNewDataPropertyStatement(dataPropertyStatement);
|
return innerDataPropertyStatementDao.insertNewDataPropertyStatement(dataPropertyStatement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
// RY What about filtering?
|
||||||
|
public List<DataPropertyStatement> getDataPropertyStatementsForIndividualByProperty(Individual subject, DataProperty property) {
|
||||||
|
return innerDataPropertyStatementDao.getDataPropertyStatementsForIndividualByProperty(subject, property);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -10,6 +10,13 @@ import com.hp.hpl.jena.datatypes.TypeMapper;
|
||||||
import com.hp.hpl.jena.ontology.DatatypeProperty;
|
import com.hp.hpl.jena.ontology.DatatypeProperty;
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.ontology.OntResource;
|
import com.hp.hpl.jena.ontology.OntResource;
|
||||||
|
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.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.Property;
|
import com.hp.hpl.jena.rdf.model.Property;
|
||||||
|
@ -32,6 +39,23 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualUpdateEvent;
|
||||||
public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPropertyStatementDao
|
public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPropertyStatementDao
|
||||||
{
|
{
|
||||||
|
|
||||||
|
protected static final String dataPropertyValueQueryString =
|
||||||
|
"SELECT ?value WHERE { \n" +
|
||||||
|
//" GRAPH ?g {\n" +
|
||||||
|
" ?subject ?property ?value . \n" +
|
||||||
|
//" }\n" +
|
||||||
|
"}";
|
||||||
|
|
||||||
|
static protected Query dataPropertyValueQuery;
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
dataPropertyValueQuery = QueryFactory.create(dataPropertyValueQueryString);
|
||||||
|
} catch(Throwable th){
|
||||||
|
log.error("could not create SPARQL query for dataPropertyQueryString " + th.getMessage());
|
||||||
|
log.error(dataPropertyValueQueryString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public DataPropertyStatementDaoJena(WebappDaoFactoryJena wadf) {
|
public DataPropertyStatementDaoJena(WebappDaoFactoryJena wadf) {
|
||||||
super(wadf);
|
super(wadf);
|
||||||
}
|
}
|
||||||
|
@ -254,4 +278,32 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
/*
|
||||||
|
* SPARQL-based method for getting the individual's values for a single data property.
|
||||||
|
*/
|
||||||
|
public List<DataPropertyStatement> getDataPropertyStatementsForIndividualByProperty(Individual subject, DataProperty property) {
|
||||||
|
log.debug("dataPropertyValueQueryString:\n" + dataPropertyValueQueryString);
|
||||||
|
log.debug("dataPropertyValueQuery:\n" + dataPropertyValueQuery);
|
||||||
|
|
||||||
|
String subjectUri = subject.getURI();
|
||||||
|
String propertyUri = property.getURI();
|
||||||
|
|
||||||
|
QuerySolutionMap bindings = new QuerySolutionMap();
|
||||||
|
bindings.add("subject", ResourceFactory.createResource(subjectUri));
|
||||||
|
bindings.add("property", ResourceFactory.createResource(propertyUri));
|
||||||
|
|
||||||
|
// Run the SPARQL query to get the properties
|
||||||
|
QueryExecution qexec = QueryExecutionFactory.create(dataPropertyValueQuery, getOntModelSelector().getFullModel(), bindings);
|
||||||
|
ResultSet results = qexec.execSelect();
|
||||||
|
|
||||||
|
List<DataPropertyStatement> values = new ArrayList<DataPropertyStatement>();
|
||||||
|
while (results.hasNext()) {
|
||||||
|
QuerySolution sol = results.next();
|
||||||
|
Literal value = sol.getLiteral("value");
|
||||||
|
DataPropertyStatement dps = new DataPropertyStatementImpl(subjectUri, propertyUri, value.getLexicalForm());
|
||||||
|
values.add(dps);
|
||||||
|
}
|
||||||
|
return values;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,17 @@ import java.util.List;
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
|
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.QuerySolutionMap;
|
||||||
|
import com.hp.hpl.jena.query.ResultSet;
|
||||||
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.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
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.Statement;
|
import com.hp.hpl.jena.rdf.model.Statement;
|
||||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||||
import com.hp.hpl.jena.shared.Lock;
|
import com.hp.hpl.jena.shared.Lock;
|
||||||
|
@ -97,4 +102,29 @@ public class DataPropertyStatementDaoSDB extends DataPropertyStatementDaoJena
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DataPropertyStatement> getDataPropertyStatementsForIndividualByProperty(Individual subject, DataProperty property) {
|
||||||
|
log.debug("dataPropertyValueQueryString:\n" + dataPropertyValueQueryString);
|
||||||
|
log.debug("dataPropertyValueQuery:\n" + dataPropertyValueQuery);
|
||||||
|
|
||||||
|
String subjectUri = subject.getURI();
|
||||||
|
String propertyUri = property.getURI();
|
||||||
|
|
||||||
|
QuerySolutionMap bindings = new QuerySolutionMap();
|
||||||
|
bindings.add("subject", ResourceFactory.createResource(subjectUri));
|
||||||
|
bindings.add("property", ResourceFactory.createResource(propertyUri));
|
||||||
|
|
||||||
|
// Run the SPARQL query to get the properties
|
||||||
|
QueryExecution qexec = QueryExecutionFactory.create(dataPropertyValueQuery, getOntModelSelector().getFullModel(), bindings);
|
||||||
|
ResultSet results = qexec.execSelect();
|
||||||
|
|
||||||
|
List<DataPropertyStatement> values = new ArrayList<DataPropertyStatement>();
|
||||||
|
while (results.hasNext()) {
|
||||||
|
QuerySolution sol = results.next();
|
||||||
|
Literal value = sol.getLiteral("value");
|
||||||
|
DataPropertyStatement dps = new DataPropertyStatementImpl(subjectUri, propertyUri, value.getLexicalForm());
|
||||||
|
values.add(dps);
|
||||||
|
}
|
||||||
|
return values;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
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;
|
||||||
|
@ -30,6 +31,8 @@ import com.hp.hpl.jena.query.Query;
|
||||||
import com.hp.hpl.jena.query.QueryExecution;
|
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.ResultSet;
|
||||||
import com.hp.hpl.jena.query.Syntax;
|
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;
|
||||||
|
@ -945,4 +948,68 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ****************************************************************************** */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a sparql query that returns a multiple rows to a list of maps.
|
||||||
|
* The maps will have column names as keys to the values.
|
||||||
|
*/
|
||||||
|
protected List<Map<String, Object>> executeQueryToCollection(
|
||||||
|
QueryExecution qexec) {
|
||||||
|
List<Map<String, Object>> rv = new ArrayList<Map<String, Object>>();
|
||||||
|
ResultSet results = qexec.execSelect();
|
||||||
|
while (results.hasNext()) {
|
||||||
|
QuerySolution soln = results.nextSolution();
|
||||||
|
rv.add(querySolutionToMap(soln));
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<String,Object> querySolutionToMap( QuerySolution soln ){
|
||||||
|
Map<String,Object> map = new HashMap<String,Object>();
|
||||||
|
Iterator<String> varNames = soln.varNames();
|
||||||
|
while(varNames.hasNext()){
|
||||||
|
String varName = varNames.next();
|
||||||
|
map.put(varName, nodeToObject( soln.get(varName)));
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
static protected Object nodeToObject( RDFNode node ){
|
||||||
|
if( node == null ){
|
||||||
|
return "";
|
||||||
|
}else if( node.isLiteral() ){
|
||||||
|
Literal literal = node.asLiteral();
|
||||||
|
return literal.getValue();
|
||||||
|
}else if( node.isURIResource() ){
|
||||||
|
Resource resource = node.asResource();
|
||||||
|
return resource.getURI();
|
||||||
|
}else if( node.isAnon() ){
|
||||||
|
Resource resource = node.asResource();
|
||||||
|
return resource.getId().getLabelString(); //get b-node id
|
||||||
|
}else{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static protected String nodeToString( RDFNode node ){
|
||||||
|
if( node == null ){
|
||||||
|
return "";
|
||||||
|
}else if( node.isLiteral() ){
|
||||||
|
Literal literal = node.asLiteral();
|
||||||
|
return literal.getLexicalForm();
|
||||||
|
}else if( node.isURIResource() ){
|
||||||
|
Resource resource = node.asResource();
|
||||||
|
return resource.getURI();
|
||||||
|
}else if( node.isAnon() ){
|
||||||
|
Resource resource = node.asResource();
|
||||||
|
return resource.getId().getLabelString(); //get b-node id
|
||||||
|
}else{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected Map<String,Object> resultsToMap(){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,68 +161,5 @@ public class PageDaoJena extends JenaBaseDao implements PageDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ****************************************************************************** */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a sparql query that returns a multiple rows to a list of maps.
|
|
||||||
* The maps will have column names as keys to the values.
|
|
||||||
*/
|
|
||||||
protected List<Map<String, Object>> executeQueryToCollection(
|
|
||||||
QueryExecution qexec) {
|
|
||||||
List<Map<String, Object>> rv = new ArrayList<Map<String, Object>>();
|
|
||||||
ResultSet results = qexec.execSelect();
|
|
||||||
while (results.hasNext()) {
|
|
||||||
QuerySolution soln = results.nextSolution();
|
|
||||||
rv.add(querySolutionToMap(soln));
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Map<String,Object> querySolutionToMap( QuerySolution soln ){
|
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
|
||||||
Iterator<String> varNames = soln.varNames();
|
|
||||||
while(varNames.hasNext()){
|
|
||||||
String varName = varNames.next();
|
|
||||||
map.put(varName, nodeToObject( soln.get(varName)));
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
static protected Object nodeToObject( RDFNode node ){
|
|
||||||
if( node == null ){
|
|
||||||
return "";
|
|
||||||
}else if( node.isLiteral() ){
|
|
||||||
Literal literal = node.asLiteral();
|
|
||||||
return literal.getValue();
|
|
||||||
}else if( node.isURIResource() ){
|
|
||||||
Resource resource = node.asResource();
|
|
||||||
return resource.getURI();
|
|
||||||
}else if( node.isAnon() ){
|
|
||||||
Resource resource = node.asResource();
|
|
||||||
return resource.getId().getLabelString(); //get b-node id
|
|
||||||
}else{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static protected String nodeToString( RDFNode node ){
|
|
||||||
if( node == null ){
|
|
||||||
return "";
|
|
||||||
}else if( node.isLiteral() ){
|
|
||||||
Literal literal = node.asLiteral();
|
|
||||||
return literal.getLexicalForm();
|
|
||||||
}else if( node.isURIResource() ){
|
|
||||||
Resource resource = node.asResource();
|
|
||||||
return resource.getURI();
|
|
||||||
}else if( node.isAnon() ){
|
|
||||||
Resource resource = node.asResource();
|
|
||||||
return resource.getId().getLabelString(); //get b-node id
|
|
||||||
}else{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected Map<String,Object> resultsToMap(){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,18 +5,31 @@ package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
public class DataPropertyStatementTemplateModel extends PropertyStatementTemplateModel {
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
||||||
|
|
||||||
|
public class DataPropertyStatementTemplateModel extends BaseTemplateModel {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(DataPropertyStatementTemplateModel.class);
|
private static final Log log = LogFactory.getLog(DataPropertyStatementTemplateModel.class);
|
||||||
|
|
||||||
// not sure whether we want the objects or the uris here
|
private DataPropertyStatement statement;
|
||||||
//protected DataProperty property = null;
|
|
||||||
protected String predicateUri = null;
|
|
||||||
protected String data = null;
|
|
||||||
|
|
||||||
DataPropertyStatementTemplateModel(String subjectUri, String predicateUri, String data) {
|
DataPropertyStatementTemplateModel(DataPropertyStatement statement) {
|
||||||
this.subjectUri = subjectUri;
|
this.statement = statement;
|
||||||
this.predicateUri = predicateUri;
|
|
||||||
this.data = data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Access methods for templates */
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return statement.getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEditLink() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeleteLink() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,18 +2,30 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
|
||||||
public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
|
|
||||||
private static final String TYPE = "data";
|
private static final String TYPE = "data";
|
||||||
|
private List<DataPropertyStatementTemplateModel> statements;
|
||||||
|
|
||||||
DataPropertyTemplateModel(DataProperty dp) {
|
DataPropertyTemplateModel(DataProperty dp, Individual subject, WebappDaoFactory wdf) {
|
||||||
super(dp);
|
super(dp);
|
||||||
|
// Get the data property statements via sparql query
|
||||||
// get the data property statements from the db via sparql query
|
DataPropertyStatementDao dpDao = wdf.getDataPropertyStatementDao();
|
||||||
|
List<DataPropertyStatement> dpStatements = dpDao.getDataPropertyStatementsForIndividualByProperty(subject, dp);
|
||||||
|
statements = new ArrayList<DataPropertyStatementTemplateModel>(dpStatements.size());
|
||||||
|
for (DataPropertyStatement dps : dpStatements) {
|
||||||
|
statements.add(new DataPropertyStatementTemplateModel(dps));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Access methods for templates */
|
/* Access methods for templates */
|
||||||
|
|
||||||
|
@ -21,25 +33,27 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
||||||
return TYPE;
|
return TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAddLink() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String addLink() {
|
public String getEditLink() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String editLink() {
|
public String getDeleteLink() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<DataPropertyStatementTemplateModel> getStatements() {
|
||||||
@Override
|
return statements;
|
||||||
public String deleteLink() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
|
|
||||||
|
|
||||||
public class DummyPropertyGroupTemplateModel extends
|
|
||||||
PropertyGroupTemplateModel {
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
DummyPropertyGroupTemplateModel(String name) {
|
|
||||||
super(null);
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -22,21 +22,21 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
public abstract boolean getIsCollatedBySubtype();
|
public abstract boolean getIsCollatedBySubtype();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String addLink() {
|
public String getAddLink() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String editLink() {
|
public String getEditLink() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deleteLink() {
|
public String getDeleteLink() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,11 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
|
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
||||||
|
|
||||||
public class PropertyGroupTemplateModel extends BaseTemplateModel {
|
public class PropertyGroupTemplateModel extends BaseTemplateModel {
|
||||||
|
@ -16,9 +18,7 @@ public class PropertyGroupTemplateModel extends BaseTemplateModel {
|
||||||
private String name;
|
private String name;
|
||||||
private List<PropertyTemplateModel> properties;
|
private List<PropertyTemplateModel> properties;
|
||||||
|
|
||||||
PropertyGroupTemplateModel() { }
|
PropertyGroupTemplateModel(WebappDaoFactory wdf, PropertyGroup group, Individual subject) {
|
||||||
|
|
||||||
PropertyGroupTemplateModel(PropertyGroup group) {
|
|
||||||
this.name = group.getName();
|
this.name = group.getName();
|
||||||
|
|
||||||
List<Property> propertyList = group.getPropertyList();
|
List<Property> propertyList = group.getPropertyList();
|
||||||
|
@ -32,7 +32,7 @@ public class PropertyGroupTemplateModel extends BaseTemplateModel {
|
||||||
properties.add(new UncollatedObjectProperty(op));
|
properties.add(new UncollatedObjectProperty(op));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
properties.add(new DataPropertyTemplateModel((DataProperty)p));
|
properties.add(new DataPropertyTemplateModel((DataProperty)p, subject, wdf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,219 +0,0 @@
|
||||||
/* $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.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
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.beans.Individual;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Property;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.PropertyInstance;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
|
||||||
|
|
||||||
public class PropertyList extends BaseTemplateModel {
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(PropertyList.class);
|
|
||||||
|
|
||||||
private List<Property> propertyList;
|
|
||||||
|
|
||||||
PropertyList() {
|
|
||||||
propertyList = new ArrayList<Property>();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addObjectProperties(List<ObjectProperty> propertyList) {
|
|
||||||
for (ObjectProperty op : propertyList) {
|
|
||||||
add(op);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void add(ObjectProperty op) {
|
|
||||||
propertyList.add(op);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addDataProperties(List<DataProperty> propertyList) {
|
|
||||||
for (DataProperty dp : propertyList) {
|
|
||||||
add(dp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void add(DataProperty p) {
|
|
||||||
propertyList.add(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean contains(Property property) {
|
|
||||||
String propertyUri = property.getURI();
|
|
||||||
if (propertyUri == null) {
|
|
||||||
log.error("Property has no propertyURI in alreadyOnPropertyList()");
|
|
||||||
return true; // don't add to list
|
|
||||||
}
|
|
||||||
for (Property p : propertyList) {
|
|
||||||
if (propertyUri.equals(p.getURI())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean contains(List<ObjectProperty> list, PropertyInstance pi) {
|
|
||||||
if (pi.getPropertyURI() == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (ObjectProperty op : list) {
|
|
||||||
if (op.getURI() != null && op.getURI().equals(pi.getPropertyURI())) {
|
|
||||||
return op.isSubjectSide() == pi.getSubjectSide();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<Property> getProperties() {
|
|
||||||
return propertyList;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void mergeAllPossibleObjectProperties(WebappDaoFactory wdf, Individual subject, List<ObjectProperty> objectPropertyList) {
|
|
||||||
PropertyInstanceDao piDao = wdf.getPropertyInstanceDao();
|
|
||||||
// RY *** Does this exclude properties in the excluded namespaces already? If not, need same test as above
|
|
||||||
Collection<PropertyInstance> allPropInstColl = piDao.getAllPossiblePropInstForIndividual(subject.getURI());
|
|
||||||
if (allPropInstColl != null) {
|
|
||||||
for (PropertyInstance pi : allPropInstColl) {
|
|
||||||
if (pi != null) {
|
|
||||||
// RY Do we need to check this before checking if it's on the property list??
|
|
||||||
if (! contains(objectPropertyList, pi)) {
|
|
||||||
ObjectPropertyDao opDao = wdf.getObjectPropertyDao();
|
|
||||||
ObjectProperty op = opDao.getObjectPropertyByURI(pi.getPropertyURI());
|
|
||||||
if (op == null) {
|
|
||||||
log.error("ObjectProperty op returned null from opDao.getObjectPropertyByURI()");
|
|
||||||
} else if (op.getURI() == null) {
|
|
||||||
log.error("ObjectProperty op returned with null propertyURI from opDao.getObjectPropertyByURI()");
|
|
||||||
} else if (! contains(op)) {
|
|
||||||
add(op);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.error("a property instance in the Collection created by PropertyInstanceDao.getAllPossiblePropInstForIndividual() is unexpectedly null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.error("a null Collection is returned from PropertyInstanceDao.getAllPossiblePropInstForIndividual()");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void mergeAllPossibleDataProperties(WebappDaoFactory wdf, Individual subject) {
|
|
||||||
DataPropertyDao dpDao = wdf.getDataPropertyDao();
|
|
||||||
// RY *** Does this exclude properties in the excluded namespaces already? If not, need same test as above
|
|
||||||
Collection <DataProperty> allDatapropColl = dpDao.getAllPossibleDatapropsForIndividual(subject.getURI());
|
|
||||||
if (allDatapropColl != null) {
|
|
||||||
for (DataProperty dp : allDatapropColl ) {
|
|
||||||
if (dp!=null) {
|
|
||||||
if (dp.getURI() == null) {
|
|
||||||
log.error("DataProperty dp returned with null propertyURI from dpDao.getAllPossibleDatapropsForIndividual()");
|
|
||||||
} else if (! contains(dp)) {
|
|
||||||
add(dp);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.error("a data property in the Collection created in DataPropertyDao.getAllPossibleDatapropsForIndividual() is unexpectedly null)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.error("a null Collection is returned from DataPropertyDao.getAllPossibleDatapropsForIndividual())");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
protected void sort(VitroRequest vreq) {
|
|
||||||
try {
|
|
||||||
Collections.sort(propertyList, new PropertyRanker(vreq));
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.error("Exception sorting merged property list: " + ex.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class PropertyRanker implements Comparator {
|
|
||||||
|
|
||||||
WebappDaoFactory wdf;
|
|
||||||
PropertyGroupDao pgDao;
|
|
||||||
|
|
||||||
private PropertyRanker(VitroRequest vreq) {
|
|
||||||
this.wdf = vreq.getWebappDaoFactory();
|
|
||||||
this.pgDao = wdf.getPropertyGroupDao();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compare (Object o1, Object o2) {
|
|
||||||
Property p1 = (Property) o1;
|
|
||||||
Property p2 = (Property) o2;
|
|
||||||
|
|
||||||
// sort first by property group rank; if the same, then sort by property rank
|
|
||||||
final int MAX_GROUP_RANK=99;
|
|
||||||
|
|
||||||
int p1GroupRank=MAX_GROUP_RANK;
|
|
||||||
try {
|
|
||||||
if (p1.getGroupURI()!=null) {
|
|
||||||
PropertyGroup pg1 = pgDao.getGroupByURI(p1.getGroupURI());
|
|
||||||
if (pg1!=null) {
|
|
||||||
p1GroupRank=pg1.getDisplayRank();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.error("Cannot retrieve p1GroupRank for group "+p1.getLabel());
|
|
||||||
}
|
|
||||||
|
|
||||||
int p2GroupRank=MAX_GROUP_RANK;
|
|
||||||
try {
|
|
||||||
if (p2.getGroupURI()!=null) {
|
|
||||||
PropertyGroup pg2 = pgDao.getGroupByURI(p2.getGroupURI());
|
|
||||||
if (pg2!=null) {
|
|
||||||
p2GroupRank=pg2.getDisplayRank();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.error("Cannot retrieve p2GroupRank for group "+p2.getLabel());
|
|
||||||
}
|
|
||||||
|
|
||||||
// int diff = pgDao.getGroupByURI(p1.getGroupURI()).getDisplayRank() - pgDao.getGroupByURI(p2.getGroupURI()).getDisplayRank();
|
|
||||||
int diff=p1GroupRank - p2GroupRank;
|
|
||||||
if (diff==0) {
|
|
||||||
diff = determineDisplayRank(p1) - determineDisplayRank(p2);
|
|
||||||
if (diff==0) {
|
|
||||||
return p1.getLabel().compareTo(p2.getLabel());
|
|
||||||
} else {
|
|
||||||
return diff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return diff;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int determineDisplayRank(Property p) {
|
|
||||||
if (p instanceof DataProperty) {
|
|
||||||
DataProperty dp = (DataProperty)p;
|
|
||||||
return dp.getDisplayTier();
|
|
||||||
} else if (p instanceof ObjectProperty) {
|
|
||||||
ObjectProperty op = (ObjectProperty)p;
|
|
||||||
String tierStr = op.getDomainDisplayTier(); // no longer used: p.isSubjectSide() ? op.getDomainDisplayTier() : op.getRangeDisplayTier();
|
|
||||||
try {
|
|
||||||
return Integer.parseInt(tierStr);
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
log.error("Cannot decode object property display tier value "+tierStr+" as an integer");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.error("Property is of unknown class in PropertyRanker()");
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -7,6 +7,7 @@ import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -56,7 +57,6 @@ public class PropertyListBuilder {
|
||||||
boolean userCanEditThisProfile = getEditingStatus();
|
boolean userCanEditThisProfile = getEditingStatus();
|
||||||
|
|
||||||
// Create the property list for the subject. The properties will be put into groups later.
|
// Create the property list for the subject. The properties will be put into groups later.
|
||||||
//PropertyList propertyList = new PropertyList();
|
|
||||||
List<Property> propertyList = new ArrayList<Property>();
|
List<Property> propertyList = new ArrayList<Property>();
|
||||||
|
|
||||||
// First get all the object properties that occur in statements in the db with this subject as subject.
|
// First get all the object properties that occur in statements in the db with this subject as subject.
|
||||||
|
@ -98,13 +98,11 @@ public class PropertyListBuilder {
|
||||||
List<PropertyGroup> groupList = addPropertiesToGroups(propertyList);
|
List<PropertyGroup> groupList = addPropertiesToGroups(propertyList);
|
||||||
|
|
||||||
// Build the template data model from the groupList
|
// Build the template data model from the groupList
|
||||||
|
// List<Map<String, Object>> groups = new ArrayList<Map<String, Object>>(groupList.size());
|
||||||
List<PropertyGroupTemplateModel> groups = new ArrayList<PropertyGroupTemplateModel>(groupList.size());
|
List<PropertyGroupTemplateModel> groups = new ArrayList<PropertyGroupTemplateModel>(groupList.size());
|
||||||
for (PropertyGroup pg : groupList) {
|
for (PropertyGroup pg : groupList) {
|
||||||
groups.add(new PropertyGroupTemplateModel(pg));
|
groups.add(new PropertyGroupTemplateModel(wdf, pg, subject));
|
||||||
}
|
}
|
||||||
// *** ADD collation and statements here ***
|
|
||||||
// Don't include custom sorting, since that will be handled from custom short views
|
|
||||||
// We'll populate each item in the property list with its statements or subclass lists
|
|
||||||
|
|
||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
|
||||||
|
|
||||||
public abstract class PropertyStatementTemplateModel extends BaseTemplateModel {
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(PropertyStatementTemplateModel.class);
|
|
||||||
|
|
||||||
protected Individual subject = null; // not sure whether we want subject, or subject uri
|
|
||||||
protected String subjectUri = null;
|
|
||||||
|
|
||||||
|
|
||||||
public String getEditLink() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDeleteLink() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -20,24 +20,16 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
|
||||||
|
|
||||||
/* Access methods for templates */
|
/* Access methods for templates */
|
||||||
|
|
||||||
public String getAddLink() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract String getType();
|
public abstract String getType();
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// protected String getUri() {
|
public abstract String getAddLink();
|
||||||
// return property.getURI();
|
|
||||||
// }
|
|
||||||
|
|
||||||
public abstract String addLink();
|
public abstract String getEditLink();
|
||||||
|
|
||||||
public abstract String editLink();
|
public abstract String getDeleteLink();
|
||||||
|
|
||||||
public abstract String deleteLink();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,8 @@
|
||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
<#-- Now list the properties in the group -->
|
<#-- Now list the properties in the group -->
|
||||||
<p>Number of properties in group: ${group.properties?size}</p> <#-- temporary -->
|
|
||||||
<#--
|
|
||||||
<#list group.properties as property>
|
<#list group.properties as property>
|
||||||
|
<h4>${property.name}</h4>
|
||||||
</#list>
|
</#list>
|
||||||
-->
|
|
||||||
|
|
||||||
</#list>
|
</#list>
|
Loading…
Add table
Add a link
Reference in a new issue