From 2d8c77ecfb0c9e22e7cd9e4588235e838c69c9d0 Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Sat, 2 Nov 2024 10:23:18 +0100 Subject: [PATCH] minor fixes Issue #606 --- .../office/forms/AnalyticController.java | 58 ++++++++++++------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/imixs-office-workflow-util/src/main/java/org/imixs/workflow/office/forms/AnalyticController.java b/imixs-office-workflow-util/src/main/java/org/imixs/workflow/office/forms/AnalyticController.java index e80e135a..6fda2ecc 100644 --- a/imixs-office-workflow-util/src/main/java/org/imixs/workflow/office/forms/AnalyticController.java +++ b/imixs-office-workflow-util/src/main/java/org/imixs/workflow/office/forms/AnalyticController.java @@ -53,6 +53,23 @@ public String getAsString(String key) { return analyticData.getItemValueString("value"); } + /** + * Returns a analytic value as a Json String for a given key. + * + * @param key + * @return + */ + public String getAsJson(String key) { + ItemCollection analyticData = computeValue(key); + String jsonval = analyticData.getItemValueString("value"); + if (jsonval == null || jsonval.isEmpty()) { + return "null"; + } else { + System.out.println(jsonval); + return jsonval; + } + } + /** * Returns a analytic value as a Double for a given key. * @@ -106,35 +123,36 @@ public String getDescription(String key) { */ protected ItemCollection computeValue(String key) { if (workflowController.getWorkitem() != null) { - // try to fetch value from cache - if (!workflowController.getWorkitem().hasItem("analytic." + key)) { - logger.fine("fire analytic event for key '" + key + "'"); - // Fire the Analytics Event for this key - AnalyticEvent event = new AnalyticEvent(key, workflowController.getWorkitem()); - if (analyticEvents != null) { - analyticEvents.fire(event); + + logger.fine("fire analytic event for key '" + key + "'"); + // Fire the Analytics Event for this key + AnalyticEvent event = new AnalyticEvent(key, workflowController.getWorkitem()); + if (analyticEvents != null) { + analyticEvents.fire(event); + if (event.getValue() != null) { ItemCollection details = new ItemCollection(); details.setItemValue("value", event.getValue()); details.setItemValue("label", event.getLabel()); details.setItemValue("description", event.getDescription()); details.setItemValue("link", event.getLink()); implodeDetails(key, details); - return details; } + } - if (event.getValue() == null) { - // set dummy value - ItemCollection details = new ItemCollection(); - details.setItemValue("value", ""); - details.setItemValue("label", ""); - details.setItemValue("description", "No data available"); - implodeDetails(key, details); - return details; - } + // try loading from cache + ItemCollection details = explodeDetails(key); + if (details == null) { + // set dummy value + details = new ItemCollection(); + details.setItemValue("value", ""); + details.setItemValue("label", ""); + details.setItemValue("description", "No data available"); + implodeDetails(key, details); } + } - // analytic value is already cached! + // analytic value is now already cached! return explodeDetails(key); } @@ -144,7 +162,7 @@ protected ItemCollection computeValue(String key) { * @param workitem */ @SuppressWarnings({ "rawtypes" }) - public void implodeDetails(String key, ItemCollection details) { + private void implodeDetails(String key, ItemCollection details) { // convert the child ItemCollection elements into a List of Map List detailsList = new ArrayList(); detailsList.add(details.getAllItems()); @@ -155,7 +173,7 @@ public void implodeDetails(String key, ItemCollection details) { * converts the Map List of a workitem into a List of ItemCollectons */ @SuppressWarnings({ "rawtypes", "unchecked" }) - public ItemCollection explodeDetails(String key) { + private ItemCollection explodeDetails(String key) { // convert current list of childItems into ItemCollection elements List mapOrderItems = workflowController.getWorkitem().getItemValue(key); if (mapOrderItems != null && mapOrderItems.size() > 0) {