File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
main/java/io/serverlessworkflow/impl/expressions/func
test/java/io/serverless/workflow/impl Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,9 @@ public Class<?> objectClass() {
94
94
95
95
@ Override
96
96
public <T > Optional <T > as (Class <T > clazz ) {
97
+ if (WorkflowModel .class .isAssignableFrom (clazz )) {
98
+ return Optional .of (clazz .cast (this ));
99
+ }
97
100
return object != null && clazz .isAssignableFrom (object .getClass ())
98
101
? Optional .of (clazz .cast (object ))
99
102
: Optional .empty ();
Original file line number Diff line number Diff line change 33
33
import io .serverlessworkflow .api .types .func .SwitchCaseFunction ;
34
34
import io .serverlessworkflow .impl .WorkflowApplication ;
35
35
import io .serverlessworkflow .impl .WorkflowDefinition ;
36
+ import io .serverlessworkflow .impl .WorkflowModel ;
36
37
import io .serverlessworkflow .impl .expressions .TaskMetadataKeys ;
37
38
import java .util .Collection ;
38
39
import java .util .List ;
@@ -166,6 +167,30 @@ void testIf() throws InterruptedException, ExecutionException {
166
167
}
167
168
}
168
169
170
+ @ Test
171
+ void testIfWithModel () throws InterruptedException , ExecutionException {
172
+ try (WorkflowApplication app = WorkflowApplication .builder ().build ()) {
173
+ Workflow workflow =
174
+ new Workflow ()
175
+ .withDocument (
176
+ new Document ().withNamespace ("test" ).withName ("testIf" ).withVersion ("1.0" ))
177
+ .withDo (
178
+ List .of (
179
+ new TaskItem (
180
+ "java" ,
181
+ new Task ()
182
+ .withCallTask (
183
+ new CallTaskJava (
184
+ withPredicate (
185
+ CallJava .function (
186
+ CallTest ::zeroWithModel , WorkflowModel .class ),
187
+ CallTest ::isOdd ))))));
188
+ WorkflowDefinition definition = app .workflowDefinition (workflow );
189
+ assertThat (definition .instance (3 ).start ().get ().asNumber ().orElseThrow ()).isEqualTo (0 );
190
+ assertThat (definition .instance (4 ).start ().get ().asNumber ().orElseThrow ()).isEqualTo (4 );
191
+ }
192
+ }
193
+
169
194
private <T > CallJava withPredicate (CallJava call , Predicate <T > pred ) {
170
195
return (CallJava )
171
196
call .withMetadata (
@@ -184,6 +209,10 @@ public static int zero(Integer value) {
184
209
return 0 ;
185
210
}
186
211
212
+ public static int zeroWithModel (WorkflowModel value ) {
213
+ return 0 ;
214
+ }
215
+
187
216
public static Integer sum (Object model , Integer item ) {
188
217
return model instanceof Collection ? item : (Integer ) model + item ;
189
218
}
You can’t perform that action at this time.
0 commit comments