From f30b08bfc5cce4cacc2ca10bd4bf047569628d97 Mon Sep 17 00:00:00 2001 From: felmer <franz-josef.elmer@id.ethz.ch> Date: Wed, 9 May 2018 07:14:42 +0200 Subject: [PATCH] SSDM-6061: Creating common experiments. More tests. --- .../task/UserManagementMaintenanceTask.java | 3 +- .../generic/server/task/UserManager.java | 167 +++++++++++++++--- .../server/task/UserManagerConfig.java | 12 ++ .../server/task/UserManagerReport.java | 16 +- .../UserManagementMaintenanceTaskTest.java | 52 +++++- .../task/UserManagerExpectationsBuilder.java | 49 ++++- .../systemtest/task/UserManagerTest.java | 151 +++++++++++----- 7 files changed, 371 insertions(+), 79 deletions(-) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UserManagementMaintenanceTask.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UserManagementMaintenanceTask.java index 1cb519193bb..eeefd78e12c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UserManagementMaintenanceTask.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UserManagementMaintenanceTask.java @@ -34,7 +34,6 @@ import ch.systemsx.cisd.common.filesystem.FileUtilities; import ch.systemsx.cisd.common.logging.Log4jSimpleLogger; import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogFactory; -import ch.systemsx.cisd.common.logging.LogLevel; import ch.systemsx.cisd.common.maintenance.IMaintenanceTask; import ch.systemsx.cisd.common.utilities.SystemTimeProvider; import ch.systemsx.cisd.openbis.generic.server.CommonServiceProvider; @@ -194,7 +193,7 @@ public class UserManagementMaintenanceTask implements IMaintenanceTask userManager.setGlobalSpaces(config.getGlobalSpaces()); try { - userManager.setCommonSpacesAndSamples(config.getCommonSpaces(), config.getCommonSamples()); + userManager.setCommon(config.getCommonSpaces(), config.getCommonSamples(), config.getCommonExperiments()); } catch (ConfigurationFailureException e) { notificationLog.error(e.getMessage()); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UserManager.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UserManager.java index 06eddfc87de..7415906d9e0 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UserManager.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UserManager.java @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -33,6 +34,7 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import org.apache.commons.collections4.map.LinkedMap; +import org.apache.commons.lang.StringUtils; import ch.ethz.sis.openbis.generic.asapi.v3.dto.authorizationgroup.AuthorizationGroup; import ch.ethz.sis.openbis.generic.asapi.v3.dto.authorizationgroup.create.AuthorizationGroupCreation; @@ -44,6 +46,10 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.authorizationgroup.update.Author import ch.ethz.sis.openbis.generic.asapi.v3.dto.authorizationgroup.update.UpdateAuthorizationGroupsOperation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.operation.IOperation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.id.EntityTypePermId; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.create.CreateExperimentsOperation; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.create.ExperimentCreation; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.fetchoptions.ExperimentFetchOptions; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.id.ExperimentIdentifier; import ch.ethz.sis.openbis.generic.asapi.v3.dto.operation.SynchronousOperationExecutionOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.person.Person; import ch.ethz.sis.openbis.generic.asapi.v3.dto.person.create.CreatePersonsOperation; @@ -53,6 +59,11 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.person.id.IPersonId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.person.id.PersonPermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.person.search.PersonSearchCriteria; import ch.ethz.sis.openbis.generic.asapi.v3.dto.person.update.PersonUpdate; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.create.CreateProjectsOperation; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.create.ProjectCreation; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.fetchoptions.ProjectFetchOptions; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.id.IProjectId; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.id.ProjectIdentifier; import ch.ethz.sis.openbis.generic.asapi.v3.dto.roleassignment.Role; import ch.ethz.sis.openbis.generic.asapi.v3.dto.roleassignment.RoleAssignment; import ch.ethz.sis.openbis.generic.asapi.v3.dto.roleassignment.RoleLevel; @@ -64,7 +75,7 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.roleassignment.id.IRoleAssignmen import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.create.CreateSamplesOperation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.create.SampleCreation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.fetchoptions.SampleFetchOptions; -import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.id.SamplePermId; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.id.SampleIdentifier; import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.Space; import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.create.CreateSpacesOperation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.create.SpaceCreation; @@ -107,7 +118,9 @@ public class UserManager private Map<Role, List<String>> commonSpacesByRole = new HashMap<>(); - private Map<String, String> commonSamplesByCode = new HashMap<>(); + private Map<String, String> commonSamples = new HashMap<>(); + + private Map<String, String> commonExperiments; private Map<String, HomeSpaceRequest> requestedHomeSpaceByUserId = new TreeMap<>(); @@ -125,21 +138,42 @@ public class UserManager this.globalSpaces = globalSpaces; } - public void setCommonSpacesAndSamples(Map<Role, List<String>> commonSpacesByRole, Map<String, String> commonSamplesByCode) + public void setCommon(Map<Role, List<String>> commonSpacesByRole, Map<String, String> commonSamples, + Map<String, String> commonExperiments) { this.commonSpacesByRole = commonSpacesByRole; - this.commonSamplesByCode = commonSamplesByCode; + this.commonSamples = commonSamples; + this.commonExperiments = commonExperiments; Set<String> commonSpaces = new HashSet<>(); commonSpacesByRole.values().forEach(spaces -> commonSpaces.addAll(spaces)); - for (String sampleCode : commonSamplesByCode.keySet()) + checkIdentifierTemplates(commonSamples, commonSpaces, "sample", "<common space code>/<common sample code>"); + checkIdentifierTemplates(commonExperiments, commonSpaces, "experiment", + "<common space code>/<common project code>/<common experiment code>"); + } + + private void checkIdentifierTemplates(Map<String, String> commonEntities, Set<String> commonSpaces, + String entityKind, String templateSchema) + { + for (String identifierTemplate : commonEntities.keySet()) { - if (commonSpaces.contains(sampleCode) == false) + String[] parts = identifierTemplate.split("/"); + if (commonSpaces.contains(parts[0]) == false) + { + throw createConfigException(identifierTemplate, templateSchema, "No common space for common " + entityKind); + } + if (parts.length != templateSchema.split("/").length) { - throw new ConfigurationFailureException("No common space for common sample '" + sampleCode + "'."); + throw createConfigException(identifierTemplate, templateSchema, ""); } } } + private ConfigurationFailureException createConfigException(String identifierTemplate, String templateSchema, String message) + { + return new ConfigurationFailureException("Identifier template '" + identifierTemplate + "' is invalid" + + (StringUtils.isBlank(message) ? ". " : " (reason: " + message + "). ") + "Template schema: " + templateSchema); + } + public void addGroup(UserGroup group, Map<String, Principal> principalsByUserId) { String groupCode = group.getKey().toUpperCase(); @@ -173,7 +207,8 @@ public class UserManager for (Entry<String, Map<String, Principal>> entry : usersByGroupCode.entrySet()) { String groupCode = entry.getKey(); - manageGroup(sessionToken, groupCode, entry.getValue(), currentState, report); + Map<String, Principal> users = entry.getValue(); + manageGroup(sessionToken, groupCode, users, currentState, report); } updateHomeSpaces(sessionToken, currentState, report); @@ -383,6 +418,7 @@ public class UserManager manageNewGroup(context, groupCode, groupUsers); } createSamples(context, groupCode); + createExperiments(context, groupCode); context.executeOperations(); } catch (Exception e) { @@ -395,18 +431,22 @@ public class UserManager private void createSamples(Context context, String groupCode) { - if (commonSamplesByCode.isEmpty() == false) + if (commonSamples.isEmpty() == false) { + Set<SampleIdentifier> sampleIdentifiers = new LinkedHashSet<>(); String sessionToken = context.getSessionToken(); - for (Entry<String, String> entry : commonSamplesByCode.entrySet()) + for (Entry<String, String> entry : commonSamples.entrySet()) { String sampleType = entry.getValue(); - String spaceCode = createCommonSpaceCode(groupCode, entry.getKey()); - SamplePermId sampleId = new SamplePermId("/" + spaceCode + "/" + spaceCode); + String[] identifierTemplateParts = entry.getKey().split("/"); + String spaceCode = createCommonSpaceCode(groupCode, identifierTemplateParts[0]); + String sampleCode = createCommonSpaceCode(groupCode, identifierTemplateParts[1]); + SampleIdentifier sampleId = new SampleIdentifier(spaceCode, null, sampleCode); + sampleIdentifiers.add(sampleId); if (service.getSamples(sessionToken, Arrays.asList(sampleId), new SampleFetchOptions()).isEmpty()) { SampleCreation sampleCreation = new SampleCreation(); - sampleCreation.setCode(spaceCode); + sampleCreation.setCode(sampleCode); sampleCreation.setTypeId(new EntityTypePermId(sampleType)); sampleCreation.setSpaceId(new SpacePermId(spaceCode)); context.add(sampleCreation); @@ -416,8 +456,56 @@ public class UserManager } } + private void createExperiments(Context context, String groupCode) + { + if (commonExperiments.isEmpty() == false) + { + Set<ProjectIdentifier> projectIdentifiers = new LinkedHashSet<>(); + Set<String> keySet = commonExperiments.keySet(); + for (String identifierTemplate : keySet) + { + String[] identifierTemplateParts = identifierTemplate.split("/"); + String spaceCode = createCommonSpaceCode(groupCode, identifierTemplateParts[0]); + String projectCode = createCommonSpaceCode(groupCode, identifierTemplateParts[1]); + projectIdentifiers.add(new ProjectIdentifier(spaceCode, projectCode)); + } + String sessionToken = context.getSessionToken(); + Set<IProjectId> existingProjects = + service.getProjects(sessionToken, new ArrayList<>(projectIdentifiers), new ProjectFetchOptions()).keySet(); + projectIdentifiers.removeAll(existingProjects); + for (ProjectIdentifier identifier : projectIdentifiers) + { + ProjectCreation projectCreation = new ProjectCreation(); + String[] spaceCodeAndProjectCode = identifier.getIdentifier().split("/"); + projectCreation.setSpaceId(new SpacePermId(spaceCodeAndProjectCode[1])); + projectCreation.setCode(spaceCodeAndProjectCode[2]); + context.add(projectCreation); + context.getReport().addProject(identifier); + } + for (Entry<String, String> entry : commonExperiments.entrySet()) + { + String experimentType = entry.getValue(); + String[] identifierTemplateParts = entry.getKey().split("/"); + String spaceCode = createCommonSpaceCode(groupCode, identifierTemplateParts[0]); + String projectCode = createCommonSpaceCode(groupCode, identifierTemplateParts[1]); + String experimentCode = createCommonSpaceCode(groupCode, identifierTemplateParts[2]); + ExperimentIdentifier identifier = new ExperimentIdentifier(spaceCode, projectCode, experimentCode); + if (service.getExperiments(sessionToken, Arrays.asList(identifier), new ExperimentFetchOptions()).isEmpty()) + { + ExperimentCreation experimentCreation = new ExperimentCreation(); + experimentCreation.setProjectId(new ProjectIdentifier(spaceCode, projectCode)); + experimentCreation.setCode(experimentCode); + experimentCreation.setTypeId(new EntityTypePermId(experimentType)); + context.add(experimentCreation); + context.getReport().addExperiment(identifier); + } + } + } + } + private void manageKnownGroup(Context context, String groupCode, Map<String, Principal> groupUsers) { + createCommonSpaces(context, groupCode); manageUsers(context, groupCode, groupUsers); } @@ -426,21 +514,31 @@ public class UserManager String adminGroupCode = createAdminGroupCode(groupCode); assertNoCommonSpaceExists(context, groupCode); - AuthorizationGroupPermId groupId = createAuthorizationGroup(context, groupCode); - AuthorizationGroupPermId adminGroupId = createAuthorizationGroup(context, adminGroupCode); + createAuthorizationGroup(context, groupCode); + createAuthorizationGroup(context, adminGroupCode); + createCommonSpaces(context, groupCode); + + manageUsers(context, groupCode, groupUsers); + } + + private void createCommonSpaces(Context context, String groupCode) + { for (Entry<Role, List<String>> entry : commonSpacesByRole.entrySet()) { Role role = entry.getKey(); - for (String space : entry.getValue()) + for (String commonSpaceCode : entry.getValue()) { - ISpaceId spaceId = createSpace(context, createCommonSpaceCode(groupCode, space)); - createRoleAssignment(context, groupId, role, spaceId); - createRoleAssignment(context, adminGroupId, Role.ADMIN, spaceId); + String spaceCode = createCommonSpaceCode(groupCode, commonSpaceCode); + Space space = context.getCurrentState().getSpace(spaceCode); + if (space == null) + { + ISpaceId spaceId = createSpace(context, spaceCode); + createRoleAssignment(context, new AuthorizationGroupPermId(groupCode), role, spaceId); + createRoleAssignment(context, new AuthorizationGroupPermId(createAdminGroupCode(groupCode)), Role.ADMIN, spaceId); + } } } - - manageUsers(context, groupCode, groupUsers); } private void manageUsers(Context context, String groupCode, Map<String, Principal> groupUsers) @@ -654,6 +752,11 @@ public class UserManager return newUsers.contains(userId) || usersById.containsKey(userId); } + public Space getSpace(String spaceCode) + { + return spacesByCode.get(spaceCode); + } + public int getNumberOfSpacesStartingWith(String userSpaceCode) { Predicate<String> predicate = code -> code.startsWith(userSpaceCode); @@ -817,8 +920,12 @@ public class UserManager private List<SpaceCreation> spaceCreations = new ArrayList<>(); + private List<ProjectCreation> projectCreations = new ArrayList<>(); + private List<SampleCreation> sampleCreations = new ArrayList<>(); + private List<ExperimentCreation> experimentCreations = new ArrayList<>(); + private List<AuthorizationGroupCreation> groupCreations = new ArrayList<>(); private List<AuthorizationGroupUpdate> groupUpdates = new ArrayList<>(); @@ -866,11 +973,21 @@ public class UserManager spaceCreations.add(spaceCreation); } + public void add(ProjectCreation projectCreation) + { + projectCreations.add(projectCreation); + } + public void add(SampleCreation sampleCreation) { sampleCreations.add(sampleCreation); } + public void add(ExperimentCreation experimentCreation) + { + experimentCreations.add(experimentCreation); + } + public void add(AuthorizationGroupCreation creation) { groupCreations.add(creation); @@ -902,10 +1019,18 @@ public class UserManager { operations.add(new CreateSpacesOperation(spaceCreations)); } + if (projectCreations.isEmpty() == false) + { + operations.add(new CreateProjectsOperation(projectCreations)); + } if (sampleCreations.isEmpty() == false) { operations.add(new CreateSamplesOperation(sampleCreations)); } + if (experimentCreations.isEmpty() == false) + { + operations.add(new CreateExperimentsOperation(experimentCreations)); + } if (groupCreations.isEmpty() == false) { operations.add(new CreateAuthorizationGroupsOperation(groupCreations)); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UserManagerConfig.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UserManagerConfig.java index b5ca92f5e3f..282a29d967a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UserManagerConfig.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UserManagerConfig.java @@ -31,6 +31,8 @@ class UserManagerConfig private Map<String, String> commonSamples = new HashMap<>(); + private Map<String, String> commonExperiments = new HashMap<>(); + private List<UserGroup> groups; public List<String> getGlobalSpaces() @@ -63,6 +65,16 @@ class UserManagerConfig this.commonSamples = commonSamples; } + public Map<String, String> getCommonExperiments() + { + return commonExperiments; + } + + public void setCommonExperiments(Map<String, String> commonExperiments) + { + this.commonExperiments = commonExperiments; + } + public List<UserGroup> getGroups() { return groups; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UserManagerReport.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UserManagerReport.java index 0d81c8119c8..84359944846 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UserManagerReport.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/task/UserManagerReport.java @@ -22,8 +22,10 @@ import java.util.List; import java.util.stream.Collectors; import ch.ethz.sis.openbis.generic.asapi.v3.dto.authorizationgroup.id.AuthorizationGroupPermId; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.id.ExperimentIdentifier; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.project.id.ProjectIdentifier; import ch.ethz.sis.openbis.generic.asapi.v3.dto.roleassignment.Role; -import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.id.SamplePermId; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.id.ISampleId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.create.SpaceCreation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.space.id.ISpaceId; import ch.systemsx.cisd.common.utilities.ITimeProvider; @@ -90,11 +92,21 @@ public class UserManagerReport log("ADD-SPACES", spaceCreations.stream().map(SpaceCreation::getCode).collect(Collectors.toList()).toString()); } - void addSample(SamplePermId sampleId) + void addSample(ISampleId sampleId) { log("ADD-SAMPLE", sampleId); } + void addProject(ProjectIdentifier identifier) + { + log("ADD-PROJECT", identifier); + } + + void addExperiment(ExperimentIdentifier identifier) + { + log("ADD-EXPERIMENT", identifier); + } + void assignRoleTo(AuthorizationGroupPermId groupId, Role role, ISpaceId spaceId) { log("ASSIGN-ROLE-TO-AUTHORIZATION-GROUP", "group: " + groupId + ", role: SPACE_" + role + " for " + spaceId); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/task/UserManagementMaintenanceTaskTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/task/UserManagementMaintenanceTaskTest.java index f39f7cbc262..e9a8a750304 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/task/UserManagementMaintenanceTaskTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/task/UserManagementMaintenanceTaskTest.java @@ -190,6 +190,7 @@ public class UserManagementMaintenanceTaskTest extends AbstractFileSystemTestCas + "INFO OPERATION.UserManagementMaintenanceTask - Global spaces: []\n" + "INFO OPERATION.UserManagementMaintenanceTask - Common spaces: {}\n" + "INFO OPERATION.UserManagementMaintenanceTask - Common samples: {}\n" + + "INFO OPERATION.UserManagementMaintenanceTask - Common experiments: {}\n" + "ERROR OPERATION.UserManagementMaintenanceTask - No ldapGroupKeys specified for group 'ABC'. Task aborted.", logRecorder.getLogContent()); } @@ -214,6 +215,7 @@ public class UserManagementMaintenanceTaskTest extends AbstractFileSystemTestCas + "INFO OPERATION.UserManagementMaintenanceTask - Global spaces: []\n" + "INFO OPERATION.UserManagementMaintenanceTask - Common spaces: {}\n" + "INFO OPERATION.UserManagementMaintenanceTask - Common samples: {}\n" + + "INFO OPERATION.UserManagementMaintenanceTask - Common experiments: {}\n" + "ERROR OPERATION.UserManagementMaintenanceTask - Empty ldapGroupKey for group 'ABC'. Task aborted.", logRecorder.getLogContent()); } @@ -238,6 +240,7 @@ public class UserManagementMaintenanceTaskTest extends AbstractFileSystemTestCas + "INFO OPERATION.UserManagementMaintenanceTask - Global spaces: []\n" + "INFO OPERATION.UserManagementMaintenanceTask - Common spaces: {}\n" + "INFO OPERATION.UserManagementMaintenanceTask - Common samples: {}\n" + + "INFO OPERATION.UserManagementMaintenanceTask - Common experiments: {}\n" + "ERROR OPERATION.UserManagementMaintenanceTask - No users found for ldapGroupKey 'a1' for group 'ABC'. Task aborted.", logRecorder.getLogContent()); } @@ -265,7 +268,41 @@ public class UserManagementMaintenanceTaskTest extends AbstractFileSystemTestCas + "INFO OPERATION.UserManagementMaintenanceTask - Global spaces: []\n" + "INFO OPERATION.UserManagementMaintenanceTask - Common spaces: {USER=[ALPHA]}\n" + "INFO OPERATION.UserManagementMaintenanceTask - Common samples: {A=B}\n" - + "ERROR NOTIFY.UserManagementMaintenanceTask - No common space for common sample 'A'.\n" + + "INFO OPERATION.UserManagementMaintenanceTask - Common experiments: {}\n" + + "ERROR NOTIFY.UserManagementMaintenanceTask - Identifier template 'A' is invalid " + + "(reason: No common space for common sample). Template schema: <common space code>/<common sample code>\n" + + "INFO OPERATION.UserManagementMaintenanceTask - Add group SIS[name:sis, ldapGroupKeys:[s], admins:null] with users [u1=u1]\n" + + "INFO OPERATION.UserManagementMaintenanceTask - 1 users for group SIS\n" + + "INFO OPERATION.UserManagementMaintenanceTask - finished", + logRecorder.getLogContent()); + } + + @Test + public void testExecuteInvalidCommonExperiments() + { + // Given + UserManagerReport report = new UserManagerReport(new MockTimeProvider(0, 1000)); + UserManagementMaintenanceTaskWithMocks task = new UserManagementMaintenanceTaskWithMocks().withGroup("s", U1) + .withUserManagerReport(report); + FileUtilities.writeToFile(configFile, ""); + task.setUp("", properties); + FileUtilities.writeToFile(configFile, "{\"commonSpaces\":{\"USER\": [\"ALPHA\"]},\"commonExperiments\":{\"ALPHA/B\":\"B\"}," + + "\"groups\": [{\"name\":\"sis\",\"key\":\"SIS\",\"ldapGroupKeys\": [\"s\"]}]}"); + + // When + task.execute(); + + // Then + assertEquals("INFO OPERATION.UserManagementMaintenanceTask - Setup plugin \n" + + "INFO OPERATION.UserManagementMaintenanceTask - Plugin '' initialized. Configuration file: " + + configFile.getAbsolutePath() + "\n" + + "INFO OPERATION.UserManagementMaintenanceTask - manage 1 groups\n" + + "INFO OPERATION.UserManagementMaintenanceTask - Global spaces: []\n" + + "INFO OPERATION.UserManagementMaintenanceTask - Common spaces: {USER=[ALPHA]}\n" + + "INFO OPERATION.UserManagementMaintenanceTask - Common samples: {}\n" + + "INFO OPERATION.UserManagementMaintenanceTask - Common experiments: {ALPHA/B=B}\n" + + "ERROR NOTIFY.UserManagementMaintenanceTask - Identifier template 'ALPHA/B' is invalid. " + + "Template schema: <common space code>/<common project code>/<common experiment code>\n" + "INFO OPERATION.UserManagementMaintenanceTask - Add group SIS[name:sis, ldapGroupKeys:[s], admins:null] with users [u1=u1]\n" + "INFO OPERATION.UserManagementMaintenanceTask - 1 users for group SIS\n" + "INFO OPERATION.UserManagementMaintenanceTask - finished", @@ -285,7 +322,7 @@ public class UserManagementMaintenanceTaskTest extends AbstractFileSystemTestCas FileUtilities.writeToFile(configFile, ""); task.setUp("", properties); FileUtilities.writeToFile(configFile, "{\"globalSpaces\":[\"ES\"],\"commonSpaces\":{\"USER\": [\"ALPHA\"]}," - + "\"commonSamples\":{\"ALPHA\":\"B\"}," + + "\"commonSamples\":{\"ALPHA/B\":\"B\"},\"commonExperiments\":{\"ALPHA/P/E\":\"E\"}," + "\"groups\": [{\"name\":\"sis\",\"key\":\"SIS\",\"ldapGroupKeys\": [\"s\"],\"admins\": [\"u2\"]}]}"); // When @@ -298,7 +335,8 @@ public class UserManagementMaintenanceTaskTest extends AbstractFileSystemTestCas + "INFO OPERATION.UserManagementMaintenanceTask - manage 1 groups\n" + "INFO OPERATION.UserManagementMaintenanceTask - Global spaces: [ES]\n" + "INFO OPERATION.UserManagementMaintenanceTask - Common spaces: {USER=[ALPHA]}\n" - + "INFO OPERATION.UserManagementMaintenanceTask - Common samples: {ALPHA=B}\n" + + "INFO OPERATION.UserManagementMaintenanceTask - Common samples: {ALPHA/B=B}\n" + + "INFO OPERATION.UserManagementMaintenanceTask - Common experiments: {ALPHA/P/E=E}\n" + "INFO OPERATION.UserManagementMaintenanceTask - Add group SIS[name:sis, ldapGroupKeys:[s], admins:[u2]] with users [u1=u1]\n" + "INFO OPERATION.UserManagementMaintenanceTask - 1 users for group SIS\n" + "ERROR NOTIFY.UserManagementMaintenanceTask - User management failed for the following reason(s):\n\n" @@ -393,11 +431,13 @@ public class UserManagementMaintenanceTaskTest extends AbstractFileSystemTestCas } @Override - public void setCommonSpacesAndSamples(Map<Role, List<String>> commonSpacesByRole, Map<String, String> commonSamplesByCode) + public void setCommon(Map<Role, List<String>> commonSpacesByRole, Map<String, String> commonSamples, + Map<String, String> commonExperiments) { logger.log(LogLevel.INFO, "Common spaces: " + commonSpacesByRole); - logger.log(LogLevel.INFO, "Common samples: " + commonSamplesByCode); - super.setCommonSpacesAndSamples(commonSpacesByRole, commonSamplesByCode); + logger.log(LogLevel.INFO, "Common samples: " + commonSamples); + logger.log(LogLevel.INFO, "Common experiments: " + commonExperiments); + super.setCommon(commonSpacesByRole, commonSamples, commonExperiments); } @Override diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/task/UserManagerExpectationsBuilder.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/task/UserManagerExpectationsBuilder.java index 85c859f6c01..02f00d01776 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/task/UserManagerExpectationsBuilder.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/task/UserManagerExpectationsBuilder.java @@ -37,6 +37,9 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.authorizationgroup.Authorization import ch.ethz.sis.openbis.generic.asapi.v3.dto.authorizationgroup.fetchoptions.AuthorizationGroupFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.authorizationgroup.id.AuthorizationGroupPermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.id.ObjectPermId; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.Experiment; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.fetchoptions.ExperimentFetchOptions; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.id.ExperimentIdentifier; import ch.ethz.sis.openbis.generic.asapi.v3.dto.person.Person; import ch.ethz.sis.openbis.generic.asapi.v3.dto.person.fetchoptions.PersonFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.person.id.IPersonId; @@ -86,6 +89,8 @@ class UserManagerExpectationsBuilder private Map<String, List<String>> sampleIdentifiersByType = new TreeMap<>(); + private Map<String, List<String>> experimentIdentifiersByType = new TreeMap<>(); + private Map<String, Map<AuthorizationLevel, Set<String>>> usersByLevelBySpace = new TreeMap<>(); UserManagerExpectationsBuilder(IApplicationServerInternalApi v3api, UserManagerTestService testService, @@ -137,13 +142,23 @@ class UserManagerExpectationsBuilder UserManagerExpectationsBuilder samples(String type, String... sampleIdentifiers) { - List<String> list = sampleIdentifiersByType.get(type); + return addIdentifiers(sampleIdentifiersByType, type, sampleIdentifiers); + } + + UserManagerExpectationsBuilder experiments(String type, String... experimentIdentifiers) + { + return addIdentifiers(experimentIdentifiersByType, type, experimentIdentifiers); + } + + private UserManagerExpectationsBuilder addIdentifiers(Map<String, List<String>> identifiersByType, String type, String... identifiers) + { + List<String> list = identifiersByType.get(type); if (list == null) { list = new ArrayList<String>(); - sampleIdentifiersByType.put(type, list); + identifiersByType.put(type, list); } - list.addAll(Arrays.asList(sampleIdentifiers)); + list.addAll(Arrays.asList(identifiers)); return this; } @@ -174,6 +189,7 @@ class UserManagerExpectationsBuilder { String sessionToken = v3api.login(TEST_USER, PASSWORD); assertSamples(sessionToken); + assertExperiments(sessionToken); assertSpaces(sessionToken); assertUnknownUsers(sessionToken); assertUsers(sessionToken); @@ -206,8 +222,7 @@ class UserManagerExpectationsBuilder { if (sampleIdentifiersByType.isEmpty() == false) { - Set<Entry<String, List<String>>> entrySet = sampleIdentifiersByType.entrySet(); - for (Entry<String, List<String>> entry : entrySet) + for (Entry<String, List<String>> entry : sampleIdentifiersByType.entrySet()) { String typeCode = entry.getKey(); List<String> sampleIdentifiers = entry.getValue(); @@ -223,6 +238,28 @@ class UserManagerExpectationsBuilder } } } + + private void assertExperiments(String sessionToken) + { + if (experimentIdentifiersByType.isEmpty() == false) + { + Set<Entry<String, List<String>>> entrySet = experimentIdentifiersByType.entrySet(); + for (Entry<String, List<String>> entry : entrySet) + { + String typeCode = entry.getKey(); + List<String> identifiers = entry.getValue(); + Collections.sort(identifiers); + List<ExperimentIdentifier> experimentIds = identifiers.stream().map(ExperimentIdentifier::new).collect(Collectors.toList()); + ExperimentFetchOptions fetchOptions = new ExperimentFetchOptions(); + fetchOptions.withType(); + Collection<Experiment> experiments = v3api.getExperiments(sessionToken, experimentIds, fetchOptions).values(); + List<String> actualIdentifiers = experiments.stream().map(e -> e.getIdentifier().getIdentifier()).collect(Collectors.toList()); + Collections.sort(actualIdentifiers); + assertEquals(actualIdentifiers.toString(), identifiers.toString()); + experiments.forEach(s -> assertEquals(s.getType().getCode(), typeCode, "Type of experiment " + s.getIdentifier())); + } + } + } private void checkMissingAuthorizationExpectations() { @@ -246,7 +283,7 @@ class UserManagerExpectationsBuilder private void assertSpaces(String sessionToken) { Set<String> spaceCodes = usersByLevelBySpace.keySet(); - assertEquals(spaceCodes.isEmpty(), false); + assertEquals(spaceCodes.isEmpty(), false, "Spaces"); List<SpacePermId> spaceIds = spaceCodes.stream().map(SpacePermId::new).collect(Collectors.toList()); Collection<Space> spaces = v3api.getSpaces(sessionToken, spaceIds, new SpaceFetchOptions()).values(); List<String> actualSpaces = spaces.stream().map(Space::getCode).collect(Collectors.toList()); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/task/UserManagerTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/task/UserManagerTest.java index 578c5b08bef..04f9518ea9e 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/task/UserManagerTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/task/UserManagerTest.java @@ -55,6 +55,10 @@ import ch.systemsx.cisd.openbis.generic.shared.IOpenBisSessionManager; */ public class UserManagerTest extends AbstractTest { + private static final String EXPERIMENT_TYPE = "DELETION_TEST"; + + private static final String SAMPLE_TYPE = "NORMAL"; + private static final Principal U1 = new Principal("u1", "Albert", "Einstein", "a.e@abc.de"); private static final Principal U2 = new Principal("u2", "Isaac", "Newton", "i.n@abc.de"); @@ -81,7 +85,7 @@ public class UserManagerTest extends AbstractTest public void testCreateOneGroupWithAUserWhichAlreadyHasAHomeSpace() { // Given - // 1. create user U2 with home space TEST-SPACE and SPACE_ADMIN on this space + // 1. create user U2 with home space TEST-SPACE and SPACE_ADMIN on this space createUserForTestSpace(U2); // 2. create groip G1 with users U1 (admin) and U2 MockLogger logger = new MockLogger(); @@ -126,6 +130,61 @@ public class UserManagerTest extends AbstractTest builder.assertExpectations(); } + @Test + public void testAddGlobalSpacesAndCommonSpacesSamplesAndExperiments() + { + // Given + // 1. create group G1 with users U1 (admin) and U2 + MockLogger logger = new MockLogger(); + Map<Role, List<String>> commonSpaces = new EnumMap<>(Role.class); + commonSpaces.put(Role.USER, Arrays.asList("ALPHA", "BETA")); + commonSpaces.put(Role.OBSERVER, Arrays.asList("GAMMA")); + UserManager userManager = new UserManagerBuilder(v3api, logger) + .commonSpaces(commonSpaces).commonSample("GAMMA/G", SAMPLE_TYPE) + .commonExperiment("ALPHA/P1/E1", EXPERIMENT_TYPE).get(); + userManager.setGlobalSpaces(Arrays.asList("A", "B")); + userManager.addGroup(group("G1", U1.getUserId()), users(U1)); + assertEquals(manage(userManager).getErrorReport(), ""); + createBuilder().groups("G1").samples(SAMPLE_TYPE, "/G1_GAMMA/G1_G").space("G1_ALPHA").assertExpectations(); + // 2. add common spaces, samples and experiments + commonSpaces.put(Role.OBSERVER, Arrays.asList("GAMMA", "DELTA")); + userManager = new UserManagerBuilder(v3api, logger) + .commonSpaces(commonSpaces).commonSample("GAMMA/G", SAMPLE_TYPE).commonSample("ALPHA/G", SAMPLE_TYPE) + .commonExperiment("ALPHA/P1/E1", EXPERIMENT_TYPE).commonExperiment("ALPHA/P1/E2", EXPERIMENT_TYPE) + .commonExperiment("BETA/P1/E1", EXPERIMENT_TYPE).get(); + userManager.setGlobalSpaces(Arrays.asList("A", "C")); + userManager.addGroup(group("G1", U1.getUserId()), users(U1)); + + // When + UserManagerReport report = manage(userManager); + + // Then + assertEquals(report.getErrorReport(), ""); + assertEquals(report.getAuditLog(), "1970-01-01 01:00:00 [ADD-SPACES] [C]\n" + + "1970-01-01 01:00:01 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: ALL_GROUPS, role: SPACE_OBSERVER for C\n" + + "1970-01-01 01:00:02 [ADD-SPACE] G1_DELTA\n" + + "1970-01-01 01:00:03 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: G1, role: SPACE_OBSERVER for G1_DELTA\n" + + "1970-01-01 01:00:04 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: G1_ADMIN, role: SPACE_ADMIN for G1_DELTA\n" + + "1970-01-01 01:00:05 [ADD-SAMPLE] /G1_ALPHA/G1_G\n" + + "1970-01-01 01:00:06 [ADD-PROJECT] /G1_BETA/G1_P1\n" + + "1970-01-01 01:00:07 [ADD-EXPERIMENT] /G1_ALPHA/G1_P1/G1_E2\n" + + "1970-01-01 01:00:08 [ADD-EXPERIMENT] /G1_BETA/G1_P1/G1_E1\n"); + UserManagerExpectationsBuilder builder = createBuilder(); + builder.globalSpaces(Arrays.asList("A", "B", "C")).groups("G1").commonSpaces(commonSpaces).users(U1); + builder.samples(SAMPLE_TYPE, "/G1_GAMMA/G1_G", "/G1_ALPHA/G1_G"); + builder.experiments(EXPERIMENT_TYPE, "/G1_ALPHA/G1_P1/G1_E1", "/G1_ALPHA/G1_P1/G1_E2", "/G1_BETA/G1_P1/G1_E1"); + builder.space("A").observer(U1); + builder.space("B").observer(U1); + builder.space("C").observer(U1); + builder.space("G1_ALPHA").admin(U1); + builder.space("G1_BETA").admin(U1); + builder.space("G1_GAMMA").admin(U1); + builder.space("G1_DELTA").admin(U1); + builder.space("G1_U1").admin(U1); + builder.homeSpace(U1, "G1_U1"); + builder.assertExpectations(); + } + private void createUserForTestSpace(Principal user) { String sessionToken = v3api.login(TEST_USER, PASSWORD); @@ -150,10 +209,10 @@ public class UserManagerTest extends AbstractTest Map<Role, List<String>> commonSpaces = commonSpaces(); UserManager userManager = new UserManagerBuilder(v3api, logger).commonSpaces(commonSpaces).get(); userManager.addGroup(group("G1", U1.getUserId(), "blabla"), users(U1, U2)); - + // When UserManagerReport report = manage(userManager); - + // Then assertEquals(report.getErrorReport(), ""); assertEquals(report.getAuditLog(), "1970-01-01 01:00:00 [ADD-AUTHORIZATION-GROUP] G1\n" @@ -188,15 +247,16 @@ public class UserManagerTest extends AbstractTest builder.homeSpace(U2, "G1_U2"); builder.assertExpectations(); } - + @Test - public void testCreateTwoGroupsWithSamplesDistinctUsers() + public void testCreateTwoGroupsWithSamplesExperimentsDistinctUsers() { // Given MockLogger logger = new MockLogger(); Map<Role, List<String>> commonSpaces = commonSpaces(); UserManager userManager = new UserManagerBuilder(v3api, logger) - .commonSpaces(commonSpaces).commonSample("GAMMA", "NORMAL").globalSpace("ALL").get(); + .commonSpaces(commonSpaces).commonSample("GAMMA/G", SAMPLE_TYPE) + .commonExperiment("ALPHA/ST/STC", EXPERIMENT_TYPE).get(); List<String> globalSpaces = Arrays.asList("A", "B"); userManager.setGlobalSpaces(globalSpaces); userManager.addGroup(group("G1", U1.getUserId(), "blabla"), users(U3, U1, U2)); @@ -238,32 +298,37 @@ public class UserManagerTest extends AbstractTest + "1970-01-01 01:00:28 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: G1_ADMIN, role: SPACE_ADMIN for G1_U3\n" + "1970-01-01 01:00:29 [ADD-USER-TO-AUTHORIZATION-GROUP] group: G1, user: u3\n" + "1970-01-01 01:00:30 [ADD-USER-TO-AUTHORIZATION-GROUP] group: ALL_GROUPS, user: u3\n" - + "1970-01-01 01:00:31 [ADD-SAMPLE] /G1_GAMMA/G1_GAMMA\n" - + "1970-01-01 01:00:32 [ADD-AUTHORIZATION-GROUP] G2\n" - + "1970-01-01 01:00:33 [ADD-AUTHORIZATION-GROUP] G2_ADMIN\n" - + "1970-01-01 01:00:34 [ADD-SPACE] G2_ALPHA\n" - + "1970-01-01 01:00:35 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: G2, role: SPACE_USER for G2_ALPHA\n" - + "1970-01-01 01:00:36 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: G2_ADMIN, role: SPACE_ADMIN for G2_ALPHA\n" - + "1970-01-01 01:00:37 [ADD-SPACE] G2_BETA\n" - + "1970-01-01 01:00:38 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: G2, role: SPACE_USER for G2_BETA\n" - + "1970-01-01 01:00:39 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: G2_ADMIN, role: SPACE_ADMIN for G2_BETA\n" - + "1970-01-01 01:00:40 [ADD-SPACE] G2_GAMMA\n" - + "1970-01-01 01:00:41 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: G2, role: SPACE_OBSERVER for G2_GAMMA\n" - + "1970-01-01 01:00:42 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: G2_ADMIN, role: SPACE_ADMIN for G2_GAMMA\n" - + "1970-01-01 01:00:43 [ADD-SPACE] G2_U4\n" - + "1970-01-01 01:00:44 [ADD-USER] u4\n" - + "1970-01-01 01:00:45 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: G2_ADMIN, role: SPACE_ADMIN for G2_U4\n" - + "1970-01-01 01:00:46 [ADD-USER-TO-AUTHORIZATION-GROUP] group: G2, user: u4\n" - + "1970-01-01 01:00:47 [ADD-USER-TO-AUTHORIZATION-GROUP] group: ALL_GROUPS, user: u4\n" - + "1970-01-01 01:00:48 [ADD-USER-TO-AUTHORIZATION-GROUP] group: G2_ADMIN, user: u4\n" - + "1970-01-01 01:00:49 [ADD-SAMPLE] /G2_GAMMA/G2_GAMMA\n" - + "1970-01-01 01:00:50 [ASSIGN-HOME-SPACE-FOR-USER] user: u1, home space: G1_U1\n" - + "1970-01-01 01:00:51 [ASSIGN-HOME-SPACE-FOR-USER] user: u2, home space: G1_U2\n" - + "1970-01-01 01:00:52 [ASSIGN-HOME-SPACE-FOR-USER] user: u3, home space: G1_U3\n" - + "1970-01-01 01:00:53 [ASSIGN-HOME-SPACE-FOR-USER] user: u4, home space: G2_U4\n"); + + "1970-01-01 01:00:31 [ADD-SAMPLE] /G1_GAMMA/G1_G\n" + + "1970-01-01 01:00:32 [ADD-PROJECT] /G1_ALPHA/G1_ST\n" + + "1970-01-01 01:00:33 [ADD-EXPERIMENT] /G1_ALPHA/G1_ST/G1_STC\n" + + "1970-01-01 01:00:34 [ADD-AUTHORIZATION-GROUP] G2\n" + + "1970-01-01 01:00:35 [ADD-AUTHORIZATION-GROUP] G2_ADMIN\n" + + "1970-01-01 01:00:36 [ADD-SPACE] G2_ALPHA\n" + + "1970-01-01 01:00:37 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: G2, role: SPACE_USER for G2_ALPHA\n" + + "1970-01-01 01:00:38 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: G2_ADMIN, role: SPACE_ADMIN for G2_ALPHA\n" + + "1970-01-01 01:00:39 [ADD-SPACE] G2_BETA\n" + + "1970-01-01 01:00:40 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: G2, role: SPACE_USER for G2_BETA\n" + + "1970-01-01 01:00:41 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: G2_ADMIN, role: SPACE_ADMIN for G2_BETA\n" + + "1970-01-01 01:00:42 [ADD-SPACE] G2_GAMMA\n" + + "1970-01-01 01:00:43 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: G2, role: SPACE_OBSERVER for G2_GAMMA\n" + + "1970-01-01 01:00:44 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: G2_ADMIN, role: SPACE_ADMIN for G2_GAMMA\n" + + "1970-01-01 01:00:45 [ADD-SPACE] G2_U4\n" + + "1970-01-01 01:00:46 [ADD-USER] u4\n" + + "1970-01-01 01:00:47 [ASSIGN-ROLE-TO-AUTHORIZATION-GROUP] group: G2_ADMIN, role: SPACE_ADMIN for G2_U4\n" + + "1970-01-01 01:00:48 [ADD-USER-TO-AUTHORIZATION-GROUP] group: G2, user: u4\n" + + "1970-01-01 01:00:49 [ADD-USER-TO-AUTHORIZATION-GROUP] group: ALL_GROUPS, user: u4\n" + + "1970-01-01 01:00:50 [ADD-USER-TO-AUTHORIZATION-GROUP] group: G2_ADMIN, user: u4\n" + + "1970-01-01 01:00:51 [ADD-SAMPLE] /G2_GAMMA/G2_G\n" + + "1970-01-01 01:00:52 [ADD-PROJECT] /G2_ALPHA/G2_ST\n" + + "1970-01-01 01:00:53 [ADD-EXPERIMENT] /G2_ALPHA/G2_ST/G2_STC\n" + + "1970-01-01 01:00:54 [ASSIGN-HOME-SPACE-FOR-USER] user: u1, home space: G1_U1\n" + + "1970-01-01 01:00:55 [ASSIGN-HOME-SPACE-FOR-USER] user: u2, home space: G1_U2\n" + + "1970-01-01 01:00:56 [ASSIGN-HOME-SPACE-FOR-USER] user: u3, home space: G1_U3\n" + + "1970-01-01 01:00:57 [ASSIGN-HOME-SPACE-FOR-USER] user: u4, home space: G2_U4\n"); UserManagerExpectationsBuilder builder = createBuilder(); builder.globalSpaces(globalSpaces).groups("G1", "G2").commonSpaces(commonSpaces).users(U1, U2, U3, U4); - builder.samples("NORMAL", "/G1_GAMMA/G1_GAMMA", "/G2_GAMMA/G2_GAMMA"); + builder.samples(SAMPLE_TYPE, "/G1_GAMMA/G1_G", "/G2_GAMMA/G2_G"); + builder.experiments(EXPERIMENT_TYPE, "/G1_ALPHA/G1_ST/G1_STC", "/G2_ALPHA/G2_ST/G2_STC"); builder.space("A").observer(U1, U2, U3, U4); builder.space("B").observer(U1, U2, U3, U4); builder.space("G1_ALPHA").admin(U1).user(U2, U3).non(U4); @@ -930,7 +995,7 @@ public class UserManagerTest extends AbstractTest public void testCreateTwoGroupsAndMoveUserWithTestSpaceAsHomeSpaceFromSecondGroupToFirstGroup() { // Given - // 1. create user U4 with home space TEST-SPACE and SPACE_ADMIN on this space + // 1. create user U4 with home space TEST-SPACE and SPACE_ADMIN on this space createUserForTestSpace(U4); // 2. create group G1 with users U1 (admin) and U2 MockLogger logger = new MockLogger(); @@ -947,10 +1012,10 @@ public class UserManagerTest extends AbstractTest userManager = new UserManagerBuilder(v3api, logger).commonSpaces(commonSpaces).get(); userManager.addGroup(group("G1", U1.getUserId()), users(U1, U2, U4)); userManager.addGroup(group("G2", U3.getUserId()), users(U3)); - + // When UserManagerReport report = manage(userManager); - + // Then assertEquals(report.getErrorReport(), ""); assertEquals(report.getAuditLog(), "1970-01-01 01:00:00 [ADD-SPACE] G1_U4\n" @@ -977,7 +1042,7 @@ public class UserManagerTest extends AbstractTest builder.homeSpace(U4, "TEST-SPACE"); builder.assertExpectations(); } - + @Test public void testUserFromAGroupHasLefted() { @@ -1148,7 +1213,9 @@ public class UserManagerTest extends AbstractTest private Map<Role, List<String>> commonSpacesByRole = new TreeMap<>(); - private Map<String, String> commonSamplesByCode = new TreeMap<>(); + private Map<String, String> commonSamples = new TreeMap<>(); + + private Map<String, String> commonExperiments = new TreeMap<>(); UserManagerBuilder(IApplicationServerInternalApi service, ISimpleLogger logger) { @@ -1172,7 +1239,7 @@ public class UserManagerTest extends AbstractTest }; UserManager userManager = new UserManager(authenticationService, service, logger, new MockTimeProvider(0, 1000)); userManager.setGlobalSpaces(globalSpaces); - userManager.setCommonSpacesAndSamples(commonSpacesByRole, commonSamplesByCode); + userManager.setCommon(commonSpacesByRole, commonSamples, commonExperiments); return userManager; } @@ -1182,21 +1249,21 @@ public class UserManagerTest extends AbstractTest return this; } - private UserManagerBuilder globalSpace(String spaceCode) + private UserManagerBuilder commonSpaces(Map<Role, List<String>> commonSpaces) { - globalSpaces.add(spaceCode); + commonSpacesByRole = commonSpaces; return this; } - private UserManagerBuilder commonSpaces(Map<Role, List<String>> commonSpaces) + private UserManagerBuilder commonSample(String sampleIdentifierTemplate, String sampleType) { - commonSpacesByRole = commonSpaces; + commonSamples.put(sampleIdentifierTemplate, sampleType); return this; } - private UserManagerBuilder commonSample(String sampleCode, String sampleType) + private UserManagerBuilder commonExperiment(String experimentIdentifierTemplate, String experimentType) { - commonSamplesByCode.put(sampleCode, sampleType); + commonExperiments.put(experimentIdentifierTemplate, experimentType); return this; } } -- GitLab