From 5b6345e89c9342a6649b6238be031e3ba7ff286d Mon Sep 17 00:00:00 2001
From: cramakri <cramakri>
Date: Wed, 13 Oct 2010 09:08:19 +0000
Subject: [PATCH] LMS-1811 Implementation of new handlers for CINA.

SVN: 18284
---
 .../registrators/BundleDataSetHelper.java     |  99 ++++-------------
 .../registrators/BundleRegistrationState.java | 101 ++++++++++++++++++
 .../GridPreparationRegistrator.java           |  26 ++++-
 .../ReplicaAnnotatedImagesRegistrator.java    |  14 ++-
 .../registrators/ReplicaRegistrator.java      |   4 +-
 .../BundleStructureConstants.java             |   2 +-
 .../GridPreparationRegistratorTest.java       |  98 +++++++++++++++--
 7 files changed, 246 insertions(+), 98 deletions(-)
 create mode 100644 rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/BundleRegistrationState.java
 rename rtd_cina/source/java/ch/systemsx/cisd/cina/shared/{metadata => constants}/BundleStructureConstants.java (97%)

diff --git a/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/BundleDataSetHelper.java b/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/BundleDataSetHelper.java
index bf184665e60..5fc0b59ec5a 100644
--- a/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/BundleDataSetHelper.java
+++ b/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/BundleDataSetHelper.java
@@ -20,14 +20,11 @@ import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
-import ch.systemsx.cisd.cina.shared.constants.CinaConstants;
 import ch.systemsx.cisd.cina.shared.metadata.IMetadataExtractor;
 import ch.systemsx.cisd.etlserver.IDataSetHandlerRpc;
 import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService;
 import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
-import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetTypeWithVocabularyTerms;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyTypeWithVocabulary;
-import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
 import ch.systemsx.cisd.openbis.generic.shared.dto.NewProperty;
 import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO;
 
@@ -40,83 +37,6 @@ abstract class BundleDataSetHelper
 {
     private static final String MISC_DATA_SET_PROPERTY_CODE = "MISC";
 
-    static class BundleRegistrationState
-    {
-        private final IDataSetHandlerRpc delegator;
-
-        private final SessionContextDTO sessionContext;
-
-        private final IEncapsulatedOpenBISService openbisService;
-
-        private final SampleType gridPrepSampleType;
-
-        private final SampleType replicaSampleType;
-
-        private final DataSetTypeWithVocabularyTerms rawImagesDataSetType;
-
-        private final DataSetTypeWithVocabularyTerms metadataDataSetType;
-
-        private final DataSetTypeWithVocabularyTerms imageDataSetType;
-
-        BundleRegistrationState(IDataSetHandlerRpc delegator,
-                IEncapsulatedOpenBISService openbisService)
-        {
-            this.delegator = delegator;
-            sessionContext = delegator.getSessionContext();
-            this.openbisService = openbisService;
-            this.gridPrepSampleType =
-                    openbisService.getSampleType(CinaConstants.GRID_PREP_SAMPLE_TYPE_CODE);
-            this.replicaSampleType =
-                    openbisService.getSampleType(CinaConstants.REPLICA_SAMPLE_TYPE_CODE);
-            this.rawImagesDataSetType =
-                    openbisService.getDataSetType(CinaConstants.RAW_IMAGES_DATA_SET_TYPE_CODE);
-            this.metadataDataSetType =
-                    openbisService.getDataSetType(CinaConstants.METADATA_DATA_SET_TYPE_CODE);
-            this.imageDataSetType =
-                    openbisService.getDataSetType(CinaConstants.IMAGE_DATA_SET_TYPE_CODE);
-        }
-
-        IDataSetHandlerRpc getDelegator()
-        {
-            return delegator;
-        }
-
-        SessionContextDTO getSessionContext()
-        {
-            return sessionContext;
-        }
-
-        IEncapsulatedOpenBISService getOpenbisService()
-        {
-            return openbisService;
-        }
-
-        SampleType getGridPrepSampleType()
-        {
-            return gridPrepSampleType;
-        }
-
-        SampleType getReplicaSampleType()
-        {
-            return replicaSampleType;
-        }
-
-        DataSetTypeWithVocabularyTerms getRawImagesDataSetType()
-        {
-            return rawImagesDataSetType;
-        }
-
-        DataSetTypeWithVocabularyTerms getMetadataDataSetType()
-        {
-            return metadataDataSetType;
-        }
-
-        DataSetTypeWithVocabularyTerms getImageDataSetType()
-        {
-            return imageDataSetType;
-        }
-    }
-
     protected final BundleRegistrationState globalState;
 
     protected final File dataSet;
@@ -155,6 +75,25 @@ abstract class BundleDataSetHelper
         return bigDataSet;
     }
 
