Skip to content

Commit

Permalink
Added or node (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgorostiaga authored Apr 16, 2018
1 parent cd6c4aa commit 23aa6d1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
9 changes: 9 additions & 0 deletions go_EMS/datatypes/taggermomimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ func (andNode AndNode) Eval(payload map[string]interface{}) bool {
return true
}

func (orNode OrNode) Eval(payload map[string]interface{}) bool {
for _,node := range orNode.Members {
if node.Eval(payload) {
return true
}
}
return false
}

func (pathfunNode PathFunNode) Eval(payload map[string]interface{}) bool {
theVal, err := extractFromMap(payload, pathfunNode.Path)
if err != nil {
Expand Down
19 changes: 18 additions & 1 deletion go_EMS/eventproc/tagnodebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func getNodeFromFilter(thejson map[string]interface{}) (dt.TagNode,error) {
case "AND":
return getAndNode(thejson)
case "OR":
//return getOrNode(thejson)
return getOrNode(thejson)
case "PATHFUN":
return getPathFunNode(thejson)
}
Expand All @@ -40,6 +40,23 @@ func getAndNode(thejson map[string]interface{}) (dt.TagNode,error) {
return dt.AndNode{memberNodes},nil
}

func getOrNode(thejson map[string]interface{}) (dt.TagNode,error) {
members, ok := thejson["members"].([]map[string]interface{})
if !ok {
err := errors.New("No valid field 'members' in OR node definition")
return nil,err
}
memberNodes := make([]dt.TagNode, len(members))
for i,member := range members {
memberNode, err := getNodeFromFilter(member)
if err!=nil {
return nil, err
}
memberNodes[i] = memberNode
}
return dt.OrNode{memberNodes},nil
}

func getPathFunNode(thejson map[string]interface{}) (dt.TagNode,error) {
funName, ok := thejson["function"].(string)
if !ok {
Expand Down

0 comments on commit 23aa6d1

Please sign in to comment.