use of eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringFilter in project CzechIdMng by bcvsolutions.
the class IdmMonitoringControllerRestTest method testFindByText.
@Test
public void testFindByText() {
IdmMonitoringDto monitoring = prepareDto();
monitoring.setEvaluatorType(getHelper().createName());
monitoring.setInstanceId("mock");
IdmMonitoringDto monitoringOne = createDto(monitoring);
//
monitoring = prepareDto();
monitoring.setEvaluatorType(TestMonitoringEvaluator.class.getCanonicalName());
monitoring.setDescription(monitoringOne.getEvaluatorType());
monitoring.setInstanceId("mock");
IdmMonitoringDto monitoringTwo = createDto(monitoring);
//
monitoring = prepareDto();
monitoring.setEvaluatorType(DemoAdminMonitoringEvaluator.class.getCanonicalName());
monitoring.setDescription(monitoringOne.getEvaluatorType());
monitoring.setInstanceId("mock");
IdmMonitoringDto monitoringThree = createDto(monitoring);
//
// other
createDto();
//
IdmMonitoringFilter filter = new IdmMonitoringFilter();
filter.setText(monitoringOne.getEvaluatorType());
List<IdmMonitoringDto> results = find(filter);
//
Assert.assertEquals(3, results.size());
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(monitoringOne.getId())));
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(monitoringTwo.getId())));
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(monitoringThree.getId())));
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringFilter in project CzechIdMng by bcvsolutions.
the class SyncConfigMonitoringAutoConfigurationProcessorIntegrationTest method testAutoConfigure.
@Test
public void testAutoConfigure() {
SysSystemDto system = getHelper().createTestResourceSystem(true);
SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter();
mappingFilter.setSystemId(system.getId());
List<SysSystemMappingDto> mappings = systemMappingService.find(mappingFilter, null).getContent();
SysSystemMappingDto mapping = mappings.get(0);
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemMappingId(mapping.getId());
List<SysSystemAttributeMappingDto> attributes = schemaAttributeMappingService.find(attributeMappingFilter, null).getContent();
SysSystemAttributeMappingDto nameAttribute = attributes.stream().filter(attribute -> {
return attribute.getName().equals(TestHelper.ATTRIBUTE_MAPPING_NAME);
}).findFirst().get();
// Create default synchronization config.
AbstractSysSyncConfigDto syncConfigCustom = new SysSyncIdentityConfigDto();
syncConfigCustom.setCustomFilter(true);
syncConfigCustom.setSystemMapping(mapping.getId());
syncConfigCustom.setCorrelationAttribute(nameAttribute.getId());
syncConfigCustom.setName(getHelper().createName());
AbstractSysSyncConfigDto syncConfig = syncConfigService.save(syncConfigCustom);
String evaluatorType = AutowireHelper.getTargetType(synchronizationMonitoringEvaluator);
IdmMonitoringFilter filter = new IdmMonitoringFilter();
filter.setEvaluatorType(evaluatorType);
IdmMonitoringDto monitoring = monitoringService.find(filter, null).stream().filter(m -> {
return syncConfig.getId().equals(m.getEvaluatorProperties().get(SynchronizationMonitoringEvaluator.PARAMETER_SYNCHRONIZATION));
}).findFirst().orElse(null);
Assert.assertNotNull(monitoring);
syncConfigService.delete(syncConfig);
monitoring = monitoringService.find(filter, null).stream().filter(m -> {
return syncConfig.getId().equals(m.getEvaluatorProperties().get(SynchronizationMonitoringEvaluator.PARAMETER_SYNCHRONIZATION));
}).findFirst().orElse(null);
Assert.assertNull(monitoring);
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringFilter in project CzechIdMng by bcvsolutions.
the class SyncConfigMonitoringAutoConfigurationProcessor method findMonitoring.
/**
* find already registered monitoring evaluator with synchronization identifier
*
* @return
*/
protected IdmMonitoringDto findMonitoring(UUID synchronizationId) {
String evaluatorType = AutowireHelper.getTargetType(synchronizationMonitoringEvaluator);
IdmMonitoringFilter filter = new IdmMonitoringFilter();
filter.setEvaluatorType(evaluatorType);
//
return monitoringService.find(filter, null).stream().filter(m -> {
// lookout - FE raw string properties can be given
return synchronizationId.equals(getParameterConverter().toUuid(m.getEvaluatorProperties(), SynchronizationMonitoringEvaluator.PARAMETER_SYNCHRONIZATION));
}).findFirst().orElse(null);
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringFilter 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.dto.filter.IdmMonitoringFilter in project CzechIdMng by bcvsolutions.
the class DefaultMonitoringManager method init.
/**
* Init last result cache, when instance is started
*/
@Override
public void init() {
String instanceId = configurationService.getInstanceId();
int counter = 0;
//
IdmMonitoringFilter filter = new IdmMonitoringFilter();
filter.setDisabled(Boolean.FALSE);
filter.setInstanceId(instanceId);
for (IdmMonitoringDto monitoring : monitoringService.find(filter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmMonitoring_.seq.getName())))) {
if (getLastResult(monitoring.getId()) != null) {
counter++;
}
}
//
LOG.info("Last monitoring results [{}] on instance [{}] loaded into cache.", counter, instanceId);
}
Aggregations