Search in sources :

Example 16 with AbstractIdmAutomaticRoleDto

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

the class RemoveAutomaticRoleTaskExecutor method validate.

/**
 * Automatic role removal can be start, if previously LRT ended.
 */
@Override
public void validate(IdmLongRunningTaskDto task) {
    super.validate(task);
    // 
    UUID automaticRoleId = getAutomaticRoleId();
    boolean byTree = true;
    AbstractIdmAutomaticRoleDto automaticRole = roleTreeNodeService.get(automaticRoleId);
    if (automaticRole == null) {
        // get from automatic role attribute service
        byTree = false;
        automaticRole = automaticRoleAttributeService.get(automaticRoleId);
    }
    if (automaticRole == null) {
        throw new EntityNotFoundException(AbstractIdmAutomaticRoleDto.class, automaticRoleId);
    }
    // 
    IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
    filter.setTaskType(AutowireHelper.getTargetType(this));
    filter.setOperationState(OperationState.RUNNING);
    // ignore waiting tasks
    filter.setRunning(Boolean.TRUE);
    // 
    if (byTree) {
        for (UUID longRunningTaskId : getLongRunningTaskService().findIds(filter, PageRequest.of(0, 1))) {
            if (longRunningTaskId.equals(getLongRunningTaskId())) {
                continue;
            }
            throw new AcceptedException(CoreResultCode.AUTOMATIC_ROLE_TASK_RUNNING, ImmutableMap.of("taskId", longRunningTaskId.toString()));
        }
        // 
        filter.setTaskType(AutowireHelper.getTargetType(ProcessAutomaticRoleByTreeTaskExecutor.class));
        for (UUID longRunningTaskId : getLongRunningTaskService().findIds(filter, PageRequest.of(0, 1))) {
            if (longRunningTaskId.equals(getLongRunningTaskId())) {
                continue;
            }
            throw new AcceptedException(CoreResultCode.AUTOMATIC_ROLE_TASK_RUNNING, ImmutableMap.of("taskId", longRunningTaskId.toString()));
        }
    } else {
        // by attribute - prevent currently removed role only
        for (IdmLongRunningTaskDto longRunningTask : getLongRunningTaskService().find(filter, null)) {
            if (longRunningTask.getId().equals(getLongRunningTaskId())) {
                continue;
            }
            if (longRunningTask.getTaskProperties().get(AbstractAutomaticRoleTaskExecutor.PARAMETER_ROLE_TREE_NODE).equals(automaticRole.getId())) {
                throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_REMOVE_TASK_RUN_CONCURRENTLY, ImmutableMap.of("roleTreeNode", automaticRole.getId().toString(), "taskId", longRunningTask.getId().toString()));
            }
        }
        // 
        filter.setTaskType(AutowireHelper.getTargetType(ProcessAutomaticRoleByAttributeTaskExecutor.class));
        for (IdmLongRunningTaskDto longRunningTask : getLongRunningTaskService().find(filter, null)) {
            if (longRunningTask.getId().equals(getLongRunningTaskId())) {
                continue;
            }
            if (longRunningTask.getTaskProperties().get(AbstractAutomaticRoleTaskExecutor.PARAMETER_ROLE_TREE_NODE).equals(automaticRole.getId())) {
                throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_REMOVE_TASK_ADD_RUNNING, ImmutableMap.of("automaticRoleId", automaticRole.getId().toString(), "taskId", longRunningTask.getId().toString()));
            }
        }
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID)

Example 17 with AbstractIdmAutomaticRoleDto

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

the class ProcessAutomaticRoleByAttributeTaskExecutor method process.

