diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..eff65d5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,22 @@ +**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 +``` + +**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):** diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..cc5f931 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,14 @@ +**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: +``` + +**Fixes**: # + +**What is the current behavior?** + +**What is the new behavior?** diff --git a/core/mapper/exprmapper/expression/function/function.go b/core/mapper/exprmapper/expression/function/function.go index aaff45e..a40fbca 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,28 @@ 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, err := ref.Eval(inputScope, resolver) + if err != nil { + return nil, err + } + 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 +295,4 @@ func (f *FunctionExp) extractErrorFromValues(values []reflect.Value) ([]reflect. } return tempValues, err -} \ No newline at end of file +} diff --git a/core/mapper/exprmapper/exprmapper.go b/core/mapper/exprmapper/exprmapper.go index 89eb48b..5b27a98 100644 --- a/core/mapper/exprmapper/exprmapper.go +++ b/core/mapper/exprmapper/exprmapper.go @@ -9,11 +9,18 @@ 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/equalsignorecase" + _ "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/function/string/length" ) var log = logger.GetLogger("mapper") @@ -178,7 +185,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 +196,3 @@ func RemovePrefixInput(str string) string { } return str } - 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() 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..9f3ad36 --- /dev/null +++ b/core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase.go @@ -0,0 +1,29 @@ +package equalsignorecase + +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..87a6756 --- /dev/null +++ b/core/mapper/exprmapper/function/string/equalsignorecase/equalsignorecase_test.go @@ -0,0 +1,42 @@ +package equalsignorecase + +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]) +} 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 +} 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 d9bc735..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 { - return nil - } - l.SetLogLevel(level) + + l.SetLogLevel(logLevel) + mutex.Lock() loggerMap[name] = l mutex.Unlock()