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;
|
}
|
|
}
|