вынес настройки удаленной SFTP папки с файлами в отдельный класс
теперь модуль можно запустить без SFTP (при отсутствии соответствующих настроек)
This commit is contained in:
parent
a0d5baef17
commit
b36ea99b28
7 changed files with 86 additions and 105 deletions
|
|
@ -4,6 +4,7 @@ import com.jcraft.jsch.ChannelSftp;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.integration.annotation.InboundChannelAdapter;
|
||||
|
|
@ -24,6 +25,7 @@ import java.io.File;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnProperty(value="import-dbf-service.store.sftp-in.sftp-src-dir")
|
||||
public class SFTPConfig {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final ImportDBFServiceSettings settings;
|
||||
|
|
@ -36,10 +38,10 @@ public class SFTPConfig {
|
|||
@Bean
|
||||
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {
|
||||
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
|
||||
factory.setHost(settings.getStore().getServerIp());
|
||||
factory.setPort(settings.getStore().getServerPort());
|
||||
factory.setUser(settings.getStore().getUser());
|
||||
factory.setPassword(settings.getStore().getPassword());
|
||||
factory.setHost(settings.getStore().getSftpIn().getServerIp());
|
||||
factory.setPort(settings.getStore().getSftpIn().getServerPort());
|
||||
factory.setUser(settings.getStore().getSftpIn().getUser());
|
||||
factory.setPassword(settings.getStore().getSftpIn().getPassword());
|
||||
factory.setAllowUnknownKeys(true);
|
||||
return new CachingSessionFactory<>(factory);
|
||||
}
|
||||
|
|
@ -56,7 +58,7 @@ public class SFTPConfig {
|
|||
SftpInboundFileSynchronizer fileSync = new SftpInboundFileSynchronizer(sftpSessionFactory());
|
||||
fileSync.setDeleteRemoteFiles(true);
|
||||
fileSync.setTemporaryFileSuffix(".tmp");
|
||||
fileSync.setRemoteDirectory(settings.getStore().getSftpSrcDir());
|
||||
fileSync.setRemoteDirectory(settings.getStore().getSftpIn().getSftpSrcDir());
|
||||
fileSync.setFilter(new AcceptAllFileListFilter<>());
|
||||
return fileSync;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package ru.spcex.clearing.dbf.importer.config.settings;
|
||||
|
||||
import ru.spcex.platform.utils.config.SftpInboundFolderSetting;
|
||||
|
||||
public class Store {
|
||||
|
||||
private String srcDir;
|
||||
|
|
@ -7,12 +9,7 @@ public class Store {
|
|||
private String outDirError;
|
||||
private boolean deleteSrcFiles = true;
|
||||
//sftp settings
|
||||
private String sftpSrcDir;
|
||||
private String user;
|
||||
private String password;
|
||||
private String serverIp;
|
||||
private int serverPort;
|
||||
|
||||
private SftpInboundFolderSetting sftpIn;
|
||||
public String getSrcDir() {
|
||||
return srcDir;
|
||||
}
|
||||
|
|
@ -45,43 +42,11 @@ public class Store {
|
|||
this.outDirError = outDirError;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
public SftpInboundFolderSetting getSftpIn() {
|
||||
return sftpIn;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getServerIp() {
|
||||
return serverIp;
|
||||
}
|
||||
|
||||
public void setServerIp(String serverIp) {
|
||||
this.serverIp = serverIp;
|
||||
}
|
||||
|
||||
public int getServerPort() {
|
||||
return serverPort;
|
||||
}
|
||||
|
||||
public void setServerPort(int serverPort) {
|
||||
this.serverPort = serverPort;
|
||||
}
|
||||
|
||||
public String getSftpSrcDir() {
|
||||
return sftpSrcDir;
|
||||
}
|
||||
|
||||
public void setSftpSrcDir(String sftpSrcDir) {
|
||||
this.sftpSrcDir = sftpSrcDir;
|
||||
public void setSftpIn(SftpInboundFolderSetting sftpIn) {
|
||||
this.sftpIn = sftpIn;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,11 +14,11 @@ import-dbf-service.common.insert-batch-size=100
|
|||
import-dbf-service.common.threads-count=10
|
||||
|
||||
#sftpSrcDir
|
||||
import-dbf-service.store.sftp-src-dir=clearing_importer_sftp
|
||||
import-dbf-service.store.user=user
|
||||
import-dbf-service.store.password=*********
|
||||
import-dbf-service.store.server-ip=127.0.0.1
|
||||
import-dbf-service.store.server-port=22
|
||||
import-dbf-service.store.sftp-in.sftp-src-dir=clearing_importer_sftp
|
||||
import-dbf-service.store.sftp-in.user=user
|
||||
import-dbf-service.store.sftp-in.password=*********
|
||||
import-dbf-service.store.sftp-in.server-ip=127.0.0.1
|
||||
import-dbf-service.store.sftp-in.server-port=22
|
||||
|
||||
import-dbf-service.hazelcast.cluster-members=10.200.200.181:5701
|
||||
import-dbf-service.hazelcast.login=dev
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import java.io.File;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnProperty(value="import-swt-service.store.sftp-src-dir")
|
||||
@ConditionalOnProperty(value="import-swt-service.store.sftp-in.sftp-src-dir")
|
||||
public class SFTPConfig {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final ImportSWTServiceSettings settings;
|
||||
|
|
@ -38,10 +38,10 @@ public class SFTPConfig {
|
|||
@Bean
|
||||
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {
|
||||
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
|
||||
factory.setHost(settings.getStore().getServerIp());
|
||||
factory.setPort(settings.getStore().getServerPort());
|
||||
factory.setUser(settings.getStore().getUser());
|
||||
factory.setPassword(settings.getStore().getPassword());
|
||||
factory.setHost(settings.getStore().getSftpIn().getServerIp());
|
||||
factory.setPort(settings.getStore().getSftpIn().getServerPort());
|
||||
factory.setUser(settings.getStore().getSftpIn().getUser());
|
||||
factory.setPassword(settings.getStore().getSftpIn().getPassword());
|
||||
factory.setAllowUnknownKeys(true);
|
||||
return new CachingSessionFactory<>(factory);
|
||||
}
|
||||
|
|
@ -58,7 +58,7 @@ public class SFTPConfig {
|
|||
SftpInboundFileSynchronizer fileSync = new SftpInboundFileSynchronizer(sftpSessionFactory());
|
||||
fileSync.setDeleteRemoteFiles(true);
|
||||
fileSync.setTemporaryFileSuffix(".tmp");
|
||||
fileSync.setRemoteDirectory(settings.getStore().getSftpSrcDir());
|
||||
fileSync.setRemoteDirectory(settings.getStore().getSftpIn().getSftpSrcDir());
|
||||
fileSync.setFilter(new AcceptAllFileListFilter<>());
|
||||
return fileSync;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,14 @@
|
|||
package ru.spcex.clearing.swt.importer.config.settings;
|
||||
|
||||
import ru.spcex.platform.utils.config.SftpInboundFolderSetting;
|
||||
|
||||
public class Store {
|
||||
|
||||
private String srcDir;
|
||||
private String outDir;
|
||||
private String outDirError;
|
||||
private boolean deleteSrcFiles = true;
|
||||
//sftp settings
|
||||
private String sftpSrcDir;
|
||||
private String user;
|
||||
private String password;
|
||||
private String serverIp;
|
||||
private int serverPort;
|
||||
private SftpInboundFolderSetting sftpIn;
|
||||
|
||||
public String getSrcDir() {
|
||||
return srcDir;
|
||||
|
|
@ -45,43 +42,11 @@ public class Store {
|
|||
this.outDirError = outDirError;
|
||||
}
|
||||
|
||||
public String getSftpSrcDir() {
|
||||
return sftpSrcDir;
|
||||
public SftpInboundFolderSetting getSftpIn() {
|
||||
return sftpIn;
|
||||
}
|
||||
|
||||
public void setSftpSrcDir(String sftpSrcDir) {
|
||||
this.sftpSrcDir = sftpSrcDir;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getServerIp() {
|
||||
return serverIp;
|
||||
}
|
||||
|
||||
public void setServerIp(String serverIp) {
|
||||
this.serverIp = serverIp;
|
||||
}
|
||||
|
||||
public int getServerPort() {
|
||||
return serverPort;
|
||||
}
|
||||
|
||||
public void setServerPort(int serverPort) {
|
||||
this.serverPort = serverPort;
|
||||
public void setSftpIn(SftpInboundFolderSetting sftpIn) {
|
||||
this.sftpIn = sftpIn;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ import-swt-service.store.out-dir=clearing-parent/swt-importer/src/test/java/ru/s
|
|||
import-swt-service.store.out-dir-error=clearing-parent/swt-importer/src/test/java/ru/spcex/clearing/swt/importer/files/importer/error/
|
||||
|
||||
#sftpSrcDir
|
||||
import-swt-service.store.sftp-src-dir=/path/to/sftp/folder
|
||||
import-swt-service.store.user=user
|
||||
import-swt-service.store.password=*********
|
||||
import-swt-service.store.server-ip=127.0.0.1
|
||||
import-swt-service.store.server-port=22
|
||||
import-swt-service.store.sftp-in.sftp-src-dir=/path/to/sftp/folder
|
||||
import-swt-service.store.sftp-in.user=user
|
||||
import-swt-service.store.sftp-in.password=*********
|
||||
import-swt-service.store.sftp-in.server-ip=127.0.0.1
|
||||
import-swt-service.store.sftp-in.server-port=22
|
||||
|
||||
import-swt-service.common.encoding-source=cp866
|
||||
import-swt-service.common.insert-batch-size=100
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
package ru.spcex.platform.utils.config;
|
||||
|
||||
public class SftpInboundFolderSetting {
|
||||
private String sftpSrcDir;
|
||||
private String user;
|
||||
private String password;
|
||||
private String serverIp;
|
||||
private int serverPort;
|
||||
|
||||
public String getSftpSrcDir() {
|
||||
return sftpSrcDir;
|
||||
}
|
||||
|
||||
public void setSftpSrcDir(String sftpSrcDir) {
|
||||
this.sftpSrcDir = sftpSrcDir;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getServerIp() {
|
||||
return serverIp;
|
||||
}
|
||||
|
||||
public void setServerIp(String serverIp) {
|
||||
this.serverIp = serverIp;
|
||||
}
|
||||
|
||||
public int getServerPort() {
|
||||
return serverPort;
|
||||
}
|
||||
|
||||
public void setServerPort(int serverPort) {
|
||||
this.serverPort = serverPort;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue