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-model/src/main/java/com/megatim/fdxcommons/model/camel/SftpConfiguration.java |  145 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 145 insertions(+), 0 deletions(-)

diff --git a/fdx-commons/fdxcommons-model/src/main/java/com/megatim/fdxcommons/model/camel/SftpConfiguration.java b/fdx-commons/fdxcommons-model/src/main/java/com/megatim/fdxcommons/model/camel/SftpConfiguration.java
new file mode 100644
index 0000000..f731730
--- /dev/null
+++ b/fdx-commons/fdxcommons-model/src/main/java/com/megatim/fdxcommons/model/camel/SftpConfiguration.java
@@ -0,0 +1,145 @@
+package com.megatim.fdxcommons.model.camel;
+
+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(), standaloneHostName(), standalonePort(), standaloneUserName(), standalonePassword());
+    }
+
+    public String fichierRouteURI() throws IOException {
+        return buildURI(fichierRemotePath(), standaloneHostName(), standalonePort(), standaloneUserName(), standalonePassword());
+    }
+
+    public String standaloneRouteURI() throws IOException {
+        return buildURI(standaloneDestinationDir(), standaloneHostName(), standalonePort(), standaloneUserName(), standalonePassword());
+    }
+
+    public String consultationRouteURI() throws IOException {
+        return buildURI(consultationDestinationDir(), consultationHostName(), consultationPort(), consultationUserName(), consultationPassword());
+    }
+
+    public String standaloneTmpDir() throws IOException {
+        return fileProperties.properties().getProperty(CamelProperties.STANDALONE_TMP_DIR_PROPERTY);
+    }
+
+    public String consultationTmpDir() throws IOException {
+        return fileProperties.properties().getProperty(CamelProperties.CONSULTATION_TMP_DIR);
+    }
+
+    private String buildURI(String path, String hostName, int port, String userName, String password) throws IOException {
+        StringBuilder stringBuilder = new StringBuilder();
+        stringBuilder
+                .append(firstURIpart(hostName, port))
+                .append(path)
+                .append(secondURIpart(userName, password));
+        return stringBuilder.toString();
+    }
+
+    private String firstURIpart(String hostName, int port) throws IOException {
+        StringBuilder stringBuilder = new StringBuilder();
+        stringBuilder
+                .append("sftp:")
+                .append(hostName)
+                .append(":")
+                .append(port)
+                .append("/");
+        return stringBuilder.toString();
+    }
+
+    private String secondURIpart(String userName, String password) 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 isStandaloneCorrect() throws IOException {
+        return standaloneRemote()
+                && referentielRemotePath() != null
+                && fichierRemotePath() != null
+                && standaloneDestinationDir() != null
+                && standaloneUserName() != null
+                && standalonePassword() != null
+                && standaloneHostName() != null;
+    }
+
+    public boolean isConsultationCorrect() throws IOException {
+        return consultationRemote()
+                && consultationDestinationDir() != null
+                && consultationUserName() != null
+                && consultationPassword() != null
+                && consultationHostName() != null;
+    }
+
+    private String referentielRemotePath() throws IOException {
+        return fileProperties.properties().getProperty(CamelProperties.REFERENTIEL_REMOTE_PATH_PROPERTY);
+    }
+
+    private String fichierRemotePath() throws IOException {
+        return fileProperties.properties().getProperty(CamelProperties.FICHIER_REMOTE_PATH_PROPERTY);
+    }
+
+    private boolean standaloneRemote() throws IOException {
+        String remoteIntegrationProperty = fileProperties.properties().getProperty(CamelProperties.STANDALONE_REMOTE_DIR_PROPERTY);
+        return remoteIntegrationProperty != null && Boolean.parseBoolean(remoteIntegrationProperty);
+    }
+
+    private boolean consultationRemote() throws IOException {
+        String remoteIntegrationProperty = fileProperties.properties().getProperty(CamelProperties.CONSULTATION_REMOTE_DIR_PROPERTY);
+        return remoteIntegrationProperty != null && Boolean.parseBoolean(remoteIntegrationProperty);
+    }
+
+    private String standaloneDestinationDir() throws IOException {
+        return fileProperties.properties().getProperty(CamelProperties.STANDALONE_DESTINATION_DIR_PROPERTY);
+    }
+
+    private String consultationDestinationDir() throws IOException {
+        return fileProperties.properties().getProperty(CamelProperties.CONSULTATION_DESTINATION_DIR_PROPERTY);
+    }
+
+    private String standaloneUserName() throws IOException {
+        return fileProperties.properties().getProperty(CamelProperties.STANDALONE_USER_NAME);
+    }
+
+    private String standalonePassword() throws IOException {
+        return fileProperties.properties().getProperty(CamelProperties.STANDALONE_PASSWORD);
+    }
+
+    private String standaloneHostName() throws IOException {
+        return fileProperties.properties().getProperty(CamelProperties.STANDALONE_HOST_NAME);
+    }
+
+    private int standalonePort() throws IOException {
+        String portProperty = fileProperties.properties().getProperty(CamelProperties.STANDALONE_PORT);
+        return portProperty != null ? Integer.parseInt(portProperty) : 22;
+    }
+
+    private String consultationUserName() throws IOException {
+        return fileProperties.properties().getProperty(CamelProperties.CONSULTATION_USER_NAME);
+    }
+
+    private String consultationPassword() throws IOException {
+        return fileProperties.properties().getProperty(CamelProperties.CONSULTATION_PASSWORD);
+    }
+
+    private String consultationHostName() throws IOException {
+        return fileProperties.properties().getProperty(CamelProperties.CONSULTATION_HOST_NAME);
+    }
+
+    private int consultationPort() throws IOException {
+        String portProperty = fileProperties.properties().getProperty(CamelProperties.CONSULTATION_PORT);
+        return portProperty != null ? Integer.parseInt(portProperty) : 22;
+    }
+
+}

--
Gitblit v1.10.0