forked from vijaynalawade/flogo-contrib
/
definition.go
353 lines (275 loc) · 7.48 KB
/
definition.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
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
package definition
import (
"fmt"
"github.com/TIBCOSoftware/flogo-lib/core/activity"
"github.com/TIBCOSoftware/flogo-lib/core/data"
//"github.com/TIBCOSoftware/flogo-contrib/action/flow/model"
)
// Definition is the object that describes the definition of
// a flow. It contains its data (attributes) and
// structure (tasks & links).
type Definition struct {
name string
modelID string
explicitReply bool
//flowModel model.FlowModel
attrs map[string]*data.Attribute
links map[int]*Link
tasks map[string]*Task
metadata *data.IOMetadata
linkExprMgr LinkExprManager
errorHandler *ErrorHandler
}
// Name returns the name of the definition
func (d *Definition) Name() string {
return d.name
}
// ModelID returns the ID of the model the definition uses
func (d *Definition) ModelID() string {
return d.modelID
}
// Metadata returns IO metadata for the flow
func (d *Definition) Metadata() *data.IOMetadata {
return d.metadata
}
// GetTask returns the task with the specified ID
func (d *Definition) GetTask(taskID string) *Task {
task := d.tasks[taskID]
return task
}
// GetLink returns the link with the specified ID
func (d *Definition) GetLink(linkID int) *Link {
task := d.links[linkID]
return task
}
func (d *Definition) ExplicitReply() bool {
return d.explicitReply
}
func (d *Definition) GetErrorHandler() *ErrorHandler {
return d.errorHandler
}
// GetAttr gets the specified attribute
func (d *Definition) GetAttr(attrName string) (attr *data.Attribute, exists bool) {
if d.attrs != nil {
attr, found := d.attrs[attrName]
if found {
return attr, true
}
}
return nil, false
}
// GetTask returns the task with the specified ID
func (d *Definition) Tasks() []*Task {
tasks := make([]*Task, 0, len(d.tasks))
for _, task := range d.tasks {
tasks = append(tasks, task)
}
return tasks
}
func (d *Definition) Links() []*Link {
links := make([]*Link, 0, len(d.links))
for _, link := range d.links {
links = append(links, link)
}
return links
}
// SetLinkExprManager sets the LinkOld Expression Manager for the definition
func (d *Definition) SetLinkExprManager(mgr LinkExprManager) {
// todo revisit
d.linkExprMgr = mgr
}
// GetLinkExprManager gets the LinkOld Expression Manager for the definition
func (d *Definition) GetLinkExprManager() LinkExprManager {
return d.linkExprMgr
}
type ActivityConfig struct {
Activity activity.Activity
settings map[string]*data.Attribute
inputAttrs map[string]*data.Attribute
outputAttrs map[string]*data.Attribute
inputMapper data.Mapper
outputMapper data.Mapper
}
// GetSetting gets the specified setting
func (ac *ActivityConfig) GetSetting(setting string) (attr *data.Attribute, exists bool) {
if ac.settings != nil {
attr, found := ac.settings[setting]
if found {
return attr, true
}
}
return nil, false
}
// GetAttr gets the specified input attribute
func (ac *ActivityConfig) GetInputAttr(attrName string) (attr *data.Attribute, exists bool) {
if ac.inputAttrs != nil {
attr, found := ac.inputAttrs[attrName]
if found {
return attr, true
}
}
return nil, false
}
// GetOutputAttr gets the specified output attribute
func (ac *ActivityConfig) GetOutputAttr(attrName string) (attr *data.Attribute, exists bool) {
if ac.outputAttrs != nil {
attr, found := ac.outputAttrs[attrName]
if found {
return attr, true
}
}
return nil, false
}
// InputMapper returns the InputMapper of the task
func (ac *ActivityConfig) InputMapper() data.Mapper {
return ac.inputMapper
}
// OutputMapper returns the OutputMapper of the task
func (ac *ActivityConfig) OutputMapper() data.Mapper {
return ac.outputMapper
}
func (ac *ActivityConfig) Ref() string {
return ac.Activity.Metadata().ID
}
// Task is the object that describes the definition of
// a task. It contains its data (attributes) and its
// nested structure (child tasks & child links).
type Task struct {
id string
typeID string
name string
activityCfg *ActivityConfig
isScope bool
definition *Definition
settings map[string]interface{}
inputAttrs map[string]*data.Attribute
outputAttrs map[string]*data.Attribute
inputMapper data.Mapper
outputMapper data.Mapper
toLinks []*Link
fromLinks []*Link
}
// ID gets the id of the task
func (task *Task) ID() string {
return task.id
}
// Name gets the name of the task
func (task *Task) Name() string {
return task.name
}
// TypeID gets the id of the task type
func (task *Task) TypeID() string {
return task.typeID
}
// GetAttr gets the specified attribute
// DEPRECATED
func (task *Task) GetAttr(attrName string) (attr *data.Attribute, exists bool) {
if task.inputAttrs != nil {
attr, found := task.inputAttrs[attrName]
if found {
return attr, true
}
}
return nil, false
}
// GetAttr gets the specified input attribute
func (task *Task) GetInputAttr(attrName string) (attr *data.Attribute, exists bool) {
if task.inputAttrs != nil {
attr, found := task.inputAttrs[attrName]
if found {
return attr, true
}
}
return nil, false
}
// GetOutputAttr gets the specified output attribute
func (task *Task) GetOutputAttr(attrName string) (attr *data.Attribute, exists bool) {
if task.outputAttrs != nil {
attr, found := task.outputAttrs[attrName]
if found {
return attr, true
}
}
return nil, false
}
func (task *Task) ActivityConfig() *ActivityConfig {
return task.activityCfg
}
func (task *Task) GetSetting(attrName string) (value interface{}, exists bool) {
value, exists = task.settings[attrName]
return value, exists
}
// ToLinks returns the predecessor links of the task
func (task *Task) ToLinks() []*Link {
return task.toLinks
}
// FromLinks returns the successor links of the task
func (task *Task) FromLinks() []*Link {
return task.fromLinks
}
func (task *Task) String() string {
return fmt.Sprintf("Task[%s] '%s'", task.id, task.name)
}
// IsScope returns flag indicating if the Task is a scope task (a container of attributes)
func (task *Task) IsScope() bool {
return task.isScope
}
////////////////////////////////////////////////////////////////////////////
// Link
// LinkType is an enum for possible Link Types
type LinkType int
const (
// LtDependency denotes an normal dependency link
LtDependency LinkType = 0
// LtExpression denotes a link with an expression
LtExpression LinkType = 1 //expr language on the model or def?
// LtLabel denotes 'label' link
LtLabel LinkType = 2
// LtError denotes an error link
LtError LinkType = 3
)
// LinkOld is the object that describes the definition of
// a link.
type Link struct {
id int
name string
fromTask *Task
toTask *Task
linkType LinkType
value string //expression or label
definition *Definition
}
// ID gets the id of the link
func (link *Link) ID() int {
return link.id
}
// Type gets the link type
func (link *Link) Type() LinkType {
return link.linkType
}
// Value gets the "value" of the link
func (link *Link) Value() string {
return link.value
}
// FromTask returns the task the link is coming from
func (link *Link) FromTask() *Task {
return link.fromTask
}
// ToTask returns the task the link is going to
func (link *Link) ToTask() *Task {
return link.toTask
}
func (link *Link) String() string {
return fmt.Sprintf("Link[%d]:'%s' - [from:%s, to:%s]", link.id, link.name, link.fromTask.id, link.toTask.id)
}
type ErrorHandler struct {
links map[int]*Link
tasks map[string]*Task
}
func (eh *ErrorHandler) Tasks() []*Task {
tasks := make([]*Task, 0, len(eh.tasks))
for _, task := range eh.tasks {
tasks = append(tasks, task)
}
return tasks
}