Search in sources :

Example 1 with IdmWebsocketLogDto

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;
}
Also used : IdmWebsocketLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmWebsocketLogDto) FlashMessage(eu.bcvsolutions.idm.core.notification.api.dto.FlashMessage) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with IdmWebsocketLogDto

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);
}
Also used : IdmWebsocketLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmWebsocketLogDto) DateTime(org.joda.time.DateTime)

Aggregations

IdmWebsocketLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmWebsocketLogDto)2 FlashMessage (eu.bcvsolutions.idm.core.notification.api.dto.FlashMessage)1 IdmNotificationRecipientDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto)1 DateTime (org.joda.time.DateTime)1 Transactional (org.springframework.transaction.annotation.Transactional)1