Search in sources :

Example 31 with DefaultResultModel

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

the class DefaultLongRunningTaskManager method createTaskExecutor.

/**
 * Create new LongRunningTaskExecutor from given LRT.
 * Handles exceptions, when task already processed, task type is removed or task initialization failed
 *
 * @param task
 * @return
 */
protected LongRunningTaskExecutor<?> createTaskExecutor(IdmLongRunningTaskDto task) {
    Assert.notNull(task, "Long running task instance is required!");
    if (!OperationState.isRunnable(task.getResultState())) {
        throw new ResultCodeException(CoreResultCode.LONG_RUNNING_TASK_IS_PROCESSED, ImmutableMap.of("taskId", task.getId()));
    }
    // 
    LongRunningTaskExecutor<?> taskExecutor = null;
    ResultModel resultModel = null;
    Exception ex = null;
    try {
        taskExecutor = (LongRunningTaskExecutor<?>) AutowireHelper.createBean(Class.forName(task.getTaskType()));
        taskExecutor.setLongRunningTaskId(task.getId());
        taskExecutor.init((Map<String, Object>) task.getTaskProperties());
    } catch (ClassNotFoundException e) {
        ex = e;
        resultModel = new DefaultResultModel(CoreResultCode.LONG_RUNNING_TASK_NOT_FOUND, ImmutableMap.of("taskId", task.getId(), "taskType", task.getTaskType(), ConfigurationService.PROPERTY_INSTANCE_ID, task.getInstanceId()));
    } catch (ResultCodeException e) {
        ex = e;
        resultModel = ((ResultCodeException) e).getError().getError();
    } catch (Exception e) {
        ex = e;
    }
    if (ex != null) {
        if (resultModel == null) {
            resultModel = new DefaultResultModel(CoreResultCode.LONG_RUNNING_TASK_INIT_FAILED, ImmutableMap.of("taskId", task.getId(), "taskType", task.getTaskType(), ConfigurationService.PROPERTY_INSTANCE_ID, task.getInstanceId()));
        }
        // 
        LOG.error(resultModel.toString(), ex);
        task.setResult(new OperationResult.Builder(OperationState.EXCEPTION).setModel(resultModel).setCause(ex).build());
        service.save(task);
        return null;
    } else {
        return taskExecutor;
    }
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ConcurrentExecutionException(eu.bcvsolutions.idm.core.scheduler.api.exception.ConcurrentExecutionException) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) TaskNotRecoverableException(eu.bcvsolutions.idm.core.scheduler.exception.TaskNotRecoverableException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Example 32 with DefaultResultModel

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

the class AddNewAutomaticRoleForPositionTaskExecutor method processItem.

@Override
public Optional<OperationResult> processItem(IdmContractPositionDto contractPosition) {
    IdmIdentityContractDto contract = DtoUtils.getEmbedded(contractPosition, IdmContractPosition_.identityContract);
    // 
    try {
        if (!contract.isValidNowOrInFuture()) {
            IdmIdentityDto identity = getIdentity(contract);
            IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role);
            return Optional.of(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_CONTRACT_IS_NOT_VALID, ImmutableMap.of("role", role.getCode(), "roleTreeNode", getRoleTreeNode().getId(), "identity", identity.getUsername()))).build());
        }
        List<IdmIdentityRoleDto> allByPosition = identityRoleService.findAllByContractPosition(contractPosition.getId());
        // skip already assigned automatic roles
        for (IdmIdentityRoleDto roleByContract : allByPosition) {
            if (ObjectUtils.equals(roleByContract.getAutomaticRole(), getRoleTreeNode().getId())) {
                IdmIdentityDto identity = getIdentity(contract);
                IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role);
                return Optional.of(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ALREADY_ASSIGNED, ImmutableMap.of("role", role.getCode(), "roleTreeNode", getRoleTreeNode().getId(), "identity", identity.getUsername()))).build());
            }
        }
        // 
        // automatic role by tree node is added directly trough identity role
        IdmRoleTreeNodeDto autoRole = getRoleTreeNode();
        IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
        conceptRoleRequest.setIdentityContract(contract.getId());
        conceptRoleRequest.setContractPosition(contractPosition.getId());
        conceptRoleRequest.setValidFrom(contract.getValidFrom());
        conceptRoleRequest.setValidTill(contract.getValidTill());
        conceptRoleRequest.setRole(autoRole.getRole());
        conceptRoleRequest.setAutomaticRole(autoRole.getId());
        conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
        roleRequestService.executeConceptsImmediate(contract.getIdentity(), Lists.newArrayList(conceptRoleRequest));
        // 
        return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
    } catch (Exception ex) {
        IdmIdentityDto identity = getIdentity(contract);
        IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role);
        // 
        LOG.error("Adding role [{}] by automatic role [{}] for identity [{}] failed", role.getCode(), getRoleTreeNode().getId(), identity.getUsername(), ex);
        // 
        return Optional.of(new OperationResult.Builder(OperationState.EXCEPTION).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ASSIGN_TASK_NOT_COMPLETE, ImmutableMap.of("role", role.getCode(), "roleTreeNode", getRoleTreeNode().getId(), "identity", identity.getUsername()))).setCause(ex).build());
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) 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) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException)

