Skip to content

Commit 5f5cc7d

Browse files
author
lorenzo
committed
Added component's metadata @annotations.
1 parent 5b1c4a2 commit 5f5cc7d

File tree

7 files changed

+32
-13
lines changed

7 files changed

+32
-13
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,33 @@
22

33
import com.reedelk.file.internal.attribute.FileAttribute;
44
import com.reedelk.file.internal.exception.FileDeleteException;
5+
import com.reedelk.file.internal.exception.NotValidFileException;
56
import com.reedelk.runtime.api.annotation.*;
67
import com.reedelk.runtime.api.component.ProcessorSync;
78
import com.reedelk.runtime.api.flow.FlowContext;
89
import com.reedelk.runtime.api.message.Message;
9-
import com.reedelk.runtime.api.message.MessageAttributes;
1010
import com.reedelk.runtime.api.message.MessageBuilder;
11+
import com.reedelk.runtime.api.message.content.MimeType;
1112
import com.reedelk.runtime.api.script.ScriptEngineService;
1213
import com.reedelk.runtime.api.script.dynamicvalue.DynamicString;
1314
import org.osgi.service.component.annotations.Component;
1415
import org.osgi.service.component.annotations.Reference;
1516
import org.osgi.service.component.annotations.ServiceScope;
1617

1718
import java.nio.file.Files;
19+
import java.nio.file.Path;
1820
import java.nio.file.Paths;
1921
import java.util.Optional;
2022

2123
import static com.reedelk.file.internal.commons.Messages.FileDelete.ERROR_FILE_DELETE;
24+
import static com.reedelk.file.internal.commons.Messages.FileDelete.FILE_NAME_ERROR;
2225
import static com.reedelk.runtime.api.commons.ComponentPrecondition.Configuration.requireNotNull;
2326

2427
@ModuleComponent("File Delete")
28+
@ComponentOutput(
29+
attributes = FileAttribute.class,
30+
payload = String.class,
31+
description = "The path and name of the deleted file.")
2532
@Description("Deletes a file from the file system with the given File name. " +
2633
"An error is raised if the given file could not be found. " +
2734
"The file name can be a dynamic expression.")
@@ -45,23 +52,25 @@ public void initialize() {
4552
@Override
4653
public Message apply(FlowContext flowContext, Message message) {
4754
return service.evaluate(fileName, flowContext, message).flatMap(evaluatedFileNameToRemove -> {
55+
Path filePathToDelete;
4856
try {
49-
Files.delete(Paths.get(evaluatedFileNameToRemove));
57+
filePathToDelete = Paths.get(evaluatedFileNameToRemove);
58+
Files.delete(filePathToDelete);
5059
} catch (Exception exception) {
5160
String errorMessage = ERROR_FILE_DELETE.format(exception.getMessage());
5261
throw new FileDeleteException(errorMessage, exception);
5362
}
5463

55-
MessageAttributes attributes = new FileAttribute(evaluatedFileNameToRemove);
64+
FileAttribute attributes = new FileAttribute(evaluatedFileNameToRemove);
5665

5766
Message outMessage = MessageBuilder.get(FileDelete.class)
5867
.attributes(attributes)
59-
.empty()
68+
.withString(filePathToDelete.toString(), MimeType.TEXT_PLAIN)
6069
.build();
6170

6271
return Optional.of(outMessage);
6372

64-
}).orElse(MessageBuilder.get(FileDelete.class).empty().build());
73+
}).orElseThrow(() -> new NotValidFileException(FILE_NAME_ERROR.format(fileName.toString())));
6574
}
6675

