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;
}
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());
}
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());
}
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());
}
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());
}
Aggregations