From 49ea49bcf55ca38635c38e18cd6fa8580ef04b46 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Wed, 2 Feb 2011 12:25:10 +0000
Subject: [PATCH] Managed Properties API: Also input lists turned into arrays.
 Test fixed. EntityLinkElementKind: Attribute label added.

SVN: 19703
---
 .../api/EntityLinkElementKind.java            | 21 ++++++++++++++++---
 .../shared/managed_property/api/IElement.java |  3 +--
 .../api/IStructuredPropertyConverter.java     |  4 +---
 .../managed_property/structured/Element.java  |  5 +++--
 .../XmlStructuredPropertyConverter.java       |  6 +++---
 .../XmlStructuredPropertyConverterTest.java   |  4 ++--
 6 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/api/EntityLinkElementKind.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/api/EntityLinkElementKind.java
index b17d88ec692..6007831c8d5 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/api/EntityLinkElementKind.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/api/EntityLinkElementKind.java
@@ -25,15 +25,22 @@ package ch.systemsx.cisd.openbis.generic.shared.managed_property.api;
 public enum EntityLinkElementKind
 {
 
-    EXPERIMENT("Experiment"), SAMPLE("Sample"), DATA_SET("Dataset"), MATERIAL("Material");
+    EXPERIMENT("Experiment"), SAMPLE("Sample"), DATA_SET("Dataset", "Data Set"), MATERIAL("Material");
 
-    private String elementName;
+    private final String elementName;
+    private final String label;
 
     private EntityLinkElementKind(String elementName)
     {
-        this.elementName = elementName;
+        this(elementName, elementName);
     }
 
+    private EntityLinkElementKind(String elementName, String label)
+    {
+        this.elementName = elementName;
+        this.label = label;
+    }
+    
     /**
      * the {@link IElement} name corresponding to the link.
      */
@@ -42,6 +49,14 @@ public enum EntityLinkElementKind
         return elementName;
     }
 
+    /**
+     * Returns the label.
+     */
+    public String getLabel()
+    {
+        return label;
+    }
+
     /**
      * @return the {@link EntityLinkElementKind} for a given element name or <code>null</code> if no
      *         matching kind exists.
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/api/IElement.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/api/IElement.java
index cf86fbf4c15..6ecf83ea157 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/api/IElement.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/api/IElement.java
@@ -16,7 +16,6 @@
 
 package ch.systemsx.cisd.openbis.generic.shared.managed_property.api;
 
-import java.util.List;
 import java.util.Map;
 
 /**
@@ -69,7 +68,7 @@ public interface IElement
     /**
      * sets the children of this {@link IElement}, replacing any previously existing children.
      */
-    IElement setChildren(List<IElement> children);
+    IElement setChildren(IElement[] children);
 
     /**
      * appends a list of children to this children elements list.
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/api/IStructuredPropertyConverter.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/api/IStructuredPropertyConverter.java
index de7436e3576..edcaf13a56d 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/api/IStructuredPropertyConverter.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/api/IStructuredPropertyConverter.java
@@ -16,8 +16,6 @@
 
 package ch.systemsx.cisd.openbis.generic.shared.managed_property.api;
 
-import java.util.List;
-
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedProperty;
 import ch.systemsx.cisd.openbis.generic.shared.managed_property.structured.Element;
 
@@ -39,6 +37,6 @@ public interface IStructuredPropertyConverter
      * @return a {@link String} representation of the specified elements that can be persisted in
      *         the database. 
      */
-    String convertToString(List<IElement> elements);
+    String convertToString(IElement[] elements);
 
 }
\ No newline at end of file
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/Element.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/Element.java
index 41fbfd07ab2..ec63d87f3df 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/Element.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/Element.java
@@ -17,6 +17,7 @@
 package ch.systemsx.cisd.openbis.generic.shared.managed_property.structured;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -86,10 +87,10 @@ public class Element implements IElement
     }
 
 
-    public IElement setChildren(List<IElement> newChildren)
+    public IElement setChildren(IElement[] newChildren)
     {
         assert newChildren != null : "Setting null children is not allowed.";
-        this.children = newChildren;
+        this.children = new ArrayList<IElement>(Arrays.asList(newChildren));
         return this;
     }
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/XmlStructuredPropertyConverter.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/XmlStructuredPropertyConverter.java
index 85b7f99f4ea..1e3cd4d0f1f 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/XmlStructuredPropertyConverter.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/XmlStructuredPropertyConverter.java
@@ -78,7 +78,7 @@ public class XmlStructuredPropertyConverter implements IStructuredPropertyConver
         return root.getChildren();
     }
 
-    public String convertToString(List<IElement> elements)
+    public String convertToString(IElement[] elements)
     {
         IElement root = createRootElement(elements);
         Document doc = createEmptyDocument();
@@ -88,7 +88,7 @@ public class XmlStructuredPropertyConverter implements IStructuredPropertyConver
         return XmlUtils.serializeDocument(doc);
     }
 
-    private IElement createRootElement(List<IElement> elements)
+    private IElement createRootElement(IElement[] elements)
     {
         IElement root = new Element(ROOT_NAME);
         root.addAttribute("xmlns:" + OPENBIS_NS, OPENBIS_NAMESPACE_URL);
@@ -150,7 +150,7 @@ public class XmlStructuredPropertyConverter implements IStructuredPropertyConver
 
         }
 
-        result.setChildren(children);
+        result.setChildren(children.toArray(new IElement[children.size()]));
         return result;
     }
 
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/XmlStructuredPropertyConverterTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/XmlStructuredPropertyConverterTest.java
index 7157515e59c..9032931a23f 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/XmlStructuredPropertyConverterTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/XmlStructuredPropertyConverterTest.java
@@ -49,7 +49,7 @@ public class XmlStructuredPropertyConverterTest extends AssertJUnit
                                 "materialAttrKey", "materialAttrVal")
         );
 
-        String persistentValue = converter.convertToString(elements);
+        String persistentValue = converter.convertToString(elements.toArray(new IElement[0]));
         IElement[] deserialized = converter.convertStringToElements(persistentValue);
 
         assertEquals(elements, Arrays.asList(deserialized));
@@ -70,7 +70,7 @@ public class XmlStructuredPropertyConverterTest extends AssertJUnit
                         factory.createMaterialLink("materialCode", "typeCode").addChildren(
                                 factory.createElement("nested2").addAttribute("na2", "nav2")));
 
-        String persistentValue = converter.convertToString(elements);
+        String persistentValue = converter.convertToString(elements.toArray(new IElement[0]));
         IElement[] deserialized = converter.convertStringToElements(persistentValue);
 
         assertEquals(elements, Arrays.asList(deserialized));
-- 
GitLab