Skip to content

Commit 0c96a26

Browse files
authored
[Fix #1489] Serializing java defined files (#1514)
* [Fix #1489] Serializing Java defined workflows Signed-off-by: fjtirado <ftirados@ibm.com> * [Fix #1489] Alternative approach Signed-off-by: fjtirado <ftirados@ibm.com> * [Fix #1489] Same approach for all classes Signed-off-by: fjtirado <ftirados@ibm.com> * [Fix #1489] Handling predicates Signed-off-by: fjtirado <ftirados@ibm.com> --------- Signed-off-by: fjtirado <ftirados@ibm.com>
1 parent cab7ecf commit 0c96a26

126 files changed

Lines changed: 2525 additions & 1696 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/src/main/java/io/serverlessworkflow/api/ObjectMapperFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ private static ObjectMapper configure(ObjectMapper mapper) {
5353
.configure(SerializationFeature.INDENT_OUTPUT, true)
5454
.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false)
5555
.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false)
56+
.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
5657
.registerModule(validationModule)
5758
.registerModule(new JacksonMixInModule())
5859
.findAndRegisterModules();

experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/FuncCallTaskBuilder.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
*/
1616
package io.serverlessworkflow.fluent.func;
1717

18+
import io.serverlessworkflow.api.types.CallTask;
1819
import io.serverlessworkflow.api.types.func.CallJava;
19-
import io.serverlessworkflow.api.types.func.CallTaskJava;
2020
import io.serverlessworkflow.api.types.func.ContextFunction;
2121
import io.serverlessworkflow.api.types.func.FilterFunction;
22+
import io.serverlessworkflow.api.types.func.SerializableFunction;
2223
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
2324
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
2425
import io.serverlessworkflow.fluent.spec.TaskBaseBuilder;
@@ -29,19 +30,16 @@ public class FuncCallTaskBuilder extends TaskBaseBuilder<FuncCallTaskBuilder>
2930
implements FuncTaskTransformations<FuncCallTaskBuilder>,
3031
ConditionalTaskBuilder<FuncCallTaskBuilder> {
3132

32-
private CallTaskJava callTaskJava;
33+
private CallTask callTaskJava;
3334

34-
FuncCallTaskBuilder() {
35-
callTaskJava = new CallTaskJava(new CallJava() {});
36-
super.setTask(callTaskJava.getCallJava());
37-
}
35+
FuncCallTaskBuilder() {}
3836

3937
@Override
4038
protected FuncCallTaskBuilder self() {
4139
return this;
4240
}
4341

44-
public <T, V> FuncCallTaskBuilder function(Function<T, V> function) {
42+
public <T, V> FuncCallTaskBuilder function(SerializableFunction<T, V> function) {
4543
return function(function, null);
4644
}
4745

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

5250
public <T, V> FuncCallTaskBuilder function(
5351
Function<T, V> function, Class<T> argClass, Class<V> returnClass) {
54-
this.callTaskJava = new CallTaskJava(CallJava.function(function, argClass, returnClass));
55-
super.setTask(this.callTaskJava.getCallJava());
52+
this.callTaskJava =
53+
new CallTask().withCallFunction(CallJava.function(function, argClass, returnClass));
54+
super.setTask(this.callTaskJava.getCallFunction());
5655
return this;
5756
}
5857

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

6766
public <T, V> FuncCallTaskBuilder function(
6867
ContextFunction<T, V> function, Class<T> argClass, Class<V> returnClass) {
69-
this.callTaskJava = new CallTaskJava(CallJava.function(function, argClass, returnClass));
70-
super.setTask(this.callTaskJava.getCallJava());
68+
this.callTaskJava =
69+
new CallTask().withCallFunction(CallJava.function(function, argClass, returnClass));
70+
super.setTask(this.callTaskJava.getCallFunction());
7171
return this;
7272
}
7373

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

8282
public <T, V> FuncCallTaskBuilder function(
8383
FilterFunction<T, V> function, Class<T> argClass, Class<V> outputClass) {
84-
this.callTaskJava = new CallTaskJava(CallJava.function(function, argClass, outputClass));
85-
super.setTask(this.callTaskJava.getCallJava());
84+
this.callTaskJava =
85+
new CallTask().withCallFunction(CallJava.function(function, argClass, outputClass));
86+
super.setTask(this.callTaskJava.getCallFunction());
8687
return this;
8788
}
8889

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

9697
/** Accept a Consumer with explicit input type hint. */
9798
public <T> FuncCallTaskBuilder consumer(Consumer<T> consumer, Class<T> argClass) {
98-
this.callTaskJava = new CallTaskJava(CallJava.consumer(consumer, argClass));
99-
super.setTask(this.callTaskJava.getCallJava());
99+
this.callTaskJava = new CallTask().withCallFunction(CallJava.consumer(consumer, argClass));
100+
super.setTask(this.callTaskJava.getCallFunction());
100101
return this;
101102
}
102103

103-
public CallTaskJava build() {
104+
public CallTask build() {
105+
if (this.callTaskJava == null) {
106+
throw new IllegalStateException(
107+
"Call task is not configured. Call function(...) or consumer(...) before build().");
108+
}
104109
return this.callTaskJava;
105110
}
106111
}

experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/FuncEmitEventPropertiesBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
package io.serverlessworkflow.fluent.func;
1717

1818
import io.cloudevents.CloudEventData;
19-
import io.serverlessworkflow.api.reflection.func.SerializableFunction;
2019
import io.serverlessworkflow.api.types.func.ContextFunction;
2120
import io.serverlessworkflow.api.types.func.EventDataFunction;
2221
import io.serverlessworkflow.api.types.func.FilterFunction;
22+
import io.serverlessworkflow.api.types.func.SerializableFunction;
2323
import io.serverlessworkflow.fluent.spec.AbstractEventPropertiesBuilder;
2424
import java.util.function.Function;
2525

experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/FuncForTaskBuilder.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
*/
1616
package io.serverlessworkflow.fluent.func;
1717

18+
import io.serverlessworkflow.api.types.CallTask;
19+
import io.serverlessworkflow.api.types.ForTask;
1820
import io.serverlessworkflow.api.types.ForTaskConfiguration;
1921
import io.serverlessworkflow.api.types.Task;
2022
import io.serverlessworkflow.api.types.TaskItem;
2123
import io.serverlessworkflow.api.types.func.CallJava;
22-
import io.serverlessworkflow.api.types.func.CallTaskJava;
23-
import io.serverlessworkflow.api.types.func.ForTaskFunction;
2424
import io.serverlessworkflow.api.types.func.LoopFunction;
2525
import io.serverlessworkflow.api.types.func.LoopPredicate;
2626
import io.serverlessworkflow.api.types.func.LoopPredicateIndex;
27+
import io.serverlessworkflow.api.types.utils.ForTaskFunction;
2728
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
2829
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
2930
import io.serverlessworkflow.fluent.spec.TaskBaseBuilder;
@@ -39,14 +40,14 @@ public class FuncForTaskBuilder extends TaskBaseBuilder<FuncForTaskBuilder>
3940
ConditionalTaskBuilder<FuncForTaskBuilder>,
4041
ForEachTaskFluent<FuncForTaskBuilder, FuncTaskItemListBuilder> {
4142

42-
private final ForTaskFunction forTaskFunction;
43+
private final ForTask forTask;
4344
private final List<TaskItem> items;
4445

4546
FuncForTaskBuilder() {
46-
this.forTaskFunction = new ForTaskFunction();
47-
this.forTaskFunction.withFor(new ForTaskConfiguration());
47+
this.forTask = new ForTask();
48+
this.forTask.withFor(new ForTaskConfiguration());
4849
this.items = new ArrayList<>();
49-
super.setTask(forTaskFunction);
50+
super.setTask(forTask);
5051
}
5152

5253
@Override
@@ -55,23 +56,23 @@ protected FuncForTaskBuilder self() {
5556
}
5657

5758
public <T, V> FuncForTaskBuilder whileC(LoopPredicate<T, V> predicate) {
58-
this.forTaskFunction.withWhile(predicate);
59+
ForTaskFunction.withWhile(forTask, predicate);
5960
return this;
6061
}
6162

6263
public <T, V> FuncForTaskBuilder whileC(LoopPredicateIndex<T, V> predicate) {
63-
this.forTaskFunction.withWhile(predicate);
64+
ForTaskFunction.withWhile(forTask, predicate);
6465
return this;
6566
}
6667

6768
public <T, V> FuncForTaskBuilder collection(Function<T, Collection<V>> collectionF) {
68-
this.forTaskFunction.withCollection(collectionF);
69+
ForTaskFunction.withCollection(forTask, collectionF);
6970
return this;
7071
}
7172

7273
public <T, V> FuncForTaskBuilder collection(
7374
Function<T, Collection<V>> collectionF, Class<T> clazz) {
74-
this.forTaskFunction.withCollection(collectionF, clazz);
75+
ForTaskFunction.withCollection(forTask, collectionF, clazz);
7576
return this;
7677
}
7778

@@ -84,9 +85,9 @@ public <T, V, R> FuncForTaskBuilder tasks(String name, LoopFunction<T, V, R> fun
8485
name,
8586
new Task()
8687
.withCallTask(
87-
new CallTaskJava(
88-
CallJava.loopFunction(
89-
function, this.forTaskFunction.getFor().getEach())))));
88+
new CallTask()
89+
.withCallFunction(
90+
CallJava.loopFunction(function, this.forTask.getFor().getEach())))));
9091
return this;
9192
}
9293

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

