Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private static ObjectMapper configure(ObjectMapper mapper) {
.configure(SerializationFeature.INDENT_OUTPUT, true)
.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false)
.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false)
.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
.registerModule(validationModule)
.registerModule(new JacksonMixInModule())
.findAndRegisterModules();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
*/
package io.serverlessworkflow.fluent.func;

import io.serverlessworkflow.api.types.CallTask;
import io.serverlessworkflow.api.types.func.CallJava;
import io.serverlessworkflow.api.types.func.CallTaskJava;
import io.serverlessworkflow.api.types.func.ContextFunction;
import io.serverlessworkflow.api.types.func.FilterFunction;
import io.serverlessworkflow.api.types.func.SerializableFunction;
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
import io.serverlessworkflow.fluent.spec.TaskBaseBuilder;
Expand All @@ -29,19 +30,16 @@ public class FuncCallTaskBuilder extends TaskBaseBuilder<FuncCallTaskBuilder>
implements FuncTaskTransformations<FuncCallTaskBuilder>,
ConditionalTaskBuilder<FuncCallTaskBuilder> {

private CallTaskJava callTaskJava;
private CallTask callTaskJava;

FuncCallTaskBuilder() {
callTaskJava = new CallTaskJava(new CallJava() {});
super.setTask(callTaskJava.getCallJava());
}
FuncCallTaskBuilder() {}

Comment thread
fjtirado marked this conversation as resolved.
Comment thread
fjtirado marked this conversation as resolved.
@Override
protected FuncCallTaskBuilder self() {
return this;
}

public <T, V> FuncCallTaskBuilder function(Function<T, V> function) {
public <T, V> FuncCallTaskBuilder function(SerializableFunction<T, V> function) {
return function(function, null);
}

Expand All @@ -51,8 +49,9 @@ public <T, V> FuncCallTaskBuilder function(Function<T, V> function, Class<T> arg

public <T, V> FuncCallTaskBuilder function(
Function<T, V> function, Class<T> argClass, Class<V> returnClass) {
this.callTaskJava = new CallTaskJava(CallJava.function(function, argClass, returnClass));
super.setTask(this.callTaskJava.getCallJava());
this.callTaskJava =
new CallTask().withCallFunction(CallJava.function(function, argClass, returnClass));
super.setTask(this.callTaskJava.getCallFunction());
return this;
}

Expand All @@ -66,8 +65,9 @@ public <T, V> FuncCallTaskBuilder function(ContextFunction<T, V> function, Class

public <T, V> FuncCallTaskBuilder function(
ContextFunction<T, V> function, Class<T> argClass, Class<V> returnClass) {
this.callTaskJava = new CallTaskJava(CallJava.function(function, argClass, returnClass));
super.setTask(this.callTaskJava.getCallJava());
this.callTaskJava =
new CallTask().withCallFunction(CallJava.function(function, argClass, returnClass));
super.setTask(this.callTaskJava.getCallFunction());
return this;
}

Expand All @@ -81,26 +81,31 @@ public <T, V> FuncCallTaskBuilder function(FilterFunction<T, V> function, Class<

public <T, V> FuncCallTaskBuilder function(
FilterFunction<T, V> function, Class<T> argClass, Class<V> outputClass) {
this.callTaskJava = new CallTaskJava(CallJava.function(function, argClass, outputClass));
super.setTask(this.callTaskJava.getCallJava());
this.callTaskJava =
new CallTask().withCallFunction(CallJava.function(function, argClass, outputClass));
super.setTask(this.callTaskJava.getCallFunction());
return this;
}

/** Accept a side-effect Consumer; engine should pass input through unchanged. */
public <T> FuncCallTaskBuilder consumer(Consumer<T> consumer) {
this.callTaskJava = new CallTaskJava(CallJava.consumer(consumer));
super.setTask(this.callTaskJava.getCallJava());
this.callTaskJava = new CallTask().withCallFunction(CallJava.consumer(consumer));
super.setTask(this.callTaskJava.getCallFunction());
return this;
}

/** Accept a Consumer with explicit input type hint. */
public <T> FuncCallTaskBuilder consumer(Consumer<T> consumer, Class<T> argClass) {
this.callTaskJava = new CallTaskJava(CallJava.consumer(consumer, argClass));
super.setTask(this.callTaskJava.getCallJava());
this.callTaskJava = new CallTask().withCallFunction(CallJava.consumer(consumer, argClass));
super.setTask(this.callTaskJava.getCallFunction());
return this;
}

public CallTaskJava build() {
public CallTask build() {
if (this.callTaskJava == null) {
throw new IllegalStateException(
"Call task is not configured. Call function(...) or consumer(...) before build().");
}
return this.callTaskJava;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package io.serverlessworkflow.fluent.func;

import io.cloudevents.CloudEventData;
import io.serverlessworkflow.api.reflection.func.SerializableFunction;
import io.serverlessworkflow.api.types.func.ContextFunction;
import io.serverlessworkflow.api.types.func.EventDataFunction;
import io.serverlessworkflow.api.types.func.FilterFunction;
import io.serverlessworkflow.api.types.func.SerializableFunction;
import io.serverlessworkflow.fluent.spec.AbstractEventPropertiesBuilder;
import java.util.function.Function;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
*/
package io.serverlessworkflow.fluent.func;

import io.serverlessworkflow.api.types.CallTask;
import io.serverlessworkflow.api.types.ForTask;
import io.serverlessworkflow.api.types.ForTaskConfiguration;
import io.serverlessworkflow.api.types.Task;
import io.serverlessworkflow.api.types.TaskItem;
import io.serverlessworkflow.api.types.func.CallJava;
import io.serverlessworkflow.api.types.func.CallTaskJava;
import io.serverlessworkflow.api.types.func.ForTaskFunction;
import io.serverlessworkflow.api.types.func.LoopFunction;
import io.serverlessworkflow.api.types.func.LoopPredicate;
import io.serverlessworkflow.api.types.func.LoopPredicateIndex;
import io.serverlessworkflow.api.types.utils.ForTaskFunction;
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
import io.serverlessworkflow.fluent.spec.TaskBaseBuilder;
Expand All @@ -39,14 +40,14 @@ public class FuncForTaskBuilder extends TaskBaseBuilder<FuncForTaskBuilder>
ConditionalTaskBuilder<FuncForTaskBuilder>,
ForEachTaskFluent<FuncForTaskBuilder, FuncTaskItemListBuilder> {

private final ForTaskFunction forTaskFunction;
private final ForTask forTask;
private final List<TaskItem> items;

FuncForTaskBuilder() {
this.forTaskFunction = new ForTaskFunction();
this.forTaskFunction.withFor(new ForTaskConfiguration());
this.forTask = new ForTask();
this.forTask.withFor(new ForTaskConfiguration());
this.items = new ArrayList<>();
super.setTask(forTaskFunction);
super.setTask(forTask);
}

@Override
Expand All @@ -55,23 +56,23 @@ protected FuncForTaskBuilder self() {
}

public <T, V> FuncForTaskBuilder whileC(LoopPredicate<T, V> predicate) {
this.forTaskFunction.withWhile(predicate);
ForTaskFunction.withWhile(forTask, predicate);
return this;
}

public <T, V> FuncForTaskBuilder whileC(LoopPredicateIndex<T, V> predicate) {
this.forTaskFunction.withWhile(predicate);
ForTaskFunction.withWhile(forTask, predicate);
return this;
}

public <T, V> FuncForTaskBuilder collection(Function<T, Collection<V>> collectionF) {
this.forTaskFunction.withCollection(collectionF);
ForTaskFunction.withCollection(forTask, collectionF);
return this;
}

public <T, V> FuncForTaskBuilder collection(
Function<T, Collection<V>> collectionF, Class<T> clazz) {
this.forTaskFunction.withCollection(collectionF, clazz);
ForTaskFunction.withCollection(forTask, collectionF, clazz);
return this;
}

Expand All @@ -84,9 +85,9 @@ public <T, V, R> FuncForTaskBuilder tasks(String name, LoopFunction<T, V, R> fun
name,
new Task()
.withCallTask(
new CallTaskJava(
CallJava.loopFunction(
function, this.forTaskFunction.getFor().getEach())))));
new CallTask()
.withCallFunction(
CallJava.loopFunction(function, this.forTask.getFor().getEach())))));
return this;
}

Expand All @@ -96,25 +97,25 @@ public <T, V, R> FuncForTaskBuilder tasks(LoopFunction<T, V, R> function) {

@Override
public FuncForTaskBuilder each(String each) {
this.forTaskFunction.getFor().withEach(each);
this.forTask.getFor().withEach(each);
return this;
}

@Override
public FuncForTaskBuilder in(String in) {
this.forTaskFunction.getFor().withIn(in);
this.forTask.getFor().withIn(in);
return this;
}

@Override
public FuncForTaskBuilder at(String at) {
this.forTaskFunction.getFor().withAt(at);
this.forTask.getFor().withAt(at);
return this;
}

@Override
public FuncForTaskBuilder whileC(String expression) {
this.forTaskFunction.setWhile(expression);
this.forTask.setWhile(expression);
return this;
}

Expand All @@ -125,8 +126,8 @@ public FuncForTaskBuilder tasks(Consumer<FuncTaskItemListBuilder> consumer) {
return this;
}

public ForTaskFunction build() {
this.forTaskFunction.setDo(this.items);
return this.forTaskFunction;
public ForTask build() {
this.forTask.setDo(this.items);
return this.forTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package io.serverlessworkflow.fluent.func;

import io.serverlessworkflow.api.types.CallTask;
import io.serverlessworkflow.api.types.Task;
import io.serverlessworkflow.api.types.TaskItem;
import io.serverlessworkflow.api.types.func.CallJava;
import io.serverlessworkflow.api.types.func.CallTaskJava;
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
import io.serverlessworkflow.fluent.spec.AbstractForkTaskBuilder;
Expand Down Expand Up @@ -61,7 +61,8 @@ public <T, V> FuncForkTaskBuilder branch(
this.defaultBranchName(name, this.currentOffset()),
new Task()
.withCallTask(
new CallTaskJava(CallJava.function(function, argParam, returnClass)))));
new CallTask()
.withCallFunction(CallJava.function(function, argParam, returnClass)))));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
*/
package io.serverlessworkflow.fluent.func;

import io.serverlessworkflow.api.types.AnyEventConsumptionStrategy;
import io.serverlessworkflow.api.types.ListenTask;
import io.serverlessworkflow.api.types.func.UntilPredicate;
import io.serverlessworkflow.api.types.utils.TaskPredicate;
import io.serverlessworkflow.api.types.utils.TypesUtils;
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
import io.serverlessworkflow.fluent.spec.AbstractListenTaskBuilder;
Expand All @@ -28,14 +27,13 @@ public class FuncListenTaskBuilder
implements ConditionalTaskBuilder<FuncListenTaskBuilder>,
FuncTaskTransformations<FuncListenTaskBuilder> {

private UntilPredicate untilPredicate;

FuncListenTaskBuilder(FuncTaskItemListBuilder factory) {
super(factory);
}

public <T> FuncListenTaskBuilder until(Predicate<T> predicate, Class<T> predClass) {
untilPredicate = new UntilPredicate().withPredicate(predicate, predClass);
TaskPredicate.withPredicate(
super.getListenTask(), TypesUtils.UNTIL_PRED_NAME, predicate, predClass);
return this;
}

Expand All @@ -46,17 +44,6 @@ protected FuncListenTaskBuilder self() {

@Override
protected FuncListenToBuilder newEventConsumptionStrategyBuilder() {
return new FuncListenToBuilder();
}

@Override
public ListenTask build() {
ListenTask task = super.build();
AnyEventConsumptionStrategy anyEvent =
task.getListen().getTo().getAnyEventConsumptionStrategy();
if (untilPredicate != null && anyEvent != null) {
anyEvent.withUntil(untilPredicate);
}
return task;
return new FuncListenToBuilder(super.getListenTask());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

import io.serverlessworkflow.api.types.AllEventConsumptionStrategy;
import io.serverlessworkflow.api.types.AnyEventConsumptionStrategy;
import io.serverlessworkflow.api.types.ListenTask;
import io.serverlessworkflow.api.types.ListenTo;
import io.serverlessworkflow.api.types.OneEventConsumptionStrategy;
import io.serverlessworkflow.api.types.Until;
import io.serverlessworkflow.api.types.func.ContextPredicate;
import io.serverlessworkflow.api.types.func.FilterPredicate;
import io.serverlessworkflow.api.types.func.UntilPredicate;
import io.serverlessworkflow.api.types.utils.TaskPredicate;
import io.serverlessworkflow.api.types.utils.TypesUtils;
import io.serverlessworkflow.fluent.spec.AbstractEventConsumptionStrategyBuilder;
import java.util.function.Predicate;

Expand All @@ -31,6 +33,11 @@ public class FuncListenToBuilder
FuncListenToBuilder, ListenTo, FuncEventFilterBuilder> {

private final ListenTo listenTo = new ListenTo();
private final ListenTask listenTask;

public FuncListenToBuilder(ListenTask listenTask) {
this.listenTask = listenTask;
}

@Override
protected FuncEventFilterBuilder newEventFilterBuilder() {
Expand Down Expand Up @@ -65,17 +72,17 @@ protected void setUntilForAny(Until until) {
}

public <T> FuncListenToBuilder until(Predicate<T> predicate, Class<T> predClass) {
this.setUntil(new UntilPredicate().withPredicate(predicate, predClass));
TaskPredicate.withPredicate(listenTask, TypesUtils.UNTIL_PRED_NAME, predicate, predClass);
return this;
}

public <T> FuncListenToBuilder until(ContextPredicate<T> predicate, Class<T> predClass) {
this.setUntil(new UntilPredicate().withPredicate(predicate, predClass));
TaskPredicate.withPredicate(listenTask, TypesUtils.UNTIL_PRED_NAME, predicate, predClass);
return this;
}

public <T> FuncListenToBuilder until(FilterPredicate<T> predicate, Class<T> predClass) {
this.setUntil(new UntilPredicate().withPredicate(predicate, predClass));
TaskPredicate.withPredicate(listenTask, TypesUtils.UNTIL_PRED_NAME, predicate, predClass);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package io.serverlessworkflow.fluent.func;

import io.serverlessworkflow.api.types.func.MapSetTaskConfiguration;
import io.serverlessworkflow.api.types.utils.MapSetTaskConfiguration;
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
import io.serverlessworkflow.fluent.spec.SetTaskBuilder;
import java.util.Map;
Expand All @@ -24,7 +24,7 @@ public class FuncSetTaskBuilder extends SetTaskBuilder
implements ConditionalTaskBuilder<FuncSetTaskBuilder> {

public FuncSetTaskBuilder expr(Map<String, Object> map) {
this.setTaskConfiguration = new MapSetTaskConfiguration(map);
this.setTaskConfiguration = MapSetTaskConfiguration.map(map);
return this;
}
}
Loading
Loading