From fc90157f4e0d948b5101bc52d169a6c90d111245 Mon Sep 17 00:00:00 2001
From: cramakri <cramakri>
Date: Tue, 9 Mar 2010 15:11:34 +0000
Subject: [PATCH] LMS-1398 Made the properties files more uniform between
 experiment registration and sample registration. Fixed problems with sample
 registration.

SVN: 15086
---
 .../dss/info/CinaDataSetInfoExtractor.java    |  4 +--
 .../dss/info/ExperimentMetadataExtractor.java | 32 +++++++++++--------
 .../dss/info/SampleMetadataExtractor.java     | 13 ++++----
 .../info/ExperimentMetadataExtractorTest.java | 32 ++++++++++++-------
 .../dss/info/SampleMetadataExtractorTest.java | 16 ++++++----
 .../experiment.properties                     |  4 +--
 6 files changed, 57 insertions(+), 44 deletions(-)

diff --git a/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/info/CinaDataSetInfoExtractor.java b/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/info/CinaDataSetInfoExtractor.java
index d7a7ec8ec11..3ddd1f239b9 100644
--- a/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/info/CinaDataSetInfoExtractor.java
+++ b/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/info/CinaDataSetInfoExtractor.java
@@ -147,8 +147,8 @@ public class CinaDataSetInfoExtractor implements IDataSetInfoExtractor
         Calendar now = GregorianCalendar.getInstance();
         StringBuffer sb = new StringBuffer();
         sb.append(now.get(Calendar.YEAR));
-        sb.append(now.get(Calendar.MONTH));
-        sb.append(now.get(Calendar.DAY_OF_MONTH));
+        sb.append(String.format("%02d", now.get(Calendar.MONTH) + 1));
+        sb.append(String.format("%02d", now.get(Calendar.DAY_OF_MONTH)));
         sb.append(now.get(Calendar.HOUR_OF_DAY));
         sb.append(now.get(Calendar.MINUTE));
         return sb.toString();
diff --git a/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/info/ExperimentMetadataExtractor.java b/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/info/ExperimentMetadataExtractor.java
index 132ec1004ac..963cf597578 100644
--- a/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/info/ExperimentMetadataExtractor.java
+++ b/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/info/ExperimentMetadataExtractor.java
@@ -25,6 +25,8 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment;
 import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier;
