|
18 | 18 | import io.serverlessworkflow.api.Workflow;
|
19 | 19 | import io.serverlessworkflow.api.actions.Action;
|
20 | 20 | import io.serverlessworkflow.api.branches.Branch;
|
| 21 | +import io.serverlessworkflow.api.defaultdef.DefaultConditionDefinition; |
21 | 22 | import io.serverlessworkflow.api.events.EventDefinition;
|
22 | 23 | import io.serverlessworkflow.api.events.OnEvents;
|
23 | 24 | import io.serverlessworkflow.api.functions.FunctionDefinition;
|
24 | 25 | import io.serverlessworkflow.api.functions.FunctionRef;
|
25 | 26 | import io.serverlessworkflow.api.interfaces.State;
|
26 | 27 | import io.serverlessworkflow.api.start.Start;
|
27 | 28 | import io.serverlessworkflow.api.states.*;
|
| 29 | +import io.serverlessworkflow.api.switchconditions.DataCondition; |
| 30 | +import io.serverlessworkflow.api.switchconditions.EventCondition; |
28 | 31 | import java.util.*;
|
29 | 32 | import java.util.stream.Collectors;
|
30 | 33 |
|
@@ -291,9 +294,40 @@ public static long getNumOfStates(Workflow workflow, DefaultState.Type type) {
|
291 | 294 | }
|
292 | 295 |
|
293 | 296 | public static long getNumOfEndStates(Workflow workflow) {
|
294 |
| - return hasStates(workflow) |
295 |
| - ? workflow.getStates().stream().filter(state -> state.getEnd() != null).count() |
296 |
| - : DEFAULT_STATE_COUNT; |
| 297 | + if (hasStates(workflow)) { |
| 298 | + long count = workflow.getStates().stream().filter(state -> state.getEnd() != null).count(); |
| 299 | + List<State> switchStates = |
| 300 | + workflow.getStates().stream() |
| 301 | + .filter(state -> state instanceof SwitchState) |
| 302 | + .collect(Collectors.toList()); |
| 303 | + for (State state : switchStates) { |
| 304 | + SwitchState switchState = (SwitchState) state; |
| 305 | + List<EventCondition> eventConditions = switchState.getEventConditions(); |
| 306 | + if (eventConditions != null) { |
| 307 | + count = |
| 308 | + count |
| 309 | + + eventConditions.stream() |
| 310 | + .filter(eventCondition -> eventCondition.getEnd() != null) |
| 311 | + .count(); |
| 312 | + } |
| 313 | + List<DataCondition> dataConditions = switchState.getDataConditions(); |
| 314 | + if (dataConditions != null) { |
| 315 | + count = |
| 316 | + count |
| 317 | + + dataConditions.stream() |
| 318 | + .filter(dataCondition -> dataCondition.getEnd() != null) |
| 319 | + .count(); |
| 320 | + } |
| 321 | + DefaultConditionDefinition defaultCondition = switchState.getDefaultCondition(); |
| 322 | + if (defaultCondition != null) { |
| 323 | + count = defaultCondition.getEnd() != null ? 1 : 0; |
| 324 | + } |
| 325 | + } |
| 326 | + |
| 327 | + return count; |
| 328 | + } else { |
| 329 | + return DEFAULT_STATE_COUNT; |
| 330 | + } |
297 | 331 | }
|
298 | 332 |
|
299 | 333 | private static List<Action> getActionsWhichUsesFunctionDefinition(
|
|
0 commit comments