@Override
public Boolean process() {
    UUID automaticRoleId = getAutomaticRoleId();
    IdmAutomaticRoleAttributeDto automaticRolAttributeDto = automaticRoleAttributeService.get(automaticRoleId);
    if (automaticRoleId == null || automaticRolAttributeDto == null) {
        throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_TASK_EMPTY);
    }
    // 
    Set<AbstractIdmAutomaticRoleDto> setWithAutomaticRole = Sets.newHashSet(automaticRolAttributeDto);
    // 
    List<String> failedEntitiesAdd = new ArrayList<>();
    List<String> failedEntitiesRemove = new ArrayList<>();
    // 
    // by contract
    List<UUID> newPassedContracts = automaticRoleAttributeService.getContractsForAutomaticRole(automaticRoleId, true, null).getContent();
    List<UUID> newNotPassedContracts = automaticRoleAttributeService.getContractsForAutomaticRole(automaticRoleId, false, null).getContent();
    // 
    counter = 0L;
    count = Long.valueOf(newPassedContracts.size() + newNotPassedContracts.size());
    // 
    // assign new passed roles
    boolean canContinue = true;
    // process contracts
    for (UUID contractId : newPassedContracts) {
        IdmIdentityContractDto contract = identityContractService.get(contractId);
        // 
        try {
            if (async) {
                automaticRoleAttributeService.addAutomaticRoles(contract, setWithAutomaticRole);
            } else {
                automaticRoleAttributeService.addAutomaticRolesInternal(contract, setWithAutomaticRole);
            }
            counter++;
        } catch (Exception ex) {
            LOG.error("Error while add new automatic role id [{}] to contract id [{}] and identity id [{}]", automaticRoleId, contractId, contract.getIdentity(), ex);
            failedEntitiesAdd.add(contractId.toString());
        } finally {
            canContinue = updateState();
            if (!canContinue) {
                break;
            }
        }
    }
    // 
    if (canContinue) {
        for (UUID contractId : newNotPassedContracts) {
            try {
                if (async) {
                    automaticRoleAttributeService.removeAutomaticRoles(contractId, setWithAutomaticRole);
                } else {
                    automaticRoleAttributeService.removeAutomaticRolesInternal(contractId, setWithAutomaticRole);
                }
                counter++;
            } catch (Exception ex) {
                LOG.error("Error while remove automatic role id [{}] from contract id [{}].", automaticRoleId, contractId, ex);
                failedEntitiesRemove.add(contractId.toString());
            } finally {
                canContinue = updateState();
                if (!canContinue) {
                    break;
                }
            }
        }
    }
    // 
    if (!failedEntitiesAdd.isEmpty() || !failedEntitiesRemove.isEmpty()) {
        throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_PROCESS_TASK_NOT_COMPLETE, ImmutableMap.of("automaticRole", automaticRoleId, "failedAddEntities", StringUtils.join(failedEntitiesAdd, ","), "failedRemoveEntities", StringUtils.join(failedEntitiesRemove, ",")));
    }
    // 
    return Boolean.TRUE;
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ArrayList(java.util.ArrayList) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)

Example 18 with AbstractIdmAutomaticRoleDto

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

the class ProcessAutomaticRoleByAttributeTaskExecutor method validate.

/**
 * Automatic role removal can be start, if previously LRT ended.
 */
@Override
public void validate(IdmLongRunningTaskDto task) {
    super.validate(task);
    // 
    UUID automaticRoleId = getAutomaticRoleId();
    AbstractIdmAutomaticRoleDto automaticRole = automaticRoleAttributeService.get(automaticRoleId);
    if (automaticRole == null) {
        throw new EntityNotFoundException(AbstractIdmAutomaticRoleDto.class, automaticRoleId);
    }
    // 
    IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
    filter.setTaskType(AutowireHelper.getTargetType(this));
    filter.setOperationState(OperationState.RUNNING);
    // by attribute - prevent currently processed role only
    for (IdmLongRunningTaskDto longRunningTask : getLongRunningTaskService().find(filter, null)) {
        if (longRunningTask.getId().equals(getLongRunningTaskId())) {
            continue;
        }
        if (longRunningTask.getTaskProperties().get(AbstractAutomaticRoleTaskExecutor.PARAMETER_ROLE_TREE_NODE).equals(automaticRole.getId())) {
            throw new AcceptedException(CoreResultCode.AUTOMATIC_ROLE_TASK_RUNNING, ImmutableMap.of("taskId", longRunningTask.getId().toString()));
        }
    }
    // 
    filter.setTaskType(AutowireHelper.getTargetType(RemoveAutomaticRoleTaskExecutor.class));
    for (IdmLongRunningTaskDto longRunningTask : getLongRunningTaskService().find(filter, null)) {
        if (longRunningTask.getId().equals(getLongRunningTaskId())) {
            continue;
        }
        if (longRunningTask.getTaskProperties().get(AbstractAutomaticRoleTaskExecutor.PARAMETER_ROLE_TREE_NODE).equals(automaticRole.getId())) {
            throw new AcceptedException(CoreResultCode.AUTOMATIC_ROLE_TASK_RUNNING, ImmutableMap.of("taskId", longRunningTask.getId().toString()));
        }
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID)

Aggregations

AbstractIdmAutomaticRoleDto (eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto)18 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)11 UUID (java.util.UUID)10 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)9 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)6 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)6 RoleRequestEvent (eu.bcvsolutions.idm.core.model.event.RoleRequestEvent)6 ArrayList (java.util.ArrayList)6 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)5 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)5 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)5 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)3 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)3 EntityNotFoundException (eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException)3 IdentityRoleEvent (eu.bcvsolutions.idm.core.model.event.IdentityRoleEvent)3 HashSet (java.util.HashSet)3 AutomaticRoleAttributeRuleType (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType)2 ConceptRoleRequestOperation (eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation)2 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)2