/
DefaultMetadataStep.java
50 lines (45 loc) · 1.49 KB
/
DefaultMetadataStep.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package io.github.juliengalet.reactorflow.flow;
import io.github.juliengalet.reactorflow.builder.StepFlowBuilder;
import io.github.juliengalet.reactorflow.report.FlowContext;
import io.github.juliengalet.reactorflow.report.Metadata;
import io.github.juliengalet.reactorflow.report.Report;
import reactor.core.publisher.Mono;
/**
* Class that should be extended, in order to be able to create {@link StepFlow}, with injecting services possibility
*
* @param <T> The context type
* @param <M> The metadata type
*/
public class DefaultMetadataStep<T extends FlowContext, M> {
private static final String DEFAULT_NAME = "Default";
/**
* Overridable method that should return the name of your step.
*
* @return The name
*/
protected String getName() {
return DEFAULT_NAME;
}
/**
* Overridable method that should implement the logic of the step.
*
* @param context The current {@link T} flow context
* @param metadata The {@link M} metadata instance
* @return A {@link Report} inside a Mono
*/
protected Mono<Report<T>> getExecution(T context, Metadata<M> metadata) {
return Mono.just(Report.success(context));
}
/**
* This method build the step. You should call it to plug your step as a {@link StepFlow} inside flows.
*
* @return The built {@link StepFlow}
*/
public final StepFlow<T, M> getStep() {
return StepFlowBuilder
.<T, M>defaultBuilder()
.named(getName())
.execution(this::getExecution)
.build();
}
}