-
Notifications
You must be signed in to change notification settings - Fork 21
/
cwl_type_type.go
288 lines (227 loc) · 7 KB
/
cwl_type_type.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
package cwl
import (
"fmt"
"reflect"
"strings"
"github.com/davecgh/go-spew/spew"
)
type CWLType_Type interface {
Is_Type()
Type2String() string
GetId() string
}
type CWLType_Type_Basic string
func (s CWLType_Type_Basic) Is_Type() {}
func (s CWLType_Type_Basic) Type2String() string { return string(s) }
func (s CWLType_Type_Basic) GetId() string { return "" }
func NewCWLType_TypeFromString(schemata []CWLType_Type, native string, context string) (result CWLType_Type, err error) {
if native == "" {
err = fmt.Errorf("(NewCWLType_TypeFromString) string is empty")
return
}
if strings.HasPrefix(native, "#") {
result = NewPointerFromstring(native)
return
}
if strings.HasSuffix(native, "[]") {
// is array
//an_array_schema := make(map[string]interface{})
//an_array_schema["type"] = "array"
base_type_str := strings.TrimSuffix(native, "[]")
var ok bool
_, ok = IsValidType(base_type_str)
if !ok {
err = fmt.Errorf("(NewCWLType_TypeFromString) base_type %s unkown", base_type_str)
return
}
// recurse:
var base_type CWLType_Type
base_type, err = NewCWLType_TypeFromString(schemata, base_type_str, context)
if err != nil {
err = fmt.Errorf("(NewCWLType_TypeFromString) recurisve call of NewCWLType_TypeFromString returned: %s", err.Error())
return
}
switch context {
case "WorkflowOutput":
oas := NewOutputArraySchema()
oas.Items = []CWLType_Type{base_type}
result = oas
return
default:
err = fmt.Errorf("(NewCWLType_TypeFromString) context %s not supported yet", context)
}
}
result, ok := IsValidType(native)
if !ok {
//for _, schema := range schemata {
// id := schema.GetId()
// fmt.Printf("found id: \"%s\"\n", id)
// if id == native {
// result = schema
// return
// }
//}
err = fmt.Errorf("(NewCWLType_TypeFromString) type %s unkown", native)
return
}
return
}
func NewCWLType_Type(schemata []CWLType_Type, native interface{}, context string) (result CWLType_Type, err error) {
native, err = MakeStringMap(native)
if err != nil {
return
}
switch native.(type) {
case string:
native_str := native.(string)
return NewCWLType_TypeFromString(schemata, native_str, context)
case CWLType_Type_Basic:
native_tt := native.(CWLType_Type_Basic)
native_str := string(native_tt)
return NewCWLType_TypeFromString(schemata, native_str, context)
case map[string]interface{}:
native_map := native.(map[string]interface{})
object_type, has_type := native_map["type"]
if !has_type {
err = fmt.Errorf("(NewCWLType_Type) map object has not field \"type\"")
return
}
if object_type == "array" {
switch context {
case "Input":
result, err = NewInputArraySchemaFromInterface(native, schemata)
if err != nil {
err = fmt.Errorf("(NewCWLType_Type) NewInputArraySchemaFromInterface returned: %s", err.Error())
}
return
case "CommandOutput": // CommandOutputRecordSchema | CommandOutputEnumSchema | CommandOutputArraySchema
result, err = NewCommandOutputArraySchemaFromInterface(native, schemata)
if err != nil {
err = fmt.Errorf("(NewCWLType_Type) NewCommandOutputArraySchemaFromInterface returned: %s", err.Error())
}
return
case "CommandInput":
result, err = NewCommandInputArraySchemaFromInterface(native, schemata)
if err != nil {
//spew.Dump(native)
//panic("done")
err = fmt.Errorf("(NewCWLType_Type) NewCommandInputArraySchemaFromInterface returned: %s", err.Error())
}
return
case "WorkflowOutput":
result, err = NewOutputArraySchemaFromInterface(native, schemata)
if err != nil {
err = fmt.Errorf("(NewCWLType_Type) NewWorkflowOutputOutputArraySchemaFromInterface returned: %s", err.Error())
}
return
default:
err = fmt.Errorf("(NewCWLType_Type) context %s unknown", context)
return
}
} else if object_type == "record" {
switch context {
case "Input": // InputRecordSchema
result, err = NewInputRecordSchemaFromInterface(native, schemata)
if err != nil {
err = fmt.Errorf("(NewCWLType_Type) NewInputRecordSchemaFromInterface returned: %s", err.Error())
}
return
case "CommandInput":
result, err = NewCommandInputRecordSchemaFromInterface(native, schemata)
if err != nil {
err = fmt.Errorf("(NewCWLType_Type) NewCommandInputRecordSchemaFromInterface returned: %s", err.Error())
}
case "CommandOutput":
panic("CommandOutput not implemented yet")
default:
err = fmt.Errorf("(NewCWLType_Type) context %s unknown", context)
return
}
} else if object_type == "enum" {
switch context {
case "Input":
result, err = NewInputEnumSchemaFromInterface(native)
if err != nil {
err = fmt.Errorf("(NewCWLType_Type) NewInputEnumSchemaFromInterface returned: %s", err.Error())
}
return
default:
err = fmt.Errorf("(NewCWLType_Type) context %s unknown", context)
return
}
} else {
fmt.Println("(NewCWLType_Type) native_map:")
spew.Dump(native_map)
err = fmt.Errorf("(NewCWLType_Type) object_type %s not supported yet", object_type)
return
}
case OutputArraySchema:
result = native.(OutputArraySchema)
return
case *OutputArraySchema:
oas_p := native.(*OutputArraySchema)
result = *oas_p
default:
spew.Dump(native)
err = fmt.Errorf("(NewCWLType_Type) type %s unkown", reflect.TypeOf(native))
return
}
return
}
func NewCWLType_TypeArray(native interface{}, schemata []CWLType_Type, context string, pass_schemata_along bool) (result []CWLType_Type, err error) {
native, err = MakeStringMap(native)
if err != nil {
return
}
switch native.(type) {
case map[string]interface{}:
original_map := native.(map[string]interface{})
var new_type CWLType_Type
new_type, err = NewCWLType_Type(schemata, original_map, context)
if err != nil {
err = fmt.Errorf("(NewCWLType_TypeArray) NewCWLType_Type returns: %s", err.Error())
return
}
result = []CWLType_Type{new_type}
return
case string:
native_str := native.(string)
var a_type CWLType_Type
a_type, err = NewCWLType_TypeFromString(schemata, native_str, context)
if err != nil {
return
}
result = []CWLType_Type{a_type}
case []string:
native_array := native.([]string)
type_array := []CWLType_Type{}
for _, element_str := range native_array {
var element_type CWLType_Type
element_type, err = NewCWLType_TypeFromString(schemata, element_str, context)
if err != nil {
return
}
type_array = append(type_array, element_type)
}
result = type_array
case []interface{}:
native_array := native.([]interface{})
type_array := []CWLType_Type{}
for _, element_str := range native_array {
var element_type CWLType_Type
element_type, err = NewCWLType_Type(schemata, element_str, context)
if err != nil {
return
}
type_array = append(type_array, element_type)
if pass_schemata_along {
schemata = append(schemata, element_type)
}
}
result = type_array
default:
spew.Dump(native)
err = fmt.Errorf("(NewCWLType_TypeArray) type unknown: %s", reflect.TypeOf(native))
}
return
}