Search in sources :

Example 1 with MonitoringEvaluator

use of eu.bcvsolutions.idm.core.monitoring.api.service.MonitoringEvaluator in project CzechIdMng by bcvsolutions.

the class DefaultMonitoringManager method getEvaluator.

private MonitoringEvaluator getEvaluator(IdmMonitoringDto monitoring) {
    String evaluatorType = monitoring.getEvaluatorType();
    MonitoringEvaluator evaluator = getEvaluator(evaluatorType);
    // 
    if (evaluator == null) {
        LOG.info("Evaluator type [{}] for monitoring [{}] not found - monitoring will not be evaluated.", evaluatorType, monitoring.getId());
    }
    // 
    return evaluator;
}
Also used : MonitoringEvaluator(eu.bcvsolutions.idm.core.monitoring.api.service.MonitoringEvaluator)

Example 2 with MonitoringEvaluator

use of eu.bcvsolutions.idm.core.monitoring.api.service.MonitoringEvaluator in project CzechIdMng by bcvsolutions.

the class DefaultMonitoringManager method getEvaluatorFormInstance.

@Override
public IdmFormInstanceDto getEvaluatorFormInstance(IdmMonitoringDto monitoring) {
    MonitoringEvaluator evaluator = getEvaluator(monitoring.getEvaluatorType());
    if (evaluator == null) {
        return null;
    }
    IdmFormInstanceDto formInstance = evaluator.getFormInstance(monitoring.getEvaluatorProperties());
    if (formInstance == null) {
        return null;
    }
    // 
    formInstance.setOwnerId(monitoring.getId());
    formInstance.setOwnerType(monitoring.getClass());
    // 
    return formInstance;
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) MonitoringEvaluator(eu.bcvsolutions.idm.core.monitoring.api.service.MonitoringEvaluator)

Example 3 with MonitoringEvaluator

use of eu.bcvsolutions.idm.core.monitoring.api.service.MonitoringEvaluator in project CzechIdMng by bcvsolutions.

the class DefaultMonitoringManager method getLastResults.

@Override
public Page<IdmMonitoringResultDto> getLastResults(IdmMonitoringResultFilter filter, Pageable pageable, BasePermission... permission) {
    // all instances => last results should be visible on each instance
    IdmMonitoringFilter monitoringFilter = new IdmMonitoringFilter();
    if (filter != null) {
        monitoringFilter.setId(filter.getMonitoring());
    }
    monitoringFilter.setDisabled(Boolean.FALSE);
    // 
    List<IdmMonitoringDto> monitorings = monitoringService.find(monitoringFilter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmMonitoring_.seq.getName())), PermissionUtils.isEmpty(permission) ? null : IdmBasePermission.AUTOCOMPLETE).getContent();
    // 
    // last results sorted by monitoring order
    List<IdmMonitoringResultDto> results = new ArrayList<>(monitorings.size());
    for (IdmMonitoringDto monitoring : monitorings) {
        MonitoringEvaluator evaluator = getEvaluator(monitoring);
        if (evaluator == null) {
            LOG.debug("Monitoring evaluator for motitoring configuration [{}] not exists.", monitoring.getId());
            continue;
        }
        IdmMonitoringResultDto lastResult = getLastResult(monitoring.getId(), permission);
        if (lastResult == null) {
            continue;
        }
        // filter by level
        NotificationLevel lastResultLevel = lastResult.getLevel();
        List<NotificationLevel> levels = filter == null ? null : filter.getLevels();
        if (CollectionUtils.isNotEmpty(levels) && !levels.contains(lastResultLevel)) {
            continue;
        }
        lastResult.setTrimmed(true);
        results.add(lastResult);
    }
    // 
    // pageable is required internally
    Pageable internalPageable;
    if (pageable == null) {
        internalPageable = PageRequest.of(0, Integer.MAX_VALUE);
    } else {
        internalPageable = pageable;
    }
    // 
    // Sort by level desc
    results.sort((r1, r2) -> {
        return ObjectUtils.compare(r2.getLevel(), r1.getLevel());
    });
    // 
    // "naive" pagination
    int first = internalPageable.getPageNumber() * internalPageable.getPageSize();
    int last = internalPageable.getPageSize() + first;
    List<IdmMonitoringResultDto> page = results.subList(first < results.size() ? first : results.size() > 0 ? results.size() - 1 : 0, last < results.size() ? last : results.size());
    // 
    return new PageImpl<>(page, internalPageable, results.size());
}
Also used : IdmMonitoringFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringFilter) PageImpl(org.springframework.data.domain.PageImpl) IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) Pageable(org.springframework.data.domain.Pageable) MonitoringEvaluator(eu.bcvsolutions.idm.core.monitoring.api.service.MonitoringEvaluator) ArrayList(java.util.ArrayList) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)

