Skip to content

Commit

Permalink
feat: Add 'outputFiles' property with a map of file name / URI
Browse files Browse the repository at this point in the history
Fixes #108
  • Loading branch information
loicmathieu committed May 20, 2024
1 parent 42ddfc7 commit 8adaf52
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/io/kestra/plugin/fs/vfs/Downloads.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import jakarta.validation.constraints.NotNull;
import java.net.URI;
import java.util.AbstractMap;
import java.util.Map;
import java.util.stream.Collectors;

import static io.kestra.core.utils.Rethrow.throwFunction;
Expand Down Expand Up @@ -105,6 +107,10 @@ public Output run(RunContext runContext) throws Exception {
}))
.collect(Collectors.toList());

Map<String, URI> outputFiles = list.stream()
.map(file -> new AbstractMap.SimpleEntry<>(file.getName(), file.getPath()))
.collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue()));

if (this.action != null) {
VfsService.performAction(
runContext,
Expand All @@ -119,6 +125,7 @@ public Output run(RunContext runContext) throws Exception {
return Downloads.Output
.builder()
.files(list)
.outputFiles(outputFiles)
.build();
}
}
Expand All @@ -138,5 +145,10 @@ public static class Output implements io.kestra.core.models.tasks.Output {
)
@PluginProperty(additionalProperties = io.kestra.plugin.fs.vfs.models.File.class)
private final java.util.List<io.kestra.plugin.fs.vfs.models.File> files;

@Schema(
title = "The downloaded files as a map of from/to URIs."
)
private final Map<String, URI> outputFiles;
}
}
2 changes: 2 additions & 0 deletions src/test/java/io/kestra/plugin/fs/ftp/DownloadsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void run_DeleteAfterDownloads() throws Exception {

assertThat(run.getFiles().size(), is(2));
assertThat(run.getFiles().get(0).getPath().getPath(), endsWith(".txt"));
assertThat(run.getOutputFiles().size(), is(2));

assertThat(ftpUtils.list(toUploadDir).getFiles().isEmpty(), is(true));
}
Expand Down Expand Up @@ -75,6 +76,7 @@ void run_NoneAfterDownloads() throws Exception {

assertThat(run.getFiles().size(), is(2));
assertThat(run.getFiles().get(0).getPath().getPath(), endsWith(".txt"));
assertThat(run.getOutputFiles().size(), is(2));

assertThat(ftpUtils.list(toUploadDir).getFiles().size(), is(2));
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/io/kestra/plugin/fs/sftp/DownloadsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void run_DeleteAfterDownloads() throws Exception {

assertThat(run.getFiles().size(), is(2));
assertThat(run.getFiles().get(0).getPath().getPath(), endsWith(".txt"));
assertThat(run.getOutputFiles().size(), is(2));

assertThat(sftpUtils.list(toUploadDir).getFiles().isEmpty(), is(true));
}
Expand Down Expand Up @@ -75,6 +76,7 @@ void run_NoneAfterDownloads() throws Exception {

assertThat(run.getFiles().size(), is(2));
assertThat(run.getFiles().get(0).getPath().getPath(), endsWith(".txt"));
assertThat(run.getOutputFiles().size(), is(2));

assertThat(sftpUtils.list(toUploadDir).getFiles().size(), is(2));
}
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/io/kestra/plugin/fs/smb/DownloadsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void run_DeleteAfterDownloads() throws Exception {

assertThat(run.getFiles().size(), is(2));
assertThat(run.getFiles().get(0).getPath().getPath(), endsWith(".txt"));
assertThat(run.getOutputFiles().size(), is(2));

assertThat(smbUtils.list(toUploadDir).getFiles().isEmpty(), is(true));
}
Expand Down Expand Up @@ -70,6 +71,7 @@ void run_MoveAfterDownloads() throws Exception {

assertThat(run.getFiles().size(), is(2));
assertThat(run.getFiles().get(0).getPath().getPath(), endsWith(".txt"));
assertThat(run.getOutputFiles().size(), is(2));

run = task.run(TestsUtils.mockRunContext(runContextFactory, task, ImmutableMap.of()));
assertThat(run.getFiles().isEmpty(), is(true));
Expand All @@ -80,6 +82,7 @@ void run_MoveAfterDownloads() throws Exception {
run = task.run(TestsUtils.mockRunContext(runContextFactory, task, ImmutableMap.of()));
assertThat(run.getFiles().size(), is(2));
assertThat(run.getFiles().get(0).getPath().getPath(), endsWith(".txt"));
assertThat(run.getOutputFiles().size(), is(2));

assertThat(smbUtils.list(toUploadDir).getFiles().isEmpty(), is(true));
assertThat(smbUtils.list(archiveShareDirectory).getFiles().size(), is(2));
Expand Down Expand Up @@ -107,6 +110,7 @@ void run_NoneAfterDownloads() throws Exception {

assertThat(run.getFiles().size(), is(2));
assertThat(run.getFiles().get(0).getPath().getPath(), endsWith(".txt"));
assertThat(run.getOutputFiles().size(), is(2));

assertThat(smbUtils.list(toUploadDir).getFiles().size(), is(2));
}
Expand Down

0 comments on commit 8adaf52

Please sign in to comment.