From 1bf66e22306d783373492da682441a6f3aeb9550 Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Mon, 27 Feb 2017 09:48:38 +0000 Subject: [PATCH] SSDM-4515: IDataSetRegistrationTransactionV2.createNewProjectSampleWithGeneratedCode() introduced and implemented. SVN: 37820 --- ...aSetRegistrationTransactionV2Delegate.java | 6 +++ .../v2/IDataSetRegistrationTransactionV2.java | 8 ++++ .../api/v2/impl/AbstractTransactionState.java | 41 +++++++++---------- .../impl/DataSetRegistrationTransaction.java | 6 +++ 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/DataSetRegistrationTransactionV2Delegate.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/DataSetRegistrationTransactionV2Delegate.java index 3fb1f4e46e8..e2839af531f 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/DataSetRegistrationTransactionV2Delegate.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/DataSetRegistrationTransactionV2Delegate.java @@ -123,6 +123,12 @@ public class DataSetRegistrationTransactionV2Delegate implements IDataSetRegistr return transaction.createNewSampleWithGeneratedCode(spaceCode, sampleTypeCode); } + @Override + public ISample createNewProjectSampleWithGeneratedCode(String projectIdentifier, String sampleTypeCode) + { + return transaction.createNewProjectSampleWithGeneratedCode(projectIdentifier, sampleTypeCode); + } + @Override public IExperimentImmutable getExperiment(String experimentIdentifierString) { diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/IDataSetRegistrationTransactionV2.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/IDataSetRegistrationTransactionV2.java index f75287037a2..ff06e7c0559 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/IDataSetRegistrationTransactionV2.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/IDataSetRegistrationTransactionV2.java @@ -123,6 +123,14 @@ public interface IDataSetRegistrationTransactionV2 */ ISample createNewSampleWithGeneratedCode(String spaceCode, String sampleTypeCode); + /** + * Create a new project sample to register with the openBIS AS. The sample will have a permId and automatically created identifier. + * + * @param projectIdentifier The project in which to create the sample identifier for the new sample + * @param sampleTypeCode The code of the type for the new sample + */ + ISample createNewProjectSampleWithGeneratedCode(String projectIdentifier, String sampleTypeCode); + /** * Get an experiment from the openBIS AS. * diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/impl/AbstractTransactionState.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/impl/AbstractTransactionState.java index 9dc41318633..3b2e1dcaa58 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/impl/AbstractTransactionState.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/impl/AbstractTransactionState.java @@ -602,39 +602,38 @@ public abstract class AbstractTransactionState<T extends DataSetInformation> public ISample createNewSampleWithGeneratedCode(String spaceCode, String sampleTypeCode) { - String permId = generatePermId(); SampleType sampleType = getSampleType(sampleTypeCode); - String sampleIdentifierString; - if (spaceCode == null || spaceCode.length() == 0) - { - sampleIdentifierString = - "/" - + openBisService.generateCodes(sampleType.getGeneratedCodePrefix(), - EntityKind.SAMPLE, 1).get(0); - } else + String sampleIdentifierString = "/" + createSampleCode(sampleType); + if (spaceCode != null && spaceCode.length() > 0) { - sampleIdentifierString = - "/" - + spaceCode - + "/" - + openBisService.generateCodes(sampleType.getGeneratedCodePrefix(), - EntityKind.SAMPLE, 1).get(0); + sampleIdentifierString = "/" + spaceCode + sampleIdentifierString; } - Sample sample = new Sample(sampleIdentifierString, permId); - sample.setSampleType(sampleTypeCode); - samplesToBeRegistered.add(sample); - addIdentifier(sampleIdentifierString, "Sample"); - return sample; + return createNewSample(sampleIdentifierString, sampleTypeCode); } + public ISample createNewProjectSampleWithGeneratedCode(String projectIdentifier, String sampleTypeCode) + { + SampleType sampleType = getSampleType(sampleTypeCode); + String sampleIdentifierString = projectIdentifier + "/" + createSampleCode(sampleType); + return createNewSample(sampleIdentifierString, sampleTypeCode); + } + + private String createSampleCode(SampleType sampleType) + { + return openBisService.generateCodes(sampleType.getGeneratedCodePrefix(), EntityKind.SAMPLE, 1).get(0); + } + /// Asserts that given entity hasn't been yet created within this transaction private void addIdentifier(String identifier, String entityKind) { String updatedId = entityKind + identifier.trim().toUpperCase(); if (registeredIdentifiers.contains(updatedId)) - throw new IllegalArgumentException(entityKind + " with identifier " + identifier + " has already been created in this transaction"); + { + throw new IllegalArgumentException(entityKind + " with identifier " + identifier + + " has already been created in this transaction"); + } registeredIdentifiers.add(updatedId); } diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/impl/DataSetRegistrationTransaction.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/impl/DataSetRegistrationTransaction.java index c778d0dd37c..8a3822776d2 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/impl/DataSetRegistrationTransaction.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/impl/DataSetRegistrationTransaction.java @@ -354,6 +354,12 @@ public class DataSetRegistrationTransaction<T extends DataSetInformation> implem return getStateAsLiveState().createNewSampleWithGeneratedCode(spaceCode, sampleTypeCode); } + @Override + public ISample createNewProjectSampleWithGeneratedCode(String projectIdentifier, String sampleTypeCode) + { + return getStateAsLiveState().createNewProjectSampleWithGeneratedCode(projectIdentifier, sampleTypeCode); + } + @Override public IExperimentImmutable getExperiment(String experimentIdentifierString) { -- GitLab