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 c3aa29a4cb0cd50ae606bfa3b5a9b8278d9ff861..2009d5f3a238c8e844089bd9e5af24e32fc9503a 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 @@ -17,14 +17,25 @@ package ch.systemsx.cisd.cina.dss.bundle.registrators; import java.io.File; +import java.util.ArrayList; import java.util.List; import ch.systemsx.cisd.cina.shared.constants.BundleStructureConstants; +import ch.systemsx.cisd.cina.shared.constants.CinaConstants; import ch.systemsx.cisd.cina.shared.metadata.ImageMetadataExtractor; import ch.systemsx.cisd.cina.shared.metadata.ReplicaMetadataExtractor; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetInformation; +import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataType; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityProperty; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewAttachment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; +import ch.systemsx.cisd.openbis.generic.shared.dto.SampleUpdatesDTO; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; /** @@ -92,20 +103,54 @@ public class ReplicaRegistrator extends BundleDataSetHelper replicaSample = getOpenbisService().tryGetSampleWithExperiment(replicaSampleId); didCreateSample = false; - // Sample doesn't exist, create it + // Get the relevant metadata from the file + String sampleDescriptionOrNull = replicaMetadataExtractor.tryReplicaSampleDescription(); + String sampleCreatorOrNull = replicaMetadataExtractor.tryReplicaSampleCreatorName(); + + ArrayList<IEntityProperty> properties = new ArrayList<IEntityProperty>(); + if (null != sampleDescriptionOrNull) + { + EntityProperty prop = createProperty(CinaConstants.DESCRIPTION_PROPERTY_CODE); + prop.setValue(sampleDescriptionOrNull); + properties.add(prop); + } + + if (null != sampleCreatorOrNull) + { + EntityProperty prop = createProperty(CinaConstants.CREATOR_EMAIL_PROPERTY_CODE); + prop.setValue(sampleCreatorOrNull); + properties.add(prop); + } + if (replicaSample == null) { + // Sample doesn't exist, create it NewSample newSample = NewSample.createWithParent(replicaSampleId.toString(), globalState.getReplicaSampleType(), null, gridPrepSampleId.toString()); newSample.setExperimentIdentifier(gridPrepSample.getExperiment().getIdentifier()); + newSample.setProperties(properties.toArray(IEntityProperty.EMPTY_ARRAY)); String userId = getSessionContext().getUserName(); getOpenbisService().registerSample(newSample, userId); - replicaSample = getOpenbisService().tryGetSampleWithExperiment(replicaSampleId); didCreateSample = true; + } else + { + ExperimentIdentifier experimentId = + new ExperimentIdentifier(replicaSample.getExperiment()); + experimentId.setDatabaseInstanceCode(replicaSample.getExperiment().getProject() + .getSpace().getInstance().getCode()); + // Sample does exist, update the metadata + SampleUpdatesDTO sampleUpdate = + new SampleUpdatesDTO(TechId.create(replicaSample), properties, experimentId, + new ArrayList<NewAttachment>(), replicaSample.getModificationDate(), + replicaSampleId, null, null); + getOpenbisService().updateSample(sampleUpdate); + didCreateSample = false; } + replicaSample = getOpenbisService().tryGetSampleWithExperiment(replicaSampleId); + assert replicaSample != null; } @@ -154,4 +199,17 @@ public class ReplicaRegistrator extends BundleDataSetHelper getDataSetInformation().addAll(registeredDataSetInfos); } } + + private EntityProperty createProperty(String propertyTypeCode) + { + PropertyType propertyType = new PropertyType(); + DataType dataType = new DataType(); + dataType.setCode(DataTypeCode.VARCHAR); + propertyType.setCode(propertyTypeCode); + propertyType.setDataType(dataType); + + EntityProperty property = new EntityProperty(); + property.setPropertyType(propertyType); + return property; + } } diff --git a/rtd_cina/source/java/ch/systemsx/cisd/cina/shared/constants/BundleStructureConstants.java b/rtd_cina/source/java/ch/systemsx/cisd/cina/shared/constants/BundleStructureConstants.java index 2715427c755a5cb6d602a203e707fb5f30ed3340..4d88ad5221977dd0494d7e8e6b73f0de18be6a87 100644 --- a/rtd_cina/source/java/ch/systemsx/cisd/cina/shared/constants/BundleStructureConstants.java +++ b/rtd_cina/source/java/ch/systemsx/cisd/cina/shared/constants/BundleStructureConstants.java @@ -59,6 +59,10 @@ public class BundleStructureConstants public static final String REPLICA_SAMPLE_CODE_KEY = "database id (replica)"; + public static final String REPLICA_SAMPLE_DESCRIPTION_KEY = "description"; + + public static final String REPLICA_SAMPLE_CREATOR_NAME = "creator name (e-mail)"; + /** * No reason to instantiate this class. */ diff --git a/rtd_cina/source/java/ch/systemsx/cisd/cina/shared/constants/CinaConstants.java b/rtd_cina/source/java/ch/systemsx/cisd/cina/shared/constants/CinaConstants.java index 1c64a8a40f3f9a48c795e64a0936d873fe54eeb2..d2a4f9416dc6f2f774a239a249905bbc0037f6ce 100644 --- a/rtd_cina/source/java/ch/systemsx/cisd/cina/shared/constants/CinaConstants.java +++ b/rtd_cina/source/java/ch/systemsx/cisd/cina/shared/constants/CinaConstants.java @@ -37,6 +37,10 @@ public class CinaConstants public static final String SIZE_PREFIX = "Size"; + public static final String DESCRIPTION_PROPERTY_CODE = "Description"; + + public static final String CREATOR_EMAIL_PROPERTY_CODE = "CREATOR_EMAIL"; + // No need to instantiate this class private CinaConstants() { diff --git a/rtd_cina/source/java/ch/systemsx/cisd/cina/shared/metadata/ReplicaMetadataExtractor.java b/rtd_cina/source/java/ch/systemsx/cisd/cina/shared/metadata/ReplicaMetadataExtractor.java index e5fc1856808ff7d2f39e2ad012f668a5e2526a66..fec9ace0bc76fdc3427d14c6febfee7af610b800 100644 --- a/rtd_cina/source/java/ch/systemsx/cisd/cina/shared/metadata/ReplicaMetadataExtractor.java +++ b/rtd_cina/source/java/ch/systemsx/cisd/cina/shared/metadata/ReplicaMetadataExtractor.java @@ -37,6 +37,12 @@ public class ReplicaMetadataExtractor implements IMetadataExtractor private static final String REPLICA_SAMPLE_CODE_KEY = BundleStructureConstants.REPLICA_SAMPLE_CODE_KEY; + private static final String REPLICA_SAMPLE_DESCRIPTION_KEY = + BundleStructureConstants.REPLICA_SAMPLE_DESCRIPTION_KEY; + + private static final String REPLICA_SAMPLE_CREATOR_NAME = + BundleStructureConstants.REPLICA_SAMPLE_CREATOR_NAME; + private final ArrayList<ImageMetadataExtractor> metadataExtractors; private final File folder; @@ -124,6 +130,28 @@ public class ReplicaMetadataExtractor implements IMetadataExtractor return metadataMap.get(REPLICA_SAMPLE_CODE_KEY); } + /** + * Return the description for the replica sample. + * + * @return Return the code, or null if none was found + */ + public String tryReplicaSampleDescription() + { + checkPrepared(); + return metadataMap.get(REPLICA_SAMPLE_DESCRIPTION_KEY); + } + + /** + * Return the creator name for the replica sample. + * + * @return Return the code, or null if none was found + */ + public String tryReplicaSampleCreatorName() + { + checkPrepared(); + return metadataMap.get(REPLICA_SAMPLE_CREATOR_NAME); + } + public File getFolder() { return folder; diff --git a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/bundle/CinaBundleDataSetHandlerTest.java b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/bundle/CinaBundleDataSetHandlerTest.java index af8432098a5fd31bab01cad806886e1eaf1efbca..7e4b5e3386af2b88bcd19e13d1d4ae15fca50a6c 100644 --- a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/bundle/CinaBundleDataSetHandlerTest.java +++ b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/bundle/CinaBundleDataSetHandlerTest.java @@ -47,7 +47,6 @@ public class CinaBundleDataSetHandlerTest extends CinaBundleRegistrationTest setupNewEntititesExpectations(); setupExistingGridPrepExpectations(); - setupExistingReplicaExpectations(); setupHandleRawDataSetExpectations("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/RawData/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"); diff --git a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/bundle/registrators/CinaBundleRegistrationTest.java b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/bundle/registrators/CinaBundleRegistrationTest.java index 71255cd6f585f968969b71e1d93aaedf63edd849..05c4838d84938b98c3fbdb8d3528d1c5a792efda 100644 --- a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/bundle/registrators/CinaBundleRegistrationTest.java +++ b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/dss/bundle/registrators/CinaBundleRegistrationTest.java @@ -19,6 +19,7 @@ package ch.systemsx.cisd.cina.dss.bundle.registrators; import java.io.File; import java.io.IOException; import java.util.Collections; +import java.util.List; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; @@ -34,11 +35,16 @@ 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.DataSetType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetTypeWithVocabularyTerms; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseInstance; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project; 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.basic.dto.Space; +import ch.systemsx.cisd.openbis.generic.shared.dto.SampleUpdatesDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifierFactory; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifierFactory; @@ -61,8 +67,12 @@ public abstract class CinaBundleRegistrationTest extends AbstractFileSystemTestC private static final String SPACE_CODE = "SPACE"; - protected static final String EXPERIMENT_IDENTIFIER = DB_CODE + ":/" + SPACE_CODE - + "/PROJECT/EXP-1"; + private static final String PROJECT_CODE = "PROJECT"; + + private static final String EXPERIMENT_CODE = "EXP-1"; + + protected static final String EXPERIMENT_IDENTIFIER = DB_CODE + ":/" + SPACE_CODE + "/" + + PROJECT_CODE + "/" + EXPERIMENT_CODE; private static final String GRID_SAMPLE_CODE = "GRID-CODE"; @@ -206,6 +216,17 @@ public abstract class CinaBundleRegistrationTest extends AbstractFileSystemTestC final Sample sample = new Sample(); Experiment exp = new Experiment(); exp.setIdentifier(EXPERIMENT_IDENTIFIER); + exp.setCode(EXPERIMENT_CODE); + Project project = new Project(); + project.setCode(PROJECT_CODE); + Space space = new Space(); + space.setCode(SPACE_CODE); + DatabaseInstance dbInstance = new DatabaseInstance(); + dbInstance.setCode(DB_CODE); + space.setInstance(dbInstance); + project.setSpace(space); + exp.setProject(project); + sample.setId((long) 1); sample.setExperiment(exp); sample.setIdentifier(REPLICA_SAMPLE_IDENTIFIER); @@ -213,6 +234,53 @@ public abstract class CinaBundleRegistrationTest extends AbstractFileSystemTestC context.checking(new Expectations() { { + // Get the sample + one(openbisService).tryGetSampleWithExperiment( + with(new SampleIdentifierFactory(REPLICA_SAMPLE_IDENTIFIER) + .createIdentifier())); + will(returnValue(sample)); + + // Update it with new data + one(openbisService).updateSample(with(new MatcherNoDesc<SampleUpdatesDTO>() + { + public boolean matches(Object item) + { + if (item instanceof SampleUpdatesDTO) + { + SampleUpdatesDTO sampleUpdatesDto = (SampleUpdatesDTO) item; + assertEquals(REPLICA_SAMPLE_IDENTIFIER, sampleUpdatesDto + .getSampleIdentifier().toString()); + assertEquals(EXPERIMENT_IDENTIFIER, sampleUpdatesDto + .getExperimentIdentifierOrNull().toString()); + List<IEntityProperty> properties = + sampleUpdatesDto.getProperties(); + + assertTrue("The update should include properties.", + properties.size() > 0); + for (IEntityProperty property : properties) + { + if (property.getPropertyType().getCode() + .equals(CinaConstants.DESCRIPTION_PROPERTY_CODE)) + { + assertEquals( + "This replica is a test for imported MRC files", + property.getValue()); + } + + if (property.getPropertyType().getCode() + .equals(CinaConstants.CREATOR_EMAIL_PROPERTY_CODE)) + { + assertEquals("thomas.braun@bsse.ethz.ch", + property.getValue()); + } + } + return true; + } + return false; + } + })); + + // Return the sample one(openbisService).tryGetSampleWithExperiment( with(new SampleIdentifierFactory(REPLICA_SAMPLE_IDENTIFIER) .createIdentifier())); @@ -474,6 +542,17 @@ public abstract class CinaBundleRegistrationTest extends AbstractFileSystemTestC } }), with(TEST_USER_NAME)); will(returnValue(new Long(2))); + + Sample sample = new Sample(); + Experiment exp = new Experiment(); + exp.setIdentifier(EXPERIMENT_IDENTIFIER); + sample.setId((long) 1); + sample.setExperiment(exp); + sample.setIdentifier(REPLICA_SAMPLE_IDENTIFIER); + one(openbisService).tryGetSampleWithExperiment( + with(new SampleIdentifierFactory(REPLICA_SAMPLE_IDENTIFIER) + .createIdentifier())); + will(returnValue(sample)); } }); } 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 408e41bc8966937a1e8280e8338c730910c25fad..fea5db7936311ec9412891b5b330a1d9e0b12411 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 @@ -73,7 +73,6 @@ public class GridPreparationRegistratorTest extends CinaBundleRegistrationTest setupNewEntititesExpectations(); setupExistingGridPrepExpectations(); - setupExistingReplicaExpectations(); setupHandleRawDataSetExpectations("sourceTest/java/ch/systemsx/cisd/cina/shared/metadata/Test.bundle/RawData/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");