|
9 | 9 |
|
10 | 10 | package com.mirth.connect.server.alert; |
11 | 11 |
|
| 12 | +import static java.util.Map.entry; |
| 13 | + |
12 | 14 | import java.util.HashMap; |
13 | 15 | import java.util.Map; |
14 | 16 | import java.util.concurrent.atomic.AtomicInteger; |
15 | 17 |
|
| 18 | +import org.apache.commons.lang3.StringUtils; |
| 19 | +import org.apache.logging.log4j.LogManager; |
| 20 | +import org.apache.logging.log4j.Logger; |
16 | 21 | import org.apache.velocity.tools.generic.DateTool; |
17 | 22 |
|
| 23 | +import com.mirth.connect.client.core.ControllerException; |
| 24 | +import com.mirth.connect.model.ServerSettings; |
18 | 25 | import com.mirth.connect.model.alert.AlertModel; |
19 | 26 | import com.mirth.connect.server.controllers.ConfigurationController; |
20 | 27 |
|
21 | 28 | public class Alert { |
| 29 | + private Logger logger = LogManager.getLogger(this.getClass()); |
22 | 30 |
|
23 | 31 | private AlertModel model; |
24 | 32 | private Long enabledDateTime; |
@@ -56,11 +64,25 @@ public Map<String, Object> createContext() { |
56 | 64 | context.put("alertId", model.getId()); |
57 | 65 | context.put("alertName", model.getName()); |
58 | 66 | context.put("serverId", ConfigurationController.getInstance().getServerId()); |
| 67 | + context.putAll(getServerSettings()); |
59 | 68 | context.put("date", new DateTool()); |
60 | 69 |
|
61 | 70 | return context; |
62 | 71 | } |
63 | 72 |
|
| 73 | + private Map<String, Object> getServerSettings() { |
| 74 | + try { |
| 75 | + ServerSettings settings = ConfigurationController.getInstance().getServerSettings(); |
| 76 | + // ensure an empty string as Velocity won't replace when given a null value |
| 77 | + return Map.ofEntries(entry("serverName", StringUtils.defaultString(settings.getServerName())), |
| 78 | + entry("environmentName", StringUtils.defaultString(settings.getEnvironmentName()))); |
| 79 | + } catch (ControllerException e) { |
| 80 | + logger.warn("Failed to retrieve server settings", e); |
| 81 | + } |
| 82 | + |
| 83 | + return Map.of(); |
| 84 | + } |
| 85 | + |
64 | 86 | public int getAlertedCount() { |
65 | 87 | return alertedCount.get(); |
66 | 88 | } |
|
0 commit comments