From dc4d683aa0e90f5af98941ba1b53cba5f8bec730 Mon Sep 17 00:00:00 2001 From: Richard Ogin Date: Thu, 18 Jul 2024 17:03:55 -0500 Subject: [PATCH] #6261 add serverName and environmentName to the alert template variables list --- .../ui/alert/DefaultAlertEditPanel.java | 2 ++ .../com/mirth/connect/server/alert/Alert.java | 25 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/client/src/com/mirth/connect/client/ui/alert/DefaultAlertEditPanel.java b/client/src/com/mirth/connect/client/ui/alert/DefaultAlertEditPanel.java index 0768a74ba..e45635369 100644 --- a/client/src/com/mirth/connect/client/ui/alert/DefaultAlertEditPanel.java +++ b/client/src/com/mirth/connect/client/ui/alert/DefaultAlertEditPanel.java @@ -106,6 +106,8 @@ public void updateVariableList() { variables.add("alertId"); variables.add("alertName"); variables.add("serverId"); + variables.add("serverName"); + variables.add("environmentName"); variables.add("globalMapVariable"); variables.add("date"); diff --git a/core-server-plugins/src/com/mirth/connect/server/alert/Alert.java b/core-server-plugins/src/com/mirth/connect/server/alert/Alert.java index 1aeaca5e1..2e237c427 100644 --- a/core-server-plugins/src/com/mirth/connect/server/alert/Alert.java +++ b/core-server-plugins/src/com/mirth/connect/server/alert/Alert.java @@ -9,19 +9,27 @@ package com.mirth.connect.server.alert; +import static java.util.Map.entry; + import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.velocity.tools.generic.DateTool; +import com.mirth.connect.client.core.ControllerException; +import com.mirth.connect.model.ServerSettings; import com.mirth.connect.model.alert.AlertModel; import com.mirth.connect.server.controllers.ConfigurationController; public class Alert { + private Logger logger = LogManager.getLogger(this.getClass()); public static Class USER_PROTOCOL_CLASS; - + private AlertModel model; private Long enabledDateTime; private Long enabledNanoTime; @@ -58,11 +66,26 @@ public Map createContext() { context.put("alertId", model.getId()); context.put("alertName", model.getName()); context.put("serverId", ConfigurationController.getInstance().getServerId()); + context.putAll(getServerSettings()); context.put("date", new DateTool()); return context; } + private Map getServerSettings() { + try { + ServerSettings settings = ConfigurationController.getInstance().getServerSettings(); + // ensure an empty string as Velocity won't replace when given a null value + return Map.ofEntries( + entry("serverName", StringUtils.defaultString(settings.getServerName())), + entry("environmentName", StringUtils.defaultString(settings.getEnvironmentName()))); + } catch (ControllerException e) { + logger.warn("Failed to retrieve server settings", e); + } + + return Map.of(); + } + public int getAlertedCount() { return alertedCount.get(); }