From 3ea1aa5200172b6dfc853f737cd7ad4619aa6ef6 Mon Sep 17 00:00:00 2001
From: kaloyane <kaloyane>
Date: Fri, 1 Jul 2011 12:30:42 +0000
Subject: [PATCH] admin console tool: add support for registering of EXPERIMENT
 types

SVN: 21947
---
 .../console/RegisterExperimentType.java       | 81 +++++++++++++++++++
 .../generic/client/console/RegisterType.java  |  3 +-
 2 files changed, 83 insertions(+), 1 deletion(-)
 create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/RegisterExperimentType.java

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/RegisterExperimentType.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/RegisterExperimentType.java
new file mode 100644
index 00000000000..667d732a52d
--- /dev/null
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/RegisterExperimentType.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2011 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.client.console;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import ch.systemsx.cisd.openbis.generic.shared.ICommonServer;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExperimentType;
+
+/**
+ * @author Kaloyan Enimanev
+ */
+public class RegisterExperimentType extends AbstractRegisterEntityType<ExperimentType> implements
+        ICommand
+{
+    private enum ExperimentTypeAttributeSetter implements AttributeSetter<ExperimentType>
+    {
+        DESCRIPTION("description")
+        {
+            public void setAttributeFor(ExperimentType experimentType, String value)
+            {
+                experimentType.setDescription(value);
+            }
+        };
+
+        private final String attributeName;
+
+        private ExperimentTypeAttributeSetter(String attributeName)
+        {
+            this.attributeName = attributeName;
+        }
+
+        public String getAttributeName()
+        {
+            return attributeName;
+        }
+
+        public void setDefaultFor(ExperimentType type)
+        {
+        }
+    }
+
+    private static final Map<String, AttributeSetter<ExperimentType>> attributeSetters =
+            new HashMap<String, AttributeSetter<ExperimentType>>();
+
+    static
+    {
+        for (ExperimentTypeAttributeSetter setter : ExperimentTypeAttributeSetter.values())
+        {
+            attributeSetters.put(setter.getAttributeName(), setter);
+        }
+    }
+
+    @Override
+    protected Map<String, AttributeSetter<ExperimentType>> attributeSetters()
+    {
+        return attributeSetters;
+    }
+
+    public void execute(ICommonServer server, String sessionToken, ScriptContext context,
+            String argument)
+    {
+        server.registerExperimentType(sessionToken,
+                prepareEntityType(new ExperimentType(), argument));
+    }
+}
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/RegisterType.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/RegisterType.java
index 414ba57d0f3..3c4f510dfd4 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/RegisterType.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/console/RegisterType.java
@@ -31,8 +31,9 @@ class RegisterType implements ICommand
     RegisterType()
     {
         commands = new HashMap<String, ICommand>();
-        commands.put("DATA_SET", new RegisterDataSetType());
+        commands.put("EXPERIMENT", new RegisterExperimentType());
         commands.put("SAMPLE", new RegisterSampleType());
+        commands.put("DATA_SET", new RegisterDataSetType());
         commands.put("MATERIAL", new RegisterMaterialType());
     }
 
-- 
GitLab