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