From 3ee6317b72cf000ce80bc48bc3964044e384cbe8 Mon Sep 17 00:00:00 2001 From: Ricardo Zanini <1538000+ricardozanini@users.noreply.github.com> Date: Wed, 9 Oct 2024 14:50:49 -0400 Subject: [PATCH] Fix #195 - Fix 'End' model when is defined (#212) Signed-off-by: Ricardo Zanini --- model/action_validator.go | 2 +- model/workflow_validator.go | 4 +- .../testdata/workflows/compensation.sw.json | 72 +++++++++++++++++++ 3 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 parser/testdata/workflows/compensation.sw.json diff --git a/model/action_validator.go b/model/action_validator.go index 384469b..3fac375 100644 --- a/model/action_validator.go +++ b/model/action_validator.go @@ -39,7 +39,7 @@ func actionStructLevelValidationCtx(ctx ValidatorContext, structLevel validator. action.SubFlowRef != nil, } - if validationNotExclusiveParamters(values) { + if validationNotExclusiveParameters(values) { structLevel.ReportError(action.FunctionRef, "FunctionRef", "FunctionRef", val.TagExclusive, "") structLevel.ReportError(action.EventRef, "EventRef", "EventRef", val.TagExclusive, "") structLevel.ReportError(action.SubFlowRef, "SubFlowRef", "SubFlowRef", val.TagExclusive, "") diff --git a/model/workflow_validator.go b/model/workflow_validator.go index fd3d7bb..dd9d1e7 100644 --- a/model/workflow_validator.go +++ b/model/workflow_validator.go @@ -217,7 +217,7 @@ func transitionStructLevelValidationCtx(ctx ValidatorContext, structLevel valida func validTransitionAndEnd(structLevel validator.StructLevel, field any, transition *Transition, end *End) { hasTransition := transition != nil - isEnd := end != nil && (end.Terminate || end.ContinueAs != nil || len(end.ProduceEvents) > 0) // TODO: check the spec continueAs/produceEvents to see how it influences the end + isEnd := end != nil && (end.Terminate || end.Compensate || end.ContinueAs != nil || len(end.ProduceEvents) > 0) // TODO: check the spec continueAs/produceEvents to see how it influences the end if !hasTransition && !isEnd { structLevel.ReportError(field, "Transition", "transition", val.TagRequired, "") @@ -226,7 +226,7 @@ func validTransitionAndEnd(structLevel validator.StructLevel, field any, transit } } -func validationNotExclusiveParamters(values []bool) bool { +func validationNotExclusiveParameters(values []bool) bool { hasOne := false hasTwo := false diff --git a/parser/testdata/workflows/compensation.sw.json b/parser/testdata/workflows/compensation.sw.json new file mode 100644 index 0000000..567a501 --- /dev/null +++ b/parser/testdata/workflows/compensation.sw.json @@ -0,0 +1,72 @@ +{ + "id": "compensation", + "version": "1.0", + "name": "Workflow Error example", + "description": "An example of how compensation works", + "start": "printStatus", + "states": [ + { + "name": "printStatus", + "type": "inject", + "data": { + "compensated": false + }, + "compensatedBy" : "compensating", + "transition": "branch" + }, + { + "name": "branch", + "type": "switch", + "dataConditions": [ + { + "condition": ".shouldCompensate==true", + "transition": { + "nextState" : "finish_compensate", + "compensate" : true + } + }, + { + "condition": ".shouldCompensate==false", + "transition": { + "nextState" : "finish_not_compensate", + "compensate" : false + } + } + ], + "defaultCondition": { + "end": true + } + }, + { + "name": "compensating", + "usedForCompensation" : true, + "type": "inject", + "data": { + "compensated": true + }, + "transition" : "compensating_more" + }, + { + "name": "compensating_more", + "usedForCompensation" : true, + "type": "inject", + "data": { + "compensating_more": "Real Betis Balompie" + } + }, + { + "name": "finish_compensate", + "type": "operation", + "actions": [], + "end": { + "compensate": true + } + }, + { + "name": "finish_not_compensate", + "type": "operation", + "actions": [], + "end": true + } + ] +} \ No newline at end of file