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/database/queries/metadata/JsonFdxTableStructure.java |   75 +++++++++++++++++++++++++++++++++++++
 1 files changed, 75 insertions(+), 0 deletions(-)

diff --git a/fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/database/queries/metadata/JsonFdxTableStructure.java b/fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/database/queries/metadata/JsonFdxTableStructure.java
new file mode 100644
index 0000000..747426d
--- /dev/null
+++ b/fdx-commons/fdxcommons-tools/src/main/java/com/megatim/fdxcommons/tools/database/queries/metadata/JsonFdxTableStructure.java
@@ -0,0 +1,75 @@
+/*
+ * 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.database.queries.metadata;
+
+import com.megatim.fdxcommons.model.enumeration.TypeDonnee;
+import com.megatim.fdxcommons.model.integration.json.JsonStructure;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import javax.naming.NamingException;
+
+/**
+ *
+ * @author ASUS
+ */
+public class JsonFdxTableStructure {
+
+    private final String referentielVersion;
+    private final String codeTypeFichier;
+    private final Connection connection;
+
+    public JsonFdxTableStructure(String referentielVersion, String codeTypeFichier, Connection connection) {
+        this.referentielVersion = referentielVersion;
+        this.codeTypeFichier = codeTypeFichier;
+        this.connection = connection;
+    }
+
+    public JsonStructure jsonStructure() throws NamingException, SQLException {
+        JsonStructure jsonStructure = null;
+        Long jsonStructureId = jsonStructureId();
+
+        if (jsonStructureId != null) {
+            String query = "SELECT * FROM JsonStructure j where j.id = ?";
+
+            try ( PreparedStatement stmt = connection.prepareStatement(query)) {
+                stmt.setLong(1, jsonStructureId);
+                ResultSet resultSet = stmt.executeQuery();
+
+                if (resultSet.next()) {
+                    jsonStructure = new JsonStructure();
+                    jsonStructure.setId(resultSet.getLong("id"));
+                    jsonStructure.setLengthh(resultSet.getInt("lengthh"));
+                    jsonStructure.setTypeDonnee(TypeDonnee.fromValeur(resultSet.getString("typedonnee")));
+                    jsonStructure.setName(resultSet.getString("name"));
+                    jsonStructure.setRequired(resultSet.getBoolean("required"));
+                    jsonStructure.setCollection(resultSet.getBoolean("collection"));
+                    jsonStructure.setFormatDate(resultSet.getString("formatdate"));
+                    
+                }
+            }
+        }
+
+        return jsonStructure;
+    }
+
+    private Long jsonStructureId() throws SQLException {
+        String query = "SELECT json_structure_id FROM typeFichierJson t WHERE t.type_fichier_code = ? AND t.referentiel_version = ?";
+
+        try ( PreparedStatement stmt = connection.prepareStatement(query)) {
+            stmt.setString(1, codeTypeFichier);
+            stmt.setString(2, referentielVersion);
+            ResultSet resultSet = stmt.executeQuery();
+
+            if (resultSet.next()) {
+                return resultSet.getLong(1);
+
+            }
+
+        }
+        return null;
+    }
+}

--
Gitblit v1.10.0