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

LMS-1844 Added experiment lister command to CINA client.

SVN: 18482
parent c5ace10d
No related branches found
No related tags found
No related merge requests found
......@@ -32,13 +32,13 @@ public class CinaCommandFactory extends AbstractCommandFactory
private static enum Command
{
LISTSAMPS, GENCODE, HELP
LISTSAMPS, GENCODE, LISTEXPS, HELP
}
public List<String> getKnownCommands()
{
String[] commands =
{ "listsamps", "gencode" };
{ "listsamps", "gencode", "listexps" };
return Arrays.asList(commands);
}
......@@ -73,6 +73,9 @@ public class CinaCommandFactory extends AbstractCommandFactory
case GENCODE:
result = new CommandGenerateSampleCode();
break;
case LISTEXPS:
result = new CommandExperimentLister();
break;
case HELP:
result = new CommandHelp(this, PROGRAM_CALL_STRING);
break;
......
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.cina.client.util.cli;
import java.util.List;
import ch.systemsx.cisd.cina.client.util.v1.ICinaUtilities;
import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.openbis.dss.client.api.cli.GlobalArguments;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Experiment;
/**
* @author Chandrasekhar Ramakrishnan
*/
public class CommandExperimentLister extends
AbstractCinaCommand<CommandExperimentLister.CommandExperimentListerArguments>
{
static class CommandExperimentListerArguments extends GlobalArguments
{
public String getExperimentTypeCode()
{
return getArguments().get(0).toString().toUpperCase();
}
@Override
public boolean isComplete()
{
if (getArguments().size() < 1)
{
return false;
}
if (getExperimentTypeCode().length() < 1)
{
return false;
}
if (false == super.isComplete())
return false;
return true;
}
}
private static class ExperimentListerExecutor extends
AbstractExecutor<CommandExperimentListerArguments>
{
/**
* @param command The parent command
*/
ExperimentListerExecutor(CommandExperimentLister command)
{
super(command);
}
@Override
protected int doExecute(ICinaUtilities component)
{
List<Experiment> results =
component.listVisibleExperiments(arguments.getExperimentTypeCode());
for (Experiment experiment : results)
{
System.out.println(experiment.toString());
}
return 0;
}
}
public CommandExperimentLister()
{
super(new CommandExperimentListerArguments());
}
public int execute(String[] args) throws UserFailureException, EnvironmentFailureException
{
return new ExperimentListerExecutor(this).execute(args);
}
public String getName()
{
return "listexps";
}
@Override
protected String getRequiredArgumentsString()
{
return "<experiment type>";
}
}
......@@ -19,6 +19,7 @@ package ch.systemsx.cisd.cina.client.util.v1;
import java.util.List;
import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException;
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;
......@@ -61,6 +62,18 @@ public interface ICinaUtilities
public String generateSampleCode(String sampleTypeCode) throws IllegalStateException,
EnvironmentFailureException;
/**
* Return a list of experiments of the given type for which the user has write priveledges.
*
* @param experimentType The type of experiment we want listed
* @return A list of experiments for the given experiment type
* @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.
*/
public List<Experiment> listVisibleExperiments(String experimentType)
throws IllegalStateException, EnvironmentFailureException;
/**
* Logs the current user out.
*/
......
......@@ -16,6 +16,7 @@
package ch.systemsx.cisd.cina.client.util.v1.impl;
import java.util.ArrayList;
import java.util.List;
import org.springframework.remoting.RemoteConnectFailureException;
......@@ -28,8 +29,11 @@ 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.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.SpaceWithProjectsAndRoleAssignments;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
/**
......@@ -177,6 +181,12 @@ public class CinaUtilitiesFacade implements ICinaUtilities
{
return state.generateSampleCode(sampleTypeCode);
}
public List<Experiment> listVisibleExperiments(String experimentType)
throws IllegalStateException, EnvironmentFailureException
{
return state.listVisibleExperiments(experimentType);
}
}
/**
......@@ -213,6 +223,12 @@ abstract class AbstractCinaFacadeState implements ICinaUtilities
throw new IllegalStateException("Please log in");
}
public List<Experiment> listVisibleExperiments(String experimentType)
throws IllegalStateException, EnvironmentFailureException
{
throw new IllegalStateException("Please log in");
}
/**
* Authenticates the <code>user</code> with given <code>password</code>.
*
......@@ -337,4 +353,29 @@ class AuthenticatedState extends AbstractCinaFacadeState
String.format("%s%d", replicaSampleType.getGeneratedCodePrefix(), sampleCodeSuffix);
return sampleCode;
}
@Override
public List<Experiment> listVisibleExperiments(String experimentType)
throws IllegalStateException, EnvironmentFailureException
{
// This functionality has only been supported since version 1.2
int minorVersion = service.getMinorVersion();
if (minorVersion < 2)
{
throw new EnvironmentFailureException("Server does not support this feature.");
}
// First get a list of spaces the user has access to
List<SpaceWithProjectsAndRoleAssignments> spaces =
service.listSpacesWithProjectsAndRoleAssignments(sessionToken, null);
ArrayList<Project> projects = new ArrayList<Project>();
for (SpaceWithProjectsAndRoleAssignments space : spaces)
{
projects.addAll(space.getProjects());
}
// Then get the experiments for these spaces
return service.listExperiments(sessionToken, projects, experimentType);
}
}
\ No newline at end of file
......@@ -72,8 +72,8 @@ public class CommandFactoryTest extends AssertJUnit
cmd.printUsage(out);
String helpText =
"usage: cina_client.sh COMMAND [options...] <command arguments>\n" + "\n"
+ "Commands:\n" + " listsamps\n" + " gencode\n" + " ls\n" + " get\n"
+ " put\n" + "\n" + "Options:\n"
+ "Commands:\n" + " listsamps\n" + " gencode\n" + " listexps\n" + " ls\n"
+ " get\n" + " put\n" + "\n" + "Options:\n"
+ " [-p,--password] VAL : User login password\n"
+ " [-s,--server-base-url] VAL : URL for openBIS Server (required)\n"
+ " [-u,--username] VAL : User login name\n";
......
......@@ -28,8 +28,12 @@ import org.testng.annotations.Test;
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.Experiment;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Project;
import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Role;
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.SpaceWithProjectsAndRoleAssignments;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
/**
......@@ -126,6 +130,49 @@ public class CinaUtilitiesFacadeTest extends AssertJUnit
context.assertIsSatisfied();
}
@Test
public void testListVisibleExperiments()
{
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);
context.checking(new Expectations()
{
{
one(service).tryToAuthenticateForAllServices(USER_ID, PASSWORD);
will(returnValue(SESSION_TOKEN));
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));
one(service).logout(SESSION_TOKEN);
}
});
CinaUtilitiesFacade facade = createFacade(service, openbisService);
facade.login(USER_ID, PASSWORD);
assertEquals(facade.getSessionToken(), SESSION_TOKEN);
List<Experiment> result = facade.listVisibleExperiments("EXP-TYPE");
assertEquals(0, result.size());
facade.logout();
context.assertIsSatisfied();
}
/**
* Utility method to create a CinaUtilitiesFacade object for testing.
*/
......
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