- Notifications
You must be signed in to change notification settings - Fork50
(WIP) Introduce Java Fluent DSL#646
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Draft
ricardozanini wants to merge1 commit intoserverlessworkflow:mainChoose a base branch fromricardozanini:fluent-java
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.
Uh oh!
There was an error while loading.Please reload this page.
Draft
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletionsexperimental/types/src/main/java/io/serverlessworkflow/api/types/SwitchCaseFunction.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
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,42 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.serverlessworkflow</groupId> | ||
<artifactId>serverlessworkflow-fluent</artifactId> | ||
<version>8.0.0-SNAPSHOT</version> | ||
</parent> | ||
<name>Serverless Workflow :: Fluent :: Java</name> | ||
<artifactId>serverlessworkflow-fluent-java</artifactId> | ||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.serverlessworkflow</groupId> | ||
<artifactId>serverlessworkflow-experimental-types</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.serverlessworkflow</groupId> | ||
<artifactId>serverlessworkflow-types</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.serverlessworkflow</groupId> | ||
<artifactId>serverlessworkflow-fluent-standard</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
47 changes: 47 additions & 0 deletionsfluent/java/src/main/java/io/serverlessworkflow/fluent/java/CallTaskJavaBuilder.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,47 @@ | ||
/* | ||
* 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.java; | ||
import io.serverlessworkflow.api.types.CallJava; | ||
import io.serverlessworkflow.api.types.CallTaskJava; | ||
import io.serverlessworkflow.fluent.standard.TaskBaseBuilder; | ||
import java.util.function.Function; | ||
public class CallTaskJavaBuilder extends TaskBaseBuilder<CallTaskJavaBuilder> | ||
implements JavaTransformationHandlers<CallTaskJavaBuilder> { | ||
private CallTaskJava callTaskJava; | ||
CallTaskJavaBuilder() { | ||
callTaskJava = new CallTaskJava(new CallJava() {}); | ||
super.setTask(callTaskJava.getCallJava()); | ||
} | ||
@Override | ||
protected CallTaskJavaBuilder self() { | ||
return this; | ||
} | ||
public <T, V> CallTaskJavaBuilder function(Function<T, V> function) { | ||
this.callTaskJava = new CallTaskJava(CallJava.function(function)); | ||
super.setTask(this.callTaskJava.getCallJava()); | ||
return this; | ||
} | ||
public CallTaskJava build() { | ||
return this.callTaskJava; | ||
} | ||
} |
73 changes: 73 additions & 0 deletionsfluent/java/src/main/java/io/serverlessworkflow/fluent/java/DoTaskJavaBuilder.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,73 @@ | ||
/* | ||
* 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.java; | ||
import io.serverlessworkflow.api.types.Task; | ||
import io.serverlessworkflow.api.types.TaskItem; | ||
import io.serverlessworkflow.fluent.standard.BaseDoTaskBuilder; | ||
import java.util.UUID; | ||
import java.util.function.Consumer; | ||
public class DoTaskJavaBuilder extends BaseDoTaskBuilder<DoTaskJavaBuilder> | ||
implements JavaTransformationHandlers<DoTaskJavaBuilder> { | ||
DoTaskJavaBuilder() { | ||
super(); | ||
} | ||
@Override | ||
protected DoTaskJavaBuilder self() { | ||
return this; | ||
} | ||
@Override | ||
protected DoTaskJavaBuilder newDo() { | ||
return new DoTaskJavaBuilder(); | ||
} | ||
public DoTaskJavaBuilder callFn(String name, Consumer<CallTaskJavaBuilder> consumer) { | ||
final CallTaskJavaBuilder callTaskJavaBuilder = new CallTaskJavaBuilder(); | ||
consumer.accept(callTaskJavaBuilder); | ||
this.addTaskItem(new TaskItem(name, new Task().withCallTask(callTaskJavaBuilder.build()))); | ||
return this; | ||
} | ||
public DoTaskJavaBuilder callFn(Consumer<CallTaskJavaBuilder> consumer) { | ||
return this.callFn(UUID.randomUUID().toString(), consumer); | ||
} | ||
public DoTaskJavaBuilder forEachFn(String name, Consumer<ForTaskJavaBuilder> consumer) { | ||
final ForTaskJavaBuilder forTaskJavaBuilder = new ForTaskJavaBuilder(); | ||
consumer.accept(forTaskJavaBuilder); | ||
this.addTaskItem(new TaskItem(name, new Task().withForTask(forTaskJavaBuilder.build()))); | ||
return this; | ||
} | ||
public DoTaskJavaBuilder forEachFn(Consumer<ForTaskJavaBuilder> consumer) { | ||
return this.forEachFn(UUID.randomUUID().toString(), consumer); | ||
} | ||
public DoTaskJavaBuilder switchCaseFn(String name, Consumer<SwitchTaskJavaBuilder> consumer) { | ||
final SwitchTaskJavaBuilder switchTaskJavaBuilder = new SwitchTaskJavaBuilder(); | ||
consumer.accept(switchTaskJavaBuilder); | ||
this.addTaskItem(new TaskItem(name, new Task().withSwitchTask(switchTaskJavaBuilder.build()))); | ||
return this; | ||
} | ||
public DoTaskJavaBuilder switchCaseFn(Consumer<SwitchTaskJavaBuilder> consumer) { | ||
return this.switchCaseFn(UUID.randomUUID().toString(), consumer); | ||
} | ||
} |
95 changes: 95 additions & 0 deletionsfluent/java/src/main/java/io/serverlessworkflow/fluent/java/ForTaskJavaBuilder.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,95 @@ | ||
/* | ||
* 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.java; | ||
import io.serverlessworkflow.api.types.CallJava; | ||
import io.serverlessworkflow.api.types.CallTaskJava; | ||
import io.serverlessworkflow.api.types.ForTaskConfiguration; | ||
import io.serverlessworkflow.api.types.ForTaskFunction; | ||
import io.serverlessworkflow.api.types.Task; | ||
import io.serverlessworkflow.api.types.TaskItem; | ||
import io.serverlessworkflow.fluent.standard.TaskBaseBuilder; | ||
import io.serverlessworkflow.impl.expressions.LoopFunction; | ||
import io.serverlessworkflow.impl.expressions.LoopPredicate; | ||
import io.serverlessworkflow.impl.expressions.LoopPredicateIndex; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
public class ForTaskJavaBuilder extends TaskBaseBuilder<ForTaskJavaBuilder> | ||
implements JavaTransformationHandlers<ForTaskJavaBuilder> { | ||
private final ForTaskFunction forTaskFunction; | ||
private final List<TaskItem> items; | ||
ForTaskJavaBuilder() { | ||
this.forTaskFunction = new ForTaskFunction(); | ||
this.forTaskFunction.withFor(new ForTaskConfiguration()); | ||
this.items = new ArrayList<>(); | ||
super.setTask(forTaskFunction); | ||
} | ||
@Override | ||
protected ForTaskJavaBuilder self() { | ||
return this; | ||
} | ||
public <T, V> ForTaskJavaBuilder whileCondition(LoopPredicate<T, V> predicate) { | ||
this.forTaskFunction.withWhile(predicate); | ||
return this; | ||
} | ||
public <T, V> ForTaskJavaBuilder whileCondition(LoopPredicateIndex<T, V> predicate) { | ||
this.forTaskFunction.withWhile(predicate); | ||
return this; | ||
} | ||
public <T> ForTaskJavaBuilder collection(Function<T, Collection<?>> collectionF) { | ||
this.forTaskFunction.withCollection(collectionF); | ||
return this; | ||
} | ||
public <T, V, R> ForTaskJavaBuilder doTasks(String name, LoopFunction<T, V, R> function) { | ||
this.items.add( | ||
new TaskItem( | ||
name, | ||
new Task() | ||
.withCallTask( | ||
new CallTaskJava( | ||
CallJava.loopFunction( | ||
function, this.forTaskFunction.getFor().getEach()))))); | ||
return this; | ||
} | ||
public <T, V, R> ForTaskJavaBuilder doTasks(LoopFunction<T, V, R> function) { | ||
return this.doTasks(UUID.randomUUID().toString(), function); | ||
} | ||
public ForTaskJavaBuilder doTasks(Consumer<DoTaskJavaBuilder> consumer) { | ||
final DoTaskJavaBuilder builder = new DoTaskJavaBuilder(); | ||
consumer.accept(builder); | ||
this.items.addAll(builder.build().getDo()); | ||
return this; | ||
} | ||
public ForTaskFunction build() { | ||
this.forTaskFunction.setDo(this.items); | ||
return this.forTaskFunction; | ||
} | ||
} |
21 changes: 21 additions & 0 deletionsfluent/java/src/main/java/io/serverlessworkflow/fluent/java/JavaForEach.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,21 @@ | ||
/* | ||
* 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.java; | ||
@FunctionalInterface | ||
public interface JavaForEach { | ||
void configure(ForTaskJavaBuilder builder); | ||
} |
21 changes: 21 additions & 0 deletionsfluent/java/src/main/java/io/serverlessworkflow/fluent/java/JavaSwitchCase.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,21 @@ | ||
/* | ||
* 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.java; | ||
@FunctionalInterface | ||
public interface JavaSwitchCase { | ||
void configure(SwitchTaskJavaBuilder consumer); | ||
} |
44 changes: 44 additions & 0 deletionsfluent/java/src/main/java/io/serverlessworkflow/fluent/java/JavaTransformationHandlers.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,44 @@ | ||
/* | ||
* 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.java; | ||
import io.serverlessworkflow.api.types.Export; | ||
import io.serverlessworkflow.api.types.ExportAsFunction; | ||
import io.serverlessworkflow.api.types.Input; | ||
import io.serverlessworkflow.api.types.InputFromFunction; | ||
import io.serverlessworkflow.api.types.Output; | ||
import io.serverlessworkflow.api.types.OutputAsFunction; | ||
import io.serverlessworkflow.fluent.standard.TransformationHandlers; | ||
import java.util.function.Function; | ||
public interface JavaTransformationHandlers<B extends JavaTransformationHandlers<B>> | ||
extends TransformationHandlers { | ||
default <T, V> B exportAsFn(Function<T, V> function) { | ||
setExport(new Export().withAs(new ExportAsFunction().withFunction(function))); | ||
return (B) this; | ||
} | ||
default <T, V> B inputFrom(Function<T, V> function) { | ||
setInput(new Input().withFrom(new InputFromFunction().withFunction(function))); | ||
return (B) this; | ||
} | ||
default <T, V> B outputAs(Function<T, V> function) { | ||
setOutput(new Output().withAs(new OutputAsFunction().withFunction(function))); | ||
return (B) this; | ||
} | ||
} |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.