diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/VclassEditController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/VclassEditController.java index e0a67114b..fb3803888 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/VclassEditController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/VclassEditController.java @@ -28,7 +28,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.Controllers; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao; -import edu.cornell.mannlib.vitro.webapp.dao.VitroModelProperties; +import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; public class VclassEditController extends BaseEditController { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/listing/ClassHierarchyListingController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/listing/ClassHierarchyListingController.java index 64b619880..4d1dde1fd 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/listing/ClassHierarchyListingController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/edit/listing/ClassHierarchyListingController.java @@ -33,7 +33,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao; -import edu.cornell.mannlib.vitro.webapp.dao.VitroModelProperties; +import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VitroModelProperties.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactoryConfig.java similarity index 56% rename from webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VitroModelProperties.java rename to webapp/src/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactoryConfig.java index f40053319..faf017275 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VitroModelProperties.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactoryConfig.java @@ -5,44 +5,22 @@ package edu.cornell.mannlib.vitro.webapp.dao; import java.util.HashSet; import java.util.Set; -public class VitroModelProperties { - - public static final int RDF_ABOX_ONLY = 50; - public static final int RDFS = 100; - public static final int OWL_FULL = 200; - public static final int OWL_DL = 202; - public static final int OWL_LITE = 204; +public class WebappDaoFactoryConfig { - private int languageProfile; private String[] preferredLanguages; private String defaultNamespace; private Set nonUserNamespaces; - public static boolean isOWL(int languageProfile) { - return ((OWL_FULL <= languageProfile && OWL_LITE >= languageProfile)); - } - - public static boolean isRDFS(int languageProfile) { - return (languageProfile==100); - } - - public VitroModelProperties() { - languageProfile = 200; - preferredLanguages = new String[1]; - preferredLanguages[0] = null; + public WebappDaoFactoryConfig() { + preferredLanguages = new String[3]; + preferredLanguages[0] = "en-US"; + preferredLanguages[1] = "en"; + preferredLanguages[2] = "EN"; defaultNamespace = "http://vitro.mannlib.cornell.edu/ns/default#"; nonUserNamespaces = new HashSet(); nonUserNamespaces.add(VitroVocabulary.vitroURI); } - public int getLanguageProfile() { - return this.languageProfile; - } - - public void setLanguageProfile(int languageProfile) { - this.languageProfile = languageProfile; - } - public String[] getPreferredLanguages() { return this.preferredLanguages; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaModelUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaModelUtils.java index 68b4d80c5..03b269620 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaModelUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaModelUtils.java @@ -25,11 +25,8 @@ import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.Property; -import com.hp.hpl.jena.rdf.model.RDFNode; 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.rdf.model.StmtIterator; import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.RDF; @@ -38,6 +35,7 @@ import com.hp.hpl.jena.vocabulary.RDFS; import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; +import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig; public class JenaModelUtils { @@ -67,7 +65,10 @@ public class JenaModelUtils { SimpleOntModelSelector oms = new SimpleOntModelSelector(); oms.setTBoxModel(ontModel); oms.setApplicationMetadataModel(modelForClassgroups); - WebappDaoFactory myWebappDaoFactory = new WebappDaoFactoryJena(new SimpleOntModelSelector(ontModel),wadf.getDefaultNamespace(),null,null,null); + WebappDaoFactoryConfig config = new WebappDaoFactoryConfig(); + config.setDefaultNamespace(wadf.getDefaultNamespace()); + WebappDaoFactory myWebappDaoFactory = new WebappDaoFactoryJena( + new SimpleOntModelSelector(ontModel), config, null); OntModel tempModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM); Resource classGroupClass = ResourceFactory.createResource(VitroVocabulary.CLASSGROUP); Property inClassGroupProperty = ResourceFactory.createProperty(VitroVocabulary.IN_CLASSGROUP); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactoryJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactoryJena.java index 30961799a..47050bb25 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactoryJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactoryJena.java @@ -54,6 +54,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao; 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.pellet.PelletListener; import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase; @@ -72,16 +73,11 @@ public class WebappDaoFactoryJena implements WebappDaoFactory { protected OntModelSelector ontModelSelector; - protected String defaultNamespace; - protected HashSet nonuserNamespaces; - protected String[] preferredLanguages; + protected WebappDaoFactoryConfig config; protected PelletListener pelletListener; protected String userURI; - - protected boolean INCLUDE_TOP_CONCEPT = false; - protected boolean INCLUDE_BOTTOM_CONCEPT = false; private Map properties = new HashMap(); @@ -91,9 +87,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory { public WebappDaoFactoryJena(WebappDaoFactoryJena base, String userURI) { this.ontModelSelector = base.ontModelSelector; - this.defaultNamespace = base.defaultNamespace; - this.nonuserNamespaces = base.nonuserNamespaces; - this.preferredLanguages = base.preferredLanguages; + this.config = base.config; this.userURI = userURI; this.dwf = base.dwf; } @@ -101,50 +95,12 @@ public class WebappDaoFactoryJena implements WebappDaoFactory { public WebappDaoFactoryJena(OntModelSelector ontModelSelector, OntModelSelector baseOntModelSelector, OntModelSelector inferenceOntModelSelector, - String defaultNamespace, - HashSet nonuserNamespaces, - String[] preferredLanguages, - String userURI){ + WebappDaoFactoryConfig config, + String userURI) { this.ontModelSelector = ontModelSelector; - - if (defaultNamespace != null) { - this.defaultNamespace = defaultNamespace; - } else { - initDefaultNamespace(); - } - if (nonuserNamespaces != null) { - this.nonuserNamespaces = nonuserNamespaces; - } else { - initNonuserNamespaces(); - } - if (preferredLanguages != null) { - this.preferredLanguages = preferredLanguages; - } else { - initPreferredLanguages(); - } + this.config = config; this.userURI = userURI; - Model languageUniversalsModel = ModelFactory.createDefaultModel(); - if (INCLUDE_TOP_CONCEPT) { - Resource top = getTopConcept(); - if (top != null) { - languageUniversalsModel.add(top, RDF.type, - this.ontModelSelector.getTBoxModel().getProfile() - .CLASS()); - } - } - if (INCLUDE_BOTTOM_CONCEPT) { - Resource bottom = getBottomConcept(); - if (bottom != null) { - languageUniversalsModel.add(bottom, RDF.type, - this.ontModelSelector.getTBoxModel().getProfile() - .CLASS()); - } - } - if (languageUniversalsModel.size()>0) { - this.ontModelSelector.getTBoxModel().addSubModel( - languageUniversalsModel); - } Model assertions = (baseOntModelSelector != null) ? baseOntModelSelector.getFullModel() @@ -157,7 +113,46 @@ public class WebappDaoFactoryJena implements WebappDaoFactory { this.dwf = new StaticDatasetFactory(dataset); } + + public WebappDaoFactoryJena(OntModelSelector ontModelSelector, + WebappDaoFactoryConfig config, + String userURI) { + this(ontModelSelector, null, null, config, userURI); + } + + public WebappDaoFactoryJena(OntModelSelector ontModelSelector, + WebappDaoFactoryConfig config) { + this(ontModelSelector, config, null); + } + public WebappDaoFactoryJena(OntModelSelector ontModelSelector, + OntModelSelector baseOntModelSelector, + OntModelSelector inferenceOntModelSelector, + WebappDaoFactoryConfig config) { + this(ontModelSelector, + baseOntModelSelector, + inferenceOntModelSelector, + config, + null); + } + + public WebappDaoFactoryJena(OntModelSelector ontModelSelector) { + this(ontModelSelector, new WebappDaoFactoryConfig(), null); + } + + public WebappDaoFactoryJena(OntModel ontModel) { + this(new SimpleOntModelSelector( + ontModel), new WebappDaoFactoryConfig(), null); + } + + public OntModelSelector getOntModelSelector() { + return this.ontModelSelector; + } + + public OntModel getOntModel() { + return this.ontModelSelector.getFullModel(); + } + public static Dataset makeInMemoryDataset(Model assertions, Model inferences) { DataSource dataset = DatasetFactory.create(); @@ -175,128 +170,6 @@ public class WebappDaoFactoryJena implements WebappDaoFactory { dataset.setDefaultModel(union); return dataset; } - - public WebappDaoFactoryJena(OntModelSelector ontModelSelector, - String defaultNamespace, - HashSet nonuserNamespaces, - String[] preferredLanguages, - String userURI){ - this(ontModelSelector, - null, - null, - defaultNamespace, - nonuserNamespaces, - preferredLanguages, - userURI); - } - - public WebappDaoFactoryJena(OntModelSelector ontModelSelector, - String defaultNamespace, - HashSet nonuserNamespaces, - String[] preferredLanguages) { - this(ontModelSelector, - defaultNamespace, - nonuserNamespaces, - preferredLanguages, - null); - } - - public WebappDaoFactoryJena(OntModelSelector ontModelSelector, - OntModelSelector baseOntModelSelector, - OntModelSelector inferenceOntModelSelector, - String defaultNamespace, - HashSet nonuserNamespaces, - String[] preferredLanguages){ - this(ontModelSelector, - baseOntModelSelector, - inferenceOntModelSelector, - defaultNamespace, - nonuserNamespaces, - preferredLanguages, - null); - } - - public WebappDaoFactoryJena(OntModelSelector ontModelSelector) { - this(ontModelSelector, null, null, null, null, null); - } - - public WebappDaoFactoryJena(OntModel ontModel, - String defaultNamespace, - HashSet nonuserNamespaces, - String[] preferredLanguages, - String userURI) { - this(new SimpleOntModelSelector(ontModel), - defaultNamespace, - nonuserNamespaces, - preferredLanguages, - userURI); - } - - public WebappDaoFactoryJena(OntModel ontModel, - String defaultNamespace, - HashSet nonuserNamespaces, - String[] preferredLanguages) { - this(new SimpleOntModelSelector(ontModel), - defaultNamespace, - nonuserNamespaces, - preferredLanguages, - null); - } - - public WebappDaoFactoryJena(OntModel ontModel) { - this(new SimpleOntModelSelector( - ontModel), null, null, null, null, null); - } - - public OntModelSelector getOntModelSelector() { - return this.ontModelSelector; - } - - public OntModel getOntModel() { - return this.ontModelSelector.getFullModel(); - } - - /** - * Return the current language profile's Top concept as a Jena resource, - * or null if not applicable. The special case is RDFS, where we use - * rdfs:Resource as the analog of Top, rather than returning null. - * @return - */ - public Resource getTopConcept() { - Resource top = null; - if (this.ontModelSelector.getTBoxModel().getProfile().NAMESPACE() - .equals(RDFS.getURI())) { - top = RDFS.Resource; - } else { - top = this.ontModelSelector.getTBoxModel().getProfile().THING(); - } - return top; - } - - /** - * Return the current language profile's Bottom concept as a Jena resource, - * or null if not applicable. - * @return - */ - public Resource getBottomConcept() { - return this.ontModelSelector.getTBoxModel().getProfile().THING(); - } - - private void initDefaultNamespace() { - defaultNamespace = "http://vivo.library.cornell.edu/ns/0.1#"; - } - - private void initNonuserNamespaces() { - nonuserNamespaces = new HashSet(); - nonuserNamespaces.add(VitroVocabulary.vitroURI); - } - - private void initPreferredLanguages() { - preferredLanguages = new String[3]; - preferredLanguages[0] = "en-US"; - preferredLanguages[1] = "en"; - preferredLanguages[2] = "EN"; - } /* ******************************************** */ @@ -366,15 +239,15 @@ public class WebappDaoFactoryJena implements WebappDaoFactory { /* **************** accessors ***************** */ public String getDefaultNamespace() { - return defaultNamespace; + return config.getDefaultNamespace(); } public String[] getPreferredLanguages() { - return this.preferredLanguages; + return config.getPreferredLanguages(); } public Set getNonuserNamespaces() { - return nonuserNamespaces; + return config.getNonUserNamespaces(); } /** @@ -595,9 +468,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory { //Not sure what this is but will set to equivalence here this.ontModelSelector = base.ontModelSelector; } - this.defaultNamespace = base.defaultNamespace; - this.nonuserNamespaces = base.nonuserNamespaces; - this.preferredLanguages = base.preferredLanguages; + this.config = base.config; this.userURI = base.userURI; this.dwf = base.dwf; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactorySDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactorySDB.java index b83a24a37..14212f7ce 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactorySDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactorySDB.java @@ -19,6 +19,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; +import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig; import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase; public class WebappDaoFactorySDB extends WebappDaoFactoryJena { @@ -30,7 +31,8 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { * For use when any database connection associated with the Dataset * is managed externally */ - public WebappDaoFactorySDB(OntModelSelector ontModelSelector, Dataset dataset) { + public WebappDaoFactorySDB(OntModelSelector ontModelSelector, + Dataset dataset) { super(ontModelSelector); this.dwf = new StaticDatasetFactory(dataset); } @@ -41,10 +43,8 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { */ public WebappDaoFactorySDB(OntModelSelector ontModelSelector, Dataset dataset, - String defaultNamespace, - HashSet nonuserNamespaces, - String[] preferredLanguages) { - super(ontModelSelector, defaultNamespace, nonuserNamespaces, preferredLanguages); + WebappDaoFactoryConfig config) { + super(ontModelSelector, config); this.dwf = new StaticDatasetFactory(dataset); } @@ -55,10 +55,8 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { public WebappDaoFactorySDB(OntModelSelector ontModelSelector, BasicDataSource bds, StoreDesc storeDesc, - String defaultNamespace, - HashSet nonuserNamespaces, - String[] preferredLanguages) { - super(ontModelSelector, defaultNamespace, nonuserNamespaces, preferredLanguages); + WebappDaoFactoryConfig config) { + super(ontModelSelector, config); this.dwf = new ReconnectingDatasetFactory(bds, storeDesc); } @@ -69,11 +67,9 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { public WebappDaoFactorySDB(OntModelSelector ontModelSelector, BasicDataSource bds, StoreDesc storeDesc, - String defaultNamespace, - HashSet nonuserNamespaces, - String[] preferredLanguages, + WebappDaoFactoryConfig config, SDBDatasetMode datasetMode) { - super(ontModelSelector, defaultNamespace, nonuserNamespaces, preferredLanguages); + super(ontModelSelector, config); this.dwf = new ReconnectingDatasetFactory(bds, storeDesc); this.datasetMode = datasetMode; } @@ -82,9 +78,7 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { public WebappDaoFactorySDB(WebappDaoFactorySDB base, String userURI) { super(base.ontModelSelector); this.ontModelSelector = base.ontModelSelector; - this.defaultNamespace = base.defaultNamespace; - this.nonuserNamespaces = base.nonuserNamespaces; - this.preferredLanguages = base.preferredLanguages; + this.config = base.config; this.userURI = userURI; this.dwf = base.dwf; } @@ -125,7 +119,6 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { } public WebappDaoFactory getUserAwareDaoFactory(String userURI) { - // TODO: put the user-aware factories in a hashmap so we don't keep re-creating them return new WebappDaoFactorySDB(this, userURI); } @@ -174,7 +167,8 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { private BasicDataSource _bds; private StoreDesc _storeDesc; - public ReconnectingDatasetFactory(BasicDataSource bds, StoreDesc storeDesc) { + public ReconnectingDatasetFactory(BasicDataSource bds, + StoreDesc storeDesc) { _bds = bds; _storeDesc = storeDesc; } @@ -187,7 +181,8 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { Dataset dataset = SDBFactory.connectDataset(store); return new DatasetWrapper(dataset, conn); } catch (SQLException sqe) { - throw new RuntimeException("Unable to connect to database", sqe); + throw new RuntimeException( + "Unable to connect to database", sqe); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/WebappDaoFactorySDBPrep.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/WebappDaoFactorySDBPrep.java index caa1214de..30351715d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/WebappDaoFactorySDBPrep.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/WebappDaoFactorySDBPrep.java @@ -31,6 +31,7 @@ import com.hp.hpl.jena.sdb.sql.SDBConnection; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; +import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig; import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector; import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB; import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase; @@ -103,8 +104,9 @@ public class WebappDaoFactorySDBPrep implements Filter { store = SDBFactory.connectStore(conn, storeDesc); dataset = SDBFactory.connectDataset(store); VitroRequest vreq = new VitroRequest((HttpServletRequest) request); - wadf = - new WebappDaoFactorySDB(oms, dataset, defaultNamespace, null, null); + WebappDaoFactoryConfig config = new WebappDaoFactoryConfig(); + config.setDefaultNamespace(defaultNamespace); + wadf = new WebappDaoFactorySDB(oms, dataset, config); vreq.setWebappDaoFactory(wadf); vreq.setFullWebappDaoFactory(wadf); vreq.setDataset(dataset); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetup.java index 38bde4c12..45079018f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetup.java @@ -43,6 +43,7 @@ import com.hp.hpl.jena.vocabulary.RDF; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; 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.JenaModelUtils; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext; import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer; @@ -54,7 +55,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; import edu.cornell.mannlib.vitro.webapp.utils.jena.InitialJenaModelUtils; -public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements javax.servlet.ServletContextListener { +public class JenaDataSourceSetup extends JenaDataSourceSetupBase + implements javax.servlet.ServletContextListener { private static final Log log = LogFactory.getLog(JenaDataSourceSetup.class); @@ -120,38 +122,57 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java } } - // The code below, which sets up the OntModelSelectors, controls whether each - // model is maintained in memory, in the DB, or both while the application - // is running. + // The code below, which sets up the OntModelSelectors, controls whether + // each model is maintained in memory, in the DB, or both while the + // application is running. - // Populate the three OntModelSelectors (BaseOntModel=assertions, InferenceOntModel=inferences - // and JenaOntModel=union of assertions and inferences) with the post-SDB-conversion models. + // Populate the three OntModelSelectors (BaseOntModel = assertions, + // InferenceOntModel = inferences and JenaOntModel = union of assertions + // and inferences) with the post-SDB-conversion models. // ABox assertions - Model aboxAssertions = makeDBModel(bds, JenaDataSourceSetupBase.JENA_DB_MODEL, DB_ONT_MODEL_SPEC, TripleStoreType.SDB, ctx); - Model listenableAboxAssertions = ModelFactory.createUnion(aboxAssertions, ModelFactory.createDefaultModel()); - baseOms.setABoxModel(ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, listenableAboxAssertions)); + Model aboxAssertions = makeDBModel( + bds, JenaDataSourceSetupBase.JENA_DB_MODEL, DB_ONT_MODEL_SPEC, + TripleStoreType.SDB, ctx); + Model listenableAboxAssertions = ModelFactory.createUnion( + aboxAssertions, ModelFactory.createDefaultModel()); + baseOms.setABoxModel( + ModelFactory.createOntologyModel( + OntModelSpec.OWL_MEM, listenableAboxAssertions)); // ABox inferences - Model aboxInferences = makeDBModel(bds, JenaDataSourceSetupBase.JENA_INF_MODEL, DB_ONT_MODEL_SPEC, TripleStoreType.SDB, ctx); - Model listenableAboxInferences = ModelFactory.createUnion(aboxInferences, ModelFactory.createDefaultModel()); - inferenceOms.setABoxModel(ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, listenableAboxInferences)); + Model aboxInferences = makeDBModel( + bds, JenaDataSourceSetupBase.JENA_INF_MODEL, DB_ONT_MODEL_SPEC, + TripleStoreType.SDB, ctx); + Model listenableAboxInferences = ModelFactory.createUnion( + aboxInferences, ModelFactory.createDefaultModel()); + inferenceOms.setABoxModel(ModelFactory.createOntologyModel( + OntModelSpec.OWL_MEM, listenableAboxInferences)); - // Since the TBox models are in memory, they do not have time out issues like the - // ABox models do (and so don't need the extra step to make them listenable). + + // Since the TBox models are in memory, they do not have timeout issues + // like the like the ABox models do (and so don't need the extra step + // to make them listenable.) + // TBox assertions try { - Model tboxAssertionsDB = makeDBModel(bds, JENA_TBOX_ASSERTIONS_MODEL, DB_ONT_MODEL_SPEC, TripleStoreType.SDB, ctx); - OntModel tboxAssertions = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC); + Model tboxAssertionsDB = makeDBModel( + bds, JENA_TBOX_ASSERTIONS_MODEL, DB_ONT_MODEL_SPEC, + TripleStoreType.SDB, ctx); + OntModel tboxAssertions = ModelFactory.createOntologyModel( + MEM_ONT_MODEL_SPEC); if (tboxAssertionsDB != null) { long startTime = System.currentTimeMillis(); - System.out.println("Copying cached tbox assertions into memory"); + System.out.println( + "Copying cached tbox assertions into memory"); tboxAssertions.add(tboxAssertionsDB); - System.out.println((System.currentTimeMillis()-startTime)/1000+" seconds to load tbox assertions"); + System.out.println((System.currentTimeMillis() - startTime) + / 1000 + " seconds to load tbox assertions"); } - tboxAssertions.getBaseModel().register(new ModelSynchronizer(tboxAssertionsDB)); + tboxAssertions.getBaseModel().register(new ModelSynchronizer( + tboxAssertionsDB)); baseOms.setTBoxModel(tboxAssertions); } catch (Throwable e) { log.error("Unable to load tbox assertion cache from DB", e); @@ -159,56 +180,80 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java // TBox inferences try { - Model tboxInferencesDB = makeDBModel(bds, JENA_TBOX_INF_MODEL, DB_ONT_MODEL_SPEC, TripleStoreType.SDB, ctx); - OntModel tboxInferences = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC); + Model tboxInferencesDB = makeDBModel( + bds, JENA_TBOX_INF_MODEL, DB_ONT_MODEL_SPEC, + TripleStoreType.SDB, ctx); + OntModel tboxInferences = ModelFactory.createOntologyModel( + MEM_ONT_MODEL_SPEC); if (tboxInferencesDB != null) { long startTime = System.currentTimeMillis(); - System.out.println("Copying cached tbox inferences into memory"); + System.out.println( + "Copying cached tbox inferences into memory"); tboxInferences.add(tboxInferencesDB); - System.out.println((System.currentTimeMillis()-startTime)/1000+" seconds to load tbox inferences"); + System.out.println((System.currentTimeMillis() - startTime) + / 1000 + " seconds to load tbox inferences"); } - tboxInferences.getBaseModel().register(new ModelSynchronizer(tboxInferencesDB)); + tboxInferences.getBaseModel().register(new ModelSynchronizer( + tboxInferencesDB)); inferenceOms.setTBoxModel(tboxInferences); } catch (Throwable e) { log.error("Unable to load tbox inference cache from DB", e); } // union ABox - OntModel unionABoxModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC,ModelFactory.createUnion(baseOms.getABoxModel(), inferenceOms.getABoxModel())); + OntModel unionABoxModel = ModelFactory.createOntologyModel( + MEM_ONT_MODEL_SPEC,ModelFactory.createUnion( + baseOms.getABoxModel(), inferenceOms.getABoxModel())); unionOms.setABoxModel(unionABoxModel); // union TBox - OntModel unionTBoxModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC,ModelFactory.createUnion(baseOms.getTBoxModel(), inferenceOms.getTBoxModel())); + OntModel unionTBoxModel = ModelFactory.createOntologyModel( + MEM_ONT_MODEL_SPEC,ModelFactory.createUnion( + baseOms.getTBoxModel(), inferenceOms.getTBoxModel())); unionOms.setTBoxModel(unionTBoxModel); // Application metadata model is cached in memory. try { - Model applicationMetadataModelDB = makeDBModel(bds, JENA_APPLICATION_METADATA_MODEL, DB_ONT_MODEL_SPEC, TripleStoreType.SDB, ctx); - OntModel applicationMetadataModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC); + Model applicationMetadataModelDB = makeDBModel( + bds, JENA_APPLICATION_METADATA_MODEL, DB_ONT_MODEL_SPEC, + TripleStoreType.SDB, ctx); + OntModel applicationMetadataModel = + ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC); long startTime = System.currentTimeMillis(); - System.out.println("Copying cached application metadata model into memory"); + 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)); + 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 (isFirstStartup()) { - applicationMetadataModel.add(InitialJenaModelUtils.loadInitialModel(ctx, getDefaultNamespace(ctx))); + applicationMetadataModel.add( + InitialJenaModelUtils.loadInitialModel( + ctx, getDefaultNamespace(ctx))); } else if (applicationMetadataModelDB.size() == 0) { - repairAppMetadataModel(applicationMetadataModel, aboxAssertions, aboxInferences); + repairAppMetadataModel( + applicationMetadataModel, aboxAssertions, + aboxInferences); } baseOms.setApplicationMetadataModel(applicationMetadataModel); - inferenceOms.setApplicationMetadataModel(baseOms.getApplicationMetadataModel()); - unionOms.setApplicationMetadataModel(baseOms.getApplicationMetadataModel()); + inferenceOms.setApplicationMetadataModel( + baseOms.getApplicationMetadataModel()); + unionOms.setApplicationMetadataModel( + baseOms.getApplicationMetadataModel()); } catch (Throwable e) { - log.error("Unable to load application metadata model cache from DB", e); + log.error("Unable to load application metadata model cache from DB" + , e); } checkForNamespaceMismatch( baseOms.getApplicationMetadataModel(), ctx ); @@ -220,31 +265,28 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java log.info("Setting up union models and DAO factories"); // create TBox + ABox union models and set up webapp DAO factories - OntModel baseUnion = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, - ModelFactory.createUnion(baseOms.getABoxModel(), baseOms.getTBoxModel())); + OntModel baseUnion = ModelFactory.createOntologyModel( + OntModelSpec.OWL_MEM, + ModelFactory.createUnion(baseOms.getABoxModel(), + baseOms.getTBoxModel())); baseOms.setFullModel(baseUnion); ModelContext.setBaseOntModel(baseOms.getFullModel(), ctx); + WebappDaoFactoryConfig config = new WebappDaoFactoryConfig(); + config.setDefaultNamespace(getDefaultNamespace(ctx)); WebappDaoFactory baseWadf = new WebappDaoFactorySDB( - baseOms, - bds, - storeDesc, - getDefaultNamespace(ctx), - null, - null, + baseOms, bds, storeDesc, config, WebappDaoFactorySDB.SDBDatasetMode.ASSERTIONS_ONLY); ctx.setAttribute("assertionsWebappDaoFactory",baseWadf); - OntModel inferenceUnion = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, - ModelFactory.createUnion(inferenceOms.getABoxModel(), inferenceOms.getTBoxModel())); + 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( - inferenceOms, - bds, - storeDesc, - getDefaultNamespace(ctx), - null, - null, + inferenceOms, bds, storeDesc, config, WebappDaoFactorySDB.SDBDatasetMode.INFERENCES_ONLY); ctx.setAttribute("deductionsWebappDaoFactory", infWadf); @@ -252,23 +294,19 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java DB_ONT_MODEL_SPEC, makeDBModel( bds, WebappDaoFactorySDB.UNION_GRAPH, DB_ONT_MODEL_SPEC, TripleStoreType.SDB, ctx)); - //OntModel masterUnion = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, - // ModelFactory.createUnion(unionABoxModel, unionTBoxModel)); unionOms.setFullModel(masterUnion); ctx.setAttribute("jenaOntModel", masterUnion); - WebappDaoFactory wadf = new WebappDaoFactorySDB(unionOms, bds, storeDesc, getDefaultNamespace(ctx), null, null); + WebappDaoFactory wadf = new WebappDaoFactorySDB( + unionOms, bds, storeDesc, 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("Setting up namespace mapper"); - - //NamespaceMapper namespaceMapper = new NamespaceMapperJena(masterUnion, masterUnion, defaultNamespace); - //ctx.setAttribute("NamespaceMapper", namespaceMapper); - //unionOms.getFullModel().getBaseModel().register(namespaceMapper); + ModelContext.setUnionOntModelSelector(unionOms, ctx); + // assertions and inferences + ModelContext.setBaseOntModelSelector(baseOms, ctx); + // assertions + ModelContext.setInferenceOntModelSelector(inferenceOms, ctx); + // inferences ctx.setAttribute("defaultNamespace", getDefaultNamespace(ctx)); @@ -352,7 +390,7 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java } - /* ====================================================================== */ + /* ===================================================================== */ @Override @@ -360,7 +398,8 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java // Nothing to do. } - private OntModel ontModelFromContextAttribute(ServletContext ctx, String attribute) { + private OntModel ontModelFromContextAttribute(ServletContext ctx, + String attribute) { OntModel ontModel; Object attributeValue = ctx.getAttribute(attribute); if (attributeValue != null && attributeValue instanceof OntModel) { @@ -387,7 +426,8 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java } } - private void loadDataFromFilesystem(OntModelSelector baseOms, ServletContext ctx) { + private void loadDataFromFilesystem(OntModelSelector baseOms, + ServletContext ctx) { Long startTime = System.currentTimeMillis(); log.debug("Initializing models from RDF files"); readOntologyFilesInPathSet(USER_ABOX_PATH, ctx, baseOms.getABoxModel()); @@ -398,7 +438,9 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java + " seconds to read RDF files "); } - private static void getTBoxModel(Model fullModel, Model submodels, Model tboxModel) { + private static void getTBoxModel(Model fullModel, + Model submodels, + Model tboxModel) { JenaModelUtils modelUtils = new JenaModelUtils(); @@ -421,7 +463,9 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java /* * Copy all statements from model 1 that are not in model 2 to model 3. */ - private static void copyDifference(Model model1, Model model2, Model model3) { + private static void copyDifference(Model model1, + Model model2, + Model model3) { StmtIterator iter = model1.listStatements(); @@ -502,16 +546,17 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java try { // This is a one-time copy of stored KB data - from a Jena RDB store - // to a Jena SDB store. In the process, we will also separate out the - // TBox from the Abox; these are in the same graph in pre 1.2 VIVO - // versions and will now be stored and maintained in separate models - // Access to the Jena RDB data is through the OntModelSelectors that have - // been set up earlier in the current session by - // JenaPersistentDataSourceSetup.java - // In the code below, note that the current getABoxModel() methods on - // the OntModelSelectors return a graph with both ABox and TBox data. + // to a Jena SDB store. In the process, we will also separate out + // the TBox from the Abox; these are in the same graph in pre-1.2 + // VIVO versions and will now be stored and maintained in separate + // models. Access to the Jena RDB data is through the + // OntModelSelectors that have been set up earlier in the current + // session by JenaPersistentDataSourceSetup.java. In the code + // below, note that the current getABoxModel() methods on the + // OntModelSelectors return a graph with both ABox and TBox data. - OntModel submodels = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC); + OntModel submodels = ModelFactory.createOntologyModel( + MEM_ONT_MODEL_SPEC); readOntologyFilesInPathSet(SUBMODELS, ctx, submodels); Model tboxAssertions = SDBFactory.connectNamedModel( @@ -540,10 +585,12 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java // Set up the application metadata model Model applicationMetadataModel = SDBFactory.connectNamedModel( - store, JenaDataSourceSetupBase.JENA_APPLICATION_METADATA_MODEL); + store, + JenaDataSourceSetupBase.JENA_APPLICATION_METADATA_MODEL); getAppMetadata(memModel, applicationMetadataModel); - log.info("During initial SDB setup, created an application metadata model of size " - + applicationMetadataModel.size()); + log.info("During initial SDB setup, created an application " + + "metadata model of size " + + applicationMetadataModel.size()); // remove application metadata from ABox model aboxAssertions.remove(applicationMetadataModel); @@ -583,7 +630,10 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java // even if the store exists, it may be empty try { - return (SDBFactory.connectNamedModel(store, JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL)).size() > 0; + return (SDBFactory.connectNamedModel( + store, + JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL)) + .size() > 0; } catch (Exception e) { return false; }