From dae9c0c12f62e44d144f49f8c9b3a108bfd80e67 Mon Sep 17 00:00:00 2001 From: brianjlowe Date: Mon, 24 Jun 2013 16:47:46 -0400 Subject: [PATCH] improvements to superclass methods in VClassDaoJena to support VIVO-60 --- .../webapp/dao/WebappDaoFactoryConfig.java | 9 +++++++ .../dao/jena/ObjectPropertyDaoJena.java | 1 - .../webapp/dao/jena/PropertyDaoJena.java | 4 ++-- .../vitro/webapp/dao/jena/VClassDaoJena.java | 24 +++++++++---------- .../vitro/webapp/dao/jena/VClassDaoSDB.java | 4 ++-- .../webapp/dao/jena/WebappDaoFactoryJena.java | 2 +- .../webapp/dao/jena/WebappDaoFactorySDB.java | 2 +- .../webapp/filters/RequestModelsPrep.java | 11 +++++++-- .../individual/GroupedPropertyList.java | 8 +++---- 9 files changed, 40 insertions(+), 25 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactoryConfig.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactoryConfig.java index 72d14454b..aea5acc1c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactoryConfig.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/WebappDaoFactoryConfig.java @@ -12,6 +12,7 @@ public class WebappDaoFactoryConfig { private List preferredLanguages; private String defaultNamespace; private Set nonUserNamespaces; + private boolean isUnderlyingStoreReasoned = false; public WebappDaoFactoryConfig() { preferredLanguages = Arrays.asList("en-US", "en", "EN"); @@ -44,4 +45,12 @@ public class WebappDaoFactoryConfig { this.nonUserNamespaces = nonUserNamespaces; } + public void setUnderlyingStoreReasoned(boolean isReasoned) { + this.isUnderlyingStoreReasoned = isReasoned; + } + + public boolean isUnderlyingStoreReasoned() { + return this.isUnderlyingStoreReasoned; + } + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java index 870a74f85..b1973d45d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java @@ -310,7 +310,6 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp ResultSet rs = qe.execSelect(); if (rs.hasNext()) { QuerySolution qsoln = rs.nextSolution(); - log.debug(qsoln); Resource groupRes = qsoln.getResource("group"); if (groupRes != null) { op.setGroupURI(groupRes.getURI()); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyDaoJena.java index ddf4b9cdd..a457b607c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyDaoJena.java @@ -503,7 +503,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao { List allTypes = ind.getVClasses(false); // include indirect types Set allSuperclassURIs = new HashSet(); - + for (VClass type : allTypes) { String classURI = type.getURI(); if (classURI != null) { @@ -718,7 +718,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao { : (op.getRange() == null && foundRanges[1] != null) ? foundRanges[1] : op.getRange(); - propInsts.add(getPropInstForPropertyAndRange(op, rangeRes, applicableProperties)); + propInsts.add(getPropInstForPropertyAndRange(op, rangeRes, applicableProperties)); List additionalFauxSubpropertyRangeURIs = getAdditionalFauxSubpropertyRangeURIsForPropertyURI(propertyURI); for (String rangeURI : additionalFauxSubpropertyRangeURIs) { if (getWebappDaoFactory().getVClassDao().isSubClassOf(rangeURI, rangeRes.getURI())) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoJena.java index 9252c994f..8c4a20e77 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoJena.java @@ -66,15 +66,21 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener; public class VClassDaoJena extends JenaBaseDao implements VClassDao { protected static final Log log = LogFactory.getLog(VClassDaoJena.class); + private boolean isUnderlyingStoreReasoned = false; - public VClassDaoJena(WebappDaoFactoryJena wadf) { + public VClassDaoJena(WebappDaoFactoryJena wadf, boolean isUnderlyingStoreReasoned) { super(wadf); + this.isUnderlyingStoreReasoned = isUnderlyingStoreReasoned; } @Override protected OntModel getOntModel() { return getOntModelSelector().getTBoxModel(); } + + protected boolean isUnderlyingStoreReasoned() { + return this.isUnderlyingStoreReasoned; + } /* ************************************************** */ @@ -412,14 +418,11 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { List superclassURIs = null; - //String infersTypes = getWebappDaoFactory().getProperties().get("infersTypes"); - //if ("true".equalsIgnoreCase(infersTypes)) { - - PelletListener pl = getWebappDaoFactory().getPelletListener(); - if (pl != null && pl.isConsistent() && !pl.isInErrorState() && !pl.isReasoning()) { + if (isUnderlyingStoreReasoned()) { superclassURIs = new ArrayList(); - OntClass cls = getOntClass(getOntModel(),classURI); - StmtIterator superClassIt = getOntModel().listStatements(cls,RDFS.subClassOf,(RDFNode)null); + Resource cls = ResourceFactory.createResource(classURI); + StmtIterator superClassIt = getOntModel().listStatements( + cls, RDFS.subClassOf, (RDFNode)null); while (superClassIt.hasNext()) { Statement stmt = superClassIt.nextStatement(); if (stmt.getObject().canAs(OntResource.class)) { @@ -766,12 +769,9 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao { } if (superVclass != null) { vClasses.add(superVclass); - String isInferencing = getWebappDaoFactory().getProperties().get("infersTypes"); // if this model infers types based on the taxonomy, adding the subclasses will only // waste time for no benefit - PelletListener pl = getWebappDaoFactory().getPelletListener(); - if (pl == null || !pl.isConsistent() || pl.isInErrorState() || pl.isReasoning() - || isInferencing == null || "false".equalsIgnoreCase(isInferencing)) { + if (!isUnderlyingStoreReasoned()) { Iterator classURIs = getAllSubClassURIs(getClassURIStr(superclass)).iterator(); while (classURIs.hasNext()) { String classURI = (String) classURIs.next(); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoSDB.java index abe8d0bbd..0e97bd923 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoSDB.java @@ -35,8 +35,8 @@ public class VClassDaoSDB extends VClassDaoJena { public VClassDaoSDB(DatasetWrapperFactory datasetWrapperFactory, SDBDatasetMode datasetMode, - WebappDaoFactoryJena wadf) { - super(wadf); + WebappDaoFactoryJena wadf, boolean isUnderlyingStoreReasoned) { + super(wadf, isUnderlyingStoreReasoned); this.dwf = datasetWrapperFactory; this.datasetMode = datasetMode; } 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 6ec54c82e..143f93c61 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 @@ -376,7 +376,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory { protected VClassDao vClassDao = null; public VClassDao getVClassDao() { if( vClassDao == null ) - vClassDao = new VClassDaoJena(this); + vClassDao = new VClassDaoJena(this, config.isUnderlyingStoreReasoned()); return vClassDao; } 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 de66561a8..2ca1c9f77 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 @@ -91,7 +91,7 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { if (vClassDao != null) return vClassDao; else - return vClassDao = new VClassDaoSDB(dwf, datasetMode, this); + return vClassDao = new VClassDaoSDB(dwf, datasetMode, this, config.isUnderlyingStoreReasoned()); } public WebappDaoFactory getUserAwareDaoFactory(String userURI) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/RequestModelsPrep.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/RequestModelsPrep.java index 19fbb148f..001e8e51f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/RequestModelsPrep.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/RequestModelsPrep.java @@ -138,7 +138,7 @@ public class RequestModelsPrep implements Filter { Dataset dataset = new RDFServiceDataset(rdfService); vreq.setDataset(dataset); - WebappDaoFactoryConfig config = createWadfConfig(langs); + WebappDaoFactoryConfig config = createWadfConfig(langs, req); WebappDaoFactory assertions = new WebappDaoFactorySDB(rdfService, ModelAccess.on(ctx).getBaseOntModelSelector(), config, @@ -175,10 +175,11 @@ public class RequestModelsPrep implements Filter { ModelAccess.on(vreq).setWebappDaoFactory(filteredWadf); } - private WebappDaoFactoryConfig createWadfConfig(List langs) { + private WebappDaoFactoryConfig createWadfConfig(List langs, HttpServletRequest req) { WebappDaoFactoryConfig config = new WebappDaoFactoryConfig(); config.setDefaultNamespace(defaultNamespace); config.setPreferredLanguages(langs); + config.setUnderlyingStoreReasoned(isStoreReasoned(req)); return config; } @@ -212,6 +213,12 @@ public class RequestModelsPrep implements Filter { ModelAccess.on(req).setOntModel(id, aware); } } + + private boolean isStoreReasoned(ServletRequest req) { + String isStoreReasoned = ConfigurationProperties.getBean(req).getProperty( + "VitroConnection.DataSource.isStoreReasoned", "true"); + return ("true".equals(isStoreReasoned)); + } @Override public void destroy() { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java index b7e1f1438..e7498e668 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java @@ -86,7 +86,7 @@ public class GroupedPropertyList extends BaseTemplateModel { } populatedObjectPropertyList.addAll(additions); - + propertyList.addAll(populatedObjectPropertyList); // If editing this page, merge in object properties applicable to the individual that are currently @@ -95,7 +95,7 @@ public class GroupedPropertyList extends BaseTemplateModel { if (editing) { mergeAllPossibleObjectProperties(populatedObjectPropertyList, propertyList); } - + // Now do much the same with data properties: get the list of populated data properties, then add in placeholders for missing ones // rjy7 Currently we are getting the list of properties in one sparql query, then doing a separate query // to get values for each property. This could be optimized by doing a single query to get a map of properties to @@ -105,11 +105,11 @@ public class GroupedPropertyList extends BaseTemplateModel { List populatedDataPropertyList = subject .getPopulatedDataPropertyList(); propertyList.addAll(populatedDataPropertyList); - + if (editing) { mergeAllPossibleDataProperties(propertyList); } - + sort(propertyList); // Put the list into groups