diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ftp/FtpServerConfig.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ftp/FtpServerConfig.java index 9f3ebd8c765eb37f74837124f6daa875990fc714..a11bbff08e082ba12d9786153263baa6b7683d4d 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ftp/FtpServerConfig.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ftp/FtpServerConfig.java @@ -17,8 +17,12 @@ package ch.systemsx.cisd.openbis.dss.generic.server.ftp; import java.io.File; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import java.util.Properties; +import ch.systemsx.cisd.common.utilities.ExtendedProperties; import ch.systemsx.cisd.common.utilities.PropertyUtils; import ch.systemsx.cisd.openbis.dss.generic.server.ConfigParameters; @@ -39,6 +43,8 @@ public class FtpServerConfig private final static String DATASET_DISPLAY_TEMPLATE_KEY = PREFIX + "dataset.display.template"; + private final static String DATASET_FILELIST_SUBPATH_KEY = PREFIX + "dataset.filelist.subpath."; + private static final int DEFAULT_PORT = 2121; private static final boolean DEFAULT_USE_SSL = false; @@ -63,6 +69,9 @@ public class FtpServerConfig private int maxThreads; + private Map<String /* dataset type */, String /* path */> fileListSubPaths = + new HashMap<String, String>(); + public FtpServerConfig(Properties props) { this.startServer = PropertyUtils.getBoolean(props, ENABLE_KEY, false); if (startServer) @@ -82,6 +91,16 @@ public class FtpServerConfig maxThreads = PropertyUtils.getPosInt(props, MAX_THREADS_KEY, DEFAULT_MAX_THREADS); dataSetDisplayTemplate = PropertyUtils.getProperty(props, DATASET_DISPLAY_TEMPLATE_KEY, DEFAULT_DATASET_TEMPLATE); + + ExtendedProperties fileListSubPathProps = + ExtendedProperties.getSubset(props, DATASET_FILELIST_SUBPATH_KEY, true); + for (Object key : fileListSubPathProps.keySet()) + { + String dataSetType = key.toString(); + String subPath = fileListSubPathProps.getProperty(dataSetType); + fileListSubPaths.put(dataSetType, subPath); + + } } private void initializeSSLProperties(Properties props) @@ -136,4 +155,9 @@ public class FtpServerConfig return dataSetDisplayTemplate; } + public Map<String, String> getFileListSubPaths() + { + return Collections.unmodifiableMap(fileListSubPaths); + } + } diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ftp/resolver/TemplateBasedDataSetResourceResolver.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ftp/resolver/TemplateBasedDataSetResourceResolver.java index 3cd9de5630b827e47957e297d25dead082333039..06b3d5a3250f2026672b469169c81bd394f7bfd7 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ftp/resolver/TemplateBasedDataSetResourceResolver.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ftp/resolver/TemplateBasedDataSetResourceResolver.java @@ -75,6 +75,8 @@ public class TemplateBasedDataSetResourceResolver implements IFtpPathResolver, I */ private final String template; + private final Map<String /* dataset type */, String /* subpath */> fileListSubPaths; + private static class DataSetAndFileName { ExternalData dataSet; @@ -87,6 +89,7 @@ public class TemplateBasedDataSetResourceResolver implements IFtpPathResolver, I public TemplateBasedDataSetResourceResolver(FtpServerConfig ftpServerConfig) { this.template = ftpServerConfig.getDataSetDisplayTemplate(); + this.fileListSubPaths = ftpServerConfig.getFileListSubPaths(); } /** @@ -117,9 +120,7 @@ public class TemplateBasedDataSetResourceResolver implements IFtpPathResolver, I IHierarchicalContentProvider provider = ServiceProvider.getHierarchicalContentProvider(); IHierarchicalContent content = provider.asContent(dataSetAndFileName.dataSet.getDataSetCode()); - IHierarchicalContentNode contentNode = - StringUtils.isBlank(relativePath) ? content.getRootNode() : content - .getNode(relativePath); + IHierarchicalContentNode contentNode = content.getNode(relativePath); return new HierarchicalContentToFtpFileAdapter(path, contentNode); } @@ -212,12 +213,14 @@ public class TemplateBasedDataSetResourceResolver implements IFtpPathResolver, I IHierarchicalContentProvider provider = ServiceProvider.getHierarchicalContentProvider(); IHierarchicalContent content = provider.asContent(dataSet.getCode()); - IHierarchicalContentNode rootNode = content.getRootNode(); + String dataSetType = dataSet.getDataSetType().getCode(); + String fileListSubPathOrNull = fileListSubPaths.get(dataSetType); + IHierarchicalContentNode rootNode = content.getNode(fileListSubPathOrNull); - for (String fileName : extractFileNames(rootNode)) + for (IHierarchicalContentNode fileNode : extractFileNames(rootNode)) { - String path = evaluateTemplate(dataSet, fileName); - result.put(fileName, path); + String path = evaluateTemplate(dataSet, fileNode.getName()); + result.put(fileNode.getRelativePath(), path); } return result; @@ -226,23 +229,18 @@ public class TemplateBasedDataSetResourceResolver implements IFtpPathResolver, I /** * @return all values to be used when evaluating the template "${fileName}" variable. */ - private List<String> extractFileNames(IHierarchicalContentNode rootNode) + private List<IHierarchicalContentNode> extractFileNames(IHierarchicalContentNode rootNode) { if (rootNode.isDirectory()) { - List<String> childrenFileNames = new ArrayList<String>(); - for (IHierarchicalContentNode child : rootNode.getChildNodes()) - { - childrenFileNames.add(child.getName()); - } - return childrenFileNames; + return rootNode.getChildNodes(); } else { - return Collections.singletonList(StringUtils.EMPTY); + return Collections.emptyList(); } } - public String evaluateTemplate(ExternalData dataSet, + private String evaluateTemplate(ExternalData dataSet, String fileName) { ExtendedProperties properties = new ExtendedProperties(); @@ -257,6 +255,7 @@ public class TemplateBasedDataSetResourceResolver implements IFtpPathResolver, I return properties.getProperty(templatePropName); } + private String extractDateValue(Date dataSetDate) {