Skip to content

add two vars to the alert template variable list #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import javax.swing.JLabel;
import javax.swing.JPanel;

import net.miginfocom.swing.MigLayout;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

Expand All @@ -35,6 +33,8 @@
import com.mirth.connect.model.alert.ChannelTrigger;
import com.mirth.connect.model.alert.DefaultTrigger;

import net.miginfocom.swing.MigLayout;

public class DefaultAlertEditPanel extends AlertEditPanel {

private Frame parent;
Expand Down Expand Up @@ -105,6 +105,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");

Expand Down
22 changes: 22 additions & 0 deletions server/src/com/mirth/connect/server/alert/Alert.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@

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());

private AlertModel model;
private Long enabledDateTime;
Expand Down Expand Up @@ -56,11 +64,25 @@ public Map<String, Object> 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<String, Object> 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();
}
Expand Down
Loading