NIHVIVO-2753 improved getUpdatedSinceIterator() and NIHVIVO-2448 visibility of workflows in arbitrary SDB graphs
This commit is contained in:
parent
4e9fa02a3f
commit
9b3a97c736
2 changed files with 72 additions and 70 deletions
|
@ -66,14 +66,18 @@ public class IndividualDaoSDB extends IndividualDaoJena {
|
||||||
|
|
||||||
protected Individual makeIndividual(String individualURI) {
|
protected Individual makeIndividual(String individualURI) {
|
||||||
try {
|
try {
|
||||||
return new IndividualSDB(individualURI, this.dwf, datasetMode, getWebappDaoFactory());
|
return new IndividualSDB(individualURI,
|
||||||
|
this.dwf,
|
||||||
|
datasetMode,
|
||||||
|
getWebappDaoFactory());
|
||||||
} catch (IndividualNotFoundException e) {
|
} catch (IndividualNotFoundException e) {
|
||||||
// If the individual does not exist, return null.
|
// If the individual does not exist, return null.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(IndividualDaoSDB.class.getName());
|
private static final Log log = LogFactory.getLog(
|
||||||
|
IndividualDaoSDB.class.getName());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected OntModel getOntModel() {
|
protected OntModel getOntModel() {
|
||||||
|
@ -83,7 +87,9 @@ public class IndividualDaoSDB extends IndividualDaoJena {
|
||||||
private static final boolean SKIP_INITIALIZATION = true;
|
private static final boolean SKIP_INITIALIZATION = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List getIndividualsByVClassURI(String vclassURI, int offset, int quantity ) {
|
public List getIndividualsByVClassURI(String vclassURI,
|
||||||
|
int offset,
|
||||||
|
int quantity ) {
|
||||||
|
|
||||||
if (vclassURI==null) {
|
if (vclassURI==null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -253,7 +259,9 @@ public class IndividualDaoSDB extends IndividualDaoJena {
|
||||||
return filteredIndividualList;
|
return filteredIndividualList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Individual makeIndividual(String uri, String label, String moniker) {
|
private Individual makeIndividual(String uri,
|
||||||
|
String label,
|
||||||
|
String moniker) {
|
||||||
Individual ent = new IndividualSDB(uri,
|
Individual ent = new IndividualSDB(uri,
|
||||||
this.dwf, datasetMode, getWebappDaoFactory(),
|
this.dwf, datasetMode, getWebappDaoFactory(),
|
||||||
SKIP_INITIALIZATION);
|
SKIP_INITIALIZATION);
|
||||||
|
@ -272,7 +280,8 @@ public class IndividualDaoSDB extends IndividualDaoJena {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fills in the Individual objects needed for any ObjectPropertyStatements attached to the specified individual.
|
* fills in the Individual objects needed for any ObjectPropertyStatements
|
||||||
|
* attached to the specified individual.
|
||||||
* @param entity
|
* @param entity
|
||||||
*/
|
*/
|
||||||
private void fillIndividualsForObjectPropertyStatements(Individual entity){
|
private void fillIndividualsForObjectPropertyStatements(Individual entity){
|
||||||
|
@ -280,7 +289,8 @@ public class IndividualDaoSDB extends IndividualDaoJena {
|
||||||
try {
|
try {
|
||||||
Iterator e2eIt = entity.getObjectPropertyStatements().iterator();
|
Iterator e2eIt = entity.getObjectPropertyStatements().iterator();
|
||||||
while (e2eIt.hasNext()) {
|
while (e2eIt.hasNext()) {
|
||||||
ObjectPropertyStatement e2e = (ObjectPropertyStatement) e2eIt.next();
|
ObjectPropertyStatement e2e =
|
||||||
|
(ObjectPropertyStatement) e2eIt.next();
|
||||||
e2e.setSubject(makeIndividual(e2e.getSubjectURI()));
|
e2e.setSubject(makeIndividual(e2e.getSubjectURI()));
|
||||||
e2e.setObject(makeIndividual(e2e.getObjectURI()));
|
e2e.setObject(makeIndividual(e2e.getObjectURI()));
|
||||||
}
|
}
|
||||||
|
@ -298,7 +308,8 @@ public class IndividualDaoSDB extends IndividualDaoJena {
|
||||||
* ontology as a data property -- only that it behaves as one.
|
* ontology as a data property -- only that it behaves as one.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Individual> getIndividualsByDataProperty(String dataPropertyUri, String value){
|
public List<Individual> getIndividualsByDataProperty(String dataPropertyUri,
|
||||||
|
String value){
|
||||||
Property prop = null;
|
Property prop = null;
|
||||||
if( RDFS.label.getURI().equals( dataPropertyUri )){
|
if( RDFS.label.getURI().equals( dataPropertyUri )){
|
||||||
prop = RDFS.label;
|
prop = RDFS.label;
|
||||||
|
@ -324,7 +335,8 @@ public class IndividualDaoSDB extends IndividualDaoJena {
|
||||||
//warning: this assumes that any language tags will be EN
|
//warning: this assumes that any language tags will be EN
|
||||||
Literal litv3 = getOntModel().createLiteral(value,"EN");
|
Literal litv3 = getOntModel().createLiteral(value,"EN");
|
||||||
|
|
||||||
HashMap<String,Individual> individualsMap = new HashMap<String, Individual>();
|
HashMap<String,Individual> individualsMap =
|
||||||
|
new HashMap<String, Individual>();
|
||||||
|
|
||||||
getOntModel().enterCriticalSection(Lock.READ);
|
getOntModel().enterCriticalSection(Lock.READ);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
@ -411,14 +423,16 @@ public class IndividualDaoSDB extends IndividualDaoJena {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator getAllOfThisTypeIterator() {
|
public Iterator<Individual> getAllOfThisTypeIterator() {
|
||||||
final List<String> list =
|
final List<String> list =
|
||||||
new LinkedList<String>();
|
new LinkedList<String>();
|
||||||
|
|
||||||
// get all labeled resources from any non-tbox and non-metadata graphs.
|
// get all labeled resources from any non-tbox and non-metadata graphs.
|
||||||
String query = "SELECT DISTINCT ?ind WHERE { \n" +
|
String query = "SELECT DISTINCT ?ind WHERE { \n" +
|
||||||
" GRAPH ?g { ?ind <" + RDFS.label.getURI() + "> ?label } \n" +
|
" GRAPH ?g { ?ind <" + RDFS.label.getURI() +
|
||||||
" FILTER (?g != <" + JenaDataSourceSetupBase.JENA_APPLICATION_METADATA_MODEL + "> " +
|
"> ?label } \n" +
|
||||||
|
" FILTER (?g != <" + JenaDataSourceSetupBase
|
||||||
|
.JENA_APPLICATION_METADATA_MODEL + "> " +
|
||||||
" && !regex(str(?g),\"tbox\")) \n " +
|
" && !regex(str(?g),\"tbox\")) \n " +
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
|
@ -441,14 +455,21 @@ public class IndividualDaoSDB extends IndividualDaoJena {
|
||||||
w.close();
|
w.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list.size() >0){
|
return getIndividualIterator(list);
|
||||||
log.info("Number of individuals from source: " + list.size());
|
|
||||||
return new Iterator(){
|
}
|
||||||
Iterator<String> innerIt = list.iterator();
|
|
||||||
|
private Iterator<Individual> getIndividualIterator(
|
||||||
|
final List<String> individualURIs) {
|
||||||
|
if (individualURIs.size() >0){
|
||||||
|
log.info("Number of individuals from source: "
|
||||||
|
+ individualURIs.size());
|
||||||
|
return new Iterator<Individual>(){
|
||||||
|
Iterator<String> innerIt = individualURIs.iterator();
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return innerIt.hasNext();
|
return innerIt.hasNext();
|
||||||
}
|
}
|
||||||
public Object next() {
|
public Individual next() {
|
||||||
String indURI = innerIt.next();
|
String indURI = innerIt.next();
|
||||||
Individual ind = makeIndividual(indURI);
|
Individual ind = makeIndividual(indURI);
|
||||||
if (ind != null) {
|
if (ind != null) {
|
||||||
|
@ -467,78 +488,59 @@ public class IndividualDaoSDB extends IndividualDaoJena {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator getAllOfThisVClassIterator(String vClassURI) {
|
public Iterator<Individual> getAllOfThisVClassIterator(String vClassURI) {
|
||||||
getOntModel().enterCriticalSection(Lock.READ);
|
getOntModel().enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
List ents = new LinkedList();
|
List<String> individualURIs = new ArrayList<String>();
|
||||||
OntClass cls = getOntModel().getOntClass(vClassURI);
|
OntClass cls = getOntModel().getOntClass(vClassURI);
|
||||||
Iterator indIt = cls.listInstances();
|
Iterator indIt = cls.listInstances();
|
||||||
while (indIt.hasNext()) {
|
while (indIt.hasNext()) {
|
||||||
com.hp.hpl.jena.ontology.Individual ind = (com.hp.hpl.jena.ontology.Individual) indIt.next();
|
com.hp.hpl.jena.ontology.Individual ind =
|
||||||
Individual ent = makeIndividual(ind.getURI());
|
(com.hp.hpl.jena.ontology.Individual) indIt.next();
|
||||||
if (ent != null) {
|
if (ind.getURI() != null) {
|
||||||
ents.add(ent);
|
individualURIs.add(ind.getURI());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ents.iterator();
|
return getIndividualIterator(individualURIs);
|
||||||
} finally {
|
} finally {
|
||||||
getOntModel().leaveCriticalSection();
|
getOntModel().leaveCriticalSection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator getUpdatedSinceIterator(long updatedSince){
|
public Iterator<Individual> getUpdatedSinceIterator(long updatedSince){
|
||||||
List ents = new ArrayList();
|
List<String> individualURIs = new ArrayList<String>();
|
||||||
Date since = new DateTime(updatedSince).toDate();
|
Date since = new DateTime(updatedSince).toDate();
|
||||||
String sinceStr = xsdDateTimeFormat.format(since);
|
String sinceStr = xsdDateTimeFormat.format(since);
|
||||||
getOntModel().enterCriticalSection(Lock.READ);
|
getOntModel().enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
Property modTimeProp = MODTIME;
|
|
||||||
if (modTimeProp == null)
|
|
||||||
modTimeProp = getOntModel().getProperty(VitroVocabulary.MODTIME);
|
|
||||||
if (modTimeProp == null)
|
|
||||||
return null; // throw an exception?
|
|
||||||
String queryStr = "PREFIX vitro: <"+ VitroVocabulary.vitroURI+"> " +
|
String queryStr = "PREFIX vitro: <"+ VitroVocabulary.vitroURI+"> " +
|
||||||
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>"+
|
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>"+
|
||||||
"SELECT ?ent " +
|
"SELECT ?ent " +
|
||||||
"WHERE { " +
|
"WHERE { " +
|
||||||
" ?ent vitro:modTime ?modTime ." +
|
" ?ent vitro:modTime ?modTime ." +
|
||||||
" FILTER (xsd:dateTime(?modTime) >= \""+sinceStr+"\"^^xsd:dateTime) " +
|
" FILTER (xsd:dateTime(?modTime) >= \""
|
||||||
|
+ sinceStr + "\"^^xsd:dateTime) " +
|
||||||
"}";
|
"}";
|
||||||
Query query = QueryFactory.create(queryStr);
|
Query query = QueryFactory.create(queryStr);
|
||||||
QueryExecution qe = QueryExecutionFactory.create(query,getOntModel());
|
QueryExecution qe = QueryExecutionFactory.create(
|
||||||
|
query,getOntModel());
|
||||||
|
try {
|
||||||
ResultSet results = qe.execSelect();
|
ResultSet results = qe.execSelect();
|
||||||
while (results.hasNext()) {
|
while (results.hasNext()) {
|
||||||
QuerySolution qs = (QuerySolution) results.next();
|
QuerySolution qs = (QuerySolution) results.next();
|
||||||
Resource res = (Resource) qs.get("?ent");
|
Resource res = (Resource) qs.get("?ent");
|
||||||
com.hp.hpl.jena.ontology.Individual ent = getOntModel().getIndividual(res.getURI());
|
if (res.getURI() != null) {
|
||||||
if (ent != null) {
|
individualURIs.add(res.getURI());
|
||||||
boolean userVisible = false;
|
|
||||||
ClosableIterator typeIt = ent.listRDFTypes(true);
|
|
||||||
try {
|
|
||||||
while (typeIt.hasNext()) {
|
|
||||||
Resource typeRes = (Resource) typeIt.next();
|
|
||||||
if (typeRes.getNameSpace() == null || (!NONUSER_NAMESPACES.contains(typeRes.getNameSpace()))) {
|
|
||||||
userVisible = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
typeIt.close();
|
qe.close();
|
||||||
}
|
|
||||||
if (userVisible) {
|
|
||||||
Individual ind = makeIndividual(ent.getURI());
|
|
||||||
if (ind != null) {
|
|
||||||
ents.add(ind);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
getOntModel().leaveCriticalSection();
|
getOntModel().leaveCriticalSection();
|
||||||
}
|
}
|
||||||
return ents.iterator();
|
return getIndividualIterator(individualURIs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import com.hp.hpl.jena.query.QueryExecution;
|
||||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
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.Syntax;
|
import com.hp.hpl.jena.query.Syntax;
|
||||||
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;
|
||||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||||
|
@ -41,7 +40,6 @@ import com.hp.hpl.jena.shared.Lock;
|
||||||
import com.hp.hpl.jena.util.iterator.ClosableIterator;
|
import com.hp.hpl.jena.util.iterator.ClosableIterator;
|
||||||
import com.hp.hpl.jena.vocabulary.RDF;
|
import com.hp.hpl.jena.vocabulary.RDF;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
@ -55,9 +53,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaModelMaker;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaSDBModelMaker;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaSDBModelMaker;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB;
|
||||||
import edu.cornell.mannlib.vitro.webapp.ontology.update.KnowledgeBaseUpdater;
|
import edu.cornell.mannlib.vitro.webapp.ontology.update.KnowledgeBaseUpdater;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.InitialJenaModelUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.InitialJenaModelUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.NamespaceMapperJena;
|
|
||||||
|
|
||||||
public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements javax.servlet.ServletContextListener {
|
public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements javax.servlet.ServletContextListener {
|
||||||
|
|
||||||
|
@ -285,8 +281,12 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java
|
||||||
WebappDaoFactorySDB.SDBDatasetMode.INFERENCES_ONLY);
|
WebappDaoFactorySDB.SDBDatasetMode.INFERENCES_ONLY);
|
||||||
ctx.setAttribute("deductionsWebappDaoFactory", infWadf);
|
ctx.setAttribute("deductionsWebappDaoFactory", infWadf);
|
||||||
|
|
||||||
OntModel masterUnion = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
|
OntModel masterUnion = ModelFactory.createOntologyModel(
|
||||||
ModelFactory.createUnion(unionABoxModel, unionTBoxModel));
|
DB_ONT_MODEL_SPEC, makeDBModel(
|
||||||
|
bds, WebappDaoFactorySDB.UNION_GRAPH,
|
||||||
|
DB_ONT_MODEL_SPEC, TripleStoreType.SDB, ctx));
|
||||||
|
//OntModel masterUnion = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
|
||||||
|
// ModelFactory.createUnion(unionABoxModel, unionTBoxModel));
|
||||||
unionOms.setFullModel(masterUnion);
|
unionOms.setFullModel(masterUnion);
|
||||||
ctx.setAttribute("jenaOntModel", masterUnion);
|
ctx.setAttribute("jenaOntModel", masterUnion);
|
||||||
WebappDaoFactory wadf = new WebappDaoFactorySDB(unionOms, bds, storeDesc, defaultNamespace, null, null);
|
WebappDaoFactory wadf = new WebappDaoFactorySDB(unionOms, bds, storeDesc, defaultNamespace, null, null);
|
||||||
|
|
Loading…
Add table
Reference in a new issue