Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #195 - Fix 'End' model when compensate is defined #212

Merged
merged 1 commit into from
Oct 9, 2024
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
2 changes: 1 addition & 1 deletion model/action_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand Down
4 changes: 2 additions & 2 deletions model/workflow_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand All @@ -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

Expand Down
72 changes: 72 additions & 0 deletions parser/testdata/workflows/compensation.sw.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
Loading