Skip to content

Commit 009adc2

Browse files
Activity name in context (#274)
* Added activity name in the initial context * Fixed implementations of InitContext
1 parent 655445a commit 009adc2

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

Diff for: activity/activity.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77

88
// Activity is an interface for defining a custom Activity Execution
99
type Activity interface {
10-
10+
1111
// Metadata returns the metadata of the activity
1212
Metadata() *Metadata
13-
13+
1414
// Eval is called when an Activity is being evaluated. Returning true indicates
1515
// that the task is done.
1616
Eval(ctx Context) (done bool, err error)
@@ -19,16 +19,19 @@ type Activity interface {
1919
type Factory func(ctx InitContext) (Activity, error)
2020

2121
type InitContext interface {
22-
22+
2323
// Settings
2424
Settings() map[string]interface{}
25-
25+
2626
// MapperFactory gets the mapper factory associated with the activity host
2727
MapperFactory() mapper.Factory
28-
28+
2929
// Logger logger to using during initialization, activity implementations should not
3030
// keep a reference to this
3131
Logger() log.Logger
32+
33+
// Name returns name of the activity
34+
Name() string
3235
}
3336

3437
type Details struct {

Diff for: api/support.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package api
22

33
import (
44
"context"
5-
"github.com/project-flogo/core/support/log"
6-
"github.com/project-flogo/core/support/trace"
75
"reflect"
86
"strconv"
97
"strings"
108

9+
"github.com/project-flogo/core/support/log"
10+
"github.com/project-flogo/core/support/trace"
11+
1112
"github.com/project-flogo/core/action"
1213
"github.com/project-flogo/core/activity"
1314
"github.com/project-flogo/core/app"
@@ -190,6 +191,10 @@ func (ctx *initCtx) Logger() log.Logger {
190191
return log.RootLogger()
191192
}
192193

194+
func (ctx *initCtx) Name() string {
195+
return ""
196+
}
197+
193198
var activityLogger = log.ChildLogger(log.RootLogger(), "activity")
194199

195200
// EvalActivity evaluates the specified activity using the provided inputs

Diff for: support/test/context.go

+21
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,27 @@ func NewActivityInitContext(settings interface{}, f mapper.Factory) activity.Ini
6767
return &TestActivityInitContext{settings: settingVals, factory: f}
6868
}
6969

70+
func NewActivityInitContextWithName(settings interface{}, f mapper.Factory, name string) activity.InitContext {
71+
72+
var settingVals map[string]interface{}
73+
74+
if sm, ok := settings.(map[string]interface{}); ok {
75+
settingVals = sm
76+
} else {
77+
settingVals = metadata.StructToMap(settings)
78+
}
79+
80+
if f == nil {
81+
f = mapper.NewFactory(resolve.GetBasicResolver())
82+
}
83+
84+
return &TestActivityInitContext{settings: settingVals, factory: f, name: name}
85+
}
86+
7087
type TestActivityInitContext struct {
7188
settings map[string]interface{}
7289
factory mapper.Factory
90+
name string
7391
}
7492

7593
func (ic *TestActivityInitContext) Settings() map[string]interface{} {
@@ -83,6 +101,9 @@ func (ic *TestActivityInitContext) MapperFactory() mapper.Factory {
83101
func (ic *TestActivityInitContext) Logger() log.Logger {
84102
return logger
85103
}
104+
func (ic *TestActivityInitContext) Name() string {
105+
return ic.name
106+
}
86107

87108
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
88109
// TestActivityHost

0 commit comments

Comments
 (0)