NIHVIVO-1341 Get custom view config file for a property.

NIHVIVO-1336 Sparql query for core:educationalTraining.
This commit is contained in:
rjy7 2010-12-15 16:52:58 +00:00
parent a161e5e737
commit 81a0a21536
5 changed files with 50 additions and 29 deletions

View file

@ -56,5 +56,5 @@ public interface ObjectPropertyDao extends PropertyDao {
public List<ObjectProperty> getObjectPropertyList(String subjectUri); public List<ObjectProperty> getObjectPropertyList(String subjectUri);
public String getCustomListView(); public String getCustomListConfigFilename(ObjectProperty objectProperty);
} }

View file

@ -216,7 +216,7 @@ class ObjectPropertyDaoFiltering extends BaseFiltering implements ObjectProperty
} }
@Override @Override
public String getCustomListView() { public String getCustomListConfigFilename(ObjectProperty objectProperty) {
return innerObjectPropertyDao.getCustomListView(); return innerObjectPropertyDao.getCustomListConfigFilename(objectProperty);
} }
} }

View file

@ -20,6 +20,7 @@ public class ApplicationDaoJena extends JenaBaseDao implements ApplicationDao {
Integer portalCount = null; Integer portalCount = null;
List<String> externallyLinkedNamespaces = null; List<String> externallyLinkedNamespaces = null;
public ApplicationDaoJena(WebappDaoFactoryJena wadf) { public ApplicationDaoJena(WebappDaoFactoryJena wadf) {
super(wadf); super(wadf);
} }

View file

@ -7,6 +7,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
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;
@ -18,15 +19,14 @@ import com.hp.hpl.jena.ontology.OntProperty;
import com.hp.hpl.jena.ontology.OntResource; import com.hp.hpl.jena.ontology.OntResource;
import com.hp.hpl.jena.ontology.ProfileException; import com.hp.hpl.jena.ontology.ProfileException;
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.QuerySolutionMap;
import com.hp.hpl.jena.query.ResultSet; 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.NodeIterator;
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.RDFNode;
import com.hp.hpl.jena.rdf.model.ResIterator;
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,9 +38,6 @@ import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.RDFS;
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean; import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; 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.ObjectPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
@ -74,6 +71,8 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
} }
} }
Map<ObjectProperty, String> customListViewConfigFiles = null;
public ObjectPropertyDaoJena(WebappDaoFactoryJena wadf) { public ObjectPropertyDaoJena(WebappDaoFactoryJena wadf) {
super(wadf); super(wadf);
} }
@ -859,9 +858,26 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
} }
@Override @Override
public String getCustomListView() { public String getCustomListConfigFilename(ObjectProperty op) {
//return getPropertyStringValue(, PROPERTY_CUSTOM_LIST_VIEW_ANNOT); if (customListViewConfigFiles == null) {
return null; customListViewConfigFiles = new HashMap<ObjectProperty, String>();
OntModel ontModel = getOntModelSelector().getDisplayModel();
Property listViewConfigProp = ontModel.getProperty(VitroVocabulary.DISPLAY + "customListViewConfigurationFile");
ResIterator resources = ontModel.listResourcesWithProperty(listViewConfigProp);
while (resources.hasNext()) {
Resource resource = resources.next();
ObjectProperty prop = getObjectPropertyByURI(resource.getURI());
NodeIterator nodes = ontModel.listObjectsOfProperty(resource, listViewConfigProp);
if (nodes.hasNext()) {
RDFNode node = nodes.next(); // there should be at most one value; just get the first one
if (node.isLiteral()) {
String configFileName = ((Literal)node).getLexicalForm();
customListViewConfigFiles.put(prop, configFileName);
}
}
}
}
return customListViewConfigFiles.get(op);
} }
} }

View file

@ -15,6 +15,7 @@ import org.w3c.dom.NodeList;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; 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.dao.ObjectPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel { public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel {
@ -30,7 +31,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
// Get the config for this object property // Get the config for this object property
try { try {
config = new PropertyListConfig(op); config = new PropertyListConfig(op, wdf);
} catch (Exception e) { } catch (Exception e) {
log.error(e, e); log.error(e, e);
} }
@ -69,31 +70,34 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
private String templateName; private String templateName;
private String collationTarget; private String collationTarget;
PropertyListConfig(ObjectProperty op) throws Exception { PropertyListConfig(ObjectProperty op, WebappDaoFactory wdf) throws Exception {
String filename = DEFAULT_CONFIG_FILE;;
// Get the config filename from ObjectPropertyDaoJena by looking for the custom property list view annotation. // Get the custom config filename
// If there is none, use the default config filename. ObjectPropertyDao opDao = wdf.getObjectPropertyDao();
// do stuff here to get the custom config filename *** String filename = opDao.getCustomListConfigFilename(op);
if (filename == null) { // no custom config; use default config
filename = DEFAULT_CONFIG_FILE;
}
log.debug("Using custom list view config file " + filename + " for object property " + op.getURI());
String configFilename = getConfigFilename(filename); String configFilePath = getConfigFilePath(filename);
try { try {
File config = new File(configFilename); File config = new File(configFilePath);
if (configFilename != DEFAULT_CONFIG_FILE && ! config.exists()) { if (configFilePath != DEFAULT_CONFIG_FILE && ! config.exists()) {
log.warn("Can't find config file " + configFilename + " for object property " + op.getURI() + "\n" + log.warn("Can't find config file " + configFilePath + " for object property " + op.getURI() + "\n" +
". Using default config file instead."); ". Using default config file instead.");
configFilename = getConfigFilename(DEFAULT_CONFIG_FILE); configFilePath = getConfigFilePath(DEFAULT_CONFIG_FILE);
// Should we test for the existence of the default, and throw an error if it doesn't exist? // Should we test for the existence of the default, and throw an error if it doesn't exist?
} }
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder(); DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(configFilename); Document doc = db.parse(configFilePath);
queryString = getConfigValue(doc, NODE_NAME_QUERY); queryString = getConfigValue(doc, NODE_NAME_QUERY);
templateName = getConfigValue(doc, NODE_NAME_TEMPLATE); templateName = getConfigValue(doc, NODE_NAME_TEMPLATE);
collationTarget = getConfigValue(doc, NODE_NAME_COLLATION_TARGET); collationTarget = getConfigValue(doc, NODE_NAME_COLLATION_TARGET);
} catch (Exception e) { } catch (Exception e) {
log.error("Error processing config file " + configFilename + " for object property " + op.getURI(), e); log.error("Error processing config file " + configFilePath + " for object property " + op.getURI(), e);
// What should we do here? // What should we do here?
} }
@ -118,7 +122,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
return value; return value;
} }
private String getConfigFilename(String filename) { private String getConfigFilePath(String filename) {
return servletContext.getRealPath(CONFIG_FILE_PATH + filename); return servletContext.getRealPath(CONFIG_FILE_PATH + filename);
} }
} }