-
Notifications
You must be signed in to change notification settings - Fork 52
feat: support to subflows on the Java DSL #1213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
matheusandre1
wants to merge
1
commit into
serverlessworkflow:main
Choose a base branch
from
matheusandre1:issue-1151
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
56 changes: 56 additions & 0 deletions
56
fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/WorkflowTaskBuilder.java
This file contains hidden or 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,56 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.fluent.spec; | ||
|
|
||
| import io.serverlessworkflow.api.types.RunTask; | ||
| import io.serverlessworkflow.api.types.RunTaskConfigurationUnion; | ||
| import io.serverlessworkflow.api.types.RunWorkflow; | ||
| import io.serverlessworkflow.api.types.SubflowConfiguration; | ||
| import io.serverlessworkflow.fluent.spec.spi.WorkflowTaskFluent; | ||
|
|
||
| public class WorkflowTaskBuilder extends TaskBaseBuilder<WorkflowTaskBuilder> | ||
| implements WorkflowTaskFluent<WorkflowTaskBuilder> { | ||
|
|
||
| private final RunTask task; | ||
| private final RunWorkflow configuration; | ||
| private final SubflowConfiguration workflow; | ||
|
|
||
| WorkflowTaskBuilder() { | ||
| this.task = new RunTask(); | ||
| this.configuration = new RunWorkflow(); | ||
| this.workflow = new SubflowConfiguration(); | ||
| this.configuration.setWorkflow(this.workflow); | ||
| this.task.setRun(new RunTaskConfigurationUnion().withRunWorkflow(this.configuration)); | ||
| this.setTask(task); | ||
| } | ||
|
|
||
| @Override | ||
| public WorkflowTaskBuilder self() { | ||
| return this; | ||
| } | ||
|
|
||
| public RunWorkflow config() { | ||
| return this.configuration; | ||
| } | ||
|
|
||
| public SubflowConfiguration workflow() { | ||
| return this.workflow; | ||
| } | ||
|
|
||
| public RunTask build() { | ||
| return this.task; | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
.../spec/src/main/java/io/serverlessworkflow/fluent/spec/configurers/WorkflowConfigurer.java
This file contains hidden or 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,22 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.fluent.spec.configurers; | ||
|
|
||
| import io.serverlessworkflow.fluent.spec.WorkflowTaskBuilder; | ||
| import java.util.function.Consumer; | ||
|
|
||
| @FunctionalInterface | ||
| public interface WorkflowConfigurer extends Consumer<WorkflowTaskBuilder> {} |
This file contains hidden or 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
71 changes: 71 additions & 0 deletions
71
fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/dsl/WorkflowSpec.java
This file contains hidden or 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,71 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.fluent.spec.dsl; | ||
|
|
||
| import io.serverlessworkflow.api.types.RunTaskConfiguration; | ||
| import io.serverlessworkflow.fluent.spec.WorkflowTaskBuilder; | ||
| import io.serverlessworkflow.fluent.spec.configurers.WorkflowConfigurer; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.function.Consumer; | ||
|
|
||
| public final class WorkflowSpec implements WorkflowConfigurer { | ||
|
|
||
| private final List<Consumer<WorkflowTaskBuilder>> steps = new ArrayList<>(); | ||
|
|
||
| public WorkflowSpec namespace(String namespace) { | ||
| steps.add(b -> b.namespace(namespace)); | ||
| return this; | ||
| } | ||
|
|
||
| public WorkflowSpec name(String name) { | ||
| steps.add(b -> b.name(name)); | ||
| return this; | ||
| } | ||
|
|
||
| public WorkflowSpec version(String version) { | ||
| steps.add(b -> b.version(version)); | ||
| return this; | ||
| } | ||
|
|
||
| public WorkflowSpec input(Map<String, Object> input) { | ||
| steps.add(b -> b.input(input)); | ||
| return this; | ||
| } | ||
|
|
||
| public WorkflowSpec input(String key, Object value) { | ||
| steps.add(b -> b.input(key, value)); | ||
| return this; | ||
| } | ||
|
|
||
| public WorkflowSpec await(boolean await) { | ||
| steps.add(b -> b.await(await)); | ||
| return this; | ||
| } | ||
|
|
||
| public WorkflowSpec returnType(RunTaskConfiguration.ProcessReturnType returnType) { | ||
| steps.add(b -> b.returnType(returnType)); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public void accept(WorkflowTaskBuilder builder) { | ||
| for (var s : steps) { | ||
| s.accept(builder); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
29 changes: 29 additions & 0 deletions
29
fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/spi/WorkflowFluent.java
This file contains hidden or 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,29 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.fluent.spec.spi; | ||
|
|
||
| import io.serverlessworkflow.fluent.spec.TaskBaseBuilder; | ||
| import java.util.UUID; | ||
| import java.util.function.Consumer; | ||
|
|
||
| public interface WorkflowFluent<SELF extends TaskBaseBuilder<SELF>, LIST> { | ||
|
|
||
| LIST workflow(String name, Consumer<SELF> itemsConfigurer); | ||
|
|
||
| default LIST workflow(Consumer<SELF> itemsConfigurer) { | ||
| return this.workflow(UUID.randomUUID().toString(), itemsConfigurer); | ||
| } | ||
| } |
68 changes: 68 additions & 0 deletions
68
fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/spi/WorkflowTaskFluent.java
This file contains hidden or 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,68 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.fluent.spec.spi; | ||
|
|
||
| import io.serverlessworkflow.api.types.RunTaskConfiguration; | ||
| import io.serverlessworkflow.api.types.SubflowInput; | ||
| import io.serverlessworkflow.fluent.spec.TaskBaseBuilder; | ||
| import io.serverlessworkflow.fluent.spec.WorkflowTaskBuilder; | ||
| import java.util.Map; | ||
|
|
||
| public interface WorkflowTaskFluent<SELF extends TaskBaseBuilder<SELF>> { | ||
|
|
||
| SELF self(); | ||
|
|
||
| default SELF namespace(String namespace) { | ||
| ((WorkflowTaskBuilder) this.self()).workflow().setNamespace(namespace); | ||
| return self(); | ||
| } | ||
|
|
||
| default SELF name(String name) { | ||
| ((WorkflowTaskBuilder) this.self()).workflow().setName(name); | ||
| return self(); | ||
| } | ||
|
|
||
| default SELF version(String version) { | ||
| ((WorkflowTaskBuilder) this.self()).workflow().setVersion(version); | ||
| return self(); | ||
| } | ||
|
|
||
| default SELF input(Map<String, Object> input) { | ||
| final SubflowInput subflowInput = new SubflowInput(); | ||
| input.forEach(subflowInput::setAdditionalProperty); | ||
| ((WorkflowTaskBuilder) this.self()).workflow().setInput(subflowInput); | ||
| return self(); | ||
| } | ||
|
|
||
| default SELF input(String key, Object value) { | ||
| final WorkflowTaskBuilder builder = (WorkflowTaskBuilder) this.self(); | ||
| if (builder.workflow().getInput() == null) { | ||
| builder.workflow().setInput(new SubflowInput()); | ||
| } | ||
| builder.workflow().getInput().setAdditionalProperty(key, value); | ||
| return self(); | ||
| } | ||
|
|
||
| default SELF await(boolean await) { | ||
| ((WorkflowTaskBuilder) this.self()).config().setAwait(await); | ||
| return self(); | ||
| } | ||
|
|
||
| default SELF returnType(RunTaskConfiguration.ProcessReturnType returnType) { | ||
| ((WorkflowTaskBuilder) this.self()).config().setReturn(returnType); | ||
| return self(); | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.