-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add DefaultStep and DefaultMetadataStep classes
- Loading branch information
1 parent
fb65c6b
commit 85a5878
Showing
9 changed files
with
1,445 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/io/github/juliengalet/reactorflow/flow/DefaultMetadataStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/io/github/juliengalet/reactorflow/flow/DefaultStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
* (see {@link DefaultMetadataStep} for the version allowing metadata type customization). | ||
* | ||
* @param <T> The context type | ||
*/ | ||
public class DefaultStep<T extends FlowContext> { | ||
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 metadata instance | ||
* @return A {@link Report} inside a Mono | ||
*/ | ||
protected Mono<Report<T>> getExecution(T context, Metadata<Object> 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, Object> getStep() { | ||
return StepFlowBuilder | ||
.<T, Object>defaultBuilder() | ||
.named(getName()) | ||
.execution(this::getExecution) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/test/java/io/github/juliengalet/reactorflow/testutils/SuccessFinallyStepFlow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.github.juliengalet.reactorflow.testutils; | ||
|
||
import io.github.juliengalet.reactorflow.builder.StepFlowBuilder; | ||
import io.github.juliengalet.reactorflow.exception.FlowException; | ||
import io.github.juliengalet.reactorflow.flow.StepFlow; | ||
import io.github.juliengalet.reactorflow.flow.StepWithMetadata; | ||
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; | ||
|
||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
|
||
public final class SuccessFinallyStepFlow<T extends FlowContext, M> implements StepWithMetadata<T, M> { | ||
private final String name; | ||
|
||
public static <T extends FlowContext, M> StepFlow<T, M> flowNamed(String name) { | ||
return StepFlowBuilder | ||
.<T, M>defaultBuilder() | ||
.named(name) | ||
.execution(new SuccessFinallyStepFlow<>(name)) | ||
.build(); | ||
} | ||
|
||
public static <T extends FlowContext, M> SuccessFinallyStepFlow<T, M> named(String name) { | ||
return new SuccessFinallyStepFlow<>(name); | ||
} | ||
|
||
private SuccessFinallyStepFlow(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public Mono<Report<T>> apply(T context, Metadata<M> metadata) { | ||
String errorEntry = String.format( | ||
"%s | %s (%s %s) | %s", | ||
this.name, | ||
metadata.getErrors().stream().map(FlowException::getMessage).collect(Collectors.joining(", ")), | ||
metadata.getData().getClass().getSimpleName(), | ||
metadata.getData(), | ||
UUID.randomUUID().toString() | ||
); | ||
context.put(errorEntry, errorEntry); | ||
return Mono.just(Report.success(context)); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
.../java/io/github/juliengalet/reactorflow/testutils/SuccessWithIntegerMetadataStepFlow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.github.juliengalet.reactorflow.testutils; | ||
|
||
import io.github.juliengalet.reactorflow.builder.StepFlowBuilder; | ||
import io.github.juliengalet.reactorflow.flow.StepFlow; | ||
import io.github.juliengalet.reactorflow.flow.StepWithMetadata; | ||
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; | ||
|
||
import java.util.UUID; | ||
|
||
public final class SuccessWithIntegerMetadataStepFlow<T extends FlowContext> implements StepWithMetadata<T, Integer> { | ||
private final String name; | ||
|
||
public static <T extends FlowContext> StepFlow<T, Integer> flowNamed(String name) { | ||
return StepFlowBuilder | ||
.<T, Integer>defaultBuilder() | ||
.named(name) | ||
.execution(new SuccessWithIntegerMetadataStepFlow<>(name)) | ||
.build(); | ||
} | ||
|
||
public static <T extends FlowContext> SuccessWithIntegerMetadataStepFlow<T> named(String name) { | ||
return new SuccessWithIntegerMetadataStepFlow<>(name); | ||
} | ||
|
||
private SuccessWithIntegerMetadataStepFlow(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public Mono<Report<T>> apply(T context, Metadata<Integer> metadata) { | ||
String metadataEntry = String.format("%s | %s | %s", this.name, metadata.getData(), UUID.randomUUID().toString()); | ||
context.put(metadataEntry, metadataEntry); | ||
return Mono.just(Report.success(context)); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...t/java/io/github/juliengalet/reactorflow/testutils/SuccessWithStringMetadataStepFlow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.github.juliengalet.reactorflow.testutils; | ||
|
||
import io.github.juliengalet.reactorflow.builder.StepFlowBuilder; | ||
import io.github.juliengalet.reactorflow.flow.StepFlow; | ||
import io.github.juliengalet.reactorflow.flow.StepWithMetadata; | ||
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; | ||
|
||
import java.util.UUID; | ||
|
||
public final class SuccessWithStringMetadataStepFlow<T extends FlowContext> implements StepWithMetadata<T, String> { | ||
private final String name; | ||
|
||
public static <T extends FlowContext> StepFlow<T, String> flowNamed(String name) { | ||
return StepFlowBuilder | ||
.<T, String>defaultBuilder() | ||
.named(name) | ||
.execution(new SuccessWithStringMetadataStepFlow<>(name)) | ||
.build(); | ||
} | ||
|
||
public static <T extends FlowContext> SuccessWithStringMetadataStepFlow<T> named(String name) { | ||
return new SuccessWithStringMetadataStepFlow<>(name); | ||
} | ||
|
||
private SuccessWithStringMetadataStepFlow(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public Mono<Report<T>> apply(T context, Metadata<String> metadata) { | ||
String metadataEntry = String.format("%s | %s | %s", this.name, metadata.getData(), UUID.randomUUID().toString()); | ||
context.put(metadataEntry, metadataEntry); | ||
return Mono.just(Report.success(context)); | ||
} | ||
} |