Skip to content

Commit 9efbde2

Browse files
committed
Loops in microflows are not supported yet. Requires more graph work
1 parent 1cab402 commit 9efbde2

File tree

1 file changed

+10
-45
lines changed

1 file changed

+10
-45
lines changed

mpr/microflow.go

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
package mpr
22

3-
import "slices"
4-
53
func transformMicroflow(mf MxDocument) MxDocument {
64
// Transform a microflow
75
log.Infof("Transforming microflow %s", mf.Name)
8-
// if !Contains([]string{"MicroflowSimple", "MicroflowSplit", "MicroflowSplitThenMerge", "MicroflowComplexSplit", "MicroflowLoop"}, mf.Name) {
9-
// return mf
10-
// }
11-
// if !Contains([]string{"MicroflowLoop"}, mf.Name) {
12-
// return mf
13-
// }
146

157
cleanedData := bsonToMap(mf.Attributes)
168
objsCollection := cleanedData["ObjectCollection"].(map[string]interface{})
@@ -24,32 +16,14 @@ func transformMicroflow(mf MxDocument) MxDocument {
2416
ID: startEvent.ID,
2517
Attributes: startEvent.Attributes,
2618
}
27-
allLoops := make([][]MxMicroflowNode, 0)
28-
buildDAG(&root, nil, flows, objs, &allLoops)
29-
30-
loops := make([]interface{}, 0)
31-
extractLoops(&loops, allLoops)
32-
mf.Attributes["Loops"] = loops
33-
19+
buildDAG(&root, nil, flows, objs)
3420
mainFlow := make([]map[string]interface{}, 0)
21+
// FIXME: flow conversion is not working for loops yet; it generates incomplete flows
3522
extractMainFlow(&mainFlow, &root)
3623
mf.Attributes["MainFunction"] = mainFlow
3724
return mf
3825
}
3926

40-
func extractLoops(loops *[]interface{}, allLoops [][]MxMicroflowNode) {
41-
for _, loop := range allLoops {
42-
myLoop := make([]map[string]interface{}, 0)
43-
for _, node := range loop {
44-
myNode := convertMxMicroflowNodeToMap(&node)
45-
myLoop = append(myLoop, myNode)
46-
}
47-
// reverse the order so that the sequence starts with ExclusiveMerge
48-
slices.Reverse(myLoop)
49-
*loops = append(*loops, myLoop)
50-
}
51-
}
52-
5327
func extractMainFlow(mainFlow *[]map[string]interface{}, current *MxMicroflowNode) {
5428
c := convertMxMicroflowNodeToMap(current)
5529
*mainFlow = append(*mainFlow, c)
@@ -85,15 +59,14 @@ func extractMainFlow(mainFlow *[]map[string]interface{}, current *MxMicroflowNod
8559
}
8660
}
8761

88-
func buildDAG(current *MxMicroflowNode, parent *MxMicroflowNode, flows []MxMicroflowEdge, objects []MxMicroflowObject, allLoops *[][]MxMicroflowNode) {
62+
func buildDAG(current *MxMicroflowNode, parent *MxMicroflowNode, flows []MxMicroflowEdge, objects []MxMicroflowObject) {
8963

9064
current.Parent = parent
9165
children := make([]MxMicroflowNode, 0)
9266

9367
switch current.Type {
9468
case "Microflows$ExclusiveMerge":
95-
newLoop := make([]MxMicroflowNode, 0)
96-
start := backtrack(current, current.Parent, &newLoop)
69+
start := backtrack(current, current.Parent)
9770
if start == nil {
9871
// no loop
9972
edges := getMxMicroflowEdgesByOrigin(flows, current.ID)
@@ -105,17 +78,12 @@ func buildDAG(current *MxMicroflowNode, parent *MxMicroflowNode, flows []MxMicro
10578
Attributes: edge.Attributes,
10679
}
10780

108-
buildDAG(&edgeNode, current, flows, objects, allLoops)
81+
buildDAG(&edgeNode, current, flows, objects)
10982
children = append(children, edgeNode)
11083
}
11184
} else {
11285
// loop
113-
newSlice := append([][]MxMicroflowNode{}, *allLoops...)
114-
newSlice = append(newSlice, newLoop)
115-
*allLoops = newSlice
116-
// mark the merge node as loop for future checks
117-
current.Attributes["Loop"] = true
118-
children = append(children, *start)
86+
return
11987
}
12088
case "Microflows$SequenceFlow":
12189
obj := getMxMicroflowObjectByID(objects, current.Attributes["DestinationPointer"].(string))
@@ -124,7 +92,7 @@ func buildDAG(current *MxMicroflowNode, parent *MxMicroflowNode, flows []MxMicro
12492
ID: obj.ID,
12593
Attributes: obj.Attributes,
12694
}
127-
buildDAG(&objectNode, current, flows, objects, allLoops)
95+
buildDAG(&objectNode, current, flows, objects)
12896
children = append(children, objectNode)
12997
default:
13098
edges := getMxMicroflowEdgesByOrigin(flows, current.ID)
@@ -136,24 +104,21 @@ func buildDAG(current *MxMicroflowNode, parent *MxMicroflowNode, flows []MxMicro
136104
Attributes: edge.Attributes,
137105
}
138106

139-
buildDAG(&edgeNode, current, flows, objects, allLoops)
107+
buildDAG(&edgeNode, current, flows, objects)
140108
children = append(children, edgeNode)
141109
}
142110
}
143111
current.Children = &children
144112
}
145113

146-
func backtrack(current *MxMicroflowNode, parent *MxMicroflowNode, path *[]MxMicroflowNode) *MxMicroflowNode {
114+
func backtrack(current *MxMicroflowNode, parent *MxMicroflowNode) *MxMicroflowNode {
147115
if parent == nil {
148116
return nil
149117
}
150-
newSlice := append([]MxMicroflowNode{}, *path...)
151-
newSlice = append(newSlice, *parent)
152-
*path = newSlice
153118
if parent.ID == current.ID {
154119
return parent
155120
}
156-
return backtrack(current, parent.Parent, path)
121+
return backtrack(current, parent.Parent)
157122
}
158123

159124
func getMxMicroflowEdgesByOrigin(edges []MxMicroflowEdge, originId string) []MxMicroflowEdge {

0 commit comments

Comments
 (0)