Search in sources :

Example 96 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class AbstractMonitoringIgnoredBulkAction method processDto.

@Override
protected OperationResult processDto(DTO dto) {
    IdmEntityStateDto state = new IdmEntityStateDto();
    state.setResult(new OperationResultDto.Builder(OperationState.BLOCKED).setModel(new DefaultResultModel(CoreResultCode.MONITORING_IGNORED)).build());
    entityStateManager.saveState(dto, state);
    // 
    return new OperationResult.Builder(OperationState.EXECUTED).build();
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult)

Example 97 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class ProcessAutomaticRoleByTreeTaskExecutor method processContract.

/**
 * Assign automatic role for given contract. Already assigned automatic role is checked.
 *
 * @param contract
 * @param automaticRole
 * @return created assigned roles
 */
private Set<UUID> processContract(IdmIdentityContractDto contract, IdmRoleTreeNodeDto automaticRole) {
    UUID contractId = contract.getId();
    Set<UUID> processedRoleRequests = new HashSet<>();
    UUID automaticRoleId = automaticRole.getId();
    IdmIdentityDto identity = getLookupService().lookupEmbeddedDto(contract, IdmIdentityContract_.identity);
    IdmRoleDto role = getLookupService().lookupEmbeddedDto(automaticRole, IdmRoleTreeNode_.role);
    // 
    try {
        List<IdmIdentityRoleDto> allByContract = identityRoleService.findAllByContract(contractId);
        // skip already assigned automatic roles
        for (IdmIdentityRoleDto roleByContract : allByContract) {
            if (ObjectUtils.equals(roleByContract.getAutomaticRole(), automaticRoleId)) {
                processedRoleRequests.add(roleByContract.getId());
                ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ALREADY_ASSIGNED, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRoleId, "identity", identity.getUsername()));
                saveItemResult(roleByContract, OperationState.NOT_EXECUTED, resultModel, null);
                return processedRoleRequests;
            }
        }
        // 
        // assign automatic role by tree node by role request
        IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
        conceptRoleRequest.setIdentityContract(contractId);
        conceptRoleRequest.setValidFrom(contract.getValidFrom());
        conceptRoleRequest.setValidTill(contract.getValidTill());
        conceptRoleRequest.setRole(automaticRole.getRole());
        conceptRoleRequest.setAutomaticRole(automaticRoleId);
        conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
        // 
        IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
        roleRequest.setConceptRoles(Lists.newArrayList(conceptRoleRequest));
        roleRequest.setApplicant(contract.getIdentity());
        RoleRequestEvent roleRequestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
        roleRequest = roleRequestService.startConcepts(roleRequestEvent, null);
        // load role concepts and add created role to processed
        if (roleRequest != null) {
            processedRoleRequests.add(roleRequest.getId());
        }
        // Log successfully assigned role
        ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ASSIGN_TASK_ROLE_ASSIGNED, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRoleId, "identity", identity.getUsername()));
        saveItemResult(contract, OperationState.EXECUTED, resultModel, null);
    } catch (Exception ex) {
        LOG.error("Adding role [{}] by automatic role [{}] for identity [{}] failed", role.getCode(), automaticRoleId, identity.getUsername(), ex);
        // 
        ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ASSIGN_TASK_NOT_COMPLETE, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRoleId, "identity", identity.getUsername()));
        saveItemResult(contract, OperationState.EXCEPTION, resultModel, ex);
    }
    // 
    return processedRoleRequests;
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) HashSet(java.util.HashSet)

Example 98 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class ProcessAutomaticRoleByTreeTaskExecutor method checkProcessedIdentityRole.

/**
 * Check currently assigned role is processed by current automatic role definition.
 * If not => assigned role will be removed by synchronous role request.
 *
 * @param processedIdentityRoles assigned roles processed by automatic role
 * @param identityRole assigned role
 * @param automaticRole automatic role definition (just for logging)
 */
private void checkProcessedIdentityRole(Set<UUID> processedIdentityRoles, IdmIdentityRoleDto identityRole, UUID automaticRoleId) {
    UUID identityRoleId = identityRole.getId();
    IdmIdentityContractDto identityContract = getLookupService().lookupEmbeddedDto(identityRole, IdmIdentityRole_.identityContract);
    IdmIdentityDto identity = getLookupService().lookupEmbeddedDto(identityContract, IdmIdentityContract_.identity);
    IdmRoleDto role = getLookupService().lookupEmbeddedDto(identityRole, IdmIdentityRole_.role);
    // 
    if (!processedIdentityRoles.contains(identityRoleId)) {
        // remove role by request
        try {
            IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
            conceptRoleRequest.setIdentityRole(identityRole.getId());
            conceptRoleRequest.setRole(identityRole.getRole());
            conceptRoleRequest.setOperation(ConceptRoleRequestOperation.REMOVE);
            conceptRoleRequest.setIdentityContract(identityRole.getIdentityContract());
            // 
            IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
            roleRequest.setConceptRoles(Lists.newArrayList(conceptRoleRequest));
            roleRequest.setApplicant(identity.getId());
            roleRequest = roleRequestService.startConcepts(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest), null);
            // log successfully removed identity role
            ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ASSIGN_TASK_ROLE_REMOVED, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRoleId, "identity", identity.getUsername()));
            saveItemResult(identityRole, OperationState.EXECUTED, resultModel, null);
        } catch (Exception ex) {
            LOG.error("Remove role [{}] by automatic role [{}] failed", role.getCode(), automaticRoleId, ex);
            // 
            ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_REMOVE_TASK_NOT_COMPLETE, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRoleId, "identity", identity.getUsername()));
            saveItemResult(identityRole, OperationState.EXCEPTION, resultModel, ex);
        }
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException)