+    /**
+     * Register a file which is already in the store as a data set and add it to the
+     * dataSetInformation collection.
+     * <p>
+     * Since the file is already in the store, the new data set contains a (hard) link to it.
+     * 
+     * @param dataSetFile A file which is already in the store
+     * @return A collection of data set information objects for each data set just registered
+     */
+    protected List<DataSetInformation> registerLinkedDataSet(File dataSetFile,
+            DataSetInformation dataSetInfo)
+    {
+        // Register the given file
+        List<DataSetInformation> bigDataSet =
+                getDelegator().linkAndHandleDataSet(dataSetFile, dataSetInfo);
+        registeredDataSets.addAll(bigDataSet);
+        return bigDataSet;
+    }
+
     protected IEncapsulatedOpenBISService getOpenbisService()
     {
         return globalState.getOpenbisService();
diff --git a/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/BundleRegistrationState.java b/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/BundleRegistrationState.java
new file mode 100644
index 00000000000..b1c069fd711
--- /dev/null
+++ b/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/BundleRegistrationState.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2010 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.cina.dss.bundle.registrators;
+
+import ch.systemsx.cisd.cina.shared.constants.CinaConstants;
+import ch.systemsx.cisd.etlserver.IDataSetHandlerRpc;
+import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetTypeWithVocabularyTerms;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
+import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO;
+
+public class BundleRegistrationState
+{
+    private final IDataSetHandlerRpc delegator;
+
+    private final SessionContextDTO sessionContext;
+
+    private final IEncapsulatedOpenBISService openbisService;
+
+    private final SampleType gridPrepSampleType;
+
+    private final SampleType replicaSampleType;
+
+    private final DataSetTypeWithVocabularyTerms rawImagesDataSetType;
+
+    private final DataSetTypeWithVocabularyTerms metadataDataSetType;
+
+    private final DataSetTypeWithVocabularyTerms imageDataSetType;
+
+    public BundleRegistrationState(IDataSetHandlerRpc delegator,
+            IEncapsulatedOpenBISService openbisService)
+    {
+        this.delegator = delegator;
+        sessionContext = delegator.getSessionContext();
+        this.openbisService = openbisService;
+        this.gridPrepSampleType =
+                openbisService.getSampleType(CinaConstants.GRID_PREP_SAMPLE_TYPE_CODE);
+        this.replicaSampleType =
+                openbisService.getSampleType(CinaConstants.REPLICA_SAMPLE_TYPE_CODE);
+        this.rawImagesDataSetType =
+                openbisService.getDataSetType(CinaConstants.RAW_IMAGES_DATA_SET_TYPE_CODE);
+        this.metadataDataSetType =
+                openbisService.getDataSetType(CinaConstants.METADATA_DATA_SET_TYPE_CODE);
+        this.imageDataSetType =
+                openbisService.getDataSetType(CinaConstants.IMAGE_DATA_SET_TYPE_CODE);
+    }
+
+    IDataSetHandlerRpc getDelegator()
+    {
+        return delegator;
+    }
+
+    SessionContextDTO getSessionContext()
+    {
+        return sessionContext;
+    }
+
+    IEncapsulatedOpenBISService getOpenbisService()
+    {
+        return openbisService;
+    }
+
+    SampleType getGridPrepSampleType()
+    {
+        return gridPrepSampleType;
+    }
+
+    SampleType getReplicaSampleType()
+    {
+        return replicaSampleType;
+    }
+
+    DataSetTypeWithVocabularyTerms getRawImagesDataSetType()
+    {
+        return rawImagesDataSetType;
+    }
+
+    DataSetTypeWithVocabularyTerms getMetadataDataSetType()
+    {
+        return metadataDataSetType;
+    }
+
+    DataSetTypeWithVocabularyTerms getImageDataSetType()
+    {
+        return imageDataSetType;
+    }
+}
\ No newline at end of file
diff --git a/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/GridPreparationRegistrator.java b/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/GridPreparationRegistrator.java
index 0d0fa3feab4..7942d64b873 100644
--- a/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/GridPreparationRegistrator.java
+++ b/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/GridPreparationRegistrator.java
@@ -17,7 +17,9 @@
 package ch.systemsx.cisd.cina.dss.bundle.registrators;
 
 import java.io.File;
+import java.util.List;
 
+import ch.systemsx.cisd.cina.shared.constants.BundleStructureConstants;
 import ch.systemsx.cisd.cina.shared.metadata.BundleMetadataExtractor;
 import ch.systemsx.cisd.cina.shared.metadata.ReplicaMetadataExtractor;
 import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
@@ -70,10 +72,17 @@ public class GridPreparationRegistrator extends BundleDataSetHelper
         for (ReplicaMetadataExtractor replicaMetadataExtractor : bundleMetadataExtractor
                 .getReplicaMetadataExtractors())
         {
-            new ReplicaRegistrator(globalState, replicaMetadataExtractor, gridPrepSample,
-                    gridPrepSampleId, dataSet).register();
+            List<DataSetInformation> childRegisteredDataSets =
+                    new ReplicaRegistrator(globalState, replicaMetadataExtractor, gridPrepSample,
+                            gridPrepSampleId, dataSet).register();
+            getDataSetInformation().addAll(childRegisteredDataSets);
         }
-        // getDataSetInformation\
+
+        // Create a DataSetInformation
+        DataSetInformation metadataDataSetInfo = createDataSetInformation();
+
+        File metadataFile = new File(dataSet, BundleStructureConstants.BUNDLE_METADATA_FILE_NAME);
+        registerDataSet(metadataFile, metadataDataSetInfo);
     }
 
     private void retrieveOrCreateGridPrepSample()
