-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathFlowDeSerializer.cs
More file actions
386 lines (346 loc) · 15.2 KB
/
FlowDeSerializer.cs
File metadata and controls
386 lines (346 loc) · 15.2 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
// -------------------------------------------------------------------------------------------------
// <copyright file="FlowDeSerializer.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.Kernel.Interactions;
using SysML2.NET.Serializer.Json;
/// <summary>
/// The purpose of the <see cref="FlowDeSerializer"/> is to provide deserialization capabilities
/// for the <see cref="IFlow"/> interface
/// </summary>
internal static class FlowDeSerializer
{
/// <summary>
/// Deserializes an instance of <see cref="IFlow"/> from the provided <see cref="JsonElement"/>
/// </summary>
/// <param name="jsonElement">
/// The <see cref="JsonElement"/> that contains the <see cref="IFlow"/> 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="IFlow"/>
/// </returns>
internal static IFlow DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null)
{
var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FlowDeSerializer");
if (!jsonElement.TryGetProperty("@type"u8, out var @type))
{
throw new InvalidOperationException("The @type property is not available, the FlowDeSerializer cannot be used to deserialize this JsonElement");
}
if (@type.GetString() != "Flow")
{
throw new InvalidOperationException($"The FlowDeSerializer can only be used to deserialize objects of type IFlow, a {@type.GetString()} was provided");
}
var dtoInstance = new SysML2.NET.Core.DTO.Kernel.Interactions.Flow();
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 Flow 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 Flow: { 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 Flow: { 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 Flow: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("direction"u8, out var directionProperty))
{
dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString());
}
else
{
logger.LogDebug("the direction Json property was not found in the Flow: { 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 Flow: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty))
{
if (isAbstractProperty.ValueKind != JsonValueKind.Null)
{
dtoInstance.IsAbstract = isAbstractProperty.GetBoolean();
}
}
else
{
logger.LogDebug("the isAbstract Json property was not found in the Flow: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty))
{
if (isCompositeProperty.ValueKind != JsonValueKind.Null)
{
dtoInstance.IsComposite = isCompositeProperty.GetBoolean();
}
}
else
{
logger.LogDebug("the isComposite Json property was not found in the Flow: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty))
{
if (isConstantProperty.ValueKind != JsonValueKind.Null)
{
dtoInstance.IsConstant = isConstantProperty.GetBoolean();
}
}
else
{
logger.LogDebug("the isConstant Json property was not found in the Flow: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty))
{
if (isDerivedProperty.ValueKind != JsonValueKind.Null)
{
dtoInstance.IsDerived = isDerivedProperty.GetBoolean();
}
}
else
{
logger.LogDebug("the isDerived Json property was not found in the Flow: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty))
{
if (isEndProperty.ValueKind != JsonValueKind.Null)
{
dtoInstance.IsEnd = isEndProperty.GetBoolean();
}
}
else
{
logger.LogDebug("the isEnd Json property was not found in the Flow: { 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 Flow: { 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 Flow: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty))
{
if (isOrderedProperty.ValueKind != JsonValueKind.Null)
{
dtoInstance.IsOrdered = isOrderedProperty.GetBoolean();
}
}
else
{
logger.LogDebug("the isOrdered Json property was not found in the Flow: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty))
{
if (isPortionProperty.ValueKind != JsonValueKind.Null)
{
dtoInstance.IsPortion = isPortionProperty.GetBoolean();
}
}
else
{
logger.LogDebug("the isPortion Json property was not found in the Flow: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty))
{
if (isSufficientProperty.ValueKind != JsonValueKind.Null)
{
dtoInstance.IsSufficient = isSufficientProperty.GetBoolean();
}
}
else
{
logger.LogDebug("the isSufficient Json property was not found in the Flow: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty))
{
if (isUniqueProperty.ValueKind != JsonValueKind.Null)
{
dtoInstance.IsUnique = isUniqueProperty.GetBoolean();
}
}
else
{
logger.LogDebug("the isUnique Json property was not found in the Flow: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty))
{
if (isVariableProperty.ValueKind != JsonValueKind.Null)
{
dtoInstance.IsVariable = isVariableProperty.GetBoolean();
}
}
else
{
logger.LogDebug("the isVariable Json property was not found in the Flow: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty))
{
foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray())
{
if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementIdProperty))
{
var propertyValue = ownedRelatedElementIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue));
}
}
}
}
else
{
logger.LogDebug("the ownedRelatedElement Json property was not found in the Flow: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty))
{
foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray())
{
if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipIdProperty))
{
var propertyValue = ownedRelationshipIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue));
}
}
}
}
else
{
logger.LogDebug("the ownedRelationship Json property was not found in the Flow: { 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 owningRelatedElementIdProperty))
{
var propertyValue = owningRelatedElementIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue);
}
}
}
}
else
{
logger.LogDebug("the owningRelatedElement Json property was not found in the Flow: { 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 owningRelationshipIdProperty))
{
var propertyValue = owningRelationshipIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.OwningRelationship = Guid.Parse(propertyValue);
}
}
}
}
else
{
logger.LogDebug("the owningRelationship Json property was not found in the Flow: { Id }", dtoInstance.Id);
}
return dtoInstance;
}
}
}
// ------------------------------------------------------------------------------------------------
// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!--------
// ------------------------------------------------------------------------------------------------