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 @@ -94,6 +94,9 @@ public Class<?> objectClass() {

@Override
public <T> Optional<T> as(Class<T> clazz) {
if (WorkflowModel.class.isAssignableFrom(clazz)) {
return Optional.of(clazz.cast(this));
}
return object != null && clazz.isAssignableFrom(object.getClass())
? Optional.of(clazz.cast(object))
: Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.serverlessworkflow.api.types.func.SwitchCaseFunction;
import io.serverlessworkflow.impl.WorkflowApplication;
import io.serverlessworkflow.impl.WorkflowDefinition;
import io.serverlessworkflow.impl.WorkflowModel;
import io.serverlessworkflow.impl.expressions.TaskMetadataKeys;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -166,6 +167,30 @@ void testIf() throws InterruptedException, ExecutionException {
}
}

@Test
void testIfWithModel() throws InterruptedException, ExecutionException {
try (WorkflowApplication app = WorkflowApplication.builder().build()) {
Workflow workflow =
new Workflow()
.withDocument(
new Document().withNamespace("test").withName("testIf").withVersion("1.0"))
.withDo(
List.of(
new TaskItem(
"java",
new Task()
.withCallTask(
new CallTaskJava(
withPredicate(
CallJava.function(
CallTest::zeroWithModel, WorkflowModel.class),
CallTest::isOdd))))));
WorkflowDefinition definition = app.workflowDefinition(workflow);
assertThat(definition.instance(3).start().get().asNumber().orElseThrow()).isEqualTo(0);
assertThat(definition.instance(4).start().get().asNumber().orElseThrow()).isEqualTo(4);
}
}

private <T> CallJava withPredicate(CallJava call, Predicate<T> pred) {
return (CallJava)
call.withMetadata(
Expand All @@ -184,6 +209,10 @@ public static int zero(Integer value) {
return 0;
}

public static int zeroWithModel(WorkflowModel value) {
return 0;
}

public static Integer sum(Object model, Integer item) {
return model instanceof Collection ? item : (Integer) model + item;
}
Expand Down
Loading