use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto 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.IdmNotificationRecipientDto in project CzechIdMng by bcvsolutions.
the class DefaultEmailNotificationSender method send.
@Override
@Transactional
public IdmEmailLogDto send(IdmMessageDto message, String[] emails) {
Assert.notNull(message);
Assert.notNull(emails);
//
IdmEmailLogDto emailLog = new IdmEmailLogDto();
// there is no parent
// build message, without password
emailLog.setMessage(notificationTemplateService.buildMessage(message, false));
//
for (String email : emails) {
// fill email to recipientDto
emailLog.getRecipients().add(new IdmNotificationRecipientDto(email));
}
emailLog = this.emailLogService.save(emailLog);
//
producerTemplate.sendBody("direct:emails", emailLog);
//
return emailLog;
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto in project CzechIdMng by bcvsolutions.
the class DefaultWebsocketNotificationSender method send.
@Override
@Transactional
public IdmWebsocketLogDto send(IdmNotificationDto notification) {
Assert.notNull(notification, "Notification is required!");
//
LOG.info("Adding websocket notification to queue [{}]", notification);
IdmWebsocketLogDto log = createLog(notification);
// send flashmessage
FlashMessage message = toFlashMessage(log);
for (IdmNotificationRecipientDto recipient : log.getRecipients()) {
if (Strings.isNullOrEmpty(recipient.getRealRecipient())) {
LOG.warn("Real recipient is empty for notification [{}]", notification);
} else {
websocket.convertAndSendToUser(recipient.getRealRecipient(), // TODO: configurable
"/queue/messages", message);
}
}
return log;
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto 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;
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto in project CzechIdMng by bcvsolutions.
the class CustomMailActivityBehavior method prepareRecipient.
private IdmNotificationRecipientDto prepareRecipient(String identityOrAddress) {
Assert.hasText(identityOrAddress);
//
IdmIdentityDto identity = getIdentity(identityOrAddress);
if (identity != null) {
return new IdmNotificationRecipientDto(identity.getId());
}
return new IdmNotificationRecipientDto(identityOrAddress);
}
Aggregations