From d3789eda717794f59f3f5f6f2ce542b5c96b0aac Mon Sep 17 00:00:00 2001 From: bdc34 Date: Wed, 6 Oct 2010 21:19:38 +0000 Subject: [PATCH] Adding warning for mismatch of namespace between DB and deploy.properties. NIHVIVO-95 --- .../vitro/webapp/ConfigurationProperties.java | 1 + .../servlet/setup/JenaDataSourceSetup.java | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/ConfigurationProperties.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/ConfigurationProperties.java index e8a48cd5d..18628f4c6 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/ConfigurationProperties.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/ConfigurationProperties.java @@ -179,6 +179,7 @@ public class ConfigurationProperties { return DEFAULT_CONFIG_PATH; } + log.info("deploy.property as specified by JNDI: " + configPath); return configPath; } catch (NamingException e) { log.warn("JNDI lookup failed. " 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 637ec7809..844f8a2c6 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 @@ -2,6 +2,11 @@ package edu.cornell.mannlib.vitro.webapp.servlet.setup; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; @@ -17,7 +22,9 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.util.iterator.ClosableIterator; +import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean; +import edu.cornell.mannlib.vitro.webapp.beans.Portal; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDaoCon; @@ -64,6 +71,8 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java inferenceOms.setDisplayModel(displayModel); unionOms.setDisplayModel(displayModel); + checkForNamespaceMismatch( memModel, defaultNamespace ); + sce.getServletContext().setAttribute("baseOntModel", memModel); WebappDaoFactory baseWadf = new WebappDaoFactoryJena(baseOms, defaultNamespace, null, null); sce.getServletContext().setAttribute("assertionsWebappDaoFactory",baseWadf); @@ -108,6 +117,37 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java } + private void checkForNamespaceMismatch(OntModel model, String defaultNamespace) { + String defaultNamespaceFromDeployProperites = ConfigurationProperties.getProperty("Vitro.defaultNamespace"); + if( defaultNamespaceFromDeployProperites == null ){ + log.error("Could not get namespace from deploy.properties."); + } + + List portalURIs = new ArrayList(); + try { + model.enterCriticalSection(Lock.READ); + Iterator portalIt = model.listIndividuals(PORTAL); + while (portalIt.hasNext()) { + portalURIs.add( ((Individual)portalIt.next()).getURI() ); + } + } finally { + model.leaveCriticalSection(); + } + if( portalURIs.size() > 0 ){ + for( String portalUri : portalURIs){ + if( portalUri != null && ! portalUri.startsWith(defaultNamespaceFromDeployProperites)){ + log.error("Namespace mismatch between db and deploy.properties."); + log.error("Vivo will not start up correctly because the default namespace specified in deploy.properties does not match the namespace of " + + "a portal in the database. Namespace from deploy.properties: \"" + defaultNamespaceFromDeployProperites + + "\" Namespace from an existing portal: \"" + portalUri + "\" To get the application to start with this " + + "database change the default namespace in deploy.properties " + portalUri.substring(0, portalUri.lastIndexOf("/")+1) + + " Another possibility is that deploy.properties does not specify the intended database."); + } + } + } + } + + /* ====================================================================== */