Search in sources :

Example 1 with IdmNotificationConfiguration

use of eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration in project CzechIdMng by bcvsolutions.

the class DefaultIdmNotificationConfigurationService method save.

@Override
@Transactional
public NotificationConfigurationDto save(NotificationConfigurationDto dto, BasePermission... permission) {
    Assert.notNull(dto);
    // 
    // check duplicity
    IdmNotificationConfiguration duplicitEntity = repository.findByTopicAndLevelAndNotificationType(dto.getTopic(), dto.getLevel(), dto.getNotificationType());
    if (duplicitEntity != null && !duplicitEntity.getId().equals(dto.getId())) {
        throw new ResultCodeException(CoreResultCode.NOTIFICATION_TOPIC_AND_LEVEL_EXISTS, ImmutableMap.of("topic", dto.getTopic()));
    }
    return super.save(dto);
}
Also used : IdmNotificationConfiguration(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with IdmNotificationConfiguration

use of eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration in project CzechIdMng by bcvsolutions.

the class DefaultNotificationServiceIntegrationTest method testSendRedirectNotificationWithEmptyRecipients.

@Test(expected = ResultCodeException.class)
public void testSendRedirectNotificationWithEmptyRecipients() {
    IdmNotificationConfiguration config = new IdmNotificationConfiguration();
    config.setTopic(getHelper().createName());
    config.setNotificationType(IdmConsoleLog.NOTIFICATION_TYPE);
    config.setRedirect(true);
    config = notificationConfigurationRepository.save(config);
    // 
    notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setLevel(NotificationLevel.SUCCESS).setMessage("message").setSubject("subject").build(), getHelper().createIdentity((GuardedString) null));
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationConfiguration(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with IdmNotificationConfiguration

use of eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration 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)

Example 4 with IdmNotificationConfiguration

use of eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration in project CzechIdMng by bcvsolutions.

the class DefaultIdmNotificationConfigurationService method saveInternal.

@Override
@Transactional
public NotificationConfigurationDto saveInternal(NotificationConfigurationDto dto) {
    Assert.notNull(dto, "DTO is required.");
    // 
    // check duplicity
    IdmNotificationConfiguration duplicitEntity = repository.findByTopicAndLevelAndNotificationType(dto.getTopic(), dto.getLevel(), dto.getNotificationType());
    if (duplicitEntity != null && !duplicitEntity.getId().equals(dto.getId())) {
        throw new ResultCodeException(CoreResultCode.NOTIFICATION_TOPIC_AND_LEVEL_EXISTS, ImmutableMap.of("topic", dto.getTopic()));
    }
    // check recipient is filled when redirect is enabled
    if (dto.isRedirect()) {
        if (getRecipients(dto).isEmpty()) {
            // redirect and no recipient is configured => exception
            throw new ResultCodeException(CoreResultCode.NOTIFICATION_CONFIGURATION_RECIPIENT_NOT_FOUND, ImmutableMap.of("topic", dto.getTopic()));
        }
    }
    // 
    return super.saveInternal(dto);
}
Also used : IdmNotificationConfiguration(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmNotificationConfiguration (eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration)4 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 Transactional (org.springframework.transaction.annotation.Transactional)2 DefaultAttachmentManagerIntegrationTest (eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest)1 NotificationLevel (eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)1 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)1 NotificationSender (eu.bcvsolutions.idm.core.notification.api.service.NotificationSender)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1