-
Notifications
You must be signed in to change notification settings - Fork 78
/
instance_chg.go
179 lines (142 loc) · 4.34 KB
/
instance_chg.go
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
package instance
import (
"github.com/TIBCOSoftware/flogo-contrib/action/flow/model"
"github.com/TIBCOSoftware/flogo-lib/core/data"
)
// ChgType denotes the type of change for an object in an instance
type ChgType int
const (
// CtAdd denotes an addition
CtAdd ChgType = 1
// CtUpd denotes an update
CtUpd ChgType = 2
// CtDel denotes an deletion
CtDel ChgType = 3
)
// WorkItemQueueChange represents a change in the WorkItem Queue
type WorkItemQueueChange struct {
ChgType ChgType
ID int
WorkItem *WorkItem
}
// TaskInstChange represents a change to a TaskInst
type TaskInstChange struct {
ChgType ChgType
ID string
TaskInst *TaskInst
}
// LinkInstChange represents a change to a LinkInst
type LinkInstChange struct {
ChgType ChgType
ID int
LinkInst *LinkInst
}
// InstanceChange represents a change to the instance
type InstanceChange struct {
SubFlowID int
Status model.FlowStatus
AttrChanges []*AttributeChange
tiChanges map[string]*TaskInstChange
liChanges map[int]*LinkInstChange
SubFlowChg *SubFlowChange
State int
}
// InstanceChange represents a change to the instance
type SubFlowChange struct {
SubFlowID int
TaskID string
ChgType ChgType
}
// AttributeChange represents a change to an Attribute
type AttributeChange struct {
SubFlowID int
ChgType ChgType
Attribute *data.Attribute
}
// InstanceChangeTracker is used to track all changes to an instance
type InstanceChangeTracker struct {
wiqChanges map[int]*WorkItemQueueChange
instChanges map[int]*InstanceChange //at most 2
}
// NewInstanceChangeTracker creates an InstanceChangeTracker
func NewInstanceChangeTracker() *InstanceChangeTracker {
return &InstanceChangeTracker{instChanges: make(map[int]*InstanceChange)}
}
func (ict *InstanceChangeTracker) getInstChange(flowId int) *InstanceChange {
change, exists := ict.instChanges[flowId]
if !exists {
change = &InstanceChange{}
ict.instChanges[flowId] = change
}
return change
}
// SetStatus is called to track a state change on an instance
func (ict *InstanceChangeTracker) SetState(subFlowId int, state int) {
ic := ict.getInstChange(subFlowId)
ic.State = state
}
// SetStatus is called to track a status change on an instance
func (ict *InstanceChangeTracker) SetStatus(subFlowId int, status model.FlowStatus) {
ic := ict.getInstChange(subFlowId)
ic.Status = status
}
// AttrChange is called to track a status change of an Attribute
func (ict *InstanceChangeTracker) AttrChange(subFlowId int, chgType ChgType, attribute *data.Attribute) {
ic := ict.getInstChange(subFlowId)
var attrChange AttributeChange
attrChange.ChgType = chgType
attrChange.Attribute = attribute
ic.AttrChanges = append(ic.AttrChanges, &attrChange)
}
// AttrChange is called to track a status change of an Attribute
func (ict *InstanceChangeTracker) SubFlowChange(parentFlowId int, chgType ChgType, subFlowId int, taskID string) {
ic := ict.getInstChange(parentFlowId)
var change SubFlowChange
change.ChgType = chgType
change.SubFlowID = subFlowId
change.TaskID = taskID
ic.SubFlowChg = &change
}
// trackWorkItem records a WorkItem Queue change
func (ict *InstanceChangeTracker) trackWorkItem(wiChange *WorkItemQueueChange) {
if ict.wiqChanges == nil {
ict.wiqChanges = make(map[int]*WorkItemQueueChange)
}
ict.wiqChanges[wiChange.ID] = wiChange
}
// trackTaskData records a TaskInst change
func (ict *InstanceChangeTracker) trackTaskData(subFlowId int, tdChange *TaskInstChange) {
ic := ict.getInstChange(subFlowId)
if ic.tiChanges == nil {
ic.tiChanges = make(map[string]*TaskInstChange)
}
ic.tiChanges[tdChange.ID] = tdChange
}
// trackLinkData records a LinkInst change
func (ict *InstanceChangeTracker) trackLinkData(subFlowId int, ldChange *LinkInstChange) {
ic := ict.getInstChange(subFlowId)
if ic.liChanges == nil {
ic.liChanges = make(map[int]*LinkInstChange)
}
ic.liChanges[ldChange.ID] = ldChange
}
// ResetChanges is used to reset any tracking data stored on instance objects
func (ict *InstanceChangeTracker) ResetChanges() {
//// reset TaskInst objects
//if ict.tdChanges != nil {
// for _, v := range ict.tdChanges {
// if v.TaskInst != nil {
// //v.TaskInst.ResetChanges()
// }
// }
//}
//
//// reset LinkInst objects
//if ict.ldChanges != nil {
// for _, v := range ict.ldChanges {
// if v.LinkInst != nil {
// //v.LinkInst.ResetChanges()
// }
// }
//}
}