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 d7a7ec8ec114ee1e0f0fdd8bf652160f07c7130b..3ddd1f239b954cd4de979658d11f5dfd7beb04ba 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 132ec1004ac8dd2df3edae10eb93a12ad4fab93f..963cf597578b45060b34420335d827e9a31fb38b 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 6e5e96bab788341c3e58604381bcb065db0b41d6..b147ce7ed99e4043d2c4f1739043b681cf7a54cc 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 911086f0428d49cbb92d15b22210bf50a73f8ab2..8fcee75876f8efd0b1018ca7f357eb630f885d9e 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 1b334fadc187191a068ac07728c3848acc15080d..491e2775934b9e3b8b2c505babde59a4d82f56eb 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 124fde3eff73f0204d67a17457233ae8d9686afd..f15a939bc1b452eb886533ecbfe67a24ab06e60c 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