-
Notifications
You must be signed in to change notification settings - Fork 9
/
types.go
108 lines (97 loc) · 2.51 KB
/
types.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
107
108
package legacybridge
import (
"encoding/json"
"errors"
legacyData "github.com/TIBCOSoftware/flogo-lib/core/data"
"github.com/project-flogo/core/data"
)
// ToTypeEnum get the data type that corresponds to the specified name
func ToNewTypeFromLegacy(legacyType legacyData.Type) (data.Type, error) {
switch legacyType {
case legacyData.TypeAny:
return data.TypeAny, nil
case legacyData.TypeString:
return data.TypeString, nil
case legacyData.TypeInteger:
return data.TypeInt, nil
case legacyData.TypeLong:
return data.TypeInt64, nil
case legacyData.TypeDouble:
return data.TypeFloat64, nil
case legacyData.TypeBoolean:
return data.TypeBool, nil
case legacyData.TypeObject:
return data.TypeObject, nil
case legacyData.TypeParams:
return data.TypeParams, nil
case legacyData.TypeArray:
return data.TypeArray, nil
case legacyData.TypeComplexObject:
return data.TypeObject, nil
default:
return 0, errors.New("unknown type: " + legacyType.String())
}
}
// ToTypeEnum get the data type that corresponds to the specified name
func ToLegacyFromNewType(dataType data.Type) (legacyData.Type, error) {
switch dataType {
case data.TypeAny:
return legacyData.TypeAny, nil
case data.TypeString:
return legacyData.TypeString, nil
case data.TypeInt:
return legacyData.TypeInteger, nil
case data.TypeInt64:
return legacyData.TypeLong, nil
case data.TypeFloat64:
return legacyData.TypeDouble, nil
case data.TypeBool:
return legacyData.TypeBoolean, nil
case data.TypeObject:
return legacyData.TypeObject, nil
case data.TypeParams:
return legacyData.TypeParams, nil
case data.TypeArray:
return legacyData.TypeArray, nil
default:
return 0, errors.New("unknown type: " + dataType.String())
}
}
func GetComplexObjectInfo(val interface{}) (interface{}, string, bool) {
switch t := val.(type) {
case string:
if val == "" {
return nil, "", false
} else {
var complexMap map[string]interface{}
err := json.Unmarshal([]byte(t), &complexMap)
if err != nil {
return nil, "", false
}
v, hasVal := complexMap["value"]
mdI, hasMd := complexMap["metadata"]
md := ""
if hasMd {
md, hasMd = mdI.(string)
}
if hasVal && hasMd {
return v, md, true
}
}
case map[string]interface{}:
v, hasVal := t["value"]
mdI, hasMd := t["metadata"]
md := ""
if hasMd {
md, hasMd = mdI.(string)
}
if hasVal || hasMd {
return v, md, true
}
case *legacyData.ComplexObject:
return t.Value, t.Metadata, true
default:
return nil, "", false
}
return nil, "", false
}