use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleServiceIntegrationTest method testExecuteRoleRequestValue.
@Test
public void testExecuteRoleRequestValue() throws Exception {
IdmIdentityDto identity = getHelper().createIdentity();
IdmRoleDto role = createRoleWithAttributes();
IdmIdentityContractDto identityContact = getHelper().createContract(identity);
IdmFormDefinitionDto definition = formService.getDefinition(role.getIdentityRoleAttributeDefinition());
IdmFormAttributeDto ipAttributeDto = //
definition.getFormAttributes().stream().filter(//
attribute -> IP.equals(attribute.getCode())).findFirst().get();
// Add value
IdmFormValueDto formValue = new IdmFormValueDto(ipAttributeDto);
formValue.setStringValue(getHelper().createName());
formValue.setPersistentType(PersistentType.TEXT);
formValue.setFormAttribute(ipAttributeDto.getId());
IdmFormInstanceDto formInstance = new IdmFormInstanceDto();
formInstance.setFormDefinition(definition);
formInstance.getValues().add(formValue);
// Create request
IdmRoleRequestDto request = new IdmRoleRequestDto();
request.setApplicant(identity.getId());
request.setRequestedByType(RoleRequestedByType.MANUALLY);
request.setExecuteImmediately(true);
request = roleRequestService.save(request);
// Create concept
IdmConceptRoleRequestDto conceptRole = new IdmConceptRoleRequestDto();
conceptRole.setIdentityContract(identityContact.getId());
conceptRole.setRole(role.getId());
conceptRole.setOperation(ConceptRoleRequestOperation.ADD);
conceptRole.setRoleRequest(request.getId());
conceptRole.getEavs().add(formInstance);
conceptRole = conceptRoleService.save(conceptRole);
IdmRoleRequestDto roleRequestDto = getHelper().startRequestInternal(request, false, true);
assertEquals(RoleRequestState.EXECUTED, roleRequestDto.getState());
conceptRole = conceptRoleService.get(conceptRole.getId());
assertEquals(RoleRequestState.EXECUTED, conceptRole.getState());
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityContractId(identityContact.getId());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, null).getContent();
assertEquals(1, identityRoles.size());
IdmIdentityRoleDto identityRoleDto = identityRoles.get(0);
IdmFormInstanceDto formInstanceDto = identityRoleService.getRoleAttributeValues(identityRoleDto);
assertNotNull(formInstanceDto);
List<IdmFormValueDto> values = formInstanceDto.getValues();
assertEquals(1, values.size());
assertEquals(formValue.getValue(), values.get(0).getValue());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter 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());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdentityAutomaticRoleProcessor method process.
@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
//
IdmIdentityDto identity = event.getContent();
UUID identityId = identity.getId();
//
// both by default
AutomaticRoleAttributeRuleType type = null;
if (identity.getEavs().isEmpty()) {
// identity is saved together with eavs.
type = AutomaticRoleAttributeRuleType.IDENTITY;
}
if (CoreEventType.EAV_SAVE.name().equals(event.getParentType())) {
type = AutomaticRoleAttributeRuleType.IDENTITY_EAV;
}
//
List<IdmConceptRoleRequestDto> concepts = new ArrayList<IdmConceptRoleRequestDto>();
//
for (IdmIdentityContractDto contract : identityContractService.findAllByIdentity(identityId)) {
UUID contractId = contract.getId();
Set<AbstractIdmAutomaticRoleDto> allNewPassedAutomaticRoleForContract = automaticRoleAttributeService.getRulesForContract(true, type, contractId);
Set<AbstractIdmAutomaticRoleDto> allNotPassedAutomaticRoleForContract = automaticRoleAttributeService.getRulesForContract(false, type, contractId);
// Iterate over newly passed
for (AbstractIdmAutomaticRoleDto autoRole : allNewPassedAutomaticRoleForContract) {
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setIdentityContract(contract.getId());
concept.setValidFrom(contract.getValidFrom());
concept.setValidTill(contract.getValidTill());
concept.setRole(autoRole.getRole());
concept.setAutomaticRole(autoRole.getId());
concept.setOperation(ConceptRoleRequestOperation.ADD);
concepts.add(concept);
}
// Iterate over newly not passed
for (AbstractIdmAutomaticRoleDto autoRole : allNotPassedAutomaticRoleForContract) {
//
// Find all identity roles
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setAutomaticRoleId(autoRole.getId());
filter.setIdentityContractId(contractId);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null).getContent();
//
for (IdmIdentityRoleDto identityRole : identityRoles) {
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setIdentityContract(contractId);
concept.setRole(autoRole.getRole());
concept.setAutomaticRole(autoRole.getId());
concept.setIdentityRole(identityRole.getId());
concept.setOperation(ConceptRoleRequestOperation.REMOVE);
concepts.add(concept);
}
}
//
}
// Execute concepts
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setConceptRoles(concepts);
roleRequest.setApplicant(identityId);
roleRequest = roleRequestService.startConcepts(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest), event);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdentityContractExpirationTaskExecutor method processItem.
@Override
public Optional<OperationResult> processItem(IdmIdentityContractDto contract) {
LOG.info("Remove roles by expired identity contract [{}]. Contract ended for expiration less than [{}]", contract.getId(), expiration);
//
try {
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityContractId(contract.getId());
filter.setDirectRole(Boolean.TRUE);
// remove all referenced roles (automatic roles are included)
List<IdmIdentityRoleDto> expiredRoles = identityRoleService.find(filter, null).getContent();
if (expiredRoles.isEmpty()) {
// nothing to do
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
}
//
UUID identityId = contract.getIdentity();
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setState(RoleRequestState.CONCEPT);
// without approval
roleRequest.setExecuteImmediately(true);
roleRequest.setApplicant(identityId);
roleRequest.setRequestedByType(RoleRequestedByType.AUTOMATICALLY);
roleRequest = roleRequestService.save(roleRequest);
//
for (IdmIdentityRoleDto identityRole : expiredRoles) {
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityRole(identityRole.getId());
conceptRoleRequest.setRole(identityRole.getRole());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.REMOVE);
conceptRoleRequest.setIdentityContract(contract.getId());
conceptRoleRequest.setRoleRequest(roleRequest.getId());
conceptRoleRequestService.save(conceptRoleRequest);
}
//
// start event with skip check authorities
RoleRequestEvent requestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
requestEvent.getProperties().put(IdmIdentityRoleService.SKIP_CHECK_AUTHORITIES, Boolean.TRUE);
// prevent to start asynchronous event before previous update event is completed.
requestEvent.setSuperOwnerId(identityId);
//
roleRequestService.startRequestInternal(requestEvent);
//
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
} catch (Exception ex) {
LOG.error("Removing roles of expired contract [{}] failed", contract.getId(), ex);
return Optional.of(new OperationResult.Builder(OperationState.EXCEPTION).setCause(ex).build());
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class AddNewRoleCompositionTaskExecutor method processItem.
@Override
public Optional<OperationResult> processItem(IdmRoleDto superiorRole) {
try {
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setRoleId(superiorRole.getId());
//
identityRoleService.find(filter, null).forEach(identityRole -> {
IdmIdentityContractDto contract = lookupService.lookupEmbeddedDto(identityRole, IdmIdentityRole_.identityContract);
// find direct sub roles - other sub roles will be processed by role request automatically
IdmRoleCompositionFilter compositionFilter = new IdmRoleCompositionFilter();
compositionFilter.setSuperiorId(identityRole.getRole());
compositionFilter.setId(roleCompositionId);
//
List<IdmConceptRoleRequestDto> concepts = roleCompositionService.find(compositionFilter, null).stream().map(subRole -> {
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
// from concept
conceptRoleRequest.setValidFrom(identityRole.getValidFrom());
conceptRoleRequest.setValidTill(identityRole.getValidTill());
conceptRoleRequest.setIdentityContract(identityRole.getIdentityContract());
conceptRoleRequest.setContractPosition(identityRole.getContractPosition());
// from assigned (~changed) sub role
conceptRoleRequest.setRole(subRole.getSub());
conceptRoleRequest.setDirectRole(identityRole.getId());
conceptRoleRequest.setRoleComposition(subRole.getId());
//
return conceptRoleRequest;
}).collect(Collectors.toList());
//
if (!concepts.isEmpty()) {
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setConceptRoles(concepts);
roleRequest.setApplicant(contract.getIdentity());
roleRequest = roleRequestService.startConcepts(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest), null);
}
});
//
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
} catch (Exception ex) {
return Optional.of(new OperationResult.Builder(OperationState.EXCEPTION).setModel(new DefaultResultModel(CoreResultCode.ROLE_COMPOSITION_ASSIGN_ROLE_FAILED, ImmutableMap.of("role", superiorRole.getCode()))).setCause(ex).build());
}
}
Aggregations