From b3d0580439b9a00c7eb918085de1694151066004 Mon Sep 17 00:00:00 2001
From: Kenmegne <stephanie.kenmegne@gmail.com>
Date: Thu, 18 Jun 2026 16:02:49 +0000
Subject: [PATCH] rename packages

---
 fdx_convert/src/main/java/com/megatim/fdxconvert/viewmodel/JsonStructureFormViewModel.java |  115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 115 insertions(+), 0 deletions(-)

diff --git a/fdx_convert/src/main/java/com/megatim/fdxconvert/viewmodel/JsonStructureFormViewModel.java b/fdx_convert/src/main/java/com/megatim/fdxconvert/viewmodel/JsonStructureFormViewModel.java
new file mode 100644
index 0000000..0b8bf10
--- /dev/null
+++ b/fdx_convert/src/main/java/com/megatim/fdxconvert/viewmodel/JsonStructureFormViewModel.java
@@ -0,0 +1,115 @@
+package com.megatim.fdxconvert.viewmodel;
+
+import com.megatim.dynamicjsonparser.enums.TypeDonnee;
+import com.megatimfx.components.customdialogs.AlertMessageUtil;
+import com.megatim.fdxconvert.model.JsonStructure;
+import com.megatim.fdxconvert.model.TypeFichier;
+import com.megatim.fdxconvert.model.TypeFichierJson;
+import com.megatim.fdxconvert.service.TypeFichierJsonService;
+import com.megatim.fdxconvert.service.TypeFichierService;
+import com.megatim.fdxconvert.views.jsonstructure.NestedJsonStructure;
+import javafx.beans.property.*;
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import javafx.concurrent.Task;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class JsonStructureFormViewModel {
+
+    private final ObservableList<TypeFichier> typeFichiers = FXCollections.observableArrayList();
+    private final BooleanProperty loading = new SimpleBooleanProperty(false);
+    private final ObjectProperty<TypeFichier> selectedTypeFichier;
+    private final ObjectProperty<TypeFichierJson> result = new SimpleObjectProperty<>(null);
+    private final TypeFichierJson typeFichierJson;
+
+    public JsonStructureFormViewModel(TypeFichierJson typeFichierJson) {
+        this.typeFichierJson = typeFichierJson != null ? typeFichierJson : new TypeFichierJson();
+        selectedTypeFichier = new SimpleObjectProperty<>(typeFichierJson != null ? typeFichierJson.getTypeFichier() : null);
+    }
+
+    public void init() {
+        loadTypeFichiersFromDB();
+    }
+
+    private void loadTypeFichiersFromDB() {
+        Task<Set<TypeFichier>> task = new Task() {
+            @Override
+            protected Object call() throws Exception {
+                return TypeFichierService.getInstance().getAll();
+            }
+        };
+        task.setOnRunning(e -> loading.set(true));
+        task.setOnSucceeded(e -> {
+            loading.set(false);
+            typeFichiers.clear();
+            typeFichiers.setAll(task.getValue());
+        });
+        task.setOnFailed(e -> {
+            loading.set(false);
+            AlertMessageUtil.showAlertException(task.getException(), "Une exception s'est produite pendant le traitement", "Erreur");
+        });
+        Thread thread = new Thread(task);
+        thread.setDaemon(true);
+        thread.start();
+    }
+
+    public void createTypeFichierJSON(NestedJsonStructure nestedJsonStructure) {
+        Task<TypeFichierJson> task = new Task() {
+            @Override
+            protected TypeFichierJson call() throws Exception {
+                typeFichierJson.setJsonStructure(jsonStructure(nestedJsonStructure, null));
+                if(typeFichierJson.getId() == null) {
+                    typeFichierJson.setTypeFichier(selectedTypeFichier.get());
+                    return TypeFichierJsonService.getInstance().add(typeFichierJson);
+                }
+                return TypeFichierJsonService.getInstance().edit(typeFichierJson);
+            }
+        };
+        task.setOnRunning(e -> loading.set(true));
+        task.setOnSucceeded(e -> {
+            loading.set(false);
+            result.set(typeFichierJson);
+        });
+        task.setOnFailed(e -> {
+            loading.set(false);
+            AlertMessageUtil.showAlertException(task.getException(), "Une exception s'est produite pendant le traitement", "Erreur");
+        });
+        Thread thread = new Thread(task);
+        thread.setDaemon(true);
+        thread.start();
+    }
+
+    private JsonStructure jsonStructure(NestedJsonStructure nestedJsonStructure, JsonStructure parent) {
+        JsonStructure jsonStructure = new JsonStructure();
+        jsonStructure.setName(nestedJsonStructure.name());
+        jsonStructure.setFormatDate(nestedJsonStructure.format());
+        jsonStructure.setTypeDonnee(nestedJsonStructure.typeDonnee());
+        jsonStructure.setLengthh(nestedJsonStructure.taille());
+        jsonStructure.setRequired(nestedJsonStructure.isRequired());
+        jsonStructure.setCollection(nestedJsonStructure.isCollection());
+
+        if (nestedJsonStructure.typeDonnee().equals(TypeDonnee.DATE)) {
+            jsonStructure.setCodeDelimiteurDate(nestedJsonStructure.delimiteur().getCode());
+        }
+
+        jsonStructure.setParent(parent);
+
+        jsonStructure.setFields(nestedJsonStructure.children().stream().map(nJ -> jsonStructure(nJ, jsonStructure)).collect(Collectors.toList()));
+
+        return jsonStructure;
+    }
+
+    public ObjectProperty<TypeFichierJson> resultProperty() {
+        return result;
+    }
+
+    public ObjectProperty<TypeFichier> selectedTypeFichierProperty() {
+        return selectedTypeFichier;
+    }
+
+    public ObservableList<TypeFichier> getTypeFichiers() {
+        return typeFichiers;
+    }
+}

--
Gitblit v1.10.0