forked from mendixlabs/mxcli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_microflows_builder_annotations.go
More file actions
244 lines (226 loc) · 7.09 KB
/
cmd_microflows_builder_annotations.go
File metadata and controls
244 lines (226 loc) · 7.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
// SPDX-License-Identifier: Apache-2.0
// Package executor - Microflow flow graph: annotation handling and terminal events
package executor
import (
"github.com/mendixlabs/mxcli/mdl/ast"
"github.com/mendixlabs/mxcli/mdl/types"
"github.com/mendixlabs/mxcli/model"
"github.com/mendixlabs/mxcli/sdk/microflows"
)
// getStatementAnnotations extracts the annotations field from any microflow statement.
func getStatementAnnotations(stmt ast.MicroflowStatement) *ast.ActivityAnnotations {
switch s := stmt.(type) {
case *ast.DeclareStmt:
return s.Annotations
case *ast.MfSetStmt:
return s.Annotations
case *ast.ReturnStmt:
return s.Annotations
case *ast.RaiseErrorStmt:
return s.Annotations
case *ast.CreateObjectStmt:
return s.Annotations
case *ast.ChangeObjectStmt:
return s.Annotations
case *ast.MfCommitStmt:
return s.Annotations
case *ast.DeleteObjectStmt:
return s.Annotations
case *ast.RollbackStmt:
return s.Annotations
case *ast.RetrieveStmt:
return s.Annotations
case *ast.IfStmt:
return s.Annotations
case *ast.LoopStmt:
return s.Annotations
case *ast.WhileStmt:
return s.Annotations
case *ast.LogStmt:
return s.Annotations
case *ast.CallMicroflowStmt:
return s.Annotations
case *ast.CallJavaActionStmt:
return s.Annotations
case *ast.ExecuteDatabaseQueryStmt:
return s.Annotations
case *ast.CallExternalActionStmt:
return s.Annotations
case *ast.BreakStmt:
return s.Annotations
case *ast.ContinueStmt:
return s.Annotations
case *ast.ListOperationStmt:
return s.Annotations
case *ast.AggregateListStmt:
return s.Annotations
case *ast.CreateListStmt:
return s.Annotations
case *ast.AddToListStmt:
return s.Annotations
case *ast.RemoveFromListStmt:
return s.Annotations
case *ast.ShowPageStmt:
return s.Annotations
case *ast.ClosePageStmt:
return s.Annotations
case *ast.ShowHomePageStmt:
return s.Annotations
case *ast.ShowMessageStmt:
return s.Annotations
case *ast.ValidationFeedbackStmt:
return s.Annotations
case *ast.RestCallStmt:
return s.Annotations
default:
return nil
}
}
// mergeStatementAnnotations extracts annotations from a statement and merges into pendingAnnotations.
func (fb *flowBuilder) mergeStatementAnnotations(stmt ast.MicroflowStatement) {
ann := getStatementAnnotations(stmt)
if ann == nil {
return
}
if fb.pendingAnnotations == nil {
fb.pendingAnnotations = &ast.ActivityAnnotations{}
}
if ann.Position != nil {
fb.pendingAnnotations.Position = ann.Position
}
if ann.Caption != "" {
fb.pendingAnnotations.Caption = ann.Caption
}
if ann.Color != "" {
fb.pendingAnnotations.Color = ann.Color
}
if ann.AnnotationText != "" {
fb.pendingAnnotations.AnnotationText = ann.AnnotationText
}
}
// applyAnnotations applies pending annotations to the activity identified by activityID.
// Note: @position is already applied before the activity is created (in addStatement),
// so this method only handles @caption, @color, and @annotation.
func (fb *flowBuilder) applyAnnotations(activityID model.ID, ann *ast.ActivityAnnotations) {
if ann == nil {
return
}
// Find the object by ID for @caption, @color, and @excluded
if ann.Caption != "" || ann.Color != "" || ann.Excluded {
for _, obj := range fb.objects {
if obj.GetID() != activityID {
continue
}
switch activity := obj.(type) {
case *microflows.ActionActivity:
if ann.Caption != "" {
activity.Caption = ann.Caption
activity.AutoGenerateCaption = false
}
if ann.Color != "" {
activity.BackgroundColor = ann.Color
}
if ann.Excluded {
activity.Disabled = true
}
case *microflows.ExclusiveSplit:
// Splits carry a human-readable Caption (e.g. "Right format?")
// independent of the expression/rule being evaluated.
if ann.Caption != "" {
activity.Caption = ann.Caption
}
case *microflows.InheritanceSplit:
if ann.Caption != "" {
activity.Caption = ann.Caption
}
case *microflows.LoopedActivity:
// LOOP / WHILE activities can carry a caption just like
// splits and action activities.
if ann.Caption != "" {
activity.Caption = ann.Caption
}
}
break
}
}
// @annotation — attach an annotation object
if ann.AnnotationText != "" {
fb.attachAnnotation(ann.AnnotationText, activityID)
}
}
// addEndEventWithReturn creates an EndEvent with the specified return value.
// This produces an actual EndEvent activity in the flow graph, allowing RETURN
// to work correctly inside IF/ELSE branches and error handler bodies.
func (fb *flowBuilder) addEndEventWithReturn(s *ast.ReturnStmt) model.ID {
retVal := ""
if s.Value != nil {
retVal = fb.exprToString(s.Value)
}
endEvent := µflows.EndEvent{
BaseMicroflowObject: microflows.BaseMicroflowObject{
BaseElement: model.BaseElement{ID: model.ID(types.GenerateID())},
Position: model.Point{X: fb.posX, Y: fb.posY},
Size: model.Size{Width: EventSize, Height: EventSize},
},
ReturnValue: retVal,
}
fb.objects = append(fb.objects, endEvent)
fb.endsWithReturn = true
fb.posX += fb.spacing / 2
return endEvent.ID
}
// addErrorEvent creates an ErrorEvent to terminate the flow with an error.
// Used by RAISE ERROR statement in custom error handlers.
func (fb *flowBuilder) addErrorEvent() model.ID {
errorEvent := µflows.ErrorEvent{
BaseMicroflowObject: microflows.BaseMicroflowObject{
BaseElement: model.BaseElement{ID: model.ID(types.GenerateID())},
Position: model.Point{X: fb.posX, Y: fb.posY},
Size: model.Size{Width: EventSize, Height: EventSize},
},
}
fb.objects = append(fb.objects, errorEvent)
fb.endsWithReturn = true // Mark as terminated (no merge needed)
fb.posX += fb.spacing / 2
return errorEvent.ID
}
// attachAnnotation creates an Annotation object positioned above the given activity
// and connects them with an AnnotationFlow.
func (fb *flowBuilder) attachAnnotation(text string, activityID model.ID) {
// Find the activity's position to place annotation above it
var actX, actY int
for _, obj := range fb.objects {
if obj.GetID() == activityID {
pos := obj.GetPosition()
actX = pos.X
actY = pos.Y
break
}
}
annotation := µflows.Annotation{
BaseMicroflowObject: microflows.BaseMicroflowObject{
BaseElement: model.BaseElement{ID: model.ID(types.GenerateID())},
Position: model.Point{X: actX, Y: actY - 100},
Size: model.Size{Width: 200, Height: 50},
},
Caption: text,
}
fb.objects = append(fb.objects, annotation)
fb.annotationFlows = append(fb.annotationFlows, µflows.AnnotationFlow{
BaseElement: model.BaseElement{ID: model.ID(types.GenerateID())},
OriginID: annotation.ID,
DestinationID: activityID,
})
}
// attachFreeAnnotation creates a free-floating Annotation not connected to any activity.
func (fb *flowBuilder) attachFreeAnnotation(text string) {
annotation := µflows.Annotation{
BaseMicroflowObject: microflows.BaseMicroflowObject{
BaseElement: model.BaseElement{ID: model.ID(types.GenerateID())},
Position: model.Point{X: fb.posX, Y: fb.posY - 100},
Size: model.Size{Width: 200, Height: 50},
},
Caption: text,
}
fb.objects = append(fb.objects, annotation)
}