NIHVIVO-1341 SPARQL version of method to get custom list views for object properties
This commit is contained in:
parent
e6934a1623
commit
bad4b806e4
1 changed files with 52 additions and 24 deletions
|
@ -13,20 +13,21 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
|
||||
import com.hp.hpl.jena.graph.Node;
|
||||
import com.hp.hpl.jena.ontology.ConversionException;
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
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.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;
|
||||
|
@ -71,7 +72,22 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
|||
}
|
||||
}
|
||||
|
||||
Map<ObjectProperty, String> customListViewConfigFiles = null;
|
||||
static protected String customListViewConfigFileQueryString =
|
||||
"PREFIX display: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#>" +
|
||||
"SELECT ?property ?filename WHERE { \n" +
|
||||
" ?property display:customListViewConfigurationFile ?filename . \n" +
|
||||
"} LIMIT 1";
|
||||
static protected Query customListViewConfigFileQuery;
|
||||
static {
|
||||
try {
|
||||
customListViewConfigFileQuery = QueryFactory.create(customListViewConfigFileQueryString);
|
||||
} catch(Throwable th){
|
||||
log.error("could not create SPARQL query for customListViewConfigFileQueryString " + th.getMessage());
|
||||
log.error(customListViewConfigFileQueryString);
|
||||
}
|
||||
}
|
||||
|
||||
Map<ObjectProperty, String> customListViewConfigFileMap = null;
|
||||
|
||||
public ObjectPropertyDaoJena(WebappDaoFactoryJena wadf) {
|
||||
super(wadf);
|
||||
|
@ -848,8 +864,8 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
|||
ResultSet results = getPropertyQueryResults(subjectUri, objectPropertyQuery);
|
||||
List<ObjectProperty> properties = new ArrayList<ObjectProperty>();
|
||||
while (results.hasNext()) {
|
||||
QuerySolution sol = results.next();
|
||||
Resource resource = sol.getResource("property");
|
||||
QuerySolution soln = results.next();
|
||||
Resource resource = soln.getResource("property");
|
||||
String uri = resource.getURI();
|
||||
ObjectProperty property = getObjectPropertyByURI(uri);
|
||||
properties.add(property);
|
||||
|
@ -859,25 +875,37 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
|||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (customListViewConfigFileMap == null) {
|
||||
customListViewConfigFileMap = new HashMap<ObjectProperty, String>();
|
||||
OntModel displayModel = getOntModelSelector().getDisplayModel();
|
||||
|
||||
// Property listViewConfigProp = displayModel.getProperty(VitroVocabulary.DISPLAY + "customListViewConfigurationFile");
|
||||
// ResIterator resources = displayModel.listResourcesWithProperty(listViewConfigProp);
|
||||
// while (resources.hasNext()) {
|
||||
// Resource resource = resources.next();
|
||||
// ObjectProperty prop = getObjectPropertyByURI(resource.getURI());
|
||||
// NodeIterator nodes = displayModel.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);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
QueryExecution qexec = QueryExecutionFactory.create(customListViewConfigFileQuery, displayModel);
|
||||
ResultSet results = qexec.execSelect();
|
||||
while (results.hasNext()) {
|
||||
QuerySolution soln = results.next();
|
||||
Resource resource = soln.getResource("property");
|
||||
String uri = resource.getURI();
|
||||
ObjectProperty prop = getObjectPropertyByURI(uri);
|
||||
String filename = soln.getLiteral("filename").getLexicalForm();
|
||||
customListViewConfigFileMap.put(prop, filename);
|
||||
}
|
||||
}
|
||||
return customListViewConfigFiles.get(op);
|
||||
return customListViewConfigFileMap.get(op);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue