GH-3372: Expose (S)FTP remoteComparator for DSL
Fixes https://github.com/spring-projects/spring-integration/issues/3372 **Cherry-pick to 5.3.x & 5.2.x**
This commit is contained in:
committed by
Gary Russell
parent
059bc896ff
commit
411e9945c3
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.file.dsl;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
@@ -282,6 +283,18 @@ public abstract class RemoteFileInboundChannelAdapterSpec<F, S extends RemoteFil
|
||||
return _this();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a comparator to sort the retrieved list of {@code F} (the Type that represents
|
||||
* the remote file) prior to applying filters and max fetch size.
|
||||
* @param remoteComparator the {@link Comparator} for remote files.
|
||||
* @return the spec.
|
||||
* @since 5.2.9
|
||||
*/
|
||||
public S remoteComparator(Comparator<F> remoteComparator) {
|
||||
this.synchronizer.setComparator(remoteComparator);
|
||||
return _this();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Object, String> getComponentsToRegister() {
|
||||
Map<Object, String> componentsToRegister = new LinkedHashMap<>();
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
@@ -76,7 +77,8 @@ public class SftpTests extends SftpTestSupport {
|
||||
.remoteDirectory("sftpSource")
|
||||
.regexFilter(".*\\.txt$")
|
||||
.localFilenameExpression("#this.toUpperCase() + '.a'")
|
||||
.localDirectory(getTargetLocalDirectory()),
|
||||
.localDirectory(getTargetLocalDirectory())
|
||||
.remoteComparator(Comparator.naturalOrder()),
|
||||
e -> e.id("sftpInboundAdapter").poller(Pollers.fixedDelay(100)))
|
||||
.channel(out)
|
||||
.get();
|
||||
@@ -86,13 +88,13 @@ public class SftpTests extends SftpTestSupport {
|
||||
Object payload = message.getPayload();
|
||||
assertThat(payload).isInstanceOf(File.class);
|
||||
File file = (File) payload;
|
||||
assertThat(file.getName()).isIn(" SFTPSOURCE1.TXT.a", "SFTPSOURCE2.TXT.a");
|
||||
assertThat(file.getName()).isEqualTo(" SFTPSOURCE1.TXT.a");
|
||||
assertThat(file.getAbsolutePath()).contains("localTarget");
|
||||
|
||||
message = out.receive(10_000);
|
||||
assertThat(message).isNotNull();
|
||||
file = (File) message.getPayload();
|
||||
assertThat(file.getName()).isIn(" SFTPSOURCE1.TXT.a", "SFTPSOURCE2.TXT.a");
|
||||
assertThat(file.getName()).isIn("SFTPSOURCE2.TXT.a");
|
||||
assertThat(file.getAbsolutePath()).contains("localTarget");
|
||||
|
||||
registration.destroy();
|
||||
|
||||
Reference in New Issue
Block a user