Skip to content

Commit 7311e1b

Browse files
committed
Improve MessageFilter logging and refactor search element styles
Refactors the ToStringStyle implementations for MessageFilter and related search elements to significantly improve debuggability and log readability. Key Changes: - Refactored MetaDataSearchElementToStringStyle into a generic SearchElementToStringStyle to eliminate code duplication. - Added ContentSearchElementToStringStyle: - Converts raw content codes into human-readable ContentType names (e.g., "1(Raw)") instead of opaque integers. - Updated MessageFilterToStringStyle: - Replaced legacy Calendar formatting with java.time (ZonedDateTime) and included time and timezone id. - Added recursive indentation logic to render nested collections in a hierarchical format. - Applied new styles to ContentSearchElement and MetaDataSearchElement toString() methods. - Previously ContentSearchElement was inheriting the Object.toString method. This change primarily adds detail for ContentSearchElements when viewing the MessageFilter in the server event log. The addition of the time and timezone id fill in some missing details for the start and end times. The additonal reformats improve readability. Signed-off-by: Tony Germano <tony@germano.name>
1 parent 346cc45 commit 7311e1b

6 files changed

Lines changed: 118 additions & 57 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-FileCopyrightText: 2026 Tony Germano <tony@germano.name>
3+
4+
packagecom.mirth.connect.model;
5+
6+
importjava.util.Collection;
7+
8+
importcom.mirth.connect.donkey.model.message.ContentType;
9+
10+
publicclassContentSearchElementToStringStyleextendsSearchElementToStringStyle {
11+
publicContentSearchElementToStringStyle() {
12+
super();
13+
setArraySeparator(", ");
14+
setArrayStart("[");
15+
setArrayEnd("]");
16+
}
17+
18+
@Override
19+
protectedvoidappendDetail(StringBufferbuffer, StringfieldName, Collection<?> coll) {
20+
appendDetail(buffer, fieldName, (Object[]) coll.toArray());
21+
}
22+
23+
@Override
24+
protectedvoidappendDetail(StringBufferbuffer, Stringfieldname, Objectvalue) {
25+
if (fieldname.equals("contentCode") && valueinstanceofIntegercode) {
26+
ContentTypetype = ContentType.fromCode(code);
27+
StringtypeName = (type != null) ? type.toString() : "UNKNOWN";
28+
Stringformatted = String.format("%d(%s)", code, typeName);
29+
buffer.append(formatted);
30+
} else {
31+
super.appendDetail(buffer, fieldname, value);
32+
}
33+
}
34+
35+
publicstaticContentSearchElementToStringStyleinstance() {
36+
returnnewContentSearchElementToStringStyle();
37+
}
38+
}
Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,68 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-FileCopyrightText: 2005-2024 NextGen Healthcare
3+
// SPDX-FileCopyrightText: 2026 Tony Germano <tony@germano.name>
4+
15
packagecom.mirth.connect.model;
26

3-
importjava.util.Calendar;
7+
importjava.time.format.DateTimeFormatter;
8+
importjava.util.GregorianCalendar;
49
importjava.util.Collection;
5-
importjava.util.Iterator;
10+
importjava.util.Set;
611

712
importorg.apache.commons.lang3.builder.ToStringStyle;
813

