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() {
9494
9595 @ Override
9696 public <T > Optional <T > as (Class <T > clazz ) {
97+ if (WorkflowModel .class .isAssignableFrom (clazz )) {
98+ return Optional .of (clazz .cast (this ));
99+ }
97100 return object != null && clazz .isAssignableFrom (object .getClass ())
98101 ? Optional .of (clazz .cast (object ))
99102 : Optional .empty ();
Original file line number Diff line number Diff line change 3333import io .serverlessworkflow .api .types .func .SwitchCaseFunction ;
3434import io .serverlessworkflow .impl .WorkflowApplication ;
3535import io .serverlessworkflow .impl .WorkflowDefinition ;
36+ import io .serverlessworkflow .impl .WorkflowModel ;
3637import io .serverlessworkflow .impl .expressions .TaskMetadataKeys ;
3738import java .util .Collection ;
3839import java .util .List ;
@@ -166,6 +167,30 @@ void testIf() throws InterruptedException, ExecutionException {
166167 }
167168 }
168169
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+
169194 private <T > CallJava withPredicate (CallJava call , Predicate <T > pred ) {
170195 return (CallJava )
171196 call .withMetadata (
@@ -184,6 +209,10 @@ public static int zero(Integer value) {
184209 return 0 ;
185210 }
186211
212+ public static int zeroWithModel (WorkflowModel value ) {
213+ return 0 ;
214+ }
215+
187216 public static Integer sum (Object model , Integer item ) {
188217 return model instanceof Collection ? item : (Integer ) model + item ;
189218 }
You can’t perform that action at this time.
0 commit comments