From 79c7c866b001d3749e355077ad115d0dc3d0d77b Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Thu, 28 Feb 2013 13:44:49 +0000 Subject: [PATCH] SP-532, BIS-281: MoveDataSetCommand renamed to MoveDataSetsCommand which now can move several data sets. MoveDataSetsCommandTest added. SVN: 28482 --- .../dss/client/admin/MoveDataSetCommand.java | 75 ------------ .../dss/client/admin/MoveDataSetsCommand.java | 94 +++++++++++++++ .../client/admin/ShareManagerApplication.java | 2 +- .../client/admin/MoveDataSetsCommandTest.java | 114 ++++++++++++++++++ 4 files changed, 209 insertions(+), 76 deletions(-) delete mode 100644 datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/admin/MoveDataSetCommand.java create mode 100644 datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/admin/MoveDataSetsCommand.java create mode 100644 datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/client/admin/MoveDataSetsCommandTest.java diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/admin/MoveDataSetCommand.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/admin/MoveDataSetCommand.java deleted file mode 100644 index 6ffe2270346..00000000000 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/admin/MoveDataSetCommand.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2013 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.openbis.dss.client.admin; - - - -/** - * - * - * @author Franz-Josef Elmer - */ -public class MoveDataSetCommand extends AbstractCommand -{ - static final class MoveDataSetCommandArguments extends CommonArguments - { - String getDataSetCode() - { - return arguments.isEmpty() ? "" : arguments.get(0); - } - - String getShareId() - { - return arguments.size() < 2 ? "" : arguments.get(1); - } - - @Override - protected boolean allAdditionalMandatoryArgumentsPresent() - { - return arguments.size() == 2; - } - } - - private MoveDataSetCommandArguments arguments; - - MoveDataSetCommand() - { - super("move"); - arguments = new MoveDataSetCommandArguments(); - } - - @Override - protected MoveDataSetCommandArguments getArguments() - { - return arguments; - } - - @Override - protected String getRequiredArgumentsString() - { - return "<data set code> <share id>"; - } - - @Override - void execute() - { - String dataSetCode = arguments.getDataSetCode(); - String shareId = arguments.getShareId(); - service.shuffleDataSet(sessionToken, dataSetCode, shareId); - System.out.println("Data set " + dataSetCode + " successfully moved to share " + shareId + "."); - } -} diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/admin/MoveDataSetsCommand.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/admin/MoveDataSetsCommand.java new file mode 100644 index 00000000000..3c8fda0fed6 --- /dev/null +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/admin/MoveDataSetsCommand.java @@ -0,0 +1,94 @@ +/* + * Copyright 2013 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.openbis.dss.client.admin; + +import java.util.Collections; +import java.util.Set; +import java.util.TreeSet; + +import ch.systemsx.cisd.common.exceptions.UserFailureException; + + + +/** + * Move data sets to another share. + * + * @author Franz-Josef Elmer + */ +public class MoveDataSetsCommand extends AbstractCommand +{ + static final class MoveDataSetsCommandArguments extends CommonArguments + { + Set<String> getDataSetCodes() + { + if (arguments.isEmpty()) + { + return Collections.emptySet(); + } + return new TreeSet<String>(arguments.subList(1, arguments.size())); + } + + String getShareId() + { + return arguments.size() < 2 ? "" : arguments.get(0); + } + + @Override + protected boolean allAdditionalMandatoryArgumentsPresent() + { + return arguments.size() >= 2; + } + } + + private MoveDataSetsCommandArguments arguments; + + MoveDataSetsCommand() + { + super("move-to"); + arguments = new MoveDataSetsCommandArguments(); + } + + @Override + protected MoveDataSetsCommandArguments getArguments() + { + return arguments; + } + + @Override + protected String getRequiredArgumentsString() + { + return "<share id> <data set code 1> [<data set code 2> <data set code 3> ...]"; + } + + @Override + void execute() + { + String shareId = arguments.getShareId(); + Set<String> dataSetCodes = arguments.getDataSetCodes(); + for (String dataSetCode : dataSetCodes) + { + try + { + service.shuffleDataSet(sessionToken, dataSetCode, shareId); + System.out.println("Data set " + dataSetCode + " successfully moved to share " + shareId + "."); + } catch (UserFailureException ex) + { + System.err.println(ex.getMessage()); + } + } + } +} diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/admin/ShareManagerApplication.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/admin/ShareManagerApplication.java index 67897e919ec..96c6f3773f7 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/admin/ShareManagerApplication.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/admin/ShareManagerApplication.java @@ -67,7 +67,7 @@ public class ShareManagerApplication { LogLog.setQuietMode(true); ShareManagerApplication application = - new ShareManagerApplication(new ListSharesCommand(), new MoveDataSetCommand()); + new ShareManagerApplication(new ListSharesCommand(), new MoveDataSetsCommand()); try { application.parseAndRun(args); diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/client/admin/MoveDataSetsCommandTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/client/admin/MoveDataSetsCommandTest.java new file mode 100644 index 00000000000..7a116ed454d --- /dev/null +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/client/admin/MoveDataSetsCommandTest.java @@ -0,0 +1,114 @@ +/* + * Copyright 2013 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.openbis.dss.client.admin; + +import org.jmock.Expectations; +import org.jmock.Mockery; +import org.testng.AssertJUnit; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import ch.systemsx.cisd.common.exceptions.UserFailureException; +import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.IDssServiceRpcGeneric; + +/** + * @author Franz-Josef Elmer + */ +public class MoveDataSetsCommandTest extends AssertJUnit +{ + private Mockery context; + + private IDssServiceRpcGeneric dssService; + + + @BeforeMethod + public void setUp() + { + context = new Mockery(); + dssService = context.mock(IDssServiceRpcGeneric.class); + } + + @AfterMethod + public void tearDown() + { + context.assertIsSatisfied(); + } + + @Test + public void testValidArguments() + { + new MoveDataSetsCommand().parseArguments(toArray("-u", "user", "-p", "pswd", "3", "ds1", + "ds2")); + } + + @Test + public void testMissingArguments() + { + MoveDataSetsCommand command = new MoveDataSetsCommand(); + try + { + command.parseArguments(toArray("-u", "user", "-p", "pswd", "3")); + } catch (UserFailureException ex) + { + assertEquals( + "Usage: " + + AbstractCommand.BASH_COMMAND + + " " + + command.getName() + + " [options] <share id> <data set code 1> " + + "[<data set code 2> <data set code 3> ...]\n" + + " [-p,--password] VAL : User login password\n" + + " [-sp,--service-properties] VAL : Path to DSS service.properties (default:\n" + + " etc/service.properties)\n" + + " [-u,--username] VAL : User login name\n" + "Example: " + + AbstractCommand.BASH_COMMAND + " " + command.getName() + + " -p VAL -sp VAL -u VAL <share id> <data set code 1> " + + "[<data set code 2> <data set code 3> ...]\n", ex.getMessage()); + } + } + + @Test + public void test() + { + context.checking(new Expectations() + { + { + one(dssService).shuffleDataSet(null, "ds1", "3"); + one(dssService).shuffleDataSet(null, "ds2", "3"); + one(dssService).shuffleDataSet(null, "ds3", "3"); + } + }); + MoveDataSetsCommand command = new MoveDataSetsCommand() + { + { + service = dssService; + } + }; + + command.parseArguments(toArray("-u", "user", "-p", "pswd", "3", "ds3", "ds2", "ds1", "ds1")); + command.execute(); + + context.assertIsSatisfied(); + } + + private String[] toArray(String... strings) + { + return strings; + } + +} -- GitLab