From ca03d3f931c90da6d459c67f2a220a355ab7ebe3 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Mon, 6 Feb 2012 14:16:01 +0000
Subject: [PATCH] LMS-2766 Introducing property 'disabled-technologies' in
 service.properties to disable technologies in GUI and core plugins.

SVN: 24364
---
 .../AbstractClientPluginFactory.java          |  6 +-
 .../web/client/dto/ApplicationInfo.java       | 14 +++++
 .../web/server/AbstractClientService.java     |  3 +
 .../coreplugin/CorePluginRegistrator.java     | 24 ++++++--
 .../generic/shared/util/ServerUtils.java      | 20 +++++++
 .../source/java/genericApplicationContext.xml |  1 +
 .../generic/shared/util/ServerUtilsTest.java  | 57 +++++++++++++++++++
 .../etc/web-client.properties                 |  2 -
 .../source/java/service.properties            |  3 +
 9 files changed, 119 insertions(+), 11 deletions(-)
 create mode 100644 openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/util/ServerUtilsTest.java

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/AbstractClientPluginFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/AbstractClientPluginFactory.java
index 28ae170514f..edfc4f2e96b 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/AbstractClientPluginFactory.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/AbstractClientPluginFactory.java
@@ -61,10 +61,8 @@ public abstract class AbstractClientPluginFactory<V extends IViewContext<? exten
 
     protected boolean checkEnabledProperty(String technology)
     {
-        String enabledProperty =
-                viewContext.getModel().getApplicationInfo().getWebClientConfiguration()
-                        .getPropertyOrNull(technology, "enabled");
-        return enabledProperty == null || Boolean.TRUE.toString().equals(enabledProperty);
+        return viewContext.getModel().getApplicationInfo().getDisabledTechnologies()
+                .contains(technology) == false;
     }
 
     protected abstract IModule maybeCreateModule();
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/ApplicationInfo.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/ApplicationInfo.java
index d18110e3234..10de72714e2 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/ApplicationInfo.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/ApplicationInfo.java
@@ -16,6 +16,8 @@
 
 package ch.systemsx.cisd.openbis.generic.client.web.client.dto;
 
+import java.util.Set;
+
 import com.google.gwt.user.client.rpc.IsSerializable;
 
 import ch.systemsx.cisd.openbis.generic.shared.basic.annotation.DoNotEscape;
@@ -39,6 +41,8 @@ public final class ApplicationInfo implements IsSerializable
 
     private WebClientConfiguration webClientConfiguration;
 
+    private Set<String> disabledTechnologies;
+
     private int maxResults = 100000;
 
     public int getMaxResults()
@@ -104,4 +108,14 @@ public final class ApplicationInfo implements IsSerializable
         return webClientConfiguration;
     }
 
+    public Set<String> getDisabledTechnologies()
+    {
+        return disabledTechnologies;
+    }
+
+    public void setDisabledTechnologies(Set<String> disabledTechnologies)
+    {
+        this.disabledTechnologies = disabledTechnologies;
+    }
+
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java
index 39f339a443d..d8b86a8ce45 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/AbstractClientService.java
@@ -77,6 +77,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModelColumnHeader;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModelRowWithObject;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.WebClientConfiguration;
 import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO;
+import ch.systemsx.cisd.openbis.generic.shared.util.ServerUtils;
 
 /**
  * An <i>abstract</i> {@link IClientService} implementation.
@@ -431,6 +432,8 @@ public abstract class AbstractClientService implements IClientService,
             applicationInfo.setWebClientConfiguration(commonApplicationInfo
                     .getWebClientConfiguration());
         }
+        applicationInfo.setDisabledTechnologies(ServerUtils.extractSet(getServiceProperties()
+                .getProperty("disabled-technologies")));
         applicationInfo.setArchivingConfigured(isArchivingConfigured());
         applicationInfo.setVersion(getVersion());
         return applicationInfo;
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/coreplugin/CorePluginRegistrator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/coreplugin/CorePluginRegistrator.java
index 9cf99c69f25..fcb9212dd34 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/coreplugin/CorePluginRegistrator.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/coreplugin/CorePluginRegistrator.java
@@ -16,6 +16,9 @@
 
 package ch.systemsx.cisd.openbis.generic.server.coreplugin;
 
+import java.util.HashSet;
+import java.util.Set;
+
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.InitializingBean;
 
@@ -25,6 +28,7 @@ import ch.systemsx.cisd.openbis.generic.server.ICommonServerForInternalUse;
 import ch.systemsx.cisd.openbis.generic.server.coreplugin.CorePluginScanner.ScannerType;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.CorePlugin;
 import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO;
+import ch.systemsx.cisd.openbis.generic.shared.util.ServerUtils;
 
 /**
  * @author Kaloyan Enimanev
@@ -37,6 +41,8 @@ public class CorePluginRegistrator implements InitializingBean
 
     private String pluginsFolderName;
 
+    private Set<String> disabledTechnologies = new HashSet<String>();
+
     /**
      * Loads and installs the deployed core plugins. Invoked from the Spring container after the
      * object is initialized.
@@ -54,12 +60,15 @@ public class CorePluginRegistrator implements InitializingBean
             String sessionToken = getSessionToken();
             for (CorePlugin plugin : pluginScanner.scanForPlugins())
             {
-                try
-                {
-                    commonServer.registerPlugin(sessionToken, plugin, pluginScanner);
-                } catch (Exception ex)
+                if (disabledTechnologies.contains(plugin.getName()) == false)
                 {
-                    operationLog.error("Failed to install core plugin: " + plugin, ex);
+                    try
+                    {
+                        commonServer.registerPlugin(sessionToken, plugin, pluginScanner);
+                    } catch (Exception ex)
+                    {
+                        operationLog.error("Failed to install core plugin: " + plugin, ex);
+                    }
                 }
             }
         }
@@ -75,6 +84,11 @@ public class CorePluginRegistrator implements InitializingBean
         this.pluginsFolderName = pluginsFolderName;
     }
 
+    public void setDisabledTechnologies(String listOfDisabledTechnologies)
+    {
+        disabledTechnologies = ServerUtils.extractSet(listOfDisabledTechnologies);
+    }
+
     public void setCommonServer(ICommonServerForInternalUse commonServer)
     {
         this.commonServer = commonServer;
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/util/ServerUtils.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/util/ServerUtils.java
index e45c9057d35..b6fda36e2c4 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/util/ServerUtils.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/util/ServerUtils.java
@@ -59,4 +59,24 @@ public class ServerUtils
         }
         return duplicated;
     }
+
+    /**
+     * Extracts from the comma-separated list of strings all distinct strings.
+     * 
+     * @return an empty list if the argument is <code>null</code>, an empty string or starts with
+     *         '${'.
+     */
+    public static Set<String> extractSet(String commaSeparatedList)
+    {
+        Set<String> result = new HashSet<String>();
+        if (commaSeparatedList != null && commaSeparatedList.startsWith("${") == false)
+        {
+            String[] terms = commaSeparatedList.split(",");
+            for (String term : terms)
+            {
+                result.add(term.trim());
+            }
+        }
+        return result;
+    }
 }
