use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method testExecuteRequestForSameAutomaticRole.
@Test
public void testExecuteRequestForSameAutomaticRole() {
IdmRoleDto role = getHelper().createRole();
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity);
//
// create two requests
IdmRoleRequestDto requestOne = new IdmRoleRequestDto();
requestOne.setApplicant(identity.getId());
requestOne.setExecuteImmediately(true);
requestOne.setRequestedByType(RoleRequestedByType.MANUALLY);
requestOne.setState(RoleRequestState.EXECUTED);
requestOne = roleRequestService.save(requestOne);
Assert.assertEquals(RoleRequestState.CONCEPT, requestOne.getState());
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setRoleRequest(requestOne.getId());
concept.setState(RoleRequestState.EXECUTED);
concept.setOperation(ConceptRoleRequestOperation.ADD);
concept.setRole(role.getId());
concept.setAutomaticRole(automaticRole.getId());
concept.setIdentityContract(primeContract.getId());
concept = conceptRoleRequestService.save(concept);
Assert.assertEquals(RoleRequestState.CONCEPT, concept.getState());
//
// create two requests
IdmRoleRequestDto requestTwo = new IdmRoleRequestDto();
requestTwo.setApplicant(identity.getId());
requestTwo.setExecuteImmediately(true);
requestTwo.setRequestedByType(RoleRequestedByType.MANUALLY);
requestTwo.setState(RoleRequestState.EXECUTED);
requestTwo = roleRequestService.save(requestTwo);
Assert.assertEquals(RoleRequestState.CONCEPT, requestTwo.getState());
concept = new IdmConceptRoleRequestDto();
concept.setRoleRequest(requestTwo.getId());
concept.setState(RoleRequestState.EXECUTED);
concept.setOperation(ConceptRoleRequestOperation.ADD);
concept.setRole(role.getId());
concept.setAutomaticRole(automaticRole.getId());
concept.setIdentityContract(primeContract.getId());
concept = conceptRoleRequestService.save(concept);
Assert.assertEquals(RoleRequestState.CONCEPT, concept.getState());
getHelper().startRequestInternal(requestOne, true, true);
requestOne = roleRequestService.get(requestOne.getId());
Assert.assertEquals(RoleRequestState.EXECUTED, requestOne.getState());
getHelper().startRequestInternal(requestTwo, true, true);
requestTwo = roleRequestService.get(requestTwo.getId());
Assert.assertEquals(RoleRequestState.EXECUTED, requestTwo.getState());
//
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().allMatch(ir -> ir.getAutomaticRole().equals(automaticRole.getId())));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method createDeleteRoleRequest.
public IdmRoleRequestDto createDeleteRoleRequest(IdmIdentityContractDto contract, List<IdmIdentityRoleDto> assignedRoles) {
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setApplicant(contract.getIdentity());
roleRequest.setRequestedByType(RoleRequestedByType.MANUALLY);
roleRequest.setExecuteImmediately(true);
roleRequest = roleRequestService.save(roleRequest);
//
for (IdmIdentityRoleDto assignedRole : assignedRoles) {
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setRoleRequest(roleRequest.getId());
conceptRoleRequest.setIdentityContract(contract.getId());
conceptRoleRequest.setValidFrom(contract.getValidFrom());
conceptRoleRequest.setValidTill(contract.getValidTill());
conceptRoleRequest.setRole(assignedRole.getRole());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.REMOVE);
conceptRoleRequest.setIdentityRole(assignedRole.getId());
//
conceptRoleRequestService.save(conceptRoleRequest);
}
return roleRequest;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method testCopyRolesWithParametersWithoutValues.
@Test
@Transactional
public void testCopyRolesWithParametersWithoutValues() {
String attributeOneCode = "attr-" + System.currentTimeMillis();
String attributeTwoCode = "attr-two-" + System.currentTimeMillis();
String attributeThreeCode = "attr-three-" + System.currentTimeMillis();
// Prepare identity, role and parameters
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmRoleDto roleOne = getHelper().createRole();
IdmRoleDto roleTwo = getHelper().createRole();
IdmFormAttributeDto attributeOne = new IdmFormAttributeDto(attributeOneCode);
attributeOne.setPersistentType(PersistentType.SHORTTEXT);
attributeOne.setRequired(false);
IdmFormAttributeDto attributeTwo = new IdmFormAttributeDto(attributeTwoCode);
attributeTwo.setPersistentType(PersistentType.SHORTTEXT);
attributeTwo.setRequired(false);
IdmFormAttributeDto attributeThree = new IdmFormAttributeDto(attributeThreeCode);
attributeThree.setPersistentType(PersistentType.SHORTTEXT);
attributeThree.setRequired(true);
IdmFormDefinitionDto definition = formService.createDefinition(IdmIdentityRole.class, FormService.DEFAULT_DEFINITION_CODE, ImmutableList.of(attributeOne, attributeTwo, attributeThree));
roleOne.setIdentityRoleAttributeDefinition(definition.getId());
roleOne = roleService.save(roleOne);
IdmRoleDto roleOneFinal = roleOne;
definition.getFormAttributes().forEach(attribute -> {
if (!attributeThreeCode.equals(attribute.getCode())) {
roleFormAttributeService.addAttributeToSubdefintion(roleOneFinal, attribute);
}
});
IdmIdentityContractDto identityContact = getHelper().createContract(identity);
this.getHelper().createIdentityRole(identityContact, roleOne);
this.getHelper().createIdentityRole(identityContact, roleTwo);
// Assign roles by identity
IdmIdentityDto identityDto = this.getHelper().createIdentity((GuardedString) null);
List<IdmIdentityRoleDto> allByIdentity = identityRoleService.findAllByIdentity(identity.getId());
List<UUID> identityRolesId = allByIdentity.stream().map(IdmIdentityRoleDto::getId).collect(Collectors.toList());
IdmIdentityContractDto identityContractDto = getHelper().createContract(identityDto);
IdmRoleRequestDto createdRequest = roleRequestService.createRequest(identityContractDto);
IdmRoleRequestByIdentityDto requestByIdentityDto = new IdmRoleRequestByIdentityDto();
requestByIdentityDto.setIdentityContract(identityContractDto.getId());
requestByIdentityDto.setRoleRequest(createdRequest.getId());
requestByIdentityDto.setIdentityRoles(identityRolesId);
requestByIdentityDto.setCopyRoleParameters(true);
IdmRoleRequestDto copyRolesByIdentity = roleRequestService.copyRolesByIdentity(requestByIdentityDto);
List<IdmConceptRoleRequestDto> concepts = conceptRoleRequestService.findAllByRoleRequest(copyRolesByIdentity.getId());
assertEquals(2, concepts.size());
UUID roleOneId = roleOne.getId();
IdmConceptRoleRequestDto conceptOne = concepts.stream().filter(concept -> {
return concept.getRole().equals(roleOneId);
}).findAny().orElse(null);
assertNotNull(conceptOne);
IdmConceptRoleRequestDto conceptTwo = concepts.stream().filter(concept -> {
return concept.getRole().equals(roleTwo.getId());
}).findAny().orElse(null);
assertNotNull(conceptTwo);
IdmFormInstanceDto formInstanceOne = conceptRoleRequestService.getRoleAttributeValues(conceptOne, false);
IdmFormInstanceDto formInstanceTwo = conceptRoleRequestService.getRoleAttributeValues(conceptTwo, false);
assertNotNull(formInstanceOne);
assertTrue(formInstanceOne.getValues().isEmpty());
assertNull(formInstanceTwo);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method testCopyRolesByIdentityWithoutTestTransaction.
@Test
public void testCopyRolesByIdentityWithoutTestTransaction() {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmRoleDto role = this.getHelper().createRole();
for (int i = 0; i < 21; i++) {
this.getHelper().createIdentityRole(identity, role);
}
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(21, assignedRoles.size());
List<UUID> identityRolesId = assignedRoles.stream().map(IdmIdentityRoleDto::getId).collect(Collectors.toList());
IdmIdentityDto identityCopy = this.getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contractCopy = getHelper().getPrimeContract(identityCopy);
IdmRoleRequestDto createdRequest = roleRequestService.createRequest(contractCopy);
IdmRoleRequestByIdentityDto requestByIdentityDto = new IdmRoleRequestByIdentityDto();
requestByIdentityDto.setIdentityContract(contractCopy.getId());
requestByIdentityDto.setIdentityRoles(identityRolesId);
requestByIdentityDto.setRoleRequest(createdRequest.getId());
IdmRoleRequestDto copyRolesByIdentity = roleRequestService.copyRolesByIdentity(requestByIdentityDto);
Assert.assertNotNull(copyRolesByIdentity);
List<IdmConceptRoleRequestDto> concepts = conceptRoleRequestService.findAllByRoleRequest(copyRolesByIdentity.getId());
assertEquals(21, concepts.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method testExecuteConcurentRoleRequests.
@Test
public void testExecuteConcurentRoleRequests() {
// prepare two requests with assigned roles
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
IdmRoleDto role = getHelper().createRole();
//
for (int i = 0; i < 10; i++) {
getHelper().createIdentityRole(contract, role);
}
//
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findValidRoles(identity.getId(), null).getContent();
Assert.assertEquals(10, assignedRoles.size());
//
IdmRoleRequestDto requestOne = createDeleteRoleRequest(contract, assignedRoles);
IdmRoleRequestDto requestTwo = createDeleteRoleRequest(contract, assignedRoles);
//
// execute request in two threads
FutureTask<?> taskOne = new FutureTask<Boolean>(() -> {
roleRequestService.startRequest(requestOne.getId(), false);
return true;
});
FutureTask<?> taskTwo = new FutureTask<Boolean>(() -> {
roleRequestService.startRequest(requestTwo.getId(), false);
return true;
});
executor.execute(taskOne);
executor.execute(taskTwo);
//
while (true) {
if (taskOne.isDone() && taskTwo.isDone()) {
break;
}
}
//
IdmRoleRequestDto executedRequestOne = roleRequestService.get(requestOne, new IdmRoleRequestFilter(true));
IdmRoleRequestDto executedRequestTwo = roleRequestService.get(requestTwo, new IdmRoleRequestFilter(true));
// One of requests ends with exception, but can be read => referential integrity is ok
Assert.assertTrue(executedRequestOne.getState().isTerminatedState());
Assert.assertTrue(executedRequestTwo.getState().isTerminatedState());
}
Aggregations