Search in sources :

Example 91 with DefaultResultModel

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

the class RoleRequestCheckSystemStateProcessor method createResult.

private EventResult<IdmRoleRequestDto> createResult(EntityEvent<IdmRoleRequestDto> event, IdmRoleRequestDto request, OperationState state, ResultCode resultCode, Map<String, Object> properties, String cause) {
    OperationResultDto systemResult = new OperationResultDto.Builder(state).setModel(new DefaultResultModel(resultCode, properties)).build();
    systemResult.setCause(cause);
    request.setSystemState(systemResult);
    DefaultEventResult<IdmRoleRequestDto> result = new DefaultEventResult<>(event, this);
    result.getEvent().getProperties().put(SYSTEM_STATE_RESOLVED_KEY, Boolean.TRUE);
    return result;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 92 with DefaultResultModel

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

the class DefaultSysProvisioningOperationService method handleSuccessful.

/**
 * REQUIRES_NEW => we want to have log in queue / archive all time, even original transaction ends with exception (after calling this method).
 */
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public SysProvisioningOperationDto handleSuccessful(SysProvisioningOperationDto operation) {
    ResultModel resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_SUCCEED, ImmutableMap.of(// FIXME: String uid = getByProvisioningOperation(operation).getUid();
    "name", // FIXME: String uid = getByProvisioningOperation(operation).getUid();
    operation.getSystemEntityUid(), "system", getSystem(operation).getName(), "operationType", operation.getOperationType(), "objectClass", operation.getProvisioningContext().getConnectorObject().getObjectClass().getType()));
    operation.setResult(new OperationResult.Builder(OperationState.EXECUTED).setModel(resultModel).build());
    if (!operation.isDryRun()) {
        operation = save(operation);
        // 
        // cleanup next attempt time - batch are not removed
        SysProvisioningBatchDto batch = DtoUtils.getEmbedded(operation, SysProvisioningOperation_.batch, (SysProvisioningBatchDto) null);
        if (batch == null) {
            batch = batchService.get(operation.getBatch());
        }
        if (batch.getNextAttempt() != null) {
            batch.setNextAttempt(null);
            batch = batchService.save(batch);
        }
        // 
        LOG.info(resultModel.toString());
    // 
    }
    return operation;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 93 with DefaultResultModel

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

the class DefaultProvisioningExecutor method persistOperation.

/**
 * Persist new operation - assign appropriate batch. Operation is put into queue, if it's already in the queue.
 */
private SysProvisioningOperationDto persistOperation(SysProvisioningOperationDto provisioningOperation) {
    Assert.notNull(provisioningOperation, "Provisioning operation is required.");
    Assert.notNull(provisioningOperation.getSystemEntity(), "System entity is required.");
    Assert.notNull(provisioningOperation.getProvisioningContext(), "Provisioning context is required.");
    // get system from service, in provisioning operation may not exist
    SysSystemDto system = DtoUtils.getEmbedded(provisioningOperation, SysProvisioningOperation_.system, (SysSystemDto) null);
    if (system == null) {
        system = systemService.get(provisioningOperation.getSystem());
    }
    Assert.notNull(system, "System is required.");
    // make sure system will be in embedded - optimize
    provisioningOperation.getEmbedded().put(SysProvisioningOperation_.system.getName(), system);
    // dryRun provisioning - skip SysProvisioningOperationDto saving
    if (provisioningOperation.isDryRun()) {
        if (provisioningOperation.getId() == null) {
            // FAKE UUID - we don't want to save provisioningOperation but its UUID must not be null
            provisioningOperation.setId(UUID.randomUUID());
        }
        provisioningOperation.setResult(new OperationResult.Builder(OperationState.CREATED).build());
        return provisioningOperation;
    }
    // save new operation to provisioning log / queue
    String uid = systemEntityService.getByProvisioningOperation(provisioningOperation).getUid();
    // look out - system entity uid can be changed - we need to use system entity id
    SysProvisioningBatchDto batch = batchService.findBatch(provisioningOperation.getSystemEntity());
    if (batch == null) {
        // new batch
        batch = batchService.save(new SysProvisioningBatchDto(provisioningOperation));
        provisioningOperation.setResult(new OperationResult.Builder(OperationState.CREATED).build());
    } else {
        SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
        filter.setNotInState(OperationState.CREATED);
        filter.setBatchId(batch.getId());
        List<SysProvisioningOperationDto> activeOperations = provisioningOperationService.find(filter, PageRequest.of(0, 1, new Sort(Direction.DESC, SysProvisioningOperation_.created.getName()))).getContent();
        if (activeOperations.isEmpty()) {
            // batch is completed (no operations in queue)
            provisioningOperation.setResult(new OperationResult.Builder(OperationState.CREATED).build());
        } else {
            // put to queue, if previous
            ResultModel resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_IS_IN_QUEUE, ImmutableMap.of("name", uid, "system", system.getName(), "operationType", provisioningOperation.getOperationType(), "objectClass", provisioningOperation.getProvisioningContext().getConnectorObject().getObjectClass()));
            LOG.debug(resultModel.toString());
            provisioningOperation.setResult(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(resultModel).build());
            if (activeOperations.get(0).getResultState() == OperationState.RUNNING) {
                // the last operation = the first operation and it's running
                // Retry date will be set for the second operation in the queue (the first is running).
                // Other operations will be executed automatically by batch.
                provisioningOperation.setMaxAttempts(provisioningConfiguration.getRetryMaxAttempts());
                batch.setNextAttempt(batchService.calculateNextAttempt(provisioningOperation));
                batch = batchService.save(batch);
            }
            if (securityService.getCurrentId() != null) {
                // TODO: check logged identity and account owner
                notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder(NotificationLevel.WARNING).setModel(provisioningOperation.getResult().getModel()).build());
            }
        }
    }
    provisioningOperation.setBatch(batch.getId());
    provisioningOperation = provisioningOperationService.save(provisioningOperation);
    // 
    return provisioningOperation;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Sort(org.springframework.data.domain.Sort) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)