6776
public void setFileName(DynamicString fileName) {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.reedelk.runtime.api.component.ProcessorSync;
88
import com.reedelk.runtime.api.flow.FlowContext;
99
import com.reedelk.runtime.api.message.Message;
10-
import com.reedelk.runtime.api.message.MessageAttributes;
1110
import com.reedelk.runtime.api.message.MessageBuilder;
1211
import com.reedelk.runtime.api.script.ScriptEngineService;
1312
import com.reedelk.runtime.api.script.dynamicvalue.DynamicString;
@@ -25,6 +24,10 @@
2524

2625

2726
@ModuleComponent("File Exists")
27+
@ComponentOutput(
28+
attributes = FileAttribute.class,
29+
payload = boolean.class,
30+
description = "True if the file exists, false otherwise.")
2831
@Description("The File Exists component Tests whether a file with the given path exists. " +
2932
"The file path can be a text only or dynamic expression.")
3033
@Component(service = FileExists.class, scope = ServiceScope.PROTOTYPE)
@@ -75,7 +78,7 @@ public Message apply(FlowContext flowContext, Message message) {
7578
return message;
7679

7780
} else {
78-
MessageAttributes attributes = new FileAttribute(path.toString());
81+
FileAttribute attributes = new FileAttribute(path.toString());
7982
return MessageBuilder.get(FileExists.class)
8083
.attributes(attributes)
8184
.withJavaObject(exists)

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.reedelk.runtime.api.component.ProcessorSync;
99
import com.reedelk.runtime.api.flow.FlowContext;
1010
import com.reedelk.runtime.api.message.Message;
11-
import com.reedelk.runtime.api.message.MessageAttributes;
1211
import com.reedelk.runtime.api.message.MessageBuilder;
1312
import com.reedelk.runtime.api.message.content.MimeType;
1413
import com.reedelk.runtime.api.script.ScriptEngineService;
@@ -26,7 +25,11 @@
2625
import static com.reedelk.runtime.api.commons.StringUtils.isBlank;
2726

2827
@ModuleComponent("File Read")
29-
@Description("Reads a file from the file system from the given File name and optionally provided Base path. " +
28+
@ComponentOutput(
29+
attributes = FileAttribute.class,
30+
payload = byte[].class,
31+
description = "The content of the file read from the file system from the given path and file name.")
32+
@Description("Reads a file from the file system from the given file name and optionally provided base path. " +
3033
"The file read strategy determines if the file should be streamed from the file system or " +
3134
"loaded into memory before continuing with the execution of the flow. " +
3235
"The component can also be configured to acquire a lock before reading the file.")
@@ -100,7 +103,7 @@ public Message apply(FlowContext flowContext, Message message) {
100103

101104
ReadConfigurationDecorator config = new ReadConfigurationDecorator(configuration);
102105

103-
MessageAttributes attributes = new FileAttribute(path.toString());
106+
FileAttribute attributes = new FileAttribute(path.toString());
104107

105108
Publisher<byte[]> data = strategy.read(path, config);
106109

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.reedelk.file.component;
22

3+
import com.reedelk.file.internal.attribute.FileAttribute;
34
import com.reedelk.file.internal.exception.FileWriteException;
45
import com.reedelk.file.internal.write.WriteConfiguration;
56
import com.reedelk.file.internal.write.WriteMode;
@@ -29,6 +30,9 @@
2930
import static com.reedelk.runtime.api.commons.StringUtils.isBlank;
3031

3132
@ModuleComponent("File Write")
33+
@ComponentOutput(
34+
attributes = FileAttribute.class,
35+
payload = Void.class)
3236
@Description("Writes a file to the file system to the given File name and optionally provided Base path. " +
3337
"The write mode can be used to override an existing file, create new file if it does not exists " +
3438
"or append to the existing file if exists already.")

src/main/java/com/reedelk/file/internal/commons/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public String template() {
4747

4848
public enum FileDelete implements FormattedMessage {
4949

50+
FILE_NAME_ERROR("Could not evaluate file with with name=[%s]"),
5051
ERROR_FILE_DELETE("The file could not be deleted, cause=[%s].");
5152

5253
private String message;

src/main/java/com/reedelk/file/internal/write/Writer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.reedelk.runtime.api.component.OnResult;
1111
import com.reedelk.runtime.api.flow.FlowContext;
1212
import com.reedelk.runtime.api.message.Message;
13-
import com.reedelk.runtime.api.message.MessageAttributes;
1413
import com.reedelk.runtime.api.message.MessageBuilder;
1514
import com.reedelk.runtime.api.message.content.TypedPublisher;
1615
import reactor.core.Exceptions;
@@ -111,7 +110,7 @@ public void write(WriteConfiguration config, FlowContext flowContext, OnResult c
111110
}).doOnSuccess(initial -> {
112111

113112
// On success build the message and invoke the callback.
114-
MessageAttributes attributes = new FileAttribute(path.toString());
113+
FileAttribute attributes = new FileAttribute(path.toString());
115114

116115
Message outMessage = MessageBuilder.get(FileWrite.class)
117116
.attributes(attributes)

0 commit comments

Comments
 (0)