914
publicclassMessageFilterToStringStyleextendsToStringStyle {
15+
privatestaticfinalintINDENT = 2;
16+
privatestaticfinalSet<String> flatten = Set.of("excludedMetaDataIds", "includedMetaDataIds", "statuses",
17+
"textSearchMetaDataColumns");
18+
privatestaticfinalDateTimeFormatterdateFormat = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mmXXX'['VV']'");
19+
20+
privateintlevel = 1;
21+
1022
publicMessageFilterToStringStyle() {
1123
super();
12-
this.setUseShortClassName(true);
13-
this.setUseIdentityHashCode(false);
14-
this.setContentStart("[\n");
15-
this.setFieldSeparator(",\n");
16-
this.setContentEnd("\n]");
24+
setUseShortClassName(true);
25+
setUseIdentityHashCode(false);
26+
resetIndent();
1727
}
18-
28+
1929
publicstaticMessageFilterToStringStyleinstance() {
2030
returnnewMessageFilterToStringStyle();
2131
}
22-
32+
33+
@Override
2334
protectedvoidappendDetail(StringBufferbuffer, StringfieldName, Objectvalue) {
24-
if (valueinstanceofCalendar) {
25-
value = String.format("%1$tY-%1$tm-%1$td", value);
35+
if (valueinstanceofGregorianCalendarcal) {
36+
value = cal.toZonedDateTime().format(dateFormat);
2637
}
2738

2839
buffer.append(value);
2940
}
3041

42+
@Override
3143
protectedvoidappendDetail(StringBufferbuffer, StringfieldName, Collection<?> coll) {
32-
if (fieldName.equals("metaDataSearch")) {
33-
buffer.append("[\n");
34-
Iterator<?> iterator = coll.iterator();
35-
while (iterator.hasNext()) {
36-
Objectelement = iterator.next();
37-
if (!iterator.hasNext()) {
38-
buffer.append(element.toString() + "\n");
39-
} else {
40-
buffer.append(element.toString() + ",\n");
41-
}
42-
}
43-
buffer.append("]");
44+
if (flatten.contains(fieldName)) {
45+
appendDetail(buffer, fieldName, coll.toString());
4446
} else {
45-
super.appendDetail(buffer, fieldName, coll);
47+
appendDetail(buffer, fieldName, (Object[]) coll.toArray());
4648
}
4749
}
50+
51+
@Override
52+
protectedvoidappendDetail(StringBufferbuffer, StringfieldName, Object[] array) {
53+
level += 1;
54+
resetIndent();
55+
super.appendDetail(buffer, fieldName, array);
56+
level -= 1;
57+
resetIndent();
58+
}
59+
60+
privatevoidresetIndent() {
61+
setArrayStart("[" + System.lineSeparator() + " ".repeat(INDENT * level));
62+
setArraySeparator("," + System.lineSeparator() + " ".repeat(INDENT * level));
63+
setArrayEnd(System.lineSeparator() + " ".repeat(INDENT * (level - 1)) + "]");
64+
setContentStart("[" + System.lineSeparator() + " ".repeat(INDENT * level));
65+
setFieldSeparator("," + System.lineSeparator() + " ".repeat(INDENT * level));
66+
setContentEnd(System.lineSeparator() + " ".repeat(INDENT * (level - 1)) + "]");
67+
}
4868
}

‎server/src/com/mirth/connect/model/MetaDataSearchElementToStringStyle.java‎

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-FileCopyrightText: 2005-2024 NextGen Healthcare
3+
// SPDX-FileCopyrightText: 2026 Tony Germano <tony@germano.name>
4+
5+
packagecom.mirth.connect.model;
6+
7+
importorg.apache.commons.lang3.builder.ToStringStyle;
8+
9+
publicclassSearchElementToStringStyleextendsToStringStyle {
10+
publicSearchElementToStringStyle() {
11+
super();
12+
setUseShortClassName(true);
13+
setUseIdentityHashCode(false);
14+
setFieldSeparator(", ");
15+
}
16+
17+
publicstaticSearchElementToStringStyleinstance() {
18+
returnnewSearchElementToStringStyle();
19+
}
20+
}

‎server/src/com/mirth/connect/model/filters/elements/ContentSearchElement.java‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
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: 2026 Tony Germano <tony@germano.name>
94

105
packagecom.mirth.connect.model.filters.elements;
116

127
importjava.io.Serializable;
138
importjava.util.List;
149

10+
importorg.apache.commons.lang3.builder.ToStringBuilder;
11+
12+
importcom.mirth.connect.model.ContentSearchElementToStringStyle;
13+
1514
publicclassContentSearchElementimplementsSerializable {
1615

1716
privateintcontentCode;
@@ -37,4 +36,9 @@ public List<String> getSearches() {
3736
publicvoidsetSearches(List<String> searches) {
3837
this.searches = searches;
3938
}
39+
40+
@Override
41+
publicStringtoString() {
42+
returnToStringBuilder.reflectionToString(this, ContentSearchElementToStringStyle.instance());
43+
}
4044
}

‎server/src/com/mirth/connect/model/filters/elements/MetaDataSearchElement.java‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
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
93

104
packagecom.mirth.connect.model.filters.elements;
115

126
importjava.io.Serializable;
137

148
importorg.apache.commons.lang3.builder.ToStringBuilder;
159

16-
importcom.mirth.connect.model.MetaDataSearchElementToStringStyle;
10+
importcom.mirth.connect.model.SearchElementToStringStyle;
1711
importcom.thoughtworks.xstream.annotations.XStreamAlias;
1812

1913
@XStreamAlias("metaDataSearchCriteria")
@@ -65,6 +59,6 @@ public void setIgnoreCase(Boolean ignoreCase) {
6559

6660
@Override
6761
publicStringtoString() {
68-
returnToStringBuilder.reflectionToString(this, MetaDataSearchElementToStringStyle.instance());
62+
returnToStringBuilder.reflectionToString(this, SearchElementToStringStyle.instance());
6963
}
7064
}

0 commit comments

Comments
 (0)