Skip to content

Commit dfe9e9f

Browse files
committed
[Fix #490] Implement until condition for any
1 parent 0c04f69 commit dfe9e9f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

impl/core/src/main/java/io/serverlessworkflow/impl/executors/ListenExecutor.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,21 @@
1818
import com.fasterxml.jackson.databind.JsonNode;
1919
import com.fasterxml.jackson.databind.node.ArrayNode;
2020
import io.cloudevents.CloudEvent;
21+
import io.serverlessworkflow.api.types.AnyEventConsumptionStrategy;
2122
import io.serverlessworkflow.api.types.EventFilter;
2223
import io.serverlessworkflow.api.types.ListenTask;
2324
import io.serverlessworkflow.api.types.ListenTaskConfiguration;
2425
import io.serverlessworkflow.api.types.ListenTaskConfiguration.ListenAndReadAs;
2526
import io.serverlessworkflow.api.types.ListenTo;
2627
import io.serverlessworkflow.api.types.SubscriptionIterator;
28+
import io.serverlessworkflow.api.types.Until;
2729
import io.serverlessworkflow.api.types.Workflow;
2830
import io.serverlessworkflow.impl.TaskContext;
2931
import io.serverlessworkflow.impl.WorkflowApplication;
3032
import io.serverlessworkflow.impl.WorkflowContext;
3133
import io.serverlessworkflow.impl.WorkflowFilter;
3234
import io.serverlessworkflow.impl.WorkflowPosition;
35+
import io.serverlessworkflow.impl.WorkflowUtils;
3336
import io.serverlessworkflow.impl.events.CloudEventUtils;
3437
import io.serverlessworkflow.impl.events.EventRegistration;
3538
import io.serverlessworkflow.impl.events.EventRegistrationBuilder;
@@ -72,9 +75,18 @@ protected ListenExecutorBuilder(
7275
isAnd = true;
7376
registrations = from(to.getAllEventConsumptionStrategy().getAll());
7477
} else if (to.getAnyEventConsumptionStrategy() != null) {
78+
AnyEventConsumptionStrategy any = to.getAnyEventConsumptionStrategy();
7579
isAnd = false;
76-
List<EventFilter> eventFilters = to.getAnyEventConsumptionStrategy().getAny();
80+
List<EventFilter> eventFilters = any.getAny();
7781
registrations = eventFilters.isEmpty() ? registerToAll() : from(eventFilters);
82+
Until untilDesc = any.getUntil();
83+
if (untilDesc != null) {
84+
if (untilDesc.getAnyEventUntilCondition() != null) {
85+
until =
86+
WorkflowUtils.buildWorkflowFilter(
87+
application.expressionFactory(), untilDesc.getAnyEventUntilCondition());
88+
}
89+
}
7890
} else if (to.getOneEventConsumptionStrategy() != null) {
7991
isAnd = false;
8092
registrations = List.of(from(to.getOneEventConsumptionStrategy().getOne()));

impl/core/src/test/resources/listen-to-any-filter.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ do:
1414
- with:
1515
type: com.fake-hospital.vitals.measurements.bpm
1616
data: ${ .bpm < 60 or .bpm > 100 }
17+
until: ( . | length ) > 0
1718
foreach:
1819
item: event
1920
do:
2021
- isSick:
2122
set:
2223
temperature: ${$event.temperature}
23-
isSick: true
24+
isSick: true
25+

0 commit comments

Comments
 (0)