Skip to content

Add then to the Java DSL#1190

Merged
fjtirado merged 3 commits intoserverlessworkflow:mainfrom
mcruzdev:issue-1188
Mar 4, 2026
Merged

Add then to the Java DSL#1190
fjtirado merged 3 commits intoserverlessworkflow:mainfrom
mcruzdev:issue-1188

Conversation

@mcruzdev
Copy link
Collaborator

@mcruzdev mcruzdev commented Feb 27, 2026

Changes

This pull request allows us to jump to a task using then(String taskName):

    Workflow wf =
        FuncWorkflowBuilder.workflow("intelligent-newsletter")
            .tasks(
                consume("sendNewsletter", (String s) -> {}, String.class).then("otherTask"),
                function("nextTask", String::strip, String.class),
                function("otherTask", String::strip, String.class))
            .build();

Closes #1188

Copy link
Member

@ricardozanini ricardozanini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and then(FlowDirectiveEnum directive) to the fluent Step DSL so function(...) / consume(...) steps can set the task’s then directive.
  • Extend DSL unit tests to assert the generated workflow model contains the expected then FlowDirective.
  • Add an integration-style test in impl/test to validate runtime execution jumps/stops based on then(...).

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.

Copy link
Collaborator

@fjtirado fjtirado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test needs to changed

Copilot AI review requested due to automatic review settings March 4, 2026 12:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
Copilot AI review requested due to automatic review settings March 4, 2026 12:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
@fjtirado fjtirado merged commit 60a4ff4 into serverlessworkflow:main Mar 4, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add then to the Java DSL

4 participants