Search in sources :

Example 1 with IdmNotificationLogDto

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

the class AbstractNotificationSender method send.

@Override
@Transactional
public List<N> send(String topic, IdmMessageDto message, IdmIdentityDto identitySender, List<IdmIdentityDto> recipients) {
    Assert.notNull(message, "Message is required");
    List<N> sendMessages = new ArrayList<>();
    // 
    List<IdmNotificationRecipientDto> notificationRecipients = new ArrayList<>();
    recipients.forEach(recipient -> {
        notificationRecipients.add(new IdmNotificationRecipientDto(recipient.getId()));
    });
    // 
    List<IdmNotificationLogDto> notifications = notificationTemplateService.prepareNotifications(topic, message);
    // 
    if (notifications.isEmpty()) {
        LOG.info("Notification for [topic:{}] not found. Any message will not be sent.", topic);
        // no notifications found
        return sendMessages;
    }
    // iterate over all prepared notifications, set recipients and send them
    for (IdmNotificationLogDto notification : notifications) {
        final IdmMessageDto notificationMessage = notification.getMessage();
        if (notificationMessage.getHtmlMessage() == null && notificationMessage.getSubject() == null && notificationMessage.getTextMessage() == null && notificationMessage.getModel() == null) {
            LOG.error("Notification has empty template and message. Message will not be sent! [topic:{}]", topic);
            continue;
        }
        notification.setRecipients(notificationRecipients);
        notification.setIdentitySender(identitySender == null ? null : identitySender.getId());
        // 
        sendMessages.add(send(notification));
    }
    return sendMessages;
}
Also used : IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) ArrayList(java.util.ArrayList) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with IdmNotificationLogDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto 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 3 with IdmNotificationLogDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto 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 4 with IdmNotificationLogDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto 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)

Example 5 with IdmNotificationLogDto

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

the class DefaultNotificationServiceIntegrationTest method sendWildCardsWithTemplateWithoutText.

@Test
public void sendWildCardsWithTemplateWithoutText() {
    String topic = "testTopic-" + 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);
    // 
    List<IdmNotificationLogDto> notifications = notificationManager.send(topic, new IdmMessageDto.Builder().setLevel(// set level
    NotificationLevel.SUCCESS).build(), identity);
    // 
    assertEquals(1, notifications.size());
    // 
    IdmNotificationLogDto notification = notifications.get(0);
    // topic has own template and in message isnt set text
    assertEquals(textTemplate, notification.getMessage().getHtmlMessage());
    assertEquals(textTemplate, notification.getMessage().getSubject());
    assertEquals(textTemplate, notification.getMessage().getTextMessage());
}
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) 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)

Aggregations

IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)107 Test (org.junit.Test)97 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)93 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)82 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)63 List (java.util.List)40 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)33 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)33 ZonedDateTime (java.time.ZonedDateTime)32 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)28 NotificationConfigurationDto (eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto)28 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)26 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)26 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)26 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)26 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)25 IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)25 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)23 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)20 UUID (java.util.UUID)18