@@ -105,4 +114,15 @@ public class GridPreparationRegistrator extends BundleDataSetHelper
 
         assert gridPrepSample != null;
     }
+
+    private DataSetInformation createDataSetInformation()
+    {
+        DataSetInformation metadataDataSetInfo = new DataSetInformation();
+        metadataDataSetInfo.setSampleCode(gridPrepSampleId.getSampleCode());
+        metadataDataSetInfo.setSpaceCode(gridPrepSampleId.getSpaceLevel().getSpaceCode());
+        metadataDataSetInfo.setInstanceCode(gridPrepSampleId.getSpaceLevel()
+                .getDatabaseInstanceCode());
+        metadataDataSetInfo.setDataSetType(globalState.getMetadataDataSetType().getDataSetType());
+        return metadataDataSetInfo;
+    }
 }
diff --git a/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/ReplicaAnnotatedImagesRegistrator.java b/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/ReplicaAnnotatedImagesRegistrator.java
index 5553a4bb188..adc6e7829d5 100644
--- a/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/ReplicaAnnotatedImagesRegistrator.java
+++ b/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/ReplicaAnnotatedImagesRegistrator.java
@@ -26,7 +26,8 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.NewProperty;
 import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
 
 /**
- * Registers annotated image data sets.
+ * Registers annotated image data sets. The annotated image data sets refer to files that are
+ * already in the store.
  * 
  * @author Chandrasekhar Ramakrishnan
  */
@@ -36,6 +37,15 @@ public class ReplicaAnnotatedImagesRegistrator extends BundleDataSetHelper
 
     private final SampleIdentifier replicaSampleId;
 
