|
1 | | -/* |
2 | | - * Copyright (c) Mirth Corporation. All rights reserved. |
3 | | - * |
4 | | - * http://www.mirthcorp.com |
5 | | - * |
6 | | - * The software in this package is published under the terms of the MPL license a copy of which has |
7 | | - * been included with this distribution in the LICENSE.txt file. |
8 | | - */ |
| 1 | +// SPDX-License-Identifier: MPL-2.0 |
| 2 | +// SPDX-FileCopyrightText: Mirth Corporation |
| 3 | +// SPDX-FileCopyrightText: 2025-2026 Open Integration Engine Contributors |
9 | 4 |
|
10 | 5 | package com.mirth.connect.server.alert; |
11 | 6 |
|
| 7 | +import static java.util.Map.entry; |
| 8 | + |
12 | 9 | import java.util.HashMap; |
| 10 | +import java.util.Objects; |
13 | 11 | import java.util.Map; |
14 | 12 | import java.util.concurrent.atomic.AtomicInteger; |
15 | 13 |
|
| 14 | +import org.apache.logging.log4j.LogManager; |
| 15 | +import org.apache.logging.log4j.Logger; |
16 | 16 | import org.apache.velocity.tools.generic.DateTool; |
17 | 17 |
|
| 18 | +import com.mirth.connect.client.core.ControllerException; |
| 19 | +import com.mirth.connect.model.ServerSettings; |
18 | 20 | import com.mirth.connect.model.alert.AlertModel; |
19 | 21 | import com.mirth.connect.server.controllers.ConfigurationController; |
20 | 22 |
|
21 | 23 | public class Alert { |
| 24 | + private static final Logger logger = LogManager.getLogger(Alert.class); |
22 | 25 |
|
23 | 26 | private AlertModel model; |
24 | 27 | private Long enabledDateTime; |
@@ -56,12 +59,25 @@ public Map<String, Object> createContext() { |
56 | 59 | context.put("alertId", model.getId()); |
57 | 60 | context.put("alertName", model.getName()); |
58 | 61 | context.put("serverId", ConfigurationController.getInstance().getServerId()); |
59 | | - context.put("serverName", ConfigurationController.getInstance().getServerName()); |
| 62 | + context.putAll(getServerSettings()); |
60 | 63 | context.put("date", new DateTool()); |
61 | 64 |
|
62 | 65 | return context; |
63 | 66 | } |
64 | 67 |
|
| 68 | + private Map<String, Object> getServerSettings() { |
| 69 | + try { |
| 70 | + ServerSettings settings = ConfigurationController.getInstance().getServerSettings(); |
| 71 | + // ensure an empty string as Velocity won't replace when given a null value |
| 72 | + return Map.ofEntries(entry("serverName", Objects.toString(settings.getServerName(), "")), |
| 73 | + entry("environmentName", Objects.toString(settings.getEnvironmentName(), ""))); |
| 74 | + } catch (ControllerException e) { |
| 75 | + logger.warn("Failed to retrieve server settings", e); |
| 76 | + } |
| 77 | + |
| 78 | + return Map.of(); |
| 79 | + } |
| 80 | + |
65 | 81 | public int getAlertedCount() { |
66 | 82 | return alertedCount.get(); |
67 | 83 | } |
|
0 commit comments