1
1
package mpr
2
2
3
- import "slices"
4
-
5
3
func transformMicroflow (mf MxDocument ) MxDocument {
6
4
// Transform a microflow
7
5
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
- // }
14
6
15
7
cleanedData := bsonToMap (mf .Attributes )
16
8
objsCollection := cleanedData ["ObjectCollection" ].(map [string ]interface {})
@@ -24,32 +16,14 @@ func transformMicroflow(mf MxDocument) MxDocument {
24
16
ID : startEvent .ID ,
25
17
Attributes : startEvent .Attributes ,
26
18
}
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 )
34
20
mainFlow := make ([]map [string ]interface {}, 0 )
21
+ // FIXME: flow conversion is not working for loops yet; it generates incomplete flows
35
22
extractMainFlow (& mainFlow , & root )
36
23
mf .Attributes ["MainFunction" ] = mainFlow
37
24
return mf
38
25
}
39
26
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
-
53
27
func extractMainFlow (mainFlow * []map [string ]interface {}, current * MxMicroflowNode ) {
54
28
c := convertMxMicroflowNodeToMap (current )
55
29
* mainFlow = append (* mainFlow , c )
@@ -85,15 +59,14 @@ func extractMainFlow(mainFlow *[]map[string]interface{}, current *MxMicroflowNod
85
59
}
86
60
}
87
61
88
- func buildDAG (current * MxMicroflowNode , parent * MxMicroflowNode , flows []MxMicroflowEdge , objects []MxMicroflowObject , allLoops * [][] MxMicroflowNode ) {
62
+ func buildDAG (current * MxMicroflowNode , parent * MxMicroflowNode , flows []MxMicroflowEdge , objects []MxMicroflowObject ) {
89
63
90
64
current .Parent = parent
91
65
children := make ([]MxMicroflowNode , 0 )
92
66
93
67
switch current .Type {
94
68
case "Microflows$ExclusiveMerge" :
95
- newLoop := make ([]MxMicroflowNode , 0 )
96
- start := backtrack (current , current .Parent , & newLoop )
69
+ start := backtrack (current , current .Parent )
97
70
if start == nil {
98
71
// no loop
99
72
edges := getMxMicroflowEdgesByOrigin (flows , current .ID )
@@ -105,17 +78,12 @@ func buildDAG(current *MxMicroflowNode, parent *MxMicroflowNode, flows []MxMicro
105
78
Attributes : edge .Attributes ,
106
79
}
107
80
108
- buildDAG (& edgeNode , current , flows , objects , allLoops )
81
+ buildDAG (& edgeNode , current , flows , objects )
109
82
children = append (children , edgeNode )
110
83
}
111
84
} else {
112
85
// 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
119
87
}
120
88
case "Microflows$SequenceFlow" :
121
89
obj := getMxMicroflowObjectByID (objects , current .Attributes ["DestinationPointer" ].(string ))
@@ -124,7 +92,7 @@ func buildDAG(current *MxMicroflowNode, parent *MxMicroflowNode, flows []MxMicro
124
92
ID : obj .ID ,
125
93
Attributes : obj .Attributes ,
126
94
}
127
- buildDAG (& objectNode , current , flows , objects , allLoops )
95
+ buildDAG (& objectNode , current , flows , objects )
128
96
children = append (children , objectNode )
129
97
default :
130
98
edges := getMxMicroflowEdgesByOrigin (flows , current .ID )
@@ -136,24 +104,21 @@ func buildDAG(current *MxMicroflowNode, parent *MxMicroflowNode, flows []MxMicro
136
104
Attributes : edge .Attributes ,
137
105
}
138
106
139
- buildDAG (& edgeNode , current , flows , objects , allLoops )
107
+ buildDAG (& edgeNode , current , flows , objects )
140
108
children = append (children , edgeNode )
141
109
}
142
110
}
143
111
current .Children = & children
144
112
}
145
113
146
- func backtrack (current * MxMicroflowNode , parent * MxMicroflowNode , path * [] MxMicroflowNode ) * MxMicroflowNode {
114
+ func backtrack (current * MxMicroflowNode , parent * MxMicroflowNode ) * MxMicroflowNode {
147
115
if parent == nil {
148
116
return nil
149
117
}
150
- newSlice := append ([]MxMicroflowNode {}, * path ... )
151
- newSlice = append (newSlice , * parent )
152
- * path = newSlice
153
118
if parent .ID == current .ID {
154
119
return parent
155
120
}
156
- return backtrack (current , parent .Parent , path )
121
+ return backtrack (current , parent .Parent )
157
122
}
158
123
159
124
func getMxMicroflowEdgesByOrigin (edges []MxMicroflowEdge , originId string ) []MxMicroflowEdge {
0 commit comments