diff --git a/rtd_cina/source/java/ch/systemsx/cisd/cina/client/util/cli/CommandGetReplica.java b/rtd_cina/source/java/ch/systemsx/cisd/cina/client/util/cli/CommandGetReplica.java index fbf3ad367c55940bfb1ff694ecbcfa2d28e3a3b0..d3574e5f4a59d03986d335500e3c573d47f9d0a8 100644 --- a/rtd_cina/source/java/ch/systemsx/cisd/cina/client/util/cli/CommandGetReplica.java +++ b/rtd_cina/source/java/ch/systemsx/cisd/cina/client/util/cli/CommandGetReplica.java @@ -88,11 +88,22 @@ public class CommandGetReplica extends protected ResultCode doExecute(ICinaUtilities component) { // Find all datasets connected to this sample + for (String sampleCode : arguments.getReplicaIdentifiers()) + { + executeForSampleCode(component, sampleCode); + } + return ResultCode.OK; + } + + protected void executeForSampleCode(ICinaUtilities component, String sampleCode) + { + // Find all datasets connected to this sample + component.listDataSetsForSampleCode(sampleCode); + // List<DataSet> dataSets = component.listDataSetsForSampleCode(sampleCode); // Download the raw-data dataset // Download the ... // List<Experiment> results = // component.listVisibleExperiments(arguments.getReplicaIdentifier()); - return ResultCode.OK; } } @@ -115,6 +126,6 @@ public class CommandGetReplica extends @Override protected String getRequiredArgumentsString() { - return "<replica identifier>"; + return "<replica identifier> [<replica identifier> ...]"; } } diff --git a/rtd_cina/source/java/ch/systemsx/cisd/cina/client/util/v1/ICinaUtilities.java b/rtd_cina/source/java/ch/systemsx/cisd/cina/client/util/v1/ICinaUtilities.java index 12bf80e0066dea6cd05a080478e5fce39eaf71a1..c6ee4323cd4cee12ceb9767c7cd5b7234eb9dcab 100644 --- a/rtd_cina/source/java/ch/systemsx/cisd/cina/client/util/v1/ICinaUtilities.java +++ b/rtd_cina/source/java/ch/systemsx/cisd/cina/client/util/v1/ICinaUtilities.java @@ -19,6 +19,8 @@ package ch.systemsx.cisd.cina.client.util.v1; import java.util.List; import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; +import ch.systemsx.cisd.common.exceptions.UserFailureException; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Experiment; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria; @@ -74,6 +76,20 @@ public interface ICinaUtilities public List<Experiment> listVisibleExperiments(String experimentType) throws IllegalStateException, EnvironmentFailureException; + /** + * Return a list of data sets for the sample specified by code. + * + * @param sampleCode The code of the sample we are interested in. It is assumed that the code is + * unique. + * @return The data sets connected to the sample + * @throws IllegalStateException Thrown if the user has not yet been authenticated. + * @throws EnvironmentFailureException Thrown in cases where it is not possible to connect to + * the server or if there are multiple samples with the given code. + * @throws UserFailureException Thrown if no sample exists with the specified code. + */ + public List<DataSet> listDataSetsForSampleCode(String sampleCode) throws IllegalStateException, + EnvironmentFailureException, UserFailureException; + /** * Logs the current user out. */ diff --git a/rtd_cina/source/java/ch/systemsx/cisd/cina/client/util/v1/impl/CinaUtilitiesFacade.java b/rtd_cina/source/java/ch/systemsx/cisd/cina/client/util/v1/impl/CinaUtilitiesFacade.java index 4cb50873a530a4045a6bb42619c949b64232975f..4380dc8921f0f3ec1ef0b32c45da97064ead0922 100644 --- a/rtd_cina/source/java/ch/systemsx/cisd/cina/client/util/v1/impl/CinaUtilitiesFacade.java +++ b/rtd_cina/source/java/ch/systemsx/cisd/cina/client/util/v1/impl/CinaUtilitiesFacade.java @@ -25,14 +25,18 @@ import ch.systemsx.cisd.cina.client.util.v1.ICinaUtilities; import ch.systemsx.cisd.common.api.client.ServiceFinder; import ch.systemsx.cisd.common.exceptions.AuthorizationFailureException; import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; +import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.openbis.generic.shared.IETLLIMSService; import ch.systemsx.cisd.openbis.generic.shared.OpenBisServiceFactory; import ch.systemsx.cisd.openbis.generic.shared.ResourceNames; import ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Experiment; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Project; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Sample; 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.api.v1.dto.SpaceWithProjectsAndRoleAssignments; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType; @@ -187,6 +191,12 @@ public class CinaUtilitiesFacade implements ICinaUtilities { return state.listVisibleExperiments(experimentType); } + + public List<DataSet> listDataSetsForSampleCode(String sampleCode) throws IllegalStateException, + EnvironmentFailureException + { + return state.listDataSetsForSampleCode(sampleCode); + } } /** @@ -229,6 +239,12 @@ abstract class AbstractCinaFacadeState implements ICinaUtilities throw new IllegalStateException("Please log in"); } + public List<DataSet> listDataSetsForSampleCode(String sampleCode) throws IllegalStateException, + EnvironmentFailureException + { + throw new IllegalStateException("Please log in"); + } + /** * Authenticates the <code>user</code> with given <code>password</code>. * @@ -301,6 +317,8 @@ class AuthenticatedState extends AbstractCinaFacadeState private final IETLLIMSService openbisService; + private final int generalInformationServiceMinorVersion; + /** * @param service */ @@ -310,6 +328,7 @@ class AuthenticatedState extends AbstractCinaFacadeState super(service); this.sessionToken = sessionToken; this.openbisService = openbisService; + this.generalInformationServiceMinorVersion = service.getMinorVersion(); } @Override @@ -328,7 +347,7 @@ class AuthenticatedState extends AbstractCinaFacadeState throws IllegalStateException, EnvironmentFailureException { // This functionality has only been supported since version 1.1 - int minorVersion = service.getMinorVersion(); + int minorVersion = generalInformationServiceMinorVersion; if (minorVersion < 1) { throw new EnvironmentFailureException("Server does not support this feature."); @@ -359,7 +378,7 @@ class AuthenticatedState extends AbstractCinaFacadeState throws IllegalStateException, EnvironmentFailureException { // This functionality has only been supported since version 1.2 - int minorVersion = service.getMinorVersion(); + int minorVersion = generalInformationServiceMinorVersion; if (minorVersion < 2) { throw new EnvironmentFailureException("Server does not support this feature."); @@ -378,4 +397,35 @@ class AuthenticatedState extends AbstractCinaFacadeState return service.listExperiments(sessionToken, projects, experimentType); } + @Override + public List<DataSet> listDataSetsForSampleCode(String sampleCode) throws IllegalStateException, + EnvironmentFailureException + { + // This functionality has only been supported since version 1.1 + int minorVersion = generalInformationServiceMinorVersion; + if (minorVersion < 1) + { + throw new EnvironmentFailureException("Server does not support this feature."); + } + + // Find the sample that matches the given code (there should only be 1) + SearchCriteria searchCriteria = new SearchCriteria(); + searchCriteria.addMatchClause(MatchClause.createAttributeMatch(MatchClauseAttribute.CODE, + sampleCode)); + List<Sample> samples = service.searchForSamples(sessionToken, searchCriteria); + if (samples.size() < 1) + { + throw new UserFailureException("No sample with specified code."); + } + + // There should only be 1 + if (samples.size() > 1) + { + throw new EnvironmentFailureException( + "Found multiple matching samples -- this should not happen. Please contact administrator to resolve this problem."); + } + + return service.listDataSets(sessionToken, samples); + } + } \ No newline at end of file diff --git a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/client/util/cli/CommandGenerateSampleCodeTest.java b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/client/util/cli/CommandGenerateSampleCodeTest.java index fcab38fcba19773cee1a9118aa8d20175fd5e0d2..adf51f82152786cd48e04d612cacfdac479b0805 100644 --- a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/client/util/cli/CommandGenerateSampleCodeTest.java +++ b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/client/util/cli/CommandGenerateSampleCodeTest.java @@ -92,6 +92,9 @@ public class CommandGenerateSampleCodeTest extends AssertJUnit one(service).tryToAuthenticateForAllServices(USER_ID, PASSWORD); will(returnValue(SESSION_TOKEN)); + one(service).getMinorVersion(); + will(returnValue(0)); + one(openbisService).getSampleType(SESSION_TOKEN, sampleTypeCode.toUpperCase()); will(returnValue(sampleType)); diff --git a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/client/util/cli/CommandGetReplicaTest.java b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/client/util/cli/CommandGetReplicaTest.java index f2fb0d7da053e86e335b880b49db92cca2584bf7..0b3cec452a45b1c096d1036508b50323cbf7ae87 100644 --- a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/client/util/cli/CommandGetReplicaTest.java +++ b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/client/util/cli/CommandGetReplicaTest.java @@ -16,6 +16,8 @@ package ch.systemsx.cisd.cina.client.util.cli; +import java.util.ArrayList; + import org.jmock.Expectations; import org.jmock.Mockery; import org.testng.AssertJUnit; @@ -24,10 +26,17 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import ch.systemsx.cisd.cina.client.util.v1.ICinaUtilities; +import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; import ch.systemsx.cisd.openbis.dss.client.api.cli.ICommand; import ch.systemsx.cisd.openbis.dss.client.api.cli.ResultCode; import ch.systemsx.cisd.openbis.generic.shared.IETLLIMSService; import ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Sample; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Sample.SampleInitializer; +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; /** * @author Chandrasekhar Ramakrishnan @@ -83,44 +92,51 @@ public class CommandGetReplicaTest extends AssertJUnit { one(service).tryToAuthenticateForAllServices(USER_ID, PASSWORD); will(returnValue(SESSION_TOKEN)); + + one(service).getMinorVersion(); + will(returnValue(1)); + one(service).logout(SESSION_TOKEN); } }); - } - @Test - public void testCodePath() + private void setupListDataSetsExpectations(final String sampleCode) { - setupAuthenticationExpectations(); context.checking(new Expectations() { { - // final ArrayList<Project> projects = new ArrayList<Project>(); - // Project project = new Project("PROJECT-1", "SPACE-1"); - // projects.add(project); - // - // final ArrayList<Experiment> experiments = new ArrayList<Experiment>(); - // - // final ArrayList<SpaceWithProjectsAndRoleAssignments> spaces = - // new ArrayList<SpaceWithProjectsAndRoleAssignments>(); - // SpaceWithProjectsAndRoleAssignments space = - // new SpaceWithProjectsAndRoleAssignments("SPACE-1"); - // space.add(project); - // space.add("user", new Role("ADMIN", true)); - // spaces.add(space); - - // one(service).getMinorVersion(); - // will(returnValue(2)); - - // one(service).listSpacesWithProjectsAndRoleAssignments(SESSION_TOKEN, null); - // will(returnValue(spaces)); - // - // one(service).listExperiments(SESSION_TOKEN, projects, "EXP-TYPE"); - // will(returnValue(experiments)); + SearchCriteria searchCriteria = new SearchCriteria(); + searchCriteria.addMatchClause(MatchClause.createAttributeMatch( + MatchClauseAttribute.CODE, sampleCode)); + + ArrayList<Sample> samples = new ArrayList<Sample>(); + SampleInitializer initializer = new SampleInitializer(); + initializer.setCode(sampleCode); + initializer.setId((long) 1); + initializer.setIdentifier("SPACE/" + sampleCode); + initializer.setPermId("PERM-ID"); + initializer.setSampleTypeCode("SAMPLE-TYPE"); + initializer.setSampleTypeId((long) 1); + Sample sample = new Sample(initializer); + samples.add(sample); + + one(service).searchForSamples(SESSION_TOKEN, searchCriteria); + will(returnValue(samples)); + + ArrayList<DataSet> dataSets = new ArrayList<DataSet>(); + one(service).listDataSets(SESSION_TOKEN, samples); + will(returnValue(dataSets)); } }); + } + + @Test + public void testCodePath() + { + setupAuthenticationExpectations(); + setupListDataSetsExpectations("REPLICA-ID"); ICommand command = new MockCommandGetReplica(); @@ -135,6 +151,7 @@ public class CommandGetReplicaTest extends AssertJUnit public void testOutputFolder() { setupAuthenticationExpectations(); + setupListDataSetsExpectations("REPLICA-ID"); ICommand command = new MockCommandGetReplica(); @@ -149,6 +166,8 @@ public class CommandGetReplicaTest extends AssertJUnit public void testMultipleReplicas() { setupAuthenticationExpectations(); + setupListDataSetsExpectations("REPLICA-ID1"); + setupListDataSetsExpectations("REPLICA-ID2"); ICommand command = new MockCommandGetReplica(); @@ -158,4 +177,34 @@ public class CommandGetReplicaTest extends AssertJUnit assertEquals(ResultCode.OK, exitCode); context.assertIsSatisfied(); } + + @Test + public void testOldVersion() + { + context.checking(new Expectations() + { + { + one(service).tryToAuthenticateForAllServices(USER_ID, PASSWORD); + will(returnValue(SESSION_TOKEN)); + + // The service used wasn't available in version 0 + one(service).getMinorVersion(); + will(returnValue(0)); + + one(service).logout(SESSION_TOKEN); + } + }); + + ICommand command = new MockCommandGetReplica(); + + try + { + command.execute(new String[] + { "-s", "url", "-u", USER_ID, "-p", PASSWORD, "REPLICA-ID" }); + fail("Command should throw an exception when run against an older version of the interface."); + } catch (EnvironmentFailureException e) + { + assertEquals("Server does not support this feature.", e.getMessage()); + } + } } diff --git a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/client/util/v1/impl/CinaUtilitiesFacadeTest.java b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/client/util/v1/impl/CinaUtilitiesFacadeTest.java index 328d4c15a1a861ac303d5c42ddd95c4c41ac5a0a..ff04903c86f9ca1e4eb4828f399cde29c8c35d07 100644 --- a/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/client/util/v1/impl/CinaUtilitiesFacadeTest.java +++ b/rtd_cina/sourceTest/java/ch/systemsx/cisd/cina/client/util/v1/impl/CinaUtilitiesFacadeTest.java @@ -112,6 +112,9 @@ public class CinaUtilitiesFacadeTest extends AssertJUnit one(service).tryToAuthenticateForAllServices(USER_ID, PASSWORD); will(returnValue(SESSION_TOKEN)); + one(service).getMinorVersion(); + will(returnValue(0)); + one(openbisService).getSampleType(SESSION_TOKEN, sampleTypeCode); will(returnValue(sampleType));