Skip to content

Commit

Permalink
Merge branch 'master' into expression_boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
lixingwang committed Mar 30, 2018
2 parents b4fc8c5 + 36e5809 commit c5e9bca
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 49 deletions.
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -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):**
14 changes: 14 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -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?**
39 changes: 26 additions & 13 deletions core/mapper/exprmapper/expression/function/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -282,4 +295,4 @@ func (f *FunctionExp) extractErrorFromValues(values []reflect.Value) ([]reflect.
}

return tempValues, err
}
}
13 changes: 9 additions & 4 deletions core/mapper/exprmapper/exprmapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -190,4 +196,3 @@ func RemovePrefixInput(str string) string {
}
return str
}

9 changes: 2 additions & 7 deletions core/mapper/exprmapper/function/string/equals/equals.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package equals

import (
"strings"

"github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function"
"github.com/TIBCOSoftware/flogo-lib/logger"
)
Expand All @@ -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
}
18 changes: 4 additions & 14 deletions core/mapper/exprmapper/function/string/equals/equals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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])
}
13 changes: 11 additions & 2 deletions core/trigger/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
1 change: 1 addition & 0 deletions logger/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func SetLogLevel(level Level) {
}

var defaultLoggerName = "flogo"
var defaultLogLevel = "INFO"

func SetDefaultLogger(name string) {
defaultLoggerName = name
Expand Down
23 changes: 14 additions & 9 deletions logger/logfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit c5e9bca

Please sign in to comment.