Skip to content
Snippets Groups Projects
Commit fb67d4cc authored by anttil's avatar anttil
Browse files

SSDM-4905: Add method to create PermIds to V3 API

SVN: 37919
parent 1bc2b82b
No related branches found
No related tags found
No related merge requests found
......@@ -266,6 +266,7 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.update.UpdateVocabula
import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.update.VocabularyTermUpdate;
import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.OperationContext;
import ch.ethz.sis.openbis.generic.server.asapi.v3.executor.operation.IExecuteOperationExecutor;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.openbis.common.spring.IInvocationLoggerContext;
import ch.systemsx.cisd.openbis.generic.server.AbstractServer;
import ch.systemsx.cisd.openbis.generic.server.business.IPropertiesBatchManager;
......@@ -932,4 +933,20 @@ public class ApplicationServerApi extends AbstractServer<IApplicationServerApi>
{
return 2;
}
@Override
public List<String> createPermIdStrings(String sessionToken, int amount)
{
if (amount > 100)
{
throw new UserFailureException("Cannot create more than 100 ids in one call (" + amount + " requested)");
}
if (amount <= 0)
{
throw new UserFailureException("Invalid amount: " + amount);
}
return getDAOFactory().getPermIdDAO().createPermIds(amount);
}
}
......@@ -678,4 +678,11 @@ public class ApplicationServerApiLogger extends AbstractServerLogger implements
logAccess(sessionToken, "delete-external-dms", "EXTERNAL_DMS_IDS(%s) DELETION_OPTIONS(%s)", abbreviate(externalDmsIds), deletionOptions);
}
@Override
public List<String> createPermIdStrings(String sessionToken, int amount)
{
logAccess(sessionToken, "get-perm-id-strings", Integer.toString(amount));
return null;
}
}
package ch.ethz.sis.openbis.systemtest.asapi.v3;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
public class CreatePermIdTest extends AbstractTest
{
@Test
public void correctAmountOfUniqueIdsGenerated()
{
String session = v3api.login(TEST_USER, PASSWORD);
List<String> batch1 = v3api.createPermIdStrings(session, 3);
List<String> batch2 = v3api.createPermIdStrings(session, 5);
Set<String> both = new HashSet<>();
both.addAll(batch1);
both.addAll(batch2);
assertThat(batch1.size(), is(3));
assertThat(batch2.size(), is(5));
assertThat(both.size(), is(8));
}
@DataProvider(name = "InvalidAmounts")
public static Object[][] invalidAmounts()
{
return new Object[][] { { Integer.MIN_VALUE }, { -1000 }, { -1 }, { 0 }, { 1000 }, { Integer.MAX_VALUE } };
}
@Test(dataProvider = "InvalidAmounts", expectedExceptions = UserFailureException.class)
public void cannotCreateTooManyOrNonPositive(int amount)
{
String session = v3api.login(TEST_USER, PASSWORD);
v3api.createPermIdStrings(session, amount);
}
}
......@@ -332,4 +332,7 @@ public interface IApplicationServerApi extends IRpcService
IOperationExecutionOptions options);
public Map<String, String> getServerInformation(String sessionToken);
@TechPreview
public List<String> createPermIdStrings(String sessionToken, int amount);
}
......@@ -10,7 +10,7 @@ public class ContentCopyPermId extends ObjectPermId implements IContentCopyId
private static final long serialVersionUID = 1L;
/**
* @param permId Data set perm id, e.g. "201108050937246-1031".
* @param permId Content copy perm id
*/
public ContentCopyPermId(String permId)
{
......
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