vitro list views with CONSTRUCTs and improvement to null individual handling
This commit is contained in:
parent
c9cf713fed
commit
eb55aa694f
4 changed files with 83 additions and 21 deletions
|
@ -30,6 +30,7 @@ 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.query.Syntax;
|
||||||
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;
|
||||||
|
@ -132,7 +133,6 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
Dataset dataset = w.getDataset();
|
Dataset dataset = w.getDataset();
|
||||||
try {
|
try {
|
||||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||||
String[] graphVars = {"?g", "?h", "?i"};
|
|
||||||
String getStatements =
|
String getStatements =
|
||||||
"CONSTRUCT " +
|
"CONSTRUCT " +
|
||||||
"{ <"+individualURI+"> <" + RDFS.label.getURI() +
|
"{ <"+individualURI+"> <" + RDFS.label.getURI() +
|
||||||
|
@ -140,18 +140,16 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
// "<"+individualURI+"> a ?type . \n" +
|
// "<"+individualURI+"> a ?type . \n" +
|
||||||
"<"+individualURI+"> <" + VitroVocabulary.MONIKER +
|
"<"+individualURI+"> <" + VitroVocabulary.MONIKER +
|
||||||
"> ?moniker \n" +
|
"> ?moniker \n" +
|
||||||
"} WHERE { GRAPH <urn:x-arq:UnionGraph> {" +
|
"} WHERE {" +
|
||||||
"{ \n" +
|
|
||||||
"{ <"+individualURI+"> <" + RDFS.label.getURI() +
|
"{ <"+individualURI+"> <" + RDFS.label.getURI() +
|
||||||
"> ?ooo } \n" +
|
"> ?ooo } \n" +
|
||||||
"UNION { <" +
|
"UNION { <" +
|
||||||
individualURI+"> <" + VitroVocabulary.MONIKER +
|
individualURI+"> <" + VitroVocabulary.MONIKER +
|
||||||
"> ?moniker } \n" +
|
"> ?moniker \n" +
|
||||||
"} \n" +
|
"} \n" +
|
||||||
// "UNION { <"
|
// "UNION { <"
|
||||||
// + individualURI + "> a ?type } \n" +
|
// + individualURI + "> a ?type } \n" +
|
||||||
// WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
|
"}";
|
||||||
"} }";
|
|
||||||
model = QueryExecutionFactory.create(
|
model = QueryExecutionFactory.create(
|
||||||
QueryFactory.create(getStatements), dataset)
|
QueryFactory.create(getStatements), dataset)
|
||||||
.execConstruct();
|
.execConstruct();
|
||||||
|
@ -163,7 +161,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
OntModel ontModel = ModelFactory.createOntologyModel(
|
OntModel ontModel = ModelFactory.createOntologyModel(
|
||||||
OntModelSpec.OWL_MEM, model);
|
OntModelSpec.OWL_MEM, model);
|
||||||
|
|
||||||
if (model.isEmpty()) {
|
if (model.isEmpty() && noTriplesFor(individualURI)) {
|
||||||
throw new IndividualNotFoundException();
|
throw new IndividualNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,6 +171,25 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
||||||
this.webappDaoFactory = wadf;
|
this.webappDaoFactory = wadf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean noTriplesFor(String individualURI) {
|
||||||
|
String ask = "ASK { <" + individualURI + "> ?p ?o }";
|
||||||
|
DatasetWrapper w = getDatasetWrapper();
|
||||||
|
Dataset dataset = w.getDataset();
|
||||||
|
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||||
|
try {
|
||||||
|
Query askQuery = QueryFactory.create(ask, Syntax.syntaxARQ);
|
||||||
|
QueryExecution qe = QueryExecutionFactory.create(askQuery, dataset);
|
||||||
|
try {
|
||||||
|
return !qe.execAsk();
|
||||||
|
} finally {
|
||||||
|
qe.close();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
dataset.getLock().leaveCriticalSection();
|
||||||
|
w.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final boolean SKIP_INITIALIZATION = true;
|
private static final boolean SKIP_INITIALIZATION = true;
|
||||||
|
|
||||||
public IndividualSDB(String individualURI,
|
public IndividualSDB(String individualURI,
|
||||||
|
|
|
@ -56,7 +56,11 @@ public abstract class BaseObjectPropertyDataPostProcessor implements
|
||||||
protected void addName(Map<String, String> map, String nameKey, String objectKey) {
|
protected void addName(Map<String, String> map, String nameKey, String objectKey) {
|
||||||
String name = map.get(nameKey);
|
String name = map.get(nameKey);
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
map.put(nameKey, getIndividual(map.get(objectKey)).getName());
|
// getIndividual() could return null
|
||||||
|
Individual ind = getIndividual(map.get(objectKey));
|
||||||
|
if (ind != null) {
|
||||||
|
map.put(nameKey, ind.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,9 @@
|
||||||
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
||||||
|
|
||||||
SELECT ?object ?name ?moniker WHERE {
|
SELECT ?object ?name ?moniker WHERE {
|
||||||
GRAPH ?g1 { ?subject ?property ?object }
|
?subject ?property ?object
|
||||||
OPTIONAL { GRAPH ?g2 { ?object rdfs:label ?name } }
|
OPTIONAL { ?object rdfs:label ?name }
|
||||||
OPTIONAL { GRAPH ?g3 { ?object vitro:moniker ?moniker } }
|
OPTIONAL { ?object vitro:moniker ?moniker }
|
||||||
}
|
}
|
||||||
</query-base>
|
</query-base>
|
||||||
|
|
||||||
|
@ -22,15 +22,43 @@
|
||||||
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
||||||
PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>
|
PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>
|
||||||
|
|
||||||
SELECT ?subclass ?object ?name ?moniker WHERE {
|
SELECT ?subclass ?object ?name ?moniker {
|
||||||
GRAPH ?g1 { ?subject ?property ?object }
|
?subject ?property ?object
|
||||||
OPTIONAL { GRAPH ?g2 { ?object rdfs:label ?name } }
|
OPTIONAL { ?object a ?subclass }
|
||||||
OPTIONAL { GRAPH ?g3 { ?object vitro:moniker ?moniker } }
|
OPTIONAL { ?object rdfs:label ?name }
|
||||||
OPTIONAL { GRAPH ?g4 { ?object a ?subclass } }
|
OPTIONAL { ?object vitro:moniker ?moniker }
|
||||||
FILTER ( afn:namespace(?subclass) != "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#" )
|
FILTER ( afn:namespace(?subclass) != "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#" )
|
||||||
} ORDER BY ?subclass
|
} ORDER BY ?subclass
|
||||||
</query-collated>
|
</query-collated>
|
||||||
|
|
||||||
|
<query-construct>
|
||||||
|
PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#>
|
||||||
|
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
||||||
|
|
||||||
|
CONSTRUCT {
|
||||||
|
?subject ?property ?object .
|
||||||
|
?object a ?subclass .
|
||||||
|
?object rdfs:label ?name .
|
||||||
|
?object vitro:moniker ?moniker
|
||||||
|
} WHERE {
|
||||||
|
{
|
||||||
|
?subject ?property ?object
|
||||||
|
}
|
||||||
|
UNION {
|
||||||
|
?subject ?property ?object .
|
||||||
|
?object a ?subclass .
|
||||||
|
}
|
||||||
|
UNION {
|
||||||
|
?subject ?property ?object .
|
||||||
|
?object rdfs:label ?name .
|
||||||
|
}
|
||||||
|
UNION {
|
||||||
|
?subject ?property ?object .
|
||||||
|
?object vitro:moniker ?moniker .
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</query-construct>
|
||||||
|
|
||||||
<postprocessor>edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.DefaultListViewDataPostProcessor</postprocessor>
|
<postprocessor>edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.DefaultListViewDataPostProcessor</postprocessor>
|
||||||
|
|
||||||
<template>propStatement-default.ftl</template>
|
<template>propStatement-default.ftl</template>
|
||||||
|
|
|
@ -14,12 +14,25 @@
|
||||||
(afn:localname(?link) AS ?linkName)
|
(afn:localname(?link) AS ?linkName)
|
||||||
?anchor
|
?anchor
|
||||||
?url WHERE {
|
?url WHERE {
|
||||||
GRAPH ?g1 { ?subject ?property ?link }
|
?subject ?property ?link
|
||||||
OPTIONAL { GRAPH ?g2 { ?link vitro:linkAnchor ?anchor } }
|
OPTIONAL { ?link vitro:linkAnchor ?anchor }
|
||||||
OPTIONAL { GRAPH ?g3 { ?link vitro:linkURL ?url } }
|
OPTIONAL { ?link vitro:linkURL ?url }
|
||||||
OPTIONAL { GRAPH ?g4 { ?link vitro:linkDisplayRank ?rank } }
|
OPTIONAL { ?link vitro:linkDisplayRank ?rank }
|
||||||
} ORDER BY ?rank
|
} ORDER BY ?rank
|
||||||
</query-base>
|
</query-base>
|
||||||
|
|
||||||
|
<query-construct>
|
||||||
|
CONSTRUCT {
|
||||||
|
?subject ?property ?link .
|
||||||
|
?link ?linkProp ?linkObj
|
||||||
|
} WHERE {
|
||||||
|
{ ?subject ?property ?link }
|
||||||
|
UNION {
|
||||||
|
?subject ?property ?link .
|
||||||
|
?link ?linkProp ?linkObj
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</query-construct>
|
||||||
|
|
||||||
<template>propStatement-vitroLink.ftl</template>
|
<template>propStatement-vitroLink.ftl</template>
|
||||||
</list-view-config>
|
</list-view-config>
|
||||||
|
|
Loading…
Add table
Reference in a new issue