use of eu.bcvsolutions.idm.core.notification.api.service.NotificationSender in project CzechIdMng by bcvsolutions.
the class DefaultIdmNotificationConfigurationService method getSender.
@Override
public NotificationSender<?> getSender(String notificationType) {
if (!notificationSenders.hasPluginFor(notificationType)) {
return null;
}
//
// default plugin by ordered definition
NotificationSender<?> sender = notificationSenders.getPluginFor(notificationType);
String implName = sender.getConfigurationValue(ConfigurationService.PROPERTY_IMPLEMENTATION);
if (StringUtils.isBlank(implName)) {
// return default sender - configuration is empty
return sender;
}
//
try {
// returns bean by name from filter configuration
return (NotificationSender<?>) context.getBean(implName);
} catch (Exception ex) {
throw new ResultCodeException(CoreResultCode.NOTIFICATION_SENDER_IMPLEMENTATION_NOT_FOUND, ImmutableMap.of("implementation", implName, "notificationType", notificationType, "configurationProperty", sender.getConfigurationPropertyName(ConfigurationService.PROPERTY_IMPLEMENTATION)), ex);
}
}
use of eu.bcvsolutions.idm.core.notification.api.service.NotificationSender 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;
}
Aggregations