From e6e6cbc015303d5223d8cfe2213c6248623585cc Mon Sep 17 00:00:00 2001
From: buczekp <buczekp>
Date: Fri, 3 Sep 2010 13:16:29 +0000
Subject: [PATCH] [LMS-1690] reverted removal of IMaterialLister method for
 enriching material properties

SVN: 17708
---
 .../bo/materiallister/IMaterialLister.java    |  3 +++
 .../bo/materiallister/MaterialLister.java     | 24 +++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/IMaterialLister.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/IMaterialLister.java
index ee0d01613ac..17a8eb465bb 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/IMaterialLister.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/IMaterialLister.java
@@ -28,6 +28,9 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material;
  */
 public interface IMaterialLister
 {
+    /** fetches and sets all properties of specified materials */
+    void enrichWithProperties(List<Material> materials);
+
     /**
      * Returns a sorted list of {@link Material}s matching given criteria.
      * 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialLister.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialLister.java
index 93d50b69401..4a0232a8f55 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialLister.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialLister.java
@@ -233,4 +233,28 @@ public class MaterialLister implements IMaterialLister
             });
     }
 
+    private static Long2ObjectMap<Material> asMap(Iterable<Material> materials)
+    {
+        Long2ObjectMap<Material> map = new Long2ObjectOpenHashMap<Material>();
+        for (Material material : materials)
+        {
+            map.put(material.getId(), material);
+        }
+        return map;
+    }
+
+    public void enrichWithProperties(List<Material> materials)
+    {
+        setEmptyProperties(materials);
+        enrichWithProperties(asMap(materials));
+    }
+
+    private void setEmptyProperties(List<Material> materials)
+    {
+        for (Material material : materials)
+        {
+            material.setProperties(new ArrayList<IEntityProperty>());
+        }
+    }
+
 }
-- 
GitLab