forked from TIBCOSoftware/flogo-contrib
/
activity.go
executable file
·59 lines (43 loc) · 1.5 KB
/
activity.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
package mapper
import (
"github.com/TIBCOSoftware/flogo-lib/core/activity"
"github.com/TIBCOSoftware/flogo-lib/core/mapper"
"github.com/TIBCOSoftware/flogo-lib/logger"
)
// log is the default package logger
var log = logger.GetLogger("activity-flogo-mapper")
const (
ivMappings = "mappings"
)
// MapperActivity is an Activity that is used to reply/return via the trigger
// inputs : {method,uri,params}
// outputs: {result}
type MapperActivity struct {
metadata *activity.Metadata
}
// NewActivity creates a new MapperActivity
func NewActivity(metadata *activity.Metadata) activity.Activity {
return &MapperActivity{metadata: metadata}
}
// Metadata returns the activity's metadata
func (a *MapperActivity) Metadata() *activity.Metadata {
return a.metadata
}
// Eval implements api.Activity.Eval - Invokes a REST Operation
func (a *MapperActivity) Eval(context activity.Context) (done bool, err error) {
mappings := context.GetInput(ivMappings).([]interface{})
log.Debugf("Mappings: %+v", mappings)
mapperDef, err := mapper.NewMapperDefFromAnyArray(mappings)
//todo move this to a action instance level initialization, need the notion of static inputs or config
actionMapper := mapper.NewBasicMapper(mapperDef, context.ActivityHost().GetResolver())
if err != nil {
return false, err
}
activityHost := context.ActivityHost()
actionScope := activityHost.WorkingData() // action/flow data
err = actionMapper.Apply(actionScope, actionScope)
if err != nil {
return false, err
}
return true, nil
}