Conversation
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
ricardozanini
left a comment
There was a problem hiding this comment.
Great work! Have you also checked how the mermaid diagram handles it? It's tangential to this work, but I can't remember whether I implemented it there.
experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/Step.java
Show resolved
Hide resolved
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR adds .then(...) chaining support to the experimental Java functional fluent DSL steps, allowing a task to direct workflow execution to a named next task (or a flow directive like END) without requiring Consumer.andThen() composition. This addresses issue #1188 by improving DSL ergonomics and adds tests to validate both model generation and runtime behavior.
Changes:
- Add
then(String taskName)andthen(FlowDirectiveEnum directive)to the fluentStepDSL sofunction(...)/consume(...)steps can set the task’sthendirective. - Extend DSL unit tests to assert the generated workflow model contains the expected
thenFlowDirective. - Add an integration-style test in
impl/testto validate runtime execution jumps/stops based onthen(...).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/Step.java |
Adds then(...) chaining APIs that defer to TaskBaseBuilder.then(...) via queued post-configurers. |
experimental/fluent/func/src/test/java/io/serverlessworkflow/fluent/func/FuncDSLTest.java |
Adds unit tests verifying then(...) is serialized into the underlying task model for both function(...) and consume(...). |
impl/test/src/test/java/io/serverlessworkflow/impl/test/WorkflowThenTest.java |
Adds runtime tests asserting .then("task") skips the next task and .then(END) stops execution. |
impl/test/pom.xml |
Adds test-scope dependencies needed to build/execute workflows created with the experimental fluent func DSL and Java lambda execution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| WorkflowApplication app = WorkflowApplication.builder().build(); | ||
| WorkflowDefinition def = app.workflowDefinition(wf); | ||
| def.instance(Map.of()).start().join(); |
There was a problem hiding this comment.
WorkflowDefinition.instance(...) is started with Map.of(), but the first task is a typed Java String function/consumer (String.class). The Java lambda execution path converts the workflow input to the requested arg type via WorkflowModel.as(String.class), which will be empty for a JSON object, causing an exception before the then(...) behavior can be validated. Pass a String (e.g., a sample newsletter payload) as the workflow input, or set an inputFrom mapping that extracts a String from the provided map.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
|
|
||
| WorkflowApplication app = WorkflowApplication.builder().build(); | ||
| WorkflowDefinition def = app.workflowDefinition(wf); | ||
| def.instance(Map.of()).start().join(); |
There was a problem hiding this comment.
Same issue as earlier: the workflow instance is started with Map.of() but the first task is a typed String Java function (String.class), so input conversion will fail for a JSON object. Use a String input value (or add an inputFrom mapping) so this test reliably exercises then("otherTask").
|
|
||
| WorkflowApplication app = WorkflowApplication.builder().build(); | ||
| WorkflowDefinition def = app.workflowDefinition(wf); | ||
| def.instance(Map.of()).start().join(); |
There was a problem hiding this comment.
The workflow instance is started with Map.of(), but the first task is a typed String Java function (String.class), so the Java lambda executor will fail converting an object input to String. Provide a String input (or set inputFrom) so this test validates then(FlowDirectiveEnum.END) rather than failing on input conversion.
Changes
This pull request allows us to jump to a task using
then(String taskName):Closes #1188