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 org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
|
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.ConversionException;
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.ontology.OntProperty;
|
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.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;
|
||||||
|
@ -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) {
|
public ObjectPropertyDaoJena(WebappDaoFactoryJena wadf) {
|
||||||
super(wadf);
|
super(wadf);
|
||||||
|
@ -848,8 +864,8 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
||||||
ResultSet results = getPropertyQueryResults(subjectUri, objectPropertyQuery);
|
ResultSet results = getPropertyQueryResults(subjectUri, objectPropertyQuery);
|
||||||
List<ObjectProperty> properties = new ArrayList<ObjectProperty>();
|
List<ObjectProperty> properties = new ArrayList<ObjectProperty>();
|
||||||
while (results.hasNext()) {
|
while (results.hasNext()) {
|
||||||
QuerySolution sol = results.next();
|
QuerySolution soln = results.next();
|
||||||
Resource resource = sol.getResource("property");
|
Resource resource = soln.getResource("property");
|
||||||
String uri = resource.getURI();
|
String uri = resource.getURI();
|
||||||
ObjectProperty property = getObjectPropertyByURI(uri);
|
ObjectProperty property = getObjectPropertyByURI(uri);
|
||||||
properties.add(property);
|
properties.add(property);
|
||||||
|
@ -859,25 +875,37 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCustomListConfigFilename(ObjectProperty op) {
|
public String getCustomListConfigFilename(ObjectProperty op) {
|
||||||
if (customListViewConfigFiles == null) {
|
if (customListViewConfigFileMap == null) {
|
||||||
customListViewConfigFiles = new HashMap<ObjectProperty, String>();
|
customListViewConfigFileMap = new HashMap<ObjectProperty, String>();
|
||||||
OntModel ontModel = getOntModelSelector().getDisplayModel();
|
OntModel displayModel = getOntModelSelector().getDisplayModel();
|
||||||
Property listViewConfigProp = ontModel.getProperty(VitroVocabulary.DISPLAY + "customListViewConfigurationFile");
|
|
||||||
ResIterator resources = ontModel.listResourcesWithProperty(listViewConfigProp);
|
// Property listViewConfigProp = displayModel.getProperty(VitroVocabulary.DISPLAY + "customListViewConfigurationFile");
|
||||||
while (resources.hasNext()) {
|
// ResIterator resources = displayModel.listResourcesWithProperty(listViewConfigProp);
|
||||||
Resource resource = resources.next();
|
// while (resources.hasNext()) {
|
||||||
ObjectProperty prop = getObjectPropertyByURI(resource.getURI());
|
// Resource resource = resources.next();
|
||||||
NodeIterator nodes = ontModel.listObjectsOfProperty(resource, listViewConfigProp);
|
// ObjectProperty prop = getObjectPropertyByURI(resource.getURI());
|
||||||
if (nodes.hasNext()) {
|
// NodeIterator nodes = displayModel.listObjectsOfProperty(resource, listViewConfigProp);
|
||||||
RDFNode node = nodes.next(); // there should be at most one value; just get the first one
|
// if (nodes.hasNext()) {
|
||||||
if (node.isLiteral()) {
|
// RDFNode node = nodes.next(); // there should be at most one value; just get the first one
|
||||||
String configFileName = ((Literal)node).getLexicalForm();
|
// if (node.isLiteral()) {
|
||||||
customListViewConfigFiles.put(prop, configFileName);
|
// 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 customListViewConfigFileMap.get(op);
|
||||||
}
|
|
||||||
return customListViewConfigFiles.get(op);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue