@Test public void testValidateRolesAssignments_roleWithInfiniteCardinality() { final String caseRole = "test"; final Integer caseRoleCardinality = -1; final Map<String, Integer> role = Collections.singletonMap(caseRole, caseRoleCardinality); final CaseDefinitionSummary cds = CaseDefinitionSummary.builder().roles(role).build(); final CaseRoleAssignmentSummary caseRoleAssignmentSummaryMock = mock(CaseRoleAssignmentSummary.class); final List<CaseRoleAssignmentSummary> roles = singletonList(caseRoleAssignmentSummaryMock); when(caseRoleAssignmentSummaryMock.getName()).thenReturn(caseRole); when(caseRoleAssignmentSummaryMock.getUsers()).thenReturn(null); try{ caseRolesValidations.validateRolesAssignments(cds, roles); } catch (NullPointerException e) { Assert.fail("Case role cardinality = " + caseRoleCardinality + ", role assignments check should be skipped"); } }
public List<String> validateRolesAssignments(final CaseDefinitionSummary caseDefinition, final List<CaseRoleAssignmentSummary> assignments) { final List<String> errors = new ArrayList<>(); assignments.forEach(a -> { final Integer roleCardinality = caseDefinition.getRoles().get(a.getName()); if (roleCardinality == -1) { return; } final Integer roleAssignments = a.getUsers().size() + a.getGroups().size(); if (roleAssignments > roleCardinality) { errors.add(translationService.format(INVALID_ROLE_ASSIGNMENT, a.getName(), roleCardinality)); } }); return errors; }
CaseRolesValidations { public List<String> validateRolesAssignments(final CaseDefinitionSummary caseDefinition, final List<CaseRoleAssignmentSummary> assignments) { final List<String> errors = new ArrayList<>(); assignments.forEach(a -> { final Integer roleCardinality = caseDefinition.getRoles().get(a.getName()); if (roleCardinality == -1) { return; } final Integer roleAssignments = a.getUsers().size() + a.getGroups().size(); if (roleAssignments > roleCardinality) { errors.add(translationService.format(INVALID_ROLE_ASSIGNMENT, a.getName(), roleCardinality)); } }); return errors; } }
CaseRolesValidations { public List<String> validateRolesAssignments(final CaseDefinitionSummary caseDefinition, final List<CaseRoleAssignmentSummary> assignments) { final List<String> errors = new ArrayList<>(); assignments.forEach(a -> { final Integer roleCardinality = caseDefinition.getRoles().get(a.getName()); if (roleCardinality == -1) { return; } final Integer roleAssignments = a.getUsers().size() + a.getGroups().size(); if (roleAssignments > roleCardinality) { errors.add(translationService.format(INVALID_ROLE_ASSIGNMENT, a.getName(), roleCardinality)); } }); return errors; }  }
CaseRolesValidations { public List<String> validateRolesAssignments(final CaseDefinitionSummary caseDefinition, final List<CaseRoleAssignmentSummary> assignments) { final List<String> errors = new ArrayList<>(); assignments.forEach(a -> { final Integer roleCardinality = caseDefinition.getRoles().get(a.getName()); if (roleCardinality == -1) { return; } final Integer roleAssignments = a.getUsers().size() + a.getGroups().size(); if (roleAssignments > roleCardinality) { errors.add(translationService.format(INVALID_ROLE_ASSIGNMENT, a.getName(), roleCardinality)); } }); return errors; }  List<String> validateRolesAssignments(final CaseDefinitionSummary caseDefinition,
                                                 final List<CaseRoleAssignmentSummary> assignments); }
CaseRolesValidations { public List<String> validateRolesAssignments(final CaseDefinitionSummary caseDefinition, final List<CaseRoleAssignmentSummary> assignments) { final List<String> errors = new ArrayList<>(); assignments.forEach(a -> { final Integer roleCardinality = caseDefinition.getRoles().get(a.getName()); if (roleCardinality == -1) { return; } final Integer roleAssignments = a.getUsers().size() + a.getGroups().size(); if (roleAssignments > roleCardinality) { errors.add(translationService.format(INVALID_ROLE_ASSIGNMENT, a.getName(), roleCardinality)); } }); return errors; }  List<String> validateRolesAssignments(final CaseDefinitionSummary caseDefinition,
                                                 final List<CaseRoleAssignmentSummary> assignments);  }