вынес настройки удаленной 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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.integration.annotation.InboundChannelAdapter;
|
import org.springframework.integration.annotation.InboundChannelAdapter;
|
||||||
|
|
@ -24,6 +25,7 @@ import java.io.File;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@ConditionalOnProperty(value="import-dbf-service.store.sftp-in.sftp-src-dir")
|
||||||
public class SFTPConfig {
|
public class SFTPConfig {
|
||||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
private final ImportDBFServiceSettings settings;
|
private final ImportDBFServiceSettings settings;
|
||||||
|
|
@ -36,10 +38,10 @@ public class SFTPConfig {
|
||||||
@Bean
|
@Bean
|
||||||
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {
|
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {
|
||||||
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
|
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
|
||||||
factory.setHost(settings.getStore().getServerIp());
|
factory.setHost(settings.getStore().getSftpIn().getServerIp());
|
||||||
factory.setPort(settings.getStore().getServerPort());
|
factory.setPort(settings.getStore().getSftpIn().getServerPort());
|
||||||
factory.setUser(settings.getStore().getUser());
|
factory.setUser(settings.getStore().getSftpIn().getUser());
|
||||||
factory.setPassword(settings.getStore().getPassword());
|
factory.setPassword(settings.getStore().getSftpIn().getPassword());
|
||||||
factory.setAllowUnknownKeys(true);
|
factory.setAllowUnknownKeys(true);
|
||||||
return new CachingSessionFactory<>(factory);
|
return new CachingSessionFactory<>(factory);
|
||||||
}
|
}
|
||||||
|
|
@ -56,7 +58,7 @@ public class SFTPConfig {
|
||||||
SftpInboundFileSynchronizer fileSync = new SftpInboundFileSynchronizer(sftpSessionFactory());
|
SftpInboundFileSynchronizer fileSync = new SftpInboundFileSynchronizer(sftpSessionFactory());
|
||||||
fileSync.setDeleteRemoteFiles(true);
|
fileSync.setDeleteRemoteFiles(true);
|
||||||
fileSync.setTemporaryFileSuffix(".tmp");
|
fileSync.setTemporaryFileSuffix(".tmp");
|
||||||
fileSync.setRemoteDirectory(settings.getStore().getSftpSrcDir());
|
fileSync.setRemoteDirectory(settings.getStore().getSftpIn().getSftpSrcDir());
|
||||||
fileSync.setFilter(new AcceptAllFileListFilter<>());
|
fileSync.setFilter(new AcceptAllFileListFilter<>());
|
||||||
return fileSync;
|
return fileSync;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package ru.spcex.clearing.dbf.importer.config.settings;
|
package ru.spcex.clearing.dbf.importer.config.settings;
|
||||||
|
|
||||||
|
import ru.spcex.platform.utils.config.SftpInboundFolderSetting;
|
||||||
|
|
||||||
public class Store {
|
public class Store {
|
||||||
|
|
||||||
private String srcDir;
|
private String srcDir;
|
||||||
|
|
@ -7,12 +9,7 @@ public class Store {
|
||||||
private String outDirError;
|
private String outDirError;
|
||||||
private boolean deleteSrcFiles = true;
|
private boolean deleteSrcFiles = true;
|
||||||
//sftp settings
|
//sftp settings
|
||||||
private String sftpSrcDir;
|
private SftpInboundFolderSetting sftpIn;
|
||||||
private String user;
|
|
||||||
private String password;
|
|
||||||
private String serverIp;
|
|
||||||
private int serverPort;
|
|
||||||
|
|
||||||
public String getSrcDir() {
|
public String getSrcDir() {
|
||||||
return srcDir;
|
return srcDir;
|
||||||
}
|
}
|
||||||
|
|
@ -45,43 +42,11 @@ public class Store {
|
||||||
this.outDirError = outDirError;
|
this.outDirError = outDirError;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUser() {
|
public SftpInboundFolderSetting getSftpIn() {
|
||||||
return user;
|
return sftpIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUser(String user) {
|
public void setSftpIn(SftpInboundFolderSetting sftpIn) {
|
||||||
this.user = user;
|
this.sftpIn = sftpIn;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,11 @@ import-dbf-service.common.insert-batch-size=100
|
||||||
import-dbf-service.common.threads-count=10
|
import-dbf-service.common.threads-count=10
|
||||||
|
|
||||||
#sftpSrcDir
|
#sftpSrcDir
|
||||||
import-dbf-service.store.sftp-src-dir=clearing_importer_sftp
|
import-dbf-service.store.sftp-in.sftp-src-dir=clearing_importer_sftp
|
||||||
import-dbf-service.store.user=user
|
import-dbf-service.store.sftp-in.user=user
|
||||||
import-dbf-service.store.password=*********
|
import-dbf-service.store.sftp-in.password=*********
|
||||||
import-dbf-service.store.server-ip=127.0.0.1
|
import-dbf-service.store.sftp-in.server-ip=127.0.0.1
|
||||||
import-dbf-service.store.server-port=22
|
import-dbf-service.store.sftp-in.server-port=22
|
||||||
|
|
||||||
import-dbf-service.hazelcast.cluster-members=10.200.200.181:5701
|
import-dbf-service.hazelcast.cluster-members=10.200.200.181:5701
|
||||||
import-dbf-service.hazelcast.login=dev
|
import-dbf-service.hazelcast.login=dev
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import java.io.File;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnProperty(value="import-swt-service.store.sftp-src-dir")
|
@ConditionalOnProperty(value="import-swt-service.store.sftp-in.sftp-src-dir")
|
||||||
public class SFTPConfig {
|
public class SFTPConfig {
|
||||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
private final ImportSWTServiceSettings settings;
|
private final ImportSWTServiceSettings settings;
|
||||||
|
|
@ -38,10 +38,10 @@ public class SFTPConfig {
|
||||||
@Bean
|
@Bean
|
||||||
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {
|
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {
|
||||||
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
|
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
|
||||||
factory.setHost(settings.getStore().getServerIp());
|
factory.setHost(settings.getStore().getSftpIn().getServerIp());
|
||||||
factory.setPort(settings.getStore().getServerPort());
|
factory.setPort(settings.getStore().getSftpIn().getServerPort());
|
||||||
factory.setUser(settings.getStore().getUser());
|
factory.setUser(settings.getStore().getSftpIn().getUser());
|
||||||
factory.setPassword(settings.getStore().getPassword());
|
factory.setPassword(settings.getStore().getSftpIn().getPassword());
|
||||||
factory.setAllowUnknownKeys(true);
|
factory.setAllowUnknownKeys(true);
|
||||||
return new CachingSessionFactory<>(factory);
|
return new CachingSessionFactory<>(factory);
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +58,7 @@ public class SFTPConfig {
|
||||||
SftpInboundFileSynchronizer fileSync = new SftpInboundFileSynchronizer(sftpSessionFactory());
|
SftpInboundFileSynchronizer fileSync = new SftpInboundFileSynchronizer(sftpSessionFactory());
|
||||||
fileSync.setDeleteRemoteFiles(true);
|
fileSync.setDeleteRemoteFiles(true);
|
||||||
fileSync.setTemporaryFileSuffix(".tmp");
|
fileSync.setTemporaryFileSuffix(".tmp");
|
||||||
fileSync.setRemoteDirectory(settings.getStore().getSftpSrcDir());
|
fileSync.setRemoteDirectory(settings.getStore().getSftpIn().getSftpSrcDir());
|
||||||
fileSync.setFilter(new AcceptAllFileListFilter<>());
|
fileSync.setFilter(new AcceptAllFileListFilter<>());
|
||||||
return fileSync;
|
return fileSync;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,14 @@
|
||||||
package ru.spcex.clearing.swt.importer.config.settings;
|
package ru.spcex.clearing.swt.importer.config.settings;
|
||||||
|
|
||||||
|
import ru.spcex.platform.utils.config.SftpInboundFolderSetting;
|
||||||
|
|
||||||
public class Store {
|
public class Store {
|
||||||
|
|
||||||
private String srcDir;
|
private String srcDir;
|
||||||
private String outDir;
|
private String outDir;
|
||||||
private String outDirError;
|
private String outDirError;
|
||||||
private boolean deleteSrcFiles = true;
|
private boolean deleteSrcFiles = true;
|
||||||
//sftp settings
|
private SftpInboundFolderSetting sftpIn;
|
||||||
private String sftpSrcDir;
|
|
||||||
private String user;
|
|
||||||
private String password;
|
|
||||||
private String serverIp;
|
|
||||||
private int serverPort;
|
|
||||||
|
|
||||||
public String getSrcDir() {
|
public String getSrcDir() {
|
||||||
return srcDir;
|
return srcDir;
|
||||||
|
|
@ -45,43 +42,11 @@ public class Store {
|
||||||
this.outDirError = outDirError;
|
this.outDirError = outDirError;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSftpSrcDir() {
|
public SftpInboundFolderSetting getSftpIn() {
|
||||||
return sftpSrcDir;
|
return sftpIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSftpSrcDir(String sftpSrcDir) {
|
public void setSftpIn(SftpInboundFolderSetting sftpIn) {
|
||||||
this.sftpSrcDir = sftpSrcDir;
|
this.sftpIn = sftpIn;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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/
|
import-swt-service.store.out-dir-error=clearing-parent/swt-importer/src/test/java/ru/spcex/clearing/swt/importer/files/importer/error/
|
||||||
|
|
||||||
#sftpSrcDir
|
#sftpSrcDir
|
||||||
import-swt-service.store.sftp-src-dir=/path/to/sftp/folder
|
import-swt-service.store.sftp-in.sftp-src-dir=/path/to/sftp/folder
|
||||||
import-swt-service.store.user=user
|
import-swt-service.store.sftp-in.user=user
|
||||||
import-swt-service.store.password=*********
|
import-swt-service.store.sftp-in.password=*********
|
||||||
import-swt-service.store.server-ip=127.0.0.1
|
import-swt-service.store.sftp-in.server-ip=127.0.0.1
|
||||||
import-swt-service.store.server-port=22
|
import-swt-service.store.sftp-in.server-port=22
|
||||||
|
|
||||||
import-swt-service.common.encoding-source=cp866
|
import-swt-service.common.encoding-source=cp866
|
||||||
import-swt-service.common.insert-batch-size=100
|
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