use of eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class IdmRequestIdentityRoleServiceIntegrationTest method testUniqueValidation.
@Test
public void testUniqueValidation() {
// Create role with attribute (include the sub-definition)
IdmRoleDto role = createRoleWithAttributes(true);
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 identity-role
IdmRequestIdentityRoleDto createdRequestIdentityRole = new IdmRequestIdentityRoleDto();
createdRequestIdentityRole.setIdentityContract(contract.getId());
// Change the valid from
createdRequestIdentityRole.setValidFrom(LocalDate.now());
createdRequestIdentityRole.setRole(role.getId());
// Create role attribute value in concept
IdmFormDefinitionDto formDefinitionDto = roleService.getFormAttributeSubdefinition(role);
IdmFormInstanceDto formInstanceDto = new IdmFormInstanceDto();
IdmFormAttributeDto attribute = formDefinitionDto.getMappedAttributeByCode(NUMBER_OF_FINGERS);
IdmFormValueDto formValueDto = new IdmFormValueDto(attribute);
formValueDto.setValue(5);
List<IdmFormValueDto> values = Lists.newArrayList(formValueDto);
formInstanceDto.setValues(values);
List<IdmFormInstanceDto> forms = Lists.newArrayList(formInstanceDto);
createdRequestIdentityRole.setEavs(forms);
createdRequestIdentityRole = requestIdentityRoleService.save(createdRequestIdentityRole);
IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
Assert.assertNotNull(request);
// Execute a role-request.
getHelper().executeRequest(request, false, true);
IdmRequestIdentityRoleFilter filterRequestIdentityRole = new IdmRequestIdentityRoleFilter();
filterRequestIdentityRole.setIdentityId(identity.getId());
filterRequestIdentityRole.setRoleRequestId(request.getId());
// Include EAV attributes
filterRequestIdentityRole.setIncludeEav(true);
// Check EAV value in the request-identity-role
List<IdmRequestIdentityRoleDto> requestIdentityRoles = requestIdentityRoleService.find(filterRequestIdentityRole, null).getContent();
Assert.assertEquals(1, requestIdentityRoles.size());
Assert.assertEquals(role.getId(), requestIdentityRoles.get(0).getRole());
Assert.assertEquals(1, requestIdentityRoles.get(0).getEavs().size());
IdmFormInstanceDto formInstance = requestIdentityRoles.get(0).getEavs().get(0);
Assert.assertEquals(1, formInstance.getValues().size());
IdmFormValueDto formValue = formInstance.getValues().get(0);
Serializable value = formValue.getValue();
Assert.assertEquals(((BigDecimal) formValueDto.getValue()).longValue(), ((BigDecimal) value).longValue());
IdmFormAttributeDto mappedAttribute = formInstance.getMappedAttribute(formValue.getFormAttribute());
Assert.assertNotNull(mappedAttribute);
Assert.assertNull(formInstance.getValidationErrors());
identityRoles = identityRoleService.find(identityRoleFilter, null).getContent();
assertEquals(1, identityRoles.size());
// Create request for change an identity-role
IdmRequestIdentityRoleDto changeRequestIdentityRole = new IdmRequestIdentityRoleDto();
changeRequestIdentityRole.setId(identityRoles.get(0).getId());
changeRequestIdentityRole.setIdentityContract(contract.getId());
// Change the valid from
changeRequestIdentityRole.setValidFrom(LocalDate.now());
changeRequestIdentityRole.setIdentityRole(identityRoles.get(0).getId());
changeRequestIdentityRole.setEavs(forms);
changeRequestIdentityRole = requestIdentityRoleService.save(changeRequestIdentityRole);
IdmRoleRequestDto requestChange = roleRequestService.get(changeRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
Assert.assertNotNull(requestChange);
// Execute a role-request.
requestChange = getHelper().executeRequest(requestChange, false, true);
assertEquals(RoleRequestState.EXECUTED, requestChange.getState());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class IdmRequestIdentityRoleServiceIntegrationTest method testUpdateAssignRole.
@Test
@Transactional
public void testUpdateAssignRole() {
IdmIdentityDto identity = this.getHelper().createIdentity(new GuardedString());
IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
IdmRoleDto role = this.getHelper().createRole();
this.getHelper().createIdentityRole(contract, role, LocalDate.now().minusDays(1), null);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertEquals(1, identityRoles.size());
// Create request for updated identity-role
IdmRequestIdentityRoleDto dto = new IdmRequestIdentityRoleDto();
dto.setIdentityContract(contract.getId());
dto.setIdentityRole(identityRoles.get(0).getId());
dto.setId(dto.getIdentityRole());
dto.setValidFrom(LocalDate.now().minusDays(10));
dto.setValidTill(LocalDate.now().plusDays(10));
IdmRequestIdentityRoleDto createdRequestIdentityRole = requestIdentityRoleService.save(dto);
Assert.assertNotNull(createdRequestIdentityRole);
// Request must been created
Assert.assertNotNull(createdRequestIdentityRole.getRoleRequest());
Assert.assertEquals(role.getId(), createdRequestIdentityRole.getRole());
Assert.assertEquals(contract.getId(), createdRequestIdentityRole.getIdentityContract());
IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
Assert.assertNotNull(request);
// Concepts are not empty now
Assert.assertEquals(1, request.getConceptRoles().size());
// Applicant must be ours identity
Assert.assertEquals(contract.getIdentity(), request.getApplicant());
IdmConceptRoleRequestDto concept = request.getConceptRoles().get(0);
Assert.assertEquals(contract.getId(), concept.getIdentityContract());
Assert.assertEquals(role.getId(), concept.getRole());
Assert.assertEquals(ConceptRoleRequestOperation.UPDATE, concept.getOperation());
Assert.assertEquals(createdRequestIdentityRole.getValidFrom(), concept.getValidFrom());
Assert.assertEquals(createdRequestIdentityRole.getValidTill(), concept.getValidTill());
this.getHelper().executeRequest(request, false, true);
identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertEquals(1, identityRoles.size());
Assert.assertEquals(createdRequestIdentityRole.getValidFrom(), identityRoles.get(0).getValidFrom());
Assert.assertEquals(createdRequestIdentityRole.getValidTill(), identityRoles.get(0).getValidTill());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class IdmRequestIdentityRoleServiceIntegrationTest method testAssignRole.
@Test
@Transactional
public void testAssignRole() {
IdmIdentityDto identity = this.getHelper().createIdentity(new GuardedString());
IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
IdmRoleDto role = this.getHelper().createRole();
// Create request for new identity-role
IdmRequestIdentityRoleDto dto = new IdmRequestIdentityRoleDto();
dto.setIdentityContract(contract.getId());
dto.setRole(role.getId());
dto.setValidFrom(LocalDate.now().minusDays(1));
dto.setValidTill(LocalDate.now().plusDays(10));
IdmRequestIdentityRoleDto createdRequestIdentityRole = requestIdentityRoleService.save(dto);
Assert.assertNotNull(createdRequestIdentityRole);
// Request must been created
Assert.assertNotNull(createdRequestIdentityRole.getRoleRequest());
Assert.assertEquals(role.getId(), createdRequestIdentityRole.getRole());
Assert.assertEquals(contract.getId(), createdRequestIdentityRole.getIdentityContract());
IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest());
Assert.assertNotNull(request);
// Concepts are empty, because the request does not return them be default
Assert.assertEquals(0, request.getConceptRoles().size());
request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
Assert.assertNotNull(request);
// Concepts are not empty now
Assert.assertEquals(1, request.getConceptRoles().size());
// Applicant must be ours identity
Assert.assertEquals(contract.getIdentity(), request.getApplicant());
IdmConceptRoleRequestDto concept = request.getConceptRoles().get(0);
Assert.assertEquals(contract.getId(), concept.getIdentityContract());
Assert.assertEquals(role.getId(), concept.getRole());
Assert.assertEquals(createdRequestIdentityRole.getValidFrom(), concept.getValidFrom());
Assert.assertEquals(createdRequestIdentityRole.getValidTill(), concept.getValidTill());
this.getHelper().executeRequest(request, false, true);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertEquals(1, identityRoles.size());
Assert.assertEquals(role.getId(), identityRoles.get(0).getRole());
Assert.assertEquals(createdRequestIdentityRole.getValidFrom(), identityRoles.get(0).getValidFrom());
Assert.assertEquals(createdRequestIdentityRole.getValidTill(), identityRoles.get(0).getValidTill());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class IdmRequestIdentityRoleServiceIntegrationTest method testFindAddingConceptWithEAVs.
@Test
public void testFindAddingConceptWithEAVs() {
// Create role with attribute (include the sub-definition)
IdmRoleDto role = createRoleWithAttributes(false);
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 identity-role
IdmRequestIdentityRoleDto createdRequestIdentityRole = new IdmRequestIdentityRoleDto();
createdRequestIdentityRole.setIdentityContract(contract.getId());
// Change the valid from
createdRequestIdentityRole.setValidFrom(LocalDate.now());
createdRequestIdentityRole.setRole(role.getId());
// Create role attribute value in concept
IdmFormDefinitionDto formDefinitionDto = roleService.getFormAttributeSubdefinition(role);
IdmFormInstanceDto formInstanceDto = new IdmFormInstanceDto();
IdmFormAttributeDto attribute = formDefinitionDto.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);
createdRequestIdentityRole.setEavs(forms);
createdRequestIdentityRole = requestIdentityRoleService.save(createdRequestIdentityRole);
IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
Assert.assertNotNull(request);
IdmRequestIdentityRoleFilter filterRequestIdentityRole = new IdmRequestIdentityRoleFilter();
filterRequestIdentityRole.setIdentityId(identity.getId());
filterRequestIdentityRole.setRoleRequestId(request.getId());
// Include EAV attributes
filterRequestIdentityRole.setIncludeEav(true);
// Check EAV value in the request-identity-role
List<IdmRequestIdentityRoleDto> requestIdentityRoles = requestIdentityRoleService.find(filterRequestIdentityRole, null).getContent();
Assert.assertEquals(1, requestIdentityRoles.size());
Assert.assertEquals(role.getId(), requestIdentityRoles.get(0).getRole());
Assert.assertEquals(1, requestIdentityRoles.get(0).getEavs().size());
Assert.assertEquals(1, requestIdentityRoles.get(0).getEavs().get(0).getValues().size());
Serializable value = requestIdentityRoles.get(0).getEavs().get(0).getValues().get(0).getValue();
Assert.assertEquals(BigDecimal.TEN.longValue(), ((BigDecimal) value).longValue());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class IdmRequestIdentityRoleServiceIntegrationTest method testAssignRemove.
@Test
@Transactional
public void testAssignRemove() {
IdmIdentityDto identity = this.getHelper().createIdentity(new GuardedString());
IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
IdmRoleDto role = this.getHelper().createRole();
this.getHelper().createIdentityRole(contract, role);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertEquals(1, identityRoles.size());
// Create request for remove identity-role
IdmRequestIdentityRoleDto dto = new IdmRequestIdentityRoleDto();
dto.setIdentityContract(contract.getId());
dto.setIdentityRole(identityRoles.get(0).getId());
dto.setId(dto.getIdentityRole());
IdmRequestIdentityRoleDto createdRequestIdentityRole = requestIdentityRoleService.deleteRequestIdentityRole(dto);
Assert.assertNotNull(createdRequestIdentityRole);
// Request must been created
Assert.assertNotNull(createdRequestIdentityRole.getRoleRequest());
Assert.assertEquals(role.getId(), createdRequestIdentityRole.getRole());
Assert.assertEquals(contract.getId(), createdRequestIdentityRole.getIdentityContract());
IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
Assert.assertNotNull(request);
// Concepts are not empty now
Assert.assertEquals(1, request.getConceptRoles().size());
// Applicant must be ours identity
Assert.assertEquals(contract.getIdentity(), request.getApplicant());
IdmConceptRoleRequestDto concept = request.getConceptRoles().get(0);
Assert.assertEquals(contract.getId(), concept.getIdentityContract());
Assert.assertEquals(role.getId(), concept.getRole());
Assert.assertEquals(ConceptRoleRequestOperation.REMOVE, concept.getOperation());
this.getHelper().executeRequest(request, false, true);
identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertEquals(0, identityRoles.size());
}
Aggregations