From 9a75effced8e3db0354483498187d502059576ff Mon Sep 17 00:00:00 2001 From: buczekp <buczekp> Date: Thu, 19 Aug 2010 16:08:06 +0000 Subject: [PATCH] [SE-260] new configuration properties for PlasMapper SVN: 17539 --- plasmid/etc/service.properties | 5 ++- .../plasmid/dss/PlasmidStorageProcessor.java | 33 +++++++++++++++---- .../plasmapper/PlasMapperUploader.java | 22 +++++++------ 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/plasmid/etc/service.properties b/plasmid/etc/service.properties index d7a42287c5c..7abaf91824e 100644 --- a/plasmid/etc/service.properties +++ b/plasmid/etc/service.properties @@ -112,9 +112,12 @@ main-thread.type-extractor.default-file-type = PROPRIETARY main-thread.type-extractor.directory-file-type = DIRECTORY # The storage processor (IStorageProcessor implementation) -#main-thread.storage-processor = ch.systemsx.cisd.etlserver.DefaultStorageProcessor main-thread.storage-processor = ch.ethz.bsse.cisd.plasmid.dss.PlasmidStorageProcessor main-thread.storage-processor.processor = ch.systemsx.cisd.etlserver.DefaultStorageProcessor +# path to the root directory of the server where PlasMapper is deployed (webapps in jetty) +main-thread.storage-processor.plasmapper-root-dir = /Users/buczekp/CISD/cifex/jetty/webapps +# the base URL of PlasMapper web application +main-thread.storage-processor.plasmapper-base-url = http://localhost:8082/PlasMapper # The dataset handler (IDataSetHandler implementation) main-thread.dataset-handler = ch.ethz.bsse.cisd.plasmid.dss.PlasmidDataSetHandler diff --git a/plasmid/source/java/ch/ethz/bsse/cisd/plasmid/dss/PlasmidStorageProcessor.java b/plasmid/source/java/ch/ethz/bsse/cisd/plasmid/dss/PlasmidStorageProcessor.java index e7a54a4bf61..1fa593d0346 100644 --- a/plasmid/source/java/ch/ethz/bsse/cisd/plasmid/dss/PlasmidStorageProcessor.java +++ b/plasmid/source/java/ch/ethz/bsse/cisd/plasmid/dss/PlasmidStorageProcessor.java @@ -28,6 +28,7 @@ import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogFactory; import ch.systemsx.cisd.common.mail.IMailClient; +import ch.systemsx.cisd.common.utilities.PropertyUtils; import ch.systemsx.cisd.etlserver.AbstractDelegatingStorageProcessor; import ch.systemsx.cisd.etlserver.ITypeExtractor; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; @@ -50,8 +51,9 @@ public class PlasmidStorageProcessor extends AbstractDelegatingStorageProcessor private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION, PlasmidStorageProcessor.class); - // TODO 2010-08-28, Piotr Buczek: get from properties - private final static String PLASMAPPER_PATH = "/Users/buczekp/CISD/cifex/jetty/webapps"; + private final static String PLASMAPPER_BASE_URL_KEY = "plasmapper-base-url"; + + private final static String PLASMAPPER_ROOT_DIR_KEY = "plasmapper-root-dir"; private static final String ORIGINAL_DIR = "original"; @@ -61,11 +63,28 @@ public class PlasmidStorageProcessor extends AbstractDelegatingStorageProcessor private static final String PNG_FILE_EXTENSION = ".png"; - private PlasMapperUploader uploader = new PlasMapperUploader(); + private final PlasMapperUploader uploader; + + private final String serverRootDir; public PlasmidStorageProcessor(Properties properties) { super(properties); + final String baseUrl = + PropertyUtils.getMandatoryProperty(properties, PLASMAPPER_BASE_URL_KEY); + this.uploader = new PlasMapperUploader(baseUrl); + this.serverRootDir = + PropertyUtils.getMandatoryProperty(properties, PLASMAPPER_ROOT_DIR_KEY); + + final File serverRootFile = new File(serverRootDir); + if ((serverRootFile.isDirectory() && serverRootFile.canRead()) == false) + { + final String msg = + String.format("'%s' (value of '%s' property) is supposed to be a path " + + "to an existing readable directory but isn't.", serverRootDir, + PLASMAPPER_ROOT_DIR_KEY); + throw new EnvironmentFailureException(msg); + } } @Override @@ -110,14 +129,14 @@ public class PlasmidStorageProcessor extends AbstractDelegatingStorageProcessor final File destinationFile) { String outputFilePath = uploader.upload(seqFile, service); - File outputFile = new File(PLASMAPPER_PATH + outputFilePath); + File outputFile = new File(serverRootDir + outputFilePath); if (outputFile.isFile()) { - operationLog.info("Moving file '" + outputFile.getName() + "' from '" + outputFile - + "' to " + destinationFile); + operationLog.info("Renaming and moving file '" + outputFile.getName() + "' from '" + + outputFile + "' to " + destinationFile); if (outputFile.renameTo(destinationFile) == false) { - throw new EnvironmentFailureException("Couldn't move file '" + outputFile + throw new EnvironmentFailureException("Couldn't rename file '" + outputFile + "' to '" + destinationFile + "'."); } } else diff --git a/plasmid/source/java/ch/ethz/bsse/cisd/plasmid/plasmapper/PlasMapperUploader.java b/plasmid/source/java/ch/ethz/bsse/cisd/plasmid/plasmapper/PlasMapperUploader.java index c56d9327548..40cc2b471a2 100644 --- a/plasmid/source/java/ch/ethz/bsse/cisd/plasmid/plasmapper/PlasMapperUploader.java +++ b/plasmid/source/java/ch/ethz/bsse/cisd/plasmid/plasmapper/PlasMapperUploader.java @@ -45,9 +45,8 @@ import ch.systemsx.cisd.common.logging.LogFactory; */ public class PlasMapperUploader { - // http://www.java-tips.org/other-api-tips/httpclient/how-to-use-multipart-post-method-for-uploading.html - private final static String PLASMAPPER_URL = "http://localhost:8082/PlasMapper"; + private final static String DEFAULT_PLASMAPPER_URL = "http://localhost:8082/PlasMapper"; private static Properties createDefaultProperties() { @@ -113,9 +112,9 @@ public class PlasMapperUploader this.servletPath = servletPath; } - String getServiceURL() + String getServletPath() { - return PLASMAPPER_URL + servletPath; + return servletPath; } } @@ -133,20 +132,23 @@ public class PlasMapperUploader public static void main(String[] args) { Properties p = createDefaultProperties(); - PlasMapperUploader uploader = new PlasMapperUploader(p); + PlasMapperUploader uploader = new PlasMapperUploader(DEFAULT_PLASMAPPER_URL, p); uploader.upload(new File("PRS316.gb"), PlasMapperService.GRAPHIC_MAP); } - private Properties properties; + private final String baseUrl; - public PlasMapperUploader(Properties properties) + private final Properties properties; + + public PlasMapperUploader(String baseUrl, Properties properties) { + this.baseUrl = baseUrl; this.properties = properties; } - public PlasMapperUploader() + public PlasMapperUploader(String baseUrl) { - this(createDefaultProperties()); + this(baseUrl, createDefaultProperties()); } /** @@ -159,7 +161,7 @@ public class PlasMapperUploader */ public String upload(File seqFile, PlasMapperService service) { - final PostMethod post = new PostMethod(service.getServiceURL()); + final PostMethod post = new PostMethod(baseUrl + service.getServletPath()); try { Part filePart = new FilePart(FILE_PART_NAME, seqFile); -- GitLab