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