From 0e34b459e50bcce83f0526bcda95ba43f88fb60f Mon Sep 17 00:00:00 2001 From: j2blake Date: Thu, 16 May 2013 14:04:04 -0400 Subject: [PATCH 1/9] VIVO-82 Refactoring WebappDaoSetup to clarify the model setup. --- .../webapp/servlet/setup/WebappDaoSetup.java | 363 +++++++----------- 1 file changed, 146 insertions(+), 217 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/WebappDaoSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/WebappDaoSetup.java index b55cba9fd..7b198a8f3 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/WebappDaoSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/WebappDaoSetup.java @@ -3,6 +3,8 @@ package edu.cornell.mannlib.vitro.webapp.servlet.setup; import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL; +import static edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode.ASSERTIONS_ONLY; +import static edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode.INFERENCES_ONLY; import java.util.ArrayList; import java.util.List; @@ -13,6 +15,8 @@ import javax.servlet.ServletContextEvent; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import com.hp.hpl.jena.graph.BulkUpdateHandler; +import com.hp.hpl.jena.graph.Graph; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.query.Dataset; @@ -20,19 +24,14 @@ import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.ResIterator; import com.hp.hpl.jena.rdf.model.Resource; -import com.hp.hpl.jena.rdf.model.ResourceFactory; -import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.util.ResourceUtils; -import com.hp.hpl.jena.util.iterator.ClosableIterator; import com.hp.hpl.jena.vocabulary.RDF; -import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; 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.OntModelSelectorImpl; import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset; import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceModelMaker; @@ -59,202 +58,96 @@ public class WebappDaoSetup extends JenaDataSourceSetupBase ServletContext ctx = sce.getServletContext(); StartupStatus ss = StartupStatus.getBean(ctx); - try { - long startTime = System.currentTimeMillis(); - setUpJenaDataSource(ctx, ss); - log.info((System.currentTimeMillis() - startTime) / 1000 + - " seconds to set up models and DAO factories"); - } catch (Throwable t) { - log.error("Throwable in " + this.getClass().getName(), t); - ss.fatal(this, "Throwable in " + this.getClass().getName(), t); - } - + long begin = System.currentTimeMillis(); + setUpJenaDataSource(ctx); + ss.info(this, secondsSince(begin) + " seconds to set up models and DAO factories"); } - private void setUpJenaDataSource(ServletContext ctx, StartupStatus ss) { - OntModelSelectorImpl baseOms = new OntModelSelectorImpl(); - OntModelSelectorImpl inferenceOms = new OntModelSelectorImpl(); - OntModelSelectorImpl unionOms = new OntModelSelectorImpl(); - - OntModel userAccountsModel = ontModelFromContextAttribute( - ctx, "userAccountsOntModel"); - baseOms.setUserAccountsModel(userAccountsModel); - inferenceOms.setUserAccountsModel(userAccountsModel); - unionOms.setUserAccountsModel(userAccountsModel); - - OntModel displayModel = ontModelFromContextAttribute( - ctx,DISPLAY_ONT_MODEL); - baseOms.setDisplayModel(displayModel); - inferenceOms.setDisplayModel(displayModel); - unionOms.setDisplayModel(displayModel); - - RDFServiceFactory rdfServiceFactory = RDFServiceUtils.getRDFServiceFactory(ctx); - RDFService rdfService = rdfServiceFactory.getRDFService(); - Dataset dataset = new RDFServiceDataset(rdfService); - setStartupDataset(dataset, ctx); - - // ABox assertions - baseOms.setABoxModel(ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, dataset.getNamedModel(JenaDataSourceSetupBase.JENA_DB_MODEL))); - - // ABox inferences - inferenceOms.setABoxModel(ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, dataset.getNamedModel(JenaDataSourceSetupBase.JENA_INF_MODEL))); - - // TBox assertions - try { - Model tboxAssertionsDB = dataset.getNamedModel( - JENA_TBOX_ASSERTIONS_MODEL); - OntModel tboxAssertions = ModelFactory.createOntologyModel( - MEM_ONT_MODEL_SPEC); - - if (tboxAssertionsDB != null) { - long startTime = System.currentTimeMillis(); - log.info("Copying cached tbox assertions into memory"); - tboxAssertions.add(tboxAssertionsDB); - log.info((System.currentTimeMillis() - startTime)/ 1000 + " seconds to load tbox assertions"); - tboxAssertions.getBaseModel().register(new ModelSynchronizer(tboxAssertionsDB)); - } - - baseOms.setTBoxModel(tboxAssertions); - } catch (Throwable e) { - log.error("Unable to load tbox assertion cache from DB", e); - throw new RuntimeException(e); - } - - // TBox inferences - try { - Model tboxInferencesDB = dataset.getNamedModel(JENA_TBOX_INF_MODEL); - OntModel tboxInferences = ModelFactory.createOntologyModel( - MEM_ONT_MODEL_SPEC); - - if (tboxInferencesDB != null) { - long startTime = System.currentTimeMillis(); - log.info( - "Copying cached tbox inferences into memory"); - tboxInferences.add(tboxInferencesDB); - System.out.println((System.currentTimeMillis() - startTime) - / 1000 + " seconds to load tbox inferences"); - - tboxInferences.getBaseModel().register(new ModelSynchronizer( - tboxInferencesDB)); - } - inferenceOms.setTBoxModel(tboxInferences); - } catch (Throwable e) { - log.error("Unable to load tbox inference cache from DB", e); - throw new RuntimeException(e); - } - - // union ABox - Model m = ModelFactory.createUnion( - baseOms.getABoxModel(), inferenceOms.getABoxModel()); - m = ModelFactory.createModelForGraph( - new SpecialBulkUpdateHandlerGraph( - m.getGraph(), - baseOms.getABoxModel().getGraph().getBulkUpdateHandler())); - OntModel unionABoxModel = ModelFactory.createOntologyModel( - MEM_ONT_MODEL_SPEC, m); - unionOms.setABoxModel(unionABoxModel); - - // union TBox - m = ModelFactory.createUnion(baseOms.getTBoxModel(), inferenceOms.getTBoxModel()); - m = ModelFactory.createModelForGraph( - new SpecialBulkUpdateHandlerGraph( - m.getGraph(), - baseOms.getTBoxModel().getGraph().getBulkUpdateHandler())); - OntModel unionTBoxModel = ModelFactory.createOntologyModel( - MEM_ONT_MODEL_SPEC, m); - unionOms.setTBoxModel(unionTBoxModel); - - - // Application metadata model is cached in memory. - try { - - Model applicationMetadataModelDB = dataset.getNamedModel( - JENA_APPLICATION_METADATA_MODEL); - OntModel applicationMetadataModel = - ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC); - - long startTime = System.currentTimeMillis(); - System.out.println( - "Copying cached application metadata model into memory"); - applicationMetadataModel.add(applicationMetadataModelDB); - System.out.println((System.currentTimeMillis() - startTime) - / 1000 + " seconds to load application metadata model " + - "assertions of size " + applicationMetadataModel.size()); - applicationMetadataModel.getBaseModel().register( - new ModelSynchronizer(applicationMetadataModelDB)); - - if (applicationMetadataModel.size()== 0 /* isFirstStartup() */) { - JenaDataSourceSetupBase.thisIsFirstStartup(); - applicationMetadataModel.add( - InitialJenaModelUtils.loadInitialModel( - ctx, getDefaultNamespace(ctx))); - } - - baseOms.setApplicationMetadataModel(applicationMetadataModel); - inferenceOms.setApplicationMetadataModel( - baseOms.getApplicationMetadataModel()); - unionOms.setApplicationMetadataModel( - baseOms.getApplicationMetadataModel()); - - } catch (Throwable e) { - log.error("Unable to load application metadata model cache from DB" - , e); - throw new RuntimeException(e); - } - - checkForNamespaceMismatch( baseOms.getApplicationMetadataModel(), ctx ); - + private void setUpJenaDataSource(ServletContext ctx) { + RDFServiceFactory rdfServiceFactory = RDFServiceUtils.getRDFServiceFactory(ctx); + RDFService rdfService = rdfServiceFactory.getRDFService(); + Dataset dataset = new RDFServiceDataset(rdfService); + setStartupDataset(dataset, ctx); + + OntModel applicationMetadataModel = createdMemoryMappedModel(dataset, JENA_APPLICATION_METADATA_MODEL, "application metadata model"); + if (applicationMetadataModel.size()== 0) { + JenaDataSourceSetupBase.thisIsFirstStartup(); + } + + OntModel userAccountsModel = ontModelFromContextAttribute(ctx, "userAccountsOntModel"); + OntModel displayModel = ontModelFromContextAttribute(ctx,DISPLAY_ONT_MODEL); + OntModel baseABoxModel = createNamedModelFromDataset(dataset, JENA_DB_MODEL); + OntModel inferenceABoxModel = createNamedModelFromDataset(dataset, JENA_INF_MODEL); + OntModel baseTBoxModel = createdMemoryMappedModel(dataset, JENA_TBOX_ASSERTIONS_MODEL, "tbox assertions"); + OntModel inferenceTBoxModel = createdMemoryMappedModel(dataset, JENA_TBOX_INF_MODEL, "tbox inferences"); + OntModel unionABoxModel = createCombinedBulkUpdatingModel(baseABoxModel, inferenceABoxModel); + OntModel unionTBoxModel = createCombinedBulkUpdatingModel(baseTBoxModel, inferenceTBoxModel); + if (isFirstStartup()) { - loadDataFromFilesystem(baseOms, ctx); + loadInitialApplicationMetadataModel(applicationMetadataModel, ctx); + loadDataFromFilesystem(baseABoxModel, baseTBoxModel, applicationMetadataModel, ctx); } - log.info("Setting up union models and DAO factories"); + log.info("Setting up union models"); + OntModel baseFullModel = createCombinedBulkUpdatingModel(baseABoxModel, baseTBoxModel); + OntModel inferenceFullModel = createCombinedModel(inferenceABoxModel, inferenceTBoxModel); + OntModel unionFullModel = ModelFactory.createOntologyModel(DB_ONT_MODEL_SPEC, dataset.getDefaultModel()); + + ModelContext.setBaseOntModel(baseFullModel, ctx); + ModelContext.setInferenceOntModel(inferenceFullModel, ctx); + + checkForNamespaceMismatch( applicationMetadataModel, ctx ); + + OntModelSelectorImpl baseOms = new OntModelSelectorImpl(); + baseOms.setApplicationMetadataModel(applicationMetadataModel); + baseOms.setUserAccountsModel(userAccountsModel); + baseOms.setDisplayModel(displayModel); + baseOms.setABoxModel(baseABoxModel); + baseOms.setTBoxModel(baseTBoxModel); + baseOms.setFullModel(baseFullModel); + + OntModelSelectorImpl inferenceOms = new OntModelSelectorImpl(); + inferenceOms.setApplicationMetadataModel(applicationMetadataModel); + inferenceOms.setUserAccountsModel(userAccountsModel); + inferenceOms.setDisplayModel(displayModel); + inferenceOms.setABoxModel(inferenceABoxModel); + inferenceOms.setTBoxModel(inferenceTBoxModel); + inferenceOms.setFullModel(inferenceFullModel); + + OntModelSelectorImpl unionOms = new OntModelSelectorImpl(); + unionOms.setApplicationMetadataModel(applicationMetadataModel); + unionOms.setUserAccountsModel(userAccountsModel); + unionOms.setDisplayModel(displayModel); + unionOms.setABoxModel(unionABoxModel); + unionOms.setTBoxModel(unionTBoxModel); + unionOms.setFullModel(unionFullModel); + + ModelContext.setOntModelSelector(unionOms, ctx); + ModelContext.setUnionOntModelSelector(unionOms, ctx); // assertions and inferences + ModelContext.setBaseOntModelSelector(baseOms, ctx); // assertions + ModelContext.setInferenceOntModelSelector(inferenceOms, ctx); // inferences + + + + + log.info("Setting up DAO factories"); + + + ctx.setAttribute("jenaOntModel", unionFullModel); - // create TBox + ABox union models and set up webapp DAO factories - Model baseDynamicUnion = ModelFactory.createUnion(baseOms.getABoxModel(), - baseOms.getTBoxModel()); - baseDynamicUnion = ModelFactory.createModelForGraph( - new SpecialBulkUpdateHandlerGraph( - baseDynamicUnion.getGraph(), - baseOms.getABoxModel().getGraph().getBulkUpdateHandler()) ); - OntModel baseUnion = ModelFactory.createOntologyModel( - OntModelSpec.OWL_MEM, baseDynamicUnion); - baseOms.setFullModel(baseUnion); - ModelContext.setBaseOntModel(baseOms.getFullModel(), ctx); WebappDaoFactoryConfig config = new WebappDaoFactoryConfig(); config.setDefaultNamespace(getDefaultNamespace(ctx)); - WebappDaoFactory baseWadf = new WebappDaoFactorySDB( - rdfService, baseOms, config, - WebappDaoFactorySDB.SDBDatasetMode.ASSERTIONS_ONLY); + + WebappDaoFactory baseWadf = new WebappDaoFactorySDB(rdfService, baseOms, config, ASSERTIONS_ONLY); ctx.setAttribute("assertionsWebappDaoFactory",baseWadf); - OntModel inferenceUnion = ModelFactory.createOntologyModel( - OntModelSpec.OWL_MEM, - ModelFactory.createUnion( - inferenceOms.getABoxModel(), - inferenceOms.getTBoxModel())); - inferenceOms.setFullModel(inferenceUnion); - ModelContext.setInferenceOntModel(inferenceOms.getFullModel(), ctx); - WebappDaoFactory infWadf = new WebappDaoFactorySDB( - rdfService, inferenceOms, config, - WebappDaoFactorySDB.SDBDatasetMode.INFERENCES_ONLY); + WebappDaoFactory infWadf = new WebappDaoFactorySDB(rdfService, inferenceOms, config, INFERENCES_ONLY); ctx.setAttribute("deductionsWebappDaoFactory", infWadf); - OntModel masterUnion = ModelFactory.createOntologyModel( - DB_ONT_MODEL_SPEC, dataset.getDefaultModel()); - unionOms.setFullModel(masterUnion); - ctx.setAttribute("jenaOntModel", masterUnion); - WebappDaoFactory wadf = new WebappDaoFactorySDB( - rdfService, unionOms, config); + WebappDaoFactory wadf = new WebappDaoFactorySDB(rdfService, unionOms, config); ctx.setAttribute("webappDaoFactory",wadf); - ModelContext.setOntModelSelector(unionOms, ctx); - ModelContext.setUnionOntModelSelector(unionOms, ctx); - // assertions and inferences - ModelContext.setBaseOntModelSelector(baseOms, ctx); - // assertions - ModelContext.setInferenceOntModelSelector(inferenceOms, ctx); - // inferences + log.info("Model makers set up"); ctx.setAttribute("defaultNamespace", getDefaultNamespace(ctx)); @@ -269,9 +162,54 @@ public class WebappDaoSetup extends JenaDataSourceSetupBase //I don't know what are the implications of this choice. setVitroModelSource( new VitroModelSource(vsmm,ctx), ctx); - log.info("Model makers set up"); } + private OntModel createNamedModelFromDataset(Dataset dataset, String name) { + return ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, dataset.getNamedModel(name)); + } + + private OntModel createdMemoryMappedModel(Dataset dataset, String name, String label) { + try { + Model dbModel = dataset.getNamedModel(name); + OntModel memoryModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC); + + 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 OntModel createCombinedModel(OntModel oneModel, OntModel otherModel) { + return ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, + ModelFactory.createUnion(oneModel, otherModel)); + } + + private OntModel createCombinedBulkUpdatingModel(OntModel baseModel, + OntModel otherModel) { + BulkUpdateHandler bulkUpdateHandler = baseModel.getGraph().getBulkUpdateHandler(); + Graph unionGraph = ModelFactory.createUnion(baseModel, otherModel).getGraph(); + Model unionModel = ModelFactory.createModelForGraph( + new SpecialBulkUpdateHandlerGraph(unionGraph, bulkUpdateHandler)); + return ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC, unionModel); + } + + private void loadInitialApplicationMetadataModel(OntModel applicationMetadataModel, + ServletContext ctx) { + try { + applicationMetadataModel.add( + InitialJenaModelUtils.loadInitialModel(ctx, getDefaultNamespace(ctx))); + } catch (Throwable e) { + throw new RuntimeException("Unable to load application metadata model cache from DB", e); + } + } + /** * If we find a "portal1" portal (and we should), its URI should use the @@ -340,6 +278,26 @@ public class WebappDaoSetup extends JenaDataSourceSetupBase } } + + /* ===================================================================== */ + + private long secondsSince(long startTime) { + return (System.currentTimeMillis() - startTime) / 1000; + } + + private void loadDataFromFilesystem(OntModel baseABoxModel, OntModel baseTBoxModel, OntModel applicationMetadataModel, + ServletContext ctx) { + Long startTime = System.currentTimeMillis(); + log.info("Initializing models from RDF files"); + + readOntologyFilesInPathSet(USER_ABOX_PATH, ctx, baseABoxModel); + readOntologyFilesInPathSet(USER_TBOX_PATH, ctx, baseTBoxModel); + readOntologyFilesInPathSet(USER_APPMETA_PATH, ctx, applicationMetadataModel); + + log.debug(((System.currentTimeMillis() - startTime) / 1000) + + " seconds to read RDF files "); + } + /* ===================================================================== */ @@ -349,35 +307,6 @@ public class WebappDaoSetup extends JenaDataSourceSetupBase // Nothing to do. } - private boolean isEmpty(Model model) { - ClosableIterator closeIt = model.listStatements( - null, RDF.type, ResourceFactory.createResource( - VitroVocabulary.PORTAL)); - try { - if (closeIt.hasNext()) { - return false; - } else { - return true; - } - } finally { - closeIt.close(); - } - } - - private void loadDataFromFilesystem(OntModelSelector baseOms, - ServletContext ctx) { - Long startTime = System.currentTimeMillis(); - log.info("Initializing models from RDF files"); - - readOntologyFilesInPathSet(USER_ABOX_PATH, ctx, baseOms.getABoxModel()); - readOntologyFilesInPathSet(USER_TBOX_PATH, ctx, baseOms.getTBoxModel()); - readOntologyFilesInPathSet( - USER_APPMETA_PATH, ctx, baseOms.getApplicationMetadataModel()); - - log.debug(((System.currentTimeMillis() - startTime) / 1000) - + " seconds to read RDF files "); - } - From 416e98f5abd160a84b4c8d9ed727a4d332af8c4e Mon Sep 17 00:00:00 2001 From: j2blake Date: Thu, 16 May 2013 16:42:57 -0400 Subject: [PATCH 2/9] VIVO-82 Split WebappDaoSetup into ContentModelSetup and ModelMaker setup. --- .../controller/jena/JenaIngestController.java | 4 +- ...ppDaoSetup.java => ContentModelSetup.java} | 74 ++++++------------- .../setup/JenaDataSourceSetupBase.java | 2 +- .../webapp/servlet/setup/ModelMakerSetup.java | 54 ++++++++++++++ .../WEB-INF/resources/startup_listeners.txt | 4 +- 5 files changed, 82 insertions(+), 56 deletions(-) rename webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/{WebappDaoSetup.java => ContentModelSetup.java} (91%) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ModelMakerSetup.java diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java index 6d1b2c346..ea0b70cb2 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java @@ -80,7 +80,7 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase; -import edu.cornell.mannlib.vitro.webapp.servlet.setup.WebappDaoSetup; +import edu.cornell.mannlib.vitro.webapp.servlet.setup.ContentModelSetup; 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.MergeResult; @@ -984,7 +984,7 @@ public class JenaIngestController extends BaseEditController { log.debug("Connecting to DB at "+jdbcUrl); StoreDesc storeDesc = new StoreDesc(LayoutType.LayoutTripleNodesHash,dbTypeObj) ; ServletContext ctx = vreq.getSession().getServletContext(); - DataSource bds = WebappDaoSetup.makeBasicDataSource( + DataSource bds = ContentModelSetup.makeBasicDataSource( driver, jdbcUrl, username, password, ctx); try { VitroJenaSDBModelMaker vsmm = new VitroJenaSDBModelMaker(storeDesc, bds); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/WebappDaoSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java similarity index 91% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/WebappDaoSetup.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java index 7b198a8f3..4917db06f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/WebappDaoSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java @@ -34,10 +34,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer; 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.RDFServiceModelMaker; import edu.cornell.mannlib.vitro.webapp.dao.jena.SpecialBulkUpdateHandlerGraph; -import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaModelMaker; -import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroModelSource; import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory; @@ -46,12 +43,12 @@ import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; import edu.cornell.mannlib.vitro.webapp.utils.jena.InitialJenaModelUtils; /** - * Primarily sets up webapp DAO factories. + * Sets up the content models, OntModelSelectors and webapp DAO factories. */ -public class WebappDaoSetup extends JenaDataSourceSetupBase +public class ContentModelSetup extends JenaDataSourceSetupBase implements javax.servlet.ServletContextListener { - private static final Log log = LogFactory.getLog(WebappDaoSetup.class); + private static final Log log = LogFactory.getLog(ContentModelSetup.class); @Override public void contextInitialized(ServletContextEvent sce) { @@ -127,12 +124,8 @@ public class WebappDaoSetup extends JenaDataSourceSetupBase ModelContext.setBaseOntModelSelector(baseOms, ctx); // assertions ModelContext.setInferenceOntModelSelector(inferenceOms, ctx); // inferences - - - log.info("Setting up DAO factories"); - ctx.setAttribute("jenaOntModel", unionFullModel); WebappDaoFactoryConfig config = new WebappDaoFactoryConfig(); @@ -150,18 +143,6 @@ public class WebappDaoSetup extends JenaDataSourceSetupBase log.info("Model makers set up"); ctx.setAttribute("defaultNamespace", getDefaultNamespace(ctx)); - - makeModelMakerFromConnectionProperties(TripleStoreType.RDB, ctx); - VitroJenaModelMaker vjmm = getVitroJenaModelMaker(); - setVitroJenaModelMaker(vjmm, ctx); - makeModelMakerFromConnectionProperties(TripleStoreType.SDB, ctx); - RDFServiceModelMaker vsmm = new RDFServiceModelMaker(rdfServiceFactory); - setVitroJenaSDBModelMaker(vsmm, ctx); - - //bdc34: I have no reason for vsmm vs vjmm. - //I don't know what are the implications of this choice. - setVitroModelSource( new VitroModelSource(vsmm,ctx), ctx); - } private OntModel createNamedModelFromDataset(Dataset dataset, String name) { @@ -210,6 +191,24 @@ public class WebappDaoSetup extends JenaDataSourceSetupBase } } + private void loadDataFromFilesystem(OntModel baseABoxModel, OntModel baseTBoxModel, OntModel applicationMetadataModel, + ServletContext ctx) { + Long startTime = System.currentTimeMillis(); + log.info("Initializing models from RDF files"); + + readOntologyFilesInPathSet(USER_ABOX_PATH, ctx, baseABoxModel); + readOntologyFilesInPathSet(USER_TBOX_PATH, ctx, baseTBoxModel); + readOntologyFilesInPathSet(USER_APPMETA_PATH, ctx, applicationMetadataModel); + + log.debug(((System.currentTimeMillis() - startTime) / 1000) + + " seconds to read RDF files "); + } + + private long secondsSince(long startTime) { + return (System.currentTimeMillis() - startTime) / 1000; + } + + /* ===================================================================== */ /** * If we find a "portal1" portal (and we should), its URI should use the @@ -258,8 +257,7 @@ public class WebappDaoSetup extends JenaDataSourceSetupBase return portals; } - private boolean noPortalForNamespace(List portals, - String expectedNamespace) { + private boolean noPortalForNamespace(List portals, String expectedNamespace) { for (Resource portal : portals) { if(expectedNamespace.equals(portal.getNameSpace())) { return false; @@ -271,44 +269,18 @@ public class WebappDaoSetup extends JenaDataSourceSetupBase private void renamePortal(Resource portal, String namespace, Model model) { model.enterCriticalSection(Lock.WRITE); try { - ResourceUtils.renameResource( - portal, namespace + portal.getLocalName()); + ResourceUtils.renameResource(portal, namespace + portal.getLocalName()); } finally { model.leaveCriticalSection(); } } - /* ===================================================================== */ - - private long secondsSince(long startTime) { - return (System.currentTimeMillis() - startTime) / 1000; - } - - private void loadDataFromFilesystem(OntModel baseABoxModel, OntModel baseTBoxModel, OntModel applicationMetadataModel, - ServletContext ctx) { - Long startTime = System.currentTimeMillis(); - log.info("Initializing models from RDF files"); - - readOntologyFilesInPathSet(USER_ABOX_PATH, ctx, baseABoxModel); - readOntologyFilesInPathSet(USER_TBOX_PATH, ctx, baseTBoxModel); - readOntologyFilesInPathSet(USER_APPMETA_PATH, ctx, applicationMetadataModel); - - log.debug(((System.currentTimeMillis() - startTime) / 1000) - + " seconds to read RDF files "); - } - - - /* ===================================================================== */ - @Override public void contextDestroyed(ServletContextEvent sce) { // Nothing to do. } - - - } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetupBase.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetupBase.java index fbe8e61f4..f56d75a3d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetupBase.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetupBase.java @@ -471,7 +471,7 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon { } else if (TripleStoreType.SDB.equals(type)) { StoreDesc storeDesc = new StoreDesc( LayoutType.LayoutTripleNodesHash, DatabaseType.fetch(dbtypeStr)); - DataSource bds = WebappDaoSetup.makeC3poDataSource( + DataSource bds = ContentModelSetup.makeC3poDataSource( getDbDriverClassName(ctx), jdbcUrl, username, password, ctx); // DataSource bds = WebappDaoSetup.makeBasicDataSource( // getDbDriverClassName(ctx), jdbcUrl, username, password, ctx); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ModelMakerSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ModelMakerSetup.java new file mode 100644 index 000000000..8ce03734b --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ModelMakerSetup.java @@ -0,0 +1,54 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.servlet.setup; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; + +import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceModelMaker; +import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaModelMaker; +import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroModelSource; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory; +import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; +import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; + +/** + * Sets up the content models, OntModelSelectors and webapp DAO factories. + */ +public class ModelMakerSetup extends JenaDataSourceSetupBase + implements javax.servlet.ServletContextListener { + + @Override + public void contextInitialized(ServletContextEvent sce) { + ServletContext ctx = sce.getServletContext(); + StartupStatus ss = StartupStatus.getBean(ctx); + + long begin = System.currentTimeMillis(); + + RDFServiceFactory rdfServiceFactory = RDFServiceUtils.getRDFServiceFactory(ctx); + makeModelMakerFromConnectionProperties(TripleStoreType.RDB, ctx); + VitroJenaModelMaker vjmm = getVitroJenaModelMaker(); + setVitroJenaModelMaker(vjmm, ctx); + makeModelMakerFromConnectionProperties(TripleStoreType.SDB, ctx); + RDFServiceModelMaker vsmm = new RDFServiceModelMaker(rdfServiceFactory); + setVitroJenaSDBModelMaker(vsmm, ctx); + + //bdc34: I have no reason for vsmm vs vjmm. + //I don't know what are the implications of this choice. + setVitroModelSource( new VitroModelSource(vsmm,ctx), ctx); + + ss.info(this, secondsSince(begin) + " seconds to set up models and DAO factories"); + } + + private long secondsSince(long startTime) { + return (System.currentTimeMillis() - startTime) / 1000; + } + + /* ===================================================================== */ + + @Override + public void contextDestroyed(ServletContextEvent sce) { + // Nothing to do. + } + } + diff --git a/webapp/web/WEB-INF/resources/startup_listeners.txt b/webapp/web/WEB-INF/resources/startup_listeners.txt index 251a26458..202508ebd 100644 --- a/webapp/web/WEB-INF/resources/startup_listeners.txt +++ b/webapp/web/WEB-INF/resources/startup_listeners.txt @@ -20,8 +20,8 @@ edu.cornell.mannlib.vitro.webapp.servlet.setup.RDFServiceSetup edu.cornell.mannlib.vitro.webapp.servlet.setup.ApplicationModelSetup edu.cornell.mannlib.vitro.webapp.servlet.setup.UserModelSetup - -edu.cornell.mannlib.vitro.webapp.servlet.setup.WebappDaoSetup +edu.cornell.mannlib.vitro.webapp.servlet.setup.ContentModelSetup +edu.cornell.mannlib.vitro.webapp.servlet.setup.ModelMakerSetup edu.cornell.mannlib.vitro.webapp.servlet.setup.UpdateKnowledgeBase From 4764751905ab0edf9934e802a43760b1db52dc8e Mon Sep 17 00:00:00 2001 From: j2blake Date: Thu, 16 May 2013 18:05:50 -0400 Subject: [PATCH 3/9] VIVO-82 Use ModelAccess to get or set the Display Model --- .../vitro/webapp/controller/VitroRequest.java | 10 +- .../vitro/webapp/dao/DisplayVocabulary.java | 3 - .../mannlib/vitro/webapp/dao/ModelAccess.java | 315 ++++++++++++++++++ .../vitro/webapp/dao/jena/ModelContext.java | 6 - .../webapp/dao/jena/VitroModelSource.java | 3 +- .../DefaultObjectPropertyFormGenerator.java | 16 +- .../webapp/filters/VitroRequestPrep.java | 29 +- .../vitro/webapp/search/solr/SolrSetup.java | 10 +- .../servlet/setup/ApplicationModelSetup.java | 7 +- .../servlet/setup/ContentModelSetup.java | 4 +- .../servlet/setup/UpdateKnowledgeBase.java | 3 +- ...ApplicationConfigurationOntologyUtils.java | 8 +- .../utils/dataGetter/DataGetterBase.java | 8 +- 13 files changed, 351 insertions(+), 71 deletions(-) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroRequest.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroRequest.java index 53587eae2..5085e2a68 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroRequest.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroRequest.java @@ -2,7 +2,6 @@ package edu.cornell.mannlib.vitro.webapp.controller; -import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL; import java.util.Map; @@ -17,6 +16,7 @@ import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.query.Dataset; import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDao; import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector; @@ -215,13 +215,7 @@ public class VitroRequest extends HttpServletRequestWrapper { //Get the display and editing configuration model public OntModel getDisplayModel(){ - Object value = _req.getAttribute(DISPLAY_ONT_MODEL); - if (value instanceof OntModel) { - return (OntModel) value; - } else { - log.error("No display model on the VitroRequest. Expecting an OntModel but found " + value); - return null; - } + return ModelAccess.on(_req).getDisplayModel(); } /** diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DisplayVocabulary.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DisplayVocabulary.java index 5d5defc36..fc89134e7 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DisplayVocabulary.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DisplayVocabulary.java @@ -119,9 +119,6 @@ public class DisplayVocabulary { public static final String CONTEXT_DISPLAY_TBOX = "displayOntModelTBOX"; public static final String CONTEXT_DISPLAY_DISPLAY = "displayOntModelDisplayModel"; - /** Key for display model in request, session or context attributes */ - public static final String DISPLAY_ONT_MODEL = "displayOntModel"; - //URL for menu management public static final String PROCESS_MENU_MANAGEMENT_URL = "/menuManagementEdit"; public static final String REORDER_MENU_URL = PROCESS_MENU_MANAGEMENT_URL + "?cmd=Reorder&" + SWITCH_TO_DISPLAY_MODEL + "=true"; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java new file mode 100644 index 000000000..4537db358 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java @@ -0,0 +1,315 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.dao; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import com.hp.hpl.jena.ontology.OntModel; + +/** + * Hierarchical storage for models. TODO + */ +public class ModelAccess { + /** These attributes should only be accessed through this class. */ + private static final String ATTRIBUTE_NAME = ModelAccess.class.getName(); + + public enum ModelID { + APPLICATION_METADATA, + + USER_ACCOUNTS, + + DISPLAY, DISPLAY_DISPLAY, DISPLAY_TBOX, + + BASE_ABOX, BASE_TBOX, BASE_FULL, + + INFERRED_ABOX, INFERRED_TBOX, INFERRED_FULL, + + UNION_ABOX, UNION_TBOX, UNION_FULL + } + + // ---------------------------------------------------------------------- + // Factory methods + // ---------------------------------------------------------------------- + + public static ModelAccess on(HttpServletRequest req) { + Object o = req.getAttribute(ATTRIBUTE_NAME); + if (o instanceof ModelAccess) { + return (ModelAccess) o; + } else { + ModelAccess parent = on(req.getSession()); + ModelAccess ma = new ModelAccess(parent); + req.setAttribute(ATTRIBUTE_NAME, ma); + return ma; + } + } + + public static ModelAccess on(HttpSession session) { + Object o = session.getAttribute(ATTRIBUTE_NAME); + if (o instanceof ModelAccess) { + return (ModelAccess) o; + } else { + ModelAccess parent = on(session.getServletContext()); + ModelAccess ma = new ModelAccess(parent); + session.setAttribute(ATTRIBUTE_NAME, ma); + return ma; + } + } + + public static ModelAccess on(ServletContext ctx) { + Object o = ctx.getAttribute(ATTRIBUTE_NAME); + if (o instanceof ModelAccess) { + return (ModelAccess) o; + } else { + ModelAccess ma = new ModelAccess(null); + ctx.setAttribute(ATTRIBUTE_NAME, ma); + return ma; + } + } + + // ---------------------------------------------------------------------- + // Instance methods + // ---------------------------------------------------------------------- + + private final ModelAccess parent; + private final Map modelMap = new HashMap<>(); + + public ModelAccess(ModelAccess parent) { + this.parent = parent; + } + + public void setDisplayModel(OntModel m) { + setOntModel(ModelID.DISPLAY, m); + } + + public OntModel getDisplayModel() { + return getOntModel(ModelID.DISPLAY); + } + + // /** Is this the same as Assertions model? */ + // // public OntModel getBaseOntModel() { + // // throw new RuntimeException( + // // "ModelAccess.getBaseOntModel not implemented."); + // // } + // + // public OntModel getAssertionsOntModel() { + // throw new RuntimeException( + // "ModelAccess.getAssertionsOntModel not implemented."); + // } + // + // public void setUserAccountsModel(OntModel m) { + // setOntModel(ModelID.USER_ACCOUNTS, m); + // } + // + // public OntModel getUserAccountsModel() { + // return getOntModel(ModelID.USER_ACCOUNTS); + // } + // + // public OntModel getDisplayTboxOntModel() { + // throw new RuntimeException( + // "ModelAccess.getDisplayTboxOntModel not implemented."); + // } + // + // public OntModel getDisplayModelDisplayOntModel() { + // throw new RuntimeException( + // "ModelAccess.getDisplayModelDisplayOntModel not implemented."); + // } + // + // public OntModelSelector getOntModelSelector() { + // return getUnionOntModelSelector(); + // } + // + // public OntModelSelector getBaseOntModelSelector() { + // return new FacadeOntModelSelector(this, ModelID.BASE_ABOX, + // ModelID.BASE_TBOX, ModelID.BASE_FULL); + // } + // + // public OntModelSelector getInferenceOntModelSelector() { + // return new FacadeOntModelSelector(this, ModelID.INFERRED_ABOX, + // ModelID.INFERRED_TBOX, ModelID.INFERRED_FULL); + // } + // + // public OntModelSelector getUnionOntModelSelector() { + // return new FacadeOntModelSelector(this, ModelID.UNION_ABOX, + // ModelID.UNION_TBOX, ModelID.UNION_FULL); + // } + // + // private static class FacadeOntModelSelector implements OntModelSelector { + // private final ModelAccess parent; + // private final ModelID aboxID; + // private final ModelID tboxID; + // private final ModelID fullID; + // + // public FacadeOntModelSelector(ModelAccess parent, ModelID aboxID, + // ModelID tboxID, ModelID fullID) { + // this.parent = parent; + // this.aboxID = aboxID; + // this.tboxID = tboxID; + // this.fullID = fullID; + // } + // + // @Override + // public OntModel getABoxModel() { + // return parent.getOntModel(aboxID); + // } + // + // @Override + // public OntModel getTBoxModel() { + // return parent.getOntModel(tboxID); + // } + // + // @Override + // public OntModel getTBoxModel(String ontologyURI) { + // return parent.getOntModel(tboxID); + // } + // + // @Override + // public OntModel getFullModel() { + // return parent.getOntModel(fullID); + // } + // + // @Override + // public OntModel getApplicationMetadataModel() { + // return parent.getOntModel(ModelID.APPLICATION_METADATA); + // } + // + // @Override + // public OntModel getUserAccountsModel() { + // return parent.getOntModel(ModelID.USER_ACCOUNTS); + // } + // + // @Override + // public OntModel getDisplayModel() { + // return parent.getOntModel(ModelID.DISPLAY); + // } + // } + + /** + *
+	 * From ModelContext
+	 * 
+	 * 	public static OntModelSelector getOntModelSelector(ServletContext ctx) {
+	 * 		return (OntModelSelector) ctx.getAttribute(ONT_MODEL_SELECTOR);
+	 * 	}
+	 * 	
+	 * 	public static void setOntModelSelector(OntModelSelector oms, ServletContext ctx) {
+	 * 		ctx.setAttribute(ONT_MODEL_SELECTOR, oms); 
+	 * 	}
+	 * 	
+	 * 	public static OntModelSelector getUnionOntModelSelector(ServletContext ctx) {
+	 * 		return (OntModelSelector) ctx.getAttribute(UNION_ONT_MODEL_SELECTOR);
+	 * 	}
+	 * 	
+	 * 	public static void setUnionOntModelSelector(OntModelSelector oms, ServletContext ctx) {
+	 * 		ctx.setAttribute(UNION_ONT_MODEL_SELECTOR, oms); 
+	 * 	}
+	 *  	
+	 * 	public static OntModelSelector getBaseOntModelSelector(ServletContext ctx) {
+	 * 		return (OntModelSelector) ctx.getAttribute(BASE_ONT_MODEL_SELECTOR);
+	 * 	}
+	 * 	
+	 * 	public static void setBaseOntModelSelector(OntModelSelector oms, ServletContext ctx) {
+	 * 		ctx.setAttribute(BASE_ONT_MODEL_SELECTOR, oms); 
+	 * 	}
+	 * 	
+	 * 	public static OntModelSelector getInferenceOntModelSelector(ServletContext ctx) {
+	 * 		return (OntModelSelector) ctx.getAttribute(INFERENCE_ONT_MODEL_SELECTOR);
+	 * 	}
+	 * 	
+	 * 	public static void setInferenceOntModelSelector(OntModelSelector oms, ServletContext ctx) {
+	 * 		ctx.setAttribute(INFERENCE_ONT_MODEL_SELECTOR, oms); 
+	 * 	}
+	 * 	
+	 * 	public static OntModel getJenaOntModel(ServletContext ctx) {
+	 * 		return (OntModel) ctx.getAttribute(JENA_ONT_MODEL);
+	 * 	}
+	 * 	
+	 * 	public static void setJenaOntModel(OntModel ontModel, ServletContext ctx) {
+	 * 		ctx.setAttribute(JENA_ONT_MODEL, ontModel);
+	 * 	}
+	 * 	
+	 * 	public static OntModel getBaseOntModel(ServletContext ctx) {
+	 * 		return (OntModel) ctx.getAttribute(BASE_ONT_MODEL);
+	 * 	}
+	 * 	
+	 * 	public static void setBaseOntModel(OntModel ontModel, ServletContext ctx) {
+	 * 		ctx.setAttribute(BASE_ONT_MODEL, ontModel);
+	 * 	}
+	 * 	
+	 * 	public static OntModel getInferenceOntModel(ServletContext ctx) {
+	 * 		return (OntModel) ctx.getAttribute(INFERENCE_ONT_MODEL);
+	 * 	}
+	 * 	
+	 * 	public static void setInferenceOntModel(OntModel ontModel, ServletContext ctx) {
+	 * 		ctx.setAttribute(INFERENCE_ONT_MODEL, ontModel);
+	 * 	}
+	 * 
+	 * 
+ */ + /** + *
+	 * VitroRequest.getAssertionsWebappDaoFactory()
+	 * VitroRequest.getDeductionsWebappDaoFactory()
+	 * VitroRequest.getFullWebappDaoFactory()
+	 * VitroRequest.getJenaOntModel()
+	 * VitroRequest.getRDFService()
+	 * VitroRequest.getUnfilteredRDFService()
+	 * VitroRequest.getWebappDaoFactory()
+	 * VitroRequest.getWriteModel()
+	 * ModelContext.getBaseOntModelSelector()
+	 * ModelContext.getInferenceOntModel()
+	 * ModelContext.getInferenceOntModelSelector()
+	 * ModelContext.getJenaOntModel()
+	 * ModelContext.getOntModelSelector()
+	 * ModelContext.getUnionOntModelSelector()
+	 * OntModelSelector.getAboxModel
+	 * OntModelSelector.getApplicationMetadataModel()
+	 * OntModelSelector.getFullModel()
+	 * OntModelSelector.getTBoxModel()
+	 * OntModelSelector.getTBoxModel(ontologyURI)
+	 * OntModelSelector.getUserAccountsModel()
+	 * VitroModelSource.getModel(URL)
+	 * VitroModelSource.getModel(URL, loadIfAbsent)
+	 * VitroModelSource.openModel(name)
+	 * VitroModelSource.openModelIfPresent(string)
+	 * ServletContext.getAttribute("assertionsWebappDaoFactory")
+	 * ServletContext.getAttribute("baseOntModelSelector")
+	 * ServletContext.getAttribute("jenaOntModel")
+	 * ServletContext.getAttribute("jenaPersistentOntModel")
+	 * ServletContext.getAttribute("pelletOntModel")
+	 * ServletContext.getAttribute("webappDaoFactory")
+	 * VitroJenaModelMaker
+	 * VitroJenaSpecialModelMaker
+	 * JenaDataSourceSetupBase.getApplicationDataSource(ctx)
+	 * JenaDataSourceSetupBase.getStartupDataset()
+	 * HttpSession.getAttribute("jenaAuditModel")
+	 * HttpSession.getAttribute("jenaOntModel")
+	 * ServletRequest.getAttribute("jenaOntModel")
+	 * 
+ */ + + public void setOntModel(ModelID id, OntModel ontModel) { + String key = id.toString(); + if (ontModel == null) { + modelMap.remove(key); + } else { + modelMap.put(key, ontModel); + } + } + + public OntModel getOntModel(ModelID id) { + String key = id.toString(); + if (modelMap.containsKey(key)) { + return modelMap.get(key); + } else if (parent != null) { + return parent.getOntModel(id); + } else { + return null; + } + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ModelContext.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ModelContext.java index 57d835a4c..4b9036a1f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ModelContext.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ModelContext.java @@ -113,10 +113,4 @@ public class ModelContext { } - public static OntModel getDisplayModel(ServletContext ctx){ - return(OntModel) ctx.getAttribute( DisplayVocabulary.DISPLAY_ONT_MODEL ); - } - public static void setDisplayModel(OntModel ontModel, ServletContext ctx){ - ctx.setAttribute(DisplayVocabulary.DISPLAY_ONT_MODEL,ontModel); - } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroModelSource.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroModelSource.java index 2366777cb..183b8860c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroModelSource.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroModelSource.java @@ -10,6 +10,7 @@ import com.hp.hpl.jena.rdf.model.ModelReader; import com.hp.hpl.jena.rdf.model.ModelSource; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; /** * ModelSource that will handle specially named Vitro models such @@ -110,7 +111,7 @@ public class VitroModelSource implements ModelSource { case TBOX: return (Model) context.getAttribute("tboxmodel???"); case DISPLAY: - return (Model) context.getAttribute(DisplayVocabulary.DISPLAY_ONT_MODEL ); + return ModelAccess.on(context).getDisplayModel(); case DISPLAY_TBOX: return (Model) context.getAttribute(DisplayVocabulary.CONTEXT_DISPLAY_TBOX); case DISPLAY_DISPLAY: diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java index a6ea9e704..e253cd13f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java @@ -31,6 +31,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils; @@ -408,16 +409,11 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene if(isSelectFromExisting(vreq)) { // set ProhibitedFromSearch object so picklist doesn't show // individuals from classes that should be hidden from list views - //TODO: Check how model is retrieved - OntModel displayOntModel = - (OntModel) session.getServletContext() - .getAttribute(DISPLAY_ONT_MODEL); - if (displayOntModel != null) { - ProhibitedFromSearch pfs = new ProhibitedFromSearch( - DisplayVocabulary.SEARCH_INDEX_URI, displayOntModel); - if( editConfig != null ) - editConfig.setProhibitedFromSearch(pfs); - } + OntModel displayOntModel = ModelAccess.on(session).getDisplayModel(); + ProhibitedFromSearch pfs = new ProhibitedFromSearch( + DisplayVocabulary.SEARCH_INDEX_URI, displayOntModel); + if( editConfig != null ) + editConfig.setProhibitedFromSearch(pfs); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java index 3f58cd191..b1217ab08 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java @@ -4,14 +4,12 @@ package edu.cornell.mannlib.vitro.webapp.filters; import static edu.cornell.mannlib.vitro.webapp.controller.VitroRequest.SPECIAL_WRITE_MODEL; import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.CONTEXT_DISPLAY_TBOX; -import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL; import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.SWITCH_TO_DISPLAY_MODEL; import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.USE_DISPLAY_MODEL_PARAM; import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.USE_MODEL_PARAM; import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.USE_TBOX_MODEL_PARAM; import java.io.IOException; -import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -42,20 +40,18 @@ import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.FilterFactory; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.HideFromDisplayByPolicyFilter; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; -import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph; import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroModelSource; import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena; import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB; -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.impl.RDFServiceUtils; -import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel; import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase; /** @@ -138,21 +134,14 @@ public class VitroRequestPrep implements Filter { log.debug("Found a WebappDaoFactory in the session and using it for this request"); } - // Set up the DisplayModel, with language filtering if appropriate. - OntModel displayModel; - Object displayModelObject = req.getSession().getAttribute(DISPLAY_ONT_MODEL); - if (displayModelObject instanceof OntModel) { - displayModel = (OntModel) displayModelObject; - } else { - displayModel = (OntModel) _context.getAttribute(DISPLAY_ONT_MODEL); - } - - if (Boolean.valueOf(ConfigurationProperties.getBean(vreq).getProperty( - "RDFService.languageFilter", "true"))) { - displayModel = LanguageFilteringUtils.wrapOntModelInALanguageFilter(displayModel, req); + // Set up the DisplayModel with language filtering, if appropriate. + ConfigurationProperties props = ConfigurationProperties.getBean(req); + Boolean languageFilteringEnabled = Boolean.valueOf(props.getProperty("RDFService.languageFilter", "true")); + if (languageFilteringEnabled) { + OntModel displayModel = ModelAccess.on(req.getSession()).getDisplayModel(); + OntModel filteredDisplayModel = LanguageFilteringUtils.wrapOntModelInALanguageFilter(displayModel, req); + ModelAccess.on(req).setDisplayModel(filteredDisplayModel); } - vreq.setAttribute(DISPLAY_ONT_MODEL, displayModel); - //Do model switching and replace the WebappDaoFactory with //a different version if requested by parameters @@ -245,7 +234,7 @@ public class VitroRequestPrep implements Filter { // If they asked for the display model, give it to them. if (isParameterPresent(vreq, SWITCH_TO_DISPLAY_MODEL)) { - OntModel mainOntModel = (OntModel)_context.getAttribute( DISPLAY_ONT_MODEL); + OntModel mainOntModel = ModelAccess.on(_context).getDisplayModel(); OntModel tboxOntModel = (OntModel) _context.getAttribute(CONTEXT_DISPLAY_TBOX); setSpecialWriteModel(vreq, mainOntModel); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java index 568f3713e..bbdb2d02e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java @@ -2,7 +2,6 @@ package edu.cornell.mannlib.vitro.webapp.search.solr; -import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; @@ -11,19 +10,16 @@ import java.util.List; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; import org.apache.solr.client.solrj.impl.XMLResponseParser; import com.hp.hpl.jena.ontology.OntModel; -import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.vocabulary.OWL; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; -import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering; @@ -31,8 +27,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; -import edu.cornell.mannlib.vitro.webapp.search.beans.FileBasedProhibitedFromSearch; -import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.beans.StatementToURIsToUpdate; import edu.cornell.mannlib.vitro.webapp.search.indexing.AdditionalURIsForContextNodes; import edu.cornell.mannlib.vitro.webapp.search.indexing.AdditionalURIsForDataProperties; @@ -120,7 +114,7 @@ public class SolrSetup implements javax.servlet.ServletContextListener{ /* set up the individual to solr doc translation */ OntModel jenaOntModel = ModelContext.getJenaOntModel(context); - Model displayModel = ModelContext.getDisplayModel(context); + OntModel displayModel = ModelAccess.on(context).getDisplayModel(); /* try to get context attribute DocumentModifiers * and use that as the start of the list of DocumentModifier diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ApplicationModelSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ApplicationModelSetup.java index 15fc6a49f..6e7269907 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ApplicationModelSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ApplicationModelSetup.java @@ -9,7 +9,6 @@ import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.sql.DataSource; -import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.joda.time.DateTime; @@ -23,7 +22,7 @@ import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; -import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; @@ -63,8 +62,8 @@ implements ServletContextListener { } OntModel displayModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC); displayModel.add(displayDbModel); - displayModel.getBaseModel().register(new ModelSynchronizer(displayDbModel)); - ModelContext.setDisplayModel(displayModel, ctx); + displayModel.getBaseModel().register(new ModelSynchronizer(displayDbModel)); + ModelAccess.on(ctx).setDisplayModel(displayModel); //at each startup load all RDF files from directory to sub-models of display model initializeDisplayLoadedAtStartup(ctx, displayModel); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java index 4917db06f..7fce186ef 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java @@ -2,7 +2,6 @@ package edu.cornell.mannlib.vitro.webapp.servlet.setup; -import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL; import static edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode.ASSERTIONS_ONLY; import static edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode.INFERENCES_ONLY; @@ -28,6 +27,7 @@ import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.util.ResourceUtils; import com.hp.hpl.jena.vocabulary.RDF; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; @@ -72,7 +72,7 @@ public class ContentModelSetup extends JenaDataSourceSetupBase } OntModel userAccountsModel = ontModelFromContextAttribute(ctx, "userAccountsOntModel"); - OntModel displayModel = ontModelFromContextAttribute(ctx,DISPLAY_ONT_MODEL); + OntModel displayModel = ModelAccess.on(ctx).getDisplayModel(); OntModel baseABoxModel = createNamedModelFromDataset(dataset, JENA_DB_MODEL); OntModel inferenceABoxModel = createNamedModelFromDataset(dataset, JENA_INF_MODEL); OntModel baseTBoxModel = createdMemoryMappedModel(dataset, JENA_TBOX_ASSERTIONS_MODEL, "tbox assertions"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java index dcfc12e3e..704931866 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateKnowledgeBase.java @@ -32,6 +32,7 @@ import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDFS; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; import edu.cornell.mannlib.vitro.webapp.ontology.update.KnowledgeBaseUpdater; @@ -106,7 +107,7 @@ public class UpdateKnowledgeBase implements ServletContextListener { settings.setUnionOntModelSelector(ModelContext.getUnionOntModelSelector(ctx)); boolean tryMigrateDisplay = true; try { - settings.setDisplayModel(ModelContext.getDisplayModel(ctx)); + settings.setDisplayModel(ModelAccess.on(ctx).getDisplayModel()); OntModel oldTBoxModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_MODEL_DIR)); settings.setOldTBoxModel(oldTBoxModel); OntModel newTBoxModel = loadModelFromDirectory(ctx.getRealPath(NEW_TBOX_MODEL_DIR)); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/ApplicationConfigurationOntologyUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/ApplicationConfigurationOntologyUtils.java index 5a64e2190..bf353c5b1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/ApplicationConfigurationOntologyUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/ApplicationConfigurationOntologyUtils.java @@ -5,6 +5,8 @@ package edu.cornell.mannlib.vitro.webapp.utils; import java.util.ArrayList; import java.util.List; +import javax.servlet.ServletContext; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -21,6 +23,7 @@ import com.hp.hpl.jena.rdf.model.Resource; import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; public class ApplicationConfigurationOntologyUtils { @@ -28,8 +31,9 @@ public class ApplicationConfigurationOntologyUtils { private static final Log log = LogFactory.getLog(ApplicationConfigurationOntologyUtils.class); public static List getAdditionalFauxSubpropertiesForList(List propList, VitroRequest vreq) { - Model displayModel = ModelContext.getDisplayModel(vreq.getSession().getServletContext()); - Model tboxModel = ModelContext.getUnionOntModelSelector(vreq.getSession().getServletContext()).getTBoxModel(); + ServletContext ctx = vreq.getSession().getServletContext(); + Model displayModel = ModelAccess.on(ctx).getDisplayModel(); + Model tboxModel = ModelContext.getUnionOntModelSelector(ctx).getTBoxModel(); return getAdditionalFauxSubpropertiesForList(propList, displayModel, tboxModel); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/DataGetterBase.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/DataGetterBase.java index 51d5b9644..a57025796 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/DataGetterBase.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/dataGetter/DataGetterBase.java @@ -1,8 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ package edu.cornell.mannlib.vitro.webapp.utils.dataGetter; -import java.util.Map; - import javax.servlet.ServletContext; import org.apache.commons.lang.StringUtils; @@ -11,9 +9,7 @@ import com.hp.hpl.jena.rdf.model.Model; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.jena.JenaIngestController; -import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; -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.ModelAccess; public abstract class DataGetterBase implements DataGetter { @@ -29,7 +25,7 @@ public abstract class DataGetterBase implements DataGetter { }else if( REQUEST_JENA_ONT_MODEL.equals(modelName)){ return vreq.getJenaOntModel(); }else if( CONTEXT_DISPLAY_MODEL.equals(modelName)){ - return (Model)context.getAttribute( DisplayVocabulary.DISPLAY_ONT_MODEL); + return ModelAccess.on(context).getDisplayModel(); }else if( ! StringUtils.isEmpty( modelName)){ Model model = JenaIngestController.getModel( modelName, vreq, context); if( model == null ) From 1c95d4e4a9a599805d872ad985eb209f40503614 Mon Sep 17 00:00:00 2001 From: j2blake Date: Thu, 16 May 2013 18:11:13 -0400 Subject: [PATCH 4/9] VIVO-82 Use ModelAccess to get or set the UserAccounts model --- .../mannlib/vitro/webapp/dao/ModelAccess.java | 16 ++++++++-------- .../webapp/servlet/setup/ContentModelSetup.java | 2 +- .../webapp/servlet/setup/UserModelSetup.java | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java index 4537db358..552e91f3a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java @@ -82,6 +82,14 @@ public class ModelAccess { this.parent = parent; } + public void setUserAccountsModel(OntModel m) { + setOntModel(ModelID.USER_ACCOUNTS, m); + } + + public OntModel getUserAccountsModel() { + return getOntModel(ModelID.USER_ACCOUNTS); + } + public void setDisplayModel(OntModel m) { setOntModel(ModelID.DISPLAY, m); } @@ -101,14 +109,6 @@ public class ModelAccess { // "ModelAccess.getAssertionsOntModel not implemented."); // } // - // public void setUserAccountsModel(OntModel m) { - // setOntModel(ModelID.USER_ACCOUNTS, m); - // } - // - // public OntModel getUserAccountsModel() { - // return getOntModel(ModelID.USER_ACCOUNTS); - // } - // // public OntModel getDisplayTboxOntModel() { // throw new RuntimeException( // "ModelAccess.getDisplayTboxOntModel not implemented."); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java index 7fce186ef..ae2a3391f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java @@ -71,7 +71,7 @@ public class ContentModelSetup extends JenaDataSourceSetupBase JenaDataSourceSetupBase.thisIsFirstStartup(); } - OntModel userAccountsModel = ontModelFromContextAttribute(ctx, "userAccountsOntModel"); + OntModel userAccountsModel = ModelAccess.on(ctx).getUserAccountsModel(); OntModel displayModel = ModelAccess.on(ctx).getDisplayModel(); OntModel baseABoxModel = createNamedModelFromDataset(dataset, JENA_DB_MODEL); OntModel inferenceABoxModel = createNamedModelFromDataset(dataset, JENA_INF_MODEL); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UserModelSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UserModelSetup.java index 3d1a54d6f..47b51a5a3 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UserModelSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UserModelSetup.java @@ -6,7 +6,6 @@ import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.sql.DataSource; -import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -14,6 +13,7 @@ import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; @@ -65,7 +65,7 @@ public class UserModelSetup extends JenaDataSourceSetupBase userAccountsModel.add(userAccountsDbModel); userAccountsModel.getBaseModel().register( new ModelSynchronizer(userAccountsDbModel)); - ctx.setAttribute("userAccountsOntModel", userAccountsModel); + ModelAccess.on(ctx).setUserAccountsModel(userAccountsModel); } catch (Throwable t) { log.error("Unable to load user accounts model from DB", t); From 0a15a6df7d0f794c830dccad81bcfa8c839d8ce4 Mon Sep 17 00:00:00 2001 From: j2blake Date: Fri, 17 May 2013 11:41:47 -0400 Subject: [PATCH 5/9] VIVO-82 Use ModelAccess to get or set the JenaOntModel (Union Full model) --- .../vedit/controller/BaseEditController.java | 12 +++++------ .../auth/identifier/common/IsBlacklisted.java | 5 +++-- .../bean/PropertyRestrictionListener.java | 3 ++- .../bean/PropertyRestrictionPolicyHelper.java | 3 ++- .../FedoraDatastreamController.java | 5 +++-- .../webapp/controller/OntologyController.java | 8 ++----- .../vitro/webapp/controller/VitroRequest.java | 13 +++--------- .../webapp/controller/edit/Authenticate.java | 12 ++--------- .../NamespacePrefixOperationController.java | 3 ++- .../jena/NamespacesListingController.java | 3 ++- .../jena/RestrictionsListingController.java | 5 +++-- .../controller/jena/JenaAdminActions.java | 13 ++++++------ .../controller/jena/JenaExportController.java | 1 - .../controller/jena/JenaIngestController.java | 17 ++++++--------- .../mannlib/vitro/webapp/dao/ModelAccess.java | 21 ++++++++----------- .../vitro/webapp/dao/jena/JenaBaseDao.java | 1 - .../vitro/webapp/dao/jena/ModelContext.java | 10 --------- .../webapp/dao/jena/VClassGroupCache.java | 3 ++- .../webapp/dao/jena/VitroJenaModelMaker.java | 10 ++------- .../dao/jena/VitroJenaSpecialModelMaker.java | 11 +++------- .../webapp/dao/jena/VitroModelSource.java | 2 +- .../VTwo/EditConfigurationUtils.java | 5 +++-- .../BaseEditConfigurationGenerator.java | 8 ++----- ...aultAddMissingIndividualFormGenerator.java | 4 +++- .../DefaultObjectPropertyFormGenerator.java | 2 +- .../generators/ManagePageGenerator.java | 8 ++++--- .../NewIndividualFormGenerator.java | 5 +++-- .../generators/RDFSLabelGenerator.java | 4 +++- .../webapp/filters/VitroRequestPrep.java | 3 ++- .../vitro/webapp/search/solr/SolrSetup.java | 2 +- .../servlet/setup/ContentModelSetup.java | 5 +++-- .../servlet/setup/PropertyMaskingSetup.java | 4 ++-- 32 files changed, 88 insertions(+), 123 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vedit/controller/BaseEditController.java b/webapp/src/edu/cornell/mannlib/vedit/controller/BaseEditController.java index b99743132..a62429c70 100644 --- a/webapp/src/edu/cornell/mannlib/vedit/controller/BaseEditController.java +++ b/webapp/src/edu/cornell/mannlib/vedit/controller/BaseEditController.java @@ -25,6 +25,7 @@ import edu.cornell.mannlib.vedit.util.FormUtils; import edu.cornell.mannlib.vitro.webapp.controller.Controllers; import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; @@ -153,14 +154,13 @@ public class BaseEditController extends VitroHttpServlet { } } - protected String MODEL_ATTR_NAME = "jenaOntModel"; - protected OntModel getOntModel( HttpServletRequest request, ServletContext ctx ) { - + + // TODO: JB - This method gets the UNION FULL model from the session, if there is one, + // TODO and the BASE_TBOX model otherwise. OntModel ontModel = null; - - try { - ontModel = (OntModel) request.getSession().getAttribute(MODEL_ATTR_NAME); + try { + ontModel = ModelAccess.on(request.getSession()).getJenaOntModel(); } catch (Exception e) { // ignoring any problems here - we're not really expecting // this attribute to be populated anyway diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/IsBlacklisted.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/IsBlacklisted.java index 21ecf1741..ea00f16d7 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/IsBlacklisted.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/identifier/common/IsBlacklisted.java @@ -16,18 +16,19 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.RDFNode; import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; /** * The current user is blacklisted for this reason. @@ -152,7 +153,7 @@ public class IsBlacklisted extends AbstractCommonIdentifier implements return NOT_BLACKLISTED; } - Model model = (Model) context.getAttribute("jenaOntModel"); + OntModel model = ModelAccess.on(context).getJenaOntModel(); queryString = queryString.replaceAll("\\?individualURI", "<" + ind.getURI() + ">"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionListener.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionListener.java index 6afeb27b0..e617a6f53 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionListener.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionListener.java @@ -13,6 +13,7 @@ import edu.cornell.mannlib.vedit.beans.EditProcessObject; import edu.cornell.mannlib.vedit.listener.ChangeListener; import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel; import edu.cornell.mannlib.vitro.webapp.beans.Property; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; /** * Add this ChangeListener to your EditProcessObject when modifying the @@ -90,7 +91,7 @@ public class PropertyRestrictionListener implements ChangeListener { } private void createAndSetBean() { - OntModel model = (OntModel) ctx.getAttribute("jenaOntModel"); + OntModel model = ModelAccess.on(ctx).getJenaOntModel(); PropertyRestrictionPolicyHelper bean = PropertyRestrictionPolicyHelper .createBean(model); PropertyRestrictionPolicyHelper.setBean(ctx, bean); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelper.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelper.java index 68ee18b04..f6bf31603 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelper.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/auth/policy/bean/PropertyRestrictionPolicyHelper.java @@ -26,6 +26,7 @@ import com.hp.hpl.jena.rdf.model.impl.Util; import com.hp.hpl.jena.shared.Lock; import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; @@ -344,7 +345,7 @@ public class PropertyRestrictionPolicyHelper { StartupStatus ss = StartupStatus.getBean(ctx); try { - OntModel model = (OntModel) ctx.getAttribute("jenaOntModel"); + OntModel model = ModelAccess.on(ctx).getJenaOntModel(); if (model == null) { throw new NullPointerException( "jenaOntModel has not been initialized."); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/FedoraDatastreamController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/FedoraDatastreamController.java index db59e7174..93def6de3 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/FedoraDatastreamController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/FedoraDatastreamController.java @@ -42,6 +42,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServletRequest; @@ -101,7 +102,7 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons log.debug("In doGet"); VitroRequest vreq = new VitroRequest(req); - OntModel sessionOntModel = (OntModel)vreq.getSession().getAttribute("jenaOntModel"); + OntModel sessionOntModel = ModelAccess.on(vreq.getSession()).getJenaOntModel(); synchronized (FedoraDatastreamController.class) { if( fedoraUrl == null ){ @@ -231,7 +232,7 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons } //check if fedora is on line - OntModel sessionOntModel = (OntModel)rawRequest.getSession().getAttribute("jenaOntModel"); + OntModel sessionOntModel = ModelAccess.on(rawRequest.getSession()).getJenaOntModel(); synchronized (FedoraDatastreamController.class) { if( fedoraUrl == null ){ setup( sessionOntModel, getServletContext() ); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/OntologyController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/OntologyController.java index 6d85141e2..0e961c262 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/OntologyController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/OntologyController.java @@ -27,6 +27,7 @@ import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.shared.Lock; import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaOutputUtils; import edu.cornell.mannlib.vitro.webapp.web.ContentType; @@ -127,12 +128,7 @@ public class OntologyController extends VitroHttpServlet{ String url = ontology; - OntModel ontModel = null; - HttpSession session = vreq.getSession(false); - if( session != null ) - ontModel =(OntModel)session.getAttribute("jenaOntModel"); - if( ontModel == null) - ontModel = (OntModel)getServletContext().getAttribute("jenaOntModel"); + OntModel ontModel = ModelAccess.on(vreq.getSession()).getJenaOntModel(); boolean found = false; Model newModel = ModelFactory.createDefaultModel(); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroRequest.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroRequest.java index 5085e2a68..9bb1d583d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroRequest.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroRequest.java @@ -17,6 +17,7 @@ import com.hp.hpl.jena.query.Dataset; import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean; 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.jena.JenaBaseDao; import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector; @@ -107,7 +108,7 @@ public class VitroRequest extends HttpServletRequestWrapper { } public void setJenaOntModel(OntModel ontModel) { - setAttribute("jenaOntModel", ontModel); + ModelAccess.on(this).setJenaOntModel(ontModel); } public void setOntModelSelector(OntModelSelector oms) { @@ -176,15 +177,7 @@ public class VitroRequest extends HttpServletRequestWrapper { public OntModel getJenaOntModel() { - Object ontModel = getAttribute("jenaOntModel"); - if (ontModel instanceof OntModel) { - return (OntModel) ontModel; - } - OntModel jenaOntModel = (OntModel)_req.getSession().getAttribute( JenaBaseDao.JENA_ONT_MODEL_ATTRIBUTE_NAME ); - if ( jenaOntModel == null ) { - jenaOntModel = (OntModel)_req.getSession().getServletContext().getAttribute( JenaBaseDao.JENA_ONT_MODEL_ATTRIBUTE_NAME ); - } - return jenaOntModel; + return ModelAccess.on(this).getJenaOntModel(); } public OntModelSelector getOntModelSelector() { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Authenticate.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Authenticate.java index df1e5bbca..46af53601 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Authenticate.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/Authenticate.java @@ -39,6 +39,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.authenticate.LoginRedirector; import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean; import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.Message; import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.State; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.jena.LoginLogoutEvent; public class Authenticate extends VitroHttpServlet { @@ -557,16 +558,7 @@ public class Authenticate extends VitroHttpServlet { return; } - OntModel jenaOntModel = (OntModel) session.getAttribute("jenaOntModel"); - if (jenaOntModel == null) { - jenaOntModel = (OntModel) context.getAttribute("jenaOntModel"); - } - if (jenaOntModel == null) { - log.error("Unable to notify audit model of login event " - + "because no model could be found"); - return; - } - + OntModel jenaOntModel = ModelAccess.on(session).getJenaOntModel(); jenaOntModel.getBaseModel().notifyEvent(event); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/NamespacePrefixOperationController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/NamespacePrefixOperationController.java index 50e60642b..2015b88e5 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/NamespacePrefixOperationController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/NamespacePrefixOperationController.java @@ -24,6 +24,7 @@ import edu.cornell.mannlib.vedit.beans.EditProcessObject; import edu.cornell.mannlib.vedit.controller.BaseEditController; import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; public class NamespacePrefixOperationController extends BaseEditController { @@ -68,7 +69,7 @@ public class NamespacePrefixOperationController extends BaseEditController { if (request.getParameter("_cancel") == null) { - OntModel ontModel = (OntModel) getServletContext().getAttribute("jenaOntModel"); + OntModel ontModel = ModelAccess.on(getServletContext()).getJenaOntModel(); String namespaceStr = request.getParameter("namespace"); String prefixStr = request.getParameter("prefix"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/listing/jena/NamespacesListingController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/listing/jena/NamespacesListingController.java index dda705e85..70845da91 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/listing/jena/NamespacesListingController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/listing/jena/NamespacesListingController.java @@ -22,6 +22,7 @@ import edu.cornell.mannlib.vedit.controller.BaseEditController; import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; import edu.cornell.mannlib.vitro.webapp.controller.Controllers; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; public class NamespacesListingController extends BaseEditController { @@ -34,7 +35,7 @@ public class NamespacesListingController extends BaseEditController { VitroRequest vrequest = new VitroRequest(request); - OntModel ontModel = (OntModel) getServletContext().getAttribute("jenaOntModel"); + OntModel ontModel = ModelAccess.on(getServletContext()).getJenaOntModel(); ArrayList results = new ArrayList(); request.setAttribute("results",results); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/listing/jena/RestrictionsListingController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/listing/jena/RestrictionsListingController.java index 1788dc42c..80dc8262f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/listing/jena/RestrictionsListingController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/listing/jena/RestrictionsListingController.java @@ -33,6 +33,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.controller.Controllers; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; @@ -51,8 +52,8 @@ public class RestrictionsListingController extends BaseEditController { epo = super.createEpo(request); - OntModel ontModel = (OntModel) getServletContext().getAttribute("jenaOntModel"); - + OntModel ontModel = ModelAccess.on(getServletContext()).getJenaOntModel(); + ObjectPropertyDao opDao = vrequest.getFullWebappDaoFactory().getObjectPropertyDao(); VClassDao vcDao = vrequest.getFullWebappDaoFactory().getVClassDao(); IndividualDao iDao = vrequest.getFullWebappDaoFactory().getIndividualDao(); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaAdminActions.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaAdminActions.java index 90d2398b1..498d4ccb3 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaAdminActions.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaAdminActions.java @@ -47,6 +47,7 @@ import com.hp.hpl.jena.vocabulary.RDFS; import edu.cornell.mannlib.vedit.controller.BaseEditController; import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; public class JenaAdminActions extends BaseEditController { @@ -171,7 +172,7 @@ public class JenaAdminActions extends BaseEditController { private String testWriteXML() { StringBuffer output = new StringBuffer(); output.append("Test Write XML
\n");
-		Model model = (Model) getServletContext().getAttribute("jenaOntModel");
+		OntModel model = ModelAccess.on(getServletContext()).getJenaOntModel();
 		Model tmp = ModelFactory.createDefaultModel();
 		boolean valid = true;
 		for (Statement stmt : ((List)model.listStatements().toList()) ) {
@@ -230,7 +231,7 @@ public class JenaAdminActions extends BaseEditController {
     }
     
     private void removeLongLiterals() {
-    	OntModel memoryModel = (OntModel) getServletContext().getAttribute("jenaOntModel");
+		OntModel memoryModel = ModelAccess.on(getServletContext()).getJenaOntModel();
     	memoryModel.enterCriticalSection(Lock.WRITE);
     	try {
     		List statementsToRemove = new LinkedList();
@@ -273,7 +274,7 @@ public class JenaAdminActions extends BaseEditController {
 		}
         
         if (actionStr.equals("checkURIs")) { 
-        	OntModel memoryModel = (OntModel) getServletContext().getAttribute("jenaOntModel");
+    		OntModel memoryModel = ModelAccess.on(getServletContext()).getJenaOntModel();
         	ClosableIterator stmtIt = memoryModel.listStatements();
         	try {
 	        	for (Iterator i = stmtIt; i.hasNext(); ) {
@@ -314,7 +315,7 @@ public class JenaAdminActions extends BaseEditController {
 	    	memoryModel = (OntModel) getServletContext().getAttribute("pelletOntModel");
 	    	System.out.println("pelletOntModel");
 	    } else {
-	    	memoryModel = (OntModel) getServletContext().getAttribute("jenaOntModel");
+			memoryModel = ModelAccess.on(getServletContext()).getJenaOntModel();
 	    	System.out.println("jenaOntModel");
 	    }  
 	    int subModelCount = 0;
@@ -340,7 +341,7 @@ public class JenaAdminActions extends BaseEditController {
         }
         
         if (actionStr.equals("isIsomorphic")) {
-            OntModel memoryModel = (OntModel) getServletContext().getAttribute("jenaOntModel");
+    		OntModel memoryModel = ModelAccess.on(getServletContext()).getJenaOntModel();
             OntModel persistentModel = (OntModel) getServletContext().getAttribute("jenaPersistentOntModel");
             if ((memoryModel != null) && (persistentModel != null)) {
                 long startTime = System.currentTimeMillis();
@@ -363,7 +364,7 @@ public class JenaAdminActions extends BaseEditController {
                 log.trace((System.currentTimeMillis()-startTime)/1000+" seconds to check isomorphism");
             }
         } else if (actionStr.equals("removeUntypedResources")) {
-            OntModel memoryModel = (OntModel) getServletContext().getAttribute("jenaOntModel");
+    		OntModel memoryModel = ModelAccess.on(getServletContext()).getJenaOntModel();
             OntModel persistentModel = (OntModel) getServletContext().getAttribute("jenaPersistentOntModel");
             ClosableIterator rIt = memoryModel.listSubjects();
             clean(rIt,memoryModel);
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaExportController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaExportController.java
index ab666c61f..2a1eff9d8 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaExportController.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaExportController.java
@@ -283,7 +283,6 @@ public class JenaExportController extends BaseEditController {
 		}
 	}
 	
-	static final String FULL_ONT_MODEL_ATTR = "jenaOntModel";
 	static final String ASSERTIONS_ONT_MODEL_ATTR = "baseOntModel";
 	static final String INFERENCES_ONT_MODEL_ATTR = "inferenceOntModel";
 	static final String FULL_GRAPH = "?g";
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java
index ea0b70cb2..80e7eaf0c 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java
@@ -67,6 +67,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
 import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
 import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
 import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
+import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
 import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
 import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
 import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph;
@@ -520,7 +521,7 @@ public class JenaIngestController extends BaseEditController {
             vreq.setAttribute("title", "Choose Workflow Step");
             vreq.setAttribute("bodyJsp", WORKFLOW_STEP_JSP);
         } else {
-            OntModel jenaOntModel = (OntModel) getServletContext().getAttribute("jenaOntModel");
+    		OntModel jenaOntModel = ModelAccess.on(getServletContext()).getJenaOntModel();
             jenaOntModel.enterCriticalSection(Lock.READ);
             List savedQueryList = new LinkedList();
             try {
@@ -537,7 +538,7 @@ public class JenaIngestController extends BaseEditController {
     
     private void processExecuteSparqlRequest(VitroRequest vreq, ModelMaker maker, String modelType) {
         String sparqlQueryStr = vreq.getParameter("sparqlQueryStr");
-        OntModel jenaOntModel = (OntModel) getServletContext().getAttribute("jenaOntModel");
+		OntModel jenaOntModel = ModelAccess.on(getServletContext()).getJenaOntModel();
         jenaOntModel.enterCriticalSection(Lock.READ);
         List savedQueryList = new LinkedList();
         try {
@@ -910,7 +911,7 @@ public class JenaIngestController extends BaseEditController {
     }
     
     private long doExecuteSparql(VitroRequest vreq) {
-        OntModel jenaOntModel = (OntModel) getServletContext().getAttribute("jenaOntModel");
+		OntModel jenaOntModel = ModelAccess.on(getServletContext()).getJenaOntModel();
         OntModel source = null;
         if ("pellet".equals(vreq.getParameter("reasoning"))) {
             source = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
@@ -1193,8 +1194,7 @@ public class JenaIngestController extends BaseEditController {
             Model baseOntModel = RDFServiceGraph.createRDFServiceModel
                     (new RDFServiceGraph(
                             rdfService, JenaDataSourceSetupBase.JENA_DB_MODEL));
-            OntModel ontModel = (OntModel)
-            getServletContext().getAttribute("jenaOntModel");
+    		OntModel ontModel = ModelAccess.on(getServletContext()).getJenaOntModel();
             List urisToChange = new LinkedList();        
             ontModel.enterCriticalSection(Lock.READ);
             try {
@@ -1312,12 +1312,7 @@ public class JenaIngestController extends BaseEditController {
 
     public static Model getModel(String name, HttpServletRequest request, ServletContext context) {
         if ("vitro:jenaOntModel".equals(name)) {
-            Object sessionOntModel = request.getSession().getAttribute("jenaOntModel");
-            if (sessionOntModel != null && sessionOntModel instanceof OntModel) {
-                return (OntModel) sessionOntModel;
-            } else {
-                return (OntModel) context.getAttribute("jenaOntModel");
-            }
+            return ModelAccess.on(request.getSession()).getJenaOntModel();
         } else if ("vitro:baseOntModel".equals(name)) {
             Object sessionOntModel = request.getSession().getAttribute("baseOntModel");
             if (sessionOntModel != null && sessionOntModel instanceof OntModel) {
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java
index 552e91f3a..3f1adb728 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java
@@ -98,6 +98,15 @@ public class ModelAccess {
 		return getOntModel(ModelID.DISPLAY);
 	}
 
+	public void setJenaOntModel(OntModel m) {
+		setOntModel(ModelID.UNION_FULL, m);
+	}
+	
+	public OntModel getJenaOntModel() {
+		return getOntModel(ModelID.UNION_FULL);
+	}
+
+
 	// /** Is this the same as Assertions model? */
 	// // public OntModel getBaseOntModel() {
 	// // throw new RuntimeException(
@@ -224,14 +233,6 @@ public class ModelAccess {
 	 * 		ctx.setAttribute(INFERENCE_ONT_MODEL_SELECTOR, oms); 
 	 * 	}
 	 * 	
-	 * 	public static OntModel getJenaOntModel(ServletContext ctx) {
-	 * 		return (OntModel) ctx.getAttribute(JENA_ONT_MODEL);
-	 * 	}
-	 * 	
-	 * 	public static void setJenaOntModel(OntModel ontModel, ServletContext ctx) {
-	 * 		ctx.setAttribute(JENA_ONT_MODEL, ontModel);
-	 * 	}
-	 * 	
 	 * 	public static OntModel getBaseOntModel(ServletContext ctx) {
 	 * 		return (OntModel) ctx.getAttribute(BASE_ONT_MODEL);
 	 * 	}
@@ -255,7 +256,6 @@ public class ModelAccess {
 	 * VitroRequest.getAssertionsWebappDaoFactory()
 	 * VitroRequest.getDeductionsWebappDaoFactory()
 	 * VitroRequest.getFullWebappDaoFactory()
-	 * VitroRequest.getJenaOntModel()
 	 * VitroRequest.getRDFService()
 	 * VitroRequest.getUnfilteredRDFService()
 	 * VitroRequest.getWebappDaoFactory()
@@ -278,7 +278,6 @@ public class ModelAccess {
 	 * VitroModelSource.openModelIfPresent(string)
 	 * ServletContext.getAttribute("assertionsWebappDaoFactory")
 	 * ServletContext.getAttribute("baseOntModelSelector")
-	 * ServletContext.getAttribute("jenaOntModel")
 	 * ServletContext.getAttribute("jenaPersistentOntModel")
 	 * ServletContext.getAttribute("pelletOntModel")
 	 * ServletContext.getAttribute("webappDaoFactory")
@@ -287,8 +286,6 @@ public class ModelAccess {
 	 * JenaDataSourceSetupBase.getApplicationDataSource(ctx)
 	 * JenaDataSourceSetupBase.getStartupDataset()
 	 * HttpSession.getAttribute("jenaAuditModel")
-	 * HttpSession.getAttribute("jenaOntModel")
-	 * ServletRequest.getAttribute("jenaOntModel")
 	 * 
*/ diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java index bec886cd9..1f0f08c25 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java @@ -54,7 +54,6 @@ public class JenaBaseDao extends JenaBaseDaoCon { public static final boolean KEEP_ONLY_IF_TRUE = true; //used for updatePropertyBooleanValue() public static final boolean KEEP_ONLY_IF_FALSE = false; //used for updatePropertyBooleanValue() - public static final String JENA_ONT_MODEL_ATTRIBUTE_NAME = "jenaOntModel"; public static final String ASSERTIONS_ONT_MODEL_ATTRIBUTE_NAME = "baseOntModel"; public static final String INFERENCE_ONT_MODEL_ATTRIBUTE_NAME = "inferenceOntModel"; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ModelContext.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ModelContext.java index 4b9036a1f..79bf35a1a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ModelContext.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ModelContext.java @@ -10,7 +10,6 @@ import org.apache.commons.logging.LogFactory; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.rdf.model.ModelChangedListener; -import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException; import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; @@ -23,7 +22,6 @@ public class ModelContext { private static final String BASE_ONT_MODEL_SELECTOR = "baseOntModelSelector"; private static final String INFERENCE_ONT_MODEL_SELECTOR = "inferenceOntModelSelector"; - private static final String JENA_ONT_MODEL = "jenaOntModel"; private static final String BASE_ONT_MODEL = "baseOntModel"; private static final String INFERENCE_ONT_MODEL = "inferenceOntModel"; @@ -61,14 +59,6 @@ public class ModelContext { ctx.setAttribute(INFERENCE_ONT_MODEL_SELECTOR, oms); } - public static OntModel getJenaOntModel(ServletContext ctx) { - return (OntModel) ctx.getAttribute(JENA_ONT_MODEL); - } - - public static void setJenaOntModel(OntModel ontModel, ServletContext ctx) { - ctx.setAttribute(JENA_ONT_MODEL, ontModel); - } - public static OntModel getBaseOntModel(ServletContext ctx) { return (OntModel) ctx.getAttribute(BASE_ONT_MODEL); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupCache.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupCache.java index 40e0eaddd..d585ae2c3 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupCache.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupCache.java @@ -31,6 +31,7 @@ import com.hp.hpl.jena.vocabulary.RDFS; import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; @@ -494,7 +495,7 @@ public class VClassGroupCache implements IndexingEventListener { } else if(VitroVocabulary.DISPLAY_RANK.equals(stmt.getPredicate().getURI())){ requestCacheUpdate(); } else { - OntModel jenaOntModel = ModelContext.getJenaOntModel(context); + OntModel jenaOntModel = ModelAccess.on(context).getJenaOntModel(); if( isClassNameChange(stmt, jenaOntModel) ) { requestCacheUpdate(); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaModelMaker.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaModelMaker.java index d2ed5b30f..53e5dcdbf 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaModelMaker.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaModelMaker.java @@ -27,6 +27,7 @@ import com.hp.hpl.jena.util.iterator.ExtendedIterator; import com.hp.hpl.jena.util.iterator.WrappedIterator; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase; /** @@ -311,14 +312,7 @@ public class VitroJenaModelMaker implements ModelMaker { private Model getSpecialModel(String modelName) { if (request != null) { if ("vitro:jenaOntModel".equals(modelName)) { - Object sessionOntModel = request.getSession().getAttribute("jenaOntModel"); - if (sessionOntModel != null && sessionOntModel instanceof OntModel) { - log.debug("Returning jenaOntModel from session"); - return (OntModel) sessionOntModel; - } else { - log.debug("Returning jenaOntModel from context"); - return (OntModel) request.getSession().getServletContext().getAttribute("jenaOntModel"); - } + return ModelAccess.on(request.getSession()).getJenaOntModel(); } else if ("vitro:baseOntModel".equals(modelName)) { Object sessionOntModel = request.getSession().getAttribute("baseOntModel"); if (sessionOntModel != null && sessionOntModel instanceof OntModel) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaSpecialModelMaker.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaSpecialModelMaker.java index 1feb261f9..af676ff5a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaSpecialModelMaker.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaSpecialModelMaker.java @@ -14,6 +14,8 @@ import com.hp.hpl.jena.rdf.model.ModelMaker; import com.hp.hpl.jena.rdf.model.ModelReader; import com.hp.hpl.jena.util.iterator.ExtendedIterator; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; + /** * Wraps a model maker and returns Models from the servlet context when * certain model URIs are requested @@ -115,14 +117,7 @@ public class VitroJenaSpecialModelMaker implements ModelMaker { private Model getSpecialModel(String modelName) { if (request != null) { if ("vitro:jenaOntModel".equals(modelName)) { - Object sessionOntModel = request.getSession().getAttribute("jenaOntModel"); - if (sessionOntModel != null && sessionOntModel instanceof OntModel) { - log.debug("Returning jenaOntModel from session"); - return (OntModel) sessionOntModel; - } else { - log.debug("Returning jenaOntModel from context"); - return (OntModel) request.getSession().getServletContext().getAttribute("jenaOntModel"); - } + return ModelAccess.on(request.getSession()).getJenaOntModel(); } else if ("vitro:baseOntModel".equals(modelName)) { Object sessionOntModel = request.getSession().getAttribute("baseOntModel"); if (sessionOntModel != null && sessionOntModel instanceof OntModel) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroModelSource.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroModelSource.java index 183b8860c..4ca09b10c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroModelSource.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroModelSource.java @@ -107,7 +107,7 @@ public class VitroModelSource implements ModelSource { private Model getNamedModel( ModelName pmn ){ switch( pmn ){ case ABOX: - return (Model) context.getAttribute("jenaOntModel"); + return ModelAccess.on(context).getJenaOntModel(); case TBOX: return (Model) context.getAttribute("tboxmodel???"); case DISPLAY: diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java index a88aa24b4..896d2518b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java @@ -14,8 +14,8 @@ import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.rdf.model.Literal; -import com.hp.hpl.jena.rdf.model.Model; import edu.cornell.mannlib.vitro.webapp.beans.DataProperty; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; @@ -23,6 +23,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfigurationLoader; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; @@ -189,7 +190,7 @@ public class EditConfigurationUtils { public static DataPropertyStatement getDataPropertyStatement(VitroRequest vreq, HttpSession session, Integer dataHash, String predicateUri) { DataPropertyStatement dps = null; if( dataHash != 0) { - Model model = (Model)session.getServletContext().getAttribute("jenaOntModel"); + OntModel model = ModelAccess.on(session.getServletContext()).getJenaOntModel(); dps = RdfLiteralHash.getPropertyStmtByHash(EditConfigurationUtils.getSubjectUri(vreq), predicateUri, dataHash, model); } return dps; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/BaseEditConfigurationGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/BaseEditConfigurationGenerator.java index 80adcecd0..0599081bd 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/BaseEditConfigurationGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/BaseEditConfigurationGenerator.java @@ -4,8 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators import java.util.ArrayList; import java.util.List; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.commons.lang.StringUtils; @@ -13,13 +11,11 @@ import org.apache.commons.lang.StringUtils; import com.hp.hpl.jena.ontology.OntModel; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; -import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.IdModelSelector; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.ModelSelector; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardModelSelector; -import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep; public abstract class BaseEditConfigurationGenerator implements EditConfigurationGenerator { @@ -66,7 +62,7 @@ public abstract class BaseEditConfigurationGenerator implements EditConfiguratio //setup the model selectors for query, write and display models on editConfig setupModelSelectorsFromVitroRequest(vreq, editConfig); - OntModel queryModel = vreq.getJenaOntModel(); // (OntModel)vreq.getAttribute("jenaOntModel"); + OntModel queryModel = ModelAccess.on(vreq).getJenaOntModel(); if( editConfig.getSubjectUri() == null) editConfig.setSubjectUri( EditConfigurationUtils.getSubjectUri(vreq)); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultAddMissingIndividualFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultAddMissingIndividualFormGenerator.java index ca2f7b74a..6b24a1825 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultAddMissingIndividualFormGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultAddMissingIndividualFormGenerator.java @@ -14,6 +14,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Model; @@ -21,6 +22,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo; @@ -350,7 +352,7 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati private void prepareForUpdate(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) { //Here, retrieve model from - Model model = (Model) session.getServletContext().getAttribute("jenaOntModel"); + OntModel model = ModelAccess.on(session.getServletContext()).getJenaOntModel(); //if object property if(EditConfigurationUtils.isObjectProperty(EditConfigurationUtils.getPredicateUri(vreq), vreq)){ Individual objectIndividual = EditConfigurationUtils.getObjectIndividual(vreq); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java index e253cd13f..e8d497d97 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java @@ -378,7 +378,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene private void prepareForUpdate(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) { //Here, retrieve model from - Model model = (Model) session.getServletContext().getAttribute("jenaOntModel"); + OntModel model = ModelAccess.on(session.getServletContext()).getJenaOntModel(); //if object property if(EditConfigurationUtils.isObjectProperty(EditConfigurationUtils.getPredicateUri(vreq), vreq)){ Individual objectIndividual = EditConfigurationUtils.getObjectIndividual(vreq); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManagePageGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManagePageGenerator.java index 225d086ed..6517520fd 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManagePageGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManagePageGenerator.java @@ -33,6 +33,7 @@ import com.hp.hpl.jena.vocabulary.XSD; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo; @@ -207,7 +208,7 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen void prepare(VitroRequest vreq, EditConfigurationVTwo editConfig) { //setup the model selectors for query, write and display models on editConfig setupModelSelectorsFromVitroRequest(vreq, editConfig); - OntModel queryModel = (OntModel)vreq.getAttribute("jenaOntModel"); + OntModel queryModel = ModelAccess.on(vreq).getJenaOntModel(); if (editConfig.isParamUpdate()) { editConfig.prepareForParamUpdate(queryModel); @@ -224,7 +225,7 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen if (editConfig.isParamUpdate()) { //setup the model selectors for query, write and display models on editConfig setupModelSelectorsFromVitroRequest(vreq, editConfig); - OntModel queryModel = (OntModel)vreq.getAttribute("jenaOntModel"); + OntModel queryModel = ModelAccess.on(vreq).getJenaOntModel(); retrieveExistingDataGetterInfo(context, editConfig, queryModel); } @@ -589,7 +590,8 @@ private String getExistingIsSelfContainedTemplateQuery() { int maxMenuPosition = 0; Literal menuPosition = null; setupModelSelectorsFromVitroRequest(vreq, editConfig); - OntModel queryModel = (OntModel)vreq.getAttribute("jenaOntModel"); + OntModel queryModel = ModelAccess.on(vreq).getJenaOntModel(); + String maxMenuPositionQuery = getMaxMenuPositionQueryString(); QueryExecution qe = null; try{ diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/NewIndividualFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/NewIndividualFormGenerator.java index 0c0adcdde..ba5b640ab 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/NewIndividualFormGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/NewIndividualFormGenerator.java @@ -10,13 +10,14 @@ import java.util.Map; import javax.servlet.http.HttpSession; +import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.rdf.model.Literal; -import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.XSD; import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo; @@ -239,7 +240,7 @@ public class NewIndividualFormGenerator implements EditConfigurationGenerator { private void prepareForUpdate(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) { //Here, retrieve model from - Model model = (Model) session.getServletContext().getAttribute("jenaOntModel"); + OntModel model = ModelAccess.on(session.getServletContext()).getJenaOntModel(); //This form is always doing a non-update editConfiguration.prepareForNonUpdate( model ); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/RDFSLabelGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/RDFSLabelGenerator.java index 764f2f7b4..7dc24a5be 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/RDFSLabelGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/RDFSLabelGenerator.java @@ -13,6 +13,7 @@ import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.vocabulary.XSD; @@ -21,6 +22,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataProperty; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo; @@ -297,7 +299,7 @@ public class RDFSLabelGenerator implements EditConfigurationGenerator { private void prepareForUpdate(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) { //Here, retrieve model from - Model model = (Model) session.getServletContext().getAttribute("jenaOntModel"); + OntModel model = ModelAccess.on(session.getServletContext()).getJenaOntModel(); if( editConfiguration.isDataPropertyUpdate() ){ editConfiguration.prepareForDataPropUpdate(model, vreq.getWebappDaoFactory().getDataPropertyDao()); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java index b1217ab08..30b8590d5 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java @@ -41,6 +41,7 @@ import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; 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.filtering.WebappDaoFactoryFiltering; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.FilterFactory; @@ -312,7 +313,7 @@ public class VitroRequestPrep implements Filter { private void setSpecialWriteModel(VitroRequest vreq, OntModel mainOntModel) { if (mainOntModel != null) { - vreq.setAttribute("jenaOntModel", mainOntModel); + ModelAccess.on(vreq).setJenaOntModel(mainOntModel); vreq.setAttribute(SPECIAL_WRITE_MODEL, mainOntModel); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java index bbdb2d02e..7d6de3e01 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/solr/SolrSetup.java @@ -113,7 +113,7 @@ public class SolrSetup implements javax.servlet.ServletContextListener{ context.setAttribute(SOLR_SERVER, server); /* set up the individual to solr doc translation */ - OntModel jenaOntModel = ModelContext.getJenaOntModel(context); + OntModel jenaOntModel = ModelAccess.on(context).getJenaOntModel(); OntModel displayModel = ModelAccess.on(context).getDisplayModel(); /* try to get context attribute DocumentModifiers diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java index ae2a3391f..0712228b5 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java @@ -28,6 +28,7 @@ import com.hp.hpl.jena.util.ResourceUtils; import com.hp.hpl.jena.vocabulary.RDF; 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.WebappDaoFactoryConfig; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; @@ -125,8 +126,8 @@ public class ContentModelSetup extends JenaDataSourceSetupBase ModelContext.setInferenceOntModelSelector(inferenceOms, ctx); // inferences log.info("Setting up DAO factories"); - - ctx.setAttribute("jenaOntModel", unionFullModel); + + ModelAccess.on(ctx).setJenaOntModel(unionFullModel); WebappDaoFactoryConfig config = new WebappDaoFactoryConfig(); config.setDefaultNamespace(getDefaultNamespace(ctx)); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/PropertyMaskingSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/PropertyMaskingSetup.java index ebba991b6..2687af6fa 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/PropertyMaskingSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/PropertyMaskingSetup.java @@ -13,15 +13,15 @@ import net.sf.jga.fn.UnaryFunctor; import com.hp.hpl.jena.ontology.OntModel; import edu.cornell.mannlib.vitro.webapp.beans.Property; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.EntityPropertyListFilter; -import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDao; public class PropertyMaskingSetup implements ServletContextListener { private final static String ENTITY_PROPERTY_LIST_FILTER_ATTR_NAME = "entityPropertyListFilter"; public void contextInitialized(ServletContextEvent sce) { - OntModel jenaOntModel = (OntModel) sce.getServletContext().getAttribute(JenaBaseDao.JENA_ONT_MODEL_ATTRIBUTE_NAME); + OntModel jenaOntModel = ModelAccess.on(sce.getServletContext()).getJenaOntModel(); sce.getServletContext().setAttribute(ENTITY_PROPERTY_LIST_FILTER_ATTR_NAME, new EntityPropertyListFilter(jenaOntModel)); } From 4e4384bd3e17662e3d1e460682fabc2595be1ab2 Mon Sep 17 00:00:00 2001 From: j2blake Date: Fri, 17 May 2013 12:28:48 -0400 Subject: [PATCH 6/9] VIVO-82 Use ModelAccess to get or set the JenaOntModel (Union Full model) --- .../src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java | 3 ++- webapp/web/admin/syncSesame.jsp | 3 ++- webapp/web/jenaIngest/executeWorkflow.jsp | 3 ++- webapp/web/jenaIngest/sparqlConstruct.jsp | 3 ++- webapp/web/jenaIngest/workflowStep.jsp | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java index 3f1adb728..0ce4050f2 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java @@ -260,10 +260,11 @@ public class ModelAccess { * VitroRequest.getUnfilteredRDFService() * VitroRequest.getWebappDaoFactory() * VitroRequest.getWriteModel() + * VitroRequest.getJenaOntModel() + * VitroRequest.setJenaOntModel() * ModelContext.getBaseOntModelSelector() * ModelContext.getInferenceOntModel() * ModelContext.getInferenceOntModelSelector() - * ModelContext.getJenaOntModel() * ModelContext.getOntModelSelector() * ModelContext.getUnionOntModelSelector() * OntModelSelector.getAboxModel diff --git a/webapp/web/admin/syncSesame.jsp b/webapp/web/admin/syncSesame.jsp index d97aa3f56..adf5f9b06 100644 --- a/webapp/web/admin/syncSesame.jsp +++ b/webapp/web/admin/syncSesame.jsp @@ -7,6 +7,7 @@ <%@page import="edu.cornell.mannlib.vitro.webapp.dao.jena.JenaModelUtils"%> <%@page import="com.hp.hpl.jena.rdf.model.Model"%> <%@page import="edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDao"%> +<%@page import="edu.cornell.mannlib.vitro.webapp.dao.ModelAccess"%> <%@page import="java.io.InputStream"%> <%@page import="java.util.Properties"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %> @@ -54,7 +55,7 @@ } String contextId = sesameProperties.getProperty(SESAME_CONTEXT); - Model fullModel = (Model) getServletContext().getAttribute(JenaBaseDao.JENA_ONT_MODEL_ATTRIBUTE_NAME); + Model fullModel = ModelAccess.on(getServletContext).getJenaOntModel(); // Copy the model to avoid locking the main model during sync. Assumes enough memory. Model copyModel = ModelFactory.createDefaultModel(); fullModel.enterCriticalSection(Lock.READ); diff --git a/webapp/web/jenaIngest/executeWorkflow.jsp b/webapp/web/jenaIngest/executeWorkflow.jsp index 46aeeecc2..b92a95933 100644 --- a/webapp/web/jenaIngest/executeWorkflow.jsp +++ b/webapp/web/jenaIngest/executeWorkflow.jsp @@ -3,6 +3,7 @@ <%@ page import="com.hp.hpl.jena.ontology.Individual" %> <%@ page import="com.hp.hpl.jena.ontology.OntModel" %> <%@ page import="com.hp.hpl.jena.rdf.model.ModelMaker" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.ModelAccess"%> <%@ page import="com.hp.hpl.jena.shared.Lock" %> <%@ page import="java.util.Iterator" %> <%@ page import="java.util.List" %> @@ -23,7 +24,7 @@ <% - OntModel jenaOntModel = (OntModel) getServletContext().getAttribute("jenaOntModel"); + OntModel jenaOntModel = ModelAccess.on(getServletContext().getJenaOntModel(); jenaOntModel.enterCriticalSection(Lock.READ); try { List savedQueries = (List) request.getAttribute("savedQueries"); diff --git a/webapp/web/jenaIngest/workflowStep.jsp b/webapp/web/jenaIngest/workflowStep.jsp index 9ea99e7ae..355f8a625 100644 --- a/webapp/web/jenaIngest/workflowStep.jsp +++ b/webapp/web/jenaIngest/workflowStep.jsp @@ -3,6 +3,7 @@ <%@ page import="com.hp.hpl.jena.ontology.Individual" %> <%@ page import="com.hp.hpl.jena.ontology.OntModel" %> <%@ page import="com.hp.hpl.jena.rdf.model.ModelMaker" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.ModelAccess"%> <%@ page import="com.hp.hpl.jena.shared.Lock" %> <%@ page import="java.util.Iterator" %> <%@ page import="java.util.List" %> @@ -25,7 +26,7 @@ <% - OntModel jenaOntModel = ModelAccess.on(getServletContext().getJenaOntModel(); + OntModel jenaOntModel = ModelAccess.on(getServletContext()).getJenaOntModel(); jenaOntModel.enterCriticalSection(Lock.READ); try { List savedQueries = (List) request.getAttribute("workflows"); diff --git a/webapp/web/jenaIngest/sparqlConstruct.jsp b/webapp/web/jenaIngest/sparqlConstruct.jsp index 090d1862f..fd0914584 100644 --- a/webapp/web/jenaIngest/sparqlConstruct.jsp +++ b/webapp/web/jenaIngest/sparqlConstruct.jsp @@ -47,7 +47,7 @@

SPARQL Query <% - OntModel jenaOntModel = ModelAccess.on(getServletContext().getJenaOntModel(); + OntModel jenaOntModel = ModelAccess.on(getServletContext()).getJenaOntModel(); jenaOntModel.enterCriticalSection(Lock.READ); try { List workflowSteps = (List) request.getAttribute("workflowSteps"); From 9b7f6c92e6f5aa086b82f767111fe598449586c6 Mon Sep 17 00:00:00 2001 From: j2blake Date: Fri, 17 May 2013 13:19:46 -0400 Subject: [PATCH 8/9] VIVO-82 Use ModelAccess to get or set the BaseOntModel a.k.a the Base Full model, or AssertionsModel --- .../vitro/webapp/controller/VitroRequest.java | 6 +--- .../edit/RefactorOperationController.java | 9 +++--- .../controller/jena/JenaAdminActions.java | 6 ++-- .../controller/jena/JenaExportController.java | 1 - .../controller/jena/JenaIngestController.java | 10 ++----- .../mannlib/vitro/webapp/dao/ModelAccess.java | 28 ++++++------------- .../vitro/webapp/dao/jena/JenaBaseDao.java | 1 - .../vitro/webapp/dao/jena/ModelContext.java | 9 ------ .../webapp/dao/jena/VitroJenaModelMaker.java | 7 +---- .../dao/jena/VitroJenaSpecialModelMaker.java | 7 +---- .../servlet/setup/AssembleModelsSetup.java | 10 ++----- .../servlet/setup/ContentModelSetup.java | 16 +++++++++-- .../servlet/setup/RunSparqlConstructs.java | 3 +- 13 files changed, 37 insertions(+), 76 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroRequest.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroRequest.java index 9bb1d583d..71e087248 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroRequest.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroRequest.java @@ -191,11 +191,7 @@ public class VitroRequest extends HttpServletRequestWrapper { public OntModel getAssertionsOntModel() { - OntModel jenaOntModel = (OntModel)_req.getSession().getAttribute( JenaBaseDao.ASSERTIONS_ONT_MODEL_ATTRIBUTE_NAME ); - if ( jenaOntModel == null ) { - jenaOntModel = (OntModel)_req.getSession().getServletContext().getAttribute( JenaBaseDao.ASSERTIONS_ONT_MODEL_ATTRIBUTE_NAME ); - } - return jenaOntModel; + return ModelAccess.on(getSession()).getBaseOntModel(); } public OntModel getInferenceOntModel() { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/RefactorOperationController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/RefactorOperationController.java index 57596ac7d..5311879a0 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/RefactorOperationController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/RefactorOperationController.java @@ -7,7 +7,6 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import javax.servlet.RequestDispatcher; import javax.servlet.http.HttpServletRequest; @@ -40,7 +39,6 @@ import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.shared.InvalidPropertyURIException; import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.util.ResourceUtils; -import com.hp.hpl.jena.util.iterator.ClosableIterator; import com.hp.hpl.jena.util.iterator.ExtendedIterator; import com.hp.hpl.jena.vocabulary.RDF; @@ -50,6 +48,7 @@ import edu.cornell.mannlib.vedit.controller.BaseEditController; import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; import edu.cornell.mannlib.vitro.webapp.controller.Controllers; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent; import edu.cornell.mannlib.vitro.webapp.servlet.setup.FileGraphSetup; @@ -74,7 +73,7 @@ public class RefactorOperationController extends BaseEditController { request.setAttribute("title","Check Datatype Properties"); request.setAttribute("css", ""); - OntModel ontModel = (OntModel) getServletContext().getAttribute("baseOntModel"); + OntModel ontModel = ModelAccess.on(getServletContext()).getBaseOntModel(); ontModel.enterCriticalSection(Lock.WRITE); ArrayList results = new ArrayList(); @@ -330,7 +329,7 @@ public class RefactorOperationController extends BaseEditController { private void doMovePropertyStatements(VitroRequest request, HttpServletResponse response, EditProcessObject epo) { String userURI = LoginStatusBean.getBean(request).getUserURI(); - OntModel ontModel = ModelContext.getBaseOntModel(getServletContext()); + OntModel ontModel = ModelAccess.on(getServletContext()).getBaseOntModel(); Model tempRetractModel = ModelFactory.createDefaultModel(); Model tempAddModel = ModelFactory.createDefaultModel(); @@ -414,7 +413,7 @@ public class RefactorOperationController extends BaseEditController { private void doMoveInstances(VitroRequest request, HttpServletResponse response, EditProcessObject epo) { String userURI = LoginStatusBean.getBean(request).getUserURI(); - OntModel ontModel = ModelContext.getBaseOntModel(getServletContext()); + OntModel ontModel = ModelAccess.on(getServletContext()).getBaseOntModel(); String oldClassURIStr = (String) epo.getAttribute("VClassURI"); String newClassURIStr = (String) request.getParameter("NewVClassURI"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaAdminActions.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaAdminActions.java index 498d4ccb3..a436eec1e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaAdminActions.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaAdminActions.java @@ -94,7 +94,7 @@ public class JenaAdminActions extends BaseEditController { * @param response */ private void outputTbox(HttpServletResponse response) { - OntModel memoryModel = (OntModel) getServletContext().getAttribute("baseOntModel"); + OntModel memoryModel = ModelAccess.on(getServletContext()).getBaseOntModel(); try { OntModel tempOntModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM); Property DescriptionProp = ResourceFactory.createProperty(VitroVocabulary.DESCRIPTION_ANNOT); @@ -306,7 +306,7 @@ public class JenaAdminActions extends BaseEditController { if (actionStr.equals("output")) { OntModel memoryModel = null; if (request.getParameter("assertionsOnly") != null) { - memoryModel = (OntModel) getServletContext().getAttribute("baseOntModel"); + memoryModel = ModelAccess.on(getServletContext()).getBaseOntModel(); System.out.println("baseOntModel"); } else if (request.getParameter("inferences") != null) { memoryModel = (OntModel) getServletContext().getAttribute("inferenceOntModel"); @@ -375,7 +375,7 @@ public class JenaAdminActions extends BaseEditController { ClosableIterator ooIt = persistentModel.listObjects(); clean(oIt,persistentModel); } else if (actionStr.equals("outputTaxonomy")) { - OntModel ontModel = (OntModel) getServletContext().getAttribute("baseOntModel"); + OntModel ontModel = ModelAccess.on(getServletContext()).getBaseOntModel(); Model taxonomyModel = extractTaxonomy(ontModel); try { taxonomyModel.write(response.getOutputStream()); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaExportController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaExportController.java index 2a1eff9d8..7317c61bf 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaExportController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaExportController.java @@ -283,7 +283,6 @@ public class JenaExportController extends BaseEditController { } } - static final String ASSERTIONS_ONT_MODEL_ATTR = "baseOntModel"; static final String INFERENCES_ONT_MODEL_ATTR = "inferenceOntModel"; static final String FULL_GRAPH = "?g"; static final String ASSERTIONS_GRAPH = ""; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java index 80e7eaf0c..3a7bb7187 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java @@ -661,8 +661,7 @@ public class JenaIngestController extends BaseEditController { /* * get baseOnt and infOnt models */ - OntModel baseOntModel = ModelContext.getBaseOntModel( - getServletContext()); + OntModel baseOntModel = ModelAccess.on(getServletContext()).getBaseOntModel(); OntModel tboxOntModel = ModelContext.getUnionOntModelSelector( getServletContext()).getTBoxModel(); @@ -1314,12 +1313,7 @@ public class JenaIngestController extends BaseEditController { if ("vitro:jenaOntModel".equals(name)) { return ModelAccess.on(request.getSession()).getJenaOntModel(); } else if ("vitro:baseOntModel".equals(name)) { - Object sessionOntModel = request.getSession().getAttribute("baseOntModel"); - if (sessionOntModel != null && sessionOntModel instanceof OntModel) { - return (OntModel) sessionOntModel; - } else { - return (OntModel) context.getAttribute("baseOntModel"); - } + return ModelAccess.on(request.getSession()).getBaseOntModel(); } else if ("vitro:inferenceOntModel".equals(name)) { Object sessionOntModel = request.getSession().getAttribute("inferenceOntModel"); if (sessionOntModel != null && sessionOntModel instanceof OntModel) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java index 0ce4050f2..572a4dd1c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ModelAccess.java @@ -106,18 +106,14 @@ public class ModelAccess { return getOntModel(ModelID.UNION_FULL); } - - // /** Is this the same as Assertions model? */ - // // public OntModel getBaseOntModel() { - // // throw new RuntimeException( - // // "ModelAccess.getBaseOntModel not implemented."); - // // } - // - // public OntModel getAssertionsOntModel() { - // throw new RuntimeException( - // "ModelAccess.getAssertionsOntModel not implemented."); - // } - // + public void setBaseOntModel(OntModel m) { + setOntModel(ModelID.BASE_FULL, m); + } + + public OntModel getBaseOntModel() { + return getOntModel(ModelID.BASE_FULL); + } + // public OntModel getDisplayTboxOntModel() { // throw new RuntimeException( // "ModelAccess.getDisplayTboxOntModel not implemented."); @@ -233,14 +229,6 @@ public class ModelAccess { * ctx.setAttribute(INFERENCE_ONT_MODEL_SELECTOR, oms); * } * - * public static OntModel getBaseOntModel(ServletContext ctx) { - * return (OntModel) ctx.getAttribute(BASE_ONT_MODEL); - * } - * - * public static void setBaseOntModel(OntModel ontModel, ServletContext ctx) { - * ctx.setAttribute(BASE_ONT_MODEL, ontModel); - * } - * * public static OntModel getInferenceOntModel(ServletContext ctx) { * return (OntModel) ctx.getAttribute(INFERENCE_ONT_MODEL); * } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java index 1f0f08c25..83c029814 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java @@ -54,7 +54,6 @@ public class JenaBaseDao extends JenaBaseDaoCon { public static final boolean KEEP_ONLY_IF_TRUE = true; //used for updatePropertyBooleanValue() public static final boolean KEEP_ONLY_IF_FALSE = false; //used for updatePropertyBooleanValue() - public static final String ASSERTIONS_ONT_MODEL_ATTRIBUTE_NAME = "baseOntModel"; public static final String INFERENCE_ONT_MODEL_ATTRIBUTE_NAME = "inferenceOntModel"; protected static final Log log = LogFactory.getLog(JenaBaseDao.class.getName()); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ModelContext.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ModelContext.java index 79bf35a1a..241840d0e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ModelContext.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ModelContext.java @@ -22,7 +22,6 @@ public class ModelContext { private static final String BASE_ONT_MODEL_SELECTOR = "baseOntModelSelector"; private static final String INFERENCE_ONT_MODEL_SELECTOR = "inferenceOntModelSelector"; - private static final String BASE_ONT_MODEL = "baseOntModel"; private static final String INFERENCE_ONT_MODEL = "inferenceOntModel"; public ModelContext() {} @@ -59,14 +58,6 @@ public class ModelContext { ctx.setAttribute(INFERENCE_ONT_MODEL_SELECTOR, oms); } - public static OntModel getBaseOntModel(ServletContext ctx) { - return (OntModel) ctx.getAttribute(BASE_ONT_MODEL); - } - - public static void setBaseOntModel(OntModel ontModel, ServletContext ctx) { - ctx.setAttribute(BASE_ONT_MODEL, ontModel); - } - public static OntModel getInferenceOntModel(ServletContext ctx) { return (OntModel) ctx.getAttribute(INFERENCE_ONT_MODEL); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaModelMaker.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaModelMaker.java index 53e5dcdbf..14139ba42 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaModelMaker.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaModelMaker.java @@ -314,12 +314,7 @@ public class VitroJenaModelMaker implements ModelMaker { if ("vitro:jenaOntModel".equals(modelName)) { return ModelAccess.on(request.getSession()).getJenaOntModel(); } else if ("vitro:baseOntModel".equals(modelName)) { - Object sessionOntModel = request.getSession().getAttribute("baseOntModel"); - if (sessionOntModel != null && sessionOntModel instanceof OntModel) { - return (OntModel) sessionOntModel; - } else { - return (OntModel) request.getSession().getServletContext().getAttribute("baseOntModel"); - } + return ModelAccess.on(request.getSession()).getBaseOntModel(); } else if ("vitro:inferenceOntModel".equals(modelName)) { Object sessionOntModel = request.getSession().getAttribute("inferenceOntModel"); if (sessionOntModel != null && sessionOntModel instanceof OntModel) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaSpecialModelMaker.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaSpecialModelMaker.java index af676ff5a..6f0928954 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaSpecialModelMaker.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaSpecialModelMaker.java @@ -119,12 +119,7 @@ public class VitroJenaSpecialModelMaker implements ModelMaker { if ("vitro:jenaOntModel".equals(modelName)) { return ModelAccess.on(request.getSession()).getJenaOntModel(); } else if ("vitro:baseOntModel".equals(modelName)) { - Object sessionOntModel = request.getSession().getAttribute("baseOntModel"); - if (sessionOntModel != null && sessionOntModel instanceof OntModel) { - return (OntModel) sessionOntModel; - } else { - return (OntModel) request.getSession().getServletContext().getAttribute("baseOntModel"); - } + return ModelAccess.on(request.getSession()).getBaseOntModel(); } else if ("vitro:inferenceOntModel".equals(modelName)) { Object sessionOntModel = request.getSession().getAttribute("inferenceOntModel"); if (sessionOntModel != null && sessionOntModel instanceof OntModel) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/AssembleModelsSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/AssembleModelsSetup.java index e9dbc9f20..d95c4fc68 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/AssembleModelsSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/AssembleModelsSetup.java @@ -22,6 +22,7 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.util.iterator.ExtendedIterator; import com.hp.hpl.jena.vocabulary.RDF; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer; /** @@ -42,14 +43,7 @@ public class AssembleModelsSetup implements ServletContextListener { private String SYNTAX = "N3"; public void contextInitialized(ServletContextEvent sce) { - - OntModel jenaOntModel = null; - try { - jenaOntModel = (OntModel) sce.getServletContext().getAttribute("baseOntModel"); - } catch (Exception e) { - log.error("No baseOntModel found to which to attach assembled models"); - return; - } + OntModel jenaOntModel = ModelAccess.on(sce.getServletContext()).getBaseOntModel(); // read assemblers out of assemblers directory Set pathSet = sce.getServletContext().getResourcePaths(ASSEMBLERS_DIR_PATH); for (String path : (Set)pathSet) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java index 0712228b5..d633e94f9 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ContentModelSetup.java @@ -90,8 +90,20 @@ public class ContentModelSetup extends JenaDataSourceSetupBase OntModel baseFullModel = createCombinedBulkUpdatingModel(baseABoxModel, baseTBoxModel); OntModel inferenceFullModel = createCombinedModel(inferenceABoxModel, inferenceTBoxModel); OntModel unionFullModel = ModelFactory.createOntologyModel(DB_ONT_MODEL_SPEC, dataset.getDefaultModel()); + + ModelAccess.on(ctx).setOntModel(ModelID.APPLICATION_METADATA, applicationMetadataModel); + ModelAccess.on(ctx).setOntModel(ModelID.USER_ACCOUNTS, userAccountsModel); + ModelAccess.on(ctx).setOntModel(ModelID.DISPLAY, displayModel); + ModelAccess.on(ctx).setOntModel(ModelID.BASE_ABOX, baseABoxModel); + ModelAccess.on(ctx).setOntModel(ModelID.BASE_TBOX, baseTBoxModel); + ModelAccess.on(ctx).setOntModel(ModelID.BASE_FULL, baseFullModel); + ModelAccess.on(ctx).setOntModel(ModelID.INFERRED_ABOX, inferenceABoxModel); + ModelAccess.on(ctx).setOntModel(ModelID.INFERRED_TBOX, inferenceTBoxModel); + ModelAccess.on(ctx).setOntModel(ModelID.INFERRED_FULL, inferenceFullModel); + ModelAccess.on(ctx).setOntModel(ModelID.UNION_ABOX, unionABoxModel); + ModelAccess.on(ctx).setOntModel(ModelID.UNION_TBOX, unionTBoxModel); + ModelAccess.on(ctx).setOntModel(ModelID.UNION_FULL, unionFullModel); - ModelContext.setBaseOntModel(baseFullModel, ctx); ModelContext.setInferenceOntModel(inferenceFullModel, ctx); checkForNamespaceMismatch( applicationMetadataModel, ctx ); @@ -127,8 +139,6 @@ public class ContentModelSetup extends JenaDataSourceSetupBase log.info("Setting up DAO factories"); - ModelAccess.on(ctx).setJenaOntModel(unionFullModel); - WebappDaoFactoryConfig config = new WebappDaoFactoryConfig(); config.setDefaultNamespace(getDefaultNamespace(ctx)); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/RunSparqlConstructs.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/RunSparqlConstructs.java index b76bebb85..1f7cd4629 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/RunSparqlConstructs.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/RunSparqlConstructs.java @@ -28,6 +28,7 @@ import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.util.ResourceUtils; +import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; public class RunSparqlConstructs implements ServletContextListener { @@ -46,7 +47,7 @@ public class RunSparqlConstructs implements ServletContextListener { String namespace = (wadf != null && wadf.getDefaultNamespace() != null) ? wadf.getDefaultNamespace() : DEFAULT_DEFAULT_NAMESPACE; - OntModel baseOntModel = (OntModel) sce.getServletContext().getAttribute("baseOntModel"); + OntModel baseOntModel = ModelAccess.on(sce.getServletContext()).getBaseOntModel(); Model anonModel = ModelFactory.createDefaultModel(); Model namedModel = ModelFactory.createDefaultModel(); From cba000c58bce5de124a3339843e3f87340e9cbfd Mon Sep 17 00:00:00 2001 From: j2blake Date: Fri, 17 May 2013 14:15:25 -0400 Subject: [PATCH 9/9] VIVO-82 Use ModelAccess to get or set the BaseOntModel a.k.a the Base Full model, or AssertionsModel --- webapp/web/admin/conceptRepair.jsp | 3 ++- webapp/web/admin/removeBadRestrictions.jsp | 5 +++-- webapp/web/admin/removeResourceDescription.jsp | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/webapp/web/admin/conceptRepair.jsp b/webapp/web/admin/conceptRepair.jsp index f8d0796cb..301b105e3 100644 --- a/webapp/web/admin/conceptRepair.jsp +++ b/webapp/web/admin/conceptRepair.jsp @@ -3,6 +3,7 @@ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.ModelAccess"%> <%@taglib prefix="vitro" uri="/WEB-INF/tlds/VitroUtils.tld" %> <%@page import="edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission" %> @@ -21,7 +22,7 @@ " FILTER(afn:bnode(?bnode) = \"" + conceptIdStr + "\")\n" + "}"; - OntModel ontModel = (OntModel) getServletContext().getAttribute("baseOntModel"); + OntModel ontModel = ModelAccess.on(getServletContext()).getBaseOntModel(); Model conceptDescription = ModelFactory.createDefaultModel(); try { ontModel.enterCriticalSection(Lock.READ); diff --git a/webapp/web/admin/removeBadRestrictions.jsp b/webapp/web/admin/removeBadRestrictions.jsp index 6954e50d0..18e8e78d8 100644 --- a/webapp/web/admin/removeBadRestrictions.jsp +++ b/webapp/web/admin/removeBadRestrictions.jsp @@ -4,12 +4,13 @@ <%@taglib prefix="vitro" uri="/WEB-INF/tlds/VitroUtils.tld" %> <%@page import="edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission" %> +<%@page import="edu.cornell.mannlib.vitro.webapp.dao.ModelAccess"%> <% request.setAttribute("requestedActions", SimplePermission.USE_MISCELLANEOUS_CURATOR_PAGES.ACTION); %> <% if (request.getParameter("execute") != null) { - OntModel ontModel = (OntModel) getServletContext().getAttribute(JenaBaseDao.ASSERTIONS_ONT_MODEL_ATTRIBUTE_NAME); + OntModel ontModel = ModelAccess.on(getServletContext()).getBaseOntModel(); int results = doRemoval(ontModel); request.setAttribute("removalCount", results); } @@ -66,7 +67,7 @@ " FILTER(afn:bnode(?bnode) = \"" + bnodeId + "\")\n" + "}"; - OntModel ontModel = (OntModel) getServletContext().getAttribute("baseOntModel"); + OntModel ontModel = ModelAccess.on(getServletContext()).getBaseOntModel(); Model conceptDescription = ModelFactory.createDefaultModel(); try { ontModel.enterCriticalSection(Lock.READ); diff --git a/webapp/web/admin/removeResourceDescription.jsp b/webapp/web/admin/removeResourceDescription.jsp index 080fb5f63..874e1f0cb 100644 --- a/webapp/web/admin/removeResourceDescription.jsp +++ b/webapp/web/admin/removeResourceDescription.jsp @@ -6,6 +6,7 @@ <%@taglib prefix="vitro" uri="/WEB-INF/tlds/VitroUtils.tld" %> <%@page import="edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission" %> +<%@page import="edu.cornell.mannlib.vitro.webapp.dao.ModelAccess"%> <% request.setAttribute("requestedActions", SimplePermission.USE_MISCELLANEOUS_CURATOR_PAGES.ACTION); %> @@ -16,7 +17,7 @@ String describeQueryStr = "DESCRIBE <" + resourceURIStr + ">"; - OntModel ontModel = (OntModel) getServletContext().getAttribute("baseOntModel"); + OntModel ontModel = ModelAccess.on(getServletContext()).getBaseOntModel(); Model resourceDescription = ModelFactory.createDefaultModel(); try { ontModel.enterCriticalSection(Lock.READ);