|
3 | 3 | import io.iworkflow.core.ObjectEncoder;
|
4 | 4 | import io.iworkflow.core.Registry;
|
5 | 5 | import io.iworkflow.core.StateDef;
|
| 6 | +import io.iworkflow.core.WorkflowDefinitionException; |
| 7 | +import io.iworkflow.gen.models.ExecuteApiFailurePolicy; |
6 | 8 | import io.iworkflow.gen.models.StateMovement;
|
7 | 9 | import io.iworkflow.gen.models.WorkflowStateOptions;
|
8 | 10 |
|
@@ -36,10 +38,40 @@ public static StateMovement toGenerated(final io.iworkflow.core.StateMovement st
|
36 | 38 | stateOptions.skipWaitUntil(true);
|
37 | 39 | }
|
38 | 40 |
|
| 41 | + autoFillFailureProceedingStateOptions(stateOptions, workflowType, registry); |
| 42 | + |
39 | 43 | if (stateOptions != null) {
|
40 | 44 | movement.stateOptions(stateOptions);
|
41 | 45 | }
|
42 | 46 | }
|
43 | 47 | return movement;
|
44 | 48 | }
|
| 49 | + |
| 50 | + public static void autoFillFailureProceedingStateOptions(WorkflowStateOptions stateOptions, final String workflowType, final Registry registry) { |
| 51 | + if (stateOptions == null) { |
| 52 | + return; |
| 53 | + } |
| 54 | + if (stateOptions.getExecuteApiFailurePolicy() == ExecuteApiFailurePolicy.PROCEED_TO_CONFIGURED_STATE |
| 55 | + && stateOptions.getExecuteApiFailureProceedStateOptions() == null) { |
| 56 | + |
| 57 | + // fill the state options for the proceeding state |
| 58 | + String proceedStateId = stateOptions.getExecuteApiFailureProceedStateId(); |
| 59 | + final StateDef proceedStatDef = registry.getWorkflowState(workflowType, proceedStateId); |
| 60 | + WorkflowStateOptions proceedStateOptions = proceedStatDef.getWorkflowState().getStateOptions(); |
| 61 | + if (proceedStateOptions != null && |
| 62 | + proceedStateOptions.getExecuteApiFailurePolicy() == ExecuteApiFailurePolicy.PROCEED_TO_CONFIGURED_STATE) { |
| 63 | + throw new WorkflowDefinitionException("nested failure handling is not supported. You cannot set a failure proceeding state on top of another failure proceeding state."); |
| 64 | + } |
| 65 | + |
| 66 | + if (shouldSkipWaitUntil(proceedStatDef.getWorkflowState())) { |
| 67 | + if (proceedStateOptions == null) { |
| 68 | + proceedStateOptions = new WorkflowStateOptions().skipWaitUntil(true); |
| 69 | + } else { |
| 70 | + proceedStateOptions.skipWaitUntil(true); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + stateOptions.executeApiFailureProceedStateOptions(proceedStateOptions); |
| 75 | + } |
| 76 | + } |
45 | 77 | }
|
0 commit comments