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;
}
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;
}
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());
}
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;
}
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;
}
Aggregations