Skip to content

Commit

Permalink
GH-3372: Expose (S)FTP remoteComparator for DSL
Browse files Browse the repository at this point in the history
Fixes #3372

**Cherry-pick to 5.3.x & 5.2.x**
  • Loading branch information
artembilan authored and garyrussell committed Sep 14, 2020
1 parent ee7ebf3 commit 7f33085
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -282,6 +283,18 @@ public S scanner(DirectoryScanner scanner) {
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<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.File;
import java.io.InputStream;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher;

Expand Down Expand Up @@ -76,7 +77,8 @@ public void testSftpInboundFlow() {
.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();
Expand All @@ -86,13 +88,13 @@ public void testSftpInboundFlow() {
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();
Expand Down

0 comments on commit 7f33085

Please sign in to comment.