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