Search in sources :

Example 16 with NotificationLevel

use of eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel in project CzechIdMng by bcvsolutions.

the class DefaultIdmNotificationConfigurationService method getSenders.

@Override
public List<NotificationSender<?>> getSenders(BaseNotification notification) {
    Assert.notNull(notification, "Notification is required.");
    Assert.notNull(notification.getMessage(), "Message is required.");
    // 
    // default senders for unknown topics
    NotificationLevel level = notification.getMessage().getLevel();
    String topic = notification.getTopic();
    if (StringUtils.isEmpty(notification.getTopic())) {
        return getDefaultSenders();
    }
    // if configuration for given topic is found, but is disabled,
    // then default senders are not used => noticication is disabled and not be sent.
    boolean disabled = false;
    // 
    List<NotificationSender<?>> senders = new ArrayList<>();
    if (!IdmNotificationLog.NOTIFICATION_TYPE.equals(notification.getType())) {
        // concrete sender - configuration was resolved before, check for disabled is not needed now
        NotificationSender<?> sender = getSender(notification.getType());
        if (sender != null) {
            senders.add(sender);
        }
    } else {
        // notification - find all senders by topic and level by configuration
        // check configuration is enabled
        List<IdmNotificationConfiguration> configs = repository.findAllByTopicAndWildcardLevel(topic, level);
        // 
        for (IdmNotificationConfiguration config : configs) {
            if (config.isDisabled()) {
                disabled = true;
                LOG.debug("Configuration for topic [{}], level [{}], type [{}] is disabled. " + "Notification will not be sent by this configuration", topic, level, config.getNotificationType());
            } else {
                NotificationSender<?> sender = getSender(config.getNotificationType());
                if (sender != null) {
                    senders.add(sender);
                }
            }
        }
    }
    // 
    if (senders.isEmpty()) {
        if (disabled) {
            LOG.info("All configurations for topic [{}], level [{}] are disabled. " + "Notification will not be sent.", topic, level);
        } else {
            // configuration not found - return default senders
            return getDefaultSenders();
        }
    }
    return senders;
}
Also used : NotificationSender(eu.bcvsolutions.idm.core.notification.api.service.NotificationSender) ArrayList(java.util.ArrayList) IdmNotificationConfiguration(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)

Aggregations

NotificationLevel (eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)16 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)10 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)10 Test (org.junit.Test)10 IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)9 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)9 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)9 Transactional (org.springframework.transaction.annotation.Transactional)9 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 JsonParser (com.fasterxml.jackson.core.JsonParser)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 Lists (com.google.common.collect.Lists)1 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)1 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 BaseDtoController (eu.bcvsolutions.idm.core.api.rest.BaseDtoController)1 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)1 InitTestDataProcessor (eu.bcvsolutions.idm.core.model.event.processor.module.InitTestDataProcessor)1