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