From 4503f3031f273dcd91799734552cc05bf48e6e77 Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Thu, 25 Jul 2024 17:31:32 +0200 Subject: [PATCH] impl Issue #591 --- .../office/forms/ChronicleController.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/imixs-office-workflow-util/src/main/java/org/imixs/workflow/office/forms/ChronicleController.java b/imixs-office-workflow-util/src/main/java/org/imixs/workflow/office/forms/ChronicleController.java index a0e48fa9..cd93b9c7 100644 --- a/imixs-office-workflow-util/src/main/java/org/imixs/workflow/office/forms/ChronicleController.java +++ b/imixs-office-workflow-util/src/main/java/org/imixs/workflow/office/forms/ChronicleController.java @@ -32,6 +32,7 @@ import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -46,6 +47,7 @@ import org.imixs.workflow.ItemCollection; import org.imixs.workflow.WorkflowKernel; import org.imixs.workflow.engine.DocumentService; +import org.imixs.workflow.engine.plugins.HistoryPlugin; import org.imixs.workflow.faces.data.WorkflowController; import org.imixs.workflow.faces.data.WorkflowEvent; @@ -125,12 +127,33 @@ public void init() { } /* collect history */ - List> history = workflowController.getWorkitem().getItemValue("txtworkflowhistory"); + List> history = null; + // test deprecated field 'txtworkflowhistory' + if (!workflowController.getWorkitem().hasItem(HistoryPlugin.ITEM_HISTORY_LOG) + && workflowController.getWorkitem().hasItem("txtworkflowhistory")) { + // migrate deprecated field name + history = workflowController.getWorkitem().getItemValue("txtworkflowhistory"); + // in old workitems, the workflow history may not be ordered chronological. + // We re-sort the order here + // Sort the list by date in descending order + Collections.sort(history, new Comparator>() { + @Override + public int compare(List entry1, List entry2) { + Date date1 = (Date) entry1.get(0); + Date date2 = (Date) entry2.get(0); + // Compare in descending order + return date1.compareTo(date2); + } + }); + } else { + history = workflowController.getWorkitem().getItemValue(HistoryPlugin.ITEM_HISTORY_LOG); + } + // change order Collections.reverse(history); // do we have real history entries? if (history.size() > 0 && history.get(0) instanceof List) { - for (List entries : history) { + for (List entries : history) { Date date = (Date) entries.get(0); String message = (String) entries.get(1); String user = (String) entries.get(2);