Browse Source

Merge pull request #11469 from thingsboard/fix/notification-unknown-recipient

Ignore unknown notification recipient groups
pull/11483/head
Viacheslav Klimov 2 years ago
committed by GitHub
parent
commit
f30cee2f12
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 10
      application/src/main/java/org/thingsboard/server/controller/NotificationController.java
  2. 20
      application/src/main/java/org/thingsboard/server/service/notification/DefaultNotificationCenter.java

10
application/src/main/java/org/thingsboard/server/controller/NotificationController.java

@ -300,9 +300,15 @@ public class NotificationController extends BaseController {
request.setOriginatorEntityId(user.getId());
List<NotificationTarget> targets = request.getTargets().stream()
.map(NotificationTargetId::new)
.map(targetId -> notificationTargetService.findNotificationTargetById(user.getTenantId(), targetId))
.map(targetId -> {
NotificationTarget target = notificationTargetService.findNotificationTargetById(user.getTenantId(), targetId);
if (target == null) {
throw new IllegalArgumentException("Notification target for id " + targetId + " not found");
}
return target;
})
.sorted(Comparator.comparing(target -> target.getConfiguration().getType()))
.collect(Collectors.toList());
.toList();
NotificationRequestPreview preview = new NotificationRequestPreview();

20
application/src/main/java/org/thingsboard/server/service/notification/DefaultNotificationCenter.java

@ -73,6 +73,7 @@ import org.thingsboard.server.service.telemetry.AbstractSubscriptionService;
import org.thingsboard.server.service.ws.notification.sub.NotificationRequestUpdate;
import org.thingsboard.server.service.ws.notification.sub.NotificationUpdate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@ -115,12 +116,23 @@ public class DefaultNotificationCenter extends AbstractSubscriptionService imple
} else {
notificationTemplate = request.getTemplate();
}
if (notificationTemplate == null) throw new IllegalArgumentException("Template is missing");
if (notificationTemplate == null) {
throw new IllegalArgumentException("Template is missing");
}
Set<NotificationDeliveryMethod> deliveryMethods = new HashSet<>();
List<NotificationTarget> targets = request.getTargets().stream().map(NotificationTargetId::new)
.map(id -> notificationTargetService.findNotificationTargetById(tenantId, id))
.collect(Collectors.toList());
List<NotificationTarget> targets = new ArrayList<>();
for (UUID targetId : request.getTargets()) {
NotificationTarget target = notificationTargetService.findNotificationTargetById(tenantId, new NotificationTargetId(targetId));
if (target != null) {
targets.add(target);
} else {
log.debug("Unknown notification target {} in request {}", targetId, request);
}
}
if (targets.isEmpty()) {
throw new IllegalArgumentException("No recipients chosen");
}
NotificationRuleId ruleId = request.getRuleId();
notificationTemplate.getConfiguration().getDeliveryMethodsTemplates().forEach((deliveryMethod, template) -> {

Loading…
Cancel
Save