Skip to content

Commit c648448

Browse files
committed
Move toString to MessageFilter and out of Browser
Signed-off-by: Mitch Gaffigan <mitch.gaffigan@comcast.net>
1 parent bfe3348 commit c648448

2 files changed

Lines changed: 170 additions & 179 deletions

File tree

client/src/com/mirth/connect/client/ui/browsers/message/MessageBrowser.java

Lines changed: 1 addition & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ protected void runSearch() {
684684
clearCache();
685685
loadPageNumber(1);
686686

687-
updateSearchCriteriaPane();
687+
lastSearchCriteria.setText(messageFilter.toString(connectors, "\n", true));
688688
auditSearch();
689689
}
690690
}
@@ -723,183 +723,6 @@ protected void auditSearch(String channelId, String channelName) {
723723
}
724724
}
725725

726-
protected void updateSearchCriteriaPane() {
727-
StringBuilder text = new StringBuilder();
728-
Calendar startDate = messageFilter.getStartDate();
729-
Calendar endDate = messageFilter.getEndDate();
730-
String padding = "\n";
731-
732-
text.append("Max Message Id: ");
733-
text.append(messageFilter.getMaxMessageId());
734-
735-
if (messageFilter.getMinMessageId() != null) {
736-
text.append(padding + "Min Message Id: ");
737-
text.append(messageFilter.getMinMessageId());
738-
}
739-
740-
String startDateFormatString = mirthTimePicker1.isEnabled() ? "yyyy-MM-dd HH:mm" : "yyyy-MM-dd";
741-
String endDateFormatString = mirthTimePicker2.isEnabled() ? "yyyy-MM-dd HH:mm" : "yyyy-MM-dd";
742-
743-
DateFormat startDateFormat = new SimpleDateFormat(startDateFormatString);
744-
DateFormat endDateFormat = new SimpleDateFormat(endDateFormatString);
745-
746-
text.append(padding + "Date Range: ");
747-
748-
if (startDate == null) {
749-
text.append("(any)");
750-
} else {
751-
text.append(startDateFormat.format(startDate.getTime()));
752-
if (!mirthTimePicker1.isEnabled()) {
753-
text.append(" (all day)");
754-
}
755-
}
756-
757-
text.append(" to ");
758-
759-
if (endDate == null) {
760-
text.append("(any)");
761-
} else {
762-
text.append(endDateFormat.format(endDate.getTime()));
763-
if (!mirthTimePicker2.isEnabled()) {
764-
text.append(" (all day)");
765-
}
766-
}
767-
768-
text.append(padding + "Statuses: ");
769-
770-
if (messageFilter.getStatuses() == null) {
771-
text.append("(any)");
772-
} else {
773-
text.append(StringUtils.join(messageFilter.getStatuses(), ", "));
774-
}
775-
776-
if (messageFilter.getTextSearch() != null) {
777-
text.append(padding + "Text Search: " + messageFilter.getTextSearch());
778-
}
779-
780-
text.append(getConnectorSearchCriteriaText(padding));
781-
782-
if (messageFilter.getOriginalIdLower() != null || messageFilter.getOriginalIdUpper() != null) {
783-
text.append(padding + "Original Id: ");
784-
if (messageFilter.getOriginalIdUpper() == null) {
785-
text.append("Greater than " + messageFilter.getOriginalIdLower());
786-
} else if (messageFilter.getOriginalIdLower() == null) {
787-
text.append("Less than " + messageFilter.getOriginalIdUpper());
788-
} else {
789-
text.append("Between " + messageFilter.getOriginalIdLower() + " and " + messageFilter.getOriginalIdUpper());
790-
}
791-
}
792-
793-
if (messageFilter.getImportIdLower() != null || messageFilter.getImportIdUpper() != null) {
794-
text.append(padding + "Import Id: ");
795-
if (messageFilter.getImportIdUpper() == null) {
796-
text.append("Greater than " + messageFilter.getImportIdLower());
797-
} else if (messageFilter.getImportIdLower() == null) {
798-
text.append("Less than " + messageFilter.getImportIdUpper());
799-
} else {
800-
text.append("Between " + messageFilter.getImportIdLower() + " and " + messageFilter.getImportIdUpper());
801-
}
802-
}
803-
804-
if (messageFilter.getServerId() != null) {
805-
text.append(padding + "Server Id: " + messageFilter.getServerId());
806-
}
807-
808-
Integer sendAttemptsLower = messageFilter.getSendAttemptsLower();
809-
Integer sendAttemptsUpper = messageFilter.getSendAttemptsUpper();
810-
811-
if (sendAttemptsLower != null || sendAttemptsUpper != null) {
812-
text.append(padding + "# of Send Attempts: ");
813-
814-
if (sendAttemptsLower != null) {
815-
text.append(sendAttemptsLower);
816-
} else {
817-
text.append("(any)");
818-
}
819-
820-
text.append(" - ");
821-
822-
if (sendAttemptsUpper != null) {
823-
text.append(sendAttemptsUpper);
824-
} else {
825-
text.append("(any)");
826-
}
827-
}
828-
829-
if (messageFilter.getContentSearch() != null) {
830-
List<ContentSearchElement> contentSearch = messageFilter.getContentSearch();
831-
832-
for (ContentSearchElement element : contentSearch) {
833-
for (String value : element.getSearches()) {
834-
text.append(padding + ContentType.fromCode(element.getContentCode()) + " contains \"" + value + "\"");
835-
}
836-
}
837-
}
838-
839-
if (messageFilter.getMetaDataSearch() != null) {
840-
List<MetaDataSearchElement> elements = messageFilter.getMetaDataSearch();
841-
842-
for (MetaDataSearchElement element : elements) {
843-
text.append(padding + element.getColumnName() + " " + MetaDataSearchOperator.fromString(element.getOperator()).toString() + " ");
844-
if (element.getValue() instanceof Calendar) {
845-
Calendar date = (Calendar) element.getValue();
846-
text.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date.getTime()));
847-
} else {
848-
text.append(element.getValue());
849-
}
850-
if (element.getIgnoreCase()) {
851-
text.append(" (Ignore Case)");
852-
}
853-
}
854-
}
855-
856-
if (messageFilter.getAttachment()) {
857-
text.append(padding + "Has Attachment");
858-
}
859-
860-
if (messageFilter.getError()) {
861-
text.append(padding + "Has Error");
862-
}
863-
864-
lastSearchCriteria.setText(text.toString());
865-
}
866-
867-
protected String getConnectorSearchCriteriaText(String padding) {
868-
StringBuilder text = new StringBuilder();
869-
text.append(padding + "Connectors: ");
870-
871-
if (messageFilter.getIncludedMetaDataIds() == null) {
872-
if (messageFilter.getExcludedMetaDataIds() == null) {
873-
text.append("(any)");
874-
} else {
875-
List<Integer> excludedMetaDataIds = messageFilter.getExcludedMetaDataIds();
876-
List<String> connectorNames = new ArrayList<String>();
877-
878-
for (Entry<Integer, String> connectorEntry : connectors.entrySet()) {
879-
if (!excludedMetaDataIds.contains(connectorEntry.getKey())) {
880-
connectorNames.add(connectorEntry.getValue());
881-
}
882-
}
883-
884-
text.append(StringUtils.join(connectorNames, ", "));
885-
}
886-
} else if (messageFilter.getIncludedMetaDataIds().isEmpty()) {
887-
text.append("(none)");
888-
} else {
889-
List<Integer> includedMetaDataIds = messageFilter.getIncludedMetaDataIds();
890-
List<String> connectorNames = new ArrayList<String>();
891-
892-
for (Entry<Integer, String> connectorEntry : connectors.entrySet()) {
893-
if (includedMetaDataIds.contains(connectorEntry.getKey())) {
894-
connectorNames.add(connectorEntry.getValue());
895-
}
896-
}
897-
898-
text.append(StringUtils.join(connectorNames, ", "));
899-
}
900-
return text.toString();
901-
}
902-
903726
public void jumpToPageNumber() {
904727
if (messages.getPageCount() != null && messages.getPageCount() > 0 && StringUtils.isNotEmpty(pageNumberField.getText())) {
905728
loadPageNumber(Math.min(Math.max(Integer.parseInt(pageNumberField.getText()), 1), messages.getPageCount()));

server/src/com/mirth/connect/model/filters/MessageFilter.java

Lines changed: 169 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@
1313
import java.util.Calendar;
1414
import java.util.List;
1515
import java.util.Set;
16+
import java.util.Map;
17+
import java.text.DateFormat;
18+
import java.text.SimpleDateFormat;
1619

20+
import org.apache.commons.lang3.StringUtils;
1721
import org.apache.commons.lang3.builder.ToStringBuilder;
1822

1923
import com.mirth.connect.donkey.model.message.Status;
2024
import com.mirth.connect.model.MessageFilterToStringStyle;
2125
import com.mirth.connect.model.filters.elements.ContentSearchElement;
2226
import com.mirth.connect.model.filters.elements.MetaDataSearchElement;
27+
import com.mirth.connect.model.filters.elements.MetaDataSearchOperator;
28+
import com.mirth.connect.donkey.model.message.ContentType;
29+
2330
import com.thoughtworks.xstream.annotations.XStreamAlias;
2431

2532
/**
@@ -224,6 +231,167 @@ public void setError(Boolean error) {
224231

225232
@Override
226233
public String toString() {
227-
return ToStringBuilder.reflectionToString(this, MessageFilterToStringStyle.instance());
234+
return toString(Map.of(), "\n", false);
235+
}
236+
237+
public String toString(Map<Integer, String> connectors, String padding, boolean includeEmptyCriteria) {
238+
StringBuilder text = new StringBuilder();
239+
240+
if (maxMessageId != null) {
241+
text.append("Max Message Id: ");
242+
text.append(maxMessageId);
243+
}
244+
245+
if (minMessageId != null) {
246+
text.append(padding + "Min Message Id: ");
247+
text.append(minMessageId);
248+
}
249+
250+
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
251+
252+
if (includeEmptyCriteria || startDate != null || endDate != null) {
253+
text.append(padding + "Date Range: ");
254+
255+
if (startDate == null) {
256+
text.append("(any)");
257+
} else {
258+
text.append(dateFormat.format(startDate.getTime()));
259+
}
260+
261+
text.append(" to ");
262+
263+
if (endDate == null) {
264+
text.append("(any)");
265+
} else {
266+
text.append(dateFormat.format(endDate.getTime()));
267+
}
268+
}
269+
270+
if (includeEmptyCriteria || (statuses != null && !statuses.isEmpty())) {
271+
text.append(padding + "Statuses: ");
272+
273+
if (statuses == null) {
274+
text.append("(any)");
275+
} else {
276+
text.append(StringUtils.join(statuses, ", "));
277+
}
278+
}
279+
280+
if (textSearch != null) {
281+
text.append(padding + "Text Search: " + textSearch);
282+
}
283+
284+
if (includeEmptyCriteria
285+
|| (includedMetaDataIds != null && !includedMetaDataIds.isEmpty())
286+
|| (excludedMetaDataIds != null && !excludedMetaDataIds.isEmpty())) {
287+
getConnectorSearchCriteriaText(text, padding, connectors);
288+
}
289+
290+
if (originalIdLower != null || originalIdUpper != null) {
291+
text.append(padding + "Original Id: ");
292+
if (originalIdUpper == null) {
293+
text.append("Greater than " + originalIdLower);
294+
} else if (originalIdLower == null) {
295+
text.append("Less than " + originalIdUpper);
296+
} else {
297+
text.append("Between " + originalIdLower + " and " + originalIdUpper);
298+
}
299+
}
300+
301+
if (importIdLower != null || importIdUpper != null) {
302+
text.append(padding + "Import Id: ");
303+
if (importIdUpper == null) {
304+
text.append("Greater than " + importIdLower);
305+
} else if (importIdLower == null) {
306+
text.append("Less than " + importIdUpper);
307+
} else {
308+
text.append("Between " + importIdLower + " and " + importIdUpper);
309+
}
310+
}
311+
312+
if (serverId != null) {
313+
text.append(padding + "Server Id: " + serverId);
314+
}
315+
316+
if (sendAttemptsLower != null || sendAttemptsUpper != null) {
317+
text.append(padding + "# of Send Attempts: ");
318+
319+
if (sendAttemptsLower != null) {
320+
text.append(sendAttemptsLower);
321+
} else {
322+
text.append("(any)");
323+
}
324+
325+
text.append(" - ");
326+
327+
if (sendAttemptsUpper != null) {
328+
text.append(sendAttemptsUpper);
329+
} else {
330+
text.append("(any)");
331+
}
332+
}
333+
334+
if (contentSearch != null) {
335+
for (ContentSearchElement element : contentSearch) {
336+
for (String value : element.getSearches()) {
337+
text.append(padding + ContentType.fromCode(element.getContentCode()) + " contains \"" + value + "\"");
338+
}
339+
}
340+
}
341+
342+
if (metaDataSearch != null) {
343+
for (MetaDataSearchElement element : metaDataSearch) {
344+
text.append(padding + element.getColumnName() + " " + MetaDataSearchOperator.fromString(element.getOperator()).toString() + " ");
345+
if (element.getValue() instanceof Calendar) {
346+
Calendar date = (Calendar) element.getValue();
347+
text.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date.getTime()));
348+
} else {
349+
text.append(element.getValue());
350+
}
351+
if (element.getIgnoreCase()) {
352+
text.append(" (Ignore Case)");
353+
}
354+
}
355+
}
356+
357+
if (attachment) {
358+
text.append(padding + "Has Attachment");
359+
}
360+
361+
if (error) {
362+
text.append(padding + "Has Error");
363+
}
364+
365+
return text.toString();
366+
}
367+
368+
private void getConnectorSearchCriteriaText(StringBuilder text, String padding, Map<Integer, String> connectors) {
369+
text.append(padding + "Connectors: ");
370+
371+
if (includedMetaDataIds == null) {
372+
text.append("(any)");
373+
} else if (includedMetaDataIds.isEmpty()) {
374+
text.append("(none)");
375+
} else {
376+
boolean first = true;
377+
for (var includedConnectorId : includedMetaDataIds) {
378+
if (!first) text.append(", ");
379+
first = false;
380+
381+
text.append(connectors.getOrDefault(includedConnectorId, String.valueOf(includedConnectorId)));
382+
}
383+
}
384+
385+
if (excludedMetaDataIds != null && !excludedMetaDataIds.isEmpty()) {
386+
text.append(" except ");
387+
388+
boolean first = true;
389+
for (var excludedConnectorId : excludedMetaDataIds) {
390+
if (!first) text.append(", ");
391+
first = false;
392+
393+
text.append(connectors.getOrDefault(excludedConnectorId, String.valueOf(excludedConnectorId)));
394+
}
395+
}
228396
}
229397
}

0 commit comments

Comments
 (0)