Ignore unconfigured delivery method for system notification type

This commit is contained in:
ViacheslavKlimov 2024-12-30 16:15:37 +02:00
parent cf9204416b
commit f02b25f15a

View File

@ -122,6 +122,7 @@ public class DefaultNotificationCenter extends AbstractSubscriptionService imple
if (notificationTemplate == null) { if (notificationTemplate == null) {
throw new IllegalArgumentException("Template is missing"); throw new IllegalArgumentException("Template is missing");
} }
NotificationType notificationType = notificationTemplate.getNotificationType();
Set<NotificationDeliveryMethod> deliveryMethods = new HashSet<>(); Set<NotificationDeliveryMethod> deliveryMethods = new HashSet<>();
List<NotificationTarget> targets = new ArrayList<>(); List<NotificationTarget> targets = new ArrayList<>();
@ -143,13 +144,13 @@ public class DefaultNotificationCenter extends AbstractSubscriptionService imple
try { try {
channels.get(deliveryMethod).check(tenantId); channels.get(deliveryMethod).check(tenantId);
} catch (Exception e) { } catch (Exception e) {
if (ruleId == null) { if (ruleId == null && !notificationType.isSystem()) {
throw new IllegalArgumentException(e.getMessage()); throw new IllegalArgumentException(e.getMessage());
} else { } else {
return; // if originated by rule - just ignore delivery method return; // if originated by rule or notification type is system - just ignore delivery method
} }
} }
if (ruleId == null && !notificationTemplate.getNotificationType().isSystem()) { if (ruleId == null && !notificationType.isSystem()) {
if (targets.stream().noneMatch(target -> target.getConfiguration().getType().getSupportedDeliveryMethods().contains(deliveryMethod))) { if (targets.stream().noneMatch(target -> target.getConfiguration().getType().getSupportedDeliveryMethods().contains(deliveryMethod))) {
throw new IllegalArgumentException("Recipients for " + deliveryMethod.getName() + " delivery method not chosen"); throw new IllegalArgumentException("Recipients for " + deliveryMethod.getName() + " delivery method not chosen");
} }