NIHVIVO-927 Merge 5386 from branch.
This commit is contained in:
parent
7911fa6490
commit
1c62224b6d
3 changed files with 38 additions and 31 deletions
|
@ -3,7 +3,6 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.filestorage.backend;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
|
@ -11,6 +10,9 @@ import javax.servlet.ServletContext;
|
|||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
|
@ -18,6 +20,8 @@ import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
|||
* context.
|
||||
*/
|
||||
public class FileStorageSetup implements ServletContextListener {
|
||||
private static final Log log = LogFactory.getLog(FileStorageSetup.class);
|
||||
|
||||
/**
|
||||
* The implementation of the {@link FileStorage} system will be stored in
|
||||
* the {@link ServletContext} as an attribute with this name.
|
||||
|
@ -43,18 +47,16 @@ public class FileStorageSetup implements ServletContextListener {
|
|||
*/
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
FileStorage fs;
|
||||
try {
|
||||
File baseDirectory = figureBaseDir();
|
||||
Collection<String> fileNamespace = confirmDefaultNamespace();
|
||||
fs = new FileStorageImpl(baseDirectory, fileNamespace);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(
|
||||
"Failed to initialize the file system.", e);
|
||||
}
|
||||
FileStorage fs = new FileStorageImpl(baseDirectory, fileNamespace);
|
||||
|
||||
ServletContext sc = sce.getServletContext();
|
||||
sc.setAttribute(ATTRIBUTE_NAME, fs);
|
||||
ServletContext sc = sce.getServletContext();
|
||||
sc.setAttribute(ATTRIBUTE_NAME, fs);
|
||||
} catch (Exception e) {
|
||||
log.fatal("Failed to initialize the file system.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -52,10 +52,9 @@ public class UpdateUploadedFiles implements ServletContextListener {
|
|||
+ "The ServletContext does not contain an attribute "
|
||||
+ "for '" + "webappDaoFactory" + "'. "
|
||||
+ "Does the log contain a previous exception from "
|
||||
+ "JenaDataSourceSetup? Have you looked in "
|
||||
+ "localhost.log for such an exception? Is it "
|
||||
+ "possible that web.xml is not set up to run "
|
||||
+ "JenaDataSourceSetup before UpdateUploadedFiles?");
|
||||
+ "JenaDataSourceSetup? Is it possible that web.xml "
|
||||
+ "is not set up to run JenaDataSourceSetup before "
|
||||
+ "UpdateUploadedFiles?");
|
||||
}
|
||||
|
||||
OntModel jenaOntModel = (OntModel) ctx
|
||||
|
@ -65,10 +64,9 @@ public class UpdateUploadedFiles implements ServletContextListener {
|
|||
+ "The ServletContext does not contain an attribute "
|
||||
+ "for '" + JENA_ONT_MODEL_ATTRIBUTE_NAME + "'. "
|
||||
+ "Does the log contain a previous exception from "
|
||||
+ "JenaDataSourceSetup? Have you looked in "
|
||||
+ "localhost.log for such an exception? Is it "
|
||||
+ "possible that web.xml is not set up to run "
|
||||
+ "JenaDataSourceSetup before UpdateUploadedFiles?");
|
||||
+ "JenaDataSourceSetup? Is it possible that web.xml "
|
||||
+ "is not set up to run JenaDataSourceSetup before "
|
||||
+ "UpdateUploadedFiles?");
|
||||
}
|
||||
|
||||
FileStorage fileStorage = (FileStorage) ctx
|
||||
|
@ -78,10 +76,9 @@ public class UpdateUploadedFiles implements ServletContextListener {
|
|||
+ "The ServletContext does not contain an attribute "
|
||||
+ "for '" + FileStorageSetup.ATTRIBUTE_NAME + "'. "
|
||||
+ "Does the log contain a previous exception from "
|
||||
+ "FileStorageSetup? Have you looked in "
|
||||
+ "localhost.log for such an exception? Is it "
|
||||
+ "possible that web.xml is not set up to run "
|
||||
+ "FileStorageSetup before UpdateUploadedFiles?");
|
||||
+ "FileStorageSetup? Is it possible that web.xml is "
|
||||
+ "not set up to run FileStorageSetup before "
|
||||
+ "UpdateUploadedFiles?");
|
||||
}
|
||||
|
||||
String uploadDirectoryName = ConfigurationProperties
|
||||
|
@ -104,8 +101,7 @@ public class UpdateUploadedFiles implements ServletContextListener {
|
|||
fileStorage, uploadDirectory, webappImageDirectory);
|
||||
fsu.update();
|
||||
} catch (Exception e) {
|
||||
log.error("Unknown problem", e);
|
||||
throw new RuntimeException(e);
|
||||
log.fatal("Unknown problem", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.filestorage.backend;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -57,8 +58,8 @@ public class FileStorageSetupTest extends AbstractTestClass {
|
|||
System.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY,
|
||||
InitialContextFactoryStub.class.getName());
|
||||
InitialContextStub.reset();
|
||||
new InitialContext().bind("java:comp/env/path.configuration", propsFile
|
||||
.getPath());
|
||||
new InitialContext().bind("java:comp/env/path.configuration",
|
||||
propsFile.getPath());
|
||||
}
|
||||
|
||||
@Before
|
||||
|
@ -77,29 +78,37 @@ public class FileStorageSetupTest extends AbstractTestClass {
|
|||
// tests
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void baseDirectoryNotSpecified() {
|
||||
setConfigurationProperties(null, "http://vivo.myDomain.edu/individual/");
|
||||
fss.contextInitialized(sce);
|
||||
assertNull("no base directory",
|
||||
sc.getAttribute(FileStorageSetup.ATTRIBUTE_NAME));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void baseDirectoryDoesntExist() throws IOException {
|
||||
setConfigurationProperties("/bogus/Directory",
|
||||
"http://vivo.myDomain.edu/individual/");
|
||||
fss.contextInitialized(sce);
|
||||
assertNull("no such directory",
|
||||
sc.getAttribute(FileStorageSetup.ATTRIBUTE_NAME));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void defaultNamespaceNotSpecified() {
|
||||
setConfigurationProperties(tempDir.getPath(), null);
|
||||
fss.contextInitialized(sce);
|
||||
assertNull("no default namespace",
|
||||
sc.getAttribute(FileStorageSetup.ATTRIBUTE_NAME));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void defaultNamespaceIsBogus() throws IOException {
|
||||
setConfigurationProperties(tempDir.getPath(), "namespace");
|
||||
fss.contextInitialized(sce);
|
||||
assertNull("default namespace is bogus",
|
||||
sc.getAttribute(FileStorageSetup.ATTRIBUTE_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -111,8 +120,8 @@ public class FileStorageSetupTest extends AbstractTestClass {
|
|||
Object o = sc.getAttribute(FileStorageSetup.ATTRIBUTE_NAME);
|
||||
FileStorage fs = (FileStorage) o;
|
||||
|
||||
assertEquals("implementation class", FileStorageImpl.class, fs
|
||||
.getClass());
|
||||
assertEquals("implementation class", FileStorageImpl.class,
|
||||
fs.getClass());
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Reference in a new issue