Example 33 with DefaultResultModel

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

the class AddNewAutomaticRoleTaskExecutor method processItem.

@Override
public Optional<OperationResult> processItem(IdmIdentityContractDto contract) {
    try {
        if (!contract.isValidNowOrInFuture()) {
            IdmIdentityDto identity = DtoUtils.getEmbedded(contract, IdmIdentityContract_.identity);
            IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role);
            return Optional.of(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_CONTRACT_IS_NOT_VALID, ImmutableMap.of("role", role.getCode(), "roleTreeNode", getRoleTreeNode().getId(), "identity", identity.getUsername()))).build());
        }
        List<IdmIdentityRoleDto> allByContract = identityRoleService.findAllByContract(contract.getId());
        // skip already assigned automatic roles
        for (IdmIdentityRoleDto roleByContract : allByContract) {
            if (ObjectUtils.equals(roleByContract.getAutomaticRole(), getRoleTreeNode().getId())) {
                IdmIdentityDto identity = DtoUtils.getEmbedded(contract, IdmIdentityContract_.identity);
                IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role);
                return Optional.of(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ALREADY_ASSIGNED, ImmutableMap.of("role", role.getCode(), "roleTreeNode", getRoleTreeNode().getId(), "identity", identity.getUsername()))).build());
            }
        }
        // 
        // automatic role by tree node is added directly trough identity role
        IdmRoleTreeNodeDto autoRole = getRoleTreeNode();
        IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
        conceptRoleRequest.setIdentityContract(contract.getId());
        conceptRoleRequest.setValidFrom(contract.getValidFrom());
        conceptRoleRequest.setValidTill(contract.getValidTill());
        conceptRoleRequest.setRole(autoRole.getRole());
        conceptRoleRequest.setAutomaticRole(autoRole.getId());
        conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
        roleRequestService.executeConceptsImmediate(contract.getIdentity(), Lists.newArrayList(conceptRoleRequest));
        // 
        return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
    } catch (Exception ex) {
        IdmIdentityDto identity = DtoUtils.getEmbedded(contract, IdmIdentityContract_.identity);
        IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role);
        // 
        LOG.error("Adding role [{}] by automatic role [{}] for identity [{}] failed", role.getCode(), getRoleTreeNode().getId(), identity.getUsername(), ex);
        // 
        return Optional.of(new OperationResult.Builder(OperationState.EXCEPTION).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ASSIGN_TASK_NOT_COMPLETE, ImmutableMap.of("role", role.getCode(), "roleTreeNode", getRoleTreeNode().getId(), "identity", identity.getUsername()))).setCause(ex).build());
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException)

Example 34 with DefaultResultModel

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

the class DefaultEntityStateManagerIntergationTest method testSaveState.

@Test
public void testSaveState() {
    IdmIdentityDto owner = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto ownerTwo = getHelper().createIdentity((GuardedString) null);
    // 
    IdmEntityStateDto state = new IdmEntityStateDto();
    state.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
    state = manager.saveState(owner, state);
    IdmEntityStateDto stateOther = new IdmEntityStateDto();
    stateOther.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
    manager.saveState(ownerTwo, stateOther);
    List<IdmEntityStateDto> states = manager.findStates(owner, null).getContent();
    Assert.assertEquals(1, states.size());
    IdmEntityStateDto persistedState = states.get(0);
    // 
    Assert.assertEquals(owner.getId(), persistedState.getOwnerId());
    Assert.assertEquals(manager.getOwnerType(owner), persistedState.getOwnerType());
    Assert.assertEquals(OperationState.RUNNING, persistedState.getResult().getState());
    // 
    manager.deleteState(state);
    // 
    Assert.assertTrue(manager.findStates(owner, PageRequest.of(0, 1)).getTotalElements() == 0);
}
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) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 35 with DefaultResultModel

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

the class AdUserConnectorType method createEntityStateWithTestUser.

/**
 * Create entity state for wizard test user
 */
private IdmEntityStateDto createEntityStateWithTestUser(SysSystemDto systemDto, String createdUserDN) {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("entityId", systemDto.getId());
    // Mark state with created user DN.
    parameters.put(TEST_CREATED_USER_DN_KEY, createdUserDN);
    DefaultResultModel resultModel = new DefaultResultModel(AccResultCode.WIZARD_AD_CREATED_TEST_USER_DN, parameters);
    IdmEntityStateDto entityStateDto = new IdmEntityStateDto();
    entityStateDto.setResult(new OperationResultDto.Builder(OperationState.CREATED).setModel(resultModel).build());
    return entityStateManager.saveState(systemDto, entityStateDto);
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) HashMap(java.util.HashMap) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString)

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