Example 94 with DefaultResultModel

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

the class DefaultEntityStateManager method createState.

@Override
@Transactional
public IdmEntityStateDto createState(Identifiable owner, OperationState operationState, ResultCode code, Map<String, Serializable> properties, BasePermission... permission) {
    IdmEntityStateDto state = new IdmEntityStateDto();
    Map<String, Object> modelParameters = null;
    if (properties != null) {
        modelParameters = new HashMap<String, Object>(properties);
    }
    state.setResult(new OperationResultDto.Builder(operationState == null ? OperationState.CREATED : operationState).setModel(code == null ? null : new DefaultResultModel(code, modelParameters)).build());
    // 
    return saveState(owner, state, permission);
}
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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 95 with DefaultResultModel

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

the class LongRunningTaskMonitoringEvaluator method evaluate.

@Override
public IdmMonitoringResultDto evaluate(IdmMonitoringDto monitoring) {
    IdmMonitoringResultDto result = new IdmMonitoringResultDto();
    ResultModel resultModel;
    // 
    IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
    filter.setOperationState(OperationState.EXCEPTION);
    filter.setMonitoringIgnored(Boolean.FALSE);
    Long givenNumberOfDays = getParameterConverter().toLong(monitoring.getEvaluatorProperties(), PARAMETER_NUMBER_OF_DAYS);
    if (givenNumberOfDays != null) {
        filter.setCreatedFrom(ZonedDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(givenNumberOfDays));
    }
    long count = longRunningTaskService.count(filter);
    // 
    if (count > 0) {
        resultModel = new DefaultResultModel(CoreResultCode.MONITORING_LONG_RUNNING_TASK_ERROR, ImmutableMap.of("count", Long.toString(count)));
    } else {
        resultModel = new DefaultResultModel(CoreResultCode.OK);
    }
    // 
    result.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).setModel(resultModel).build());
    result.setValue(String.valueOf(count));
    // 
    return result;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)

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