Skip to content

Commit d19499d

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 7c85593 commit d19499d

6 files changed

Lines changed: 127 additions & 57 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-FileCopyrightText: 2026 Tony Germano <tony@germano.name>
3+
4+
package com.mirth.connect.model;
5+
6+
import java.util.Collection;
7+
8+
import com.mirth.connect.donkey.model.message.ContentType;
9+
10+
public class ContentSearchElementToStringStyle extends SearchElementToStringStyle {
11+
public ContentSearchElementToStringStyle() {
12+
super();
13+
setFieldSeparator(", ");
14+
setArraySeparator(", ");
15+
setArrayStart("[");
16+
setArrayEnd("]");
17+
}
18+
19+
@Override
20+
protected void appendDetail(StringBuffer buffer, String fieldName, Collection<?> coll) {
21+
appendDetail(buffer, fieldName, (Object[]) coll.toArray());
22+
}
23+
24+
@Override
25+
protected void appendDetail(StringBuffer buffer, String fieldname, Object value) {
26+
if (fieldname.equals("contentCode") && value instanceof Integer code) {
27+
ContentType type = ContentType.fromCode(code);
28+
String typeName = (type != null) ? type.toString() : "UNKNOWN";
29+
String formatted = String.format("%d(%s)", code, typeName);
30+
buffer.append(formatted);
31+
} else {
32+
super.appendDetail(buffer, fieldname, value);
33+
}
34+
}
35+
36+
public static ContentSearchElementToStringStyle instance() {
37+
return new ContentSearchElementToStringStyle();
38+
}
39+
}
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
package com.mirth.connect.model;
26

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

712
import org.apache.commons.lang3.builder.ToStringStyle;
813

914
public class MessageFilterToStringStyle extends ToStringStyle {
15+
private static final int INDENT = 2;
16+
private static final Set<String> flatten = Set.of("excludedMetaDataIds", "includedMetaDataIds", "statuses",
17+
"textSearchMetaDataColumns");
18+
private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mmXXX'['VV']'");
19+
20+
private int level = 1;
21+
1022
public MessageFilterToStringStyle() {
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
public static MessageFilterToStringStyle instance() {
2030
return new MessageFilterToStringStyle();
2131
}
22-
32+
33+
@Override
2334
protected void appendDetail(StringBuffer buffer, String fieldName, Object value) {
24-
if (value instanceof Calendar) {
25-
value = String.format("%1$tY-%1$tm-%1$td", value);
35+
if (value instanceof GregorianCalendar cal) {
36+
value = cal.toZonedDateTime().format(dateFormat);
2637
}
2738

2839
buffer.append(value);
2940
}
3041

42+
@Override
3143
protected void appendDetail(StringBuffer buffer, String fieldName, Collection<?> coll) {
32-
if (fieldName.equals("metaDataSearch")) {
33-
buffer.append("[\n");
34-
Iterator<?> iterator = coll.iterator();
35-
while (iterator.hasNext()) {
36-
Object element = 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+
protected void appendDetail(StringBuffer buffer, String fieldName, Object[] array) {
53+
level += 1;
54+
resetIndent();
55+
super.appendDetail(buffer, fieldName, array);
56+
level -= 1;
57+
resetIndent();
58+
}
59+
60+
private void resetIndent() {
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
package com.mirth.connect.model;
6+
7+
import org.apache.commons.lang3.builder.ToStringStyle;
8+
9+
public class SearchElementToStringStyle extends ToStringStyle {
10+
public SearchElementToStringStyle() {
11+
super();
12+
this.setUseShortClassName(true);
13+
this.setUseIdentityHashCode(false);
14+
}
15+
16+
@Override
17+
protected void appendDetail(StringBuffer buffer, String fieldname, Object value) {
18+
if (value instanceof String) {
19+
buffer.append("\"" + value + "\"");
20+
} else {
21+
super.appendDetail(buffer, fieldname, value);
22+
}
23+
}
24+
25+
public static SearchElementToStringStyle instance() {
26+
return new SearchElementToStringStyle();
27+
}
28+
}

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
package com.mirth.connect.model.filters.elements;
116

127
import java.io.Serializable;
138
import java.util.List;
149

10+
import org.apache.commons.lang3.builder.ToStringBuilder;
11+
12+
import com.mirth.connect.model.ContentSearchElementToStringStyle;
13+
1514
public class ContentSearchElement implements Serializable {
1615

1716
private int contentCode;
@@ -37,4 +36,9 @@ public List<String> getSearches() {
3736
public void setSearches(List<String> searches) {
3837
this.searches = searches;
3938
}
39+
40+
@Override
41+
public String toString() {
42+
return ToStringBuilder.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
package com.mirth.connect.model.filters.elements;
115

126
import java.io.Serializable;
137

148
import org.apache.commons.lang3.builder.ToStringBuilder;
159

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

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

6660
@Override
6761
public String toString() {
68-
return ToStringBuilder.reflectionToString(this, MetaDataSearchElementToStringStyle.instance());
62+
return ToStringBuilder.reflectionToString(this, SearchElementToStringStyle.instance());
6963
}
7064
}

0 commit comments

Comments
 (0)