From 23a46b4be35277e06ec89f48730eeb694e686be8 Mon Sep 17 00:00:00 2001
From: Kenmegne <stephanie.kenmegne@gmail.com>
Date: Thu, 18 Jun 2026 15:40:06 +0000
Subject: [PATCH] add fdx-commons and fdx-consultation

---
 fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/utils/JsonFdxParsedDataAction.java |   73 ++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+), 0 deletions(-)

diff --git a/fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/utils/JsonFdxParsedDataAction.java b/fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/utils/JsonFdxParsedDataAction.java
new file mode 100644
index 0000000..f92aa49
--- /dev/null
+++ b/fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/utils/JsonFdxParsedDataAction.java
@@ -0,0 +1,73 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package com.megatim.fdxcommons.tools.utils;
+
+import com.megatim.fdxcommons.model.integration.json.JsonStructure;
+import com.megatim.fdxcommons.tools.database.exceptions.BadDataValueException;
+import com.megatim.fdxcommons.tools.database.exceptions.ColumnNotFoundException;
+import com.megatim.fdxcommons.tools.database.exceptions.LocalDateTimeValueParseError;
+import com.megatim.fdxcommons.tools.database.queries.metadata.JsonFdxParsedDataRow;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ForkJoinTask;
+import java.util.concurrent.RecursiveTask;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author ASUS
+ */
+public class JsonFdxParsedDataAction extends RecursiveTask<List<Map<String, Object>>> {
+
+    private final List<LinkedHashMap<String, Object>> sourceData;
+    private final JsonStructure jsonStructure;
+    private final List<Map<String, Object>> cachedData = new ArrayList<>();
+    private final int THRESHOLD = 5000;
+
+    public JsonFdxParsedDataAction(List<LinkedHashMap<String, Object>> sourceData, JsonStructure jsonStructure) {
+        this.sourceData = sourceData;
+        this.jsonStructure = jsonStructure;
+    }
+
+    @Override
+    protected List<Map<String, Object>> compute() {
+        if (sourceData.size() > THRESHOLD) {
+            ForkJoinTask
+                    .invokeAll(createSubtasks())
+                    .stream()
+                    .map(JsonFdxParsedDataAction::join)
+                    .forEach(l -> cachedData.addAll(l));
+            return cachedData;
+        } else {
+            if (cachedData.isEmpty()) {
+                for (Map<String, Object> data : sourceData) {
+                    try {
+                        cachedData.add(new JsonFdxParsedDataRow(data, jsonStructure).dataRow());
+                    } catch (ColumnNotFoundException | BadDataValueException | LocalDateTimeValueParseError ex) {
+                        Logger.getLogger(JsonFdxParsedDataAction.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
+                        throw new RuntimeException(ex);
+                    }
+                }
+            }
+            return cachedData;
+        }
+    }
+
+    private List<JsonFdxParsedDataAction> createSubtasks() {
+        List<JsonFdxParsedDataAction> subtasks = new ArrayList<>();
+        int size = sourceData.size() / 4;
+        int remainder = sourceData.size() % 4;
+
+        subtasks.add(new JsonFdxParsedDataAction(sourceData.subList(0, size), jsonStructure));
+        subtasks.add(new JsonFdxParsedDataAction(sourceData.subList(size, size * 2), jsonStructure));
+        subtasks.add(new JsonFdxParsedDataAction(sourceData.subList(size * 2, size * 3), jsonStructure));
+        subtasks.add(new JsonFdxParsedDataAction(sourceData.subList(size * 3, size * 4 + remainder), jsonStructure));
+
+        return subtasks;
+    }
+}

--
Gitblit v1.10.0