Skip to content
Snippets Groups Projects
Commit ec2fc659 authored by cramakri's avatar cramakri
Browse files

LMS-1887 Development of the download replica command.

SVN: 18838
parent 1c252be7
No related branches found
No related tags found
No related merge requests found
......@@ -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> ...]";
}
}
......@@ -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.
*/
......
......@@ -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
......@@ -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));
......
......@@ -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());
}
}
}
......@@ -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));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment