use of eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter in project CzechIdMng by bcvsolutions.
the class DefaultMonitoringManagerIntegrationTest method testExecuteMonitoringAfterSave.
@Test
@Transactional
public void testExecuteMonitoringAfterSave() {
IdmMonitoringDto monitoring = new IdmMonitoringDto();
monitoring.setCheckPeriod(0L);
monitoring.setEvaluatorType(AutowireHelper.getTargetType(h2DatabaseMonitoringEvaluator));
monitoring.setInstanceId(configurationService.getInstanceId());
monitoring.setDisabled(false);
//
MonitoringEvent event = new MonitoringEvent(MonitoringEventType.CREATE, monitoring);
event.setPriority(PriorityType.HIGH);
monitoring = monitoringService.publish(event).getContent();
try {
IdmMonitoringResultFilter filter = new IdmMonitoringResultFilter();
filter.setMonitoring(monitoring.getId());
List<IdmMonitoringResultDto> results = monitoringResultService.find(filter, null).getContent();
Assert.assertFalse(results.isEmpty());
} finally {
monitoringService.delete(monitoring);
}
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter in project CzechIdMng by bcvsolutions.
the class DefaultMonitoringManagerIntegrationTest method testRegisterMonitoringEvaluatorWithCheckPeriod.
@Test
public void testRegisterMonitoringEvaluatorWithCheckPeriod() {
IdmMonitoringDto monitoring = new IdmMonitoringDto();
// ~ hour
monitoring.setCheckPeriod(3600L);
monitoring.setEvaluatorType(AutowireHelper.getTargetType(h2DatabaseMonitoringEvaluator));
monitoring.setInstanceId(configurationService.getInstanceId());
monitoring = monitoringService.save(monitoring);
try {
//
manager.scheduleExecute();
manager.scheduleExecute();
manager.scheduleExecute();
//
IdmMonitoringResultFilter filter = new IdmMonitoringResultFilter();
filter.setMonitoring(monitoring.getId());
//
List<IdmMonitoringResultDto> results = monitoringResultService.find(filter, null).getContent();
// executed only once => 0 check period
Assert.assertEquals(1, results.size());
//
List<IdmMonitoringResultDto> lastResults = manager.getLastResults(filter, null).getContent();
//
Assert.assertEquals(1, lastResults.size());
Assert.assertEquals(results.get(0).getId(), lastResults.get(0).getId());
//
manager.init();
//
lastResults = manager.getLastResults(filter, null).getContent();
//
Assert.assertEquals(1, lastResults.size());
Assert.assertEquals(results.get(0).getId(), lastResults.get(0).getId());
//
// evict and load cache again
cacheManager.evictCache(MonitoringManager.LAST_RESULT_CACHE_NAME);
lastResults = manager.getLastResults(filter, null).getContent();
//
Assert.assertEquals(1, lastResults.size());
Assert.assertEquals(results.get(0).getId(), lastResults.get(0).getId());
} finally {
monitoringService.delete(monitoring);
}
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter in project CzechIdMng by bcvsolutions.
the class DefaultMonitoringManager method getLastResult.
/**
* Find last monitoring result.
*
* @param monitoringId monitoring evaluator identifier
* @return last result
*/
private IdmMonitoringResultDto getLastResult(UUID monitoringId, BasePermission... permission) {
// try to get cached value
ValueWrapper value = cacheManager.getValue(LAST_RESULT_CACHE_NAME, monitoringId);
if (value != null) {
return monitoringResultService.checkAccess((IdmMonitoringResultDto) value.get(), permission);
}
// or load from database
IdmMonitoringResultFilter resultFilter = new IdmMonitoringResultFilter();
resultFilter.setMonitoring(monitoringId);
List<IdmMonitoringResultDto> monitoringResults = monitoringResultService.find(resultFilter, PageRequest.of(0, 1, Sort.by(Direction.DESC, IdmMonitoringResult_.created.getName())), permission).getContent();
if (monitoringResults.isEmpty()) {
// null => prevent to load again
cacheManager.cacheValue(LAST_RESULT_CACHE_NAME, monitoringId, null);
//
return null;
}
//
IdmMonitoringResultDto lastResult = monitoringResults.get(0);
cacheManager.cacheValue(LAST_RESULT_CACHE_NAME, monitoringId, lastResult);
//
return lastResult;
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter in project CzechIdMng by bcvsolutions.
the class IdmMonitoringResultController method toFilter.
@Override
protected IdmMonitoringResultFilter toFilter(MultiValueMap<String, Object> parameters) {
IdmMonitoringResultFilter filter = new IdmMonitoringResultFilter(parameters, getParameterConverter());
//
filter.setMonitoring(getParameterConverter().toEntityUuid(parameters, IdmMonitoringResultFilter.PARAMETER_MONITORING, IdmMonitoringDto.class));
//
return filter;
}
Aggregations