Search in sources :

Example 1 with IdmNotificationRecipientDto

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;
}
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 IdmNotificationRecipientDto

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

Example 3 with IdmNotificationRecipientDto

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;
}
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 4 with IdmNotificationRecipientDto

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;
}
Also used : Arrays(java.util.Arrays) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmJwtAuthentication(eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Lists(com.google.common.collect.Lists) IdmAuthorityUtils(eu.bcvsolutions.idm.core.security.api.utils.IdmAuthorityUtils) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) InitTestData(eu.bcvsolutions.idm.InitTestData) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) MediaTypes(org.springframework.hateoas.MediaTypes) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) StringWriter(java.io.StringWriter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) List(java.util.List) BaseDtoController(eu.bcvsolutions.idm.core.api.rest.BaseDtoController) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) Authentication(org.springframework.security.core.Authentication) Assert.assertEquals(org.junit.Assert.assertEquals) IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto)

Example 5 with IdmNotificationRecipientDto

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);
}
Also used : IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto)

Aggregations

IdmNotificationRecipientDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto)7 Transactional (org.springframework.transaction.annotation.Transactional)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)2 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)2 DateTime (org.joda.time.DateTime)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 Lists (com.google.common.collect.Lists)1 InitTestData (eu.bcvsolutions.idm.InitTestData)1 BaseDtoController (eu.bcvsolutions.idm.core.api.rest.BaseDtoController)1 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)1 NotificationLevel (eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)1 FlashMessage (eu.bcvsolutions.idm.core.notification.api.dto.FlashMessage)1 IdmConsoleLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmConsoleLogDto)1 IdmEmailLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto)1 IdmNotificationDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto)1 IdmWebsocketLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmWebsocketLogDto)1 IdmJwtAuthentication (eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication)1 IdmAuthorityUtils (eu.bcvsolutions.idm.core.security.api.utils.IdmAuthorityUtils)1