Skip to content

Commit

Permalink
Merge pull request #4 from project-flogo/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
skothari-tibco committed Mar 5, 2019
2 parents cc38f18 + 7988ae3 commit 1c33c16
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 283 deletions.
2 changes: 1 addition & 1 deletion definition/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package definition

import (
"fmt"
"github.com/project-flogo/core/support/log"

"github.com/project-flogo/core/activity"
"github.com/project-flogo/core/data"
"github.com/project-flogo/core/data/expression"
"github.com/project-flogo/core/data/mapper"
"github.com/project-flogo/core/data/metadata"
"github.com/project-flogo/core/support/log"
)

// Definition is the object that describes the definition of
Expand Down
120 changes: 26 additions & 94 deletions definition/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ package definition

import (
"fmt"
"github.com/project-flogo/core/data/path"

"github.com/project-flogo/core/data"
"github.com/project-flogo/core/data/resolve"
)

var defResolver = resolve.NewCompositeResolver(map[string]resolve.Resolver{
".": &resolve.ScopeResolver{},
"env": &resolve.EnvResolver{},
"property": &resolve.PropertyResolver{},
"loop": &resolve.LoopResolver{},
"activity": &ActivityResolver{},
"error": &ErrorResolver{},
"flow": &FlowResolver{}})
".": &resolve.ScopeResolver{},
"env": &resolve.EnvResolver{},
"property": &resolve.PropertyResolver{},
"loop": &resolve.LoopResolver{},
"iteration": &IteratorResolver{}, //todo should we create a separate resolver to use in iterations?
"activity": &ActivityResolver{},
"error": &ErrorResolver{},
"flow": &FlowResolver{}})

