Skip to content

Commit 293cf73

Browse files
artembilangaryrussell
authored andcommitted
GH-3372: Expose (S)FTP remoteComparator for DSL
Fixes #3372 **Cherry-pick to 5.3.x & 5.2.x**
1 parent 24baf78 commit 293cf73

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

spring-integration-file/src/main/java/org/springframework/integration/file/dsl/RemoteFileInboundChannelAdapterSpec.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.integration.file.dsl;
1818

1919
import java.io.File;
20+
import java.util.Comparator;
2021
import java.util.LinkedHashMap;
2122
import java.util.Map;
2223
import java.util.function.Function;
@@ -282,6 +283,18 @@ public S scanner(DirectoryScanner scanner) {
282283
return _this();
283284
}
284285

286+
/**
287+
* Set a comparator to sort the retrieved list of {@code F} (the Type that represents
288+
* the remote file) prior to applying filters and max fetch size.
289+
* @param remoteComparator the {@link Comparator} for remote files.
290+
* @return the spec.
291+
* @since 5.2.9
292+
*/
293+
public S remoteComparator(Comparator<F> remoteComparator) {
294+
this.synchronizer.setComparator(remoteComparator);
295+
return _this();
296+
}
297+
285298
@Override
286299
public Map<Object, String> getComponentsToRegister() {
287300
Map<Object, String> componentsToRegister = new LinkedHashMap<>();

spring-integration-sftp/src/test/java/org/springframework/integration/sftp/dsl/SftpTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.File;
2222
import java.io.InputStream;
23+
import java.util.Comparator;
2324
import java.util.List;
2425
import java.util.regex.Matcher;
2526

@@ -76,7 +77,8 @@ public void testSftpInboundFlow() {
7677
.remoteDirectory("sftpSource")
7778
.regexFilter(".*\\.txt$")
7879
.localFilenameExpression("#this.toUpperCase() + '.a'")
79-
.localDirectory(getTargetLocalDirectory()),
80+
.localDirectory(getTargetLocalDirectory())
81+
.remoteComparator(Comparator.naturalOrder()),
8082
e -> e.id("sftpInboundAdapter").poller(Pollers.fixedDelay(100)))
8183
.channel(out)
8284
.get();
@@ -86,13 +88,13 @@ public void testSftpInboundFlow() {
8688
Object payload = message.getPayload();
8789
assertThat(payload).isInstanceOf(File.class);
8890
File file = (File) payload;
89-
assertThat(file.getName()).isIn(" SFTPSOURCE1.TXT.a", "SFTPSOURCE2.TXT.a");
91+
assertThat(file.getName()).isEqualTo(" SFTPSOURCE1.TXT.a");
9092
assertThat(file.getAbsolutePath()).contains("localTarget");
9193

9294
message = out.receive(10_000);
9395
assertThat(message).isNotNull();
9496
file = (File) message.getPayload();
95-
assertThat(file.getName()).isIn(" SFTPSOURCE1.TXT.a", "SFTPSOURCE2.TXT.a");
97+
assertThat(file.getName()).isIn("SFTPSOURCE2.TXT.a");
9698
assertThat(file.getAbsolutePath()).contains("localTarget");
9799

98100
registration.destroy();

0 commit comments

Comments
 (0)