Example 99 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class ProcessAutomaticRoleByTreeTaskExecutor method processItem.

@Override
public Optional<OperationResult> processItem(IdmRoleTreeNodeDto automaticRole) {
    try {
        // process contracts
        Set<UUID> processedRoleRequestsByContract = processContracts(automaticRole);
        if (processedRoleRequestsByContract == null) {
            // task was canceled from the outside => not continue
            return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
        }
        processedRoleRequests.addAll(processedRoleRequestsByContract);
        // 
        // process contract positions
        Set<UUID> processedRoleRequestsByPositions = processPositions(automaticRole);
        if (processedRoleRequestsByPositions == null) {
            // task was canceled from the outside => not continue
            return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
        }
        processedRoleRequests.addAll(processedRoleRequestsByPositions);
        // 
        // delete automatic role is skipped flag for already processed automatic role
        entityStateManager.deleteStates(automaticRole, OperationState.BLOCKED, CoreResultCode.AUTOMATIC_ROLE_SKIPPED);
        // 
        return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
    } catch (Exception ex) {
        // catch - just for sure, but all exception will be processed in new transaction to prevent whole automatic role fails.
        IdmRoleDto role = getLookupService().lookupEmbeddedDto(automaticRole, IdmRoleTreeNode_.role);
        // 
        return Optional.of(new OperationResult.Builder(OperationState.EXCEPTION).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ASSIGN_TASK_NOT_COMPLETE, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRole.getId()))).setCause(ex).build());
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) UUID(java.util.UUID) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException)

Example 100 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class ProcessAutomaticRoleByTreeTaskExecutor method processPosition.

/**
 * Assign automatic role for given other. Already assigned automatic role is checked.
 *
 * @param contract
 * @param automaticRole
 * @return created assigned roles
 */
private Set<UUID> processPosition(IdmContractPositionDto position, IdmRoleTreeNodeDto automaticRole) {
    UUID positionId = position.getId();
    IdmIdentityContractDto contract = getLookupService().lookupEmbeddedDto(position, IdmContractPosition_.identityContract);
    UUID contractId = contract.getId();
    Set<UUID> processedRoleRequests = new HashSet<>();
    UUID automaticRoleId = automaticRole.getId();
    IdmIdentityDto identity = getLookupService().lookupEmbeddedDto(contract, IdmIdentityContract_.identity);
    IdmRoleDto role = getLookupService().lookupEmbeddedDto(automaticRole, IdmRoleTreeNode_.role);
    // 
    try {
        List<IdmIdentityRoleDto> allByPosition = identityRoleService.findAllByContractPosition(positionId);
        // skip already assigned automatic roles
        for (IdmIdentityRoleDto roleByContract : allByPosition) {
            if (ObjectUtils.equals(roleByContract.getAutomaticRole(), automaticRoleId)) {
                processedRoleRequests.add(roleByContract.getId());
                ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ALREADY_ASSIGNED, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRoleId, "identity", identity.getUsername()));
                saveItemResult(roleByContract, OperationState.NOT_EXECUTED, resultModel, null);
                return processedRoleRequests;
            }
        }
        // 
        // automatic role by tree node is added directly trough identity role
        IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
        conceptRoleRequest.setIdentityContract(contractId);
        conceptRoleRequest.setContractPosition(positionId);
        conceptRoleRequest.setValidFrom(contract.getValidFrom());
        conceptRoleRequest.setValidTill(contract.getValidTill());
        conceptRoleRequest.setRole(automaticRole.getRole());
        conceptRoleRequest.setAutomaticRole(automaticRoleId);
        conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
        // 
        IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
        roleRequest.setConceptRoles(Lists.newArrayList(conceptRoleRequest));
        roleRequest.setApplicant(contract.getIdentity());
        RoleRequestEvent roleRequestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
        roleRequest = roleRequestService.startConcepts(roleRequestEvent, null);
        // load role concepts and add created role to processed
        if (roleRequest != null) {
            processedRoleRequests.add(roleRequest.getId());
        }
        // Log successfully assigned role
        ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ASSIGN_TASK_ROLE_ASSIGNED, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRoleId, "identity", identity.getUsername()));
        saveItemResult(position, OperationState.EXECUTED, resultModel, null);
    } catch (Exception ex) {
        LOG.error("Adding role [{}] by automatic role [{}] for identity [{}] failed", role.getCode(), automaticRoleId, identity.getUsername(), ex);
        // 
        ResultModel resultModel = new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ASSIGN_TASK_NOT_COMPLETE, ImmutableMap.of("role", role.getCode(), "roleTreeNode", automaticRoleId, "identity", identity.getUsername()));
        saveItemResult(position, OperationState.EXCEPTION, resultModel, ex);
    }
    // 
    return processedRoleRequests;
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) UUID(java.util.UUID) 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) HashSet(java.util.HashSet)

Aggregations

DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)104 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)52 UUID (java.util.UUID)48 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)40 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)35 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)25 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)24 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)21 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)19 HashMap (java.util.HashMap)19 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)18 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)16 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)16 Autowired (org.springframework.beans.factory.annotation.Autowired)16 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)15 List (java.util.List)15 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)14 Set (java.util.Set)14 ImmutableMap (com.google.common.collect.ImmutableMap)13 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)13