forked from TIBCOSoftware/flogo-contrib
/
resolve.go
106 lines (91 loc) · 2.91 KB
/
resolve.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package definition
import (
"fmt"
"os"
"strings"
"github.com/TIBCOSoftware/flogo-lib/core/data"
"github.com/TIBCOSoftware/flogo-lib/logger"
)
var resolver = &FlowResolver{}
func GetDataResolver() data.Resolver {
return resolver
}
type FlowResolver struct {
}
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.Value()
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.Value()
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.Value()
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.Value()
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.Value()
default:
return nil, fmt.Errorf("unsupported resolver: %s", details.ResolverName)
}
value = data.GetComplexValue(value)
if details.Path != "" {
value, err = data.PathGetValue(value, details.Path)
if err != nil {
logger.Error(err.Error())
return nil, err
}
}
return value, nil
}