Skip to content

Commit acc5db6

Browse files
committed
Use ModelFactory for resolve last state model
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
1 parent 68837c4 commit acc5db6

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/EnrichWithModelBiFunction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
/**
2121
* A function that enriches a typed value by combining it with the root workflow input.
2222
*
23-
* <p>This is useful when you need to merge a task output or state value with the original
24-
* workflow input, where the value is typed and the root input is a {@link WorkflowModel}.
23+
* <p>This is useful when you need to merge a task output or state value with the original workflow
24+
* input, where the value is typed and the root input is a {@link WorkflowModel}.
2525
*
2626
* @param <T> The type of the input value to be enriched
2727
* @param <R> The type of the enriched result

experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/FuncDSL.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,18 @@ public static <T, R> JavaContextFunction<T, R> enrich(
309309
return (lastState, workflowContext) -> {
310310
Objects.requireNonNull(lastStateClass, "lastStateClass must not be null");
311311
final WorkflowModel rootInput = workflowContext.instanceData().input();
312-
final T typedLastState = lastStateClass.cast(lastState);
312+
final WorkflowModel lastStateModel =
313+
workflowContext.definition().application().modelFactory().fromAny(lastState);
314+
final T typedLastState =
315+
lastStateModel
316+
.as(lastStateClass)
317+
.orElseThrow(
318+
() ->
319+
new IllegalArgumentException(
320+
"Cannot convert lastState of type "
321+
+ (lastState != null ? lastState.getClass().getName() : "null")
322+
+ " to "
323+
+ lastStateClass.getName()));
313324
return fn.apply(typedLastState, rootInput);
314325
};
315326
}

0 commit comments

Comments
 (0)