Merge pull request #11469 from thingsboard/fix/notification-unknown-recipient
Ignore unknown notification recipient groups
This commit is contained in:
commit
f30cee2f12
@ -300,9 +300,15 @@ public class NotificationController extends BaseController {
|
|||||||
request.setOriginatorEntityId(user.getId());
|
request.setOriginatorEntityId(user.getId());
|
||||||
List<NotificationTarget> targets = request.getTargets().stream()
|
List<NotificationTarget> targets = request.getTargets().stream()
|
||||||
.map(NotificationTargetId::new)
|
.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()))
|
.sorted(Comparator.comparing(target -> target.getConfiguration().getType()))
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
|
|
||||||
NotificationRequestPreview preview = new NotificationRequestPreview();
|
NotificationRequestPreview preview = new NotificationRequestPreview();
|
||||||
|
|
||||||
|
|||||||
@ -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.NotificationRequestUpdate;
|
||||||
import org.thingsboard.server.service.ws.notification.sub.NotificationUpdate;
|
import org.thingsboard.server.service.ws.notification.sub.NotificationUpdate;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -115,12 +116,23 @@ public class DefaultNotificationCenter extends AbstractSubscriptionService imple
|
|||||||
} else {
|
} else {
|
||||||
notificationTemplate = request.getTemplate();
|
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<>();
|
Set<NotificationDeliveryMethod> deliveryMethods = new HashSet<>();
|
||||||
List<NotificationTarget> targets = request.getTargets().stream().map(NotificationTargetId::new)
|
List<NotificationTarget> targets = new ArrayList<>();
|
||||||
.map(id -> notificationTargetService.findNotificationTargetById(tenantId, id))
|
for (UUID targetId : request.getTargets()) {
|
||||||
.collect(Collectors.toList());
|
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();
|
NotificationRuleId ruleId = request.getRuleId();
|
||||||
notificationTemplate.getConfiguration().getDeliveryMethodsTemplates().forEach((deliveryMethod, template) -> {
|
notificationTemplate.getConfiguration().getDeliveryMethodsTemplates().forEach((deliveryMethod, template) -> {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user