Skip to content

Commit

Permalink
Merge pull request #146 from TIBCOSoftware/resolve-value-complex-object
Browse files Browse the repository at this point in the history
Handle complex object value
  • Loading branch information
lixingwang authored Mar 17, 2018
2 parents 07decdc + efa9040 commit 6e7b3e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions core/data/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func PathGetValue(value interface{}, path string) (interface{}, error) {
newVal, newPath, err = pathGetSetObjValue(objVal, path, nil, false)
} else if paramsVal, ok := value.(map[string]string); ok {
newVal, newPath, err = pathGetSetParamsValue(paramsVal, path, nil, false)
} else if objVal, ok := value.(*ComplexObject); ok {
return PathGetValue(objVal.Value, path)
} else {
return nil, fmt.Errorf("unable to evaluate path: %s", path)
}
Expand All @@ -32,6 +34,8 @@ func PathGetValue(value interface{}, path string) (interface{}, error) {
newVal, newPath, err = pathGetSetMapValue(objVal, path, nil, false)
} else if paramsVal, ok := value.(map[string]string); ok {
newVal, newPath, err = pathGetSetMapParamsValue(paramsVal, path, nil, false)
} else if objVal, ok := value.(*ComplexObject); ok {
return PathGetValue(objVal.Value, path)
} else {
return nil, fmt.Errorf("unable to evaluate path: %s", path)
}
Expand Down Expand Up @@ -62,6 +66,8 @@ func PathSetValue(attrValue interface{}, path string, value interface{}) error {
newVal, newPath, err = pathGetSetObjValue(objVal, path, value, true)
} else if paramsVal, ok := attrValue.(map[string]string); ok {
newVal, newPath, err = pathGetSetParamsValue(paramsVal, path, value, true)
} else if objVal, ok := value.(*ComplexObject); ok {
return PathSetValue(objVal.Value, path, value)
} else {
return fmt.Errorf("Unable to evaluate path: %s", path)
}
Expand All @@ -70,6 +76,8 @@ func PathSetValue(attrValue interface{}, path string, value interface{}) error {
newVal, newPath, err = pathGetSetMapValue(objVal, path, value, true)
} else if paramsVal, ok := attrValue.(map[string]string); ok {
newVal, newPath, err = pathGetSetMapParamsValue(paramsVal, path, value, true)
} else if objVal, ok := value.(*ComplexObject); ok {
return PathSetValue(objVal.Value, path, value)
} else {
return fmt.Errorf("unable to evaluate path: %s", path)
}
Expand Down
13 changes: 12 additions & 1 deletion core/data/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,18 @@ func NewFixedScopeFromMap(metadata map[string]*Attribute) *FixedScope {
func (s *FixedScope) GetAttr(name string) (attr *Attribute, exists bool) {

attr, found := s.attrs[name]
return attr, found

if found {
return attr, true
} else {
metaAttr, found := s.metadata[name]
if found {
attr, _ := NewAttribute(name, metaAttr.Type(), metaAttr.value)
s.attrs[name] = attr
return attr, true
}
}
return nil, false
}

// GetAttrs gets the attributes set in the scope
Expand Down

0 comments on commit 6e7b3e9

Please sign in to comment.