Skip to content

Commit 08ac76c

Browse files
committed
Implemented a HashMap instead
1 parent 6a4a15a commit 08ac76c

File tree

4 files changed

+61
-112
lines changed

4 files changed

+61
-112
lines changed

client/src/com/mirth/connect/plugins/serverlog/ServerLogClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
package com.mirth.connect.plugins.serverlog;
1111

12-
import java.util.ArrayList;
13-
import java.util.LinkedList;
14-
import java.util.List;
12+
import java.util.*;
1513

1614
import javax.swing.JComponent;
1715

@@ -26,7 +24,9 @@
2624
public class ServerLogClient extends DashboardTabPlugin {
2725
private ServerLogPanel serverLogPanel;
2826
private LinkedList<ServerLogItem> serverLogs;
29-
private static final ServerLogItem unauthorizedLog = new ServerLogItem("You are not authorized to view the server log.");
27+
private static final ServerLogItem unauthorizedLog = new ServerLogItem(new HashMap<String, Object>(){{
28+
put("message", "You are not authorized to view the server log.");
29+
}});
3030
private int currentServerLogSize;
3131
private boolean receivedNewLogs;
3232
private Long lastLogId;

server/src/com/mirth/connect/plugins/serverlog/ServerLogItem.java

Lines changed: 27 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.io.Serializable;
1313
import java.text.SimpleDateFormat;
1414
import java.util.Date;
15+
import java.util.HashMap;
16+
import java.util.Map;
1517

1618
import org.apache.commons.lang3.StringUtils;
1719

@@ -30,116 +32,28 @@ public class ServerLogItem implements Serializable {
3032
private String message;
3133
private String throwableInformation;
3234
private String channelName;
35+
private HashMap<String, Object> context;
3336

3437
public ServerLogItem() {}
3538

36-
public ServerLogItem(String message) {
37-
this(null, null, null, null, null, null, null, null, null, message, null);
38-
}
39-
40-
public ServerLogItem(String serverId, Long id, String level, Date date, String threadName, String category, String lineNumber, String message, String throwableInformation) {
41-
this(serverId, id, null, null, level, date, threadName, category, lineNumber, message, throwableInformation);
42-
}
43-
44-
public ServerLogItem(String serverId, Long id, String channelId, String channelName, String level, Date date, String threadName, String category, String lineNumber, String message, String throwableInformation) {
45-
this.serverId = serverId;
46-
this.id = id;
47-
this.channelId = channelId;
48-
this.channelName = channelName;
49-
this.level = level;
50-
this.date = date;
51-
this.threadName = threadName;
52-
this.category = category;
53-
this.lineNumber = lineNumber;
54-
this.message = message;
55-
this.throwableInformation = throwableInformation;
56-
}
57-
58-
private ServerLogItem(Builder builder) {
59-
this.serverId = builder.serverId;
60-
this.id = builder.id;
61-
this.channelId = builder.channelId;
62-
this.channelName = builder.channelName;
63-
this.level = builder.level;
64-
this.date = builder.date;
65-
this.threadName = builder.threadName;
66-
this.category = builder.category;
67-
this.lineNumber = builder.lineNumber;
68-
this.message = builder.message;
69-
this.throwableInformation = builder.throwableInformation;
70-
}
71-
72-
public static class Builder {
73-
private String serverId;
74-
private Long id;
75-
private String channelId;
76-
private String channelName;
77-
private String level;
78-
private Date date;
79-
private String threadName;
80-
private String category;
81-
private String lineNumber;
82-
private String message;
83-
private String throwableInformation;
84-
85-
public Builder serverId(String serverId) {
86-
this.serverId = serverId;
87-
return this;
88-
}
89-
90-
public Builder id(Long id) {
91-
this.id = id;
92-
return this;
93-
}
94-
95-
public Builder channelId(String channelId) {
96-
this.channelId = channelId;
97-
return this;
98-
}
99-
100-
public Builder channelName(String channelName) {
101-
this.channelName = channelName;
102-
return this;
103-
}
104-
105-
public Builder level(String level) {
106-
this.level = level;
107-
return this;
108-
}
109-
110-
public Builder date(Date date) {
111-
this.date = date;
112-
return this;
113-
}
114-
115-
public Builder threadName(String threadName) {
116-
this.threadName = threadName;
117-
return this;
118-
}
119-
120-
public Builder category(String category) {
121-
this.category = category;
122-
return this;
123-
}
124-
125-
public Builder lineNumber(String lineNumber) {
126-
this.lineNumber = lineNumber;
127-
return this;
128-
}
129-
130-
public Builder message(String message) {
131-
this.message = message;
132-
return this;
133-
}
134-
135-
public Builder throwableInformation(String throwableInformation) {
136-
this.throwableInformation = throwableInformation;
137-
return this;
39+
public ServerLogItem(Map<String, Object> properties) {
40+
if (properties != null) {
41+
this.context = new HashMap<>(properties);
42+
} else {
43+
this.context = new HashMap<>();
13844
}
13945

140-
public ServerLogItem build() {
141-
return new ServerLogItem(this);
142-
}
46+
this.serverId = (String) context.getOrDefault("serverId", "");
47+
this.id = (Long) context.getOrDefault("id", "");
48+
this.channelId = (String) context.getOrDefault("channelId", "");
49+
this.channelName = (String) context.getOrDefault("channelName", "");
50+
this.level = (String) context.getOrDefault("level", "");
51+
this.date = (Date) context.getOrDefault("date", "");
52+
this.threadName = (String) context.getOrDefault("threadName", "");
53+
this.category = (String) context.getOrDefault("category", "");
54+
this.lineNumber = (String) context.getOrDefault("lineNumber", "");
55+
this.message = (String) context.getOrDefault("message", "");
56+
this.throwableInformation = (String) context.getOrDefault("throwableInformation", "");
14357
}
14458

14559
public String getServerId() {
@@ -229,6 +143,14 @@ public String getChannelName() {
229143
public void setChannelName(String channelName) {
230144
this.channelName = channelName;
231145
}
146+
147+
public Map<String, Object> getContext() {
148+
return context;
149+
}
150+
151+
public void setContext(Map<String, Object> context) {
152+
this.context = new HashMap<>(context);
153+
}
232154

233155
@Override
234156
public String toString() {

server/src/com/mirth/connect/plugins/serverlog/ServerLogProvider.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
import java.util.ArrayList;
1616
import java.util.Date;
17+
import java.util.HashMap;
1718
import java.util.List;
19+
import java.util.Map;
1820
import java.util.Properties;
1921

2022
import org.apache.logging.log4j.LogManager;
@@ -57,7 +59,20 @@ public void init(Properties properties) {
5759

5860
public synchronized void newServerLogReceived(String channelId, String channelName, String level, Date date, String threadName, String category, String lineNumber, String message, String throwableInformation) {
5961
if (logController != null) {
60-
logController.addLogItem(new ServerLogItem(serverId, logId, channelId, channelName, level, date, threadName, category, lineNumber, message, throwableInformation));
62+
Map<String, Object> properties = new HashMap<>();
63+
properties.put("serverId", serverId);
64+
properties.put("id", logId);
65+
properties.put("channelId", channelId);
66+
properties.put("channelName", channelName);
67+
properties.put("level", level);
68+
properties.put("date", date);
69+
properties.put("threadName", threadName);
70+
properties.put("category", category);
71+
properties.put("lineNumber", lineNumber);
72+
properties.put("message", message);
73+
properties.put("throwableInformation", throwableInformation);
74+
75+
logController.addLogItem(new ServerLogItem(properties));
6176
logId++;
6277
}
6378
}

server/src/com/mirth/connect/server/servlets/SwaggerExamplesServlet.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,8 +1286,20 @@ private List<ServerEvent> getServerEventListExample() {
12861286
}
12871287

12881288
private ServerLogItem getServerLogItemExample() {
1289-
return new ServerLogItem(UUID.randomUUID().toString(), 1L, "INFO", dateNow.getTime(), "Main Server Thread", "com.mirth.connect.server.Mirth", "1", "Example message", "Example throwable information");
1290-
}
1289+
// return new ServerLogItem(UUID.randomUUID().toString(), 1L, "INFO", dateNow.getTime(), "Main Server Thread", "com.mirth.connect.server.Mirth", "1", "Example message", "Example throwable information");
1290+
Map<String, Object> properties = new HashMap<>();
1291+
properties.put("serverId", UUID.randomUUID().toString());
1292+
properties.put("id", 1L);
1293+
properties.put("channelId", "INFO");
1294+
properties.put("date", dateNow.getTime());
1295+
properties.put("threadName", "Main Server Thread");
1296+
properties.put("category", "com.mirth.connect.server.Mirth");
1297+
properties.put("lineNumber", "1");
1298+
properties.put("message", "Example Message");
1299+
properties.put("throwableInformation", "Example throwable Information");
1300+
1301+
return new ServerLogItem(properties);
1302+
}
12911303

12921304
private List<ServerLogItem> getServerLogItemListExample() {
12931305
List<ServerLogItem> serverLogList = new ArrayList<>();

0 commit comments

Comments
 (0)