NIHVIVO-3995 It is important that the default namespace end in "/individual/". Important enough that it becomes part of the startup smoke tests.

This commit is contained in:
j2blake 2012-10-17 19:09:38 +00:00
parent 52314c4640
commit 7d11a24191
2 changed files with 43 additions and 42 deletions

View file

@ -17,10 +17,11 @@ import javax.servlet.ServletContextListener;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/** /**
* Test that gets run at servlet context startup to check for the existence and * Test that gets run at servlet context startup to check for the existence and
* validity of properties in the configuration. * validity of properties in the configuration.
*/ */
public class ConfigurationPropertiesSmokeTests implements ServletContextListener { public class ConfigurationPropertiesSmokeTests implements
ServletContextListener {
private static final String PROPERTY_HOME_DIRECTORY = "vitro.home.directory"; private static final String PROPERTY_HOME_DIRECTORY = "vitro.home.directory";
private static final String PROPERTY_DB_URL = "VitroConnection.DataSource.url"; private static final String PROPERTY_DB_URL = "VitroConnection.DataSource.url";
@ -138,27 +139,39 @@ public class ConfigurationPropertiesSmokeTests implements ServletContextListener
+ username + "'", e); + username + "'", e);
} }
} }
/** /**
* Confirm that the default namespace is specified and a syntactically valid URI. * Confirm that the default namespace is specified and a syntactically valid
*/ * URI. It should also end with "/individual/".
private void checkDefaultNamespace(ServletContext ctx, */
ConfigurationProperties props, StartupStatus ss) { private void checkDefaultNamespace(ServletContext ctx,
String ns = props.getProperty(PROPERTY_DEFAULT_NAMESPACE); ConfigurationProperties props, StartupStatus ss) {
if (ns == null || ns.isEmpty()) { String ns = props.getProperty(PROPERTY_DEFAULT_NAMESPACE);
ss.fatal(this, "deploy.properties does not contain a value for '" if (ns == null || ns.isEmpty()) {
+ PROPERTY_DEFAULT_NAMESPACE + "'"); ss.fatal(this, "deploy.properties does not contain a value for '"
} else { + PROPERTY_DEFAULT_NAMESPACE + "'");
try { return;
URI uri = new URI(ns); }
} catch (URISyntaxException e) {
ss.fatal(this, PROPERTY_DEFAULT_NAMESPACE + " '" + ns + try {
"' is not a valid URI. " + new URI(ns);
(e.getMessage() != null ? e.getMessage() : "")); } catch (URISyntaxException e) {
} ss.fatal(this,
} PROPERTY_DEFAULT_NAMESPACE + " '" + ns
} + "' is not a valid URI. "
+ (e.getMessage() != null ? e.getMessage() : ""));
return;
}
String suffix = "/individual/";
if (!ns.endsWith(suffix)) {
ss.warning(this,
"Default namespace does not match the expected form "
+ "(does not end with '" + suffix + "'): '" + ns
+ "'");
}
}
@Override @Override
public void contextDestroyed(ServletContextEvent sce) { public void contextDestroyed(ServletContextEvent sce) {
// nothing to do at shutdown // nothing to do at shutdown

View file

@ -73,14 +73,14 @@ public class FileStorageSetup implements ServletContextListener {
* For use by the constructor in implementations of {@link FileStorage}. * For use by the constructor in implementations of {@link FileStorage}.
*/ */
private File figureBaseDir(ServletContextEvent sce) throws IOException { private File figureBaseDir(ServletContextEvent sce) throws IOException {
String homeDirPath = ConfigurationProperties.getBean(sce) String homeDirPath = ConfigurationProperties.getBean(sce).getProperty(
.getProperty(PROPERTY_VITRO_HOME_DIR); PROPERTY_VITRO_HOME_DIR);
if (homeDirPath == null) { if (homeDirPath == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Configuration properties must contain a value for '" "Configuration properties must contain a value for '"
+ PROPERTY_VITRO_HOME_DIR + "'"); + PROPERTY_VITRO_HOME_DIR + "'");
} }
File homeDir = new File(homeDirPath); File homeDir = new File(homeDirPath);
if (!homeDir.exists()) { if (!homeDir.exists()) {
throw new IllegalStateException("Vitro home directory '" throw new IllegalStateException("Vitro home directory '"
@ -91,20 +91,16 @@ public class FileStorageSetup implements ServletContextListener {
if (!baseDir.exists()) { if (!baseDir.exists()) {
boolean created = baseDir.mkdir(); boolean created = baseDir.mkdir();
if (!created) { if (!created) {
throw new IOException( throw new IOException("Unable to create uploads directory at '"
"Unable to create uploads directory at '" + baseDir + "'");
+ baseDir + "'");
} }
} }
return baseDir; return baseDir;
} }
/** /**
* Get the configuration property for the default namespace, and confirm * Get the configuration property for the default namespace. For use by the
* that it is in the proper form. The default namespace is assumed to be in * constructor in implementations of {@link FileStorage}.
* this form: <code>http://vivo.mydomain.edu/individual/</code>
*
* For use by the constructor in implementations of {@link FileStorage}.
* *
* @returns a collection containing the default namespace. * @returns a collection containing the default namespace.
*/ */
@ -117,14 +113,6 @@ public class FileStorageSetup implements ServletContextListener {
+ PROPERTY_DEFAULT_NAMESPACE + "'"); + PROPERTY_DEFAULT_NAMESPACE + "'");
} }
String defaultSuffix = "/individual/";
if (!defaultNamespace.endsWith(defaultSuffix)) {
log.warn("Default namespace does not match the expected form "
+ "(does not end with '" + defaultSuffix + "'): '"
+ defaultNamespace + "'");
}
return Collections.singleton(defaultNamespace); return Collections.singleton(defaultNamespace);
} }