Search in sources :

Example 21 with IdmMessageDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmNotificationTemplateService method prepareNotifications.

@Override
public List<IdmNotificationLogDto> prepareNotifications(String topic, IdmMessageDto message) {
    Assert.notNull(message);
    List<IdmNotificationLogDto> notifications = new ArrayList<>();
    // 
    // find all configuration by topic and level
    List<IdmNotificationConfiguration> configurations = notificationConfigurationRepository.findByTopicAndLevel(topic, message.getLevel());
    // if configurations is empty, found a wild card configuration
    if (configurations.isEmpty()) {
        configurations = notificationConfigurationRepository.findByTopicAndLevelIsNull(topic);
    }
    // if configurations still empty and exists final message send only his message, this message will be sent without type
    if (configurations.isEmpty()) {
        // this state is possible send message to topic that hasn't set any configurations
        IdmNotificationLogDto notification = new IdmNotificationLogDto();
        notification.setTopic(topic);
        notification.setMessage(this.buildMessage(message, false));
        notifications.add(notification);
        return notifications;
    }
    // html, text and subject is not empty use them
    for (IdmNotificationConfiguration configuration : configurations) {
        IdmMessageDto finalMessage = null;
        if (message.getTemplate() != null) {
            // exist template in message
            finalMessage = this.buildMessage(message, false);
        } else if (configuration.getTemplate() != null) {
            finalMessage = new IdmMessageDto(message);
            finalMessage.setTemplate(this.get(configuration.getTemplate()));
            finalMessage = this.buildMessage(finalMessage, false);
        } else {
            finalMessage = message;
        }
        if (!StringUtils.isEmpty(message.getSubject())) {
            finalMessage.setSubject(message.getSubject());
        }
        if (!StringUtils.isEmpty(message.getTextMessage())) {
            finalMessage.setTextMessage(message.getTextMessage());
        }
        if (!StringUtils.isEmpty(message.getHtmlMessage())) {
            finalMessage.setHtmlMessage(message.getHtmlMessage());
        }
        // 
        // send message for every found configuration
        IdmNotificationLogDto notification = new IdmNotificationLogDto();
        notification.setTopic(topic);
        notification.setType(configuration.getNotificationType());
        notification.setMessage(finalMessage);
        notifications.add(notification);
    }
    // 
    return notifications;
}
Also used : IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) ArrayList(java.util.ArrayList) IdmNotificationConfiguration(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration)

Example 22 with IdmMessageDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto in project CzechIdMng by bcvsolutions.

the class DefaultWebsocketNotificationSender method toFlashMessage.

private FlashMessage toFlashMessage(IdmWebsocketLogDto log) {
    IdmMessageDto message = this.getMessage(log, true);
    // 
    FlashMessage flashMessage = new FlashMessage();
    flashMessage.setId(log.getId());
    flashMessage.setKey(log.getTopic());
    flashMessage.setTitle(message.getSubject());
    // default message
    flashMessage.setMessage(message.getTextMessage());
    flashMessage.setDate(log.getCreated());
    flashMessage.setLevel(message.getLevel() == null ? null : message.getLevel().toString().toLowerCase());
    flashMessage.setModel(message.getModel());
    // TODO: other params
    flashMessage.setPosition("tr");
    return flashMessage;
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) FlashMessage(eu.bcvsolutions.idm.core.notification.api.dto.FlashMessage)

Aggregations

IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)22 Test (org.junit.Test)14 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)10 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)6 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)6 IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)6 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)5 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)5 IdmNotificationDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto)3 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)3 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 ArrayList (java.util.ArrayList)3 IdmNotificationRecipientDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto)2 StringWriter (java.io.StringWriter)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 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1