Skip to content

Commit 2bb75d9

Browse files
author
lorenzo
committed
code
1 parent abcd60d commit 2bb75d9

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

src/main/java/com/reedelk/file/component/FileDelete.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
attributes = FileAttribute.class,
3030
payload = String.class,
3131
description = "The path and name of the deleted file.")
32+
@ComponentInput(
33+
payload = Object.class,
34+
description = "The input payload is used to evaluate the file name to delete.")
3235
@Description("Deletes a file from the file system with the given File name. " +
3336
"An error is raised if the given file could not be found. " +
3437
"The file name can be a dynamic expression.")
@@ -51,11 +54,16 @@ public void initialize() {
5154

5255
@Override
5356
public Message apply(FlowContext flowContext, Message message) {
57+
5458
return service.evaluate(fileName, flowContext, message).flatMap(evaluatedFileNameToRemove -> {
5559
Path filePathToDelete;
60+
5661
try {
62+
5763
filePathToDelete = Paths.get(evaluatedFileNameToRemove);
64+
5865
Files.delete(filePathToDelete);
66+
5967
} catch (Exception exception) {
6068
String errorMessage = ERROR_FILE_DELETE.format(exception.getMessage());
6169
throw new FileDeleteException(errorMessage, exception);

src/main/java/com/reedelk/file/component/FileExists.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
attributes = FileAttribute.class,
2929
payload = boolean.class,
3030
description = "True if the file exists, false otherwise.")
31+
@ComponentInput(
32+
payload = Object.class,
33+
description = "The input payload is used to evaluate the file name to check for existence.")
3134
@Description("The File Exists component Tests whether a file with the given path exists. " +
3235
"The file path can be a text only or dynamic expression.")
3336
@Component(service = FileExists.class, scope = ServiceScope.PROTOTYPE)

src/main/java/com/reedelk/file/component/FileRead.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
attributes = FileAttribute.class,
3030
payload = byte[].class,
3131
description = "The content of the file read from the file system from the given path and file name.")
32+
@ComponentInput(
33+
payload = Object.class,
34+
description = "The input payload is used to evaluate the file name to read.")
3235
@Description("Reads a file from the file system from the given file name and optionally provided base path. " +
3336
"The file read strategy determines if the file should be streamed from the file system or " +
3437
"loaded into memory before continuing with the execution of the flow. " +

src/main/java/com/reedelk/file/component/FileWrite.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
@ComponentOutput(
3434
attributes = FileAttribute.class,
3535
payload = Void.class)
36+
@ComponentInput(
37+
payload = Object.class,
38+
description = "The input payload is used to evaluate the file name to write.")
3639
@Description("Writes a file to the file system to the given File name and optionally provided Base path. " +
3740
"The write mode can be used to override an existing file, create new file if it does not exists " +
3841
"or append to the existing file if exists already.")
@@ -43,7 +46,7 @@ public class FileWrite implements ProcessorAsync {
4346
@Hint("/var/logs/log1.txt")
4447
@Example("/var/logs/log1.txt")
4548
@Description("The path and name of the file to be written on the file system.")
46-
private DynamicString filePath;
49+
private DynamicString fileName;
4750

4851
@Property("Base path")
4952
@Hint("/var/logs")
@@ -74,7 +77,7 @@ public class FileWrite implements ProcessorAsync {
7477
public void apply(FlowContext flowContext, Message message, OnResult callback) {
7578

7679

77-
Optional<String> evaluated = scriptService.evaluate(filePath, flowContext, message);
80+
Optional<String> evaluated = scriptService.evaluate(fileName, flowContext, message);
7881

7982
if (evaluated.isPresent()) {
8083

@@ -110,8 +113,8 @@ public void apply(FlowContext flowContext, Message message, OnResult callback) {
110113
}
111114
}
112115

113-
public void setFilePath(DynamicString filePath) {
114-
this.filePath = filePath;
116+
public void setFileName(DynamicString fileName) {
117+
this.fileName = fileName;
115118
}
116119

117120
public void setBasePath(String basePath) {

0 commit comments

Comments
 (0)