-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathactivity.go
executable file
·88 lines (64 loc) · 1.76 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
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
package log
import (
"fmt"
"strconv"
"github.com/TIBCOSoftware/flogo-lib/core/activity"
"github.com/TIBCOSoftware/flogo-lib/logger"
)
// activityLog is the default logger for the Log Activity
var activityLog = logger.GetLogger("activity-flogo-log")
const (
ivMessage = "message"
ivFlowInfo = "flowInfo"
ivAddToFlow = "addToFlow"
ovMessage = "message"
)
func init() {
activityLog.SetLogLevel(logger.InfoLevel)
}
// LogActivity is an Activity that is used to log a message to the console
// inputs : {message, flowInfo}
// outputs: none
type LogActivity struct {
metadata *activity.Metadata
}
// NewActivity creates a new AppActivity
func NewActivity(metadata *activity.Metadata) activity.Activity {
return &LogActivity{metadata: metadata}
}
// Metadata returns the activity's metadata
func (a *LogActivity) Metadata() *activity.Metadata {
return a.metadata
}
// Eval implements api.Activity.Eval - Logs the Message
func (a *LogActivity) Eval(context activity.Context) (done bool, err error) {
//mv := context.GetInput(ivMessage)
message, _ := context.GetInput(ivMessage).(string)
flowInfo, _ := toBool(context.GetInput(ivFlowInfo))
addToFlow, _ := toBool(context.GetInput(ivAddToFlow))
msg := message
if flowInfo {
msg = fmt.Sprintf("'%s' - FlowInstanceID [%s], Flow [%s], Task [%s]", msg,
context.ActivityHost().ID(), context.ActivityHost().Name(), context.Name())
}
activityLog.Info(msg)
if addToFlow {
context.SetOutput(ovMessage, msg)
}
return true, nil
}
func toBool(val interface{}) (bool, error) {
b, ok := val.(bool)
if !ok {
s, ok := val.(string)
if !ok {
return false, fmt.Errorf("unable to convert to boolean")
}
var err error
b, err = strconv.ParseBool(s)
if err != nil {
return false, err
}
}
return b, nil
}