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 #333
  • Loading branch information
loicmathieu committed May 20, 2024
1 parent 58c6910 commit 9538d02
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/io/kestra/plugin/gcp/gcs/Downloads.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import io.kestra.plugin.gcp.gcs.models.Blob;

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

Expand Down Expand Up @@ -130,6 +133,10 @@ public Output run(RunContext runContext) throws Exception {
}))
.collect(Collectors.toList());

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

Downloads.performAction(
run.getBlobs(),
this.action,
Expand All @@ -143,6 +150,7 @@ public Output run(RunContext runContext) throws Exception {
return Output
.builder()
.blobs(list)
.outputFiles(outputFiles)
.build();
}

Expand All @@ -153,5 +161,10 @@ public static class Output implements io.kestra.core.models.tasks.Output {
title = "The bucket of the downloaded file"
)
private final java.util.List<Blob> blobs;

@Schema(
title = "The downloaded files as a map of from/to URIs."
)
private final Map<String, URI> outputFiles;
}
}
1 change: 1 addition & 0 deletions src/test/java/io/kestra/plugin/gcp/gcs/DownloadsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void run() throws Exception {
Downloads.Output run = task.run(runContext(task));

assertThat(run.getBlobs().size(), is(2));
assertThat(run.getOutputFiles().size(), is(2));
}

private RunContext runContext(Task task) {
Expand Down

0 comments on commit 9538d02

Please sign in to comment.