-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbatch_item_model.go
322 lines (286 loc) · 7.59 KB
/
batch_item_model.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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
package msgraphgocore
import (
"errors"
abs "github.com/microsoft/kiota-abstractions-go"
"github.com/microsoft/kiota-abstractions-go/serialization"
jsonserialization "github.com/microsoft/kiota-serialization-json-go"
"reflect"
)
// BatchItem is an instance of the BatchRequest payload to be later serialized to a json payload
type BatchItem interface {
serialization.Parsable
GetId() *string
SetId(value *string)
GetMethod() *string
SetMethod(value *string)
GetUrl() *string
SetUrl(value *string)
GetHeaders() RequestHeader
SetHeaders(value RequestHeader)
GetBody() RequestBody
SetBody(value RequestBody)
GetDependsOn() []string
SetDependsOn(value []string)
GetStatus() *int32
SetStatus(value *int32)
DependsOnItem(item BatchItem)
}
type batchItem struct {
Id *string
method *string
Url *string
Headers RequestHeader
Body RequestBody
DependsOn []string
Status *int32
}
// DependsOnItem creates a dependency chain between BatchItems.If A depends on B, then B will be sent before B
// A batchItem can only depend on one other batchItem
// see: https://docs.microsoft.com/en-us/graph/known-issues#request-dependencies-are-limited
func (bi *batchItem) DependsOnItem(item BatchItem) {
dependsOn := append(item.GetDependsOn(), *item.GetId())
bi.SetDependsOn(dependsOn)
}
// NewBatchItem creates an instance of BatchItem
func NewBatchItem() BatchItem {
return &batchItem{
DependsOn: make([]string, 0),
}
}
// GetId returns batch item `id` property
func (bi *batchItem) GetId() *string {
return bi.Id
}
// SetId sets string value as batch item `id` property
func (bi *batchItem) SetId(value *string) {
bi.Id = value
}
// GetMethod returns batch item `Method` property
func (bi *batchItem) GetMethod() *string {
return bi.method
}
// SetMethod sets string value as batch item `Method` property
func (bi *batchItem) SetMethod(value *string) {
bi.method = value
}
// GetUrl returns batch item `Url` property
func (bi *batchItem) GetUrl() *string {
return bi.Url
}
// SetUrl sets string value as batch item `Url` property
func (bi *batchItem) SetUrl(value *string) {
bi.Url = value
}
// GetHeaders returns batch item `Header` as a map[string]string
func (bi *batchItem) GetHeaders() RequestHeader {
return bi.Headers
}
// SetHeaders sets map[string]string value as batch item `Header` property
func (bi *batchItem) SetHeaders(value RequestHeader) {
bi.Headers = value
}
// GetBody returns batch item `RequestBody` property
func (bi *batchItem) GetBody() RequestBody {
return bi.Body
}
// SetBody sets map[string]string value as batch item `RequestBody` property
func (bi *batchItem) SetBody(value RequestBody) {
bi.Body = value
}
// GetDependsOn returns batch item `dependsOn` property as a string array
func (bi *batchItem) GetDependsOn() []string {
return bi.DependsOn
}
// SetDependsOn sets []string value as batch item `dependsOn` property
func (bi *batchItem) SetDependsOn(value []string) {
bi.DependsOn = value
}
// GetStatus returns batch item `status` property
func (bi *batchItem) GetStatus() *int32 {
return bi.Status
}
// SetStatus sets int32 value as batch item `int` property
func (bi *batchItem) SetStatus(value *int32) {
bi.Status = value
}
// Serialize serializes information the current object
func (bi *batchItem) Serialize(writer serialization.SerializationWriter) error {
{
err := writer.WriteStringValue("id", bi.GetId())
if err != nil {
return err
}
}
{
err := writer.WriteStringValue("method", bi.GetMethod())
if err != nil {
return err
}
}
{
err := writer.WriteStringValue("url", bi.GetUrl())
if err != nil {
return err
}
}
{
err := writer.WriteAnyValue("headers", bi.GetHeaders())
if err != nil {
return err
}
}
{
err := writer.WriteAnyValue("body", bi.GetBody())
if err != nil {
return err
}
}
{
err := writer.WriteCollectionOfStringValues("dependsOn", bi.GetDependsOn())
if err != nil {
return err
}
}
{
err := writer.WriteInt32Value("status", bi.GetStatus())
if err != nil {
return err
}
}
return nil
}
// GetFieldDeserializers the deserialization information for the current model
func (bi *batchItem) GetFieldDeserializers() map[string]func(serialization.ParseNode) error {
res := make(map[string]func(serialization.ParseNode) error)
res["id"] = abs.SetStringValue(bi.SetId)
res["method"] = abs.SetStringValue(bi.SetMethod)
res["url"] = abs.SetStringValue(bi.SetUrl)
res["headers"] = func(n serialization.ParseNode) error {
rawVal, err := n.GetRawValue()
if err != nil {
return err
}
if rawVal == nil {
return nil
}
result, err := castMapOfStrings(rawVal)
if err != nil {
return err
}
bi.SetHeaders(result)
return nil
}
res["body"] = func(n serialization.ParseNode) error {
rawVal, err := n.GetRawValue()
if err != nil {
return err
}
if rawVal == nil {
return nil
}
result, err := convertToMap(rawVal)
if err != nil {
return err
}
bi.SetBody(result)
return nil
}
res["dependsOn"] = abs.SetCollectionOfPrimitiveValues("string", bi.SetDependsOn)
res["status"] = abs.SetInt32Value(bi.SetStatus)
return res
}
func convertToMap(rawVal interface{}) (map[string]interface{}, error) {
kind := reflect.ValueOf(rawVal)
if kind.Kind() == reflect.Map {
result := make(map[string]interface{})
err := deserializeMapped(kind, result)
if err != nil {
return nil, err
}
return result, nil
}
return nil, errors.New("interface was not a map")
}
func deserializeNode(value serialization.ParseNode) (interface{}, error) {
rawVal, err := value.GetRawValue()
if err != nil {
return nil, err
} else {
kind := reflect.ValueOf(rawVal)
if kind.Kind() == reflect.Map {
result := make(map[string]interface{})
err := deserializeMapped(kind, result)
if err != nil {
return nil, err
}
return result, nil
} else {
return deserializeValue(rawVal)
}
}
}
func deserializeMapped(v reflect.Value, result map[string]interface{}) error {
for _, key := range v.MapKeys() {
value, err := deserializeValue(v.MapIndex(key).Interface())
if err != nil {
return err
} else {
result[key.String()] = value
}
}
return nil
}
func deserializeNodes(value []*jsonserialization.JsonParseNode) (interface{}, error) {
slice := make([]interface{}, len(value))
for index, element := range value {
res, err := deserializeNode(element)
if err != nil {
return nil, err
}
slice[index] = res
}
return slice, nil
}
func deserializeValue(value interface{}) (interface{}, error) {
switch v := value.(type) {
case int:
case float64:
case string:
return value, nil
case *int:
case *float64:
case *string:
return value, nil
case jsonserialization.JsonParseNode:
case *jsonserialization.JsonParseNode:
return deserializeNode(v)
case []*jsonserialization.JsonParseNode:
return deserializeNodes(v)
case []jsonserialization.JsonParseNode:
return deserializeNodes(abs.CollectionApply(v, func(x jsonserialization.JsonParseNode) *jsonserialization.JsonParseNode {
return &x
}))
default:
return value, nil
}
return nil, nil
}
func castMapOfStrings(rawVal interface{}) (map[string]string, error) {
result := make(map[string]string)
v := reflect.ValueOf(rawVal)
if v.Kind() == reflect.Map {
for _, key := range v.MapKeys() {
val, err := deserializeValue(v.MapIndex(key).Interface())
if err != nil {
return nil, err
}
result[key.String()] = *(val.(*string))
}
}
return result, nil
}
// CreateBatchRequestItemDiscriminator creates a new instance of the appropriate class based on discriminator value
func CreateBatchRequestItemDiscriminator(serialization.ParseNode) (serialization.Parsable, error) {
var res batchItem
return &res, nil
}