VIVO-823 Adjust these classes to use the new ModelMakers, as much as possible.
There are commented Kluges in RequestModelsPrep and ModelAccess, where things still are not as clean as they should be.
This commit is contained in:
parent
b4395fcb31
commit
e1bc897154
10 changed files with 219 additions and 428 deletions
|
@ -67,6 +67,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelMakerID;
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelMakerID;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.BlankNodeFilteringModelMaker;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
||||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
|
||||||
|
@ -74,6 +75,7 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils.WhichService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.SparqlQueryUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.SparqlQueryUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils.MergeResult;
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils.MergeResult;
|
||||||
|
@ -1204,9 +1206,15 @@ public class JenaIngestController extends BaseEditController {
|
||||||
protected static ModelMaker getModelMaker(HttpServletRequest req){
|
protected static ModelMaker getModelMaker(HttpServletRequest req){
|
||||||
ServletContext ctx = req.getSession().getServletContext();
|
ServletContext ctx = req.getSession().getServletContext();
|
||||||
if (isUsingMainStoreForIngest(req)) {
|
if (isUsingMainStoreForIngest(req)) {
|
||||||
return ModelAccess.on(ctx).getModelMaker(CONTENT);
|
RDFService rdfService = RDFServiceUtils.getRDFServiceFactory(ctx,
|
||||||
|
WhichService.CONTENT).getRDFService();
|
||||||
|
return new BlankNodeFilteringModelMaker(rdfService, ModelAccess.on(
|
||||||
|
ctx).getModelMaker(CONTENT));
|
||||||
} else {
|
} else {
|
||||||
return ModelAccess.on(ctx).getModelMaker(CONFIGURATION);
|
RDFService rdfService = RDFServiceUtils.getRDFServiceFactory(ctx,
|
||||||
|
WhichService.CONFIGURATION).getRDFService();
|
||||||
|
return new BlankNodeFilteringModelMaker(rdfService, ModelAccess.on(
|
||||||
|
ctx).getModelMaker(CONFIGURATION));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@ import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.adapters.VitroModelFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hierarchical storage for models. TODO
|
* Hierarchical storage for models. TODO
|
||||||
|
@ -140,34 +142,18 @@ public class ModelAccess {
|
||||||
return getOntModel(ModelID.APPLICATION_METADATA);
|
return getOntModel(ModelID.APPLICATION_METADATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserAccountsModel(OntModel m) {
|
|
||||||
setOntModel(ModelID.USER_ACCOUNTS, m);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OntModel getUserAccountsModel() {
|
public OntModel getUserAccountsModel() {
|
||||||
return getOntModel(ModelID.USER_ACCOUNTS);
|
return getOntModel(ModelID.USER_ACCOUNTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDisplayModel(OntModel m) {
|
|
||||||
setOntModel(ModelID.DISPLAY, m);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OntModel getDisplayModel() {
|
public OntModel getDisplayModel() {
|
||||||
return getOntModel(ModelID.DISPLAY);
|
return getOntModel(ModelID.DISPLAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setJenaOntModel(OntModel m) {
|
|
||||||
setOntModel(ModelID.UNION_FULL, m);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OntModel getJenaOntModel() {
|
public OntModel getJenaOntModel() {
|
||||||
return getOntModel(ModelID.UNION_FULL);
|
return getOntModel(ModelID.UNION_FULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBaseOntModel(OntModel m) {
|
|
||||||
setOntModel(ModelID.BASE_FULL, m);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OntModel getBaseOntModel() {
|
public OntModel getBaseOntModel() {
|
||||||
return getOntModel(ModelID.BASE_FULL);
|
return getOntModel(ModelID.BASE_FULL);
|
||||||
}
|
}
|
||||||
|
@ -184,10 +170,6 @@ public class ModelAccess {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeOntModel(ModelID id) {
|
|
||||||
setOntModel(id, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OntModel getOntModel(ModelID id) {
|
public OntModel getOntModel(ModelID id) {
|
||||||
if (modelMap.containsKey(id)) {
|
if (modelMap.containsKey(id)) {
|
||||||
log.debug("Using " + id + " model from " + scope);
|
log.debug("Using " + id + " model from " + scope);
|
||||||
|
@ -284,20 +266,60 @@ public class ModelAccess {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModelMaker(ModelMakerID id, ModelMaker modelMaker) {
|
public void setModelMaker(ModelMakerID id, ModelMaker modelMaker) {
|
||||||
if (modelMaker == null) {
|
modelMakerMap.put(id, modelMaker);
|
||||||
modelMakerMap.remove(id);
|
if (id == ModelMakerID.CONFIGURATION) {
|
||||||
|
setOntModel(ModelID.USER_ACCOUNTS, modelMaker,
|
||||||
|
ModelNames.USER_ACCOUNTS);
|
||||||
|
setOntModel(ModelID.DISPLAY, modelMaker, ModelNames.DISPLAY);
|
||||||
|
setOntModel(ModelID.DISPLAY_DISPLAY, modelMaker,
|
||||||
|
ModelNames.DISPLAY_DISPLAY);
|
||||||
|
setOntModel(ModelID.DISPLAY_TBOX, modelMaker,
|
||||||
|
ModelNames.DISPLAY_TBOX);
|
||||||
} else {
|
} else {
|
||||||
modelMakerMap.put(id, modelMaker);
|
setOntModel(ModelID.APPLICATION_METADATA, modelMaker,
|
||||||
|
ModelNames.APPLICATION_METADATA);
|
||||||
|
setOntModel(ModelID.BASE_TBOX, modelMaker,
|
||||||
|
ModelNames.TBOX_ASSERTIONS);
|
||||||
|
setOntModel(ModelID.INFERRED_TBOX, modelMaker,
|
||||||
|
ModelNames.TBOX_INFERENCES);
|
||||||
|
setOntModel(ModelID.UNION_TBOX, modelMaker, ModelNames.TBOX_UNION);
|
||||||
|
setOntModel(ModelID.BASE_ABOX, modelMaker,
|
||||||
|
ModelNames.ABOX_ASSERTIONS);
|
||||||
|
setOntModel(ModelID.INFERRED_ABOX, modelMaker,
|
||||||
|
ModelNames.ABOX_INFERENCES);
|
||||||
|
setOntModel(ModelID.UNION_ABOX, modelMaker, ModelNames.ABOX_UNION);
|
||||||
|
setOntModel(ModelID.BASE_FULL, modelMaker,
|
||||||
|
ModelNames.FULL_ASSERTIONS);
|
||||||
|
setOntModel(ModelID.INFERRED_FULL, modelMaker,
|
||||||
|
ModelNames.FULL_INFERENCES);
|
||||||
|
setOntModel(ModelID.UNION_FULL, modelMaker, ModelNames.FULL_UNION);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* KLUGE
|
||||||
|
*
|
||||||
|
* For some reason, the union of two OntModels (like this) works
|
||||||
|
* fine as the UNION_TBOX, but an OntModel wrapped around the union
|
||||||
|
* of two Models (from ModelMakers) does not work.
|
||||||
|
*
|
||||||
|
* See also the Kluge in RequestModelsPrep.
|
||||||
|
*/
|
||||||
|
setOntModel(ModelID.UNION_TBOX, VitroModelFactory.createUnion(
|
||||||
|
getOntModel(ModelID.BASE_TBOX),
|
||||||
|
getOntModel(ModelID.INFERRED_TBOX)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setOntModel(ModelID id, ModelMaker mm, String uri) {
|
||||||
|
setOntModel(id, VitroModelFactory.createOntologyModel(mm.getModel(uri)));
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Close all locally stored models, WADFs, etc.
|
// Close all locally stored models, WADFs, etc.
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
if (this.scope == Scope.REQUEST) {
|
if (this.scope == Scope.REQUEST) {
|
||||||
for (WebappDaoFactory wadf: factoryMap.values()) {
|
for (WebappDaoFactory wadf : factoryMap.values()) {
|
||||||
wadf.close();
|
wadf.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,171 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
import com.hp.hpl.jena.graph.GraphMaker;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
|
||||||
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
|
||||||
import com.hp.hpl.jena.rdf.model.ModelReader;
|
|
||||||
import com.hp.hpl.jena.shared.AlreadyExistsException;
|
|
||||||
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
|
||||||
import com.hp.hpl.jena.util.iterator.NiceIterator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A decorator on top of a model maker. It looks for requests on particular
|
|
||||||
* URIs, and shunts them to the pre-made models on ModelAccess.
|
|
||||||
*
|
|
||||||
* The result is two-fold:
|
|
||||||
*
|
|
||||||
* We have effective URIs for models that only exist as combinations of other
|
|
||||||
* named models (UNION_FULL, BASE_FULL, INFERRED_FULL).
|
|
||||||
*
|
|
||||||
* For models with in-memory mapping, a request will return a reference to that
|
|
||||||
* mapping.
|
|
||||||
*/
|
|
||||||
public class VitroInterceptingModelMaker implements ModelMaker {
|
|
||||||
private final ModelMaker innerMM;
|
|
||||||
private final Map<String, Model> specialMap;
|
|
||||||
|
|
||||||
public VitroInterceptingModelMaker(ModelMaker innerMM, Map<String, Model> specialMap) {
|
|
||||||
this.innerMM = innerMM;
|
|
||||||
this.specialMap = Collections.unmodifiableMap(new HashMap<>(specialMap));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model getModel(String url) {
|
|
||||||
return isSpecial(url) ? getSpecial(url) : innerMM.getModel(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model getModel(String url, ModelReader loadIfAbsent) {
|
|
||||||
return isSpecial(url) ? getSpecial(url) : innerMM.getModel(url,
|
|
||||||
loadIfAbsent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model createDefaultModel() {
|
|
||||||
return innerMM.createDefaultModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model createFreshModel() {
|
|
||||||
return innerMM.createFreshModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model openModel(String name) {
|
|
||||||
return isSpecial(name) ? getSpecial(name) : innerMM.openModel(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model openModelIfPresent(String name) {
|
|
||||||
return isSpecial(name) ? getSpecial(name) : innerMM
|
|
||||||
.openModelIfPresent(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
innerMM.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model createModel(String name) {
|
|
||||||
return isSpecial(name) ? getSpecial(name) : innerMM.createModel(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model createModel(String name, boolean strict) {
|
|
||||||
if (isSpecial(name)) {
|
|
||||||
if (strict) {
|
|
||||||
throw new AlreadyExistsException(name);
|
|
||||||
} else {
|
|
||||||
return getSpecial(name);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return innerMM.createModel(name, strict);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO this should actually return an intercepting graph maker.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public GraphMaker getGraphMaker() {
|
|
||||||
return innerMM.getGraphMaker();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasModel(String name) {
|
|
||||||
return isSpecial(name) || innerMM.hasModel(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ExtendedIterator<String> listModels() {
|
|
||||||
return new SetsExtendedIterator(getSpecialNames(), innerMM.listModels()
|
|
||||||
.toSet());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Model openModel(String name, boolean strict) {
|
|
||||||
return isSpecial(name) ? getSpecial(name) : innerMM.openModel(name,
|
|
||||||
strict);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We don't lete anyone remove the special models.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void removeModel(String name) {
|
|
||||||
if (!isSpecial(name)) {
|
|
||||||
innerMM.removeModel(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
// Intercepting mechanism
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
private Collection<String> getSpecialNames() {
|
|
||||||
return specialMap.keySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isSpecial(String url) {
|
|
||||||
return specialMap.containsKey(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Model getSpecial(String url) {
|
|
||||||
return specialMap.get(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class SetsExtendedIterator extends NiceIterator<String> {
|
|
||||||
private final Iterator<String> iter;
|
|
||||||
|
|
||||||
@SafeVarargs
|
|
||||||
public SetsExtendedIterator(Collection<String>... collections) {
|
|
||||||
Set<String> set = new TreeSet<>();
|
|
||||||
for (Collection<String> c : collections) {
|
|
||||||
set.addAll(c);
|
|
||||||
}
|
|
||||||
this.iter = set.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNext() {
|
|
||||||
return iter.hasNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String next() {
|
|
||||||
return iter.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -121,7 +121,7 @@ public class ModelSwitcher {
|
||||||
|
|
||||||
private void setSpecialWriteModel(VitroRequest vreq, OntModel mainOntModel) {
|
private void setSpecialWriteModel(VitroRequest vreq, OntModel mainOntModel) {
|
||||||
if (mainOntModel != null) {
|
if (mainOntModel != null) {
|
||||||
ModelAccess.on(vreq).setJenaOntModel(mainOntModel);
|
ModelAccess.on(vreq).setOntModel(ModelID.UNION_FULL, mainOntModel);
|
||||||
vreq.setAttribute(SPECIAL_WRITE_MODEL, mainOntModel);
|
vreq.setAttribute(SPECIAL_WRITE_MODEL, mainOntModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.filters;
|
package edu.cornell.mannlib.vitro.webapp.filters;
|
||||||
|
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelMakerID.CONFIGURATION;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelMakerID.CONTENT;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
@ -27,7 +30,7 @@ import org.apache.jena.atlas.lib.Pair;
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
//import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList;
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList;
|
||||||
|
@ -47,12 +50,12 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelectorImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
|
||||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelMakerUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.adapters.VitroModelFactory;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringRDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringRDFService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringUtils;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils.WhichService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This sets up several objects in the Request scope for each incoming HTTP
|
* This sets up several objects in the Request scope for each incoming HTTP
|
||||||
|
@ -142,17 +145,18 @@ public class RequestModelsPrep implements Filter {
|
||||||
|
|
||||||
setRdfServicesAndDatasets(rawRdfService, vreq);
|
setRdfServicesAndDatasets(rawRdfService, vreq);
|
||||||
|
|
||||||
|
setRawModels(vreq);
|
||||||
|
|
||||||
RDFService rdfService = vreq.getRDFService();
|
RDFService rdfService = vreq.getRDFService();
|
||||||
Dataset dataset = vreq.getDataset();
|
|
||||||
|
|
||||||
setRawModels(vreq, dataset);
|
// We need access to some language-neutral items - either because we
|
||||||
|
// need to see all contents regardless of language, or because we need
|
||||||
// We need access to some language-neutral items - either because we need to see all
|
// to see the blank nodes that are removed during language filtering.
|
||||||
// contents regardless of language, or because we need to see the blank nodes that
|
vreq.setLanguageNeutralUnionFullModel(ModelAccess.on(vreq).getOntModel(
|
||||||
// are removed during language filtering.
|
ModelID.UNION_FULL));
|
||||||
vreq.setLanguageNeutralUnionFullModel(ModelAccess.on(vreq).getOntModel(ModelID.UNION_FULL));
|
|
||||||
vreq.setLanguageNeutralWebappDaoFactory(new WebappDaoFactorySDB(
|
vreq.setLanguageNeutralWebappDaoFactory(new WebappDaoFactorySDB(
|
||||||
rdfService, createLanguageNeutralOntModelSelector(vreq), createWadfConfig(vreq)));
|
rdfService, createLanguageNeutralOntModelSelector(vreq),
|
||||||
|
createWadfConfig(vreq)));
|
||||||
|
|
||||||
wrapModelsWithLanguageAwareness(vreq);
|
wrapModelsWithLanguageAwareness(vreq);
|
||||||
|
|
||||||
|
@ -177,41 +181,38 @@ public class RequestModelsPrep implements Filter {
|
||||||
vreq.setDataset(dataset);
|
vreq.setDataset(dataset);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setRawModels(VitroRequest vreq, Dataset dataset) {
|
private void setRawModels(VitroRequest vreq) {
|
||||||
// These are memory-mapped (fast), and read-mostly (low contention), so
|
ModelAccess models = ModelAccess.on(vreq);
|
||||||
// just use the ones from the context.
|
|
||||||
useModelFromContext(vreq, ModelID.APPLICATION_METADATA);
|
RDFService shortTermConfigRdfService = RDFServiceUtils
|
||||||
useModelFromContext(vreq, ModelID.USER_ACCOUNTS);
|
.getRDFServiceFactory(ctx, WhichService.CONFIGURATION)
|
||||||
useModelFromContext(vreq, ModelID.DISPLAY);
|
.getShortTermRDFService();
|
||||||
useModelFromContext(vreq, ModelID.DISPLAY_DISPLAY);
|
ModelMaker configMM = ModelMakerUtils.getShortTermModelMaker(ctx,
|
||||||
useModelFromContext(vreq, ModelID.DISPLAY_TBOX);
|
shortTermConfigRdfService, WhichService.CONFIGURATION);
|
||||||
|
models.setModelMaker(CONFIGURATION, configMM);
|
||||||
|
|
||||||
|
RDFService shortTermContentRdfService = RDFServiceUtils
|
||||||
|
.getRDFServiceFactory(ctx, WhichService.CONTENT)
|
||||||
|
.getShortTermRDFService();
|
||||||
|
ModelMaker contentMM = ModelMakerUtils.getShortTermModelMaker(ctx,
|
||||||
|
shortTermContentRdfService, WhichService.CONTENT);
|
||||||
|
models.setModelMaker(CONTENT, contentMM);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* KLUGE
|
||||||
|
*
|
||||||
|
* The BASE_TBOX in the context is wrapped by an OntModel with
|
||||||
|
* sub-models (file-graph models). If we wrap a new OntModel around it,
|
||||||
|
* we will lose those sub-models, so use the OntModel from the context.
|
||||||
|
*
|
||||||
|
* Do we need to do the same with INFERRED_TBOX and UNION_TBOX? Maybe
|
||||||
|
* not.
|
||||||
|
*
|
||||||
|
* See also the Kluge in ModelAccess.
|
||||||
|
*/
|
||||||
useModelFromContext(vreq, ModelID.BASE_TBOX);
|
useModelFromContext(vreq, ModelID.BASE_TBOX);
|
||||||
useModelFromContext(vreq, ModelID.INFERRED_TBOX);
|
useModelFromContext(vreq, ModelID.INFERRED_TBOX);
|
||||||
useModelFromContext(vreq, ModelID.UNION_TBOX);
|
useModelFromContext(vreq, ModelID.UNION_TBOX);
|
||||||
|
|
||||||
// Anything derived from the ABOX is not memory-mapped, so create
|
|
||||||
// versions from the short-term RDF service.
|
|
||||||
OntModel baseABoxModel = VitroModelFactory.createOntologyModel(dataset
|
|
||||||
.getNamedModel(ModelNames.ABOX_ASSERTIONS));
|
|
||||||
OntModel inferenceABoxModel = VitroModelFactory
|
|
||||||
.createOntologyModel(dataset.getNamedModel(ModelNames.ABOX_INFERENCES));
|
|
||||||
OntModel unionABoxModel = VitroModelFactory.createUnion(
|
|
||||||
baseABoxModel, inferenceABoxModel);
|
|
||||||
|
|
||||||
OntModel baseFullModel = VitroModelFactory.createUnion(baseABoxModel,
|
|
||||||
ModelAccess.on(vreq).getOntModel(ModelID.BASE_TBOX));
|
|
||||||
OntModel inferenceFullModel = VitroModelFactory.createUnion(
|
|
||||||
inferenceABoxModel,
|
|
||||||
ModelAccess.on(vreq).getOntModel(ModelID.INFERRED_TBOX));
|
|
||||||
OntModel unionFullModel = VitroModelFactory.createOntologyModel(
|
|
||||||
dataset.getDefaultModel());
|
|
||||||
|
|
||||||
ModelAccess.on(vreq).setOntModel(ModelID.BASE_ABOX, baseABoxModel);
|
|
||||||
ModelAccess.on(vreq).setOntModel(ModelID.INFERRED_ABOX, inferenceABoxModel);
|
|
||||||
ModelAccess.on(vreq).setOntModel(ModelID.UNION_ABOX, unionABoxModel);
|
|
||||||
ModelAccess.on(vreq).setOntModel(ModelID.BASE_FULL, baseFullModel);
|
|
||||||
ModelAccess.on(vreq).setOntModel(ModelID.INFERRED_FULL, inferenceFullModel);
|
|
||||||
ModelAccess.on(vreq).setOntModel(ModelID.UNION_FULL, unionFullModel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void useModelFromContext(VitroRequest vreq, ModelID modelId) {
|
private void useModelFromContext(VitroRequest vreq, ModelID modelId) {
|
||||||
|
@ -219,16 +220,21 @@ public class RequestModelsPrep implements Filter {
|
||||||
ModelAccess.on(vreq).setOntModel(modelId, contextModel);
|
ModelAccess.on(vreq).setOntModel(modelId, contextModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create an OntModelSelector that will hold the un-language-filtered models. */
|
/**
|
||||||
|
* Create an OntModelSelector that will hold the un-language-filtered
|
||||||
|
* models.
|
||||||
|
*/
|
||||||
private OntModelSelector createLanguageNeutralOntModelSelector(
|
private OntModelSelector createLanguageNeutralOntModelSelector(
|
||||||
VitroRequest vreq) {
|
VitroRequest vreq) {
|
||||||
OntModelSelectorImpl oms = new OntModelSelectorImpl();
|
OntModelSelectorImpl oms = new OntModelSelectorImpl();
|
||||||
oms.setABoxModel(ModelAccess.on(vreq).getOntModel(ModelID.UNION_ABOX));
|
oms.setABoxModel(ModelAccess.on(vreq).getOntModel(ModelID.UNION_ABOX));
|
||||||
oms.setTBoxModel(ModelAccess.on(vreq).getOntModel(ModelID.UNION_TBOX));
|
oms.setTBoxModel(ModelAccess.on(vreq).getOntModel(ModelID.UNION_TBOX));
|
||||||
oms.setFullModel(ModelAccess.on(vreq).getOntModel(ModelID.UNION_FULL));
|
oms.setFullModel(ModelAccess.on(vreq).getOntModel(ModelID.UNION_FULL));
|
||||||
oms.setApplicationMetadataModel(ModelAccess.on(vreq).getOntModel(ModelID.APPLICATION_METADATA));
|
oms.setApplicationMetadataModel(ModelAccess.on(vreq).getOntModel(
|
||||||
|
ModelID.APPLICATION_METADATA));
|
||||||
oms.setDisplayModel(ModelAccess.on(vreq).getOntModel(ModelID.DISPLAY));
|
oms.setDisplayModel(ModelAccess.on(vreq).getOntModel(ModelID.DISPLAY));
|
||||||
oms.setUserAccountsModel(ModelAccess.on(vreq).getOntModel(ModelID.USER_ACCOUNTS));
|
oms.setUserAccountsModel(ModelAccess.on(vreq).getOntModel(
|
||||||
|
ModelID.USER_ACCOUNTS));
|
||||||
return oms;
|
return oms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,24 +299,26 @@ public class RequestModelsPrep implements Filter {
|
||||||
config.setDefaultNamespace(defaultNamespace);
|
config.setDefaultNamespace(defaultNamespace);
|
||||||
config.setPreferredLanguages(langs);
|
config.setPreferredLanguages(langs);
|
||||||
config.setUnderlyingStoreReasoned(isStoreReasoned(req));
|
config.setUnderlyingStoreReasoned(isStoreReasoned(req));
|
||||||
config.setCustomListViewConfigFileMap(getCustomListViewConfigFileMap(
|
config.setCustomListViewConfigFileMap(getCustomListViewConfigFileMap(req
|
||||||
req.getSession().getServletContext()));
|
.getSession().getServletContext()));
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is also used by VitroHttpServlet to retrieve the right Collator
|
* This method is also used by VitroHttpServlet to retrieve the right
|
||||||
* instance for picklist sorting
|
* Collator instance for picklist sorting
|
||||||
|
*
|
||||||
* @param req
|
* @param req
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Enumeration<Locale> getPreferredLocales(HttpServletRequest req) {
|
public static Enumeration<Locale> getPreferredLocales(HttpServletRequest req) {
|
||||||
return req.getLocales();
|
return req.getLocales();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getPreferredLanguages(HttpServletRequest req) {
|
private List<String> getPreferredLanguages(HttpServletRequest req) {
|
||||||
log.debug("Accept-Language: " + req.getHeader("Accept-Language"));
|
log.debug("Accept-Language: " + req.getHeader("Accept-Language"));
|
||||||
return LanguageFilteringUtils.localesToLanguages(getPreferredLocales(req));
|
return LanguageFilteringUtils
|
||||||
|
.localesToLanguages(getPreferredLocales(req));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -331,35 +339,35 @@ public class RequestModelsPrep implements Filter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCollator(VitroRequest vreq) {
|
private void setCollator(VitroRequest vreq) {
|
||||||
Enumeration<Locale> locales = getPreferredLocales(vreq);
|
Enumeration<Locale> locales = getPreferredLocales(vreq);
|
||||||
while(locales.hasMoreElements()) {
|
while (locales.hasMoreElements()) {
|
||||||
Locale locale = locales.nextElement();
|
Locale locale = locales.nextElement();
|
||||||
Collator collator = Collator.getInstance(locale);
|
Collator collator = Collator.getInstance(locale);
|
||||||
if(collator != null) {
|
if (collator != null) {
|
||||||
vreq.setCollator(collator);
|
vreq.setCollator(collator);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vreq.setCollator(Collator.getInstance());
|
vreq.setCollator(Collator.getInstance());
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isStoreReasoned(ServletRequest req) {
|
|
||||||
String isStoreReasoned = ConfigurationProperties.getBean(req).getProperty(
|
|
||||||
"VitroConnection.DataSource.isStoreReasoned", "true");
|
|
||||||
return ("true".equals(isStoreReasoned));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Pair<String,Pair<ObjectProperty, String>>, String>
|
private boolean isStoreReasoned(ServletRequest req) {
|
||||||
getCustomListViewConfigFileMap(ServletContext ctx) {
|
String isStoreReasoned = ConfigurationProperties.getBean(req)
|
||||||
Map<Pair<String,Pair<ObjectProperty, String>>, String> map =
|
.getProperty("VitroConnection.DataSource.isStoreReasoned",
|
||||||
(Map<Pair<String,Pair<ObjectProperty, String>>, String>)
|
"true");
|
||||||
ctx.getAttribute("customListViewConfigFileMap");
|
return ("true".equals(isStoreReasoned));
|
||||||
if (map == null) {
|
}
|
||||||
map = new ConcurrentHashMap<Pair<String,Pair<ObjectProperty, String>>, String>();
|
|
||||||
ctx.setAttribute("customListViewConfigFileMap", map);
|
private Map<Pair<String, Pair<ObjectProperty, String>>, String> getCustomListViewConfigFileMap(
|
||||||
}
|
ServletContext ctx) {
|
||||||
return map;
|
Map<Pair<String, Pair<ObjectProperty, String>>, String> map = (Map<Pair<String, Pair<ObjectProperty, String>>, String>) ctx
|
||||||
|
.getAttribute("customListViewConfigFileMap");
|
||||||
|
if (map == null) {
|
||||||
|
map = new ConcurrentHashMap<Pair<String, Pair<ObjectProperty, String>>, String>();
|
||||||
|
ctx.setAttribute("customListViewConfigFileMap", map);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tearDownTheRequestModels(HttpServletRequest req) {
|
private void tearDownTheRequestModels(HttpServletRequest req) {
|
||||||
|
|
|
@ -43,6 +43,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.BulkUpdateEvent;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.BulkUpdateEvent;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.adapters.VitroModelFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread;
|
import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread;
|
||||||
|
|
||||||
|
@ -105,8 +106,8 @@ public class SimpleReasoner extends StatementListener {
|
||||||
OntModelSpec.OWL_MEM, ModelFactory.createModelForGraph(
|
OntModelSpec.OWL_MEM, ModelFactory.createModelForGraph(
|
||||||
new RDFServiceGraph(rdfService)));
|
new RDFServiceGraph(rdfService)));
|
||||||
|
|
||||||
this.aboxModel = ModelFactory.createOntologyModel(
|
this.aboxModel = VitroModelFactory.createOntologyModel(
|
||||||
OntModelSpec.OWL_MEM, ModelFactory.createModelForGraph(
|
VitroModelFactory.createModelForGraph(
|
||||||
new DifferenceGraph(new DifferenceGraph(new RDFServiceGraph(rdfService),inferenceModel.getGraph()),
|
new DifferenceGraph(new DifferenceGraph(new RDFServiceGraph(rdfService),inferenceModel.getGraph()),
|
||||||
tboxModel.getGraph())));
|
tboxModel.getGraph())));
|
||||||
|
|
||||||
|
|
|
@ -2,24 +2,15 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||||
|
|
||||||
import static edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils.WhichService.CONFIGURATION;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
import javax.servlet.ServletContextListener;
|
import javax.servlet.ServletContextListener;
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.adapters.VitroModelFactory;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,8 +24,7 @@ public class ConfigurationModelsSetup implements ServletContextListener {
|
||||||
StartupStatus ss = StartupStatus.getBean(ctx);
|
StartupStatus ss = StartupStatus.getBean(ctx);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setupModel(ctx, ModelNames.DISPLAY, "display",
|
setupModel(ctx, ModelNames.DISPLAY, "display", ModelID.DISPLAY);
|
||||||
ModelID.DISPLAY);
|
|
||||||
|
|
||||||
setupModel(ctx, ModelNames.DISPLAY_TBOX, "displayTbox",
|
setupModel(ctx, ModelNames.DISPLAY_TBOX, "displayTbox",
|
||||||
ModelID.DISPLAY_TBOX);
|
ModelID.DISPLAY_TBOX);
|
||||||
|
@ -42,12 +32,11 @@ public class ConfigurationModelsSetup implements ServletContextListener {
|
||||||
setupModel(ctx, ModelNames.DISPLAY_DISPLAY, "displayDisplay",
|
setupModel(ctx, ModelNames.DISPLAY_DISPLAY, "displayDisplay",
|
||||||
ModelID.DISPLAY_DISPLAY);
|
ModelID.DISPLAY_DISPLAY);
|
||||||
|
|
||||||
ss.info(this, "Set up the display models.");
|
|
||||||
|
|
||||||
setupModel(ctx, ModelNames.USER_ACCOUNTS, "auth",
|
setupModel(ctx, ModelNames.USER_ACCOUNTS, "auth",
|
||||||
ModelID.USER_ACCOUNTS);
|
ModelID.USER_ACCOUNTS);
|
||||||
|
|
||||||
ss.info(this, "Set up the user accounts model.");
|
ss.info(this,
|
||||||
|
"Set up the display models and the user accounts model.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ss.fatal(this, e.getMessage(), e.getCause());
|
ss.fatal(this, e.getMessage(), e.getCause());
|
||||||
}
|
}
|
||||||
|
@ -56,44 +45,21 @@ public class ConfigurationModelsSetup implements ServletContextListener {
|
||||||
private void setupModel(ServletContext ctx, String modelUri,
|
private void setupModel(ServletContext ctx, String modelUri,
|
||||||
String modelPath, ModelID modelId) {
|
String modelPath, ModelID modelId) {
|
||||||
try {
|
try {
|
||||||
Dataset dataset = getConfigurationModelsDataset(ctx);
|
OntModel ontModel = ModelAccess.on(ctx).getOntModel(modelId);
|
||||||
OntModel baseModel = getNamedOntModel(modelUri, dataset);
|
loadFirstTimeFiles(ctx, modelPath, ontModel);
|
||||||
|
loadEveryTimeFiles(ctx, modelPath, ontModel);
|
||||||
loadFirstTimeFiles(ctx, modelPath, baseModel);
|
|
||||||
loadEveryTimeFiles(ctx, modelPath, baseModel);
|
|
||||||
|
|
||||||
OntModel memoryModel = wrapWithMemoryModel(baseModel);
|
|
||||||
ModelAccess.on(ctx).setOntModel(modelId, memoryModel);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Failed to create the '" + modelPath
|
throw new RuntimeException("Failed to create the '" + modelPath
|
||||||
+ "' model (" + modelUri + ").", e);
|
+ "' model (" + modelUri + ").", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dataset getConfigurationModelsDataset(ServletContext ctx) {
|
|
||||||
RDFServiceFactory factory = RDFServiceUtils.getRDFServiceFactory(ctx,
|
|
||||||
CONFIGURATION);
|
|
||||||
return new RDFServiceDataset(factory.getRDFService());
|
|
||||||
}
|
|
||||||
|
|
||||||
private OntModel getNamedOntModel(String modelUri, Dataset dataset) {
|
|
||||||
Model model = dataset.getNamedModel(modelUri);
|
|
||||||
return VitroModelFactory.createOntologyModel(model);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadFirstTimeFiles(ServletContext ctx, String modelPath,
|
private void loadFirstTimeFiles(ServletContext ctx, String modelPath,
|
||||||
OntModel baseModel) {
|
OntModel baseModel) {
|
||||||
RDFFilesLoader.loadFirstTimeFiles(ctx, modelPath, baseModel,
|
RDFFilesLoader.loadFirstTimeFiles(ctx, modelPath, baseModel,
|
||||||
baseModel.isEmpty());
|
baseModel.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
private OntModel wrapWithMemoryModel(OntModel baseModel) {
|
|
||||||
OntModel memoryModel = VitroModelFactory.createOntologyModel();
|
|
||||||
memoryModel.add(baseModel);
|
|
||||||
memoryModel.getBaseModel().register(new ModelSynchronizer(baseModel));
|
|
||||||
return memoryModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadEveryTimeFiles(ServletContext ctx, String modelPath,
|
private void loadEveryTimeFiles(ServletContext ctx, String modelPath,
|
||||||
OntModel memoryModel) {
|
OntModel memoryModel) {
|
||||||
RDFFilesLoader.loadEveryTimeFiles(ctx, modelPath, memoryModel);
|
RDFFilesLoader.loadEveryTimeFiles(ctx, modelPath, memoryModel);
|
||||||
|
|
|
@ -29,13 +29,10 @@ import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
|
||||||
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;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB;
|
||||||
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.adapters.VitroModelFactory;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.adapters.VitroModelFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||||
|
@ -59,24 +56,19 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpJenaDataSource(ServletContext ctx) {
|
private void setUpJenaDataSource(ServletContext ctx) {
|
||||||
RDFServiceFactory rdfServiceFactory = RDFServiceUtils.getRDFServiceFactory(ctx);
|
ModelAccess models = ModelAccess.on(ctx);
|
||||||
RDFService rdfService = rdfServiceFactory.getRDFService();
|
|
||||||
Dataset dataset = new RDFServiceDataset(rdfService);
|
|
||||||
setStartupDataset(dataset, ctx);
|
|
||||||
|
|
||||||
OntModel applicationMetadataModel = createdMemoryMappedModel(dataset, ModelNames.APPLICATION_METADATA, "application metadata model");
|
RDFService rdfService = createRdfService(ctx);
|
||||||
|
createStartupDataset(ctx, rdfService);
|
||||||
|
|
||||||
|
Model applicationMetadataModel = models.getOntModel(ModelID.APPLICATION_METADATA);
|
||||||
if (applicationMetadataModel.size()== 0) {
|
if (applicationMetadataModel.size()== 0) {
|
||||||
JenaDataSourceSetupBase.thisIsFirstStartup();
|
thisIsFirstStartup();
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelAccess models = ModelAccess.on(ctx);
|
|
||||||
OntModel baseABoxModel = createNamedModelFromDataset(dataset, ModelNames.ABOX_ASSERTIONS);
|
|
||||||
OntModel inferenceABoxModel = createNamedModelFromDataset(dataset, ModelNames.ABOX_INFERENCES);
|
|
||||||
OntModel baseTBoxModel = createdMemoryMappedModel(dataset, ModelNames.TBOX_ASSERTIONS, "tbox assertions");
|
|
||||||
OntModel inferenceTBoxModel = createdMemoryMappedModel(dataset, ModelNames.TBOX_INFERENCES, "tbox inferences");
|
|
||||||
OntModel unionABoxModel = VitroModelFactory.createUnion(baseABoxModel, inferenceABoxModel);
|
|
||||||
OntModel unionTBoxModel = VitroModelFactory.createUnion(baseTBoxModel, inferenceTBoxModel);
|
|
||||||
|
|
||||||
|
OntModel baseABoxModel = models.getOntModel(ModelID.BASE_ABOX);
|
||||||
|
OntModel baseTBoxModel = models.getOntModel(ModelID.BASE_TBOX);
|
||||||
|
|
||||||
if (isFirstStartup()) {
|
if (isFirstStartup()) {
|
||||||
initializeApplicationMetadata(ctx, applicationMetadataModel);
|
initializeApplicationMetadata(ctx, applicationMetadataModel);
|
||||||
|
@ -88,24 +80,6 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
|
||||||
RDFFilesLoader.loadEveryTimeFiles(ctx, "abox", baseABoxModel);
|
RDFFilesLoader.loadEveryTimeFiles(ctx, "abox", baseABoxModel);
|
||||||
RDFFilesLoader.loadEveryTimeFiles(ctx, "tbox", baseTBoxModel);
|
RDFFilesLoader.loadEveryTimeFiles(ctx, "tbox", baseTBoxModel);
|
||||||
|
|
||||||
log.info("Setting up full models");
|
|
||||||
OntModel baseFullModel = VitroModelFactory.createUnion(baseABoxModel, baseTBoxModel);
|
|
||||||
OntModel inferenceFullModel = VitroModelFactory.createUnion(inferenceABoxModel, inferenceTBoxModel);
|
|
||||||
OntModel unionFullModel = VitroModelFactory.createOntologyModel(dataset.getDefaultModel());
|
|
||||||
|
|
||||||
models.setOntModel(ModelID.APPLICATION_METADATA, applicationMetadataModel);
|
|
||||||
|
|
||||||
models.setOntModel(ModelID.BASE_ABOX, baseABoxModel);
|
|
||||||
models.setOntModel(ModelID.BASE_TBOX, baseTBoxModel);
|
|
||||||
models.setOntModel(ModelID.BASE_FULL, baseFullModel);
|
|
||||||
models.setOntModel(ModelID.INFERRED_ABOX, inferenceABoxModel);
|
|
||||||
models.setOntModel(ModelID.INFERRED_TBOX, inferenceTBoxModel);
|
|
||||||
models.setOntModel(ModelID.INFERRED_FULL, inferenceFullModel);
|
|
||||||
models.setOntModel(ModelID.UNION_ABOX, unionABoxModel);
|
|
||||||
models.setOntModel(ModelID.UNION_TBOX, unionTBoxModel);
|
|
||||||
models.setOntModel(ModelID.UNION_FULL, unionFullModel);
|
|
||||||
|
|
||||||
|
|
||||||
log.info("Setting up DAO factories");
|
log.info("Setting up DAO factories");
|
||||||
|
|
||||||
WebappDaoFactoryConfig config = new WebappDaoFactoryConfig();
|
WebappDaoFactoryConfig config = new WebappDaoFactoryConfig();
|
||||||
|
@ -121,31 +95,16 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
|
||||||
ModelAccess.on(ctx).setWebappDaoFactory(FactoryID.UNION, wadf);
|
ModelAccess.on(ctx).setWebappDaoFactory(FactoryID.UNION, wadf);
|
||||||
ModelAccess.on(ctx).setWebappDaoFactory(FactoryID.UNFILTERED_UNION, wadf);
|
ModelAccess.on(ctx).setWebappDaoFactory(FactoryID.UNFILTERED_UNION, wadf);
|
||||||
|
|
||||||
log.info("Model makers set up");
|
|
||||||
|
|
||||||
ctx.setAttribute("defaultNamespace", getDefaultNamespace(ctx));
|
ctx.setAttribute("defaultNamespace", getDefaultNamespace(ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
private OntModel createNamedModelFromDataset(Dataset dataset, String name) {
|
private RDFService createRdfService(ServletContext ctx) {
|
||||||
return VitroModelFactory.createOntologyModel(dataset.getNamedModel(name));
|
return RDFServiceUtils.getRDFServiceFactory(ctx).getRDFService();
|
||||||
}
|
}
|
||||||
|
|
||||||
private OntModel createdMemoryMappedModel(Dataset dataset, String name, String label) {
|
private void createStartupDataset(ServletContext ctx, RDFService rdfService) {
|
||||||
try {
|
Dataset dataset = new RDFServiceDataset(rdfService);
|
||||||
Model dbModel = dataset.getNamedModel(name);
|
setStartupDataset(dataset, ctx);
|
||||||
OntModel memoryModel = VitroModelFactory.createOntologyModel();
|
|
||||||
|
|
||||||
if (dbModel != null) {
|
|
||||||
long begin = System.currentTimeMillis();
|
|
||||||
log.info("Copying cached " + label + " into memory");
|
|
||||||
memoryModel.add(dbModel);
|
|
||||||
log.info(secondsSince(begin) + " seconds to load " + label);
|
|
||||||
memoryModel.getBaseModel().register(new ModelSynchronizer(dbModel));
|
|
||||||
}
|
|
||||||
return memoryModel;
|
|
||||||
} catch (Throwable e) {
|
|
||||||
throw new RuntimeException("Unable to load " + label + " from DB", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private long secondsSince(long startTime) {
|
private long secondsSince(long startTime) {
|
||||||
|
@ -162,7 +121,7 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
|
||||||
* warnings about editing a blank node.
|
* warnings about editing a blank node.
|
||||||
*/
|
*/
|
||||||
private void initializeApplicationMetadata(ServletContext ctx,
|
private void initializeApplicationMetadata(ServletContext ctx,
|
||||||
OntModel applicationMetadataModel) {
|
Model applicationMetadataModel) {
|
||||||
OntModel temporaryAMModel = VitroModelFactory.createOntologyModel();
|
OntModel temporaryAMModel = VitroModelFactory.createOntologyModel();
|
||||||
RDFFilesLoader.loadFirstTimeFiles(ctx, "applicationMetadata", temporaryAMModel, true);
|
RDFFilesLoader.loadFirstTimeFiles(ctx, "applicationMetadata", temporaryAMModel, true);
|
||||||
setPortalUriOnFirstTime(temporaryAMModel, ctx);
|
setPortalUriOnFirstTime(temporaryAMModel, ctx);
|
||||||
|
@ -173,7 +132,7 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
|
||||||
* If we are loading the application metadata for the first time, set the
|
* If we are loading the application metadata for the first time, set the
|
||||||
* URI of the Portal based on the default namespace.
|
* URI of the Portal based on the default namespace.
|
||||||
*/
|
*/
|
||||||
private void setPortalUriOnFirstTime(OntModel model, ServletContext ctx) {
|
private void setPortalUriOnFirstTime(Model model, ServletContext ctx) {
|
||||||
// Only a single portal is permitted in the initialization data
|
// Only a single portal is permitted in the initialization data
|
||||||
Resource portalResource = null;
|
Resource portalResource = null;
|
||||||
ClosableIterator<Resource> portalResIt = model
|
ClosableIterator<Resource> portalResIt = model
|
||||||
|
@ -200,7 +159,7 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
|
||||||
* If we find a "portal1" portal (and we should), its URI should use the
|
* If we find a "portal1" portal (and we should), its URI should use the
|
||||||
* default namespace.
|
* default namespace.
|
||||||
*/
|
*/
|
||||||
private void checkForNamespaceMismatch(OntModel model, ServletContext ctx) {
|
private void checkForNamespaceMismatch(Model model, ServletContext ctx) {
|
||||||
String expectedNamespace = getDefaultNamespace(ctx);
|
String expectedNamespace = getDefaultNamespace(ctx);
|
||||||
|
|
||||||
List<Resource> portals = getPortal1s(model);
|
List<Resource> portals = getPortal1s(model);
|
||||||
|
|
|
@ -29,12 +29,16 @@ import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
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.ModelMaker;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceModelMaker;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.BlankNodeFilteringModelMaker;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelMakerUtils;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils.WhichService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||||
|
|
||||||
// This ContextListener must run after the JenaDataSourceSetup ContextListener
|
// This ContextListener must run after the JenaDataSourceSetup ContextListener
|
||||||
|
@ -63,32 +67,33 @@ public class FileGraphSetup implements ServletContextListener {
|
||||||
|
|
||||||
boolean aboxChanged = false; // indicates whether any ABox file graph model has changed
|
boolean aboxChanged = false; // indicates whether any ABox file graph model has changed
|
||||||
boolean tboxChanged = false; // indicates whether any TBox file graph model has changed
|
boolean tboxChanged = false; // indicates whether any TBox file graph model has changed
|
||||||
OntModelSelector baseOms = null;
|
|
||||||
|
|
||||||
ServletContext ctx = sce.getServletContext();
|
ServletContext ctx = sce.getServletContext();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OntDocumentManager.getInstance().setProcessImports(true);
|
OntDocumentManager.getInstance().setProcessImports(true);
|
||||||
baseOms = ModelAccess.on(ctx).getBaseOntModelSelector();
|
|
||||||
Dataset dataset = JenaDataSourceSetupBase.getStartupDataset(ctx);
|
Dataset dataset = JenaDataSourceSetupBase.getStartupDataset(ctx);
|
||||||
RDFServiceModelMaker maker = new RDFServiceModelMaker(RDFServiceUtils.getRDFServiceFactory(ctx));
|
RDFService rdfService = RDFServiceUtils.getRDFServiceFactory(ctx,
|
||||||
|
WhichService.CONTENT).getRDFService();
|
||||||
|
ModelMaker modelMaker = new BlankNodeFilteringModelMaker(
|
||||||
|
rdfService, ModelMakerUtils.getModelMaker(ctx,
|
||||||
|
WhichService.CONTENT));
|
||||||
|
|
||||||
// ABox files
|
// ABox files
|
||||||
Set<Path> paths = getFilegraphPaths(ctx, RDF, ABOX, FILEGRAPH);
|
Set<Path> paths = getFilegraphPaths(ctx, RDF, ABOX, FILEGRAPH);
|
||||||
|
|
||||||
cleanupDB(dataset, pathsToURIs(paths, ABOX), ABOX);
|
cleanupDB(dataset, pathsToURIs(paths, ABOX), ABOX);
|
||||||
|
|
||||||
OntModel aboxBaseModel = baseOms.getABoxModel();
|
|
||||||
// Just update the ABox filegraphs in the DB; don't attach them to a base model.
|
// Just update the ABox filegraphs in the DB; don't attach them to a base model.
|
||||||
aboxChanged = readGraphs(paths, maker, ABOX, /* aboxBaseModel */ null);
|
aboxChanged = readGraphs(paths, modelMaker, ABOX, /* aboxBaseModel */ null);
|
||||||
|
|
||||||
// TBox files
|
// TBox files
|
||||||
paths = getFilegraphPaths(ctx, RDF, TBOX, FILEGRAPH);
|
paths = getFilegraphPaths(ctx, RDF, TBOX, FILEGRAPH);
|
||||||
|
|
||||||
cleanupDB(dataset, pathsToURIs(paths, TBOX),TBOX);
|
cleanupDB(dataset, pathsToURIs(paths, TBOX),TBOX);
|
||||||
|
|
||||||
OntModel tboxBaseModel = baseOms.getTBoxModel();
|
OntModel tboxBaseModel = ModelAccess.on(ctx).getOntModel(ModelID.BASE_TBOX);
|
||||||
tboxChanged = readGraphs(paths, maker, TBOX, tboxBaseModel);
|
tboxChanged = readGraphs(paths, modelMaker, TBOX, tboxBaseModel);
|
||||||
} catch (ClassCastException cce) {
|
} catch (ClassCastException cce) {
|
||||||
String errMsg = "Unable to cast servlet context attribute to the appropriate type " + cce.getLocalizedMessage();
|
String errMsg = "Unable to cast servlet context attribute to the appropriate type " + cce.getLocalizedMessage();
|
||||||
log.error(errMsg);
|
log.error(errMsg);
|
||||||
|
@ -100,16 +105,16 @@ public class FileGraphSetup implements ServletContextListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (isUpdateRequired(sce.getServletContext())) {
|
if (isUpdateRequired(ctx)) {
|
||||||
log.info("mostSpecificType will be computed because a knowledge base migration was performed." );
|
log.info("mostSpecificType will be computed because a knowledge base migration was performed." );
|
||||||
SimpleReasonerSetup.setMSTComputeRequired(sce.getServletContext());
|
SimpleReasonerSetup.setMSTComputeRequired(ctx);
|
||||||
} else
|
} else
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( (aboxChanged || tboxChanged) && !isUpdateRequired(sce.getServletContext())) {
|
if ( (aboxChanged || tboxChanged) && !isUpdateRequired(ctx)) {
|
||||||
log.info("a full recompute of the Abox will be performed because" +
|
log.info("a full recompute of the Abox will be performed because" +
|
||||||
" the filegraph abox(s) and/or tbox(s) have changed or are being read for the first time." );
|
" the filegraph abox(s) and/or tbox(s) have changed or are being read for the first time." );
|
||||||
SimpleReasonerSetup.setRecomputeRequired(sce.getServletContext(), SimpleReasonerSetup.RecomputeMode.BACKGROUND);
|
SimpleReasonerSetup.setRecomputeRequired(ctx, SimpleReasonerSetup.RecomputeMode.BACKGROUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,14 +146,6 @@ public class FileGraphSetup implements ServletContextListener {
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Reads graphs without using submodels to separate filegraph content from the
|
|
||||||
* base model.
|
|
||||||
*/
|
|
||||||
public boolean readGraphs(Set<Path> pathSet, RDFServiceModelMaker dataset, String type, OntModel baseModel) {
|
|
||||||
return readGraphs(pathSet, dataset, type, baseModel, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reads the graphs stored as files in sub-directories of
|
* Reads the graphs stored as files in sub-directories of
|
||||||
* 1. updates the SDB store to reflect the current contents of the graph.
|
* 1. updates the SDB store to reflect the current contents of the graph.
|
||||||
|
@ -157,7 +154,7 @@ public class FileGraphSetup implements ServletContextListener {
|
||||||
* Note: no connection needs to be maintained between the in-memory copy of the
|
* Note: no connection needs to be maintained between the in-memory copy of the
|
||||||
* graph and the DB copy.
|
* graph and the DB copy.
|
||||||
*/
|
*/
|
||||||
public boolean readGraphs(Set<Path> pathSet, RDFServiceModelMaker dataset, String type, OntModel baseModel, boolean useSubmodels) {
|
private boolean readGraphs(Set<Path> pathSet, ModelMaker modelMaker, String type, OntModel baseModel) {
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
|
@ -182,15 +179,11 @@ public class FileGraphSetup implements ServletContextListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !model.isEmpty() && baseModel != null ) {
|
if ( !model.isEmpty() && baseModel != null ) {
|
||||||
if (useSubmodels) {
|
baseModel.addSubModel(model);
|
||||||
baseModel.addSubModel(model);
|
|
||||||
} else {
|
|
||||||
baseModel.add(model);
|
|
||||||
}
|
|
||||||
log.debug("Attached file graph as " + type + " submodel " + p.getFileName());
|
log.debug("Attached file graph as " + type + " submodel " + p.getFileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
modelChanged = modelChanged | updateGraphInDB(dataset, model, type, p);
|
modelChanged = modelChanged | updateGraphInDB(modelMaker, model, type, p);
|
||||||
|
|
||||||
} catch (Exception ioe) {
|
} catch (Exception ioe) {
|
||||||
log.error("Unable to process file graph " + p, ioe);
|
log.error("Unable to process file graph " + p, ioe);
|
||||||
|
@ -224,10 +217,14 @@ public class FileGraphSetup implements ServletContextListener {
|
||||||
* Otherwise, if a graph with the given name is in the DB and is isomorphic with
|
* Otherwise, if a graph with the given name is in the DB and is isomorphic with
|
||||||
* the graph that was read from the files system, then do nothing.
|
* the graph that was read from the files system, then do nothing.
|
||||||
*/
|
*/
|
||||||
public boolean updateGraphInDB(RDFServiceModelMaker dataset, Model fileModel, String type, Path path) {
|
public boolean updateGraphInDB(ModelMaker modelMaker, Model fileModel, String type, Path path) {
|
||||||
String graphURI = pathToURI(path,type);
|
String graphURI = pathToURI(path,type);
|
||||||
Model dbModel = dataset.getModel(graphURI);
|
Model dbModel = modelMaker.getModel(graphURI);
|
||||||
boolean modelChanged = false;
|
boolean modelChanged = false;
|
||||||
|
log.debug(String.format(
|
||||||
|
"%s %s dbModel size is %d, fileModel size is %d", type,
|
||||||
|
path.getFileName(), dbModel.size(), fileModel.size()));
|
||||||
|
|
||||||
|
|
||||||
boolean isIsomorphic = dbModel.isIsomorphicWith(fileModel);
|
boolean isIsomorphic = dbModel.isIsomorphicWith(fileModel);
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,14 @@ import javax.servlet.ServletContextListener;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.vocabulary.OWL;
|
import com.hp.hpl.jena.vocabulary.OWL;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener;
|
||||||
|
@ -52,13 +53,13 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// set up Pellet reasoning for the TBox
|
// set up Pellet reasoning for the TBox
|
||||||
OntModelSelector assertionsOms = ModelAccess.on(ctx).getBaseOntModelSelector();
|
OntModel tboxAssertionsModel = ModelAccess.on(ctx).getOntModel(ModelID.BASE_TBOX);
|
||||||
OntModelSelector inferencesOms = ModelAccess.on(ctx).getInferenceOntModelSelector();
|
OntModel tboxInferencesModel = ModelAccess.on(ctx).getOntModel(ModelID.INFERRED_TBOX);
|
||||||
OntModelSelector unionOms = ModelAccess.on(ctx).getUnionOntModelSelector();
|
OntModel tboxUnionModel = ModelAccess.on(ctx).getOntModel(ModelID.UNION_TBOX);
|
||||||
|
|
||||||
WebappDaoFactory wadf = ModelAccess.on(ctx).getWebappDaoFactory();
|
WebappDaoFactory wadf = ModelAccess.on(ctx).getWebappDaoFactory();
|
||||||
|
|
||||||
if (!assertionsOms.getTBoxModel().getProfile().NAMESPACE().equals(OWL.NAMESPACE.getNameSpace())) {
|
if (!tboxAssertionsModel.getProfile().NAMESPACE().equals(OWL.NAMESPACE.getNameSpace())) {
|
||||||
log.error("Not connecting Pellet reasoner - the TBox assertions model is not an OWL model");
|
log.error("Not connecting Pellet reasoner - the TBox assertions model is not an OWL model");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -71,7 +72,7 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
//PelletOptions.USE_INCREMENTAL_CONSISTENCY = true;
|
//PelletOptions.USE_INCREMENTAL_CONSISTENCY = true;
|
||||||
//PelletOptions.USE_INCREMENTAL_DELETION = true;
|
//PelletOptions.USE_INCREMENTAL_DELETION = true;
|
||||||
|
|
||||||
PelletListener pelletListener = new PelletListener(unionOms.getTBoxModel(),assertionsOms.getTBoxModel(),inferencesOms.getTBoxModel(),ReasonerConfiguration.DEFAULT);
|
PelletListener pelletListener = new PelletListener(tboxUnionModel,tboxAssertionsModel,tboxInferencesModel,ReasonerConfiguration.DEFAULT);
|
||||||
sce.getServletContext().setAttribute("pelletListener",pelletListener);
|
sce.getServletContext().setAttribute("pelletListener",pelletListener);
|
||||||
sce.getServletContext().setAttribute("pelletOntModel", pelletListener.getPelletModel());
|
sce.getServletContext().setAttribute("pelletOntModel", pelletListener.getPelletModel());
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
|
|
||||||
// the simple reasoner will register itself as a listener to the ABox assertions
|
// the simple reasoner will register itself as a listener to the ABox assertions
|
||||||
SimpleReasoner simpleReasoner = new SimpleReasoner(
|
SimpleReasoner simpleReasoner = new SimpleReasoner(
|
||||||
unionOms.getTBoxModel(), rdfService, inferenceModel, rebuildModel, scratchModel);
|
tboxUnionModel, rdfService, inferenceModel, rebuildModel, scratchModel);
|
||||||
sce.getServletContext().setAttribute(SimpleReasoner.class.getName(),simpleReasoner);
|
sce.getServletContext().setAttribute(SimpleReasoner.class.getName(),simpleReasoner);
|
||||||
|
|
||||||
StartupStatus ss = StartupStatus.getBean(ctx);
|
StartupStatus ss = StartupStatus.getBean(ctx);
|
||||||
|
@ -117,8 +118,8 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
|
|
||||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = new SimpleReasonerTBoxListener(simpleReasoner);
|
SimpleReasonerTBoxListener simpleReasonerTBoxListener = new SimpleReasonerTBoxListener(simpleReasoner);
|
||||||
sce.getServletContext().setAttribute(SimpleReasonerTBoxListener.class.getName(),simpleReasonerTBoxListener);
|
sce.getServletContext().setAttribute(SimpleReasonerTBoxListener.class.getName(),simpleReasonerTBoxListener);
|
||||||
assertionsOms.getTBoxModel().register(simpleReasonerTBoxListener);
|
tboxAssertionsModel.register(simpleReasonerTBoxListener);
|
||||||
inferencesOms.getTBoxModel().register(simpleReasonerTBoxListener);
|
tboxInferencesModel.register(simpleReasonerTBoxListener);
|
||||||
|
|
||||||
RecomputeMode mode = getRecomputeRequired(ctx);
|
RecomputeMode mode = getRecomputeRequired(ctx);
|
||||||
if (RecomputeMode.FOREGROUND.equals(mode)) {
|
if (RecomputeMode.FOREGROUND.equals(mode)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue