use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testAssignAutomaticRoleAfterNodeIsMovedWithUpRecursion.
@Test
public void testAssignAutomaticRoleAfterNodeIsMovedWithUpRecursion() {
IdmTreeNodeDto parentNode = getHelper().createTreeNode();
IdmTreeNodeDto node = getHelper().createTreeNode();
// define automatic role for parent
IdmRoleDto role = getHelper().createRole();
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, node, RecursionType.UP, true);
// create identity with contract on node
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
getHelper().createContract(identity, parentNode);
// no role should be assigned now
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
node.setParent(parentNode.getId());
node = service.save(node);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
//
IdmTreeNodeDto otherNode = getHelper().createTreeNode(null, null, node);
IdmRoleDto roleOther = getHelper().createRole();
IdmRoleTreeNodeDto otherAutomaticRole = getHelper().createRoleTreeNode(roleOther, otherNode, RecursionType.UP, false);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(2, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRole.getId().equals(ir.getAutomaticRole())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> otherAutomaticRole.getId().equals(ir.getAutomaticRole())));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testDontAssignAutomaticRoleOnPositionAfterNodeIsMovedToInvalidContract.
@Test
public void testDontAssignAutomaticRoleOnPositionAfterNodeIsMovedToInvalidContract() {
IdmTreeNodeDto parentNode = getHelper().createTreeNode();
IdmTreeNodeDto node = getHelper().createTreeNode();
// define automatic role for parent
IdmRoleDto role = getHelper().createRole();
getHelper().createRoleTreeNode(role, node, RecursionType.UP, true);
// create identity with contract on node
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().createContract(identity, null, null, LocalDate.now().minusDays(1));
getHelper().createContractPosition(contract, parentNode);
// no role should be assigned now
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
node.setParent(parentNode.getId());
node = service.save(node);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testRecalculateAllAutomaticRoles.
@Test
public void testRecalculateAllAutomaticRoles() {
IdmTreeNodeDto parentNode = getHelper().createTreeNode();
IdmTreeNodeDto node = getHelper().createTreeNode();
// define automatic role for parent
IdmRoleDto role = getHelper().createRole();
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, node, RecursionType.UP, true);
// create identity with contract on node
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().createContract(identity, parentNode);
entityStateManager.createState(contract, OperationState.BLOCKED, CoreResultCode.AUTOMATIC_ROLE_SKIPPED, null);
Assert.assertEquals(1, entityStateManager.findStates(contract, null).getTotalElements());
// no role should be assigned now
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
node.setParent(parentNode.getId());
EntityEvent<IdmTreeNodeDto> event = new TreeNodeEvent(TreeNodeEventType.UPDATE, node);
event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
node = service.publish(event).getContent();
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
// recount skipped automatic roles
ProcessAllAutomaticRoleByTreeTaskExecutor taskExecutor = AutowireHelper.createBean(ProcessAllAutomaticRoleByTreeTaskExecutor.class);
taskExecutor.init(null);
longRunningTaskManager.execute(taskExecutor);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
Assert.assertEquals(0, entityStateManager.findStates(contract, null).getTotalElements());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultLookupServiceIntegrationTest method testLookupEmbeddedNotEmbeddable.
@Test(expected = IllegalArgumentException.class)
public void testLookupEmbeddedNotEmbeddable() {
IdmIdentityRoleDto identityRole = new IdmIdentityRoleDto();
//
identityRole.setValidFrom(LocalDate.now());
//
lookupService.lookupEmbeddedDto(identityRole, IdmIdentityRole_.validTill);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleFormAttributeServiceIntegrationTest method testDeleteRoleAttributeValueViaRoleRequest.
@Test
public void testDeleteRoleAttributeValueViaRoleRequest() {
// Create role with attribute (include the sub-definition)
IdmRoleDto role = createRoleWithAttributes();
IdmRoleFormAttributeFilter filter = new IdmRoleFormAttributeFilter();
filter.setRole(role.getId());
List<IdmRoleFormAttributeDto> list = roleFormAttributeService.find(filter, null).getContent();
Assert.assertEquals(2, list.size());
IdmFormDefinitionDto formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
// Delete IP attribute from the sub-definition
list.stream().filter(roleFormAttributeDto -> {
IdmFormAttributeDto formAttributeDto = DtoUtils.getEmbedded(roleFormAttributeDto, IdmRoleFormAttribute_.formAttribute.getName(), IdmFormAttributeDto.class);
return formAttributeDto.getCode().equals(IP);
}).forEach(roleFormAttributeDto -> roleFormAttributeService.delete(roleFormAttributeDto));
formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
Assert.assertEquals(1, formAttributeSubdefinition.getFormAttributes().size());
Assert.assertEquals(NUMBER_OF_FINGERS, formAttributeSubdefinition.getFormAttributes().get(0).getCode());
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityContractId(contract.getId());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, null).getContent();
assertEquals(0, identityRoles.size());
// Create request
IdmRoleRequestDto request = getHelper().createRoleRequest(identity);
// Create change role-concept
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setRoleRequest(request.getId());
conceptRoleRequest.setIdentityContract(contract.getId());
// Change the valid from
conceptRoleRequest.setValidFrom(LocalDate.now());
conceptRoleRequest.setRole(role.getId());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
conceptRoleRequest = conceptRoleRequestService.save(conceptRoleRequest);
conceptRoleRequest.getEavs().clear();
// Create role attribute value in concept
IdmFormInstanceDto formInstanceDto = conceptRoleRequestService.getRoleAttributeValues(conceptRoleRequest, false);
Assert.assertNotNull(formInstanceDto);
Assert.assertNotNull(formInstanceDto.getFormDefinition());
Assert.assertEquals(0, formInstanceDto.getValues().size());
IdmFormAttributeDto attribute = formInstanceDto.getMappedAttributeByCode(NUMBER_OF_FINGERS);
IdmFormValueDto formValueDto = new IdmFormValueDto(attribute);
formValueDto.setValue(BigDecimal.TEN);
List<IdmFormValueDto> values = Lists.newArrayList(formValueDto);
formInstanceDto.setValues(values);
List<IdmFormInstanceDto> forms = Lists.newArrayList(formInstanceDto);
conceptRoleRequest.setEavs(forms);
conceptRoleRequest = conceptRoleRequestService.save(conceptRoleRequest);
conceptRoleRequest.getEavs().clear();
formInstanceDto = conceptRoleRequestService.getRoleAttributeValues(conceptRoleRequest, false);
Assert.assertEquals(1, formInstanceDto.getValues().size());
Serializable value = formInstanceDto.toSinglePersistentValue(NUMBER_OF_FINGERS);
Assert.assertEquals(BigDecimal.TEN.longValue(), ((BigDecimal) value).longValue());
request = getHelper().executeRequest(request, false, true);
// Check request
assertEquals(RoleRequestState.EXECUTED, request.getState());
identityRoles = identityRoleService.find(identityRoleFilter, null).getContent();
assertEquals(1, identityRoles.size());
IdmIdentityRoleDto identityRole = identityRoles.get(0);
// Check identity-role
identityRole = identityRoleService.get(identityRole.getId());
assertEquals(conceptRoleRequest.getValidFrom(), identityRole.getValidFrom());
// Check role attribute value in identity-role
identityRole.getEavs().clear();
IdmFormInstanceDto identityRoleFormInstanceDto = identityRoleService.getRoleAttributeValues(identityRole);
Assert.assertEquals(1, identityRoleFormInstanceDto.getValues().size());
value = identityRoleFormInstanceDto.toSinglePersistentValue(NUMBER_OF_FINGERS);
Assert.assertEquals(BigDecimal.TEN.longValue(), ((BigDecimal) value).longValue());
// Create request for delete attribute value
IdmRoleRequestDto requestUpdate = getHelper().createRoleRequest(identity);
// Create change role-concept
IdmConceptRoleRequestDto updateConceptRoleRequest = new IdmConceptRoleRequestDto();
updateConceptRoleRequest.setRoleRequest(requestUpdate.getId());
updateConceptRoleRequest.setIdentityContract(contract.getId());
// Change the valid from
updateConceptRoleRequest.setValidFrom(LocalDate.now());
updateConceptRoleRequest.setRole(role.getId());
updateConceptRoleRequest.setIdentityRole(identityRole.getId());
updateConceptRoleRequest.setOperation(ConceptRoleRequestOperation.UPDATE);
updateConceptRoleRequest = conceptRoleRequestService.save(updateConceptRoleRequest);
updateConceptRoleRequest.getEavs().clear();
/**
* Erase role attribute value in concept
*/
formInstanceDto = conceptRoleRequestService.getRoleAttributeValues(updateConceptRoleRequest, false);
Assert.assertNotNull(formInstanceDto);
Assert.assertNotNull(formInstanceDto.getFormDefinition());
Assert.assertEquals(0, formInstanceDto.getValues().size());
attribute = formInstanceDto.getMappedAttributeByCode(NUMBER_OF_FINGERS);
formValueDto = new IdmFormValueDto(attribute);
formValueDto.setValue(null);
values = Lists.newArrayList(formValueDto);
formInstanceDto.setValues(values);
forms = Lists.newArrayList(formInstanceDto);
updateConceptRoleRequest.setEavs(forms);
updateConceptRoleRequest = conceptRoleRequestService.save(updateConceptRoleRequest);
updateConceptRoleRequest.getEavs().clear();
formInstanceDto = conceptRoleRequestService.getRoleAttributeValues(updateConceptRoleRequest, false);
// No form-value can exists
Assert.assertEquals(0, formInstanceDto.getValues().size());
requestUpdate = getHelper().executeRequest(requestUpdate, false, true);
// Check request
assertEquals(RoleRequestState.EXECUTED, requestUpdate.getState());
identityRoles = identityRoleService.find(identityRoleFilter, null).getContent();
assertEquals(1, identityRoles.size());
identityRole = identityRoles.get(0);
// Check identity-role
identityRole = identityRoleService.get(identityRole.getId());
assertEquals(updateConceptRoleRequest.getValidFrom(), identityRole.getValidFrom());
// Check role attribute value in identity-role
identityRole.getEavs().clear();
identityRoleFormInstanceDto = identityRoleService.getRoleAttributeValues(identityRole);
Assert.assertEquals(0, identityRoleFormInstanceDto.getValues().size());
}
Aggregations