-
Notifications
You must be signed in to change notification settings - Fork 21
/
workflowOutputParameter.go
163 lines (131 loc) · 4.65 KB
/
workflowOutputParameter.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
package cwl
import (
"fmt"
"reflect"
"github.com/davecgh/go-spew/spew"
"github.com/mitchellh/mapstructure"
)
type WorkflowOutputParameter struct {
OutputParameter `yaml:",inline" json:",inline" bson:",inline" mapstructure:",squash"`
Doc string `yaml:"doc,omitempty" bson:"doc,omitempty" json:"doc,omitempty"`
//OutputBinding *CommandOutputBinding `yaml:"outputBinding,omitempty" bson:"outputBinding,omitempty" json:"outputBinding,omitempty"` //TODO
OutputSource interface{} `yaml:"outputSource,omitempty" bson:"outputSource,omitempty" json:"outputSource,omitempty"` //string or []string
LinkMerge LinkMergeMethod `yaml:"linkMerge,omitempty" bson:"linkMerge,omitempty" json:"linkMerge,omitempty"`
//Type []interface{} `yaml:"type,omitempty" bson:"type,omitempty" json:"type,omitempty"` //WorkflowOutputParameterType TODO CWLType | OutputRecordSchema | OutputEnumSchema | OutputArraySchema | string | array<CWLType | OutputRecordSchema | OutputEnumSchema | OutputArraySchema | string>
}
func NewWorkflowOutputParameter(original interface{}, schemata []CWLType_Type) (wop *WorkflowOutputParameter, err error) {
var output_parameter WorkflowOutputParameter
original, err = MakeStringMap(original)
if err != nil {
return
}
switch original.(type) {
case map[string]interface{}:
original_map, ok := original.(map[string]interface{})
if !ok {
err = fmt.Errorf("(NewWorkflowOutputParameter) type switch error")
return
}
err = NormalizeOutputParameter(original_map)
if err != nil {
err = fmt.Errorf("(NewWorkflowOutputParameter) NormalizeOutputParameter returns %s", err.Error())
return
}
outputSource_if, ok := original_map["outputSource"]
if ok {
switch outputSource_if.(type) {
case string:
original_map["outputSource"] = outputSource_if.(string)
case []string:
original_map["outputSource"] = outputSource_if.([]string)
case []interface{}:
outputSource_if_array := outputSource_if.([]interface{})
outputSource_string_array := []string{}
for _, elem := range outputSource_if_array {
elem_str, ok := elem.(string)
if !ok {
err = fmt.Errorf("(NewWorkflowOutputParameter) not a string ?!")
return
}
outputSource_string_array = append(outputSource_string_array, elem_str)
}
original_map["outputSource"] = outputSource_string_array
default:
outputSource_str, ok := outputSource_if.(string)
if ok {
original_map["outputSource"] = []string{outputSource_str}
} else {
spew.Dump(outputSource_if)
err = fmt.Errorf("(NewWorkflowOutputParameter) type of outputSource_if unknown: %s", reflect.TypeOf(outputSource_if))
return
}
}
}
wop_type, has_type := original_map["type"]
if has_type {
wop_type_array, xerr := NewWorkflowOutputParameterTypeArray(wop_type, schemata)
if xerr != nil {
err = fmt.Errorf("from NewWorkflowOutputParameterTypeArray: %s", xerr.Error())
return
}
//fmt.Println("type of wop_type_array")
//fmt.Println(reflect.TypeOf(wop_type_array))
//fmt.Println("original:")
//spew.Dump(original)
//fmt.Println("wop_type_array:")
//spew.Dump(wop_type_array)
original_map["type"] = wop_type_array
}
err = mapstructure.Decode(original, &output_parameter)
if err != nil {
err = fmt.Errorf("(NewWorkflowOutputParameter) decode error: %s", err.Error())
return
}
wop = &output_parameter
default:
err = fmt.Errorf("(NewWorkflowOutputParameter) type unknown, %s", reflect.TypeOf(original))
return
}
return
}
// WorkflowOutputParameter
func NewWorkflowOutputParameterArray(original interface{}, schemata []CWLType_Type) (new_array_ptr *[]WorkflowOutputParameter, err error) {
new_array := []WorkflowOutputParameter{}
switch original.(type) {
case map[interface{}]interface{}:
for k, v := range original.(map[interface{}]interface{}) {
//fmt.Printf("A")
output_parameter, xerr := NewWorkflowOutputParameter(v, schemata)
if xerr != nil {
err = xerr
return
}
output_parameter.Id = k.(string)
//fmt.Printf("C")
new_array = append(new_array, *output_parameter)
//fmt.Printf("D")
}
new_array_ptr = &new_array
return
case []interface{}:
for _, v := range original.([]interface{}) {
//fmt.Printf("A")
output_parameter, xerr := NewWorkflowOutputParameter(v, schemata)
if xerr != nil {
err = xerr
return
}
//output_parameter.Id = k.(string)
//fmt.Printf("C")
new_array = append(new_array, *output_parameter)
//fmt.Printf("D")
}
new_array_ptr = &new_array
return
default:
spew.Dump(new_array)
err = fmt.Errorf("(NewWorkflowOutputParameterArray) type %s unknown", reflect.TypeOf(original))
}
//spew.Dump(new_array)
return
}