Search in sources :

Example 1 with NotificationConfigurationDto

use of eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmNotificationConfigurationService method initDefaultTopics.

/**
 * Inits default notification configuration from all module descriptors.
 */
@Override
@Transactional
public void initDefaultTopics() {
    moduleService.getInstalledModules().forEach(module -> {
        Set<String> topicToCreate = new HashSet<>();
        module.getDefaultNotificationConfigurations().forEach(config -> {
            String topic = config.getTopic();
            Long count = repository.countByTopic(topic);
            if (topicToCreate.contains(topic) || count == 0) {
                topicToCreate.add(topic);
                UUID template = config.getTemplate();
                NotificationConfigurationDto notConfiguration = new NotificationConfigurationDto(config);
                notConfiguration.setTemplate(template);
                repository.save(toEntity(notConfiguration, null));
            }
        });
    });
}
Also used : NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) UUID(java.util.UUID) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with NotificationConfigurationDto

use of eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto in project CzechIdMng by bcvsolutions.

the class ExampleModuleDescriptor method getDefaultNotificationConfigurations.

@Override
public List<NotificationConfigurationDto> getDefaultNotificationConfigurations() {
    List<NotificationConfigurationDto> configs = new ArrayList<>();
    configs.add(new NotificationConfigurationDto(TOPIC_EXAMPLE, null, IdmWebsocketLog.NOTIFICATION_TYPE, "Example notification", null));
    return configs;
}
Also used : NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) ArrayList(java.util.ArrayList)

Example 3 with NotificationConfigurationDto

use of eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto in project CzechIdMng by bcvsolutions.

the class DefaultNotificationServiceIntegrationTest method sendWildCardsWithTemplateAndOwnText.

@Test
public void sendWildCardsWithTemplateAndOwnText() {
    String topic = "testTopic-" + System.currentTimeMillis();
    String textMessage = "testMessageText-" + System.currentTimeMillis();
    String textTemplate = "testMessageTemplate-" + System.currentTimeMillis();
    // 
    IdmNotificationTemplateDto template = new IdmNotificationTemplateDto();
    template.setName(textTemplate);
    template.setCode(textTemplate);
    template.setBodyHtml(textTemplate);
    template.setBodyText(textTemplate);
    template.setSubject(textTemplate);
    template = notificationTemplateService.save(template);
    // 
    IdmIdentityDto identity = helper.createIdentity();
    // create config, for email, topic, template and without level = wildcard
    NotificationConfigurationDto config = new NotificationConfigurationDto();
    // topic
    config.setTopic(topic);
    // template
    config.setTemplate(template.getId());
    // email
    config.setNotificationType(IdmEmailLog.NOTIFICATION_TYPE);
    config = notificationConfigurationService.save(config);
    // 
    // set all text into message
    List<IdmNotificationLogDto> notifications = notificationManager.send(topic, new IdmMessageDto.Builder().setLevel(// set level
    NotificationLevel.SUCCESS).setHtmlMessage(textMessage).setTextMessage(textMessage).setSubject(textMessage).build(), identity);
    // 
    assertEquals(1, notifications.size());
    // 
    IdmNotificationLogDto notification = notifications.get(0);
    // topic has own template, but in message is set text
    assertEquals(textMessage, notification.getMessage().getHtmlMessage());
    assertEquals(textMessage, notification.getMessage().getSubject());
    assertEquals(textMessage, notification.getMessage().getTextMessage());
}
Also used : NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) 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)

Example 4 with NotificationConfigurationDto

use of eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto in project CzechIdMng by bcvsolutions.

the class DefaultNotificationServiceIntegrationTest method sendWildCardsWithoutTemplate.

@Test
public void sendWildCardsWithoutTemplate() {
    String topic = "testTopic-" + System.currentTimeMillis();
    String text = "testMessageText-" + System.currentTimeMillis();
    // 
    IdmIdentityDto identity = helper.createIdentity();
    // create config, for email, topic and without level = wildcard
    NotificationConfigurationDto config = new NotificationConfigurationDto();
    // topic
    config.setTopic(topic);
    // email
    config.setNotificationType(IdmEmailLog.NOTIFICATION_TYPE);
    config = notificationConfigurationService.save(config);
    // 
    // set all text into message
    List<IdmNotificationLogDto> notifications = notificationManager.send(topic, new IdmMessageDto.Builder().setLevel(// set level
    NotificationLevel.SUCCESS).setHtmlMessage(text).setTextMessage(text).setSubject(text).build(), identity);
    // 
    assertEquals(1, notifications.size());
    // 
    IdmNotificationLogDto notification = notifications.get(0);
    assertEquals(text, notification.getMessage().getHtmlMessage());
    assertEquals(text, notification.getMessage().getSubject());
    assertEquals(text, notification.getMessage().getTextMessage());
}
Also used : NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 5 with NotificationConfigurationDto

use of eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto in project CzechIdMng by bcvsolutions.

the class DefaultNotificationServiceIntegrationTest method sendNofificationToConsoleIfTopicNotFound.

@Test
public void sendNofificationToConsoleIfTopicNotFound() {
    String topic = helper.createName();
    // create config, for email, topic, template and without level = wildcard
    NotificationConfigurationDto config = new NotificationConfigurationDto();
    // topic
    config.setTopic(topic);
    config.setLevel(NotificationLevel.INFO);
    // email
    config.setNotificationType(IdmEmailLog.NOTIFICATION_TYPE);
    config = notificationConfigurationService.save(config);
    // 
    IdmIdentityDto identity = helper.createIdentity();
    List<IdmNotificationLogDto> notifications = notificationManager.send(topic, new IdmMessageDto.Builder().setLevel(// set level
    NotificationLevel.SUCCESS).setMessage("message").setSubject("subject").build(), identity);
    // 
    assertEquals(1, notifications.size());
    // 
    // console channel is expected, because topic configuration is wrong
    IdmNotificationLogDto notification = notifications.get(0);
    // 
    Assert.assertEquals(IdmConsoleLog.NOTIFICATION_TYPE, notification.getType());
}
Also used : NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

NotificationConfigurationDto (eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto)19 Test (org.junit.Test)11 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)10 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)7 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)6 IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)5 ArrayList (java.util.ArrayList)5 IdmNotificationConfigurationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationConfigurationFilter)4 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)3 EmailModel (com.nilhcem.fakesmtp.model.EmailModel)1 AbstractNotificationTest (eu.bcvsolutions.idm.test.api.AbstractNotificationTest)1 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 Before (org.junit.Before)1 Transactional (org.springframework.transaction.annotation.Transactional)1