-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDependencyDeSerializer.cs
More file actions
508 lines (455 loc) · 20.5 KB
/
DependencyDeSerializer.cs
File metadata and controls
508 lines (455 loc) · 20.5 KB
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
// -------------------------------------------------------------------------------------------------
// <copyright file="DependencyDeSerializer.cs" company="Starion Group S.A.">
//
// Copyright 2022-2025 Starion Group S.A.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!--------
// ------------------------------------------------------------------------------------------------
namespace SysML2.NET.Serializer.Json.Core.DTO
{
using System;
using System.Text.Json;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using SysML2.NET.Common;
using SysML2.NET.Core.DTO.Root.Dependencies;
using SysML2.NET.Serializer.Json;
/// <summary>
/// The purpose of the <see cref="DependencyDeSerializer"/> is to provide deserialization capabilities
/// for the <see cref="IDependency"/> interface
/// </summary>
internal static class DependencyDeSerializer
{
/// <summary>
/// Deserializes an instance of <see cref="IDependency"/> from the provided <see cref="JsonElement"/>
/// </summary>
/// <param name="jsonElement">
/// The <see cref="JsonElement"/> that contains the <see cref="IDependency"/> json object
/// </param>
/// <param name="serializationModeKind">
/// enumeration specifying what kind of serialization shall be used
/// </param>
/// <param name="loggerFactory">
/// The <see cref="ILoggerFactory"/> used to setup logging
/// </param>
/// <returns>
/// an instance of <see cref="IDependency"/>
/// </returns>
internal static IDependency DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null)
{
var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("DependencyDeSerializer");
if (!jsonElement.TryGetProperty("@type"u8, out var @type))
{
throw new InvalidOperationException("The @type property is not available, the DependencyDeSerializer cannot be used to deserialize this JsonElement");
}
if (@type.GetString() != "Dependency")
{
throw new InvalidOperationException($"The DependencyDeSerializer can only be used to deserialize objects of type IDependency, a {@type.GetString()} was provided");
}
var dtoInstance = new SysML2.NET.Core.DTO.Root.Dependencies.Dependency();
if (jsonElement.TryGetProperty("@id"u8, out var idProperty))
{
var propertyValue = idProperty.GetString();
if (propertyValue == null)
{
throw new JsonException("The @id property is not present, the Dependency cannot be deserialized");
}
else
{
dtoInstance.Id = Guid.Parse(propertyValue);
}
}
if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty))
{
foreach (var arrayItem in aliasIdsProperty.EnumerateArray())
{
var propertyValue = arrayItem.GetString();
if (propertyValue != null)
{
dtoInstance.AliasIds.Add(propertyValue);
}
}
}
else
{
logger.LogDebug("the aliasIds Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("client"u8, out var clientProperty))
{
foreach (var arrayItem in clientProperty.EnumerateArray())
{
if (arrayItem.TryGetProperty("@id"u8, out var clientExternalIdProperty))
{
var propertyValue = clientExternalIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.Client.Add(Guid.Parse(propertyValue));
}
}
}
}
else
{
logger.LogDebug("the client Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("declaredName"u8, out var declaredNameProperty))
{
dtoInstance.DeclaredName = declaredNameProperty.GetString();
}
else
{
logger.LogDebug("the declaredName Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("declaredShortName"u8, out var declaredShortNameProperty))
{
dtoInstance.DeclaredShortName = declaredShortNameProperty.GetString();
}
else
{
logger.LogDebug("the declaredShortName Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("documentation"u8, out var documentationProperty))
{
foreach (var arrayItem in documentationProperty.EnumerateArray())
{
if (arrayItem.TryGetProperty("@id"u8, out var documentationExternalIdProperty))
{
var propertyValue = documentationExternalIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.documentation.Add(Guid.Parse(propertyValue));
}
}
}
}
else
{
logger.LogDebug("the documentation Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("elementId"u8, out var elementIdProperty))
{
var propertyValue = elementIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.ElementId = propertyValue;
}
}
else
{
logger.LogDebug("the elementId Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty))
{
if (isImpliedProperty.ValueKind != JsonValueKind.Null)
{
dtoInstance.IsImplied = isImpliedProperty.GetBoolean();
}
}
else
{
logger.LogDebug("the isImplied Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("isImpliedIncluded"u8, out var isImpliedIncludedProperty))
{
if (isImpliedIncludedProperty.ValueKind != JsonValueKind.Null)
{
dtoInstance.IsImpliedIncluded = isImpliedIncludedProperty.GetBoolean();
}
}
else
{
logger.LogDebug("the isImpliedIncluded Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("isLibraryElement"u8, out var isLibraryElementProperty))
{
if (isLibraryElementProperty.ValueKind != JsonValueKind.Null)
{
dtoInstance.isLibraryElement = isLibraryElementProperty.GetBoolean();
}
}
else
{
logger.LogDebug("the isLibraryElement Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("name"u8, out var nameProperty))
{
dtoInstance.name = nameProperty.GetString();
}
else
{
logger.LogDebug("the name Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("ownedAnnotation"u8, out var ownedAnnotationProperty))
{
foreach (var arrayItem in ownedAnnotationProperty.EnumerateArray())
{
if (arrayItem.TryGetProperty("@id"u8, out var ownedAnnotationExternalIdProperty))
{
var propertyValue = ownedAnnotationExternalIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.ownedAnnotation.Add(Guid.Parse(propertyValue));
}
}
}
}
else
{
logger.LogDebug("the ownedAnnotation Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("ownedElement"u8, out var ownedElementProperty))
{
foreach (var arrayItem in ownedElementProperty.EnumerateArray())
{
if (arrayItem.TryGetProperty("@id"u8, out var ownedElementExternalIdProperty))
{
var propertyValue = ownedElementExternalIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.ownedElement.Add(Guid.Parse(propertyValue));
}
}
}
}
else
{
logger.LogDebug("the ownedElement Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty))
{
foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray())
{
if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty))
{
var propertyValue = ownedRelatedElementExternalIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue));
}
}
}
}
else
{
logger.LogDebug("the ownedRelatedElement Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty))
{
foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray())
{
if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty))
{
var propertyValue = ownedRelationshipExternalIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue));
}
}
}
}
else
{
logger.LogDebug("the ownedRelationship Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty))
{
if (ownerProperty.ValueKind == JsonValueKind.Null)
{
dtoInstance.owner = null;
}
else
{
if (ownerProperty.TryGetProperty("@id"u8, out var ownerExternalIdProperty))
{
var propertyValue = ownerExternalIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.owner = Guid.Parse(propertyValue);
}
}
}
}
else
{
logger.LogDebug("the owner Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("owningMembership"u8, out var owningMembershipProperty))
{
if (owningMembershipProperty.ValueKind == JsonValueKind.Null)
{
dtoInstance.owningMembership = null;
}
else
{
if (owningMembershipProperty.TryGetProperty("@id"u8, out var owningMembershipExternalIdProperty))
{
var propertyValue = owningMembershipExternalIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.owningMembership = Guid.Parse(propertyValue);
}
}
}
}
else
{
logger.LogDebug("the owningMembership Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("owningNamespace"u8, out var owningNamespaceProperty))
{
if (owningNamespaceProperty.ValueKind == JsonValueKind.Null)
{
dtoInstance.owningNamespace = null;
}
else
{
if (owningNamespaceProperty.TryGetProperty("@id"u8, out var owningNamespaceExternalIdProperty))
{
var propertyValue = owningNamespaceExternalIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.owningNamespace = Guid.Parse(propertyValue);
}
}
}
}
else
{
logger.LogDebug("the owningNamespace Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty))
{
if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null)
{
dtoInstance.OwningRelatedElement = null;
}
else
{
if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty))
{
var propertyValue = owningRelatedElementExternalIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue);
}
}
}
}
else
{
logger.LogDebug("the owningRelatedElement Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("owningRelationship"u8, out var owningRelationshipProperty))
{
if (owningRelationshipProperty.ValueKind == JsonValueKind.Null)
{
dtoInstance.OwningRelationship = null;
}
else
{
if (owningRelationshipProperty.TryGetProperty("@id"u8, out var owningRelationshipExternalIdProperty))
{
var propertyValue = owningRelationshipExternalIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.OwningRelationship = Guid.Parse(propertyValue);
}
}
}
}
else
{
logger.LogDebug("the owningRelationship Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("qualifiedName"u8, out var qualifiedNameProperty))
{
dtoInstance.qualifiedName = qualifiedNameProperty.GetString();
}
else
{
logger.LogDebug("the qualifiedName Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("relatedElement"u8, out var relatedElementProperty))
{
foreach (var arrayItem in relatedElementProperty.EnumerateArray())
{
if (arrayItem.TryGetProperty("@id"u8, out var relatedElementExternalIdProperty))
{
var propertyValue = relatedElementExternalIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.relatedElement.Add(Guid.Parse(propertyValue));
}
}
}
}
else
{
logger.LogDebug("the relatedElement Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty))
{
dtoInstance.shortName = shortNameProperty.GetString();
}
else
{
logger.LogDebug("the shortName Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("supplier"u8, out var supplierProperty))
{
foreach (var arrayItem in supplierProperty.EnumerateArray())
{
if (arrayItem.TryGetProperty("@id"u8, out var supplierExternalIdProperty))
{
var propertyValue = supplierExternalIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.Supplier.Add(Guid.Parse(propertyValue));
}
}
}
}
else
{
logger.LogDebug("the supplier Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("textualRepresentation"u8, out var textualRepresentationProperty))
{
foreach (var arrayItem in textualRepresentationProperty.EnumerateArray())
{
if (arrayItem.TryGetProperty("@id"u8, out var textualRepresentationExternalIdProperty))
{
var propertyValue = textualRepresentationExternalIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.textualRepresentation.Add(Guid.Parse(propertyValue));
}
}
}
}
else
{
logger.LogDebug("the textualRepresentation Json property was not found in the Dependency: { Id }", dtoInstance.Id);
}
return dtoInstance;
}
}
}
// ------------------------------------------------------------------------------------------------
// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!--------
// ------------------------------------------------------------------------------------------------