Search in sources :

Example 1 with IdmMonitoringFilter

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())));
}
Also used : IdmMonitoringFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringFilter) MockMvcRequestBuilders.put(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put) IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) IdmMonitoringService(eu.bcvsolutions.idm.core.monitoring.api.service.IdmMonitoringService) H2DatabaseMonitoringEvaluator(eu.bcvsolutions.idm.core.monitoring.service.impl.H2DatabaseMonitoringEvaluator) Autowired(org.springframework.beans.factory.annotation.Autowired) DemoAdminMonitoringEvaluator(eu.bcvsolutions.idm.core.monitoring.service.impl.DemoAdminMonitoringEvaluator) Test(org.junit.Test) UUID(java.util.UUID) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) TestMonitoringEvaluator(eu.bcvsolutions.idm.core.monitoring.service.impl.TestMonitoringEvaluator) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) List(java.util.List) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) IdmMonitoringFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringFilter) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) Assert(org.junit.Assert) DemoAdminMonitoringEvaluator(eu.bcvsolutions.idm.core.monitoring.service.impl.DemoAdminMonitoringEvaluator) IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) TestMonitoringEvaluator(eu.bcvsolutions.idm.core.monitoring.service.impl.TestMonitoringEvaluator) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 2 with IdmMonitoringFilter

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);
}
Also used : IdmMonitoringFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringFilter) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) IdmMonitoringService(eu.bcvsolutions.idm.core.monitoring.api.service.IdmMonitoringService) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SynchronizationMonitoringEvaluator(eu.bcvsolutions.idm.acc.monitoring.SynchronizationMonitoringEvaluator) SysSyncIdentityConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) List(java.util.List) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) IdmMonitoringFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) SysSyncConfigService(eu.bcvsolutions.idm.acc.service.api.SysSyncConfigService) TestHelper(eu.bcvsolutions.idm.acc.TestHelper) Assert(org.junit.Assert) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncIdentityConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 3 with IdmMonitoringFilter

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);
}
Also used : IdmMonitoringFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringFilter)

Example 4 with IdmMonitoringFilter

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());
}
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 5 with IdmMonitoringFilter

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);
}
Also used : IdmMonitoringFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringFilter) IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto)

Aggregations

IdmMonitoringFilter (eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringFilter)9 IdmMonitoringDto (eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto)5 AutowireHelper (eu.bcvsolutions.idm.core.api.utils.AutowireHelper)2 IdmMonitoringResultDto (eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)2 IdmMonitoringService (eu.bcvsolutions.idm.core.monitoring.api.service.IdmMonitoringService)2 List (java.util.List)2 UUID (java.util.UUID)2 Assert (org.junit.Assert)2 Test (org.junit.Test)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 TestHelper (eu.bcvsolutions.idm.acc.TestHelper)1 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)1 SysSyncIdentityConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto)1 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)1 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)1 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)1 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)1 SysSystemMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter)1 SynchronizationMonitoringEvaluator (eu.bcvsolutions.idm.acc.monitoring.SynchronizationMonitoringEvaluator)1 SysSyncConfigService (eu.bcvsolutions.idm.acc.service.api.SysSyncConfigService)1