diff --git a/openbis/source/java/genericApplicationContext.xml b/openbis/source/java/genericApplicationContext.xml
index e37c807da1a..671ac5cf518 100644
--- a/openbis/source/java/genericApplicationContext.xml
+++ b/openbis/source/java/genericApplicationContext.xml
@@ -229,6 +229,7 @@
     <bean id="core-plugin-registrator" class="ch.systemsx.cisd.openbis.generic.server.coreplugin.CorePluginRegistrator">
         <property name="commonServer" ref="common-server"/>
         <property name="pluginsFolderName" value="${core-plugins-folder}"/>
+        <property name="disabledTechnologies" value="${disabled-technologies}"/>
     </bean>
     
     <!--
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/util/ServerUtilsTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/util/ServerUtilsTest.java
new file mode 100644
index 00000000000..508bbc6603f
--- /dev/null
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/util/ServerUtilsTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2012 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.openbis.generic.shared.util;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Set;
+
+import org.testng.AssertJUnit;
+import org.testng.annotations.Test;
+
+/**
+ * @author Franz-Josef Elmer
+ */
+public class ServerUtilsTest extends AssertJUnit
+{
+    @Test
+    public void testExtractSetWithNullArgument()
+    {
+        assertEquals("[]", ServerUtils.extractSet(null).toString());
+    }
+
+    @Test
+    public void testExtractSetWithUnassignedProperty()
+    {
+        assertEquals("[]", ServerUtils.extractSet("${blabla}").toString());
+    }
+
+    @Test
+    public void testExtractSetWithOneElement()
+    {
+        assertEquals("[blabla]", ServerUtils.extractSet("   blabla  ").toString());
+    }
+
+    @Test
+    public void testExtractSetWithThreeElementsOneDuplicated()
+    {
+        Set<String> set = ServerUtils.extractSet("   a,   b,  a  ");
+        ArrayList<String> list = new ArrayList<String>(set);
+        Collections.sort(list);
+        assertEquals("[a, b]", list.toString());
+    }
+}
diff --git a/openbis_standard_technologies/etc/web-client.properties b/openbis_standard_technologies/etc/web-client.properties
index b1908f9ce1b..febe36110a0 100644
--- a/openbis_standard_technologies/etc/web-client.properties
+++ b/openbis_standard_technologies/etc/web-client.properties
@@ -89,7 +89,6 @@ microscopy-dataset-view.hide-file-view = true
 
 technologies = proteomics, screening
 
-#proteomics.enabled = false
 # Relative path of cache. Default value is 'cache'.
 proteomics.cache-folder = ../../../web-client-data-cache
 # Minimum free disk space needed for the cache. Default value is 1 GB.
@@ -97,7 +96,6 @@ proteomics.cache-folder = ../../../web-client-data-cache
 # Maximum retention time. Data older than this time will be removed from cache. Default value is a week.
 #proteomics.maximum-retention-time-in-days = 7
 
-#screening.enabled = false
 screening.image-viewer-enabled = true
 # Material properties of the configured type will be rendered as links 
 # to the material detail view. 
diff --git a/openbis_standard_technologies/source/java/service.properties b/openbis_standard_technologies/source/java/service.properties
index 1c127333ac8..7adbd39f86a 100644
--- a/openbis_standard_technologies/source/java/service.properties
+++ b/openbis_standard_technologies/source/java/service.properties
@@ -72,6 +72,9 @@ hibernate.search.maxResults = 100000
 # If 'async', the update of indices will be done in a separate thread.
 hibernate.search.worker.execution=async
 
+# Comma-separated list of technologies which are disabled. By default all technologies are enabled.
+#disabled-technologies = proteomics
+
 web-client-configuration-file = etc/web-client.properties
 
 core-plugins-folder=dist/core-plugins
-- 
GitLab