Example 4 with MonitoringEvaluator

use of eu.bcvsolutions.idm.core.monitoring.api.service.MonitoringEvaluator in project CzechIdMng by bcvsolutions.

the class DefaultMonitoringManager method evaluate.

@Override
public IdmMonitoringResultDto evaluate(IdmMonitoringDto monitoring) {
    Assert.notNull(monitoring, "Monitoring is required.");
    UUID monitoringId = monitoring.getId();
    Assert.notNull(monitoringId, "Persisted monitoring is required.");
    // 
    MonitoringEvaluator evaluator = getEvaluator(monitoring);
    if (evaluator == null) {
        LOG.warn("Monitoring evaluator for motitoring configuration [{}] not exists.", monitoringId);
        return null;
    }
    // 
    ZonedDateTime monitoringStarted = ZonedDateTime.now();
    IdmMonitoringResultDto result = null;
    try {
        result = evaluator.evaluate(monitoring);
    } catch (AcceptedException ex) {
        result = new IdmMonitoringResultDto(new OperationResultDto.Builder(OperationState.RUNNING).setException(ex).build());
        result.setLevel(NotificationLevel.INFO);
    } catch (ResultCodeException ex) {
        result = new IdmMonitoringResultDto(new OperationResultDto.Builder(OperationState.EXCEPTION).setException(ex).build());
        result.setLevel(NotificationLevel.ERROR);
    } catch (Exception ex) {
        Throwable resolvedException = ExceptionUtils.resolveException(ex);
        if (resolvedException instanceof ResultCodeException) {
            result = new IdmMonitoringResultDto(// 
            new OperationResultDto.Builder(OperationState.EXCEPTION).setException(// 
            (ResultCodeException) resolvedException).build());
            result.setLevel(NotificationLevel.ERROR);
        } else {
            result = new IdmMonitoringResultDto(new OperationResultDto.Builder(OperationState.EXCEPTION).setCause(ex).build());
        }
    }
    // 
    if (result != null) {
        result.setMonitoring(monitoringId);
        result.setEvaluatorType(monitoring.getEvaluatorType());
        result.setProcessedOrder(monitoring.getSeq());
        result.setEvaluatorProperties(monitoring.getEvaluatorProperties());
        result.setInstanceId(monitoring.getInstanceId());
        // default result state
        if (result.getResult() == null) {
            result.setResult(new OperationResultDto(OperationState.EXECUTED));
        }
        // default level by result model
        if (result.getLevel() == null) {
            ResultModel resultModel = result.getResult().getModel();
            if (resultModel != null) {
                result.setLevel(resultModel.getLevel());
            }
        }
        // 
        result.setMonitoringStarted(monitoringStarted);
        result.setMonitoringEnded(ZonedDateTime.now());
        result.setLastResult(true);
        // reset last result flag
        monitoringResultService.resetLastResult(monitoringId);
        // save new last result
        result = monitoringResultService.save(result);
        // 
        cacheManager.cacheValue(LAST_RESULT_CACHE_NAME, monitoringId, result);
    } else {
        LOG.debug("Monitoring [{}] ended without result - result will not be persisted.", monitoringId);
    }
    // 
    return result;
}
Also used : MonitoringEvaluator(eu.bcvsolutions.idm.core.monitoring.api.service.MonitoringEvaluator) ZonedDateTime(java.time.ZonedDateTime) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)

Example 5 with MonitoringEvaluator

use of eu.bcvsolutions.idm.core.monitoring.api.service.MonitoringEvaluator in project CzechIdMng by bcvsolutions.

the class DefaultMonitoringManager method getEvaluatorFormInstance.

@Override
public IdmFormInstanceDto getEvaluatorFormInstance(IdmMonitoringResultDto monitoringResult) {
    MonitoringEvaluator evaluator = getEvaluator(monitoringResult.getEvaluatorType());
    if (evaluator == null) {
        return null;
    }
    IdmFormInstanceDto formInstance = evaluator.getFormInstance(monitoringResult.getEvaluatorProperties());
    if (formInstance == null) {
        return null;
    }
    // 
    formInstance.setOwnerId(monitoringResult.getId());
    formInstance.setOwnerType(monitoringResult.getClass());
    // 
    return formInstance;
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) MonitoringEvaluator(eu.bcvsolutions.idm.core.monitoring.api.service.MonitoringEvaluator)

Aggregations

MonitoringEvaluator (eu.bcvsolutions.idm.core.monitoring.api.service.MonitoringEvaluator)5 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)2 IdmMonitoringResultDto (eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)2 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)1 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)1 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 IdmMonitoringDto (eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto)1 IdmMonitoringFilter (eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringFilter)1 NotificationLevel (eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)1 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 PageImpl (org.springframework.data.domain.PageImpl)1 Pageable (org.springframework.data.domain.Pageable)1