From 7202ecd794b304fc30a219020ccb54fae7ae8acd Mon Sep 17 00:00:00 2001
From: cramakri <cramakri>
Date: Thu, 5 Jan 2012 15:24:48 +0000
Subject: [PATCH] LMS-2735 Include container information in the DTOs. Necessary
 for InfectX

SVN: 24099
---
 .../openbis/dss/client/api/v1/DataSet.java    | 34 +++++++++++++++++++
 .../dss/client/api/v1/impl/DssComponent.java  | 15 ++++++--
 .../systemtests/OpenbisServiceFacadeTest.java |  9 +++++
 3 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/v1/DataSet.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/v1/DataSet.java
index e47609a106c..336ddb82b03 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/v1/DataSet.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/v1/DataSet.java
@@ -18,6 +18,7 @@ package ch.systemsx.cisd.openbis.dss.client.api.v1;
 
 import java.io.File;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.EnumSet;
 import java.util.HashMap;
@@ -44,6 +45,8 @@ public class DataSet
 
     private ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet metadata;
 
+    private List<DataSet> containedDataSets;
+
     private IDataSetDss dataSetDss;
 
     /* Default constructor needed to create a retry-proxy */
@@ -154,6 +157,37 @@ public class DataSet
         return getMetadata().getChildrenCodes();
     }
 
+    /**
+     * @see ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet#isContainerDataSet()
+     */
+    @Retry
+    public boolean isContainerDataSet()
+    {
+        return getMetadata().isContainerDataSet();
+    }
+
+    /**
+     * @see ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet#isContainerDataSet()
+     */
+    @Retry
+    public List<DataSet> getContainedDataSets()
+    {
+        if (null == containedDataSets)
+        {
+            containedDataSets = new ArrayList<DataSet>();
+            List<ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet> primitiveContainedDataSets =
+                    getMetadata().getContainedDataSets();
+            for (ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet primitiveContainedDataSet : primitiveContainedDataSets)
+            {
+                DataSet containedDataSet =
+                        new DataSet(facade, dssComponent, primitiveContainedDataSet, null);
+                containedDataSets.add(containedDataSet);
+            }
+
+        }
+        return containedDataSets;
+    }
+
     /**
      * @see ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet#equals(java.lang.Object)
      */
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/v1/impl/DssComponent.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/v1/impl/DssComponent.java
index b570166d889..7abdf8cac4f 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/v1/impl/DssComponent.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/v1/impl/DssComponent.java
@@ -497,9 +497,18 @@ class AuthenticatedState extends AbstractDssComponentState
         }
 
         // Get the path
-        String path =
-                dataSetDss.getService().getPathToDataSet(getSessionToken(), dataSetDss.getCode(),
-                        overrideStoreRootPathOrNull);
+
+        String path;
+        try
+        {
+            path =
+                    dataSetDss.getService().getPathToDataSet(getSessionToken(),
+                            dataSetDss.getCode(), overrideStoreRootPathOrNull);
+        } catch (IllegalArgumentException e)
+        {
+            // We could not create a link, return null
+            return null;
+        }
 
         // Check if the file referenced by the path exists, if so return it.
         // NOTE: the path will never exist if the data set is a container.
diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/OpenbisServiceFacadeTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/OpenbisServiceFacadeTest.java
index 3c4ae7584ea..f3e4beb9431 100644
--- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/OpenbisServiceFacadeTest.java
+++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/OpenbisServiceFacadeTest.java
@@ -153,6 +153,15 @@ public class OpenbisServiceFacadeTest extends SystemTestCase
         assertEquals(fileInfoString("original/my-data/data/2.data", 7), files[6].toString());
     }
 
+    @Test(dependsOnMethods = "testPutDataSet")
+    public void testGetDataSetContainedDataSets() throws Exception
+    {
+        DataSet ds = getLatestDataSet();
+
+        List<DataSet> contained = ds.getContainedDataSets();
+        assertEquals(0, contained.size());
+    }
+
     private static String fileInfoString(String startPath, String pathInListing, long length)
     {
         return String.format("FileInfoDssDTO[%s/%s,%s,%d]", startPath, pathInListing,
-- 
GitLab