Kenmegne
7 days ago 23a46b4be35277e06ec89f48730eeb694e686be8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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;
    }
 
}