+    /**
+     * Constructor.
+     * 
+     * @param globalState The registration state
+     * @param imageMetadataExtractor An image metadata extractor referring to a file that is already
+     *            in the store
+     * @param replicaSample The owning sample of the data set
+     * @param replicaSampleId The owning sample id
+     */
     ReplicaAnnotatedImagesRegistrator(BundleRegistrationState globalState,
             ImageMetadataExtractor imageMetadataExtractor, Sample replicaSample,
             SampleIdentifier replicaSampleId)
@@ -53,7 +63,7 @@ public class ReplicaAnnotatedImagesRegistrator extends BundleDataSetHelper
         // Import the metadata
         ArrayList<NewProperty> properties = createDataSetProperties(imageMetadataExtractor);
         metadataDataSetInfo.setDataSetProperties(properties);
-        registerDataSet(dataSet, metadataDataSetInfo);
+        registerLinkedDataSet(dataSet, metadataDataSetInfo);
 
         return getDataSetInformation();
     }
diff --git a/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/ReplicaRegistrator.java b/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/ReplicaRegistrator.java
index d06500e51a3..0278c672018 100644
--- a/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/ReplicaRegistrator.java
+++ b/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/bundle/registrators/ReplicaRegistrator.java
@@ -73,7 +73,8 @@ public class ReplicaRegistrator extends BundleDataSetHelper
         {
             registerRawImages();
         }
-        registerMetadata();
+        File registeredDataSetFile = registerMetadata();
+        registerAnnotatedImages(registeredDataSetFile);
 
         return getDataSetInformation();
     }
@@ -129,7 +130,6 @@ public class ReplicaRegistrator extends BundleDataSetHelper
         return registrator.getMetadataDataSetFile();
     }
 
