use of eu.bcvsolutions.idm.core.notification.api.dto.IdmWebsocketLogDto 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.IdmWebsocketLogDto in project CzechIdMng by bcvsolutions.
the class DefaultWebsocketNotificationSender method createLog.
/**
* Persists new websocket record from given notification
*
* @param notification
* @return
*/
private IdmWebsocketLogDto createLog(IdmNotificationDto notification) {
Assert.notNull(notification);
Assert.notNull(notification.getMessage());
// we can only create log, if notification is instance of IdmNotificationLog
if (notification instanceof IdmWebsocketLogDto) {
notification.setSent(new DateTime());
return websocketLogService.save((IdmWebsocketLogDto) notification);
}
//
IdmWebsocketLogDto log = new IdmWebsocketLogDto();
log.setSent(new DateTime());
log.setTopic(notification.getTopic());
// parent message
if (notification.getId() != null) {
log.setParent(notification.getId());
}
// clone message
log.setMessage(cloneMessage(notification));
// clone recipients - resolve real email
notification.getRecipients().forEach(recipient -> {
log.getRecipients().add(cloneRecipient(log, recipient));
});
log.setIdentitySender(notification.getIdentitySender());
log.setType(IdmWebsocketLog.NOTIFICATION_TYPE);
return websocketLogService.save(log);
}
Aggregations