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/service/impl/camel/config/SftpConfiguration.java |  111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 111 insertions(+), 0 deletions(-)

diff --git a/apifdxweb/api/apifdxweb-service-impl/src/main/java/com/megatim/apifdxweb/service/impl/camel/config/SftpConfiguration.java b/apifdxweb/api/apifdxweb-service-impl/src/main/java/com/megatim/apifdxweb/service/impl/camel/config/SftpConfiguration.java
new file mode 100644
index 0000000..9ab46bb
--- /dev/null
+++ b/apifdxweb/api/apifdxweb-service-impl/src/main/java/com/megatim/apifdxweb/service/impl/camel/config/SftpConfiguration.java
@@ -0,0 +1,111 @@
+package com.megatim.apifdxweb.service.impl.camel.config;
+
+import java.io.IOException;
+
+public class SftpConfiguration {
+
+    private final FileProperties fileProperties;
+
+    public SftpConfiguration(FileProperties fileProperties) {
+        this.fileProperties = fileProperties;
+    }
+
+    public String referentielRouteURI() throws IOException {
+        return buildURI(referentielRemotePath());
+    }
+
+    public String fichierRouteURI() throws IOException {
+        return buildURI(fichierRemotePath());
+    }
+
+    public String standaloneRouteURI() throws IOException {
+        return buildURI(standaloneDestinationRemotePath());
+    }
+
+    public String standaloneTmpRouteURI() throws IOException {
+        return "file:" + standaloneTmpDir() + "?include=.*.txt" + routeParameters();
+    }
+    
+    public String standaloneTmpDir() throws IOException {
+        return fileProperties.properties().getProperty("fdx.api.integration-standalone-temp-dir");
+    }
+
+    private String routeParameters() {
+        return "&moveFailed=error&delete=true&readLock=changed";
+    }
+
+    private String buildURI(String path) throws IOException {
+        StringBuilder stringBuilder = new StringBuilder();
+        stringBuilder
+                .append(firstURIpart())
+                .append(path)
+                .append(secondURIpart());
+        return stringBuilder.toString();
+    }
+
+    private String firstURIpart() throws IOException {
+        StringBuilder stringBuilder = new StringBuilder();
+        stringBuilder
+                .append("sftp:")
+                .append(hostName())
+                .append(":")
+                .append(port())
+                .append("/");
+        return stringBuilder.toString();
+    }
+
+    private String secondURIpart() throws IOException {
+        StringBuilder stringBuilder = new StringBuilder();
+        stringBuilder
+                .append("?username=").append(userName())
+                .append("&password=").append(password())
+                .append("&streamDownload=true&stepwise=false&disconnect=true&useUserKnownHostsFile=false&readLock=changed&readLockLoggingLevel=ERROR")
+                .append("&jschLoggingLevel=ERROR&runLoggingLevel=OFF&moveFailed=error&delete=true");
+        return stringBuilder.toString();
+    }
+
+    public boolean isCorrect() throws IOException {
+        return standaloneRemote()
+                && referentielRemotePath() != null
+                && fichierRemotePath() != null
+                && standaloneDestinationRemotePath() != null
+                && userName() != null
+                && password() != null
+                && hostName() != null;
+    }
+
+    private String referentielRemotePath() throws IOException {
+        return fileProperties.properties().getProperty("fdx.api.referentiel-integration-remote-path");
+    }
+
+    private String fichierRemotePath() throws IOException {
+        return fileProperties.properties().getProperty("fdx.api.fichier-integration-remote-path");
+    }
+
+    private boolean standaloneRemote() throws IOException {
+        String remoteIntegrationProperty = fileProperties.properties().getProperty("fdx.integration-standalone-remote");
+        return remoteIntegrationProperty != null && Boolean.parseBoolean(remoteIntegrationProperty);
+    }
+
+    private String standaloneDestinationRemotePath() throws IOException {
+        return fileProperties.properties().getProperty("fdx.api.integration-standalone-destination-dir");
+    }
+
+    private String userName() throws IOException {
+        return fileProperties.properties().getProperty("fdx.integration-standalone-username");
+    }
+
+    private String password() throws IOException {
+        return fileProperties.properties().getProperty("fdx.integration-standalone-password");
+    }
+
+    private String hostName() throws IOException {
+        return fileProperties.properties().getProperty("fdx.integration-standalone-hostname");
+    }
+
+    private int port() throws IOException {
+        String portProperty = fileProperties.properties().getProperty("fdx.integration-standalone-port");
+        return portProperty != null ? Integer.parseInt(portProperty) : 22;
+    }
+
+}

--
Gitblit v1.10.0