NIHVIVO-1341 Get custom view config file for a property.
NIHVIVO-1336 Sparql query for core:educationalTraining.
This commit is contained in:
parent
a161e5e737
commit
81a0a21536
5 changed files with 50 additions and 29 deletions
|
@ -56,5 +56,5 @@ public interface ObjectPropertyDao extends PropertyDao {
|
|||
|
||||
public List<ObjectProperty> getObjectPropertyList(String subjectUri);
|
||||
|
||||
public String getCustomListView();
|
||||
public String getCustomListConfigFilename(ObjectProperty objectProperty);
|
||||
}
|
||||
|
|
|
@ -216,7 +216,7 @@ class ObjectPropertyDaoFiltering extends BaseFiltering implements ObjectProperty
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getCustomListView() {
|
||||
return innerObjectPropertyDao.getCustomListView();
|
||||
public String getCustomListConfigFilename(ObjectProperty objectProperty) {
|
||||
return innerObjectPropertyDao.getCustomListConfigFilename(objectProperty);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ public class ApplicationDaoJena extends JenaBaseDao implements ApplicationDao {
|
|||
Integer portalCount = null;
|
||||
List<String> externallyLinkedNamespaces = null;
|
||||
|
||||
|
||||
public ApplicationDaoJena(WebappDaoFactoryJena wadf) {
|
||||
super(wadf);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
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.ProfileException;
|
||||
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.Literal;
|
||||
import com.hp.hpl.jena.rdf.model.NodeIterator;
|
||||
import com.hp.hpl.jena.rdf.model.Property;
|
||||
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.ResourceFactory;
|
||||
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 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.ObjectProperty;
|
||||
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) {
|
||||
super(wadf);
|
||||
}
|
||||
|
@ -859,9 +858,26 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getCustomListView() {
|
||||
//return getPropertyStringValue(, PROPERTY_CUSTOM_LIST_VIEW_ANNOT);
|
||||
return null;
|
||||
public String getCustomListConfigFilename(ObjectProperty op) {
|
||||
if (customListViewConfigFiles == 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.w3c.dom.NodeList;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
|
||||
public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel {
|
||||
|
@ -30,7 +31,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
|
||||
// Get the config for this object property
|
||||
try {
|
||||
config = new PropertyListConfig(op);
|
||||
config = new PropertyListConfig(op, wdf);
|
||||
} catch (Exception e) {
|
||||
log.error(e, e);
|
||||
}
|
||||
|
@ -69,31 +70,34 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
private String templateName;
|
||||
private String collationTarget;
|
||||
|
||||
PropertyListConfig(ObjectProperty op) throws Exception {
|
||||
String filename = DEFAULT_CONFIG_FILE;;
|
||||
PropertyListConfig(ObjectProperty op, WebappDaoFactory wdf) throws Exception {
|
||||
|
||||
// Get the config filename from ObjectPropertyDaoJena by looking for the custom property list view annotation.
|
||||
// If there is none, use the default config filename.
|
||||
// do stuff here to get the custom config filename ***
|
||||
// Get the custom config filename
|
||||
ObjectPropertyDao opDao = wdf.getObjectPropertyDao();
|
||||
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 {
|
||||
File config = new File(configFilename);
|
||||
if (configFilename != DEFAULT_CONFIG_FILE && ! config.exists()) {
|
||||
log.warn("Can't find config file " + configFilename + " for object property " + op.getURI() + "\n" +
|
||||
File config = new File(configFilePath);
|
||||
if (configFilePath != DEFAULT_CONFIG_FILE && ! config.exists()) {
|
||||
log.warn("Can't find config file " + configFilePath + " for object property " + op.getURI() + "\n" +
|
||||
". 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?
|
||||
}
|
||||
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
Document doc = db.parse(configFilename);
|
||||
Document doc = db.parse(configFilePath);
|
||||
queryString = getConfigValue(doc, NODE_NAME_QUERY);
|
||||
templateName = getConfigValue(doc, NODE_NAME_TEMPLATE);
|
||||
collationTarget = getConfigValue(doc, NODE_NAME_COLLATION_TARGET);
|
||||
} 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?
|
||||
}
|
||||
|
||||
|
@ -118,7 +122,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
return value;
|
||||
}
|
||||
|
||||
private String getConfigFilename(String filename) {
|
||||
private String getConfigFilePath(String filename) {
|
||||
return servletContext.getRealPath(CONFIG_FILE_PATH + filename);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue