-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAssociationDeSerializer.cs
More file actions
281 lines (250 loc) · 11.4 KB
/
AssociationDeSerializer.cs
File metadata and controls
281 lines (250 loc) · 11.4 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
// -------------------------------------------------------------------------------------------------
// <copyright file="AssociationDeSerializer.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.Associations;
using SysML2.NET.Serializer.Json;
/// <summary>
/// The purpose of the <see cref="AssociationDeSerializer"/> is to provide deserialization capabilities
/// for the <see cref="IAssociation"/> interface
/// </summary>
internal static class AssociationDeSerializer
{
/// <summary>
/// Deserializes an instance of <see cref="IAssociation"/> from the provided <see cref="JsonElement"/>
/// </summary>
/// <param name="jsonElement">
/// The <see cref="JsonElement"/> that contains the <see cref="IAssociation"/> 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="IAssociation"/>
/// </returns>
internal static IAssociation DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null)
{
var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("AssociationDeSerializer");
if (!jsonElement.TryGetProperty("@type"u8, out var @type))
{
throw new InvalidOperationException("The @type property is not available, the AssociationDeSerializer cannot be used to deserialize this JsonElement");
}
if (@type.GetString() != "Association")
{
throw new InvalidOperationException($"The AssociationDeSerializer can only be used to deserialize objects of type IAssociation, a {@type.GetString()} was provided");
}
var dtoInstance = new SysML2.NET.Core.DTO.Kernel.Associations.Association();
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 Association 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 Association: { 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 Association: { 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 Association: { 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 Association: { 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 Association: { 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 Association: { 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 Association: { 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 Association: { 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 Association: { 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 Association: { 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 Association: { 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 Association: { Id }", dtoInstance.Id);
}
return dtoInstance;
}
}
}
// ------------------------------------------------------------------------------------------------
// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!--------
// ------------------------------------------------------------------------------------------------