INT-4302: Add fileExistsMode() to Java DSL

JIRA: https://jira.spring.io/browse/INT-4302

Add `RemoteFileOutboundGatewaySpec#fileExistsMode()`
This commit is contained in:
Artem Bilan
2017-06-23 11:51:37 -04:00
committed by Gary Russell
parent 171d169748
commit 4679c9bdbe
2 changed files with 16 additions and 1 deletions

View File

@@ -32,6 +32,7 @@ import org.springframework.integration.file.filters.FileListFilter;
import org.springframework.integration.file.filters.RegexPatternFileListFilter;
import org.springframework.integration.file.filters.SimplePatternFileListFilter;
import org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway;
import org.springframework.integration.file.support.FileExistsMode;
import org.springframework.messaging.Message;
/**
@@ -338,6 +339,19 @@ public abstract class RemoteFileOutboundGatewaySpec<F, S extends RemoteFileOutbo
return _this();
}
/**
* Determine the action to take when using GET and MGET operations when the file
* already exists locally, or PUT and MPUT when the file exists on the remote
* system.
* @param fileExistsMode the fileExistsMode to set.
* @return the current Spec
*/
public S fileExistsMode(FileExistsMode fileExistsMode) {
this.target.setFileExistsMode(fileExistsMode);
return _this();
}
@Override
public Map<Object, String> getComponentsToRegister() {
Map<Object, String> componentsToRegister = new LinkedHashMap<>();
@@ -351,7 +365,6 @@ public abstract class RemoteFileOutboundGatewaySpec<F, S extends RemoteFileOutbo
return componentsToRegister;
}
/**
* Specify a simple pattern to match remote files (e.g. '*.txt').
* @param pattern the pattern.

View File

@@ -62,6 +62,7 @@ import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Artem Bilan
* @author Gary Russell
*
* @since 5.0
*/
@RunWith(SpringRunner.class)
@@ -170,6 +171,7 @@ public class FtpTests extends FtpTestSupport {
.handle(Ftp.outboundGateway(sessionFactory(),
AbstractRemoteFileOutboundGateway.Command.MGET, "payload")
.options(AbstractRemoteFileOutboundGateway.Option.RECURSIVE)
.fileExistsMode(FileExistsMode.IGNORE)
.filterExpression("name matches 'subFtpSource|.*1.txt'")
.localDirectoryExpression("'" + getTargetLocalDirectoryName() + "' + #remoteDirectory")
.localFilenameExpression("#remoteFileName.replaceFirst('ftpSource', 'localTarget')"))