|
|
@ -47,6 +47,7 @@ import org.thingsboard.server.common.data.notification.targets.NotificationRecip |
|
|
import org.thingsboard.server.common.data.notification.targets.NotificationTarget; |
|
|
import org.thingsboard.server.common.data.notification.targets.NotificationTarget; |
|
|
import org.thingsboard.server.common.data.notification.targets.NotificationTargetType; |
|
|
import org.thingsboard.server.common.data.notification.targets.NotificationTargetType; |
|
|
import org.thingsboard.server.common.data.notification.targets.platform.PlatformUsersNotificationTargetConfig; |
|
|
import org.thingsboard.server.common.data.notification.targets.platform.PlatformUsersNotificationTargetConfig; |
|
|
|
|
|
import org.thingsboard.server.common.data.notification.targets.slack.SlackNotificationTargetConfig; |
|
|
import org.thingsboard.server.common.data.notification.template.DeliveryMethodNotificationTemplate; |
|
|
import org.thingsboard.server.common.data.notification.template.DeliveryMethodNotificationTemplate; |
|
|
import org.thingsboard.server.common.data.notification.template.NotificationTemplate; |
|
|
import org.thingsboard.server.common.data.notification.template.NotificationTemplate; |
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
@ -230,28 +231,34 @@ public class NotificationController extends BaseController { |
|
|
preview.setProcessedTemplates(processedTemplates); |
|
|
preview.setProcessedTemplates(processedTemplates); |
|
|
|
|
|
|
|
|
// generic permission
|
|
|
// generic permission
|
|
|
Set<User> recipientsPreview = new LinkedHashSet<>(); |
|
|
Set<String> recipientsPreview = new LinkedHashSet<>(); |
|
|
Map<String, Integer> recipientsCountByTarget = new HashMap<>(); |
|
|
Map<String, Integer> recipientsCountByTarget = new HashMap<>(); |
|
|
|
|
|
|
|
|
List<NotificationTarget> targets = notificationTargetService.findNotificationTargetsByTenantIdAndIds(user.getTenantId(), |
|
|
List<NotificationTarget> targets = notificationTargetService.findNotificationTargetsByTenantIdAndIds(user.getTenantId(), |
|
|
request.getTargets().stream().map(NotificationTargetId::new).collect(Collectors.toList())); |
|
|
request.getTargets().stream().map(NotificationTargetId::new).collect(Collectors.toList())); |
|
|
for (NotificationTarget target : targets) { |
|
|
for (NotificationTarget target : targets) { |
|
|
int recipientsCount; |
|
|
int recipientsCount; |
|
|
|
|
|
List<NotificationRecipient> recipientsPart; |
|
|
if (target.getConfiguration().getType() == NotificationTargetType.PLATFORM_USERS) { |
|
|
if (target.getConfiguration().getType() == NotificationTargetType.PLATFORM_USERS) { |
|
|
PageData<User> recipients = notificationTargetService.findRecipientsForNotificationTargetConfig(user.getTenantId(), |
|
|
PageData<User> recipients = notificationTargetService.findRecipientsForNotificationTargetConfig(user.getTenantId(), |
|
|
(PlatformUsersNotificationTargetConfig) target.getConfiguration(), new PageLink(recipientsPreviewSize)); |
|
|
(PlatformUsersNotificationTargetConfig) target.getConfiguration(), new PageLink(recipientsPreviewSize)); |
|
|
recipientsCount = (int) recipients.getTotalElements(); |
|
|
recipientsCount = (int) recipients.getTotalElements(); |
|
|
for (User recipient : recipients.getData()) { |
|
|
recipientsPart = recipients.getData().stream().map(r -> (NotificationRecipient) r).collect(Collectors.toList()); |
|
|
if (recipientsPreview.size() < recipientsPreviewSize) { |
|
|
|
|
|
recipientsPreview.add(recipient); |
|
|
|
|
|
} else { |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
recipientsCount = 1; |
|
|
recipientsCount = 1; |
|
|
|
|
|
recipientsPart = List.of(((SlackNotificationTargetConfig) target.getConfiguration()).getConversation()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (NotificationRecipient recipient : recipientsPart) { |
|
|
|
|
|
if (recipientsPreview.size() < recipientsPreviewSize) { |
|
|
|
|
|
recipientsPreview.add(recipient.getTitle()); |
|
|
|
|
|
} else { |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
recipientsCountByTarget.put(target.getName(), recipientsCount); |
|
|
recipientsCountByTarget.put(target.getName(), recipientsCount); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
preview.setRecipientsPreview(recipientsPreview); |
|
|
preview.setRecipientsPreview(recipientsPreview); |
|
|
preview.setRecipientsCountByTarget(recipientsCountByTarget); |
|
|
preview.setRecipientsCountByTarget(recipientsCountByTarget); |
|
|
preview.setTotalRecipientsCount(recipientsCountByTarget.values().stream().mapToInt(Integer::intValue).sum()); |
|
|
preview.setTotalRecipientsCount(recipientsCountByTarget.values().stream().mapToInt(Integer::intValue).sum()); |
|
|
|