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

@ -20,7 +20,8 @@ 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";
@ -140,7 +141,8 @@ public class ConfigurationPropertiesSmokeTests implements ServletContextListener
} }
/** /**
* 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, private void checkDefaultNamespace(ServletContext ctx,
ConfigurationProperties props, StartupStatus ss) { ConfigurationProperties props, StartupStatus ss) {
@ -148,14 +150,25 @@ public class ConfigurationPropertiesSmokeTests implements ServletContextListener
if (ns == null || ns.isEmpty()) { if (ns == null || ns.isEmpty()) {
ss.fatal(this, "deploy.properties does not contain a value for '" ss.fatal(this, "deploy.properties does not contain a value for '"
+ PROPERTY_DEFAULT_NAMESPACE + "'"); + PROPERTY_DEFAULT_NAMESPACE + "'");
} else { return;
try {
URI uri = new URI(ns);
} catch (URISyntaxException e) {
ss.fatal(this, PROPERTY_DEFAULT_NAMESPACE + " '" + ns +
"' is not a valid URI. " +
(e.getMessage() != null ? e.getMessage() : ""));
} }
try {
new URI(ns);
} 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
+ "'");
} }
} }

View file

@ -73,8 +73,8 @@ 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 '"
@ -91,8 +91,7 @@ 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 + "'");
} }
} }
@ -100,11 +99,8 @@ public class FileStorageSetup implements ServletContextListener {
} }
/** /**
* 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);
} }