From c0b1713834803b928c2078551671e4366c286cfa Mon Sep 17 00:00:00 2001 From: tpylak <tpylak> Date: Wed, 12 Jan 2011 12:04:11 +0000 Subject: [PATCH] LMS-1942 allow the overview plugin to work for all dataset types which match a given pattern (*.IMG*. for microscopy) SVN: 19386 --- .../DatasetImageOverviewConfiguration.java | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetImageOverviewConfiguration.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetImageOverviewConfiguration.java index 19d855d0aec..4ca3699e385 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetImageOverviewConfiguration.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetImageOverviewConfiguration.java @@ -19,6 +19,7 @@ package ch.systemsx.cisd.openbis.dss.generic.server; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Properties; import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel; @@ -39,7 +40,7 @@ public class DatasetImageOverviewConfiguration private static final String PLUGIN_SERVICE_DEFAULT_KEY = "default"; - private static final String PLUGIN_SERVICE_DATASET_TYPES_KEY = "dataset-types"; + private static final String PLUGIN_SERVICE_DATASET_TYPE_PATTERNS_KEY = "dataset-types"; public static DatasetImageOverviewConfiguration createConfiguration(Properties properties) { @@ -59,23 +60,24 @@ public class DatasetImageOverviewConfiguration configuration.setDefaultPluginService(pluginClassName, props); } else { - List<String> dataSetTypes = - PropertyUtils.getMandatoryList(props, PLUGIN_SERVICE_DATASET_TYPES_KEY); - configuration.addPluginService(pluginClassName, dataSetTypes, props); + List<String> dataSetTypePatterns = + PropertyUtils.getMandatoryList(props, + PLUGIN_SERVICE_DATASET_TYPE_PATTERNS_KEY); + configuration.addPluginService(pluginClassName, dataSetTypePatterns, props); } } return configuration; } - private Map<String, IDatasetImageOverviewPlugin> pluginsByDataSetType = + private Map<String, IDatasetImageOverviewPlugin> pluginsByDataSetTypePattern = new HashMap<String, IDatasetImageOverviewPlugin>(); private IDatasetImageOverviewPlugin defaultPluginOrNull; public IDatasetImageOverviewPlugin getDatasetImageOverviewPlugin(String datasetTypeCode) { - IDatasetImageOverviewPlugin plugin = pluginsByDataSetType.get(datasetTypeCode); + IDatasetImageOverviewPlugin plugin = tryFindPlugin(datasetTypeCode); if (plugin == null) { if (defaultPluginOrNull == null) @@ -92,20 +94,34 @@ public class DatasetImageOverviewConfiguration return plugin; } - private void addPluginService(String pluginClass, List<String> dataSetTypes, + private IDatasetImageOverviewPlugin tryFindPlugin(String datasetTypeCode) + { + for (Entry<String, IDatasetImageOverviewPlugin> entry : pluginsByDataSetTypePattern + .entrySet()) + { + String datasetTypePattern = entry.getKey(); + if (datasetTypeCode.matches(datasetTypePattern)) + { + return entry.getValue(); + } + } + return null; + } + + private void addPluginService(String pluginClass, List<String> dataSetTypePatterns, Properties pluginProperties) { - for (String dataSetType : dataSetTypes) + for (String dataSetTypePattern : dataSetTypePatterns) { - addPluginService(dataSetType, pluginClass, pluginProperties); + addPluginService(dataSetTypePattern, pluginClass, pluginProperties); } } - private void addPluginService(String dataSetType, String pluginClassName, + private void addPluginService(String dataSetTypePattern, String pluginClassName, Properties pluginProperties) { - String normalizedType = dataSetType.toUpperCase(); - IDatasetImageOverviewPlugin oldPluginOrNull = pluginsByDataSetType.get(normalizedType); + String normalizedTypePattern = dataSetTypePattern.toUpperCase(); + IDatasetImageOverviewPlugin oldPluginOrNull = tryFindPlugin(normalizedTypePattern); if (oldPluginOrNull != null) { throw new ConfigurationFailureException( @@ -114,7 +130,7 @@ public class DatasetImageOverviewConfiguration oldPluginOrNull.getClass().getName(), pluginClassName)); } IDatasetImageOverviewPlugin plugin = createPlugin(pluginClassName, pluginProperties); - pluginsByDataSetType.put(normalizedType, plugin); + pluginsByDataSetTypePattern.put(normalizedTypePattern, plugin); } private void setDefaultPluginService(String pluginClassName, Properties pluginProperties) -- GitLab