9798
@Override
9899
public FuncForTaskBuilder each(String each) {
99-
this.forTaskFunction.getFor().withEach(each);
100+
this.forTask.getFor().withEach(each);
100101
return this;
101102
}
102103

103104
@Override
104105
public FuncForTaskBuilder in(String in) {
105-
this.forTaskFunction.getFor().withIn(in);
106+
this.forTask.getFor().withIn(in);
106107
return this;
107108
}
108109

109110
@Override
110111
public FuncForTaskBuilder at(String at) {
111-
this.forTaskFunction.getFor().withAt(at);
112+
this.forTask.getFor().withAt(at);
112113
return this;
113114
}
114115

115116
@Override
116117
public FuncForTaskBuilder whileC(String expression) {
117-
this.forTaskFunction.setWhile(expression);
118+
this.forTask.setWhile(expression);
118119
return this;
119120
}
120121

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

128-
public ForTaskFunction build() {
129-
this.forTaskFunction.setDo(this.items);
130-
return this.forTaskFunction;
129+
public ForTask build() {
130+
this.forTask.setDo(this.items);
131+
return this.forTask;
131132
}
132133
}

experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/FuncForkTaskBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
*/
1616
package io.serverlessworkflow.fluent.func;
1717

18+
import io.serverlessworkflow.api.types.CallTask;
1819
import io.serverlessworkflow.api.types.Task;
1920
import io.serverlessworkflow.api.types.TaskItem;
2021
import io.serverlessworkflow.api.types.func.CallJava;
21-
import io.serverlessworkflow.api.types.func.CallTaskJava;
2222
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
2323
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
2424
import io.serverlessworkflow.fluent.spec.AbstractForkTaskBuilder;
@@ -61,7 +61,8 @@ public <T, V> FuncForkTaskBuilder branch(
6161
this.defaultBranchName(name, this.currentOffset()),
6262
new Task()
6363
.withCallTask(
64-
new CallTaskJava(CallJava.function(function, argParam, returnClass)))));
64+
new CallTask()
65+
.withCallFunction(CallJava.function(function, argParam, returnClass)))));
6566
return this;
6667
}
6768

experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/FuncListenTaskBuilder.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
*/
1616
package io.serverlessworkflow.fluent.func;
1717

18-
import io.serverlessworkflow.api.types.AnyEventConsumptionStrategy;
19-
import io.serverlessworkflow.api.types.ListenTask;
20-
import io.serverlessworkflow.api.types.func.UntilPredicate;
18+
import io.serverlessworkflow.api.types.utils.TaskPredicate;
19+
import io.serverlessworkflow.api.types.utils.TypesUtils;
2120
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
2221
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
2322
import io.serverlessworkflow.fluent.spec.AbstractListenTaskBuilder;
@@ -28,14 +27,13 @@ public class FuncListenTaskBuilder
2827
implements ConditionalTaskBuilder<FuncListenTaskBuilder>,
2928
FuncTaskTransformations<FuncListenTaskBuilder> {
3029

31-
private UntilPredicate untilPredicate;
32-
3330
FuncListenTaskBuilder(FuncTaskItemListBuilder factory) {
3431
super(factory);
3532
}
3633

3734
public <T> FuncListenTaskBuilder until(Predicate<T> predicate, Class<T> predClass) {
38-
untilPredicate = new UntilPredicate().withPredicate(predicate, predClass);
35+
TaskPredicate.withPredicate(
36+
super.getListenTask(), TypesUtils.UNTIL_PRED_NAME, predicate, predClass);
3937
return this;
4038
}
4139

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

4745
@Override
4846
protected FuncListenToBuilder newEventConsumptionStrategyBuilder() {
49-
return new FuncListenToBuilder();
50-
}
51-
52-
@Override
53-
public ListenTask build() {
54-
ListenTask task = super.build();
55-
AnyEventConsumptionStrategy anyEvent =
56-
task.getListen().getTo().getAnyEventConsumptionStrategy();
57-
if (untilPredicate != null && anyEvent != null) {
58-
anyEvent.withUntil(untilPredicate);
59-
}
60-
return task;
47+
return new FuncListenToBuilder(super.getListenTask());
6148
}
6249
}

experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/FuncListenToBuilder.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818
import io.serverlessworkflow.api.types.AllEventConsumptionStrategy;
1919
import io.serverlessworkflow.api.types.AnyEventConsumptionStrategy;
20+
import io.serverlessworkflow.api.types.ListenTask;
2021
import io.serverlessworkflow.api.types.ListenTo;
2122
import io.serverlessworkflow.api.types.OneEventConsumptionStrategy;
2223
import io.serverlessworkflow.api.types.Until;
2324
import io.serverlessworkflow.api.types.func.ContextPredicate;
2425
import io.serverlessworkflow.api.types.func.FilterPredicate;
25-
import io.serverlessworkflow.api.types.func.UntilPredicate;
26+
import io.serverlessworkflow.api.types.utils.TaskPredicate;
27+
import io.serverlessworkflow.api.types.utils.TypesUtils;
2628
import io.serverlessworkflow.fluent.spec.AbstractEventConsumptionStrategyBuilder;
2729
import java.util.function.Predicate;
2830

@@ -31,6 +33,11 @@ public class FuncListenToBuilder
3133
FuncListenToBuilder, ListenTo, FuncEventFilterBuilder> {
3234

3335
private final ListenTo listenTo = new ListenTo();
36+
private final ListenTask listenTask;
37+
38+
public FuncListenToBuilder(ListenTask listenTask) {
39+
this.listenTask = listenTask;
40+
}
3441

3542
@Override
3643
protected FuncEventFilterBuilder newEventFilterBuilder() {
@@ -65,17 +72,17 @@ protected void setUntilForAny(Until until) {
6572
}
6673

6774
public <T> FuncListenToBuilder until(Predicate<T> predicate, Class<T> predClass) {
68-
this.setUntil(new UntilPredicate().withPredicate(predicate, predClass));
75+
TaskPredicate.withPredicate(listenTask, TypesUtils.UNTIL_PRED_NAME, predicate, predClass);
6976
return this;
7077
}
7178

7279
public <T> FuncListenToBuilder until(ContextPredicate<T> predicate, Class<T> predClass) {
73-
this.setUntil(new UntilPredicate().withPredicate(predicate, predClass));
80+
TaskPredicate.withPredicate(listenTask, TypesUtils.UNTIL_PRED_NAME, predicate, predClass);
7481
return this;
7582
}
7683

7784
public <T> FuncListenToBuilder until(FilterPredicate<T> predicate, Class<T> predClass) {
78-
this.setUntil(new UntilPredicate().withPredicate(predicate, predClass));
85+
TaskPredicate.withPredicate(listenTask, TypesUtils.UNTIL_PRED_NAME, predicate, predClass);
7986
return this;
8087
}
8188
}

experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/FuncSetTaskBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package io.serverlessworkflow.fluent.func;
1717

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

2626
public FuncSetTaskBuilder expr(Map<String, Object> map) {
27-
this.setTaskConfiguration = new MapSetTaskConfiguration(map);
27+
this.setTaskConfiguration = MapSetTaskConfiguration.map(map);
2828
return this;
2929
}
3030
}

0 commit comments

Comments
 (0)