Search in sources :

Example 11 with DefaultResultModel

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

the class LongRunningTaskResultMonitoringEvaluator method evaluate.

@Override
public IdmMonitoringResultDto evaluate(IdmMonitoringDto monitoring) {
    IdmMonitoringResultDto result = new IdmMonitoringResultDto();
    ResultModel resultModel;
    // 
    IdmProcessedTaskItemFilter filter = new IdmProcessedTaskItemFilter();
    filter.setOperationState(OperationState.EXCEPTION);
    filter.setTaskMonitoringIgnored(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 = processedTaskItemService.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) IdmProcessedTaskItemFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmProcessedTaskItemFilter) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)

Example 12 with DefaultResultModel

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

the class IdmMessageDtoUnitTest method testModelSuccess.

@Test
public void testModelSuccess() {
    ResultModel model = new DefaultResultModel(CoreResultCode.ACCEPTED);
    IdmMessageDto message = new IdmMessageDto.Builder().setModel(model).build();
    Assert.assertEquals(model.getStatusEnum(), message.getSubject());
    Assert.assertEquals(model.getMessage(), message.getTextMessage());
    Assert.assertEquals(model.getMessage(), message.getHtmlMessage());
    Assert.assertEquals(NotificationLevel.SUCCESS, message.getLevel());
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) 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) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) Test(org.junit.Test)

Example 13 with DefaultResultModel

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

the class IdmMessageDtoUnitTest method testModelOveloadMessageAndSubject.

@Test
public void testModelOveloadMessageAndSubject() {
    ResultModel model = new DefaultResultModel(CoreResultCode.INTERNAL_SERVER_ERROR);
    IdmMessageDto message = new IdmMessageDto.Builder().setModel(model).setMessage(PARAMETER_TEXT).setSubject(PARAMETER_SUBJECT).build();
    Assert.assertEquals(PARAMETER_SUBJECT, message.getSubject());
    Assert.assertEquals(PARAMETER_TEXT, message.getTextMessage());
    Assert.assertEquals(PARAMETER_TEXT, message.getHtmlMessage());
    Assert.assertEquals(NotificationLevel.ERROR, message.getLevel());
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) 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) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) Test(org.junit.Test)

Example 14 with DefaultResultModel

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

the class SystemMappingDeleteBulkAction method prevalidate.

@Override
public ResultModels prevalidate() {
    IdmBulkActionDto action = getAction();
    List<UUID> entities = getEntities(action, new StringBuilder());
    ResultModels result = new ResultModels();
    Map<ResultModel, Long> models = new HashMap<>();
    entities.forEach(mappingId -> {
        SysSystemMappingDto mapping = getService().get(mappingId);
        SysSyncConfigFilter syncFilter = new SysSyncConfigFilter();
        syncFilter.setSystemMappingId(mappingId);
        long count = synchronizationService.count(syncFilter);
        if (count > 0) {
            models.put(new DefaultResultModel(AccResultCode.SYSTEM_MAPPING_DELETE_BULK_ACTION_MAPPING_IN_USE, ImmutableMap.of("mapping", mapping.getName(), "count", count)), count);
        }
    });
    List<Entry<ResultModel, Long>> collect = // 
    models.entrySet().stream().sorted(// 
    Collections.reverseOrder(Map.Entry.comparingByValue())).collect(Collectors.toList());
    collect.forEach(entry -> {
        result.addInfo(entry.getKey());
    });
    return result;
}
Also used : IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) HashMap(java.util.HashMap) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) Entry(java.util.Map.Entry) UUID(java.util.UUID) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)

Example 15 with DefaultResultModel

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

the class AbstractProvisioningOperationRetryCancelBulkAction method processEntities.

@Override
protected OperationResult processEntities(Collection<UUID> entitiesId) {
    for (UUID entityId : entitiesId) {
        SysProvisioningOperationDto dto = getService().get(entityId);
        if (dto == null) {
            dto = new SysProvisioningOperationDto(entityId);
            boolean processed = false;
            // 
            // try to find provisioning operation by id => NotFound(Ignore) annotation will be effective
            SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
            filter.setId(entityId);
            List<SysProvisioningOperationDto> operations = getService().find(filter, PageRequest.of(0, 1)).getContent();
            if (operations.size() == 1) {
                SysProvisioningOperationDto invalidOperation = operations.get(0);
                if (invalidOperation.getSystemEntity() == null) {
                    LOG.warn("System entity for provisioning operation [{}] was already deleted. " + "Operation cannot be executed or canceled. Operation can be deleted only.", entityId);
                    processed = true;
                    // 
                    this.logItemProcessed(invalidOperation, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(AccResultCode.SYSTEM_ENTITY_NOT_FOUND, ImmutableMap.of("system", invalidOperation.getSystem()))).build());
                }
            }
            // batch and it not exists.
            if (processed) {
            // item logged above already
            } else if (!isRetryWholeBatchAttribute()) {
                this.logItemProcessed(dto, new OperationResult.Builder(OperationState.NOT_EXECUTED).build());
            } else {
                LOG.warn("Entity with id [{}] not found. The Entity will be skipped by batch processing.", entityId);
                // 
                this.logItemProcessed(dto, new OperationResult.Builder(OperationState.EXECUTED).setModel(new DefaultResultModel(AccResultCode.PROVISONING_OPERATION_RETRY_CANCEL_NOT_FOUND, ImmutableMap.of("provisioningOperation", entityId.toString()))).build());
            }
            if (!updateState()) {
                return new OperationResult.Builder(OperationState.CANCELED).build();
            }
            continue;
        }
        try {
            if (checkPermissionForEntity(dto)) {
                OperationResult result = processDto(dto);
                this.logItemProcessed(dto, result);
            } else {
                // check permission failed
                createPermissionFailedLog(dto);
            }
            // 
            if (!updateState()) {
                return new OperationResult.Builder(OperationState.CANCELED).build();
            }
        } catch (Exception ex) {
            // log failed result and continue
            LOG.error("Processing of entity [{}] failed.", entityId, ex);
            this.logItemProcessed(dto, new OperationResult.Builder(OperationState.EXCEPTION).setCause(ex).build());
            if (!updateState()) {
                return new OperationResult.Builder(OperationState.CANCELED).setCause(ex).build();
            }
        }
    }
    return new OperationResult.Builder(OperationState.EXECUTED).build();
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) UUID(java.util.UUID) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)

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