+import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ProjectIdentifier;
+import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ProjectIdentifierFactory;
 
 /**
  * Package-visible helper class to extract information from the XML metadata file and register a new
@@ -35,9 +37,9 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifi
 class ExperimentMetadataExtractor
 {
     // Keys expected in metadata properties file
-    public static final String PROJECT_CODE_KEY = "project.code";
+    public static final String PROJECT_IDENTIFIER_KEY = "project.identifier";
 
-    public static final String EXPERIMENT_CODE_KEY = "experiment.code";
+    public static final String EXPERIMENT_CODE_KEY = "experiment.code-prefix";
 
     public static final String EXPERIMENT_OWNER_EMAIL_KEY = "experiment.owner-email";
 
@@ -51,14 +53,12 @@ class ExperimentMetadataExtractor
     private final IEncapsulatedOpenBISService openbisService;
 
     // Internal state used during extraction
-    private String projectCode;
+    private ProjectIdentifier projectIdentifier;
 
     private String experimentCodePrefix;
 
     private String emailAddress;
 
-    static final String SPACE_CODE = "CINA";
-
     static final String EXPERIMENT_TYPE_CODE = "CINA_EXP_TYPE";
 
     static final String SAMPLE_TYPE_CODE = "CINA_SAMPLE_TYPE";
@@ -96,7 +96,11 @@ class ExperimentMetadataExtractor
 
     private void extractMetadata()
     {
-        projectCode = experimentMetadata.get(PROJECT_CODE_KEY);
+        String projectIdString = experimentMetadata.get(PROJECT_IDENTIFIER_KEY);
+        if (projectIdString != null)
+        {
+            projectIdentifier = new ProjectIdentifierFactory(projectIdString).createIdentifier();
+        }
         experimentCodePrefix = experimentMetadata.get(EXPERIMENT_CODE_KEY);
         emailAddress = experimentMetadata.get(EXPERIMENT_OWNER_EMAIL_KEY);
     }
@@ -106,22 +110,22 @@ class ExperimentMetadataExtractor
      */
     private ExperimentIdentifier createExperiment() throws EnvironmentFailureException
     {
-        ExperimentIdentifier identifier =
-                new ExperimentIdentifier(null, SPACE_CODE, projectCode, experimentCodePrefix + "-"
+        ExperimentIdentifier experimentIdentifier =
+                new ExperimentIdentifier(projectIdentifier, experimentCodePrefix + "-"
                         + experimentCodeSuffix);
 
         // Check that the identifier is unique
-        Experiment experiment = openbisService.tryToGetExperiment(identifier);
+        Experiment experiment = openbisService.tryToGetExperiment(experimentIdentifier);
         if (experiment != null)
         {
             throw new EnvironmentFailureException(
                     "The generated experiment identifer, which must be unique, is already in the database. This should not happen: Please contact the administrator.");
         }
 
-        openbisService.registerExperiment(new NewExperiment(identifier.toString(),
+        openbisService.registerExperiment(new NewExperiment(experimentIdentifier.toString(),
                 EXPERIMENT_TYPE_CODE));
 
-        return identifier;
+        return experimentIdentifier;
     }
 
     /**
@@ -130,16 +134,16 @@ class ExperimentMetadataExtractor
      */
     private void verifyRequiredMetadataDataHasBeenProvided() throws UserFailureException
     {
-        if (null == projectCode)
+        if (null == projectIdentifier)
         {
             throw new UserFailureException(
-                    "A project code must be specified to register an experiment.");
+                    "A project identifier must be specified to register an experiment.");
         }
 
         if (null == experimentCodePrefix)
         {
             throw new UserFailureException(
-                    "An experiment code must be specified to register an experiment.");
+                    "An experiment code prefix must be specified to register an experiment.");
         }
 
         if (null == emailAddress)
diff --git a/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/info/SampleMetadataExtractor.java b/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/info/SampleMetadataExtractor.java
index 6e5e96bab78..b147ce7ed99 100644
--- a/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/info/SampleMetadataExtractor.java
+++ b/rtd_cina/source/java/ch/systemsx/cisd/cina/dss/info/SampleMetadataExtractor.java
@@ -28,8 +28,8 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
 import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier;
 import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifierFactory;
+import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.GroupIdentifier;
 import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
-import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleOwnerIdentifier;
 
 /**
  * Package-visible helper class to extract information from the XML metadata file and register a new
@@ -43,8 +43,6 @@ class SampleMetadataExtractor
 {
     // Keys expected in metadata properties file
 
-    public static final String PROJECT_CODE_KEY = ExperimentMetadataExtractor.PROJECT_CODE_KEY;
-
     public static final String EXPERIMENT_IDENTIFIER_KEY = "experiment.identifier";
 
     public static final String EXPERIMENT_OWNER_EMAIL_KEY =
@@ -98,6 +96,7 @@ class SampleMetadataExtractor
 
         SampleIdentifier sampleId = this.createSample();
         dataSetInformation.setExperimentIdentifier(experimentIdentifier);
+        dataSetInformation.setGroupCode(sampleId.getGroupLevel().getGroupCode());
         dataSetInformation.setSampleCode(sampleId.getSampleCode());
         dataSetInformation.setUploadingUserEmail(emailAddress);
     }
@@ -134,8 +133,8 @@ class SampleMetadataExtractor
         }
 
         SampleIdentifier sampleId =
-                SampleIdentifier.createOwnedBy(new SampleOwnerIdentifier(experimentIdentifier),
-                        sampleCodePrefix + "-" + sampleCodeSuffix);
+                new SampleIdentifier(new GroupIdentifier((String) null, experimentIdentifier
+                        .getGroupCode()), sampleCodePrefix + "-" + sampleCodeSuffix);
 
         NewSample sample = new NewSample();
         SampleType sampleType = new SampleType();
@@ -165,13 +164,13 @@ class SampleMetadataExtractor
         if (null == experimentIdentifier)
         {
             throw new UserFailureException(
-                    "An experiment code must be specified to register an experiment.");
+                    "An experiment identifier must be specified to register an experiment.");
         }
 
         if (null == sampleCodePrefix)
         {
             throw new UserFailureException(
-                    "An sample code must be specified to register an experiment.");
+                    "An sample code prefix must be specified to register an experiment.");
         }
 
         if (null == emailAddress)
diff --git a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/info/ExperimentMetadataExtractorTest.java b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/info/ExperimentMetadataExtractorTest.java
index 911086f0428..8fcee75876f 100644
--- a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/info/ExperimentMetadataExtractorTest.java
+++ b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/info/ExperimentMetadataExtractorTest.java
@@ -32,6 +32,8 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment;
 import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier;
+import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ProjectIdentifier;
+import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ProjectIdentifierFactory;
 
 /**
  * @author Chandrasekhar Ramakrishnan
@@ -66,18 +68,21 @@ public class ExperimentMetadataExtractorTest extends AssertJUnit
     @Test
     public void testSuccessfulExperimentRegistration()
     {
-        final String projectCode = "CINA1";
-        final String experimentCode = "EXP";
+        final String projectIdString = "/CINA/CINA1";
+        final String experimentCodePrefix = "EXP";
         final String experimentCodeSuffix = "SUFFIX";
         final String ownerEmail = "no-one@nowhere.ch";
 
         final HashMap<String, String> experimentMetadata = new HashMap<String, String>();
-        experimentMetadata.put("project.code", projectCode);
-        experimentMetadata.put("experiment.code", experimentCode);
+        experimentMetadata.put("project.identifier", projectIdString);
+        experimentMetadata.put("experiment.code-prefix", experimentCodePrefix);
         experimentMetadata.put("experiment.owner-email", ownerEmail);
 
+        final ProjectIdentifier projectIdentifier =
+                new ProjectIdentifierFactory(projectIdString).createIdentifier();
+
         final ExperimentIdentifier identifier =
-                new ExperimentIdentifier(null, "CINA", projectCode, experimentCode + "-"
+                new ExperimentIdentifier(projectIdentifier, experimentCodePrefix + "-"
                         + experimentCodeSuffix);
         final NewExperiment newExperiment =
                 new NewExperiment(identifier.toString(), "CINA_EXP_TYPE");
@@ -94,7 +99,7 @@ public class ExperimentMetadataExtractorTest extends AssertJUnit
                 new ExperimentMetadataExtractor(dataSetInformation, experimentMetadata,
                         experimentCodeSuffix, openbisService);
         extractor.processMetadataAndFillDataSetInformation();
-        assertTrue(ownerEmail.equals(dataSetInformation.tryGetUploadingUserEmail()));
+        assertEquals(ownerEmail, dataSetInformation.tryGetUploadingUserEmail());
 
         context.assertIsSatisfied();
     }
@@ -106,18 +111,21 @@ public class ExperimentMetadataExtractorTest extends AssertJUnit
     @Test
     public void testDuplicateExperimentRegistration()
     {
-        final String projectCode = "CINA1";
-        final String experimentCode = "EXP";
+        final String projectIdString = "/CINA/CINA1";
+        final String experimentCodePrefix = "EXP";
         final String experimentCodeSuffix = "SUFFIX";
         final String ownerEmail = "no-one@nowhere.ch";
 
         final HashMap<String, String> experimentMetadata = new HashMap<String, String>();
-        experimentMetadata.put("project.code", projectCode);
-        experimentMetadata.put("experiment.code", experimentCode);
+        experimentMetadata.put("project.identifier", projectIdString);
+        experimentMetadata.put("experiment.code-prefix", experimentCodePrefix);
         experimentMetadata.put("experiment.owner-email", ownerEmail);
 
+        final ProjectIdentifier projectIdentifier =
+                new ProjectIdentifierFactory(projectIdString).createIdentifier();
+
         final ExperimentIdentifier identifier =
-                new ExperimentIdentifier(null, "CINA", projectCode, experimentCode + "-"
+                new ExperimentIdentifier(projectIdentifier, experimentCodePrefix + "-"
                         + experimentCodeSuffix);
         final Experiment existingExperiment = new Experiment();
         context.checking(new Expectations()
@@ -139,7 +147,7 @@ public class ExperimentMetadataExtractorTest extends AssertJUnit
         {
             // this should happen
         }
-        assertTrue(ownerEmail.equals(dataSetInformation.tryGetUploadingUserEmail()));
+        assertEquals(ownerEmail, dataSetInformation.tryGetUploadingUserEmail());
 
         context.assertIsSatisfied();
     }
diff --git a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/info/SampleMetadataExtractorTest.java b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/info/SampleMetadataExtractorTest.java
index 1b334fadc18..491e2775934 100644
--- a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/info/SampleMetadataExtractorTest.java
+++ b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/info/SampleMetadataExtractorTest.java
@@ -35,6 +35,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
 import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier;
 import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifierFactory;
+import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.GroupIdentifier;
 import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
 import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleOwnerIdentifier;
 
@@ -87,8 +88,8 @@ public class SampleMetadataExtractorTest extends AssertJUnit
         experiment.setIdentifier(experimentIdentifier.toString());
 
         final SampleIdentifier sampleIdentifier =
-                SampleIdentifier.createOwnedBy(new SampleOwnerIdentifier(experimentIdentifier),
-                        sampleCodePrefix + "-" + sampleCodeSuffix);
+                new SampleIdentifier(new GroupIdentifier((String) null, "CINA"), sampleCodePrefix
+                        + "-" + sampleCodeSuffix);
 
         final NewSample newSample = new NewSample();
         SampleType sampleType = new SampleType();
@@ -111,7 +112,8 @@ public class SampleMetadataExtractorTest extends AssertJUnit
                 new SampleMetadataExtractor(dataSetInformation, sampleMetadata, sampleCodeSuffix,
                         openbisService);
         extractor.processMetadataAndFillDataSetInformation();
-        assertTrue(ownerEmail.equals(dataSetInformation.tryGetUploadingUserEmail()));
+        assertEquals(ownerEmail, dataSetInformation.tryGetUploadingUserEmail());
+        assertEquals("/CINA/S-SUFFIX", dataSetInformation.getSampleIdentifier().toString());
 
         context.assertIsSatisfied();
     }
@@ -139,8 +141,8 @@ public class SampleMetadataExtractorTest extends AssertJUnit
         experiment.setIdentifier(experimentIdentifier.toString());
 
         final SampleIdentifier sampleIdentifier =
-                SampleIdentifier.createOwnedBy(new SampleOwnerIdentifier(experimentIdentifier),
-                        sampleCodePrefix + "-" + sampleCodeSuffix);
+                new SampleIdentifier(new GroupIdentifier((String) null, "CINA"), sampleCodePrefix
+                        + "-" + sampleCodeSuffix);
 
         final Sample existingSample = new Sample();
         context.checking(new Expectations()
@@ -165,7 +167,7 @@ public class SampleMetadataExtractorTest extends AssertJUnit
         {
             // this should happen
         }
-        assertTrue(ownerEmail.equals(dataSetInformation.tryGetUploadingUserEmail()));
+        assertEquals(ownerEmail, dataSetInformation.tryGetUploadingUserEmail());
 
         context.assertIsSatisfied();
     }
@@ -274,7 +276,7 @@ public class SampleMetadataExtractorTest extends AssertJUnit
         {
             // This should happen
         }
-        assertTrue(ownerEmail.equals(dataSetInformation.tryGetUploadingUserEmail()));
+        assertEquals(ownerEmail, dataSetInformation.tryGetUploadingUserEmail());
 
         context.assertIsSatisfied();
     }
diff --git a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/info/experiment-data-folder/experiment.properties b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/info/experiment-data-folder/experiment.properties
index 124fde3eff7..f15a939bc1b 100644
--- a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/info/experiment-data-folder/experiment.properties
+++ b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/info/experiment-data-folder/experiment.properties
@@ -1,3 +1,3 @@
-project.code = CINA1
-experiment.code = EXP
+project.identifier = /CINA/CINA1
+experiment.code-prefix = EXP
 experiment.owner-email = no-one@nowhere.ch
\ No newline at end of file
-- 
GitLab