From 2ae23a6048463bddfd561d9785b6cf203457d3a7 Mon Sep 17 00:00:00 2001 From: vburlachenko Date: Thu, 2 Nov 2023 15:55:49 +0200 Subject: [PATCH] 1497 - Use odd.platform-base-url property instead of PLATFORM_HOST_URL environment variable for email notifications. --- .../notification/config/NotificationConfiguration.java | 2 ++ .../notification/sender/EmailNotificationSender.java | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/notification/config/NotificationConfiguration.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/notification/config/NotificationConfiguration.java index ec20438a8..c5351e22e 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/notification/config/NotificationConfiguration.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/notification/config/NotificationConfiguration.java @@ -98,6 +98,7 @@ public NotificationSender webhookNotificationSender( @ConditionalOnProperty(name = "notifications.receivers.email.sender") public NotificationSender emailNotificationSender( @Value("${notifications.receivers.email.notification.emails}") final String notificationEmails, + @Value("${odd.platform-base-url:http://localhost:8080}") final String platformHost, final freemarker.template.Configuration configuration, final HttpClient httpClient, final JavaMailSender mailSender @@ -109,6 +110,7 @@ public NotificationSender emailNotificationSender( return new EmailNotificationSender(httpClient, mailSender, configuration, + platformHost, List.of(notificationEmails.trim().split(","))); } diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/notification/sender/EmailNotificationSender.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/notification/sender/EmailNotificationSender.java index ee3d47ccd..1348e6b17 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/notification/sender/EmailNotificationSender.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/notification/sender/EmailNotificationSender.java @@ -22,14 +22,17 @@ public class EmailNotificationSender extends AbstractNotificationSender notificationsEmails; private final Configuration configuration; + private final String platformHost; public EmailNotificationSender(final HttpClient httpClient, final JavaMailSender mailSender, final Configuration configuration, + final String platformHost, final List notificationsEmails) { super(httpClient); this.emailSender = mailSender; this.configuration = configuration; + this.platformHost = platformHost; this.notificationsEmails = notificationsEmails; } @@ -60,10 +63,7 @@ public void send(final AlertNotificationMessage message) throws InterruptedExcep private String getEmailContent(final AlertNotificationMessage message) throws IOException, TemplateException { final StringWriter stringWriter = new StringWriter(); final Map model = new HashMap<>(); - final String host = StringUtils.isBlank(System.getenv("PLATFORM_HOST_URL")) - ? "http://localhost:8080" - : System.getenv("PLATFORM_HOST_URL"); - final String alertUrl = host + ALERT_PATH.replace("{dataEntityId}", + final String alertUrl = platformHost + ALERT_PATH.replace("{dataEntityId}", String.valueOf(message.getDataEntity().id())); model.put("dataEntityId", String.valueOf(message.getDataEntity().id()));