11// -------------------------------------------------------------------------------------------------
22// <copyright file="PartDefinitionDeSerializer.cs" company="RHEA System S.A.">
3- //
3+ //
44// Copyright 2022 RHEA System S.A.
5- //
5+ //
66// Licensed under the Apache License, Version 2.0 (the "License");
77// you may not use this file except in compliance with the License.
88// You may obtain a copy of the License at
9- //
9+ //
1010// http://www.apache.org/licenses/LICENSE-2.0
11- //
11+ //
1212// Unless required by applicable law or agreed to in writing, software
1313// distributed under the License is distributed on an "AS IS" BASIS,
1414// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515// See the License for the specific language governing permissions and
1616// limitations under the License.
17- //
17+ //
1818// </copyright>
1919// ------------------------------------------------------------------------------------------------
2020
@@ -55,19 +55,19 @@ internal static class PartDefinitionDeSerializer
5555 /// </returns>
5656 internal static IPartDefinition DeSerialize ( JsonElement jsonElement , SerializationModeKind serializationModeKind , ILoggerFactory loggerFactory = null )
5757 {
58- var logger = loggerFactory == null ? NullLogger . Instance : loggerFactory . CreateLogger ( "IPartDefinition.DeSerialize " ) ;
58+ var logger = loggerFactory == null ? NullLogger . Instance : loggerFactory . CreateLogger ( "PartDefinitionDeSerializer " ) ;
5959
60- if ( ! jsonElement . TryGetProperty ( "@type" , out JsonElement typeProperty ) )
60+ if ( ! jsonElement . TryGetProperty ( "@type" , out JsonElement @type ) )
6161 {
6262 throw new InvalidOperationException ( "The @type property is not available, the PartDefinitionDeSerializer cannot be used to deserialize this JsonElement" ) ;
6363 }
6464
65- if ( typeProperty . GetString ( ) != "PartDefinition" )
65+ if ( @type . GetString ( ) != "PartDefinition" )
6666 {
67- throw new InvalidOperationException ( $ "The PartDefinitionDeSerializer can only be used to deserialize objects of type PartDefinition , a { typeProperty . GetString ( ) } was provided") ;
67+ throw new InvalidOperationException ( $ "The PartDefinitionDeSerializer can only be used to deserialize objects of type IPartDefinition , a { @type . GetString ( ) } was provided") ;
6868 }
6969
70- var partDefinition = new PartDefinition ( ) ;
70+ var dtoInstance = new DTO . PartDefinition ( ) ;
7171
7272 if ( jsonElement . TryGetProperty ( "@id" , out JsonElement idProperty ) )
7373 {
@@ -78,102 +78,105 @@ internal static IPartDefinition DeSerialize(JsonElement jsonElement, Serializati
7878 }
7979 else
8080 {
81- partDefinition . Id = Guid . Parse ( propertyValue ) ;
81+ dtoInstance . Id = Guid . Parse ( propertyValue ) ;
8282 }
8383 }
8484
8585 if ( jsonElement . TryGetProperty ( "aliasIds" , out JsonElement aliasIdsProperty ) )
8686 {
87- foreach ( var item in aliasIdsProperty . EnumerateArray ( ) )
87+ foreach ( var arrayItem in aliasIdsProperty . EnumerateArray ( ) )
8888 {
89- partDefinition . AliasIds . Add ( item . GetString ( ) ) ;
89+ var propertyValue = arrayItem . GetString ( ) ;
90+ if ( propertyValue != null )
91+ {
92+ dtoInstance . AliasIds . Add ( propertyValue ) ;
93+ }
9094 }
9195 }
9296 else
9397 {
94- logger . LogDebug ( $ "the aliasIds Json property was not found in the PartDefinition: { partDefinition . Id } ") ;
98+ logger . LogDebug ( $ "the aliasIds Json property was not found in the PartDefinition: { dtoInstance . Id } ") ;
9599 }
96100
97101 if ( jsonElement . TryGetProperty ( "elementId" , out JsonElement elementIdProperty ) )
98102 {
99103 var propertyValue = elementIdProperty . GetString ( ) ;
100104 if ( propertyValue != null )
101105 {
102- partDefinition . ElementId = propertyValue ;
106+ dtoInstance . ElementId = propertyValue ;
103107 }
104108 }
105109 else
106110 {
107- logger . LogDebug ( $ "the elementId Json property was not found in the PartDefinition: { partDefinition . Id } ") ;
111+ logger . LogDebug ( $ "the elementId Json property was not found in the PartDefinition: { dtoInstance . Id } ") ;
108112 }
109113
110114 if ( jsonElement . TryGetProperty ( "isAbstract" , out JsonElement isAbstractProperty ) )
111115 {
112- partDefinition . IsAbstract = isAbstractProperty . GetBoolean ( ) ;
116+ dtoInstance . IsAbstract = isAbstractProperty . GetBoolean ( ) ;
113117 }
114118 else
115119 {
116- logger . LogDebug ( $ "the isAbstract Json property was not found in the PartDefinition: { partDefinition . Id } ") ;
120+ logger . LogDebug ( $ "the isAbstract Json property was not found in the PartDefinition: { dtoInstance . Id } ") ;
117121 }
118122
119123 if ( jsonElement . TryGetProperty ( "isIndividual" , out JsonElement isIndividualProperty ) )
120124 {
121- partDefinition . IsIndividual = isIndividualProperty . GetBoolean ( ) ;
125+ dtoInstance . IsIndividual = isIndividualProperty . GetBoolean ( ) ;
122126 }
123127 else
124128 {
125- logger . LogDebug ( $ "the isIndividual Json property was not found in the PartDefinition: { partDefinition . Id } ") ;
129+ logger . LogDebug ( $ "the isIndividual Json property was not found in the PartDefinition: { dtoInstance . Id } ") ;
126130 }
127131
128132 if ( jsonElement . TryGetProperty ( "isSufficient" , out JsonElement isSufficientProperty ) )
129133 {
130- partDefinition . IsSufficient = isSufficientProperty . GetBoolean ( ) ;
134+ dtoInstance . IsSufficient = isSufficientProperty . GetBoolean ( ) ;
131135 }
132136 else
133137 {
134- logger . LogDebug ( $ "the isSufficient Json property was not found in the PartDefinition: { partDefinition . Id } ") ;
138+ logger . LogDebug ( $ "the isSufficient Json property was not found in the PartDefinition: { dtoInstance . Id } ") ;
135139 }
136140
137141 if ( jsonElement . TryGetProperty ( "isVariation" , out JsonElement isVariationProperty ) )
138142 {
139- partDefinition . IsVariation = isVariationProperty . GetBoolean ( ) ;
143+ dtoInstance . IsVariation = isVariationProperty . GetBoolean ( ) ;
140144 }
141145 else
142146 {
143- logger . LogDebug ( $ "the isVariation Json property was not found in the PartDefinition: { partDefinition . Id } ") ;
147+ logger . LogDebug ( $ "the isVariation Json property was not found in the PartDefinition: { dtoInstance . Id } ") ;
144148 }
145149
146150 if ( jsonElement . TryGetProperty ( "name" , out JsonElement nameProperty ) )
147151 {
148152 var propertyValue = nameProperty . GetString ( ) ;
149153 if ( propertyValue != null )
150154 {
151- partDefinition . Name = propertyValue ;
155+ dtoInstance . Name = propertyValue ;
152156 }
153157 }
154158 else
155159 {
156- logger . LogDebug ( $ "the name Json property was not found in the PartDefinition: { partDefinition . Id } ") ;
160+ logger . LogDebug ( $ "the name Json property was not found in the PartDefinition: { dtoInstance . Id } ") ;
157161 }
158162
159163 if ( jsonElement . TryGetProperty ( "ownedRelationship" , out JsonElement ownedRelationshipProperty ) )
160164 {
161- foreach ( var item in ownedRelationshipProperty . EnumerateArray ( ) )
165+ foreach ( var arrayItem in ownedRelationshipProperty . EnumerateArray ( ) )
162166 {
163- if ( item . TryGetProperty ( "@id" , out JsonElement ownedRelationshipIdProperty ) )
167+ if ( arrayItem . TryGetProperty ( "@id" , out JsonElement ownedRelationshipIdProperty ) )
164168 {
165169 var propertyValue = ownedRelationshipIdProperty . GetString ( ) ;
166170 if ( propertyValue != null )
167171 {
168-
169- partDefinition . OwnedRelationship . Add ( Guid . Parse ( propertyValue ) ) ;
172+ dtoInstance . OwnedRelationship . Add ( Guid . Parse ( propertyValue ) ) ;
170173 }
171174 }
172175 }
173176 }
174177 else
175178 {
176- logger . LogDebug ( $ "the ownedRelationship Json property was not found in the PartDefinition: { partDefinition . Id } ") ;
179+ logger . LogDebug ( $ "the ownedRelationship Json property was not found in the PartDefinition: { dtoInstance . Id } ") ;
177180 }
178181
179182 if ( jsonElement . TryGetProperty ( "owningRelationship" , out JsonElement owningRelationshipProperty ) )
@@ -183,29 +186,30 @@ internal static IPartDefinition DeSerialize(JsonElement jsonElement, Serializati
183186 var propertyValue = owningRelationshipIdProperty . GetString ( ) ;
184187 if ( propertyValue != null )
185188 {
186- partDefinition . OwningRelationship = Guid . Parse ( propertyValue ) ;
189+ dtoInstance . OwningRelationship = Guid . Parse ( propertyValue ) ;
187190 }
188191 }
189192 }
190193 else
191194 {
192- logger . LogDebug ( $ "the owningRelationship Json property was not found in the PartDefinition: { partDefinition . Id } ") ;
195+ logger . LogDebug ( $ "the owningRelationship Json property was not found in the PartDefinition: { dtoInstance . Id } ") ;
193196 }
194197
195198 if ( jsonElement . TryGetProperty ( "shortName" , out JsonElement shortNameProperty ) )
196199 {
197200 var propertyValue = shortNameProperty . GetString ( ) ;
198201 if ( propertyValue != null )
199202 {
200- partDefinition . ShortName = propertyValue ;
203+ dtoInstance . ShortName = propertyValue ;
201204 }
202205 }
203206 else
204207 {
205- logger . LogDebug ( $ "the shortName Json property was not found in the PartDefinition: { partDefinition . Id } ") ;
208+ logger . LogDebug ( $ "the shortName Json property was not found in the PartDefinition: { dtoInstance . Id } ") ;
206209 }
207210
208- return partDefinition ;
211+
212+ return dtoInstance ;
209213 }
210214 }
211215}
0 commit comments