diff --git a/application/src/main/java/org/thingsboard/server/service/notification/NotificationProcessingContext.java b/application/src/main/java/org/thingsboard/server/service/notification/NotificationProcessingContext.java index 27a9cabe43..9782fb473f 100644 --- a/application/src/main/java/org/thingsboard/server/service/notification/NotificationProcessingContext.java +++ b/application/src/main/java/org/thingsboard/server/service/notification/NotificationProcessingContext.java @@ -18,7 +18,7 @@ package org.thingsboard.server.service.notification; import com.google.common.base.Strings; import lombok.Builder; import lombok.Getter; -import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.notification.NotificationDeliveryMethod; import org.thingsboard.server.common.data.notification.NotificationRequest; @@ -27,10 +27,8 @@ import org.thingsboard.server.common.data.notification.settings.NotificationDeli import org.thingsboard.server.common.data.notification.settings.NotificationSettings; import org.thingsboard.server.common.data.notification.targets.NotificationRecipient; import org.thingsboard.server.common.data.notification.template.DeliveryMethodNotificationTemplate; -import org.thingsboard.server.common.data.notification.template.HasSubject; import org.thingsboard.server.common.data.notification.template.NotificationTemplate; import org.thingsboard.server.common.data.notification.template.NotificationTemplateConfig; -import org.thingsboard.server.common.data.notification.template.WebDeliveryMethodNotificationTemplate; import org.thingsboard.server.common.data.util.TemplateUtils; import java.util.EnumMap; @@ -38,8 +36,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; -import static org.apache.commons.lang3.StringUtils.isNotEmpty; - @SuppressWarnings("unchecked") public class NotificationProcessingContext { @@ -86,12 +82,11 @@ public class NotificationProcessingContext { public T getProcessedTemplate(NotificationDeliveryMethod deliveryMethod, NotificationRecipient recipient) { T template = (T) templates.get(deliveryMethod); - Map additionalTemplateContext = null; if (recipient != null) { - additionalTemplateContext = createTemplateContextForRecipient(recipient); - } - if (MapUtils.isNotEmpty(additionalTemplateContext) && template.containsAny(additionalTemplateContext.keySet().toArray(String[]::new))) { - template = processTemplate(template, additionalTemplateContext); + Map additionalTemplateContext = createTemplateContextForRecipient(recipient); + if (template.getTemplatableValues().stream().anyMatch(value -> value.containsParams(additionalTemplateContext.keySet()))) { + template = processTemplate(template, additionalTemplateContext); + } } return template; } @@ -107,22 +102,13 @@ public class NotificationProcessingContext { if (templateContext.isEmpty()) return template; template = (T) template.copy(); - template.setBody(TemplateUtils.processTemplate(template.getBody(), templateContext)); - if (template instanceof HasSubject) { - String subject = ((HasSubject) template).getSubject(); - ((HasSubject) template).setSubject(TemplateUtils.processTemplate(subject, templateContext)); - } - if (template instanceof WebDeliveryMethodNotificationTemplate) { - WebDeliveryMethodNotificationTemplate webNotificationTemplate = (WebDeliveryMethodNotificationTemplate) template; - String buttonText = webNotificationTemplate.getButtonText(); - if (isNotEmpty(buttonText)) { - webNotificationTemplate.setButtonText(TemplateUtils.processTemplate(buttonText, templateContext)); + template.getTemplatableValues().forEach(templatableValue -> { + String value = templatableValue.get(); + if (StringUtils.isNotEmpty(value)) { + value = TemplateUtils.processTemplate(value, templateContext); + templatableValue.set(value); } - String buttonLink = webNotificationTemplate.getButtonLink(); - if (isNotEmpty(buttonLink)) { - webNotificationTemplate.setButtonLink(TemplateUtils.processTemplate(buttonLink, templateContext)); - } - } + }); return template; } diff --git a/application/src/main/java/org/thingsboard/server/service/notification/channels/MicrosoftTeamsNotificationChannel.java b/application/src/main/java/org/thingsboard/server/service/notification/channels/MicrosoftTeamsNotificationChannel.java index ceab93c888..c628bf11f6 100644 --- a/application/src/main/java/org/thingsboard/server/service/notification/channels/MicrosoftTeamsNotificationChannel.java +++ b/application/src/main/java/org/thingsboard/server/service/notification/channels/MicrosoftTeamsNotificationChannel.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.thingsboard.server.service.notification.channels; import com.fasterxml.jackson.annotation.JsonInclude; diff --git a/application/src/test/java/org/thingsboard/server/service/notification/NotificationApiTest.java b/application/src/test/java/org/thingsboard/server/service/notification/NotificationApiTest.java index be972b29c3..946c15a68d 100644 --- a/application/src/test/java/org/thingsboard/server/service/notification/NotificationApiTest.java +++ b/application/src/test/java/org/thingsboard/server/service/notification/NotificationApiTest.java @@ -23,9 +23,10 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.client.RestTemplate; -import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.rule.engine.api.NotificationCenter; import org.thingsboard.server.common.data.User; +import org.thingsboard.server.common.data.audit.ActionType; +import org.thingsboard.server.common.data.id.DeviceId; import org.thingsboard.server.common.data.id.NotificationTargetId; import org.thingsboard.server.common.data.notification.Notification; import org.thingsboard.server.common.data.notification.NotificationDeliveryMethod; @@ -36,7 +37,7 @@ import org.thingsboard.server.common.data.notification.NotificationRequestPrevie import org.thingsboard.server.common.data.notification.NotificationRequestStats; import org.thingsboard.server.common.data.notification.NotificationRequestStatus; import org.thingsboard.server.common.data.notification.NotificationType; -import org.thingsboard.server.common.data.notification.info.AlarmNotificationInfo; +import org.thingsboard.server.common.data.notification.info.EntityActionNotificationInfo; import org.thingsboard.server.common.data.notification.settings.NotificationSettings; import org.thingsboard.server.common.data.notification.settings.SlackNotificationDeliveryMethodConfig; import org.thingsboard.server.common.data.notification.targets.MicrosoftTeamsNotificationTargetConfig; @@ -66,20 +67,18 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; import java.util.concurrent.TimeUnit; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.in; import static org.assertj.core.api.InstanceOfAssertFactories.type; import static org.awaitility.Awaitility.await; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; @DaoSqlTest @Slf4j @@ -554,12 +553,13 @@ public class NotificationApiTest extends AbstractNotificationApiTest { var template = new MicrosoftTeamsDeliveryMethodNotificationTemplate(); template.setEnabled(true); - template.setSubject("This is subject"); - template.setBody("This is text"); + String templateParams = "${recipientTitle} - ${entityType}"; + template.setSubject("Subject: " + templateParams); + template.setBody("Body: " + templateParams); template.setThemeColor("ff0000"); var button = new MicrosoftTeamsDeliveryMethodNotificationTemplate.Button(); - button.setName("Go to ThingsBoard Cloud"); - button.setUri("https://thingsboard.cloud"); + button.setName("Button: " + templateParams); + button.setUri("https://" + templateParams); template.setButton(button); NotificationTemplate notificationTemplate = new NotificationTemplate(); notificationTemplate.setName("Notification to Teams"); @@ -576,23 +576,28 @@ public class NotificationApiTest extends AbstractNotificationApiTest { .originatorEntityId(tenantAdminUserId) .templateId(notificationTemplate.getId()) .targets(List.of(target.getUuidId())) + .info(EntityActionNotificationInfo.builder() + .entityId(new DeviceId(UUID.randomUUID())) // to test templatization + .actionType(ActionType.ADDED) + .userId(tenantAdminUserId.getId()) + .build()) .build(); NotificationRequestPreview preview = doPost("/api/notification/request/preview", notificationRequest, NotificationRequestPreview.class); - System.err.println(preview); assertThat(preview.getRecipientsCountByTarget().get(target.getName())).isEqualTo(1); assertThat(preview.getRecipientsPreview()).containsOnly(targetConfig.getChannelName()); var messageCaptor = ArgumentCaptor.forClass(MicrosoftTeamsNotificationChannel.Message.class); - doPost("/api/notification/request", notificationRequest, NotificationRequest.class); + notificationCenter.processNotificationRequest(tenantId, notificationRequest, null); verify(restTemplate, timeout(20000)).postForEntity(eq(webhookUrl), messageCaptor.capture(), any()); var message = messageCaptor.getValue(); + String expectedParams = "My channel - Device"; assertThat(message.getThemeColor()).isEqualTo(template.getThemeColor()); - assertThat(message.getSections().get(0).getActivityTitle()).isEqualTo(template.getSubject()); - assertThat(message.getSections().get(0).getActivitySubtitle()).isEqualTo(template.getBody()); - assertThat(message.getPotentialAction().get(0).getName()).isEqualTo(button.getName()); - assertThat(message.getPotentialAction().get(0).getTargets().get(0).getUri()).isEqualTo(button.getUri()); + assertThat(message.getSections().get(0).getActivityTitle()).isEqualTo("Subject: " + expectedParams); + assertThat(message.getSections().get(0).getActivitySubtitle()).isEqualTo("Body: " + expectedParams); + assertThat(message.getPotentialAction().get(0).getName()).isEqualTo("Button: " + expectedParams); + assertThat(message.getPotentialAction().get(0).getTargets().get(0).getUri()).isEqualTo("https://" + expectedParams); } private void checkFullNotificationsUpdate(UnreadNotificationsUpdate notificationsUpdate, String... expectedNotifications) { diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/MicrosoftTeamsNotificationTargetConfig.java b/common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/MicrosoftTeamsNotificationTargetConfig.java index 02e787c038..826f64bbd4 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/MicrosoftTeamsNotificationTargetConfig.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/MicrosoftTeamsNotificationTargetConfig.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.thingsboard.server.common.data.notification.targets; import lombok.Data; diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/DeliveryMethodNotificationTemplate.java b/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/DeliveryMethodNotificationTemplate.java index ecb7f2d2b6..30316ef33b 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/DeliveryMethodNotificationTemplate.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/DeliveryMethodNotificationTemplate.java @@ -22,10 +22,10 @@ import com.fasterxml.jackson.annotation.JsonSubTypes.Type; import com.fasterxml.jackson.annotation.JsonTypeInfo; import lombok.Data; import lombok.NoArgsConstructor; -import org.apache.commons.lang3.StringUtils; import org.thingsboard.server.common.data.notification.NotificationDeliveryMethod; import javax.validation.constraints.NotEmpty; +import java.util.List; @JsonIgnoreProperties(ignoreUnknown = true) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "method") @@ -33,7 +33,8 @@ import javax.validation.constraints.NotEmpty; @Type(name = "WEB", value = WebDeliveryMethodNotificationTemplate.class), @Type(name = "EMAIL", value = EmailDeliveryMethodNotificationTemplate.class), @Type(name = "SMS", value = SmsDeliveryMethodNotificationTemplate.class), - @Type(name = "SLACK", value = SlackDeliveryMethodNotificationTemplate.class) + @Type(name = "SLACK", value = SlackDeliveryMethodNotificationTemplate.class), + @Type(name = "MICROSOFT_TEAMS", value = MicrosoftTeamsDeliveryMethodNotificationTemplate.class) }) @Data @NoArgsConstructor @@ -41,7 +42,7 @@ public abstract class DeliveryMethodNotificationTemplate { private boolean enabled; @NotEmpty - private String body; + protected String body; public DeliveryMethodNotificationTemplate(DeliveryMethodNotificationTemplate other) { this.enabled = other.enabled; @@ -54,8 +55,7 @@ public abstract class DeliveryMethodNotificationTemplate { @JsonIgnore public abstract DeliveryMethodNotificationTemplate copy(); - public boolean containsAny(String... params) { - return StringUtils.containsAny(body, params); - } + @JsonIgnore + public abstract List getTemplatableValues(); } diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/EmailDeliveryMethodNotificationTemplate.java b/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/EmailDeliveryMethodNotificationTemplate.java index fe909a104e..4ac2e1fb17 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/EmailDeliveryMethodNotificationTemplate.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/EmailDeliveryMethodNotificationTemplate.java @@ -19,12 +19,12 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString; -import org.apache.commons.lang3.StringUtils; import org.thingsboard.server.common.data.notification.NotificationDeliveryMethod; import org.thingsboard.server.common.data.validation.Length; import org.thingsboard.server.common.data.validation.NoXss; import javax.validation.constraints.NotEmpty; +import java.util.List; @Data @NoArgsConstructor @@ -37,6 +37,11 @@ public class EmailDeliveryMethodNotificationTemplate extends DeliveryMethodNotif @NotEmpty private String subject; + private final List templatableValues = List.of( + TemplatableValue.of(this::getBody, this::setBody), + TemplatableValue.of(this::getSubject, this::setSubject) + ); + public EmailDeliveryMethodNotificationTemplate(EmailDeliveryMethodNotificationTemplate other) { super(other); this.subject = other.subject; @@ -52,9 +57,4 @@ public class EmailDeliveryMethodNotificationTemplate extends DeliveryMethodNotif return new EmailDeliveryMethodNotificationTemplate(this); } - @Override - public boolean containsAny(String... params) { - return super.containsAny(params) || StringUtils.containsAny(subject, params); - } - } diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/MicrosoftTeamsDeliveryMethodNotificationTemplate.java b/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/MicrosoftTeamsDeliveryMethodNotificationTemplate.java index 0dd75a86fe..c29849d83e 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/MicrosoftTeamsDeliveryMethodNotificationTemplate.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/MicrosoftTeamsDeliveryMethodNotificationTemplate.java @@ -1,15 +1,27 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.thingsboard.server.common.data.notification.template; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.Pair; import org.thingsboard.server.common.data.notification.NotificationDeliveryMethod; import java.util.List; -import java.util.function.Consumer; @Data @EqualsAndHashCode(callSuper = true) @@ -23,8 +35,22 @@ public class MicrosoftTeamsDeliveryMethodNotificationTemplate extends DeliveryMe private String customMessageCardJson; - public MicrosoftTeamsDeliveryMethodNotificationTemplate(DeliveryMethodNotificationTemplate other) { + private final List templatableValues = List.of( + TemplatableValue.of(this::getBody, this::setBody), + TemplatableValue.of(this::getSubject, this::setSubject), + TemplatableValue.of(() -> button != null ? button.getName() : null, + processed -> {if (button != null) button.setName(processed);}), + TemplatableValue.of(() -> button != null ? button.getUri() : null, + processed -> {if (button != null) button.setUri(processed);}), + TemplatableValue.of(this::getCustomMessageCardJson, this::setCustomMessageCardJson) + ); + + public MicrosoftTeamsDeliveryMethodNotificationTemplate(MicrosoftTeamsDeliveryMethodNotificationTemplate other) { super(other); + this.subject = other.subject; + this.themeColor = other.themeColor; + this.button = other.button != null ? new Button(other.button) : null; + this.customMessageCardJson = other.customMessageCardJson; } @Override @@ -37,21 +63,16 @@ public class MicrosoftTeamsDeliveryMethodNotificationTemplate extends DeliveryMe return new MicrosoftTeamsDeliveryMethodNotificationTemplate(this); } - @Override - public List getTemplatableValues() { - return List.of( - TemplatableValue.of(body, this::setBody), - TemplatableValue.of(subject, this::setSubject), - TemplatableValue.of(button, Button::getName, Button::setName), - TemplatableValue.of(button, Button::getUri, Button::setUri), - TemplatableValue.of(customMessageCardJson, this::setCustomMessageCardJson) - ); - } - @Data + @NoArgsConstructor public static class Button { private String name; private String uri; + + public Button(Button other) { + this.name = other.name; + this.uri = other.uri; + } } } diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/SlackDeliveryMethodNotificationTemplate.java b/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/SlackDeliveryMethodNotificationTemplate.java index 8457677308..6a3790feb6 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/SlackDeliveryMethodNotificationTemplate.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/SlackDeliveryMethodNotificationTemplate.java @@ -22,12 +22,18 @@ import lombok.ToString; import org.thingsboard.server.common.data.notification.NotificationDeliveryMethod; import org.thingsboard.server.common.data.validation.NoXss; +import java.util.List; + @Data @NoArgsConstructor @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class SlackDeliveryMethodNotificationTemplate extends DeliveryMethodNotificationTemplate { + private final List templatableValues = List.of( + TemplatableValue.of(this::getBody, this::setBody) + ); + public SlackDeliveryMethodNotificationTemplate(DeliveryMethodNotificationTemplate other) { super(other); } diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/SmsDeliveryMethodNotificationTemplate.java b/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/SmsDeliveryMethodNotificationTemplate.java index 7dc2e494f3..f4aab10e1e 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/SmsDeliveryMethodNotificationTemplate.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/SmsDeliveryMethodNotificationTemplate.java @@ -23,12 +23,18 @@ import org.thingsboard.server.common.data.notification.NotificationDeliveryMetho import org.thingsboard.server.common.data.validation.Length; import org.thingsboard.server.common.data.validation.NoXss; +import java.util.List; + @Data @NoArgsConstructor @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class SmsDeliveryMethodNotificationTemplate extends DeliveryMethodNotificationTemplate { + private final List templatableValues = List.of( + TemplatableValue.of(this::getBody, this::setBody) + ); + public SmsDeliveryMethodNotificationTemplate(SmsDeliveryMethodNotificationTemplate other) { super(other); } diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/TemplatableValue.java b/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/TemplatableValue.java new file mode 100644 index 0000000000..25dfeb643a --- /dev/null +++ b/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/TemplatableValue.java @@ -0,0 +1,46 @@ +/** + * Copyright © 2016-2023 The Thingsboard Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.thingsboard.server.common.data.notification.template; + +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.StringUtils; + +import java.util.Collection; +import java.util.function.Consumer; +import java.util.function.Supplier; + +@RequiredArgsConstructor +public class TemplatableValue { + private final Supplier getter; + private final Consumer setter; + + public static TemplatableValue of(Supplier getter, Consumer setter) { + return new TemplatableValue(getter, setter); + } + + public String get() { + return getter.get(); + } + + public void set(String processed) { + setter.accept(processed); + } + + public boolean containsParams(Collection params) { + return StringUtils.containsAny(get(), params.toArray(String[]::new)); + } + +} diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/WebDeliveryMethodNotificationTemplate.java b/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/WebDeliveryMethodNotificationTemplate.java index f26ed00568..f45371f716 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/WebDeliveryMethodNotificationTemplate.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/notification/template/WebDeliveryMethodNotificationTemplate.java @@ -23,12 +23,12 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString; -import org.apache.commons.lang3.StringUtils; import org.thingsboard.server.common.data.notification.NotificationDeliveryMethod; import org.thingsboard.server.common.data.validation.Length; import org.thingsboard.server.common.data.validation.NoXss; import javax.validation.constraints.NotEmpty; +import java.util.List; import java.util.Optional; @Data @@ -43,6 +43,13 @@ public class WebDeliveryMethodNotificationTemplate extends DeliveryMethodNotific private String subject; private JsonNode additionalConfig; + private final List templatableValues = List.of( + TemplatableValue.of(this::getBody, this::setBody), + TemplatableValue.of(this::getSubject, this::setSubject), + TemplatableValue.of(this::getButtonText, this::setButtonText), + TemplatableValue.of(this::getButtonLink, this::setButtonLink) + ); + public WebDeliveryMethodNotificationTemplate(WebDeliveryMethodNotificationTemplate other) { super(other); this.subject = other.subject; @@ -107,10 +114,4 @@ public class WebDeliveryMethodNotificationTemplate extends DeliveryMethodNotific return new WebDeliveryMethodNotificationTemplate(this); } - @Override - public boolean containsAny(String... params) { - return super.containsAny(params) || StringUtils.containsAny(subject, params) - || StringUtils.containsAny(getButtonText(), params) || StringUtils.containsAny(getButtonLink(), params); - } - }