Search in sources :

Example 1 with NotificationLevel

use of eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel in project CzechIdMng by bcvsolutions.

the class IdmNotificationConfigurationDisabledTest method testNotDisabledError.

@Test
@Transactional
public void testNotDisabledError() {
    assertEquals(0, idmNotificationRepository.count());
    NotificationLevel level = NotificationLevel.ERROR;
    IdmNotificationTemplateDto template = createTestTemplate("Idm test notification", "disabled test");
    IdmIdentityDto identity = getHelper().createIdentity("Test_disable_notifications" + System.currentTimeMillis());
    configs.add(createNotificationConfiguration(TOPIC, level, IdmConsoleLog.NOTIFICATION_TYPE, template.getId(), false));
    configs.add(createNotificationConfiguration(TOPIC, level, IdmEmailLog.NOTIFICATION_TYPE, template.getId(), false));
    IdmMessageDto message = new IdmMessageDto();
    message.setTemplate(template);
    message.setLevel(level);
    notificationManager.send(TOPIC, message, identity);
    IdmNotificationFilter filter = new IdmNotificationFilter();
    filter.setNotificationType(IdmNotificationLog.class);
    assertEquals(2, notificationLogService.find(filter, null).getTotalElements());
    deleteNotificationConfig();
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with NotificationLevel

use of eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel in project CzechIdMng by bcvsolutions.

the class IdmNotificationConfigurationDisabledTest method testDisabledErrorWebsocket.

@Test
@Transactional
public void testDisabledErrorWebsocket() {
    assertEquals(0, idmNotificationRepository.count());
    NotificationLevel level = NotificationLevel.ERROR;
    IdmNotificationTemplateDto template = createTestTemplate("Idm test notification", "disabled test");
    IdmIdentityDto identity = getHelper().createIdentity("Test_disable_notifications" + System.currentTimeMillis());
    configs.add(createNotificationConfiguration(TOPIC, level, IdmConsoleLog.NOTIFICATION_TYPE, template.getId(), true));
    IdmMessageDto message = new IdmMessageDto();
    message.setTemplate(template);
    message.setLevel(level);
    notificationManager.send(TOPIC, message, identity);
    IdmNotificationFilter filter = new IdmNotificationFilter();
    filter.setNotificationType(IdmNotificationLog.class);
    assertEquals(0, notificationLogService.find(filter, null).getTotalElements());
    deleteNotificationConfig();
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with NotificationLevel

use of eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel in project CzechIdMng by bcvsolutions.

the class IdmNotificationConfigurationDisabledTest method testNotDisabledErrorEmail.

@Test
@Transactional
public void testNotDisabledErrorEmail() {
    assertEquals(0, idmNotificationRepository.count());
    NotificationLevel level = NotificationLevel.ERROR;
    IdmNotificationTemplateDto template = createTestTemplate("Idm test notification", "disabled test");
    IdmIdentityDto identity = getHelper().createIdentity("Test_disable_notifications" + System.currentTimeMillis());
    configs.add(createNotificationConfiguration(TOPIC, level, IdmEmailLog.NOTIFICATION_TYPE, template.getId(), false));
    IdmMessageDto message = new IdmMessageDto();
    message.setTemplate(template);
    message.setLevel(level);
    notificationManager.send(TOPIC, message, identity);
    IdmNotificationFilter filter = new IdmNotificationFilter();
    filter.setNotificationType(IdmNotificationLog.class);
    assertEquals(1, notificationLogService.find(filter, null).getTotalElements());
    deleteNotificationConfig();
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with NotificationLevel

use of eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel 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 NotificationLevel

use of eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel in project CzechIdMng by bcvsolutions.

the class NotificationRestTest method createTestNotification.

IdmNotificationDto createTestNotification(NotificationLevel level, String subject, String message, String topic, IdmIdentityDto sender, IdmIdentityDto... recipients) {
    final IdmMessageDto msg = new IdmMessageDto();
    msg.setHtmlMessage(message);
    msg.setTextMessage(message);
    msg.setLevel(level);
    msg.setSubject(subject);
    // 
    final List<IdmNotificationRecipientDto> rec = Arrays.stream(recipients).map(r -> {
        final IdmNotificationRecipientDto res = new IdmNotificationRecipientDto();
        res.setIdentityRecipient(r.getId());
        res.setRealRecipient(r.getUsername());
        return res;
    }).collect(Collectors.toList());
    // 
    final IdmNotificationDto result = new IdmNotificationDto();
    result.setIdentitySender(sender.getId());
    result.setRecipients(rec);
    result.setTopic(topic);
    result.setMessage(msg);
    return result;
}
Also used : Arrays(java.util.Arrays) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmJwtAuthentication(eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Lists(com.google.common.collect.Lists) IdmAuthorityUtils(eu.bcvsolutions.idm.core.security.api.utils.IdmAuthorityUtils) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) InitTestDataProcessor(eu.bcvsolutions.idm.core.model.event.processor.module.InitTestDataProcessor) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) MediaTypes(org.springframework.hateoas.MediaTypes) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) StringWriter(java.io.StringWriter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) List(java.util.List) BaseDtoController(eu.bcvsolutions.idm.core.api.rest.BaseDtoController) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) Authentication(org.springframework.security.core.Authentication) Assert.assertEquals(org.junit.Assert.assertEquals) IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto)

Aggregations

NotificationLevel (eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)16 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)10 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)10 Test (org.junit.Test)10 IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)9 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)9 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)9 Transactional (org.springframework.transaction.annotation.Transactional)9 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 JsonParser (com.fasterxml.jackson.core.JsonParser)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 Lists (com.google.common.collect.Lists)1 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)1 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 BaseDtoController (eu.bcvsolutions.idm.core.api.rest.BaseDtoController)1 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)1 InitTestDataProcessor (eu.bcvsolutions.idm.core.model.event.processor.module.InitTestDataProcessor)1