/
activity.go
executable file
·83 lines (63 loc) · 2 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
/*
* Copyright © 2020. TIBCO Software Inc.
* This file is subject to the license terms contained
* in the license file that is distributed with this file.
*/
package simplefilter
import (
"fmt"
"sync"
"github.com/TIBCOSoftware/flogo-lib/core/activity"
"github.com/TIBCOSoftware/flogo-lib/core/data"
"github.com/TIBCOSoftware/flogo-lib/logger"
)
// activityLogger is the default logger for the Filter Activity
var activityLogger = logger.GetLogger("activity-simple-filter")
const (
passFilterFlag = "filterExpression"
sProceedOnlyOnEmit = "proceedOnlyOnEmit"
ivValue = "value"
ovFiltered = "filtered"
ovValue = "value"
)
// FilterActivity is an Activity that is used to Filter a message to the console
type FilterActivity struct {
metadata *activity.Metadata
mux sync.Mutex
}
// NewActivity creates a new AppActivity
func NewActivity(md *activity.Metadata) activity.Activity {
filterActivity := FilterActivity{metadata: md}
return &filterActivity
}
// Metadata returns the activity's metadata
func (a *FilterActivity) Metadata() *activity.Metadata {
return a.metadata
}
// Eval implements api.Activity.Eval - Filters the Message
func (a *FilterActivity) Eval(ctx activity.Context) (done bool, err error) {
proceedOnlyOnEmit, err := a.getProceedOnlyOnEmit(ctx)
if nil != err {
return true, err
}
in := ctx.GetInput(ivValue)
passFilter := ctx.GetInput(passFilterFlag).(bool)
done = !(proceedOnlyOnEmit && !passFilter)
activityLogger.Info("proceedOnlyOnEmit : ", proceedOnlyOnEmit, ", passFilter : ", passFilter, ", done : ", done)
if done {
ctx.SetOutput(ovFiltered, !passFilter)
ctx.SetOutput(ovValue, in)
}
return done, nil
}
func (a *FilterActivity) getProceedOnlyOnEmit(context activity.Context) (bool, error) {
setting, exists := context.GetSetting(sProceedOnlyOnEmit)
if !exists {
return true, fmt.Errorf("ProceedOnlyOnEmit flag not found!")
}
val, err := data.CoerceToBoolean(setting)
if err != nil {
return true, err
}
return val, nil
}