From 3915a37424f5116d8570a3abe5af6abca5adc80a Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Thu, 25 Feb 2016 12:05:58 +0000 Subject: [PATCH] SSDM-3220: Using in drop box API sample permId for identifying the sample a data set is connected. System test JavaDropboxSystemTest (with ExampleJavaDataSetRegistrationDropboxV2) modified to test the example of the issue SVN: 35735 --- .../api/v2/impl/ConversionUtils.java | 7 +++++ ...ampleJavaDataSetRegistrationDropboxV2.java | 13 ++++---- .../systemtests/JavaDropboxSystemTest.java | 30 ++++++++++++++++--- .../server/ServiceForDataStoreServer.java | 21 +++++++++---- .../generic/shared/dto/NewExternalData.java | 12 ++++++++ 5 files changed, 67 insertions(+), 16 deletions(-) diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/impl/ConversionUtils.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/impl/ConversionUtils.java index 636d97137ff..66069e499f9 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/impl/ConversionUtils.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/impl/ConversionUtils.java @@ -228,6 +228,7 @@ public class ConversionUtils data.setDataStoreCode(dataStoreCode); data.setExperimentIdentifierOrNull(dataSetInformation.getExperimentIdentifier()); data.setSampleIdentifierOrNull(dataSetInformation.getSampleIdentifier()); + data.setSamplePermIdOrNull(getSamplePermIdOrNull(dataSetInformation)); data.setParentDataSetCodes(dataSetInformation.getParentDataSetCodes()); data.setStorageFormat(storageFormat); @@ -239,6 +240,12 @@ public class ConversionUtils return data; } + private static String getSamplePermIdOrNull(DataSetInformation dataSetInformation) + { + ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sample = dataSetInformation.tryToGetSample(); + return sample == null ? null : sample.getPermId(); + } + public static NewLinkDataSet convertToNewLinkDataSet( DataSetRegistrationDetails<?> registrationDetails, String dataStoreCode) { diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/api/v2/ExampleJavaDataSetRegistrationDropboxV2.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/api/v2/ExampleJavaDataSetRegistrationDropboxV2.java index 9eae847a6ab..722c8adce94 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/api/v2/ExampleJavaDataSetRegistrationDropboxV2.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/api/v2/ExampleJavaDataSetRegistrationDropboxV2.java @@ -16,7 +16,7 @@ package ch.systemsx.cisd.etlserver.registrator.api.v2; -import ch.systemsx.cisd.openbis.dss.generic.shared.api.internal.v2.IExperimentImmutable; +import ch.systemsx.cisd.openbis.dss.generic.shared.api.internal.v2.ISampleImmutable; /** * An example dropbox implemented in Java. @@ -30,12 +30,11 @@ public class ExampleJavaDataSetRegistrationDropboxV2 extends @Override public void process(IDataSetRegistrationTransactionV2 transaction) { - String sampleId = "/CISD/JAVA-TEST"; - ISample sample = transaction.createNewSample(sampleId, "DYNAMIC_PLATE"); - IExperimentImmutable exp = - transaction.getSearchService().getExperiment("/CISD/NEMO/EXP-TEST-1"); - sample.setExperiment(exp); - IDataSet dataSet = transaction.createNewDataSet(); + @SuppressWarnings("deprecation") + ISampleImmutable container = transaction.getSample("/CISD/PLATE_WELLSEARCH"); + ISample sample = transaction.createNewSample("/CISD/DP1-A", "NORMAL"); + sample.setContainer(container); + IDataSet dataSet = transaction.createNewDataSet("UNKNOWN"); dataSet.setSample(sample); transaction.moveFile(transaction.getIncoming().getAbsolutePath(), dataSet); } diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/JavaDropboxSystemTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/JavaDropboxSystemTest.java index c70328785a8..5f7ad4b636e 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/JavaDropboxSystemTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/JavaDropboxSystemTest.java @@ -17,6 +17,8 @@ package ch.systemsx.cisd.openbis.datastoreserver.systemtests; import java.io.File; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -25,7 +27,13 @@ import org.testng.annotations.Test; import ch.systemsx.cisd.openbis.dss.generic.shared.IEncapsulatedOpenBISService; import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria.MatchClause; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria.MatchClauseAttribute; +import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AbstractExternalData; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListSampleCriteria; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TrackingDataSetCriteria; /** @@ -102,12 +110,26 @@ public class JavaDropboxSystemTest extends SystemTestCase List<AbstractExternalData> x = openBISService.listDataSetsByCode(codes); assertEquals("Exactly one dataset should have been imported.", 1, x.size()); - - for (AbstractExternalData a : x) + assertEquals("/CISD/PLATE_WELLSEARCH:DP1-A", x.get(0).getSampleIdentifier()); + + SearchCriteria searchCriteria = new SearchCriteria(); + searchCriteria.addMatchClause(MatchClause.createAttributeMatch(MatchClauseAttribute.CODE, "PLATE_WELLSEARCH")); + List<Sample> samples = openBISService.searchForSamples(searchCriteria); + assertEquals("[/CISD/PLATE_WELLSEARCH]", extractIdentifiers(samples).toString()); + List<Sample> components = openBISService.listSamples(ListSampleCriteria.createForContainer(new TechId(samples.get(0)))); + assertEquals("[/CISD/PLATE_WELLSEARCH:DP1-A, /CISD/PLATE_WELLSEARCH:WELL-A01, /CISD/PLATE_WELLSEARCH:WELL-A02]", + extractIdentifiers(components).toString()); + } + + private List<String> extractIdentifiers(List<Sample> samples) + { + List<String> identifiers = new ArrayList<>(); + for (Sample sample : samples) { - assertEquals("/CISD/JAVA-TEST", a.getSampleIdentifier()); - assertEquals("/CISD/NEMO/EXP-TEST-1", a.getExperiment().getIdentifier()); + identifiers.add(sample.getIdentifier()); } + Collections.sort(identifiers); + return identifiers; } private void createExampleDataSet(File exampleDataSet) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ServiceForDataStoreServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ServiceForDataStoreServer.java index 4ed6eb2bc14..18fdf36cd9f 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ServiceForDataStoreServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ServiceForDataStoreServer.java @@ -47,6 +47,7 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.id.StorageFormatPermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.datastore.id.DataStorePermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.id.EntityTypePermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.externaldms.id.ExternalDmsPermId; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.id.SamplePermId; import ch.ethz.sis.openbis.generic.server.asapi.v3.context.IProgress; import ch.ethz.sis.openbis.generic.server.asapi.v3.context.IProgressListener; import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.IOperationContext; @@ -2475,11 +2476,7 @@ public class ServiceForDataStoreServer extends AbstractCommonServer<IServiceForD } // sample - if (newData.getSampleIdentifierOrNull() != null) - { - creation.setSampleId(new ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.id.SampleIdentifier(newData.getSampleIdentifierOrNull() - .toString())); - } + injectSampleId(creation, newData); // data store if (newData.getDataStoreCode() != null) @@ -2588,6 +2585,20 @@ public class ServiceForDataStoreServer extends AbstractCommonServer<IServiceForD return ids.size(); } + private void injectSampleId(DataSetCreation creation, NewExternalData newData) + { + SampleIdentifier sampleIdentifier = newData.getSampleIdentifierOrNull(); + String permId = newData.getSamplePermIdOrNull(); + if (permId != null) + { + creation.setSampleId(new SamplePermId(permId)); + } else if (sampleIdentifier != null) + { + creation.setSampleId(new ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.id.SampleIdentifier( + sampleIdentifier.toString())); + } + } + private void checkDataSetCreationAllowed(Session session, List<? extends NewExternalData> dataSets) { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/NewExternalData.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/NewExternalData.java index 0db7c371f3f..9f3fd67b3c8 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/NewExternalData.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/NewExternalData.java @@ -77,6 +77,8 @@ public class NewExternalData implements Serializable private ExperimentIdentifier experimentIdentifierOrNull; private SampleIdentifier sampleIdentifierOrNull; + + private String samplePermIdOrNull; public ExperimentIdentifier getExperimentIdentifierOrNull() { @@ -98,6 +100,16 @@ public class NewExternalData implements Serializable this.sampleIdentifierOrNull = sampleIdentifierOrNull; } + public String getSamplePermIdOrNull() + { + return samplePermIdOrNull; + } + + public void setSamplePermIdOrNull(String samplePermId) + { + this.samplePermIdOrNull = samplePermId; + } + /** Returns <code>dataSetType</code>. */ public final DataSetType getDataSetType() { -- GitLab