use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter 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.filter.IdmRoleFormAttributeFilter 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.filter.IdmRoleFormAttributeFilter in project CzechIdMng by bcvsolutions.
the class DuplicateRoleFormAttributeProcessor method process.
@Override
public EventResult<IdmRoleDto> process(EntityEvent<IdmRoleDto> event) {
// newly set role
IdmRoleDto duplicate = event.getContent();
// cloned role
IdmRoleDto originalSource = event.getOriginalSource();
// just for sure
Assert.notNull(originalSource.getId(), "Original source identifier is required.");
//
// search current, create, update, remove
IdmRoleFormAttributeFilter filter = new IdmRoleFormAttributeFilter();
Map<UUID, IdmRoleFormAttributeDto> currentAttributes = null;
if (duplicate.getId() != null) {
filter.setRole(duplicate.getId());
currentAttributes = roleFormAttributeService.find(filter, null).getContent().stream().collect(Collectors.toMap(IdmRoleFormAttributeDto::getFormAttribute, Function.identity()));
} else {
// we need prepare id - role will be persisted after
duplicate.setId(UUID.randomUUID());
currentAttributes = new HashMap<>();
}
//
filter.setRole(originalSource.getId());
for (IdmRoleFormAttributeDto originalRoleFormAttribute : roleFormAttributeService.find(filter, null).getContent()) {
IdmRoleFormAttributeDto duplicateRoleFormAttribute;
if (currentAttributes.containsKey(originalRoleFormAttribute.getFormAttribute())) {
duplicateRoleFormAttribute = currentAttributes.get(originalRoleFormAttribute.getFormAttribute());
// used => remove. Unused attributes will be removed at end.
currentAttributes.remove(originalRoleFormAttribute.getFormAttribute());
} else {
duplicateRoleFormAttribute = new IdmRoleFormAttributeDto();
duplicateRoleFormAttribute.setRole(duplicate.getId());
}
duplicateProperties(originalRoleFormAttribute, duplicateRoleFormAttribute);
//
roleFormAttributeService.save(duplicateRoleFormAttribute);
}
// remove removed attributed at end
currentAttributes.values().forEach(attribute -> {
roleFormAttributeService.delete(attribute);
});
//
event.setContent(duplicate);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleFormAttributeServiceIntegrationTest method testChangeOfSuperdefinitionNotAllowed.
@Test(expected = ResultCodeException.class)
public void testChangeOfSuperdefinitionNotAllowed() {
// 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 definitionTwo = formService.createDefinition(IdmIdentityRole.class, getHelper().createName(), ImmutableList.of());
role.setIdentityRoleAttributeDefinition(definitionTwo.getId());
// Save role - change of definition is not allowed (if exists some
// role-form-attribute) -> throw exception
roleService.save(role);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter 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