From e92024a2e8e35fb7094e4028dbf47c6772d34f6d Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Mon, 26 Mar 2018 08:54:26 -0600 Subject: [PATCH 01/13] Create pull_request_template.md --- .github/pull_request_template.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..7df7b5c --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,14 @@ +Fixes: # . + +**What kind of change does this PR introduce?** (check one with "x") +``` +[] Bugfix +[] Feature +[] Code style update (formatting, local variables) +[] Refactoring (no functional changes, no api changes) +[] Other... Please describe: +``` + +**What is the current behavior?** + +**What is the new behavior?** From 91299c201c9b461d126bd5605b51bc88e7acbdfe Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Mon, 26 Mar 2018 09:33:09 -0600 Subject: [PATCH 02/13] Create ISSUE_TEMPLATE.md --- .github/ISSUE_TEMPLATE.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE.md diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..2027ee4 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,21 @@ +**I'm submitting a ...** (check one with "x") +``` +[] bug report => search github for a similar issue or PR before submitting +[] feature request +[] support request +[] general question +``` + +**Current behavior (how does the issue manifest):** + +**Expected behavior:** + +**Minimal steps to reproduce the problem (not required if feature enhancement):** + +**What is the motivation / use case for changing the behavior?** + +**Please tell us about your environment (Operating system, docker version, browser & verison if webui, etc):** + +**Flogo version (CLI & contrib/lib. If unknown, leave empty or state unknown):** 0.X.X + +**Additional information you deem important (e.g. issue happens only occasionally):** From 5d2e317eb91bb19ecd0115d791755f9b81761e28 Mon Sep 17 00:00:00 2001 From: Tracy Li Date: Tue, 27 Mar 2018 13:51:30 -0500 Subject: [PATCH 03/13] Function support get from current data scope --- .../expression/function/function.go | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/core/mapper/exprmapper/expression/function/function.go b/core/mapper/exprmapper/expression/function/function.go index aaff45e..154d912 100644 --- a/core/mapper/exprmapper/expression/function/function.go +++ b/core/mapper/exprmapper/expression/function/function.go @@ -10,9 +10,9 @@ import ( "fmt" "github.com/TIBCOSoftware/flogo-lib/core/data" + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/funcexprtype" "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/ref" "github.com/TIBCOSoftware/flogo-lib/logger" - "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/funcexprtype" ) var logrus = logger.GetLogger("function") @@ -28,16 +28,16 @@ type FunctionExp struct { } type Parameter struct { - Function *FunctionExp `json:"function"` - Type funcexprtype.Type `json:"type"` - Value interface{} `json:"value"` + Function *FunctionExp `json:"function"` + Type funcexprtype.Type `json:"type"` + Value interface{} `json:"value"` } func (p *Parameter) UnmarshalJSON(paramData []byte) error { ser := &struct { - Function *FunctionExp `json:"function"` - Type funcexprtype.Type `json:"type"` - Value interface{} `json:"value"` + Function *FunctionExp `json:"function"` + Type funcexprtype.Type `json:"type"` + Value interface{} `json:"value"` }{} if err := json.Unmarshal(paramData, ser); err != nil { @@ -223,15 +223,25 @@ func (f *FunctionExp) callFunction(fdata interface{}, inputScope data.Scope, res case *ref.ArrayRef: field = p.Value.(*ref.ArrayRef) } - //TODO if inputScope == nil { p.Value = field.GetRef() } else { - v, err := field.EvalFromData(fdata) - if err != nil { - return nil, err + if fdata == nil { + //Array mapping should not go here for today, take is as get current scope. + //TODO how to know it is array mapping or get current scope + ref := ref.NewMappingRef(field.GetRef()) + v, _ := ref.Eval(inputScope, resolver) + p.Value = v + + } else { + v, err := field.EvalFromData(fdata) + if err != nil { + return nil, err + } + p.Value = v + } - p.Value = v + } } if p.Value != nil { @@ -282,4 +292,4 @@ func (f *FunctionExp) extractErrorFromValues(values []reflect.Value) ([]reflect. } return tempValues, err -} \ No newline at end of file +} From f3189baf1e08e70a2d0fbc31a90de776f579b333 Mon Sep 17 00:00:00 2001 From: Tracy Li Date: Tue, 27 Mar 2018 13:54:51 -0500 Subject: [PATCH 04/13] Pre-registry all functions --- core/mapper/exprmapper/exprmapper.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/mapper/exprmapper/exprmapper.go b/core/mapper/exprmapper/exprmapper.go index 89eb48b..b73defc 100644 --- a/core/mapper/exprmapper/exprmapper.go +++ b/core/mapper/exprmapper/exprmapper.go @@ -9,11 +9,17 @@ import ( "reflect" + "github.com/TIBCOSoftware/flogo-lib/core/data" "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression" - "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/ref" "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/json" - "github.com/TIBCOSoftware/flogo-lib/core/data" + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/ref" "github.com/TIBCOSoftware/flogo-lib/logger" + + //Pre registry all function for now + _ "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/function/number/random" + _ "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/function/string/concat" + _ "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/function/string/equals" + _ "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/function/string/length" ) var log = logger.GetLogger("mapper") @@ -178,7 +184,6 @@ func SetAttribute(fieldName string, value interface{}, outputScope data.Scope) e return nil } - func RemovePrefixInput(str string) string { if str != "" && strings.HasPrefix(str, MAP_TO_INPUT) { //Remove $INPUT for mapTo @@ -190,4 +195,3 @@ func RemovePrefixInput(str string) string { } return str } - From 8fba9ec7ce5aae2fad0fa934be3576a617785267 Mon Sep 17 00:00:00 2001 From: Tracy Li Date: Tue, 27 Mar 2018 14:43:17 -0500 Subject: [PATCH 05/13] Handler error --- core/mapper/exprmapper/expression/function/function.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/mapper/exprmapper/expression/function/function.go b/core/mapper/exprmapper/expression/function/function.go index 154d912..a40fbca 100644 --- a/core/mapper/exprmapper/expression/function/function.go +++ b/core/mapper/exprmapper/expression/function/function.go @@ -230,7 +230,10 @@ func (f *FunctionExp) callFunction(fdata interface{}, inputScope data.Scope, res //Array mapping should not go here for today, take is as get current scope. //TODO how to know it is array mapping or get current scope ref := ref.NewMappingRef(field.GetRef()) - v, _ := ref.Eval(inputScope, resolver) + v, err := ref.Eval(inputScope, resolver) + if err != nil { + return nil, err + } p.Value = v } else { From 73cb64c61bc9117b0f543b44aeb8671799164c82 Mon Sep 17 00:00:00 2001 From: Tracy Li Date: Tue, 27 Mar 2018 16:49:36 -0500 Subject: [PATCH 06/13] Add action metadata into inputs no matter has input mapper or not --- core/trigger/handler.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/core/trigger/handler.go b/core/trigger/handler.go index 14b757a..797559b 100644 --- a/core/trigger/handler.go +++ b/core/trigger/handler.go @@ -3,11 +3,12 @@ package trigger import ( "context" + "fmt" + "github.com/TIBCOSoftware/flogo-lib/core/action" "github.com/TIBCOSoftware/flogo-lib/core/data" "github.com/TIBCOSoftware/flogo-lib/core/mapper" "github.com/TIBCOSoftware/flogo-lib/logger" - "fmt" ) type Handler struct { @@ -183,6 +184,14 @@ func (h *Handler) generateInputs(triggerData map[string]interface{}) (map[string attrName := "_T." + attr.Name() inputs[attrName] = data.CloneAttribute(attrName, attr) } + + //Add action metadata into flow + if h.act.IOMetadata() != nil && h.act.IOMetadata().Input != nil { + //Adding action metadat into inputs + for _, attr := range h.act.IOMetadata().Input { + inputs[attr.Name()] = attr + } + } } return inputs, nil @@ -219,4 +228,4 @@ func (h *Handler) generateOutputs(actionResults map[string]*data.Attribute) (map func (h *Handler) String() string { return fmt.Sprintf("Handler[action:%s]", h.config.Action.Ref) -} \ No newline at end of file +} From 780ea5930a2e098e2153ec0756a454464ee96245 Mon Sep 17 00:00:00 2001 From: Vijay Nalawade Date: Wed, 28 Mar 2018 10:43:48 -0700 Subject: [PATCH 07/13] Added option for enhancement request --- .github/ISSUE_TEMPLATE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 2027ee4..eff65d5 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,6 +1,7 @@ **I'm submitting a ...** (check one with "x") ``` [] bug report => search github for a similar issue or PR before submitting +[] enhancement request [] feature request [] support request [] general question From 8a6d4559a521c15dcce1896da041156b841aa7a4 Mon Sep 17 00:00:00 2001 From: Vijay Nalawade Date: Wed, 28 Mar 2018 12:30:28 -0700 Subject: [PATCH 08/13] Panic when invalid log level is set --- logger/logfactory.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logger/logfactory.go b/logger/logfactory.go index d9bc735..19e71cf 100644 --- a/logger/logfactory.go +++ b/logger/logfactory.go @@ -145,7 +145,7 @@ func (logfactory *DefaultLoggerFactory) GetLogger(name string) Logger { // Get log level for name level, err := GetLevelForName(logLevelName) if err != nil { - return nil + panic(fmt.Sprintf("Unsupported Log Level - [%s]. Supported Value - [INFO DEBUG WARN ERROR]", logLevelName)) } l.SetLogLevel(level) mutex.Lock() From eceddd1cdf866b0fbe0d040335a301463e42cb70 Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Wed, 28 Mar 2018 15:15:03 -0600 Subject: [PATCH 09/13] Update pull_request_template.md moving the fixes field --- .github/pull_request_template.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 7df7b5c..cc5f931 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,5 +1,3 @@ -Fixes: # . - **What kind of change does this PR introduce?** (check one with "x") ``` [] Bugfix @@ -9,6 +7,8 @@ Fixes: # . [] Other... Please describe: ``` +**Fixes**: # + **What is the current behavior?** **What is the new behavior?** From 357ed9836b0a5ff60ed32cb3a18c5888a0ccf9cd Mon Sep 17 00:00:00 2001 From: Vijay Nalawade Date: Wed, 28 Mar 2018 15:08:45 -0700 Subject: [PATCH 10/13] Use default log level instead --- logger/exported.go | 1 + logger/logfactory.go | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/logger/exported.go b/logger/exported.go index a8550df..937782f 100644 --- a/logger/exported.go +++ b/logger/exported.go @@ -41,6 +41,7 @@ func SetLogLevel(level Level) { } var defaultLoggerName = "flogo" +var defaultLogLevel = "INFO" func SetDefaultLogger(name string) { defaultLoggerName = name diff --git a/logger/logfactory.go b/logger/logfactory.go index 19e71cf..3a017e7 100644 --- a/logger/logfactory.go +++ b/logger/logfactory.go @@ -10,12 +10,22 @@ import ( var loggerMap = make(map[string]Logger) var mutex = &sync.RWMutex{} - +var logLevel = InfoLevel type DefaultLoggerFactory struct { } func init() { + RegisterLoggerFactory(&DefaultLoggerFactory{}) + + logLevelName := config.GetLogLevel() + // Get log level for name + getLogLevel, err := GetLevelForName(logLevelName) + if err != nil { + println("Unsupported Log Level - ["+logLevelName+"]. Set to Log Level - ["+defaultLogLevel+"]") + } else { + logLevel = getLogLevel + } } type DefaultLogger struct { @@ -140,14 +150,9 @@ func (logfactory *DefaultLoggerFactory) GetLogger(name string) Logger { loggerName: name, loggerImpl: logImpl, } - // Get log level from config - logLevelName := config.GetLogLevel() - // Get log level for name - level, err := GetLevelForName(logLevelName) - if err != nil { - panic(fmt.Sprintf("Unsupported Log Level - [%s]. Supported Value - [INFO DEBUG WARN ERROR]", logLevelName)) - } - l.SetLogLevel(level) + + l.SetLogLevel(logLevel) + mutex.Lock() loggerMap[name] = l mutex.Unlock() From 3ef4a178cde9d84d33792ac921e22503d3031065 Mon Sep 17 00:00:00 2001 From: Tracy Li Date: Wed, 28 Mar 2018 18:28:07 -0500 Subject: [PATCH 11/13] Remove ignore case argument for string.equals --- .../function/string/equals/equals.go | 9 ++------- .../function/string/equals/equals_test.go | 18 ++++-------------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/core/mapper/exprmapper/function/string/equals/equals.go b/core/mapper/exprmapper/function/string/equals/equals.go index cfcf99f..85d4987 100644 --- a/core/mapper/exprmapper/function/string/equals/equals.go +++ b/core/mapper/exprmapper/function/string/equals/equals.go @@ -1,8 +1,6 @@ package equals import ( - "strings" - "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" "github.com/TIBCOSoftware/flogo-lib/logger" ) @@ -23,10 +21,7 @@ func (s *Equals) GetName() string { func (s *Equals) GetCategory() string { return "string" } -func (s *Equals) Eval(str, str2 string, ignoreCase bool) bool { - log.Debugf(`Reports whether "%s" equels "%s" with ignore case %s`, str, str2, ignoreCase) - if ignoreCase { - return strings.EqualFold(str, str2) - } +func (s *Equals) Eval(str, str2 string) bool { + log.Debugf(`Reports whether "%s" equals "%s" `, str, str2) return str == str2 } diff --git a/core/mapper/exprmapper/function/string/equals/equals_test.go b/core/mapper/exprmapper/function/string/equals/equals_test.go index bcee511..0813f29 100644 --- a/core/mapper/exprmapper/function/string/equals/equals_test.go +++ b/core/mapper/exprmapper/function/string/equals/equals_test.go @@ -11,28 +11,18 @@ import ( var s = &Equals{} func TestStaticFunc_Starts_with(t *testing.T) { - final1 := s.Eval("TIBCO FLOGO", "TIBCO", true) + final1 := s.Eval("TIBCO FLOGO", "TIBCO") fmt.Println(final1) assert.Equal(t, false, final1) - final2 := s.Eval("TIBCO", "tibco", true) + final2 := s.Eval("TIBCO", "tibco") fmt.Println(final2) - assert.Equal(t, true, final2) + assert.Equal(t, false, final2) } func TestExpression(t *testing.T) { - fun, err := expression.NewFunctionExpression(`string.equals("TIBCO FLOGO", "TIBCO FLOGO", false)`).GetFunction() - assert.Nil(t, err) - assert.NotNil(t, fun) - v, err := fun.Eval() - assert.Nil(t, err) - assert.NotNil(t, v) - assert.Equal(t, true, v[0]) -} - -func TestExpressionIgnoreCase(t *testing.T) { - fun, err := expression.NewFunctionExpression(`string.equals("TIBCO flogo", "TIBCO FLOGO", true)`).GetFunction() + fun, err := expression.NewFunctionExpression(`string.equals("TIBCO FLOGO", "TIBCO FLOGO")`).GetFunction() assert.Nil(t, err) assert.NotNil(t, fun) v, err := fun.Eval() From 76fc5d070e1a7c15d7bfc8836083524a4e981d10 Mon Sep 17 00:00:00 2001 From: Tracy Li Date: Wed, 28 Mar 2018 21:51:39 -0500 Subject: [PATCH 12/13] Add equals ignorecase function --- .../equalsignorecase/equalsignorecase.go | 29 +++++++++++++ .../equalsignorecase/equalsignorecase_test.go | 42 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase.go create mode 100644 core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase_test.go diff --git a/core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase.go b/core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase.go new file mode 100644 index 0000000..46daa60 --- /dev/null +++ b/core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase.go @@ -0,0 +1,29 @@ +package equals + +import ( + "strings" + + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" +) + +var log = logger.GetLogger("equalsIgnoreCase-function") + +type EqualsIgnoreCase struct { +} + +func init() { + function.Registry(&EqualsIgnoreCase{}) +} + +func (s *EqualsIgnoreCase) GetName() string { + return "equalsIgnoreCase" +} + +func (s *EqualsIgnoreCase) GetCategory() string { + return "string" +} +func (s *EqualsIgnoreCase) Eval(str, str2 string) bool { + log.Debugf(`Reports whether "%s" equels "%s" with ignore case`, str, str2) + return strings.EqualFold(str, str2) +} diff --git a/core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase_test.go b/core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase_test.go new file mode 100644 index 0000000..bcac62c --- /dev/null +++ b/core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase_test.go @@ -0,0 +1,42 @@ +package equals + +import ( + "fmt" + "testing" + + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression" + "github.com/stretchr/testify/assert" +) + +var s = &EqualsIgnoreCase{} + +func TestStaticFunc_Starts_with(t *testing.T) { + final1 := s.Eval("TIBCO FLOGO", "TIBCO") + fmt.Println(final1) + assert.Equal(t, false, final1) + + final2 := s.Eval("TIBCO", "tibco") + fmt.Println(final2) + assert.Equal(t, true, final2) + +} + +func TestExpression(t *testing.T) { + fun, err := expression.NewFunctionExpression(`string.equalsIgnoreCase("TIBCO FLOGO", "TIBCO FLOGO")`).GetFunction() + assert.Nil(t, err) + assert.NotNil(t, fun) + v, err := fun.Eval() + assert.Nil(t, err) + assert.NotNil(t, v) + assert.Equal(t, true, v[0]) +} + +func TestExpressionIgnoreCase(t *testing.T) { + fun, err := expression.NewFunctionExpression(`string.equalsIgnoreCase("TIBCO flogo", "TIBCO FLOGO")`).GetFunction() + assert.Nil(t, err) + assert.NotNil(t, fun) + v, err := fun.Eval() + assert.Nil(t, err) + assert.NotNil(t, v) + assert.Equal(t, true, v[0]) +} From 468073de5a9853355dddb44e08f02f80df2d372f Mon Sep 17 00:00:00 2001 From: Tracy Li Date: Wed, 28 Mar 2018 21:54:23 -0500 Subject: [PATCH 13/13] Import and correct package name --- core/mapper/exprmapper/exprmapper.go | 1 + .../function/string/equalsignorecase/equalsignorecase.go | 2 +- .../function/string/equalsignorecase/equalsignorecase_test.go | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/mapper/exprmapper/exprmapper.go b/core/mapper/exprmapper/exprmapper.go index b73defc..5b27a98 100644 --- a/core/mapper/exprmapper/exprmapper.go +++ b/core/mapper/exprmapper/exprmapper.go @@ -19,6 +19,7 @@ import ( _ "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/function/number/random" _ "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/function/string/concat" _ "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/function/string/equals" + _ "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/function/string/equalsignorecase" _ "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/function/string/length" ) diff --git a/core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase.go b/core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase.go index 46daa60..9f3ad36 100644 --- a/core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase.go +++ b/core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase.go @@ -1,4 +1,4 @@ -package equals +package equalsignorecase import ( "strings" diff --git a/core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase_test.go b/core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase_test.go index bcac62c..87a6756 100644 --- a/core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase_test.go +++ b/core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase_test.go @@ -1,4 +1,4 @@ -package equals +package equalsignorecase import ( "fmt"