Search in sources :

Example 16 with IdmIdentityRoleFilter

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());
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 17 with IdmIdentityRoleFilter

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());
}
Also used : IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) IdmRoleFormAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleFormAttributeDto) IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) ImmutableList(com.google.common.collect.ImmutableList) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleFormAttributeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) IdmRoleFormAttributeService(eu.bcvsolutions.idm.core.api.service.IdmRoleFormAttributeService) Serializable(java.io.Serializable) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) LocalDate(java.time.LocalDate) Assert(org.junit.Assert) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Assert.assertEquals(org.junit.Assert.assertEquals) IdmRoleFormAttribute_(eu.bcvsolutions.idm.core.model.entity.IdmRoleFormAttribute_) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Serializable(java.io.Serializable) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmRoleFormAttributeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFormAttributeFilter) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 18 with IdmIdentityRoleFilter

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);
}
Also used : ArrayList(java.util.ArrayList) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) AutomaticRoleAttributeRuleType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 19 with IdmIdentityRoleFilter

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());
    }
}
Also used : IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) UUID(java.util.UUID) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 20 with IdmIdentityRoleFilter

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());
    }
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) IdmRoleCompositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleCompositionFilter) Autowired(org.springframework.beans.factory.annotation.Autowired) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) Map(java.util.Map) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) Pageable(org.springframework.data.domain.Pageable) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmCheckConcurrentExecution(eu.bcvsolutions.idm.core.scheduler.api.domain.IdmCheckConcurrentExecution) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) ImmutableMap(com.google.common.collect.ImmutableMap) IdmRoleComposition_(eu.bcvsolutions.idm.core.model.entity.IdmRoleComposition_) AbstractSchedulableStatefulExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.AbstractSchedulableStatefulExecutor) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) PageRequest(org.springframework.data.domain.PageRequest) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmRoleCompositionService(eu.bcvsolutions.idm.core.api.service.IdmRoleCompositionService) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) List(java.util.List) Component(org.springframework.stereotype.Component) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) Optional(java.util.Optional) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) RoleRequestEventType(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent.RoleRequestEventType) PageImpl(org.springframework.data.domain.PageImpl) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Assert(org.springframework.util.Assert) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmRoleCompositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleCompositionFilter)

Aggregations

IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)116 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)85 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)84 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)81 Test (org.junit.Test)72 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)67 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)46 UUID (java.util.UUID)41 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)39 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)38 List (java.util.List)38 Autowired (org.springframework.beans.factory.annotation.Autowired)38 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)33 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)31 LocalDate (java.time.LocalDate)31 Assert (org.junit.Assert)28 IdmRoleService (eu.bcvsolutions.idm.core.api.service.IdmRoleService)27 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)25 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)25 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)25