forked from TIBCOSoftware/flogo-contrib
/
patch.go
76 lines (58 loc) · 2.09 KB
/
patch.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
package support
import "github.com/TIBCOSoftware/flogo-lib/core/data"
// Patch contains a set of task patches for a Flow Patch, this
// can be used to override the default data and mappings of a Flow
type Patch struct {
TaskPatches []*TaskPatch `json:"tasks"` //put in mapper object
taskPatchMap map[string]*TaskPatch
}
// Init initializes the FlowPatch, usually called after deserialization
func (pp *Patch) Init() {
numAttrs := len(pp.TaskPatches)
if numAttrs > 0 {
pp.taskPatchMap = make(map[string]*TaskPatch, numAttrs)
for _, patch := range pp.TaskPatches {
pp.taskPatchMap[patch.ID] = patch
}
}
}
// GetPatch returns the Task Patch for the specified task (referred to by ID)
func (pp *Patch) GetPatch(taskID string) *TaskPatch {
return pp.taskPatchMap[taskID]
}
// GetInputMapper returns the InputMapper for the specified task (referred to by ID)
func (pp *Patch) GetInputMapper(taskID string) data.Mapper {
taskPatch, exists := pp.taskPatchMap[taskID]
if exists {
return taskPatch.InputMapper()
}
return nil
}
// GetOutputMapper returns the OutputMapper for the specified task (referred to by ID)
func (pp *Patch) GetOutputMapper(taskID string) data.Mapper {
taskPatch, exists := pp.taskPatchMap[taskID]
if exists {
return taskPatch.OutputMapper()
}
return nil
}
// TaskPatch contains patching information for a Task, such has attributes,
// input mappings, output mappings. This is used to override the corresponding
// settings for a Task in the Process
type TaskPatch struct {
ID string `json:"id"`
Attributes []*data.Attribute `json:"attributes"`
InputMappings []*data.MappingDef `json:"inputMappings"` //put in mapper object
OutputMappings []*data.MappingDef `json:"ouputMappings"` //put in mapper object
Attrs map[string]*data.Attribute
inputMapper data.Mapper
outputMapper data.Mapper
}
// InputMapper returns the overriding InputMapper
func (tp *TaskPatch) InputMapper() data.Mapper {
return tp.inputMapper
}
// OutputMapper returns the overriding OutputMapper
func (tp *TaskPatch) OutputMapper() data.Mapper {
return tp.outputMapper
}