-    @SuppressWarnings("unused")
     private void registerAnnotatedImages(File registeredMetadataFile)
     {
         // Create a metadata extractor on the data set in the store (the ivar is a replica metadata
diff --git a/rtd_cina/source/java/ch/systemsx/cisd/cina/shared/metadata/BundleStructureConstants.java b/rtd_cina/source/java/ch/systemsx/cisd/cina/shared/constants/BundleStructureConstants.java
similarity index 97%
rename from rtd_cina/source/java/ch/systemsx/cisd/cina/shared/metadata/BundleStructureConstants.java
rename to rtd_cina/source/java/ch/systemsx/cisd/cina/shared/constants/BundleStructureConstants.java
index 2ddf9d74d5a..2715427c755 100644
--- a/rtd_cina/source/java/ch/systemsx/cisd/cina/shared/metadata/BundleStructureConstants.java
+++ b/rtd_cina/source/java/ch/systemsx/cisd/cina/shared/constants/BundleStructureConstants.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package ch.systemsx.cisd.cina.shared.metadata;
+package ch.systemsx.cisd.cina.shared.constants;
 
 /**
  * Constants that describe the structure fo the CINA bundle files.
diff --git a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/bundle/registrators/GridPreparationRegistratorTest.java b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/bundle/registrators/GridPreparationRegistratorTest.java
index 2feeca594d1..ea7ed9072b1 100644
--- a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/bundle/registrators/GridPreparationRegistratorTest.java
+++ b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/bundle/registrators/GridPreparationRegistratorTest.java
@@ -29,7 +29,6 @@ import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import ch.systemsx.cisd.base.tests.AbstractFileSystemTestCase;
-import ch.systemsx.cisd.cina.dss.bundle.registrators.BundleDataSetHelper.BundleRegistrationState;
 import ch.systemsx.cisd.cina.shared.constants.CinaConstants;
 import ch.systemsx.cisd.etlserver.IDataSetHandlerRpc;
 import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService;
@@ -76,6 +75,8 @@ public class GridPreparationRegistratorTest extends AbstractFileSystemTestCase
     private static final String REPLICA_SAMPLE_IDENTIFIER = DB_CODE + ":/" + SPACE_CODE + "/"
             + REPLICA_SAMPLE_CODE;
 
+    private static final String BUNDLE_METADATA_DATA_SET_CODE = null;
+
     private static abstract class MatcherNoDesc<T> extends BaseMatcher<T>
     {
 
@@ -96,6 +97,12 @@ public class GridPreparationRegistratorTest extends AbstractFileSystemTestCase
 
     private GridPreparationRegistrator registrator;
 
+    private DataSetTypeWithVocabularyTerms rawImagesDataSetTypeWithTerms;
+
+    private DataSetTypeWithVocabularyTerms metadataDataSetTypeWithTerms;
+
+    private DataSetTypeWithVocabularyTerms imageDataSetTypeWithTerms;
+
     @Override
     @BeforeMethod
     public void setUp() throws IOException
@@ -217,7 +224,8 @@ public class GridPreparationRegistratorTest extends AbstractFileSystemTestCase
         setupExistingGridPrepExpectations();
         setupExistingReplicaExpectations();
         setupHandleRawDataSetExpectations("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/RawData/ReplicTest");
-        setupHandleMetadataDataSetExpectations("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/Annotations/ReplicTest");
+        setupHandleReplicaMetadataDataSetExpectations("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/Annotations/ReplicTest");
+        setupHandleBundleMetadataDataSetExpectations("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/BundleMetadata.xml");
 
         createRegistrator(dataSetFile);
         registrator.register();
@@ -238,18 +246,15 @@ public class GridPreparationRegistratorTest extends AbstractFileSystemTestCase
         replicaSampleType.setGeneratedCodePrefix("Replica-");
 
         DataSetType dataSetType = new DataSetType(CinaConstants.IMAGE_DATA_SET_TYPE_CODE);
-        final DataSetTypeWithVocabularyTerms rawImagesDataSetTypeWithTerms =
-                new DataSetTypeWithVocabularyTerms();
+        rawImagesDataSetTypeWithTerms = new DataSetTypeWithVocabularyTerms();
         rawImagesDataSetTypeWithTerms.setDataSetType(dataSetType);
 
         dataSetType = new DataSetType(CinaConstants.METADATA_DATA_SET_TYPE_CODE);
-        final DataSetTypeWithVocabularyTerms metadataDataSetTypeWithTerms =
-                new DataSetTypeWithVocabularyTerms();
+        metadataDataSetTypeWithTerms = new DataSetTypeWithVocabularyTerms();
         metadataDataSetTypeWithTerms.setDataSetType(dataSetType);
 
         dataSetType = new DataSetType(CinaConstants.IMAGE_DATA_SET_TYPE_CODE);
-        final DataSetTypeWithVocabularyTerms imageDataSetTypeWithTerms =
-                new DataSetTypeWithVocabularyTerms();
+        imageDataSetTypeWithTerms = new DataSetTypeWithVocabularyTerms();
         imageDataSetTypeWithTerms.setDataSetType(dataSetType);
 
         externalData = new ExternalData();
@@ -337,6 +342,9 @@ public class GridPreparationRegistratorTest extends AbstractFileSystemTestCase
                                         {
                                             DataSetInformation dataSetInfo =
                                                     (DataSetInformation) item;
+                                            assertEquals(
+                                                    rawImagesDataSetTypeWithTerms.getDataSetType(),
+                                                    dataSetInfo.getDataSetType());
                                             assertEquals(REPLICA_SAMPLE_CODE,
                                                     dataSetInfo.getSampleCode());
                                             return true;
@@ -349,7 +357,7 @@ public class GridPreparationRegistratorTest extends AbstractFileSystemTestCase
             });
     }
 
-    private void setupHandleMetadataDataSetExpectations(final String path)
+    private void setupHandleReplicaMetadataDataSetExpectations(final String path)
     {
         // Create the Raw Images Data Set
         final DataSetInformation dataSetInformation = new DataSetInformation();
@@ -359,14 +367,16 @@ public class GridPreparationRegistratorTest extends AbstractFileSystemTestCase
         dataSetInformation.setInstanceCode(DB_CODE);
 
         externalData = new ExternalData();
-        externalData.setCode("1");
+        externalData.setCode(METADATA_DATA_SET_CODE);
 
         final File dataSetFile = new File(path);
+        final File imageDataSetFile = new File(dataSetFile, "stem_134629_1.imag");
 
         // set up the expectations
         context.checking(new Expectations()
             {
                 {
+                    // Register the metadata data set
                     one(delegator).handleDataSet(with(dataSetFile),
                             with(new MatcherNoDesc<DataSetInformation>()
                                 {
@@ -376,6 +386,9 @@ public class GridPreparationRegistratorTest extends AbstractFileSystemTestCase
                                         {
                                             DataSetInformation dataSetInfo =
                                                     (DataSetInformation) item;
+                                            assertEquals(
+                                                    metadataDataSetTypeWithTerms.getDataSetType(),
+                                                    dataSetInfo.getDataSetType());
                                             assertEquals(REPLICA_SAMPLE_CODE,
                                                     dataSetInfo.getSampleCode());
                                             return true;
@@ -384,10 +397,75 @@ public class GridPreparationRegistratorTest extends AbstractFileSystemTestCase
                                     }
                                 }));
                     will(returnValue(Collections.singletonList(dataSetInformation)));
+
+                    // Retrieve the registered data set from openBIS
                     one(openbisService).tryGetDataSet(SESSION_TOKEN, METADATA_DATA_SET_CODE);
                     will(returnValue(externalData));
+                    // Retrieve the registered data set from the store
                     one(delegator).getFileForExternalData(externalData);
                     will(returnValue(dataSetFile.getParentFile()));
+
+                    // Register the images data set
+                    one(delegator).linkAndHandleDataSet(with(imageDataSetFile),
+                            with(new MatcherNoDesc<DataSetInformation>()
+                                {
+                                    public boolean matches(Object item)
+                                    {
+                                        if (item instanceof DataSetInformation)
+                                        {
+                                            DataSetInformation dataSetInfo =
+                                                    (DataSetInformation) item;
+                                            assertEquals(
+                                                    imageDataSetTypeWithTerms.getDataSetType(),
+                                                    dataSetInfo.getDataSetType());
+                                            assertEquals(REPLICA_SAMPLE_CODE,
+                                                    dataSetInfo.getSampleCode());
+                                            return true;
+                                        }
+                                        return false;
+                                    }
+                                }));
+                    will(returnValue(Collections.singletonList(dataSetInformation)));
+                }
+            });
+    }
+
+    private void setupHandleBundleMetadataDataSetExpectations(final String path)
+    {
+        // Create the Raw Images Data Set
+        final DataSetInformation dataSetInformation = new DataSetInformation();
+        dataSetInformation.setDataSetCode(BUNDLE_METADATA_DATA_SET_CODE);
+        dataSetInformation.setSampleCode(GRID_SAMPLE_CODE);
+        dataSetInformation.setSpaceCode(SPACE_CODE);
+        dataSetInformation.setInstanceCode(DB_CODE);
+
+        final File dataSetFile = new File(path);
+
+        // set up the expectations
+        context.checking(new Expectations()
+            {
+                {
+                    // Register the metadata data set
+                    one(delegator).handleDataSet(with(dataSetFile),
+                            with(new MatcherNoDesc<DataSetInformation>()
+                                {
+                                    public boolean matches(Object item)
+                                    {
+                                        if (item instanceof DataSetInformation)
+                                        {
+                                            DataSetInformation dataSetInfo =
+                                                    (DataSetInformation) item;
+                                            assertEquals(
+                                                    metadataDataSetTypeWithTerms.getDataSetType(),
+                                                    dataSetInfo.getDataSetType());
+                                            assertEquals(GRID_SAMPLE_CODE,
+                                                    dataSetInfo.getSampleCode());
+                                            return true;
+                                        }
+                                        return false;
+                                    }
+                                }));
+                    will(returnValue(Collections.singletonList(dataSetInformation)));
                 }
             });
     }
-- 
GitLab