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

---
 apifdxweb/api/apifdxweb-service-impl/src/main/java/com/megatim/apifdxweb/impl/tools/Utilities.java |  100 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 100 insertions(+), 0 deletions(-)

diff --git a/apifdxweb/api/apifdxweb-service-impl/src/main/java/com/megatim/apifdxweb/impl/tools/Utilities.java b/apifdxweb/api/apifdxweb-service-impl/src/main/java/com/megatim/apifdxweb/impl/tools/Utilities.java
new file mode 100644
index 0000000..2a54215
--- /dev/null
+++ b/apifdxweb/api/apifdxweb-service-impl/src/main/java/com/megatim/apifdxweb/impl/tools/Utilities.java
@@ -0,0 +1,100 @@
+/*
+ * 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.apifdxweb.impl.tools;
+
+import com.megatim.apifdxweb.tools.AppContext;
+import com.megatim.apifdxweb.tools.exceptions.ApplicationServerException;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import javax.ws.rs.core.MultivaluedMap;
+import org.jboss.resteasy.plugins.providers.multipart.InputPart;
+
+/**
+ *
+ * @author ASUS
+ */
+public class Utilities {
+
+//    public static boolean arePropertiesOk() {
+//        boolean dirOk = AppContext.INTEGRATION_STANDALONE_DESTINATION_DIR != null && !AppContext.INTEGRATION_STANDALONE_DESTINATION_DIR.isEmpty()
+//                && AppContext.INTEGRATION_STANDALONE_TEMP_DIR != null && !AppContext.INTEGRATION_STANDALONE_TEMP_DIR.isEmpty()
+//                && Files.exists(Paths.get(AppContext.INTEGRATION_STANDALONE_TEMP_DIR));
+//        System.out.println("dirOk = " + dirOk);
+//
+//        if (!AppContext.INTEGRATION_STANDALONE_IS_REMOTE) {
+//            return dirOk;
+//        } else {
+//            boolean paramsOk = AppContext.INTEGRATION_STANDALONE_HOSTNAME != null && !AppContext.INTEGRATION_STANDALONE_HOSTNAME.isEmpty()
+//                    && AppContext.INTEGRATION_STANDALONE_PASSWORD != null && !AppContext.INTEGRATION_STANDALONE_PASSWORD.isEmpty()
+//                    && AppContext.INTEGRATION_STANDALONE_USERNAME != null && !AppContext.INTEGRATION_STANDALONE_USERNAME.isEmpty();
+//
+//            System.out.println("paramsOk = " + paramsOk);
+//            return dirOk && paramsOk;
+//        }
+//    }
+
+    public static File saveFileToDisk(List<InputPart> inputParts) throws ApplicationServerException {
+
+        int bufferSize = 1024;
+        File customDir = new File(AppContext.UPLOAD_DIR);
+
+        //Si le repertoire n'existe pas, on crée
+        if (!customDir.exists()) {
+            //On crée le repertoire
+            customDir.mkdir();
+        }
+
+        if (inputParts != null) {
+            for (InputPart inputPart : inputParts) {
+                MultivaluedMap<String, String> header = inputPart.getHeaders();
+                try {
+                    String fileName = getFileName(header);
+                    InputStream inputStream = inputPart.getBody(InputStream.class, null);
+                    fileName = customDir + File.separator + fileName;
+                    File file = writeFile(inputStream, fileName, bufferSize);
+                    return file;
+                } catch (IOException ex) {
+                    ex.printStackTrace();
+                    throw new ApplicationServerException();
+                }
+            }
+        }
+        return null;
+    }
+
+    private static String getFileName(MultivaluedMap<String, String> header) {
+        String[] contentDisposition = header.getFirst("Content-Disposition").split(";");
+        for (String filename : contentDisposition) {
+            if ((filename.trim().startsWith("filename"))) {
+                String[] name = filename.split("=");
+                String finalFileName = name[1].trim().replaceAll("\"", "");
+                return finalFileName;
+            }
+        }
+        return null;
+    }
+
+    private static File writeFile(InputStream input, String filename, int bufferSize) throws IOException {
+
+        File file = new File(filename);
+        if (!file.exists()) {
+            file.createNewFile();
+        }
+
+        try ( FileOutputStream fop = new FileOutputStream(file)) {
+            byte[] buffer = new byte[bufferSize];
+            int n = 0;
+            while (-1 != (n = input.read(buffer))) {
+                fop.write(buffer, 0, n);
+            }
+            fop.flush();
+        }
+
+        return file;
+    }
+}

--
Gitblit v1.10.0