func GetDataResolver() resolve.CompositeResolver {
return defResolver
Expand All @@ -39,13 +41,13 @@ func (r *FlowResolver) Resolve(scope data.Scope, itemName, valueName string) (in
return value, nil
}

var actResolverInfo = resolve.NewResolverInfo(false, true)
var dynamicItemResolver = resolve.NewResolverInfo(false, true)

type ActivityResolver struct {
}

func (r *ActivityResolver) GetResolverInfo() *resolve.ResolverInfo {
return actResolverInfo
return dynamicItemResolver
}

func (r *ActivityResolver) Resolve(scope data.Scope, itemName, valueName string) (interface{}, error) {
Expand Down Expand Up @@ -75,88 +77,18 @@ func (r *ErrorResolver) Resolve(scope data.Scope, itemName, valueName string) (i
return value, nil
}

//
//func (r *FlowResolver) Resolve(toResolve string, scope data.Scope) (value interface{}, err error) {
//
// var details *data.ResolutionDetails
//
// if strings.HasPrefix(toResolve, "${") {
// details, err = data.GetResolutionDetailsOld(toResolve)
// } else if strings.HasPrefix(toResolve, "$") {
// details, err = data.GetResolutionDetails(toResolve[1:])
// } else {
// return data.SimpleScopeResolve(toResolve, scope)
// }
//
// if err != nil {
// return nil, err
// }
//
// if details == nil {
// return nil, fmt.Errorf("unable to determine resolver for %s", toResolve)
// }
//
// var exists bool
//
// switch details.ResolverName {
// case "property":
// // Property resolution
// provider := data.GetPropertyProvider()
// value, exists = provider.GetProperty(details.Property + details.Path) //should we add the path and reset it to ""
// if !exists {
// err := fmt.Errorf("failed to resolve Property: '%s', ensure that property is configured in the application", details.Property)
// logger.Error(err.Error())
// return nil, err
// }
// case "env":
// // Environment resolution
// value, exists = os.LookupEnv(details.Property + details.Path)
// if !exists {
// err := fmt.Errorf("failed to resolve Environment Variable: '%s', ensure that variable is configured", details.Property)
// logger.Error(err.Error())
// return "", err
// }
// case "activity":
// attr, exists := scope.GetAttr("_A." + details.Item + "." + details.Property)
// if !exists {
// return nil, fmt.Errorf("failed to resolve activity attr: '%s', not found in flow", details.Property)
// }
// value = attr.TypedValue()
// case "error":
// attr, exists := scope.GetAttr("_E." + details.Property)
// if !exists {
// return nil, fmt.Errorf("failed to resolve error attr: '%s', not found in flow", details.Property)
// }
// value = attr.TypedValue()
// case "trigger":
// attr, exists := scope.GetAttr("_T." + details.Property)
// if !exists {
// return nil, fmt.Errorf("failed to resolve trigger attr: '%s', not found in flow", details.Property)
// }
// value = attr.TypedValue()
// case "flow":
// attr, exists := scope.GetAttr(details.Property)
// if !exists {
// return nil, fmt.Errorf("failed to resolve flow attr: '%s', not found in flow", details.Property)
// }
// value = attr.TypedValue()
// case "current":
// attr, exists := scope.GetAttr("$current." + details.Property)
// if !exists {
// return nil, fmt.Errorf("failed to resolve current working data: '%s', not found in scope", details.Property)
// }
// value = attr.TypedValue()
// default:
// return nil, fmt.Errorf("unsupported resolver: %s", details.ResolverName)
// }
//
// if details.Path != "" {
// value, err = data.PathGetValue(value, details.Path)
// if err != nil {
// logger.Error(err.Error())
// return nil, err
// }
// }
//
// return value, nil
//}
type IteratorResolver struct {
}

func (*IteratorResolver) GetResolverInfo() *resolve.ResolverInfo {
return dynamicItemResolver
}

//Resolve resolved iterator value using the following syntax: $iteration[key], or $iteration[value]
func (*IteratorResolver) Resolve(scope data.Scope, item string, field string) (interface{}, error) {
value, exists := scope.GetValue("_W.iteration")
if !exists {
return nil, fmt.Errorf("failed to resolve iteration value, not in an iterator")
}
return path.GetValue(value, "."+item)
}
163 changes: 25 additions & 138 deletions instance/scopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,160 +6,47 @@ import (
"github.com/project-flogo/core/data"
)

type IteratorScope struct {
iteratorData map[string]interface{}
parent data.Scope
type WorkingDataScope struct {
workingData map[string]interface{}
parent data.Scope
}

func (s *IteratorScope) GetValue(name string) (value interface{}, exists bool) {
if strings.HasPrefix(name, "$current.") {
val, ok := s.iteratorData[name[9:]]
func (s *WorkingDataScope) GetValue(name string) (value interface{}, exists bool) {
if strings.HasPrefix(name, "_W.") {
val, ok := s.workingData[name[3:]]
if ok {
return val, true
//attr, _ = data.NewAttribute(attrName[6:], data.ANY, val)
//return attr, true
}
return nil, false
} else {
return s.parent.GetValue(name)
}
}

func (s *IteratorScope) SetValue(name string, value interface{}) error {
func (s *WorkingDataScope) SetValue(name string, value interface{}) error {
return s.parent.SetValue(name, value)
}

//
func NewIteratorScope(parentScope data.Scope, workingData map[string]interface{}) data.Scope {
func (s *WorkingDataScope) GetWorkingValue(name string) (value interface{}, exists bool) {
val, ok := s.workingData[name]
if ok {
return val, true
}
return nil, false
}

func (s *WorkingDataScope) SetWorkingValue(name string, value interface{}) error {
s.workingData[name] = value
return nil
}

// NewWorkingDataScope
func NewWorkingDataScope(parentScope data.Scope) *WorkingDataScope {

scope := &IteratorScope{
parent: parentScope,
iteratorData: workingData,
scope := &WorkingDataScope{
parent: parentScope,
workingData: make(map[string]interface{}),
}

return scope
}

//
//// WorkingDataScope is scope restricted by the set of reference attrs and backed by the specified Task
//type WorkingDataScope struct {
// parent data.Scope
// workingData map[string]*data.Attribute
//}
//
//// NewFixedTaskScope creates a FixedTaskScope
//func NewWorkingDataScope(parentScope data.Scope, workingData map[string]*data.Attribute) data.Scope {
//
// scope := &WorkingDataScope{
// parent: parentScope,
// workingData: workingData,
// }
//
// return scope
//}
//
//// GetAttr implements Scope.GetAttr
//func (s *WorkingDataScope) GetAttr(attrName string) (attr *data.Attribute, exists bool) {
//
// if strings.HasPrefix(attrName, "$current.") {
// val, ok := s.workingData[attrName[9:]]
// if ok {
// return val, true
// //attr, _ = data.NewAttribute(attrName[6:], data.ANY, val)
// //return attr, true
// }
// return nil, false
// } else {
// return s.parent.GetAttr(attrName)
// }
//}
//
//// SetAttrValue implements Scope.SetAttrValue
//func (s *WorkingDataScope) SetAttrValue(attrName string, value interface{}) error {
// return s.parent.SetAttrValue(attrName, value)
//}
//
//// FixedTaskScope is scope restricted by the set of reference attrs and backed by the specified Task
//type FixedTaskScope struct {
// attrs map[string]*data.Attribute
// refAttrs map[string]*data.Attribute
// activityCfg *definition.ActivityConfig
// isInput bool
//}
//
//// NewFixedTaskScope creates a FixedTaskScope
//func NewFixedTaskScope(refAttrs map[string]*data.Attribute, task *definition.Task, isInput bool) data.Scope {
//
// scope := &FixedTaskScope{
// refAttrs: refAttrs,
// isInput: isInput,
// }
//
// if task != nil {
// scope.activityCfg = task.ActivityConfig()
// }
//
// return scope
//}
//
//// GetAttr implements Scope.GetAttr
//func (s *FixedTaskScope) GetAttr(attrName string) (attr *data.Attribute, exists bool) {
//
// if len(s.attrs) > 0 {
//
// attr, found := s.attrs[attrName]
//
// if found {
// return attr, true
// }
// }
//
// if s.activityCfg != nil {
//
// var attr *data.Attribute
// var found bool
//
// if s.isInput {
// attr, found = s.activityCfg.GetInputAttr(attrName)
// } else {
// attr, found = s.activityCfg.GetOutputAttr(attrName)
// }
//
// if !found {
// attr, found = s.refAttrs[attrName]
// }
//
// return attr, found
// }
//
// return nil, false
//}
//
//// SetAttrValue implements Scope.SetAttrValue
//func (s *FixedTaskScope) SetAttrValue(attrName string, value interface{}) error {
//
// if len(s.attrs) == 0 {
// s.attrs = make(map[string]*data.Attribute)
// }
//
// logger.Debugf("SetAttr: %s = %v", attrName, value)
//
// attr, found := s.attrs[attrName]
//
// var err error
// if found {
// err = attr.SetValue(value)
// } else {
// // look up reference for type
// attr, found = s.refAttrs[attrName]
// if found {
// s.attrs[attrName], err = data.NewAttribute(attrName, attr.Type(), value)
// } else {
// logger.Debugf("SetAttr: Attr '%s' not found in metadata\n", attrName)
// logger.Debugf("SetAttr: metadata %v\n", s.refAttrs)
// }
// //todo: else error
// }
//
// return err
//}

0 comments on commit 1c33c16

Please sign in to comment.