diff --git a/CDP4-SDK.sln.DotSettings b/CDP4-SDK.sln.DotSettings index 3e8a67ef4..64ed4378d 100644 --- a/CDP4-SDK.sln.DotSettings +++ b/CDP4-SDK.sln.DotSettings @@ -246,7 +246,7 @@ <copyright file="${File.FileName}" company="Starion Group S.A."> Copyright (c) 2015-${CurrentDate.Year} Starion Group S.A. - Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar + Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar This file is part of CDP4-COMET SDK Community Edition diff --git a/CDP4Common.NetCore.Tests/CDP4Common.NetCore.Tests.csproj b/CDP4Common.NetCore.Tests/CDP4Common.NetCore.Tests.csproj index 258bb07ed..a0049ddd5 100644 --- a/CDP4Common.NetCore.Tests/CDP4Common.NetCore.Tests.csproj +++ b/CDP4Common.NetCore.Tests/CDP4Common.NetCore.Tests.csproj @@ -14,7 +14,7 @@ - + diff --git a/CDP4Common.Tests/CDP4Common.Tests.csproj b/CDP4Common.Tests/CDP4Common.Tests.csproj index 643e8d26c..8fbce3656 100644 --- a/CDP4Common.Tests/CDP4Common.Tests.csproj +++ b/CDP4Common.Tests/CDP4Common.Tests.csproj @@ -17,7 +17,7 @@ - + diff --git a/CDP4Common/CDP4Common.csproj b/CDP4Common/CDP4Common.csproj index ac05277d4..20a4713f0 100644 --- a/CDP4Common/CDP4Common.csproj +++ b/CDP4Common/CDP4Common.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4Common Community Edition - 27.4.0 + 28.0.0 CDP4 Common Class Library that contains DTOs, POCOs Copyright © Starion Group S.A. Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael, Ahmed @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [ADD] SharpZipLibExtension Methods + [Refactor] Newtonsoft to System.Text.Json README.md diff --git a/CDP4Dal.NetCore.Tests/CDP4Dal.NetCore.Tests.csproj b/CDP4Dal.NetCore.Tests/CDP4Dal.NetCore.Tests.csproj index 032f1813d..a8b5dc3de 100644 --- a/CDP4Dal.NetCore.Tests/CDP4Dal.NetCore.Tests.csproj +++ b/CDP4Dal.NetCore.Tests/CDP4Dal.NetCore.Tests.csproj @@ -16,7 +16,7 @@ - + diff --git a/CDP4Dal.NetCore.Tests/DAL/DalTestFixture.cs b/CDP4Dal.NetCore.Tests/DAL/DalTestFixture.cs index b59f1a5c6..d8d55bfd0 100644 --- a/CDP4Dal.NetCore.Tests/DAL/DalTestFixture.cs +++ b/CDP4Dal.NetCore.Tests/DAL/DalTestFixture.cs @@ -10,17 +10,17 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests.DAL { @@ -36,11 +36,12 @@ namespace CDP4Dal.Tests.DAL using CDP4Common.Helpers; using CDP4Dal.Composition; + using CDP4Dal.DAL; using CDP4Dal.Exceptions; using CDP4Dal.Operations; - using CDP4Dal.DAL; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; using NUnit.Framework; @@ -140,6 +141,7 @@ public void Verify_That_SetIterationId_Works_as_expected() var iteration = new Iteration(); var elementDefinition = new ElementDefinition(); var parameter = new Parameter(); + var list = new List { model, @@ -303,7 +305,10 @@ public void Verify_that_OperationContainerFileVerification_throws_no_exception_w [CDPVersion("1.1.0")] internal class TestDal : Dal { - public override bool IsReadOnly { get { return false; } } + public override bool IsReadOnly + { + get { return false; } + } public TestDal(Credentials credentials) : base() @@ -451,6 +456,7 @@ public override Task> CherryPick(Guid engineeringModelId, Gui internal class DecoratedDal : Dal { public override bool IsReadOnly { get; } + public override Task> Write(IEnumerable operationContainer, IEnumerable files = null) { throw new NotImplementedException(); @@ -566,4 +572,4 @@ public override Task> CherryPick(Guid engineeringModelId, Gui throw new NotSupportedException(); } } -} \ No newline at end of file +} diff --git a/CDP4Dal.NetCore.Tests/Operations/OperationContainerTestFixture.cs b/CDP4Dal.NetCore.Tests/Operations/OperationContainerTestFixture.cs index a24abc35e..8db7f0950 100644 --- a/CDP4Dal.NetCore.Tests/Operations/OperationContainerTestFixture.cs +++ b/CDP4Dal.NetCore.Tests/Operations/OperationContainerTestFixture.cs @@ -10,17 +10,17 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests { @@ -28,10 +28,14 @@ namespace CDP4Dal.Tests using System.Linq; using CDP4Common.CommonData; - using CDP4Common.DTO; + using CDP4Common.DTO; + using CDP4Dal.Operations; + + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; - + [TestFixture] public class OperationContainerTestFixture { @@ -42,7 +46,7 @@ public class OperationContainerTestFixture [SetUp] public void SetUp() { - this.siteDirectoryContext = "/SiteDirectory/47363f0d-eb6d-4a58-95f5-fa7854995650"; + this.siteDirectoryContext = "/SiteDirectory/47363f0d-eb6d-4a58-95f5-fa7854995650"; this.iterationContext = "/EngineeringModel/5e5dc7f8-833d-4331-b421-eb2c64fcf64b/iteration/b58ea73d-350d-4520-b9d9-a52c75ac2b5d"; } @@ -98,9 +102,9 @@ public void VerifyExecutionOfOperationAddAndRemove() var elementDefinition = new ElementDefinition(Guid.NewGuid(), 0); elementDefinition.PartialRoutes.Add("iteration/b58ea73d-350d-4520-b9d9-a52c75ac2b5d"); elementDefinition.PartialRoutes.Add("EngineeringModel/5e5dc7f8-833d-4331-b421-eb2c64fcf64b"); - + var clone = elementDefinition.DeepClone(); - var operation = new Operation(elementDefinition, clone, OperationKind.Update); + var operation = new Operation(elementDefinition, clone, OperationKind.Update); var operationContainer = new OperationContainer(this.iterationContext); diff --git a/CDP4Dal.NetCore.Tests/Operations/OperationTestFixture.cs b/CDP4Dal.NetCore.Tests/Operations/OperationTestFixture.cs index f0e46dd64..b226b6a3a 100644 --- a/CDP4Dal.NetCore.Tests/Operations/OperationTestFixture.cs +++ b/CDP4Dal.NetCore.Tests/Operations/OperationTestFixture.cs @@ -10,12 +10,12 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -26,7 +26,7 @@ namespace CDP4Dal.Tests { using CDP4Common.DTO; - using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; using NUnit.Framework; diff --git a/CDP4Dal.NetCore.Tests/Operations/PostOperationTestFixture.cs b/CDP4Dal.NetCore.Tests/Operations/PostOperationTestFixture.cs index 29bda68f0..4eaec5265 100644 --- a/CDP4Dal.NetCore.Tests/Operations/PostOperationTestFixture.cs +++ b/CDP4Dal.NetCore.Tests/Operations/PostOperationTestFixture.cs @@ -10,17 +10,17 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests { @@ -29,9 +29,9 @@ namespace CDP4Dal.Tests using CDP4Common; using CDP4Common.Dto; using CDP4Common.DTO; - - using CDP4Dal.Operations; - + + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; [TestFixture] @@ -50,13 +50,5 @@ public void VerifyThatConstructorSetsLists() internal class TestPostOperation : PostOperation { - public override List Delete { get; set; } - public override List Create { get; set; } - public override List Update { get; set; } - public override List Copy { get; set; } - public override void ConstructFromOperation(Operation operation) - { - throw new System.NotImplementedException(); - } } } diff --git a/CDP4Dal.NetCore.Tests/Operations/ThingTransactionTestFixture.cs b/CDP4Dal.NetCore.Tests/Operations/ThingTransactionTestFixture.cs index 848587a43..9abeaa4b9 100644 --- a/CDP4Dal.NetCore.Tests/Operations/ThingTransactionTestFixture.cs +++ b/CDP4Dal.NetCore.Tests/Operations/ThingTransactionTestFixture.cs @@ -10,17 +10,17 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests { @@ -34,9 +34,11 @@ namespace CDP4Dal.Tests using CDP4Common.EngineeringModelData; using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - + using CDP4Dal.Operations; - + + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; /// @@ -131,6 +133,7 @@ public void VerifyThatCreateThingWorksWithAbstractContainer() { Container = this.siteDirectory }; + this.cache.TryAdd(new CacheKey(siteRdl.Iid, null), new Lazy(() => siteRdl)); var cloneRdl = siteRdl.Clone(false); @@ -183,7 +186,7 @@ public void VerifyThatCreateThingTwiceDoesntThrowException() var transaction = new ThingTransaction(transactionContext, this.siteDirectory.Clone(false)); var phone = new TelephoneNumber(Guid.NewGuid(), this.cache, this.uri); - Assert.That(() => + Assert.That(() => { transaction.Create(phone); transaction.Create(phone); @@ -246,7 +249,6 @@ public void VerifyThatDeleteThingAlreadyDeletedWorks() [Test] public void VerifyThatUpdateContainerWorks() { - var iterationClone = this.iteration.Clone(false); var option1 = new Option(Guid.NewGuid(), this.cache, this.uri); @@ -328,6 +330,7 @@ public void FunctionalTestCase1() emailTrans.Create(email); emailTrans.FinalizeSubTransaction(email, person1_1); + // end add email, verify that email is added to person1_1, (the clone of person1) Assert.That(2, Is.EqualTo(person1_1Tr.AddedThing.Count())); @@ -339,6 +342,7 @@ public void FunctionalTestCase1() var phone_1Trans = new ThingTransaction(phone_1, person1_1Tr, person1_1); phone_1Trans.CreateOrUpdate(phone_1); phone_1Trans.FinalizeSubTransaction(phone_1, person1_1); + // end update phone // verify that the new reference is used @@ -354,7 +358,6 @@ public void FunctionalTestCase1() Assert.That(rootTransaction.AddedThing.Contains(phone_1), Is.True); Assert.That(1, Is.EqualTo(cloneSiteDir.Person.Count)); - // Create new person var person2 = new Person(); var person2Trans = new ThingTransaction(person2, rootTransaction, cloneSiteDir); @@ -828,6 +831,7 @@ public void VerifyThatCascadeDeleteWorksOnAddedThing() transaction.Delete(person.Clone(false)); var operationContainer = transaction.FinalizeTransaction(); + // Update sitedir Assert.That(1, Is.EqualTo(operationContainer.Operations.Count())); } diff --git a/CDP4Dal.NetCore.Tests/SessionTestFixture.cs b/CDP4Dal.NetCore.Tests/SessionTestFixture.cs index b978e39e5..77734e5e4 100644 --- a/CDP4Dal.NetCore.Tests/SessionTestFixture.cs +++ b/CDP4Dal.NetCore.Tests/SessionTestFixture.cs @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.NetCore.Tests { @@ -37,17 +37,18 @@ namespace CDP4Dal.NetCore.Tests using CDP4Common.Types; using CDP4Dal.Composition; - using CDP4Dal.Operations; using CDP4Dal.DAL; using CDP4Dal.Events; using CDP4Dal.Exceptions; + using CDP4Dal.Operations; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; using Moq; - + using NUnit.Framework; - + using DomainOfExpertise = CDP4Common.SiteDirectoryData.DomainOfExpertise; using EngineeringModelSetup = CDP4Common.DTO.EngineeringModelSetup; using ModelReferenceDataLibrary = CDP4Common.SiteDirectoryData.ModelReferenceDataLibrary; @@ -129,10 +130,7 @@ public void TearDown() public async Task VerifythatOpenCallAssemblerSynchronizeWithDtos() { var eventReceived = false; - this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => - { - eventReceived = true; - }); + this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => { eventReceived = true; }); await this.session.Open(); @@ -149,20 +147,20 @@ public async Task VerifyThatWriteWithEmptyResponseSendsMessages() writeWithNoResultsTaskCompletionSource.SetResult(new List()); this.mockedDal.Setup(x => x.Open(It.IsAny(), It.IsAny())).Returns(writeWithNoResultsTaskCompletionSource.Task); - this.messageBus.Listen() - .Subscribe(x => - { - if (x.Status == SessionStatus.BeginUpdate) + this.messageBus.Listen() + .Subscribe(x => { - beginUpdateReceived = true; - return; - } + if (x.Status == SessionStatus.BeginUpdate) + { + beginUpdateReceived = true; + return; + } - if (x.Status == SessionStatus.EndUpdate) - { - endUpdateReceived = true; - } - }); + if (x.Status == SessionStatus.EndUpdate) + { + endUpdateReceived = true; + } + }); var context = $"/SiteDirectory/{Guid.NewGuid()}"; @@ -186,13 +184,10 @@ public async Task VerifythatRefreshSynchronizeTheAssembler() var readTaskCompletionSource = new TaskCompletionSource>(); readTaskCompletionSource.SetResult(this.dalOutputs); this.mockedDal.Setup(x => x.Read(It.IsAny(), It.IsAny(), It.Is(query => query.RevisionNumber == 0))).Returns(readTaskCompletionSource.Task); - + await this.session.Open(); - this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => - { - eventReceived = true; - }); + this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => { eventReceived = true; }); // refresh shouldnt do anything await this.session.Refresh(); @@ -216,10 +211,7 @@ public async Task VerifythatReloadSynchronizeTheAssembler() await this.session.Open(); - this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => - { - eventReceived = true; - }); + this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => { eventReceived = true; }); await this.session.Reload(); @@ -277,10 +269,10 @@ public async Task VerifyThatCloseRdlWorks() var rdlDto = new CDP4Common.DTO.SiteReferenceDataLibrary { Iid = Guid.NewGuid() }; var rdlPoco = new CDP4Common.SiteDirectoryData.SiteReferenceDataLibrary { Iid = rdlDto.Iid, Name = rdlDto.Name, ShortName = rdlDto.ShortName, Container = siteDirectoryPoco }; - + var requiredSiteReferenceDataLibraryDto = new CDP4Common.DTO.SiteReferenceDataLibrary() { Iid = Guid.NewGuid() }; var requiredSiteReferenceDataLibraryPoco = new CDP4Common.SiteDirectoryData.SiteReferenceDataLibrary(requiredSiteReferenceDataLibraryDto.Iid, this.session.Assembler.Cache, this.uri); - + rdlDto.RequiredRdl = requiredSiteReferenceDataLibraryDto.Iid; rdlPoco.RequiredRdl = requiredSiteReferenceDataLibraryPoco; @@ -319,7 +311,7 @@ public async Task VerifyThatSiteRdlRequiredByModelRdlCannotBeClosed() rdlDto.RequiredRdl = requiredRdlDto.Iid; siteDirDto.SiteReferenceDataLibrary.Add(rdlDto.Iid); siteDirDto.SiteReferenceDataLibrary.Add(requiredRdlDto.Iid); - + siteDirDto.Person.Add(this.person.Iid); var mrdl = new CDP4Common.DTO.ModelReferenceDataLibrary(Guid.NewGuid(), 0) { RequiredRdl = requiredRdlDto.Iid }; @@ -348,14 +340,15 @@ public async Task VerifyThatSiteRdlRequiredByModelRdlCannotBeClosed() var participant = new CDP4Common.DTO.Participant(Guid.NewGuid(), 0) { Person = this.person.Iid }; modelsetup.Participant.Add(participant.Iid); - var modelPoco = new CDP4Common.EngineeringModelData.EngineeringModel(model.Iid, null, null){EngineeringModelSetup = modelsetuppoco}; + var modelPoco = new CDP4Common.EngineeringModelData.EngineeringModel(model.Iid, null, null) { EngineeringModelSetup = modelsetuppoco }; var iterationPoco = new CDP4Common.EngineeringModelData.Iteration(iteration.Iid, null, null); modelPoco.Iteration.Add(iterationPoco); var readTaskCompletionSource = new TaskCompletionSource>(); readTaskCompletionSource.SetResult(readReturn); + this.mockedDal.Setup( - x => x.Read(It.IsAny(), It.IsAny(), null)) + x => x.Read(It.IsAny(), It.IsAny(), null)) .Returns(readTaskCompletionSource.Task); var thingsToAdd = new List() { siteDirDto, requiredRdlDto, rdlDto, this.person, participant, modelsetup }; @@ -449,6 +442,7 @@ public async Task VerifyThatReadRdlWorks() { var siteDir = new CDP4Common.SiteDirectoryData.SiteDirectory(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; + this.session.Assembler.Cache.TryAdd(new CacheKey(siteDir.Iid, null), new Lazy(() => siteDir)); @@ -518,14 +512,14 @@ public async Task Verify_that_EngineeringModel_returns_result() await this.session.Read(iids); - Assert.That(this.session.Assembler.Cache.ContainsKey(new CacheKey(engineeringModel.Iid, null)), Is.True); + Assert.That(this.session.Assembler.Cache.ContainsKey(new CacheKey(engineeringModel.Iid, null)), Is.True); } [Test] public async Task VerifyThatReadIterationWorks() { var siteDir = new CDP4Common.SiteDirectoryData.SiteDirectory(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); - var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) {ShortName = "John"}; + var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; var modelSetup = new CDP4Common.SiteDirectoryData.EngineeringModelSetup(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); var iterationSetup = new CDP4Common.SiteDirectoryData.IterationSetup(Guid.NewGuid(), this.session.Assembler.Cache, this.uri) { FrozenOn = DateTime.Now, IterationIid = Guid.NewGuid() }; var mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); @@ -570,7 +564,7 @@ public async Task VerifyThatReadIterationWorks() var iterationToOpen = new CDP4Common.EngineeringModelData.Iteration(iteration.Iid, null, null); var modelToOpen = new CDP4Common.EngineeringModelData.EngineeringModel(model.Iid, null, null); iterationToOpen.Container = modelToOpen; - + await this.session.Read(iterationToOpen, activeDomain); this.mockedDal.Verify(x => x.Read(It.Is(i => i.Iid == iterationToOpen.Iid), It.IsAny(), It.IsAny()), Times.Once); @@ -607,7 +601,7 @@ public void Verify_that_when_active_person_is_null_Iteration_is_not_read() var activeDomain = new DomainOfExpertise(Guid.NewGuid(), null, null); var model = new EngineeringModel(Guid.NewGuid(), 1); var iteration = new Iteration(Guid.NewGuid(), 10) { IterationSetup = iterationSetup.Iid }; - + var iterationToOpen = new CDP4Common.EngineeringModelData.Iteration(iteration.Iid, null, null); var modelToOpen = new CDP4Common.EngineeringModelData.EngineeringModel(model.Iid, null, null); iterationToOpen.Container = modelToOpen; @@ -664,10 +658,7 @@ public async Task VerifyThatWriteWorksWithEventHandler() var johnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; this.session.GetType().GetProperty("ActivePerson")?.SetValue(this.session, johnDoe, null); - this.session.BeforeWrite += (o, args) => - { - args.Cancelled = false; - }; + this.session.BeforeWrite += (o, args) => { args.Cancelled = false; }; await this.session.Write(new OperationContainer(context)); @@ -681,10 +672,7 @@ public void VerifyThatCancelWriteWorks() var johnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; this.session.GetType().GetProperty("ActivePerson")?.SetValue(this.session, johnDoe, null); - this.session.BeforeWrite += (o, args) => - { - args.Cancelled = true; - }; + this.session.BeforeWrite += (o, args) => { args.Cancelled = true; }; Assert.ThrowsAsync(async () => await this.session.Write(new OperationContainer(context))); @@ -746,11 +734,11 @@ public async Task VerifyCanReadCometTasks() var returnedCometTasks = new List() { - new () + new() { Id = Guid.NewGuid() }, - new () + new() { Id = Guid.NewGuid() }, @@ -788,7 +776,7 @@ public async Task VerifyWritePossibleLongRunningTask() this.mockedDal.Setup(x => x.Write(It.IsAny(), It.IsAny(), It.IsAny>())) .ReturnsAsync(new LongRunningTaskResult(new CometTask() { Id = Guid.Empty })); - + var cometTask = await this.session.Write(new OperationContainer(context), 1); Assert.Multiple(() => @@ -817,7 +805,7 @@ public async Task VerifyWritePossibleLongRunningTask() this.mockedDal.Setup(x => x.Write(It.IsAny(), It.IsAny(), It.IsAny>())) .ThrowsAsync(new DalReadException()); - Assert.That(() =>this.session.Write(new OperationContainer(context), 1), Throws.Exception.TypeOf()); + Assert.That(() => this.session.Write(new OperationContainer(context), 1), Throws.Exception.TypeOf()); } private void AssignActivePerson() @@ -830,17 +818,21 @@ private void AssignActivePerson() [DalExport("test dal", "test dal description", "1.1.0", DalType.Web)] internal class TestDal : IDal { - public Version SupportedVersion { get {return new Version(1, 0, 0);} } + public static Version SupportedVersion => new (1, 0, 0); - public Version DalVersion { get {return new Version("1.1.0");} } - public IMetaDataProvider MetaDataProvider { get {return new MetaDataProvider();} } + public Version DalVersion => new(1, 1, 0); + + public IMetaDataProvider MetaDataProvider => new MetaDataProvider(); /// /// Gets or sets the that uses this /// public ISession Session { get; set; } - public bool IsReadOnly { get { return false; } } + public bool IsReadOnly + { + get { return false; } + } /// /// Write all the s from all the s asynchronously. @@ -958,7 +950,7 @@ public Task> Read(Iteration iteration, CancellationToken canc /// A list of s /// /// - /// Only those s are retunred that the is a in + /// Only those s are retunred that the is a in /// public Task> Read(IEnumerable engineeringModels, CancellationToken cancellationToken) { @@ -1097,4 +1089,4 @@ public Task> CherryPick(Guid engineeringModelId, Guid iterati throw new System.NotImplementedException(); } } -} \ No newline at end of file +} diff --git a/CDP4Dal.Tests/CDP4Dal.Tests.csproj b/CDP4Dal.Tests/CDP4Dal.Tests.csproj index 9b1f57b17..bda4c0dce 100644 --- a/CDP4Dal.Tests/CDP4Dal.Tests.csproj +++ b/CDP4Dal.Tests/CDP4Dal.Tests.csproj @@ -17,7 +17,7 @@ - + diff --git a/CDP4Dal.Tests/DAL/DalTestFixture.cs b/CDP4Dal.Tests/DAL/DalTestFixture.cs index 536f3b888..a2d012d56 100644 --- a/CDP4Dal.Tests/DAL/DalTestFixture.cs +++ b/CDP4Dal.Tests/DAL/DalTestFixture.cs @@ -10,17 +10,17 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests.DAL { @@ -36,11 +36,11 @@ namespace CDP4Dal.Tests.DAL using CDP4Common.Helpers; using CDP4Dal.Composition; + using CDP4Dal.DAL; using CDP4Dal.Exceptions; using CDP4Dal.Operations; - using CDP4Dal.DAL; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Tasks; using NUnit.Framework; @@ -64,7 +64,7 @@ public void SetUp() [Test] public void Verify_that_the_credentials_are_set_to_Null_when_closed() { - var dal = new TestDal(this.credentials); + var dal = new TestDal(this.credentials); dal.CloseSession(); Assert.That(dal.Credentials, Is.Null); } @@ -140,6 +140,7 @@ public void Verify_That_SetIterationId_Works_as_expected() var iteration = new Iteration(); var elementDefinition = new ElementDefinition(); var parameter = new Parameter(); + var list = new List { model, @@ -216,7 +217,7 @@ public void Verify_That_QueryRequestContext_Returns_Expected_Result() public void Verify_that_for_a_decorated_dal_the_version_is_set() { var dal = new DecoratedDal(); - Assert.That(dal.DalVersion, Is.EqualTo(new Version(1,1,0))); + Assert.That(dal.DalVersion, Is.EqualTo(new Version(1, 1, 0))); } [Test] @@ -238,7 +239,7 @@ public void Verify_that_OperationContainerFileVerification_throws_an_exception_w var commonFileStore = new CDP4Common.EngineeringModelData.CommonFileStore(Guid.NewGuid(), null, null); engineeringModel.Iteration.Add(iteration); engineeringModel.CommonFileStore.Add(commonFileStore); - + var context = TransactionContextResolver.ResolveContext(commonFileStore); var transaction = new ThingTransaction(context); @@ -246,13 +247,13 @@ public void Verify_that_OperationContainerFileVerification_throws_an_exception_w var file = new CDP4Common.EngineeringModelData.File(Guid.NewGuid(), null, null); var fileRevision = new CDP4Common.EngineeringModelData.FileRevision(Guid.NewGuid(), null, null); - + transaction.Create(file, commonFileStoreClone); transaction.Create(fileRevision, file); var operationContainer = transaction.FinalizeTransaction(); - var files = new List {this.filePath}; + var files = new List { this.filePath }; var testDal = new TestDal(this.credentials); Assert.Throws(() => testDal.TestOperationContainerFileVerification(operationContainer, files)); @@ -277,7 +278,7 @@ public void Verify_that_OperationContainerFileVerification_throws_no_exception_w var commonFileStore = new CDP4Common.EngineeringModelData.CommonFileStore(Guid.NewGuid(), null, null); engineeringModel.Iteration.Add(iteration); engineeringModel.CommonFileStore.Add(commonFileStore); - + var context = TransactionContextResolver.ResolveContext(commonFileStore); var transaction = new ThingTransaction(context); @@ -286,13 +287,13 @@ public void Verify_that_OperationContainerFileVerification_throws_no_exception_w var file = new CDP4Common.EngineeringModelData.File(Guid.NewGuid(), null, null); var fileRevision = new CDP4Common.EngineeringModelData.FileRevision(Guid.NewGuid(), null, null); fileRevision.ContentHash = "1B686ADFA2CAE870A96E5885087337C032781BE6"; - + transaction.Create(file, commonFileStoreClone); transaction.Create(fileRevision, file); var operationContainer = transaction.FinalizeTransaction(); - var files = new List {this.filePath}; + var files = new List { this.filePath }; var testDal = new TestDal(this.credentials); @@ -300,10 +301,13 @@ public void Verify_that_OperationContainerFileVerification_throws_no_exception_w } } - [CDPVersion("1.1.0")] + [CDPVersion("1.1.0")] internal class TestDal : Dal { - public override bool IsReadOnly { get { return false; } } + public override bool IsReadOnly + { + get { return false; } + } public TestDal(Credentials credentials) : base() @@ -410,7 +414,7 @@ public override IEnumerable Update(T thing) { throw new System.NotImplementedException(); } - + public override IEnumerable Delete(T thing) { throw new System.NotImplementedException(); @@ -447,10 +451,11 @@ public override Task> CherryPick(Guid engineeringModelId, Gui } } - [DalExportAttribute("decorateddal","a decorated dal","1.1.0",DalType.Web)] + [DalExportAttribute("decorateddal", "a decorated dal", "1.1.0", DalType.Web)] internal class DecoratedDal : Dal { public override bool IsReadOnly { get; } + public override Task> Write(IEnumerable operationContainer, IEnumerable files = null) { throw new NotImplementedException(); @@ -566,4 +571,4 @@ public override Task> CherryPick(Guid engineeringModelId, Gui throw new NotSupportedException(); } } -} \ No newline at end of file +} diff --git a/CDP4Dal.Tests/Operations/OperationContainerTestFixture.cs b/CDP4Dal.Tests/Operations/OperationContainerTestFixture.cs index a24abc35e..8db7f0950 100644 --- a/CDP4Dal.Tests/Operations/OperationContainerTestFixture.cs +++ b/CDP4Dal.Tests/Operations/OperationContainerTestFixture.cs @@ -10,17 +10,17 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests { @@ -28,10 +28,14 @@ namespace CDP4Dal.Tests using System.Linq; using CDP4Common.CommonData; - using CDP4Common.DTO; + using CDP4Common.DTO; + using CDP4Dal.Operations; + + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; - + [TestFixture] public class OperationContainerTestFixture { @@ -42,7 +46,7 @@ public class OperationContainerTestFixture [SetUp] public void SetUp() { - this.siteDirectoryContext = "/SiteDirectory/47363f0d-eb6d-4a58-95f5-fa7854995650"; + this.siteDirectoryContext = "/SiteDirectory/47363f0d-eb6d-4a58-95f5-fa7854995650"; this.iterationContext = "/EngineeringModel/5e5dc7f8-833d-4331-b421-eb2c64fcf64b/iteration/b58ea73d-350d-4520-b9d9-a52c75ac2b5d"; } @@ -98,9 +102,9 @@ public void VerifyExecutionOfOperationAddAndRemove() var elementDefinition = new ElementDefinition(Guid.NewGuid(), 0); elementDefinition.PartialRoutes.Add("iteration/b58ea73d-350d-4520-b9d9-a52c75ac2b5d"); elementDefinition.PartialRoutes.Add("EngineeringModel/5e5dc7f8-833d-4331-b421-eb2c64fcf64b"); - + var clone = elementDefinition.DeepClone(); - var operation = new Operation(elementDefinition, clone, OperationKind.Update); + var operation = new Operation(elementDefinition, clone, OperationKind.Update); var operationContainer = new OperationContainer(this.iterationContext); diff --git a/CDP4Dal.Tests/Operations/OperationTestFixture.cs b/CDP4Dal.Tests/Operations/OperationTestFixture.cs index f0e46dd64..5048f43bb 100644 --- a/CDP4Dal.Tests/Operations/OperationTestFixture.cs +++ b/CDP4Dal.Tests/Operations/OperationTestFixture.cs @@ -10,12 +10,12 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -28,6 +28,8 @@ namespace CDP4Dal.Tests using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; [TestFixture] diff --git a/CDP4Dal.Tests/Operations/PostOperationTestFixture.cs b/CDP4Dal.Tests/Operations/PostOperationTestFixture.cs index 6da8350cb..235d9ce5a 100644 --- a/CDP4Dal.Tests/Operations/PostOperationTestFixture.cs +++ b/CDP4Dal.Tests/Operations/PostOperationTestFixture.cs @@ -10,26 +10,28 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // -------------------------------------------------------------------------------------------------------------------- -using CDP4Common; - namespace CDP4Dal.Tests { using System.Collections.Generic; + + using CDP4Common; using CDP4Common.Dto; using CDP4Common.DTO; - using CDP4Dal.Operations; + + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; [TestFixture] @@ -48,13 +50,5 @@ public void VerifyThatConstructorSetsLists() internal class TestPostOperation : PostOperation { - public override List Delete { get; set; } - public override List Create { get; set; } - public override List Update { get; set; } - public override List Copy { get; set; } - public override void ConstructFromOperation(Operation operation) - { - throw new System.NotImplementedException(); - } } } diff --git a/CDP4Dal.Tests/Operations/ThingTransactionTestFixture.cs b/CDP4Dal.Tests/Operations/ThingTransactionTestFixture.cs index 4ed2d35c7..31ae676cf 100644 --- a/CDP4Dal.Tests/Operations/ThingTransactionTestFixture.cs +++ b/CDP4Dal.Tests/Operations/ThingTransactionTestFixture.cs @@ -10,17 +10,17 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests { @@ -31,12 +31,14 @@ namespace CDP4Dal.Tests using System.Text; using CDP4Common.CommonData; - using CDP4Common.EngineeringModelData; + using CDP4Common.EngineeringModelData; using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - + using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; /// @@ -65,7 +67,7 @@ public void Setup() iterationSetup.IterationIid = this.iteration.Iid; this.engineeringModel.Iteration.Add(this.iteration); - + this.cache.TryAdd(new CacheKey(this.siteDirectory.Iid, null), new Lazy(() => this.siteDirectory)); this.cache.TryAdd(new CacheKey(this.engineeringModel.Iid, null), new Lazy(() => this.engineeringModel)); this.cache.TryAdd(new CacheKey(this.iteration.Iid, null), new Lazy(() => this.iteration)); @@ -95,7 +97,7 @@ public void VerifyThatCanOnlyUseThingTransactionOnOneTopContainer() var person = new Person(Guid.NewGuid(), this.cache, this.uri) { Container = this.siteDirectory }; var transaction = new ThingTransaction(transactionContext, person); - + var duplicateSiteDirectory = new SiteDirectory(this.siteDirectory.Iid, this.cache, this.uri); var anotherPerson = new Person(Guid.NewGuid(), this.cache, this.uri) { Container = duplicateSiteDirectory }; transaction.CreateOrUpdate(anotherPerson); @@ -109,7 +111,7 @@ public void VerifyThatCanOnlyUseThingTransactionOnOneTopContainer() [Test] public void VerifyThatCreateThingWorks() { - var person = new Person(Guid.NewGuid(), this.cache, this.uri) {Container = this.siteDirectory}; + var person = new Person(Guid.NewGuid(), this.cache, this.uri) { Container = this.siteDirectory }; this.cache.TryAdd(new CacheKey(person.Iid, null), new Lazy(() => person)); var clonePerson = person.Clone(false); @@ -131,6 +133,7 @@ public void VerifyThatCreateThingWorksWithAbstractContainer() { Container = this.siteDirectory }; + this.cache.TryAdd(new CacheKey(siteRdl.Iid, null), new Lazy(() => siteRdl)); var cloneRdl = siteRdl.Clone(false); @@ -152,7 +155,7 @@ public void VerifyThatCreateModelDoesNotWorks() var newModel = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri); var transactionContext = TransactionContextResolver.ResolveContext(this.siteDirectory); - + Assert.Throws(() => new ThingTransaction(transactionContext, newModel)); } @@ -162,7 +165,7 @@ public void VerifyThatCreateSiteDirDoesNotWorks() var newSiteDirectory = new SiteDirectory(Guid.NewGuid(), this.cache, this.uri); var transactionContext = TransactionContextResolver.ResolveContext(this.siteDirectory); - + Assert.Throws(() => new ThingTransaction(transactionContext, newSiteDirectory)); } @@ -195,7 +198,7 @@ public void VerifyThatUpdateThingWorks() { var phone = new TelephoneNumber(Guid.NewGuid(), this.cache, this.uri); this.cache.TryAdd(new CacheKey(phone.Iid, null), new Lazy(() => phone)); - + var clone = phone.Clone(false); var transactionContext = TransactionContextResolver.ResolveContext(this.siteDirectory); @@ -208,9 +211,9 @@ public void VerifyThatUpdateThingWorks() [Test] public void VerifyThatUpdateThingThrowsExceptionUponUpdatingExistingCloneWithAnotherClone() { - var phone = new TelephoneNumber(Guid.NewGuid(), this.cache, this.uri); + var phone = new TelephoneNumber(Guid.NewGuid(), this.cache, this.uri); this.cache.TryAdd(new CacheKey(phone.Iid, null), new Lazy(() => phone)); - + var clone1 = phone.Clone(false); var clone2 = phone.Clone(false); @@ -246,10 +249,9 @@ public void VerifyThatDeleteThingAlreadyDeletedWorks() [Test] public void VerifyThatUpdateContainerWorks() { - var iterationClone = this.iteration.Clone(false); var option1 = new Option(Guid.NewGuid(), this.cache, this.uri); - + var transactionContext = TransactionContextResolver.ResolveContext(this.iteration); var transaction = new ThingTransaction(transactionContext, iterationClone); transaction.CreateOrUpdate(iterationClone); @@ -272,7 +274,7 @@ public void VerifyThatUpdateContainerWorks() Assert.That(0, Is.EqualTo(this.iteration.Option.Count)); Assert.That(2, Is.EqualTo(clone.Option.Count)); } - + /// /// Create a containment tree under site directory and update /// @@ -328,6 +330,7 @@ public void FunctionalTestCase1() emailTrans.Create(email); emailTrans.FinalizeSubTransaction(email, person1_1); + // end add email, verify that email is added to person1_1, (the clone of person1) Assert.That(2, Is.EqualTo(person1_1Tr.AddedThing.Count())); @@ -339,6 +342,7 @@ public void FunctionalTestCase1() var phone_1Trans = new ThingTransaction(phone_1, person1_1Tr, person1_1); phone_1Trans.CreateOrUpdate(phone_1); phone_1Trans.FinalizeSubTransaction(phone_1, person1_1); + // end update phone // verify that the new reference is used @@ -577,7 +581,7 @@ public void VerifyThatCreateDeepWorks() enumValue.Definition.Add(enumValueDef); enumPt.ValueDefinition.Add(enumValue); - + var transactionContext = TransactionContextResolver.ResolveContext(this.siteDirectory); var transaction = new ThingTransaction(transactionContext); transaction.CreateDeep(enumPt); @@ -827,6 +831,7 @@ public void VerifyThatCascadeDeleteWorksOnAddedThing() transaction.Delete(person.Clone(false)); var operationContainer = transaction.FinalizeTransaction(); + // Update sitedir Assert.That(1, Is.EqualTo(operationContainer.Operations.Count())); } @@ -852,8 +857,8 @@ public void VerifyThatDryCopyWorks() var elementDefinitionClone = elementDefinition.Clone(false); var targetIterationClone = targetIteration.Clone(false); - - var transactionContext = TransactionContextResolver.ResolveContext(targetIteration); + + var transactionContext = TransactionContextResolver.ResolveContext(targetIteration); var transaction = new ThingTransaction(transactionContext); transaction.Copy(elementDefinitionClone, targetIterationClone, OperationKind.CopyDefaultValuesChangeOwner); @@ -886,7 +891,7 @@ public void VerifyThatCtrlCopyWorks() var elementDefinitionClone = elementDefinition.Clone(false); var targetIterationClone = targetIteration.Clone(false); - + var transactionContext = TransactionContextResolver.ResolveContext(targetIteration); var transaction = new ThingTransaction(transactionContext); transaction.Copy(elementDefinitionClone, targetIterationClone, OperationKind.CopyKeepValuesChangeOwner); @@ -994,7 +999,7 @@ public void VerifyThatWhenCopyOperationIsInvokedWithNonCopyOperationExceptionIsT Assert.Throws(() => transaction.Copy(elementDefinitionClone, targetIterationClone, OperationKind.Create)); } - [Test] + [Test] public void VerifyThatCopyThrowsExcpetionCloneThatIsToBeCopiedIsNull() { var sourceModel = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri); @@ -1019,7 +1024,7 @@ public void VerifyThatCopyThrowsExcpetionCloneThatIsToBeCopiedIsNull() Assert.Throws(() => transaction.Copy(null, OperationKind.Copy)); } - [Test] + [Test] public void VerifyThatCopyThrowsExceptionWhenDestinationIsNull() { var sourceModel = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri); @@ -1050,9 +1055,9 @@ public void VerifyThatGetLastCloneCreatedThrowsExceptionWhenThingIsNullOrGuidIsE { var model = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri); var iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri); - + model.Iteration.Add(iteration); - + var transactionContext = TransactionContextResolver.ResolveContext(iteration); var transaction = new ThingTransaction(transactionContext); @@ -1066,9 +1071,9 @@ public void VerifyThatGetLastCloneCreatedThrowsExceptionWhenThingIsNullOrGuidIsE [Test] public void VerifyThatArgumentNullExceptionIsThrownWhenContextIsNull() { - Assert.Throws(() => new ThingTransaction(null)); + Assert.Throws(() => new ThingTransaction(null)); } - + [Test] public void VerifyThatArgumentNullExceptionIsThrownWhenCloneIsNull() { @@ -1084,7 +1089,7 @@ public void VerifyThatArgumentNullExceptionIsThrownWhenCloneIsNull() var iterationClone = iteration.Clone(false); var elementDefinitionClone = elementDefinition.Clone(false); - Assert.Throws(() => new ThingTransaction(null, null, iterationClone)); + Assert.Throws(() => new ThingTransaction(null, null, iterationClone)); } } } diff --git a/CDP4Dal.Tests/SessionTestFixture.cs b/CDP4Dal.Tests/SessionTestFixture.cs index fbce86254..3bd36e4a8 100644 --- a/CDP4Dal.Tests/SessionTestFixture.cs +++ b/CDP4Dal.Tests/SessionTestFixture.cs @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Tests { @@ -37,12 +37,12 @@ namespace CDP4Dal.Tests using CDP4Common.Types; using CDP4Dal.Composition; - using CDP4Dal.Operations; using CDP4Dal.DAL; using CDP4Dal.Events; using CDP4Dal.Exceptions; + using CDP4Dal.Operations; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Tasks; using Moq; @@ -130,10 +130,7 @@ public void TearDown() public async Task VerifythatOpenCallAssemblerSynchronizeWithDtos() { var eventReceived = false; - this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => - { - eventReceived = true; - }); + this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => { eventReceived = true; }); await this.session.Open(); @@ -178,10 +175,7 @@ public void VerifyThatOpenCallMightBeCancelled() })); } - Assert.DoesNotThrowAsync(async () => - { - await Task.WhenAll(tasks.ToArray()); - }); + Assert.DoesNotThrowAsync(async () => { await Task.WhenAll(tasks.ToArray()); }); } [Test] @@ -196,18 +190,18 @@ public async Task VerifyThatWriteWithEmptyResponseSendsMessages() this.messageBus.Listen() .Subscribe(x => - { - if (x.Status == SessionStatus.BeginUpdate) { - beginUpdateReceived = true; - return; - } + if (x.Status == SessionStatus.BeginUpdate) + { + beginUpdateReceived = true; + return; + } - if (x.Status == SessionStatus.EndUpdate) - { - endUpdateReceived = true; - } - }); + if (x.Status == SessionStatus.EndUpdate) + { + endUpdateReceived = true; + } + }); var context = $"/SiteDirectory/{Guid.NewGuid()}"; @@ -234,10 +228,7 @@ public async Task VerifythatRefreshSynchronizeTheAssembler() await this.session.Open(); - this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => - { - eventReceived = true; - }); + this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => { eventReceived = true; }); // refresh shouldnt do anything await this.session.Refresh(); @@ -267,10 +258,7 @@ public async Task VerifythatReloadSynchronizeTheAssembler() await this.session.Open(); - this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => - { - eventReceived = true; - }); + this.messageBus.Listen(typeof(TelephoneNumber)).Subscribe(x => { eventReceived = true; }); await this.session.Reload(); @@ -467,14 +455,15 @@ public async Task VerifyThatSiteRdlRequiredByModelRdlCannotBeClosed() var participant = new CDP4Common.DTO.Participant(Guid.NewGuid(), 0) { Person = this.person.Iid }; modelsetup.Participant.Add(participant.Iid); - var modelPoco = new CDP4Common.EngineeringModelData.EngineeringModel(model.Iid, null, null){EngineeringModelSetup = modelsetuppoco}; + var modelPoco = new CDP4Common.EngineeringModelData.EngineeringModel(model.Iid, null, null) { EngineeringModelSetup = modelsetuppoco }; var iterationPoco = new CDP4Common.EngineeringModelData.Iteration(iteration.Iid, null, null); modelPoco.Iteration.Add(iterationPoco); var readTaskCompletionSource = new TaskCompletionSource>(); readTaskCompletionSource.SetResult(readReturn); + this.mockedDal.Setup( - x => x.Read(It.IsAny(), It.IsAny(), null)) + x => x.Read(It.IsAny(), It.IsAny(), null)) .Returns(readTaskCompletionSource.Task); var thingsToAdd = new List() { siteDirDto, requiredRdlDto, rdlDto, this.person, participant, modelsetup }; @@ -568,6 +557,7 @@ public async Task VerifyThatReadRdlWorks() { var siteDir = new CDP4Common.SiteDirectoryData.SiteDirectory(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; + this.session.Assembler.Cache.TryAdd(new CacheKey(siteDir.Iid, null), new Lazy(() => siteDir)); @@ -599,7 +589,7 @@ public async Task VerifyThatReadRdlWorks() public async Task VerifyThatReadIterationWorks() { var siteDir = new CDP4Common.SiteDirectoryData.SiteDirectory(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); - var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) {ShortName = "John"}; + var JohnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; var modelSetup = new CDP4Common.SiteDirectoryData.EngineeringModelSetup(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); var iterationSetup = new CDP4Common.SiteDirectoryData.IterationSetup(Guid.NewGuid(), this.session.Assembler.Cache, this.uri) { FrozenOn = DateTime.Now, IterationIid = Guid.NewGuid() }; var mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), this.session.Assembler.Cache, this.uri); @@ -738,10 +728,7 @@ public async Task VerifyThatWriteWorksWithEventHandler() var johnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; this.session.GetType().GetProperty("ActivePerson")?.SetValue(this.session, johnDoe, null); - this.session.BeforeWrite += (o, args) => - { - args.Cancelled = false; - }; + this.session.BeforeWrite += (o, args) => { args.Cancelled = false; }; await this.session.Write(new OperationContainer(context)); @@ -755,10 +742,7 @@ public void VerifyThatCancelWriteWorks() var johnDoe = new CDP4Common.SiteDirectoryData.Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; this.session.GetType().GetProperty("ActivePerson")?.SetValue(this.session, johnDoe, null); - this.session.BeforeWrite += (o, args) => - { - args.Cancelled = true; - }; + this.session.BeforeWrite += (o, args) => { args.Cancelled = true; }; Assert.ThrowsAsync(async () => await this.session.Write(new OperationContainer(context))); @@ -784,11 +768,11 @@ public async Task VerifyCanCherryPick() categoriesId.Add(Guid.NewGuid()); var elementDefinitionId = Guid.NewGuid(); - cherryPickedThings.Add(new Iteration(){Iid = engineeringModelId, Element = new List{elementDefinitionId}}); - cherryPickedThings.Add(new ElementDefinition(){Iid = elementDefinitionId, Category = new List { categoriesId[0] }}); + cherryPickedThings.Add(new Iteration() { Iid = engineeringModelId, Element = new List { elementDefinitionId } }); + cherryPickedThings.Add(new ElementDefinition() { Iid = elementDefinitionId, Category = new List { categoriesId[0] } }); readThings = (await this.session.CherryPick(engineeringModelId, iterationId, classKinds, categoriesId)).ToList(); - + Assert.Multiple(() => { Assert.That(readThings, Is.Not.Empty); @@ -893,7 +877,7 @@ public async Task VerifyWritePossibleLongRunningTask() this.mockedDal.Setup(x => x.Write(It.IsAny(), It.IsAny(), It.IsAny>())) .ReturnsAsync(new LongRunningTaskResult(new CometTask() { Id = Guid.Empty })); - + var cometTask = await this.session.Write(new OperationContainer(context), 1); Assert.Multiple(() => @@ -922,8 +906,9 @@ public async Task VerifyWritePossibleLongRunningTask() this.mockedDal.Setup(x => x.Write(It.IsAny(), It.IsAny(), It.IsAny>())) .ThrowsAsync(new DalReadException()); - Assert.That(() =>this.session.Write(new OperationContainer(context), 1), Throws.Exception.TypeOf()); + Assert.That(() => this.session.Write(new OperationContainer(context), 1), Throws.Exception.TypeOf()); } + private void AssignActivePerson() { var johnDoe = new Person(this.person.Iid, this.session.Assembler.Cache, this.uri) { ShortName = "John" }; @@ -934,16 +919,30 @@ private void AssignActivePerson() [DalExport("test dal", "test dal description", "1.1.0", DalType.Web)] internal class TestDal : IDal { - public Version SupportedVersion { get {return new Version(1, 0, 0);} } - public Version DalVersion { get {return new Version("1.1.0");} } - public IMetaDataProvider MetaDataProvider { get {return new MetaDataProvider();} } + public Version SupportedVersion + { + get { return new Version(1, 0, 0); } + } + + public Version DalVersion + { + get { return new Version("1.1.0"); } + } + + public IMetaDataProvider MetaDataProvider + { + get { return new MetaDataProvider(); } + } /// /// Gets or sets the that uses this /// public ISession Session { get; set; } - public bool IsReadOnly { get { return false; } } + public bool IsReadOnly + { + get { return false; } + } /// /// Write all the s from all the s asynchronously. @@ -1184,4 +1183,4 @@ public Task> CherryPick(Guid engineeringModelId, Guid iterati throw new NotImplementedException(); } } -} \ No newline at end of file +} diff --git a/CDP4Dal/Assembler.cs b/CDP4Dal/Assembler.cs index c96136dca..5b855584d 100644 --- a/CDP4Dal/Assembler.cs +++ b/CDP4Dal/Assembler.cs @@ -143,9 +143,7 @@ public async Task Synchronize(IEnumerable dtoThings, bool logger.Info("Start Synchronization of {0}", this.IDalUri); var existentGuid = - this.Cache.Select( - x => new Tuple(x.Value.Value.CacheKey, x.Value.Value.RevisionNumber)) - .ToList(); + new Dictionary(this.Cache.ToDictionary(x => x.Value.Value.CacheKey, y => y.Value.Value.RevisionNumber)); this.CheckPartitionDependentContainmentContainerIds(dtoThings); @@ -224,17 +222,14 @@ public async Task Synchronize(IEnumerable dtoThings, bool if (succeed) { var thingObject = updatedLazyThing.Value; - var cacheId = new CacheKey(dtoThing.Iid, dtoThing.IterationContainerId); - - if (!existentGuid.Select(x => x.Item1).Contains(cacheId)) + + if (!existentGuid.TryGetValue(cacheKey, out var cacheThingRevisionNumber)) { this.messageBus.SendObjectChangeEvent(thingObject, EventKind.Added); messageCounter++; } else { - var cacheThingRevisionNumber = existentGuid.Single(x => x.Item1.Equals(cacheId)).Item2; - if (dtoThing.RevisionNumber > cacheThingRevisionNumber) { // send event if revision number has increased from the old cached version @@ -243,7 +238,7 @@ public async Task Synchronize(IEnumerable dtoThings, bool } else if (dtoThing.RevisionNumber < cacheThingRevisionNumber) { - if (this.Cache.TryGetValue(cacheId, out var cacheThing)) + if (this.Cache.TryGetValue(cacheKey, out var cacheThing)) { // send event if revision number is lower. That means that the original cached item was changed (revision was added!) ICDPMessageBus.Current.SendObjectChangeEvent(cacheThing.Value, EventKind.Updated); this.messageBus.SendObjectChangeEvent(cacheThing.Value, EventKind.Updated); diff --git a/CDP4Dal/CDP4Dal.csproj b/CDP4Dal/CDP4Dal.csproj index cc693e52b..1b78dc814 100644 --- a/CDP4Dal/CDP4Dal.csproj +++ b/CDP4Dal/CDP4Dal.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4Dal Community Edition - 27.4.0 + 28.0.0 CDP4 Data Access Layer library, a consumer of an ECSS-E-TM-10-25 Annex C API Copyright © Starion Group S.A. Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael, Ahmed @@ -20,13 +20,13 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json README.md - + @@ -50,4 +50,4 @@ - \ No newline at end of file + diff --git a/CDP4Dal/DAL/Dal.cs b/CDP4Dal/DAL/Dal.cs index fb562484b..28c88814b 100644 --- a/CDP4Dal/DAL/Dal.cs +++ b/CDP4Dal/DAL/Dal.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of COMET-SDK Community Edition -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.DAL { @@ -36,15 +36,16 @@ namespace CDP4Dal.DAL using CDP4Common.DTO; using CDP4Common.Helpers; using CDP4Common.MetaInfo; - - using CDP4Dal.Operations; + using CDP4Dal.Composition; using CDP4Dal.Exceptions; + using CDP4Dal.Operations; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; using NLog; - + using Iteration = CDP4Common.DTO.Iteration; using Thing = CDP4Common.DTO.Thing; @@ -217,7 +218,7 @@ protected Dal() /// The /// /// an await-able that returns a array. - public abstract Task ReadFile(Thing thing, CancellationToken cancellationToken) ; + public abstract Task ReadFile(Thing thing, CancellationToken cancellationToken); /// /// Creates the specified on a data source @@ -438,7 +439,7 @@ public bool TryExtractIterationIdfromUri(Uri uri, out Guid iterationId) } catch (Exception ex) { - Logger.Warn(ex,"The Iteration identifier could not be exracted from {0}", uri); + Logger.Warn(ex, "The Iteration identifier could not be exracted from {0}", uri); iterationId = Guid.Empty; return false; @@ -543,4 +544,4 @@ protected virtual void SetCdpVersion() } } } -} \ No newline at end of file +} diff --git a/CDP4Dal/DAL/IDal.cs b/CDP4Dal/DAL/IDal.cs index 0ff6a7f3c..3e4c8dd7f 100644 --- a/CDP4Dal/DAL/IDal.cs +++ b/CDP4Dal/DAL/IDal.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.DAL { @@ -35,7 +35,8 @@ namespace CDP4Dal.DAL using CDP4Dal.Operations; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; using Thing = CDP4Common.DTO.Thing; @@ -63,7 +64,7 @@ public interface IDal /// Gets the value indicating whether this is read only /// bool IsReadOnly { get; } - + /// /// Write all the s from all the s asynchronously. /// @@ -91,7 +92,7 @@ public interface IDal /// A list of s that has been created or updated since the last Read or Write operation. /// Task> Write(OperationContainer operationContainer, IEnumerable files = null); - + /// /// Write all the s from an asynchronously for a possible long running task. /// @@ -276,7 +277,7 @@ public interface IDal /// A collection of s /// The /// A of type of read - Task> CherryPick(Guid engineeringModelId, Guid iterationId, IEnumerable classKinds, + Task> CherryPick(Guid engineeringModelId, Guid iterationId, IEnumerable classKinds, IEnumerable categoriesId, CancellationToken cancellationToken); } -} \ No newline at end of file +} diff --git a/CDP4Dal/Exceptions/InvalidOperationContainerException.cs b/CDP4Dal/Exceptions/InvalidOperationContainerException.cs index 5240da47e..3a8e2bad5 100644 --- a/CDP4Dal/Exceptions/InvalidOperationContainerException.cs +++ b/CDP4Dal/Exceptions/InvalidOperationContainerException.cs @@ -1,21 +1,21 @@ // ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexandervan Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed -// -// This file is part of COMET-SDK Community Edition -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -28,6 +28,8 @@ namespace CDP4Dal.Exceptions using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + /// /// A is thrown when an is invalid or incomplete, /// or one of the contained s is invalid or incomplete. diff --git a/CDP4Dal/Exceptions/InvalidOperationKindException.cs b/CDP4Dal/Exceptions/InvalidOperationKindException.cs index 21fc6d120..b616feee3 100644 --- a/CDP4Dal/Exceptions/InvalidOperationKindException.cs +++ b/CDP4Dal/Exceptions/InvalidOperationKindException.cs @@ -1,21 +1,21 @@ // ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexandervan Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed -// -// This file is part of COMET-SDK Community Edition -// -// The COMET-SDK Community Edition is free software; you can redistribute it and/or +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -28,9 +28,11 @@ namespace CDP4Dal.Exceptions using CDP4Dal.DAL; + using CDP4DalCommon.Protocol.Operations; + /// /// A InvalidOperationKindException is thrown whenever an contains - /// that are not supported by the implementation of an + /// that are not supported by the implementation of an /// public class InvalidOperationKindException : Exception { diff --git a/CDP4Dal/ISession.cs b/CDP4Dal/ISession.cs index 8f3014022..3139414fb 100644 --- a/CDP4Dal/ISession.cs +++ b/CDP4Dal/ISession.cs @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal { @@ -34,13 +34,13 @@ namespace CDP4Dal using CDP4Common.ExceptionHandlerService; using CDP4Common.SiteDirectoryData; - using CDP4Dal.Operations; using CDP4Dal.DAL; using CDP4Dal.Events; + using CDP4Dal.Operations; + using CDP4Dal.Permission; - using CDP4DalCommon.Tasks; - - using Permission; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; /// /// The interface encapsulates an and @@ -56,7 +56,7 @@ public interface ISession /// /// Gets the that are use to connect to the data source /// - Credentials Credentials { get; } + Credentials Credentials { get; } /// /// Gets all the s that the active person is linked with. @@ -112,7 +112,7 @@ public interface ISession /// /// Gets the name of the session which is the concatentation of the data-source uri and the active person /// - string Name { get; } + string Name { get; } /// /// Gets the list of that are currently open in the running application. @@ -122,7 +122,7 @@ public interface ISession /// /// Gets the list of s that are currently open with the active and /// - IReadOnlyDictionary > OpenIterations { get; } + IReadOnlyDictionary> OpenIterations { get; } /// /// Gets the that handles messaging for this session diff --git a/CDP4Dal/Operations/IThingTransaction.cs b/CDP4Dal/Operations/IThingTransaction.cs index 6d04848cb..5bdd8f5d0 100644 --- a/CDP4Dal/Operations/IThingTransaction.cs +++ b/CDP4Dal/Operations/IThingTransaction.cs @@ -1,35 +1,38 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Operations { using System; using System.Collections.Generic; + using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.Types; + using CDP4DalCommon.Protocol.Operations; + /// /// The interface operations /// @@ -190,4 +193,4 @@ public interface IThingTransaction /// The sub- void Merge(IThingTransaction subTransaction); } -} \ No newline at end of file +} diff --git a/CDP4Dal/Operations/LongRunningTaskResult.cs b/CDP4Dal/Operations/LongRunningTaskResult.cs index d9e6bf8d4..19c1221b6 100644 --- a/CDP4Dal/Operations/LongRunningTaskResult.cs +++ b/CDP4Dal/Operations/LongRunningTaskResult.cs @@ -2,7 +2,7 @@ // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -28,7 +28,7 @@ namespace CDP4Dal.Operations using CDP4Common.DTO; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Tasks; /// /// Handle the returned data of a possible long running task diff --git a/CDP4Dal/Operations/OperationContainer.cs b/CDP4Dal/Operations/OperationContainer.cs index 86b6b785f..71cdd1f39 100644 --- a/CDP4Dal/Operations/OperationContainer.cs +++ b/CDP4Dal/Operations/OperationContainer.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Operations { @@ -30,6 +30,8 @@ namespace CDP4Dal.Operations using CDP4Common.DTO; using CDP4Common.Helpers; + using CDP4DalCommon.Protocol.Operations; + /// /// A container for the s that need to be executed on a data source using an implementation of /// @@ -62,7 +64,7 @@ public OperationContainer(string context, int? topContainerRevNumber = null) this.Token = TokenGenerator.GenerateRandomToken(); this.Context = context; - + this.operations = new List(); this.TopContainerRevisionNumber = topContainerRevNumber; } @@ -94,10 +96,7 @@ public OperationContainer(string context, int? topContainerRevNumber = null) /// public IEnumerable Operations { - get - { - return this.operations; - } + get { return this.operations; } } /// @@ -136,7 +135,7 @@ private void ValidateContextOfOperation(Operation operation) /// public void RemoveOperation(Operation operation) { - this.operations.Remove(operation); + this.operations.Remove(operation); } } -} \ No newline at end of file +} diff --git a/CDP4Dal/Operations/OperationKindExtensions.cs b/CDP4Dal/Operations/OperationKindExtensions.cs index 8cdb67486..ce7f45cfa 100644 --- a/CDP4Dal/Operations/OperationKindExtensions.cs +++ b/CDP4Dal/Operations/OperationKindExtensions.cs @@ -1,31 +1,33 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Nathanael Smiechowski -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Operations { using CDP4Common.DTO; + using CDP4DalCommon.Protocol.Operations; + /// /// Utils class to provide OperationKind Extensions to CDP4Dal /// diff --git a/CDP4Dal/Operations/ThingTransaction.cs b/CDP4Dal/Operations/ThingTransaction.cs index bc6cb4758..9286973e3 100644 --- a/CDP4Dal/Operations/ThingTransaction.cs +++ b/CDP4Dal/Operations/ThingTransaction.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details.copy -// +// Lesser General Public License for more details. +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal.Operations { @@ -31,15 +31,17 @@ namespace CDP4Dal.Operations using System.Reflection; using CDP4Common; + using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; using CDP4Common.Extensions; using CDP4Common.Polyfills; using CDP4Common.SiteDirectoryData; - using CDP4Common.CommonData; using CDP4Common.Types; using CDP4Dal.Exceptions; + using CDP4DalCommon.Protocol.Operations; + using NLog; /// @@ -92,10 +94,10 @@ public class ThingTransaction : IThingTransaction /// public ThingTransaction(TransactionContext transactionContext, Thing clone = null) { - this.TransactionContext = - transactionContext ?? + this.TransactionContext = + transactionContext ?? throw new ArgumentNullException(nameof(transactionContext), $"The {nameof(transactionContext)} may not be null"); - + this.addedThing = new List(); this.updatedThing = new Dictionary(); this.deletedThing = new List(); @@ -137,7 +139,7 @@ public ThingTransaction(Thing clone, IThingTransaction parentTransaction, Thing { throw new ArgumentNullException(nameof(clone), $"The {nameof(clone)} may not be null."); } - + this.TransactionContext = parentTransaction.TransactionContext; this.addedThing = new List(); @@ -299,18 +301,19 @@ public void CreateOrUpdate(Thing clone) throw new ArgumentNullException(nameof(clone), $"The {nameof(clone)} may not be null"); } - if(this.UpdatedThing.Values.Any(x => x == clone) || this.AddedThing.Any(x => x == clone)) + if (this.UpdatedThing.Values.Any(x => x == clone) || this.AddedThing.Any(x => x == clone)) { return; } - if(this.UpdatedThing.Values.Any(x => x.Iid == clone.Iid) || this.AddedThing.Any(x => x.Iid == clone.Iid)) + if (this.UpdatedThing.Values.Any(x => x.Iid == clone.Iid) || this.AddedThing.Any(x => x.Iid == clone.Iid)) { return; } var UpdatedThing = this.GetUpdatedThing(clone); - if(UpdatedThing != null) + + if (UpdatedThing != null) { if (clone.Iid == Guid.Empty) { @@ -337,7 +340,7 @@ public void Delete(Thing clone, Thing containerClone = null) { throw new ArgumentNullException(nameof(clone), $"The {nameof(clone)} may not be null."); } - + if (this.DeletedThing.Any(x => x.Iid == clone.Iid)) { return; @@ -363,6 +366,7 @@ public void Delete(Thing clone, Thing containerClone = null) { // remove potential reference from the list of updated thing in the current transaction var updatedThingKey = this.UpdatedThing.Keys.SingleOrDefault(x => x.Iid == clone.Iid); + if (updatedThingKey != null) { this.updatedThing.Remove(updatedThingKey); @@ -375,6 +379,7 @@ public void Delete(Thing clone, Thing containerClone = null) { // remove from the list of added thing var thingInAddedList = this.AddedThing.SingleOrDefault(x => x.Iid == clone.Iid); + if (thingInAddedList != null) { this.addedThing.Remove(thingInAddedList); @@ -434,7 +439,7 @@ public void Copy(Thing clone, OperationKind operationKind) { throw new ArgumentException("The copy operation may only be performed with Copy or CopyDefaultValuesChangeOwner or CopyKeepValues or CopyKeepValuesChangeOwner", nameof(operationKind)); } - + var original = this.GetUpdatedThing(clone); // setting a new iid for the copy @@ -445,7 +450,7 @@ public void Copy(Thing clone, OperationKind operationKind) { return; } - + // setting a new iid for the copy clone.Iid = Guid.NewGuid(); this.copiedThing.Add(originalCopyPair, operationKind); @@ -469,13 +474,14 @@ public Thing GetClone(Thing thing) } var clone = this.UpdatedThing.Values.SingleOrDefault(x => x.Iid == thing.Iid); + if (clone != null) { return clone; } clone = this.AddedThing.SingleOrDefault(x => x.Iid == thing.Iid); - + return clone; } @@ -498,6 +504,7 @@ public Thing GetLastCloneCreated(Thing thing) var allAddedThing = this.GetAllAddedThings().ToList(); var clone = allAddedThing.SingleOrDefault(x => x.Iid == thing.Iid); + if (clone != null) { return clone; @@ -505,7 +512,7 @@ public Thing GetLastCloneCreated(Thing thing) var allUpdatedThing = this.GetAllUpdatedThings().ToList(); clone = allUpdatedThing.SingleOrDefault(x => x.Iid == thing.Iid); - + return clone; } @@ -549,8 +556,8 @@ public void FinalizeSubTransaction(Thing clone, Thing containerclone, Thing next foreach ( var addedThing in - this.AddedThing.Where( - x => x != this.AssociatedClone && x.GetContainerInformation().Item1 == cloneTypeToUpdate)) + this.AddedThing.Where( + x => x != this.AssociatedClone && x.GetContainerInformation().Item1 == cloneTypeToUpdate)) { if (!addedThing.IsContainedBy(rootClone.Iid)) { @@ -560,6 +567,7 @@ var addedThing in // the clone should have been added var containerOfAddedThing = this.GetClone(addedThing.Container); + if (containerOfAddedThing == null) { throw new TransactionException("could not find the corresponding clone for the container of the added thing added outside the chain of transaction."); @@ -570,8 +578,8 @@ var addedThing in foreach ( var updatedThing in - this.UpdatedThing.Values.Where( - x => x != this.AssociatedClone && x.GetContainerInformation().Item1 == cloneTypeToUpdate)) + this.UpdatedThing.Values.Where( + x => x != this.AssociatedClone && x.GetContainerInformation().Item1 == cloneTypeToUpdate)) { if (!updatedThing.IsContainedBy(rootClone.Iid)) { @@ -581,6 +589,7 @@ var updatedThing in // the clone should have been added var containerOfUpdatedThing = this.GetClone(updatedThing.Container); + if (containerOfUpdatedThing == null) { throw new TransactionException( @@ -605,7 +614,7 @@ public OperationContainer FinalizeTransaction() } this.FilterOperationCausedByDelete(); - + var context = this.TransactionContext.ContextRoute(); var operationContainer = new OperationContainer(context, this.GetTopContainerRevisionNumber()); @@ -629,7 +638,7 @@ public string[] GetFiles() { if (string.IsNullOrWhiteSpace(thing.ContentHash)) { - throw new InvalidOperationException($"File {thing.LocalPath} cannot be saved because of an empty ContentHash" ); + throw new InvalidOperationException($"File {thing.LocalPath} cannot be saved because of an empty ContentHash"); } files.Add(thing.LocalPath); @@ -649,7 +658,8 @@ private Thing GetUpdatedThing(Thing clone) var allUpdatedThings = this.GetAllUpdatedThings().ToList(); var updatedThing = allUpdatedThings.SingleOrDefault(x => x.Iid == clone.Iid); - if(updatedThing != null) + + if (updatedThing != null) { if (updatedThing == clone) { @@ -662,6 +672,7 @@ private Thing GetUpdatedThing(Thing clone) // case2: the updated thing is already in the transaction as an added thing var allAddedThings = this.GetAllAddedThings().ToList(); updatedThing = allAddedThings.SingleOrDefault(x => x.Iid == clone.Iid); + if (updatedThing != null) { if (updatedThing == clone) @@ -681,6 +692,7 @@ private Thing GetUpdatedThing(Thing clone) // case3: the cache does not contain the key, its a new var lazy = clone.Cache.SingleOrDefault(x => Equals(x.Key, clone.CacheKey)).Value; + if (lazy == null) { return null; @@ -688,6 +700,7 @@ private Thing GetUpdatedThing(Thing clone) // case4: the updated thing is the original updatedThing = lazy.Value; + if (updatedThing == clone) { throw new InvalidOperationException("The transaction only accepts clones."); @@ -703,6 +716,7 @@ private Thing GetUpdatedThing(Thing clone) private IEnumerable GetAllAddedThings() { var allAddedThing = this.AddedThing.ToList(); + if (this.ParentTransaction != null) { this.PopulateAllAddedThingsList(this.ParentTransaction, allAddedThing); @@ -720,6 +734,7 @@ private void PopulateAllAddedThingsList(IThingTransaction transaction, List allAddedThing.All(y => y.Iid != x.Iid)); allAddedThing.AddRange(thingsToAdd); + if (transaction.ParentTransaction != null) { this.PopulateAllAddedThingsList(transaction.ParentTransaction, allAddedThing); @@ -733,6 +748,7 @@ private void PopulateAllAddedThingsList(IThingTransaction transaction, List GetAllUpdatedThings() { var allUpdatedThings = this.UpdatedThing.Values.ToList(); + if (this.ParentTransaction != null) { this.PopulateAllUpdatedThingsList(this.ParentTransaction, allUpdatedThings); @@ -750,6 +766,7 @@ private void PopulateAllUpdatedThingsList(IThingTransaction transaction, List allUpdatedThing.All(y => y.Iid != x.Iid)); allUpdatedThing.AddRange(thingsToAdd); + if (transaction.ParentTransaction != null) { this.PopulateAllUpdatedThingsList(transaction.ParentTransaction, allUpdatedThing); @@ -765,14 +782,15 @@ private void PopulateAllUpdatedThingsList(IThingTransaction transaction, List) }); + var findIndexMethod = containerProperty.PropertyType.GetMethod("FindIndex", new[] { typeof(Predicate) }); Predicate predicate = x => x.Iid == thing.Iid; - var index = (int)(findIndexMethod?.Invoke(containerList, new object[] { predicate })??-1); + var index = (int)(findIndexMethod?.Invoke(containerList, new object[] { predicate }) ?? -1); + if (index != -1) { // Get the indexer property, by default the indexer property name is "Item" @@ -809,6 +827,7 @@ private void UpdateOrderedItemList(Thing thing, Thing containerClone, Thing next Predicate predicate = x => x.Iid == thing.Iid; var index = (int)findIndexMethod.Invoke(containerList, new object[] { predicate }); + if (index != -1) { // Get the indexer property, by default the indexer property name is "Item" @@ -822,7 +841,7 @@ private void UpdateOrderedItemList(Thing thing, Thing containerClone, Thing next { // normal add var addMethod = orderedListProperty.PropertyType.GetMethod("Add"); - addMethod.Invoke(containerList, new object[] {thing}); + addMethod.Invoke(containerList, new object[] { thing }); } else { @@ -830,6 +849,7 @@ private void UpdateOrderedItemList(Thing thing, Thing containerClone, Thing next var indexOfMethod = orderedListProperty.PropertyType.GetMethod("IndexOf"); var index = indexOfMethod.Invoke(containerList, new object[] { nextThing }) as int?; + if (index == -1 || !index.HasValue) { throw new InvalidOperationException("The Thing before which the new item needs to be inserted does not exist."); @@ -850,14 +870,15 @@ private void UpdateOrderedItemList(Thing thing, Thing containerClone, Thing next private void RemoveThingFromContainer(Thing thing) { var containers = this.AddedThing.Concat(this.UpdatedThing.Values); - + var thingType = thing.GetType(); Thing originalThing = null; + if (thing.Cache != null && thing.Cache.ContainsKey(thing.CacheKey)) { var result = thing.Cache.TryGetValue(thing.CacheKey, out var lazyThing); - originalThing = (result)? lazyThing.Value : null; + originalThing = (result) ? lazyThing.Value : null; } // Find in all the thing in the transaction the potential container that contains the current thing @@ -877,7 +898,7 @@ private void RemoveThingFromContainer(Thing thing) var matchingPropertyInfos = containerType.GetProperties().Where(x => x.PropertyType.QueryIsGenericType() && (x.PropertyType.GetGenericTypeDefinition() == typeof(ContainerList<>) || - x.PropertyType.GetGenericTypeDefinition() == typeof(OrderedItemList<>)) && + x.PropertyType.GetGenericTypeDefinition() == typeof(OrderedItemList<>)) && x.PropertyType.GetGenericArguments().Single().QueryIsAssignableFrom(thingType)).ToList(); foreach (var propertyInfo in matchingPropertyInfos) @@ -886,6 +907,7 @@ private void RemoveThingFromContainer(Thing thing) var containerList = propertyInfo.GetValue(container) as IEnumerable; Thing thingToRemove = null; + foreach (Thing containedThing in containerList) { if (containedThing.Iid == thing.Iid) @@ -900,6 +922,7 @@ private void RemoveThingFromContainer(Thing thing) } var success = (bool)removeMethod.Invoke(containerList, new object[] { thingToRemove }); + if (success) { thingToRemove.Container = null; @@ -921,6 +944,7 @@ private void InitializeSubTransaction(ThingTransaction subTransaction, Thing con if (containerClone != null) { var currentContainertype = containerClone.GetType(); + if (!containerType.QueryIsAssignableFrom(currentContainertype)) { throw new InvalidOperationException("The specified container is not allowed as a container."); @@ -949,6 +973,7 @@ private void InitializeSubTransaction(ThingTransaction subTransaction, Thing con private void AddChainOfContainers(Thing clone) { var topOperationClone = this.GetOperationRootClone(); + if (!clone.IsContainedBy(topOperationClone.Iid)) { return; @@ -972,6 +997,7 @@ private void AddChainOfContainers(Thing clone) // add a new clone if newContainerClone is not contained by the current operation's chain of clones var containerType = transaction.AssociatedClone.GetType(); var container = clone.GetContainerOfType(containerType); + if (container == null) { return; @@ -992,6 +1018,7 @@ private Thing GetOperationRootClone() { var rootClone = this.AssociatedClone; var parent = this.ParentTransaction; + while (parent != null) { rootClone = parent.AssociatedClone ?? rootClone; @@ -1008,9 +1035,11 @@ private Thing GetOperationRootClone() private IEnumerable GetChainOfSubTransactions() { var parent = this.ParentTransaction; + while (parent != null) { yield return parent; + parent = parent.ParentTransaction; } } @@ -1027,6 +1056,7 @@ private IEnumerable GetChainOfSubTransactions() private void UpdateContainer(Thing clone, Thing containerclone, Thing nextThing = null) { var containerInformation = clone.GetContainerInformation(); + if (!containerInformation.Item1.IsInstanceOfType(containerclone)) { throw new InvalidOperationException("The containerClone does not have the right type"); @@ -1055,6 +1085,7 @@ private void UpdateContainer(Thing clone, Thing containerclone, Thing nextThing private void AddCloneToContainer(Thing clone, Thing containerclone, Thing nextThing = null) { var containerInformation = clone.GetContainerInformation(); + if (!containerInformation.Item1.IsInstanceOfType(containerclone)) { throw new InvalidOperationException("The containerClone does not have the right type"); @@ -1095,6 +1126,7 @@ public void Merge(IThingTransaction subTransaction) } var existingThing = this.AddedThing.SingleOrDefault(t => t.Iid == thing.Iid); + if (existingThing != null) { // replace the current thing with the one from the sub-transaction @@ -1112,6 +1144,7 @@ public void Merge(IThingTransaction subTransaction) if (this.UpdatedThing.ContainsKey(keyValuePair.Key)) { var parentKeyValue = this.UpdatedThing.Single(x => x.Key == keyValuePair.Key); + if (parentKeyValue.Value != keyValuePair.Value) { throw new InvalidOperationException("2 clones have been created for the same thing."); @@ -1122,6 +1155,7 @@ public void Merge(IThingTransaction subTransaction) // check if the key in a sub-transaction correspond to a value in the current one var existingKeyValue = this.UpdatedThing.SingleOrDefault(x => x.Value == keyValuePair.Key); + if (existingKeyValue.Key != null) { this.updatedThing[existingKeyValue.Key] = keyValuePair.Value; @@ -1249,7 +1283,7 @@ private void CreateCopyThingOperation(OperationContainer operationContainer) if (copyOperationKind.IsCopyOperation()) { operationContainer.AddOperation(new Operation(original, copy, copyOperationKind)); - } + } } } @@ -1273,7 +1307,8 @@ private int GetTopContainerRevisionNumber() things.AddRange(this.DeletedThing); things.AddRange(this.CopiedThing.Select(x => x.Key.Item2)); - var distinctTopContainer = things.Select(x => x.TopContainer).DistinctBy(t => t.Iid).ToList(); + var distinctTopContainer = things.Select(x => x.TopContainer).DistinctBy(t => t.Iid).ToList(); + if (distinctTopContainer.Count != 1) { throw new InvalidOperationException("multiple top container updates in one transaction, operation not allowed."); @@ -1290,18 +1325,21 @@ private void FilterOperationCausedByDelete() // filter out the added thing or updated thing that have been marked as deleted // filter out the contained thing of a deleted thing var markedForDeletion = this.DeletedThing.ToList(); + foreach (var thing in markedForDeletion) { var cloneType = thing.GetType(); + var containersInfo = cloneType.GetProperties().Where(x => - x.PropertyType.QueryIsGenericType() && - (x.PropertyType.GetGenericTypeDefinition() == typeof(ContainerList<>) || - x.PropertyType.GetGenericTypeDefinition() == typeof(OrderedItemList<>)) && - typeof(Thing).QueryIsAssignableFrom(x.PropertyType.GetGenericArguments().Single())).ToList(); + x.PropertyType.QueryIsGenericType() && + (x.PropertyType.GetGenericTypeDefinition() == typeof(ContainerList<>) || + x.PropertyType.GetGenericTypeDefinition() == typeof(OrderedItemList<>)) && + typeof(Thing).QueryIsAssignableFrom(x.PropertyType.GetGenericArguments().Single())).ToList(); foreach (var containerInfo in containersInfo) { var container = (IEnumerable)containerInfo.GetValue(thing); + foreach (Thing containedThing in container) { this.RemoveThingFromOperationLists(containedThing); @@ -1320,6 +1358,7 @@ private void RemoveThingFromOperationLists(Thing thingToRemove) { // remove it from the list of updated thing in the current transaction var updatedThingKey = this.UpdatedThing.Keys.SingleOrDefault(x => x.Iid == thingToRemove.Iid); + if (updatedThingKey != null) { this.updatedThing.Remove(updatedThingKey); @@ -1327,6 +1366,7 @@ private void RemoveThingFromOperationLists(Thing thingToRemove) // remove from the list of added thing var thingInAddedList = this.AddedThing.SingleOrDefault(x => x.Iid == thingToRemove.Iid); + if (thingInAddedList != null) { this.addedThing.Remove(thingInAddedList); @@ -1336,6 +1376,7 @@ private void RemoveThingFromOperationLists(Thing thingToRemove) if (!thingToRemove.IsCached()) { var thingInDeletedList = this.DeletedThing.SingleOrDefault(x => x.Iid == thingToRemove.Iid); + if (thingInDeletedList != null) { this.deletedThing.Remove(thingInDeletedList); @@ -1343,4 +1384,4 @@ private void RemoveThingFromOperationLists(Thing thingToRemove) } } } -} \ No newline at end of file +} diff --git a/CDP4Dal/Session.cs b/CDP4Dal/Session.cs index d7fec261c..5d2378bda 100644 --- a/CDP4Dal/Session.cs +++ b/CDP4Dal/Session.cs @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4Dal { @@ -48,7 +48,8 @@ namespace CDP4Dal using CDP4Dal.Operations; using CDP4Dal.Permission; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; using NLog; @@ -529,7 +530,7 @@ public async Task Read(ReferenceDataLibrary rdl) throw new InvalidOperationException("The ReferenceDataLibrary cannot be read when the ActivePerson is null; The Open method must be called prior to any of the Read methods"); } - await this.Read((Thing) rdl); + await this.Read((Thing)rdl); this.AddRdlToOpenList(rdl); } @@ -559,7 +560,7 @@ public async Task Read(IEnumerable engineeringModels) } logger.Info("Session.Read {EngineeringModel} {0}", !engineeringModels.Any() ? "*" : $"EngineeringModel/{engineeringModels.ToShortGuidArray()}"); - + // Create the token source var cancellationTokenSource = new CancellationTokenSource(); var cancellationTokenKey = Guid.NewGuid(); @@ -1265,7 +1266,7 @@ private IEnumerable GetSiteDirectoryAndActiveIterations() .Select(x => x.Value.Value) .Where(x => x is SiteDirectory - || x is Iteration && ((Iteration) x).IterationSetup.FrozenOn == null && this.OpenIterations.ContainsKey((Iteration) x) + || x is Iteration && ((Iteration)x).IterationSetup.FrozenOn == null && this.OpenIterations.ContainsKey((Iteration)x) ) .ToList(); } @@ -1332,7 +1333,7 @@ private void AddIterationToOpenList(Guid iterationId, DomainOfExpertise activeDo return; } - var activeParticipant = ((EngineeringModel) iteration.Container).EngineeringModelSetup.Participant.SingleOrDefault(p => p.Person == this.ActivePerson); + var activeParticipant = ((EngineeringModel)iteration.Container).EngineeringModelSetup.Participant.SingleOrDefault(p => p.Person == this.ActivePerson); if (activeParticipant == null) { @@ -1341,7 +1342,7 @@ private void AddIterationToOpenList(Guid iterationId, DomainOfExpertise activeDo this.openIterations.Add(iteration, new Tuple(activeDomain, activeParticipant)); - var modelRdl = ((EngineeringModel) iteration.Container).EngineeringModelSetup.RequiredRdl.Single(); + var modelRdl = ((EngineeringModel)iteration.Container).EngineeringModelSetup.RequiredRdl.Single(); this.AddRdlToOpenList(modelRdl); } diff --git a/CDP4DalCommon/CDP4DalCommon.csproj b/CDP4DalCommon/CDP4DalCommon.csproj index 65793335c..8c40d62df 100644 --- a/CDP4DalCommon/CDP4DalCommon.csproj +++ b/CDP4DalCommon/CDP4DalCommon.csproj @@ -5,7 +5,7 @@ Starion Group S.A. latest CDP4DalCommon Community Edition - 27.4.0 + 28.0.0 CDP4 Common Class Library that contains common types for any CDP4 server and the CDP4Dal Copyright © Starion Group S.A. Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime @@ -21,7 +21,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json README.md true diff --git a/CDP4Dal/Operations/Operation.cs b/CDP4DalCommon/Protocol/Operations/Operation.cs similarity index 90% rename from CDP4Dal/Operations/Operation.cs rename to CDP4DalCommon/Protocol/Operations/Operation.cs index 7adfa43f3..a7a258167 100644 --- a/CDP4Dal/Operations/Operation.cs +++ b/CDP4DalCommon/Protocol/Operations/Operation.cs @@ -10,19 +10,19 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- -namespace CDP4Dal.Operations +namespace CDP4DalCommon.Protocol.Operations { using CDP4Common.DTO; diff --git a/CDP4Dal/Operations/OperationKind.cs b/CDP4DalCommon/Protocol/Operations/OperationKind.cs similarity index 92% rename from CDP4Dal/Operations/OperationKind.cs rename to CDP4DalCommon/Protocol/Operations/OperationKind.cs index 40150f475..a35f69463 100644 --- a/CDP4Dal/Operations/OperationKind.cs +++ b/CDP4DalCommon/Protocol/Operations/OperationKind.cs @@ -10,19 +10,19 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- -namespace CDP4Dal.Operations +namespace CDP4DalCommon.Protocol.Operations { using CDP4Common.DTO; @@ -87,4 +87,4 @@ public enum OperationKind /// CopyKeepValues } -} \ No newline at end of file +} diff --git a/CDP4Dal/Operations/PostOperation.cs b/CDP4DalCommon/Protocol/Operations/PostOperation.cs similarity index 63% rename from CDP4Dal/Operations/PostOperation.cs rename to CDP4DalCommon/Protocol/Operations/PostOperation.cs index 74acb4d1b..d73009864 100644 --- a/CDP4Dal/Operations/PostOperation.cs +++ b/CDP4DalCommon/Protocol/Operations/PostOperation.cs @@ -10,21 +10,23 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- -namespace CDP4Dal.Operations +namespace CDP4DalCommon.Protocol.Operations { + using System; using System.Collections.Generic; + using CDP4Common; using CDP4Common.Dto; using CDP4Common.DTO; @@ -32,38 +34,48 @@ namespace CDP4Dal.Operations /// /// The abstract super class from which all POST operations derive. /// - public abstract class PostOperation + public class PostOperation { - /// - /// Initializes a new instance of the class - /// - protected PostOperation() - { - this.Delete = new List(); - this.Create = new List(); - this.Update = new List(); - this.Copy = new List(); - } + private List delete = []; + private List create = []; + private List update = []; + private List copy = []; /// /// Gets or sets the collection of DTOs to delete. /// - public abstract List Delete { get; set; } + public List Delete + { + get => this.delete ?? []; + set => this.delete = value ?? []; + } /// /// Gets or sets the collection of DTOs to create. /// - public abstract List Create { get; set; } + public List Create + { + get => this.create ?? []; + set => this.create = value ?? []; + } /// /// Gets or sets the collection of DTOs to update. /// - public abstract List Update { get; set; } + public List Update + { + get => this.update ?? []; + set => this.update = value ?? []; + } /// /// Gets or sets the collection of DTOs to copy. /// - public abstract List Copy { get; set; } + public List Copy + { + get => this.copy ?? []; + set => this.copy = value ?? []; + } /// /// Populate the current with the content based on the @@ -73,6 +85,9 @@ protected PostOperation() /// The that contains all the s that need to be /// updated to the data-source /// - public abstract void ConstructFromOperation(Operation operation); + public virtual void ConstructFromOperation(Operation operation) + { + throw new NotSupportedException("Cannot construct a PostOperation based on Operation"); + } } } diff --git a/CDP4DalCommon/Tasks/CometTask.cs b/CDP4DalCommon/Protocol/Tasks/CometTask.cs similarity index 96% rename from CDP4DalCommon/Tasks/CometTask.cs rename to CDP4DalCommon/Protocol/Tasks/CometTask.cs index 9016cdee8..e25e78f49 100644 --- a/CDP4DalCommon/Tasks/CometTask.cs +++ b/CDP4DalCommon/Protocol/Tasks/CometTask.cs @@ -2,7 +2,7 @@ // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -22,7 +22,7 @@ // // ------------------------------------------------------------------------------------------------------------------------------- -namespace CDP4DalCommon.Tasks +namespace CDP4DalCommon.Protocol.Tasks { using System; diff --git a/CDP4DalCommon/Tasks/StatusKind.cs b/CDP4DalCommon/Protocol/Tasks/StatusKind.cs similarity index 69% rename from CDP4DalCommon/Tasks/StatusKind.cs rename to CDP4DalCommon/Protocol/Tasks/StatusKind.cs index 639b6ff14..fa05f1ebb 100644 --- a/CDP4DalCommon/Tasks/StatusKind.cs +++ b/CDP4DalCommon/Protocol/Tasks/StatusKind.cs @@ -2,28 +2,29 @@ // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET Webservices Community Edition. // The CDP4-COMET Web Services Community Edition is the Starion implementation of ECSS-E-TM-10-25 Annex A and Annex C. // This is an auto-generated class. Any manual changes to this file will be overwritten! // -// The CDP4-COMET Web Services Community Edition is free software; you can redistribute it and/or -// modify it under the terms of the GNU Affero General Public +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. // -// The CDP4-COMET Web Services Community Edition is distributed in the hope that it will be useful, +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- -namespace CDP4DalCommon.Tasks +namespace CDP4DalCommon.Protocol.Tasks { using System.Threading.Tasks; @@ -52,4 +53,4 @@ public enum StatusKind /// CANCELLED } -} \ No newline at end of file +} diff --git a/CDP4JsonFileDal.NetCore.Tests/CDP4JsonFileDal.NetCore.Tests.csproj b/CDP4JsonFileDal.NetCore.Tests/CDP4JsonFileDal.NetCore.Tests.csproj index 37be5d683..65118c357 100644 --- a/CDP4JsonFileDal.NetCore.Tests/CDP4JsonFileDal.NetCore.Tests.csproj +++ b/CDP4JsonFileDal.NetCore.Tests/CDP4JsonFileDal.NetCore.Tests.csproj @@ -17,12 +17,12 @@ - + - + diff --git a/CDP4JsonFileDal.NetCore.Tests/JsonFileDalTestFixture.cs b/CDP4JsonFileDal.NetCore.Tests/JsonFileDalTestFixture.cs index 441ecee16..12bcab025 100644 --- a/CDP4JsonFileDal.NetCore.Tests/JsonFileDalTestFixture.cs +++ b/CDP4JsonFileDal.NetCore.Tests/JsonFileDalTestFixture.cs @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonFileDal.NetCore.Tests { @@ -32,6 +32,7 @@ namespace CDP4JsonFileDal.NetCore.Tests using System.Threading; using System.Threading.Tasks; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.DTO; using CDP4Common.Types; @@ -41,7 +42,7 @@ namespace CDP4JsonFileDal.NetCore.Tests using CDP4Dal.Exceptions; using CDP4Dal.Operations; - using CDP4JsonFileDal; + using CDP4DalCommon.Protocol.Operations; using Moq; @@ -69,9 +70,6 @@ namespace CDP4JsonFileDal.NetCore.Tests using SampledFunctionParameterType = CDP4Common.SiteDirectoryData.SampledFunctionParameterType; using ElementDefinition = CDP4Common.EngineeringModelData.ElementDefinition; using Parameter = CDP4Common.EngineeringModelData.Parameter; - - using CDP4Common; - using OrganizationalParticipant = CDP4Common.SiteDirectoryData.OrganizationalParticipant; [TestFixture] @@ -530,7 +528,7 @@ public async Task VerifyWriteOfIncompatibleVersionFile() var domain = siteDirectory.Domain.First(); var model = new CDP4Common.EngineeringModelData.EngineeringModel(modelSetup.EngineeringModelIid, newSession.Assembler.Cache, newDal.Credentials.Uri) - { EngineeringModelSetup = modelSetup }; + { EngineeringModelSetup = modelSetup }; var iteration = new CDP4Common.EngineeringModelData.Iteration(this.iterationIid, newSession.Assembler.Cache, newDal.Credentials.Uri); @@ -590,7 +588,7 @@ public async Task VerifyWriteOfCompatibleVersionFile() var domain = siteDirectory.Domain.First(); var model = new CDP4Common.EngineeringModelData.EngineeringModel(modelSetup.EngineeringModelIid, newSession.Assembler.Cache, newDal.Credentials.Uri) - { EngineeringModelSetup = modelSetup }; + { EngineeringModelSetup = modelSetup }; var iteration = new CDP4Common.EngineeringModelData.Iteration(this.iterationIid, newSession.Assembler.Cache, newDal.Credentials.Uri); @@ -690,6 +688,7 @@ private void CreateBasicModel() iterationSetup.IterationIid = this.iterationIid; iterationSetupPoco.IterationIid = this.iterationIid; + // EngineeringModel this.model = new EngineeringModel(Guid.NewGuid(), this.cache, this.credentials.Uri); this.modelSetupId = Guid.NewGuid(); diff --git a/CDP4JsonFileDal.Tests/CDP4JsonFileDal.Tests.csproj b/CDP4JsonFileDal.Tests/CDP4JsonFileDal.Tests.csproj index 329ba1735..2654a5b64 100644 --- a/CDP4JsonFileDal.Tests/CDP4JsonFileDal.Tests.csproj +++ b/CDP4JsonFileDal.Tests/CDP4JsonFileDal.Tests.csproj @@ -22,7 +22,7 @@ - + diff --git a/CDP4JsonFileDal.Tests/JsonFileDalTestFixture.cs b/CDP4JsonFileDal.Tests/JsonFileDalTestFixture.cs index c9e23a607..fdcfb68e5 100644 --- a/CDP4JsonFileDal.Tests/JsonFileDalTestFixture.cs +++ b/CDP4JsonFileDal.Tests/JsonFileDalTestFixture.cs @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonFileDal.Tests { @@ -32,6 +32,7 @@ namespace CDP4JsonFileDal.Tests using System.Threading; using System.Threading.Tasks; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.DTO; using CDP4Common.Types; @@ -41,7 +42,7 @@ namespace CDP4JsonFileDal.Tests using CDP4Dal.Exceptions; using CDP4Dal.Operations; - using CDP4JsonFileDal; + using CDP4DalCommon.Protocol.Operations; using Moq; @@ -69,9 +70,6 @@ namespace CDP4JsonFileDal.Tests using SampledFunctionParameterType = CDP4Common.SiteDirectoryData.SampledFunctionParameterType; using ElementDefinition = CDP4Common.EngineeringModelData.ElementDefinition; using Parameter = CDP4Common.EngineeringModelData.Parameter; - - using CDP4Common; - using OrganizationalParticipant = CDP4Common.SiteDirectoryData.OrganizationalParticipant; [TestFixture] @@ -252,7 +250,7 @@ public async Task VerifyThatReadReturnsCorrectDTO() // General assertions for any kind of Thing we read Assert.That(readResult, Is.Not.Null); Assert.That(readResult.Count, Is.Not.EqualTo(1)); - + var iter1 = readResult.Single(d => d.ClassKind == ClassKind.Iteration); Assert.That(iter1.ClassKind, Is.EqualTo(iterObject.ClassKind)); Assert.That(iter1.Iid, Is.EqualTo(iterObject.Iid)); @@ -436,7 +434,7 @@ public void VerifyCtorWithVersionAndCopyright() Assert.That(this.dal.Serializer.RequestDataModelVersion.Major, Is.EqualTo(1)); Assert.That(this.dal.Serializer.RequestDataModelVersion.Minor, Is.EqualTo(0)); Assert.That(this.dal.Serializer.RequestDataModelVersion.Build, Is.EqualTo(0)); - + this.dal.UpdateExchangeFileHeader(new Person { ShortName = "admin" }); Assert.That(this.dal.FileHeader, Is.InstanceOf()); @@ -689,6 +687,7 @@ private void CreateBasicModel() iterationSetup.IterationIid = this.iterationIid; iterationSetupPoco.IterationIid = this.iterationIid; + // EngineeringModel this.model = new EngineeringModel(Guid.NewGuid(), this.cache, this.credentials.Uri); this.modelSetupId = Guid.NewGuid(); @@ -732,10 +731,10 @@ private void AddExtraThingsForExportFilteringTests() var elementDefinition2 = new ElementDefinition(Guid.NewGuid(), this.cache, this.credentials.Uri); elementDefinition2.ShortName = "ED2"; elementDefinition2.Owner = this.model.EngineeringModelSetup.ActiveDomain.First(); - + var elementDefinition3 = new ElementDefinition(Guid.NewGuid(), this.cache, this.credentials.Uri); elementDefinition3.ShortName = "ED3"; - + var elementDefinition4 = new ElementDefinition(Guid.NewGuid(), this.cache, this.credentials.Uri); elementDefinition4.ShortName = "ED4"; elementDefinition4.Owner = new DomainOfExpertise(Guid.NewGuid(), this.cache, this.credentials.Uri); //Not in file @@ -754,7 +753,7 @@ private void AddExtraThingsForExportFilteringTests() elementDefinition1.Parameter.Add(sampledFunctionParameter1); elementDefinition2.Parameter.Add(sampledFunctionParameter2); - + this.iterationPoco.Element.Add(elementDefinition1); this.iterationPoco.Element.Add(elementDefinition2); this.iterationPoco.Element.Add(elementDefinition3); @@ -770,7 +769,7 @@ private void AddExtraThingsForExportFilteringTests() parameterOverride.ValueSet.Add(new CDP4Common.EngineeringModelData.ParameterOverrideValueSet(Guid.NewGuid(), this.cache, this.credentials.Uri)); parameterOverride.ValueSet.First().ParameterValueSet = sampledFunctionParameter2.ValueSet.First(); elementUsage.ParameterOverride.Add(parameterOverride); - + elementDefinition1.ContainedElement.Add(elementUsage); var citation = new CDP4Common.CommonData.Citation(Guid.NewGuid(), this.cache, this.credentials.Uri); diff --git a/CDP4JsonFileDal/CDP4JsonFileDal.csproj b/CDP4JsonFileDal/CDP4JsonFileDal.csproj index 3b71d3674..5656ccdce 100644 --- a/CDP4JsonFileDal/CDP4JsonFileDal.csproj +++ b/CDP4JsonFileDal/CDP4JsonFileDal.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4JsonFileDal Community Edition - 27.4.0 + 28.0.0 CDP4 Json File Dal Plugin Copyright © Starion Group S.A. Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - - Remove DotNetZip and use SharpZipLib + [Refactor] Newtonsoft to System.Text.Json README.md diff --git a/CDP4JsonFileDal/JsonFileDal.cs b/CDP4JsonFileDal/JsonFileDal.cs index 6780ecad5..dc1020d14 100644 --- a/CDP4JsonFileDal/JsonFileDal.cs +++ b/CDP4JsonFileDal/JsonFileDal.cs @@ -10,12 +10,12 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -45,7 +45,8 @@ namespace CDP4JsonFileDal using CDP4Dal.Exceptions; using CDP4Dal.Operations; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; using CDP4JsonFileDal.Json; @@ -122,7 +123,7 @@ public class JsonFileDal : Dal /// public JsonFileDal() { - this.Serializer = new Cdp4JsonSerializer(this.MetaDataProvider, this.DalVersion); + this.Serializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion, false); } /// @@ -141,7 +142,7 @@ public JsonFileDal(Version dalVersion) this.DalVersion = dalVersion; } - this.Serializer = new Cdp4JsonSerializer(this.MetaDataProvider, this.DalVersion); + this.Serializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion, false); } /// @@ -160,9 +161,9 @@ public void UpdateExchangeFileHeader(Person person, string headerCopyright = nul } /// - /// Gets the + /// Gets the /// - public Cdp4JsonSerializer Serializer { get; private set; } + public Cdp4DalJsonSerializer Serializer { get; private set; } /// /// Gets the value indicating whether this is read only diff --git a/CDP4JsonSerializer.NetCore.Tests/CDP4JsonSerializer.NetCore.Tests.csproj b/CDP4JsonSerializer.NetCore.Tests/CDP4JsonSerializer.NetCore.Tests.csproj index be855025d..f7de3a262 100644 --- a/CDP4JsonSerializer.NetCore.Tests/CDP4JsonSerializer.NetCore.Tests.csproj +++ b/CDP4JsonSerializer.NetCore.Tests/CDP4JsonSerializer.NetCore.Tests.csproj @@ -16,7 +16,7 @@ - + @@ -41,6 +41,12 @@ + + Always + + + Always + Always diff --git a/CDP4JsonSerializer.NetCore.Tests/Helper/SerializerHelperTestFixture.cs b/CDP4JsonSerializer.NetCore.Tests/Helper/SerializerHelperTestFixture.cs index ab90ec5bf..94d1f2894 100644 --- a/CDP4JsonSerializer.NetCore.Tests/Helper/SerializerHelperTestFixture.cs +++ b/CDP4JsonSerializer.NetCore.Tests/Helper/SerializerHelperTestFixture.cs @@ -5,28 +5,31 @@ // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft // // This file is part of CDP4-COMET SDK Community Edition -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer.Tests.Helper { using System; using System.Collections.Generic; + using System.IO; using System.Linq; + using System.Text.Json; + using System.Text.Json.Nodes; using CDP4Common.EngineeringModelData; using CDP4Common.MetaInfo; @@ -54,17 +57,23 @@ public void VerifyThatToJsonObjectOfOrderedItemReturnsJObject() object value = null; value = System.Convert.ChangeType(123, Nullable.GetUnderlyingType(propertyInfo.PropertyType)); propertyInfo.SetValue(orderedItem, value); + var stream = new MemoryStream(); + var utf8Writer = new Utf8JsonWriter(stream); + utf8Writer.WriteOrderedItem(orderedItem); + utf8Writer.Flush(); + stream.Position = 0; + var ut8Reader = new Utf8JsonReader(stream.ToArray()); - var jObject = SerializerHelper.ToJsonObject(orderedItem); - Assert.That(jObject.Properties().Count(), Is.EqualTo(3)); + var jObject = JsonObject.Create(JsonElement.ParseValue(ref ut8Reader)); + Assert.That(jObject.AsEnumerable().Count(), Is.EqualTo(3)); - var k = jObject.Property("k"); + jObject.TryGetPropertyValue("k", out var k); Assert.That(k, Is.Not.Null); - var v = jObject.Property("v"); + jObject.TryGetPropertyValue("v", out var v); Assert.That(v, Is.Not.Null); - var m = jObject.Property("m"); + jObject.TryGetPropertyValue("m", out var m); Assert.That(m, Is.Not.Null); } @@ -75,10 +84,11 @@ public void Verify_that_ParameterValueSet_is_serialized_and_deserialized() values.Add("this is a\nnewline"); values.Add("this is another\nnewline"); - var engineeringModel = new EngineeringModel {Iid = Guid.Parse("5643764e-f880-44bf-90ae-361f6661ceae")}; - var iteration = new Iteration {Iid = Guid.Parse("f744ae63-cf36-4cc4-8d76-e83edd44f6d2")}; - var elementDefinition = new ElementDefinition {Iid = Guid.Parse("f7f173ea-a742-42a5-81f1-59da2f470f16") }; - var parameter = new Parameter {Iid = Guid.Parse("607764de-7598-4be2-9a95-34669de273e3") }; + var engineeringModel = new EngineeringModel { Iid = Guid.Parse("5643764e-f880-44bf-90ae-361f6661ceae") }; + var iteration = new Iteration { Iid = Guid.Parse("f744ae63-cf36-4cc4-8d76-e83edd44f6d2") }; + var elementDefinition = new ElementDefinition { Iid = Guid.Parse("f7f173ea-a742-42a5-81f1-59da2f470f16") }; + var parameter = new Parameter { Iid = Guid.Parse("607764de-7598-4be2-9a95-34669de273e3") }; + var parameterValueSet = new ParameterValueSet { Iid = Guid.Parse("2366c662-b857-4313-85ea-51f9bf4588b1"), Manual = new ValueArray(values) @@ -171,7 +181,7 @@ the CEND sequence.If I need to use CEND I must escape one of the "; - private static readonly string[] TestStrings = + private static readonly string[] TestStrings = { "value with trailing spaces ", "value with trailing space ", diff --git a/CDP4JsonSerializer.NetCore.Tests/JsonSerializerTestFixture.cs b/CDP4JsonSerializer.NetCore.Tests/JsonSerializerTestFixture.cs index 81f841d5b..bbd8505e9 100644 --- a/CDP4JsonSerializer.NetCore.Tests/JsonSerializerTestFixture.cs +++ b/CDP4JsonSerializer.NetCore.Tests/JsonSerializerTestFixture.cs @@ -1,26 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft // // This file is part of CDP4-COMET SDK Community Edition -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer.Tests { @@ -41,8 +41,6 @@ namespace CDP4JsonSerializer.Tests using CDP4JsonSerializer.Tests.Helper; - using Newtonsoft.Json; - using NUnit.Framework; using Dto = CDP4Common.DTO; @@ -117,7 +115,7 @@ public void VerifyThatSerializeTimeCorrectly() using var reader = new StreamReader(memoryStream); var txt = reader.ReadToEnd(); - + Assert.That(txt, Does.Not.Contain("2222-02-02T22:22:22.222222")); Assert.That(txt, Does.Contain("2222-02-02T22:22:22.222Z")); } @@ -407,7 +405,7 @@ public void VerifyThatSerializationofOperationsWorks() result.Update.Single(x => x["Iid"].ToString() == subscriptionValueset.Iid.ToString()); var valueArray = (ValueArray)subscriptionValueSetClasslessDto["Manual"]; - + Assert.That(subscriptionValueSetClasslessDto["Iid"] is Guid, Is.True); Assert.That(subscriptionValueSetClasslessDto["ClassKind"] is ClassKind, Is.True); @@ -457,7 +455,7 @@ public void VerifyThatSerializeGiveSameInput() using var reader = new StreamReader(stream); var serializerResult = reader.ReadToEnd().Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty).Replace(" ", string.Empty).Trim(); - + Assert.That(response.Length, Is.EqualTo(serializerResult.Length)); } } @@ -498,7 +496,7 @@ public void VerifyThatValueSetDeserializationIsCorrectForStringThatRepresentEsca using var reader = new StreamReader(stream); var serializerResult = reader.ReadToEnd().Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty).Replace(" ", string.Empty).Trim(); - + Assert.That(serializedParameterValueSet.Length, Is.EqualTo(serializerResult.Length)); } } @@ -611,19 +609,16 @@ private class TestPostOperation /// /// Gets or sets the collection of DTOs to delete. /// - [JsonProperty("_delete")] public List Delete { get; set; } /// /// Gets or sets the collection of DTOs to create. /// - [JsonProperty("_create")] public List Create { get; set; } /// /// Gets or sets the collection of DTOs to update. /// - [JsonProperty("_update")] public List Update { get; set; } /// diff --git a/CDP4JsonSerializer.NetCore.Tests/PostOperation/CreateDerivedQuantityKindPostMessage.json b/CDP4JsonSerializer.NetCore.Tests/PostOperation/CreateDerivedQuantityKindPostMessage.json new file mode 100644 index 000000000..11e51e3de --- /dev/null +++ b/CDP4JsonSerializer.NetCore.Tests/PostOperation/CreateDerivedQuantityKindPostMessage.json @@ -0,0 +1,62 @@ +{ + "_delete": [], + "_create": [ + { + "alias": [], + "category": [], + "classKind": "DerivedQuantityKind", + "defaultScale": "56863161-fa3a-47b8-a3cd-16465f734b27", + "definition": [], + "excludedDomain": [], + "excludedPerson": [], + "hyperLink": [], + "iid": "08c130ca-a270-408f-8069-b7e1d00659f0", + "isDeprecated": false, + "modifiedOn": "2018-08-12T14:10:55.560Z", + "name": "derivedQuantityKind", + "possibleScale": [ "56863161-fa3a-47b8-a3cd-16465f734b27" ], + "quantityDimensionSymbol": "dqk", + "quantityKindFactor": [ + { + "k": -12551680, + "v": "11aa4db6-40ef-4368-92ac-bda8af9b27a9" + }, + { + "k": 77606679, + "v": "125abfbd-f717-42c0-91da-738316159ea5" + } + ], + "revisionNumber": 0, + "shortName": "derivedQuantityKind", + "symbol": "derivedQuantityKind" + }, + { + "classKind": "QuantityKindFactor", + "excludedDomain": [], + "excludedPerson": [], + "exponent": "1", + "iid": "11aa4db6-40ef-4368-92ac-bda8af9b27a9", + "modifiedOn": "2018-08-12T14:10:45.476Z", + "quantityKind": "9513aca9-5397-48a1-8187-1683490bdb4f", + "revisionNumber": 0 + }, + { + "classKind": "QuantityKindFactor", + "excludedDomain": [], + "excludedPerson": [], + "exponent": "2", + "iid": "125abfbd-f717-42c0-91da-738316159ea5", + "modifiedOn": "2018-08-12T14:10:50.681Z", + "quantityKind": "1c53f8f4-024b-4f42-987a-439901a4bcb2", + "revisionNumber": 0 + } + ], + "_update": [ + { + "classKind": "SiteReferenceDataLibrary", + "iid": "bff9f871-3b7f-4e57-ac82-5ab499f9baf5", + "parameterType": [ "08c130ca-a270-408f-8069-b7e1d00659f0" ] + } + ], + "_copy": [] +} \ No newline at end of file diff --git a/CDP4JsonSerializer.NetCore.Tests/PostOperation/JsonSerializerPostOperationTestFixture.cs b/CDP4JsonSerializer.NetCore.Tests/PostOperation/JsonSerializerPostOperationTestFixture.cs new file mode 100644 index 000000000..9833beaf3 --- /dev/null +++ b/CDP4JsonSerializer.NetCore.Tests/PostOperation/JsonSerializerPostOperationTestFixture.cs @@ -0,0 +1,106 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace CDP4JsonSerializer.NetCore.Tests.PostOperation +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Text; + + using CDP4Common.DTO; + using CDP4Common.MetaInfo; + using CDP4Common.Types; + + using CDP4DalCommon.Protocol.Operations; + + using NUnit.Framework; + + /// + /// Suite of tests to verify that PostOperation deserialization works as expected + /// + [TestFixture] + public class JsonSerializerPostOperationTestFixture + { + private IMetaDataProvider metaDataProvider; + + private Version supportedVersion; + + [SetUp] + public void SetUp() + { + this.metaDataProvider = new MetaDataProvider(); + this.supportedVersion = new Version(1,1,0); + } + + [Test] + public void Verify_that_post_message_with_move_keys_can_be_deserialized() + { + var postMessage = System.IO.File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "PostOperation/ReOderFactorsOfDerivedQuantityKindPostMessage.json")); + var byteArray = Encoding.UTF8.GetBytes(postMessage); + var stream = new MemoryStream(byteArray); + + var cdp4JsonSerializer = new Cdp4DalJsonSerializer(this.metaDataProvider, this.supportedVersion, false); + + var cdpPostOperation = cdp4JsonSerializer.Deserialize(stream); + + Assert.That(cdpPostOperation.Create, Is.Empty); + Assert.That(cdpPostOperation.Delete, Is.Empty); + Assert.That(cdpPostOperation.Copy, Is.Empty); + + var classlessDto = cdpPostOperation.Update.First(); + + var orderedItems = classlessDto["QuantityKindFactor"] as IEnumerable; + + var orderedItem_1 = orderedItems.First(); + orderedItem_1.M = 77606679; + + var orderedItem_2 = orderedItems.Last(); + orderedItem_2.M = -12551680; + } + + [Test] + public void Verify_that_post_message_can_be_deserialized() + { + var postMessage = System.IO.File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "PostOperation/CreateDerivedQuantityKindPostMessage.json")); + var byteArray = Encoding.UTF8.GetBytes(postMessage); + var stream = new MemoryStream(byteArray); + + var cdp4JsonSerializer = new Cdp4DalJsonSerializer(this.metaDataProvider, this.supportedVersion, false); + + var cdpPostOperation = cdp4JsonSerializer.Deserialize(stream); + + Assert.That(cdpPostOperation.Delete, Is.Empty); + Assert.That(cdpPostOperation.Copy, Is.Empty); + + var derivedQuantityKind = cdpPostOperation.Create.First() as DerivedQuantityKind; + var qkf_1 = derivedQuantityKind.QuantityKindFactor.Single(x => x.K == -12551680); + + Assert.That(qkf_1.V, Is.Not.Null); + + Assert.That(qkf_1.M, Is.Null); + } + } +} \ No newline at end of file diff --git a/CDP4JsonSerializer.NetCore.Tests/PostOperation/ReOderFactorsOfDerivedQuantityKindPostMessage.json b/CDP4JsonSerializer.NetCore.Tests/PostOperation/ReOderFactorsOfDerivedQuantityKindPostMessage.json new file mode 100644 index 000000000..5b7161c8f --- /dev/null +++ b/CDP4JsonSerializer.NetCore.Tests/PostOperation/ReOderFactorsOfDerivedQuantityKindPostMessage.json @@ -0,0 +1,24 @@ +{ + "_delete": [], + "_create": [], + "_update": [ + { + "classKind": "DerivedQuantityKind", + "iid": "08c130ca-a270-408f-8069-b7e1d00659f0", + "modifiedOn": "2018-08-12T14:11:56.580Z", + "quantityKindFactor": [ + { + "k": -12551680, + "m": 77606679, + "v": "11aa4db6-40ef-4368-92ac-bda8af9b27a9" + }, + { + "k": 77606679, + "m": -12551680, + "v": "125abfbd-f717-42c0-91da-738316159ea5" + } + ] + } + ], + "_copy": [] +} \ No newline at end of file diff --git a/CDP4JsonSerializer.Tests/CDP4JsonSerializer.Tests.csproj b/CDP4JsonSerializer.Tests/CDP4JsonSerializer.Tests.csproj index 7617d3d16..098fc4c00 100644 --- a/CDP4JsonSerializer.Tests/CDP4JsonSerializer.Tests.csproj +++ b/CDP4JsonSerializer.Tests/CDP4JsonSerializer.Tests.csproj @@ -16,7 +16,7 @@ - + diff --git a/CDP4JsonSerializer.Tests/Helper/SerializerHelperTestFixture.cs b/CDP4JsonSerializer.Tests/Helper/SerializerHelperTestFixture.cs index bd785bddb..c01d93151 100644 --- a/CDP4JsonSerializer.Tests/Helper/SerializerHelperTestFixture.cs +++ b/CDP4JsonSerializer.Tests/Helper/SerializerHelperTestFixture.cs @@ -5,29 +5,32 @@ // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft // // This file is part of CDP4-COMET SDK Community Edition -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer.Tests.Helper { using System; using System.Collections.Generic; + using System.IO; using System.Linq; - + using System.Text.Json; + using System.Text.Json.Nodes; + using CDP4Common.EngineeringModelData; using CDP4Common.MetaInfo; using CDP4Common.Types; @@ -45,23 +48,30 @@ public void VerifyThatToJsonObjectOfOrderedItemReturnsJObject() { var uniqueIdentifier = Guid.NewGuid(); - var orderedItem = new OrderedItem {K = 1, V = uniqueIdentifier}; + var orderedItem = new OrderedItem { K = 1, V = uniqueIdentifier }; var propertyInfo = orderedItem.GetType().GetProperty("M"); - var value = System.Convert.ChangeType(123, Nullable.GetUnderlyingType(propertyInfo.PropertyType)); + object value = null; + value = System.Convert.ChangeType(123, Nullable.GetUnderlyingType(propertyInfo.PropertyType)); propertyInfo.SetValue(orderedItem, value); + var stream = new MemoryStream(); + var utf8Writer = new Utf8JsonWriter(stream); + utf8Writer.WriteOrderedItem(orderedItem); + utf8Writer.Flush(); + stream.Position = 0; + var ut8Reader = new Utf8JsonReader(stream.ToArray()); - var jObject = orderedItem.ToJsonObject(); - Assert.That(jObject.Properties().Count(), Is.EqualTo(3)); + var jObject = JsonObject.Create(JsonElement.ParseValue(ref ut8Reader)); + Assert.That(jObject.AsEnumerable().Count(), Is.EqualTo(3)); - var k = jObject.Property("k"); + jObject.TryGetPropertyValue("k", out var k); Assert.That(k, Is.Not.Null); - var v = jObject.Property("v"); + jObject.TryGetPropertyValue("v", out var v); Assert.That(v, Is.Not.Null); - var m = jObject.Property("m"); + jObject.TryGetPropertyValue("m", out var m); Assert.That(m, Is.Not.Null); } @@ -113,7 +123,7 @@ public void Verify_that_a_ValueArray_is_serialized_and_deserialized([ValueSource Assert.That(resultjson, Is.EqualTo(json), $"Json creation failed for string \"{input}\"."); } - + private const string JsonString = @"{""widget"": { ""debug"": ""on"", ""window"": { @@ -170,7 +180,7 @@ the CEND sequence.If I need to use CEND I must escape one of the "; - private static readonly string[] TestStrings = + private static readonly string[] TestStrings = { "value with trailing spaces ", "value with trailing space ", @@ -212,4 +222,4 @@ the CEND sequence.If I need to use CEND I must escape one of the JsonString }; } -} \ No newline at end of file +} diff --git a/CDP4JsonSerializer.Tests/JsonSerializerTestFixture.cs b/CDP4JsonSerializer.Tests/JsonSerializerTestFixture.cs index 146a70369..0a5013739 100644 --- a/CDP4JsonSerializer.Tests/JsonSerializerTestFixture.cs +++ b/CDP4JsonSerializer.Tests/JsonSerializerTestFixture.cs @@ -5,22 +5,22 @@ // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft // // This file is part of CDP4-COMET SDK Community Edition -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer.Tests { @@ -30,6 +30,7 @@ namespace CDP4JsonSerializer.Tests using System.Diagnostics; using System.IO; using System.Linq; + using System.Text.Json.Serialization; using CDP4Common; using CDP4Common.CommonData; @@ -41,8 +42,6 @@ namespace CDP4JsonSerializer.Tests using CDP4JsonSerializer.Tests.Helper; - using Newtonsoft.Json; - using NUnit.Framework; using Dto = CDP4Common.DTO; @@ -170,7 +169,7 @@ public void VerifyThatValueArrayAreSerializedCorrectly() var txt = reader.ReadToEnd(); // output: "manual":"[\"123\",\"abc\"]" - Assert.That(txt, Does.Contain("\"manual\":\"[\\\"123\\\",\\\"abc\\\"]\"")); + Assert.That(txt, Does.Contain("\"manual\":\"[\\\"123\\\",\\\"abc\\\"]\"")); } } } @@ -412,9 +411,10 @@ public void VerifyThatSerializationofOperationsWorks() // necessary memoryStream.Position = 0; - + var content = new StreamReader(memoryStream).ReadToEnd(); + memoryStream.Position = 0; var result = this.serializer.Deserialize(memoryStream); - + Assert.That(result.Delete.Count, Is.EqualTo(1)); Assert.That(result.Create.Count, Is.EqualTo(1)); Assert.That(result.Update.Count, Is.EqualTo(2)); @@ -617,19 +617,19 @@ private class TestPostOperation /// /// Gets or sets the collection of DTOs to delete. /// - [JsonProperty("_delete")] + [JsonPropertyName("_delete")] public List Delete { get; set; } /// /// Gets or sets the collection of DTOs to create. /// - [JsonProperty("_create")] + [JsonPropertyName("_create")] public List Create { get; set; } /// /// Gets or sets the collection of DTOs to update. /// - [JsonProperty("_update")] + [JsonPropertyName("_update")] public List Update { get; set; } /// diff --git a/CDP4JsonSerializer.Tests/PostOperation/CdpPostOperation.cs b/CDP4JsonSerializer.Tests/PostOperation/CdpPostOperation.cs deleted file mode 100644 index 607c8e50b..000000000 --- a/CDP4JsonSerializer.Tests/PostOperation/CdpPostOperation.cs +++ /dev/null @@ -1,51 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-COMET SDK Community Edition -// -// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program; if not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace CDP4JsonSerializer.Tests.Cdp4PostOperation -{ - using System.Collections.Generic; - - using CDP4Common; - using CDP4Common.DTO; - - using Newtonsoft.Json; - - /// - /// A CdpPostOperation class used for testing purposes - /// - public class CdpPostOperation - { - [JsonProperty("_delete")] - public List Delete { get; set; } - - [JsonProperty("_create")] - public List Create { get; set; } - - [JsonProperty("_update")] - public List Update { get; set; } - - [JsonProperty("_copy")] - public List Copy { get; set; } - } -} \ No newline at end of file diff --git a/CDP4JsonSerializer.Tests/PostOperation/JsonSerializerPostOperationTestFixture.cs b/CDP4JsonSerializer.Tests/PostOperation/JsonSerializerPostOperationTestFixture.cs index 8c654209f..96a623eac 100644 --- a/CDP4JsonSerializer.Tests/PostOperation/JsonSerializerPostOperationTestFixture.cs +++ b/CDP4JsonSerializer.Tests/PostOperation/JsonSerializerPostOperationTestFixture.cs @@ -34,7 +34,7 @@ namespace CDP4JsonSerializer.Tests.PostOperation using CDP4Common.MetaInfo; using CDP4Common.Types; - using CDP4JsonSerializer.Tests.Cdp4PostOperation; + using CDP4DalCommon.Protocol.Operations; using NUnit.Framework; @@ -62,9 +62,9 @@ public void Verify_that_post_message_with_move_keys_can_be_deserialized() var byteArray = Encoding.UTF8.GetBytes(postMessage); var stream = new MemoryStream(byteArray); - var cdp4JsonSerializer = new Cdp4JsonSerializer(this.metaDataProvider, this.supportedVersion); + var cdp4JsonSerializer = new Cdp4DalJsonSerializer(this.metaDataProvider, this.supportedVersion, false); - var cdpPostOperation = cdp4JsonSerializer.Deserialize(stream); + var cdpPostOperation = cdp4JsonSerializer.Deserialize(stream); Assert.That(cdpPostOperation.Create, Is.Empty); Assert.That(cdpPostOperation.Delete, Is.Empty); @@ -88,9 +88,9 @@ public void Verify_that_post_message_can_be_deserialized() var byteArray = Encoding.UTF8.GetBytes(postMessage); var stream = new MemoryStream(byteArray); - var cdp4JsonSerializer = new Cdp4JsonSerializer(this.metaDataProvider, this.supportedVersion); + var cdp4JsonSerializer = new Cdp4DalJsonSerializer(this.metaDataProvider, this.supportedVersion, false); - var cdpPostOperation = cdp4JsonSerializer.Deserialize(stream); + var cdpPostOperation = cdp4JsonSerializer.Deserialize(stream); Assert.That(cdpPostOperation.Delete, Is.Empty); Assert.That(cdpPostOperation.Copy, Is.Empty); diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs index f4815aad3..81ac2b50b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActionItemResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,151 +28,290 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ActionItemResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ActionItem FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ActionItem FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var actionItem = new CDP4Common.DTO.ActionItem(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ActionItemResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actionee"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - actionItem.Actionee = jObject["actionee"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actor"].IsNullOrEmpty()) + var actionItem = new CDP4Common.DTO.ActionItem(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("actionee"u8, out var actioneeProperty)) { - actionItem.Actor = jObject["actor"].ToObject(); + if(actioneeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale actionee property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Actionee = actioneeProperty.GetGuid(); + } } - if (!jObject["approvedBy"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - actionItem.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + actionItem.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - actionItem.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - actionItem.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + actionItem.Category.Add(element.GetGuid()); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - actionItem.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale classification property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["closeOutDate"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("closeOutDate"u8, out var closeOutDateProperty)) { - actionItem.CloseOutDate = jObject["closeOutDate"].ToObject(); + if(closeOutDateProperty.ValueKind == JsonValueKind.Null) + { + actionItem.CloseOutDate = null; + } + else + { + actionItem.CloseOutDate = closeOutDateProperty.GetDateTime(); + } } - if (!jObject["closeOutStatement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("closeOutStatement"u8, out var closeOutStatementProperty)) { - actionItem.CloseOutStatement = jObject["closeOutStatement"].ToObject(); + if(closeOutStatementProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale closeOutStatement property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.CloseOutStatement = closeOutStatementProperty.GetString(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - actionItem.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - actionItem.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - actionItem.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + actionItem.Discussion.Add(element.GetGuid()); + } } - if (!jObject["dueDate"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("dueDate"u8, out var dueDateProperty)) { - actionItem.DueDate = jObject["dueDate"].ToObject(); + if(dueDateProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale dueDate property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.DueDate = dueDateProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - actionItem.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + actionItem.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - actionItem.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + actionItem.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - actionItem.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - actionItem.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - actionItem.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - actionItem.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + actionItem.PrimaryAnnotatedThing = null; + } + else + { + actionItem.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - actionItem.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + actionItem.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - actionItem.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - actionItem.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + actionItem.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - actionItem.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - actionItem.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - actionItem.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale title property of the actionItem {id} is null", actionItem.Iid); + } + else + { + actionItem.Title = titleProperty.GetString(); + } } return actionItem; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs index c840513ae..b4e715a54 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateListResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,76 +28,115 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ActualFiniteStateListResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ActualFiniteStateList FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ActualFiniteStateList FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var actualFiniteStateList = new CDP4Common.DTO.ActualFiniteStateList(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ActualFiniteStateListResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - actualFiniteStateList.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actualState"].IsNullOrEmpty()) + var actualFiniteStateList = new CDP4Common.DTO.ActualFiniteStateList(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("actualState"u8, out var actualStateProperty) && actualStateProperty.ValueKind != JsonValueKind.Null) { - actualFiniteStateList.ActualState.AddRange(jObject["actualState"].ToObject>()); + foreach(var element in actualStateProperty.EnumerateArray()) + { + actualFiniteStateList.ActualState.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - actualFiniteStateList.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + actualFiniteStateList.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - actualFiniteStateList.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + actualFiniteStateList.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["excludeOption"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludeOption"u8, out var excludeOptionProperty) && excludeOptionProperty.ValueKind != JsonValueKind.Null) { - actualFiniteStateList.ExcludeOption.AddRange(jObject["excludeOption"].ToObject>()); + foreach(var element in excludeOptionProperty.EnumerateArray()) + { + actualFiniteStateList.ExcludeOption.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - actualFiniteStateList.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the actualFiniteStateList {id} is null", actualFiniteStateList.Iid); + } + else + { + actualFiniteStateList.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - actualFiniteStateList.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the actualFiniteStateList {id} is null", actualFiniteStateList.Iid); + } + else + { + actualFiniteStateList.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["possibleFiniteStateList"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleFiniteStateList"u8, out var possibleFiniteStateListProperty)) { - actualFiniteStateList.PossibleFiniteStateList.AddRange(jObject["possibleFiniteStateList"].ToOrderedItemCollection()); + actualFiniteStateList.PossibleFiniteStateList.AddRange(possibleFiniteStateListProperty.ToOrderedItemCollection()); } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - actualFiniteStateList.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the actualFiniteStateList {id} is null", actualFiniteStateList.Iid); + } + else + { + actualFiniteStateList.ThingPreference = thingPreferenceProperty.GetString(); + } } return actualFiniteStateList; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs index ee6f1001d..e4bfb8917 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ActualFiniteStateResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,102 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ActualFiniteStateResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ActualFiniteState FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ActualFiniteState FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var actualFiniteState = new CDP4Common.DTO.ActualFiniteState(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ActualFiniteStateResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - actualFiniteState.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var actualFiniteState = new CDP4Common.DTO.ActualFiniteState(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - actualFiniteState.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + actualFiniteState.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - actualFiniteState.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + actualFiniteState.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["kind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("kind"u8, out var kindProperty)) { - actualFiniteState.Kind = jObject["kind"].ToObject(); + if(kindProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale kind property of the actualFiniteState {id} is null", actualFiniteState.Iid); + } + else + { + actualFiniteState.Kind = ActualFiniteStateKindDeserializer.Deserialize(kindProperty); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - actualFiniteState.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the actualFiniteState {id} is null", actualFiniteState.Iid); + } + else + { + actualFiniteState.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["possibleState"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleState"u8, out var possibleStateProperty) && possibleStateProperty.ValueKind != JsonValueKind.Null) { - actualFiniteState.PossibleState.AddRange(jObject["possibleState"].ToObject>()); + foreach(var element in possibleStateProperty.EnumerateArray()) + { + actualFiniteState.PossibleState.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - actualFiniteState.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the actualFiniteState {id} is null", actualFiniteState.Iid); + } + else + { + actualFiniteState.ThingPreference = thingPreferenceProperty.GetString(); + } } return actualFiniteState; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs index c72e5fdc6..a21a60780 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/AliasResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,118 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class AliasResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Alias FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Alias FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var alias = new CDP4Common.DTO.Alias(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the AliasResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - alias.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["content"].IsNullOrEmpty()) + var alias = new CDP4Common.DTO.Alias(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - alias.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the alias {id} is null", alias.Iid); + } + else + { + alias.Content = contentProperty.GetString(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - alias.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + alias.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - alias.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + alias.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isSynonym"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isSynonym"u8, out var isSynonymProperty)) { - alias.IsSynonym = jObject["isSynonym"].ToObject(); + if(isSynonymProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isSynonym property of the alias {id} is null", alias.Iid); + } + else + { + alias.IsSynonym = isSynonymProperty.GetBoolean(); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - alias.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the alias {id} is null", alias.Iid); + } + else + { + alias.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - alias.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the alias {id} is null", alias.Iid); + } + else + { + alias.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - alias.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the alias {id} is null", alias.Iid); + } + else + { + alias.ThingPreference = thingPreferenceProperty.GetString(); + } } return alias; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs index 76841ff87..a555636ae 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/AndExpressionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,61 +28,90 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class AndExpressionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.AndExpression FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.AndExpression FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var andExpression = new CDP4Common.DTO.AndExpression(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the AndExpressionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - andExpression.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var andExpression = new CDP4Common.DTO.AndExpression(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - andExpression.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + andExpression.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - andExpression.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + andExpression.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - andExpression.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the andExpression {id} is null", andExpression.Iid); + } + else + { + andExpression.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["term"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("term"u8, out var termProperty) && termProperty.ValueKind != JsonValueKind.Null) { - andExpression.Term.AddRange(jObject["term"].ToObject>()); + foreach(var element in termProperty.EnumerateArray()) + { + andExpression.Term.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - andExpression.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the andExpression {id} is null", andExpression.Iid); + } + else + { + andExpression.ThingPreference = thingPreferenceProperty.GetString(); + } } return andExpression; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs index 88600f96a..d10cf77d2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ApprovalResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,154 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ApprovalResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Approval FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Approval FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var approval = new CDP4Common.DTO.Approval(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ApprovalResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - approval.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var approval = new CDP4Common.DTO.Approval(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - approval.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the approval {id} is null", approval.Iid); + } + else + { + approval.Author = authorProperty.GetGuid(); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - approval.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale classification property of the approval {id} is null", approval.Iid); + } + else + { + approval.Classification = AnnotationApprovalKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - approval.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the approval {id} is null", approval.Iid); + } + else + { + approval.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - approval.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the approval {id} is null", approval.Iid); + } + else + { + approval.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - approval.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + approval.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - approval.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + approval.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - approval.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the approval {id} is null", approval.Iid); + } + else + { + approval.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - approval.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the approval {id} is null", approval.Iid); + } + else + { + approval.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - approval.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the approval {id} is null", approval.Iid); + } + else + { + approval.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - approval.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the approval {id} is null", approval.Iid); + } + else + { + approval.ThingPreference = thingPreferenceProperty.GetString(); + } } return approval; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs index b73fef9ef..d54336e54 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ArrayParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,116 +28,196 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ArrayParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ArrayParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ArrayParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var arrayParameterType = new CDP4Common.DTO.ArrayParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ArrayParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - arrayParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var arrayParameterType = new CDP4Common.DTO.ArrayParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + arrayParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + arrayParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["component"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("component"u8, out var componentProperty)) { - arrayParameterType.Component.AddRange(jObject["component"].ToOrderedItemCollection()); + arrayParameterType.Component.AddRange(componentProperty.ToOrderedItemCollection()); } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + arrayParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["dimension"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("dimension"u8, out var dimensionProperty)) { - arrayParameterType.Dimension.AddRange(jObject["dimension"].ToOrderedItemCollection()); + arrayParameterType.Dimension.AddRange(dimensionProperty.ToOrderedItemCollection()); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + arrayParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + arrayParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - arrayParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + arrayParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - arrayParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isFinalized"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isFinalized"u8, out var isFinalizedProperty)) { - arrayParameterType.IsFinalized = jObject["isFinalized"].ToObject(); + if(isFinalizedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isFinalized property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.IsFinalized = isFinalizedProperty.GetBoolean(); + } } - if (!jObject["isTensor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isTensor"u8, out var isTensorProperty)) { - arrayParameterType.IsTensor = jObject["isTensor"].ToObject(); + if(isTensorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isTensor property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.IsTensor = isTensorProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - arrayParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - arrayParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - arrayParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - arrayParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - arrayParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the arrayParameterType {id} is null", arrayParameterType.Iid); + } + else + { + arrayParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return arrayParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs index ab33fda49..359bc749e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryNoteResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,162 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BinaryNoteResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.BinaryNote FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.BinaryNote FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var binaryNote = new CDP4Common.DTO.BinaryNote(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the BinaryNoteResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - binaryNote.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["caption"].IsNullOrEmpty()) + var binaryNote = new CDP4Common.DTO.BinaryNote(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("caption"u8, out var captionProperty)) { - binaryNote.Caption = jObject["caption"].ToObject(); + if(captionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale caption property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.Caption = captionProperty.GetString(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - binaryNote.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + binaryNote.Category.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - binaryNote.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - binaryNote.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + binaryNote.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - binaryNote.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + binaryNote.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fileType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fileType"u8, out var fileTypeProperty)) { - binaryNote.FileType = jObject["fileType"].ToObject(); + if(fileTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale fileType property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.FileType = fileTypeProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - binaryNote.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - binaryNote.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - binaryNote.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - binaryNote.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - binaryNote.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the binaryNote {id} is null", binaryNote.Iid); + } + else + { + binaryNote.ThingPreference = thingPreferenceProperty.GetString(); + } } return binaryNote; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs index be5c2b92f..2f4a6addf 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,146 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BinaryRelationshipResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.BinaryRelationship FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.BinaryRelationship FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var binaryRelationship = new CDP4Common.DTO.BinaryRelationship(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the BinaryRelationshipResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - binaryRelationship.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var binaryRelationship = new CDP4Common.DTO.BinaryRelationship(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - binaryRelationship.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + binaryRelationship.Category.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - binaryRelationship.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + binaryRelationship.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - binaryRelationship.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + binaryRelationship.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - binaryRelationship.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - binaryRelationship.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - binaryRelationship.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValue"u8, out var parameterValueProperty) && parameterValueProperty.ValueKind != JsonValueKind.Null) { - binaryRelationship.ParameterValue.AddRange(jObject["parameterValue"].ToObject>()); + foreach(var element in parameterValueProperty.EnumerateArray()) + { + binaryRelationship.ParameterValue.Add(element.GetGuid()); + } } - if (!jObject["source"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("source"u8, out var sourceProperty)) { - binaryRelationship.Source = jObject["source"].ToObject(); + if(sourceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale source property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.Source = sourceProperty.GetGuid(); + } } - if (!jObject["target"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("target"u8, out var targetProperty)) { - binaryRelationship.Target = jObject["target"].ToObject(); + if(targetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale target property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.Target = targetProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - binaryRelationship.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the binaryRelationship {id} is null", binaryRelationship.Iid); + } + else + { + binaryRelationship.ThingPreference = thingPreferenceProperty.GetString(); + } } return binaryRelationship; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs index 9cca314ad..309c2010d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BinaryRelationshipRuleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,111 +28,202 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BinaryRelationshipRuleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.BinaryRelationshipRule FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var binaryRelationshipRule = new CDP4Common.DTO.BinaryRelationshipRule(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.BinaryRelationshipRule FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - binaryRelationshipRule.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the BinaryRelationshipRuleResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["alias"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - binaryRelationshipRule.Alias.AddRange(jObject["alias"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["definition"].IsNullOrEmpty()) + var binaryRelationshipRule = new CDP4Common.DTO.BinaryRelationshipRule(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - binaryRelationshipRule.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + binaryRelationshipRule.Alias.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - binaryRelationshipRule.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + binaryRelationshipRule.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - binaryRelationshipRule.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + binaryRelationshipRule.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["forwardRelationshipName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - binaryRelationshipRule.ForwardRelationshipName = jObject["forwardRelationshipName"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + binaryRelationshipRule.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("forwardRelationshipName"u8, out var forwardRelationshipNameProperty)) { - binaryRelationshipRule.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + if(forwardRelationshipNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale forwardRelationshipName property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.ForwardRelationshipName = forwardRelationshipNameProperty.GetString(); + } } - if (!jObject["inverseRelationshipName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - binaryRelationshipRule.InverseRelationshipName = jObject["inverseRelationshipName"].ToObject(); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + binaryRelationshipRule.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("inverseRelationshipName"u8, out var inverseRelationshipNameProperty)) { - binaryRelationshipRule.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(inverseRelationshipNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale inverseRelationshipName property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.InverseRelationshipName = inverseRelationshipNameProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - binaryRelationshipRule.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - binaryRelationshipRule.Name = jObject["name"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["relationshipCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - binaryRelationshipRule.RelationshipCategory = jObject["relationshipCategory"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relationshipCategory"u8, out var relationshipCategoryProperty)) { - binaryRelationshipRule.ShortName = jObject["shortName"].ToObject(); + if(relationshipCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale relationshipCategory property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.RelationshipCategory = relationshipCategoryProperty.GetGuid(); + } } - if (!jObject["sourceCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - binaryRelationshipRule.SourceCategory = jObject["sourceCategory"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["targetCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceCategory"u8, out var sourceCategoryProperty)) { - binaryRelationshipRule.TargetCategory = jObject["targetCategory"].ToObject(); - } + if(sourceCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale sourceCategory property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.SourceCategory = sourceCategoryProperty.GetGuid(); + } + } + + if (jsonElement.TryGetProperty("targetCategory"u8, out var targetCategoryProperty)) + { + if(targetCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale targetCategory property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.TargetCategory = targetCategoryProperty.GetGuid(); + } + } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - binaryRelationshipRule.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the binaryRelationshipRule {id} is null", binaryRelationshipRule.Iid); + } + else + { + binaryRelationshipRule.ThingPreference = thingPreferenceProperty.GetString(); + } } return binaryRelationshipRule; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs index e8798e510..982609cac 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BookResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,143 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BookResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Book FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Book FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var book = new CDP4Common.DTO.Book(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the BookResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - book.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var book = new CDP4Common.DTO.Book(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - book.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + book.Category.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - book.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the book {id} is null", book.Iid); + } + else + { + book.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - book.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + book.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - book.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + book.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - book.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the book {id} is null", book.Iid); + } + else + { + book.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - book.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the book {id} is null", book.Iid); + } + else + { + book.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - book.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the book {id} is null", book.Iid); + } + else + { + book.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["section"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("section"u8, out var sectionProperty)) { - book.Section.AddRange(jObject["section"].ToOrderedItemCollection()); + book.Section.AddRange(sectionProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - book.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the book {id} is null", book.Iid); + } + else + { + book.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - book.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the book {id} is null", book.Iid); + } + else + { + book.ThingPreference = thingPreferenceProperty.GetString(); + } } return book; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs index 23f9588e2..302db7082 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BooleanParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,162 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BooleanParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.BooleanParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.BooleanParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var booleanParameterType = new CDP4Common.DTO.BooleanParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the BooleanParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - booleanParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var booleanParameterType = new CDP4Common.DTO.BooleanParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + booleanParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + booleanParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + booleanParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + booleanParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + booleanParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - booleanParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + booleanParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - booleanParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - booleanParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - booleanParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - booleanParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - booleanParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - booleanParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the booleanParameterType {id} is null", booleanParameterType.Iid); + } + else + { + booleanParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return booleanParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs index 50d6680de..bbb3a0735 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BoundsResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,142 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BoundsResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Bounds FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Bounds FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var bounds = new CDP4Common.DTO.Bounds(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the BoundsResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - bounds.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var bounds = new CDP4Common.DTO.Bounds(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - bounds.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + bounds.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - bounds.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + bounds.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["height"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("height"u8, out var heightProperty)) { - bounds.Height = jObject["height"].ToObject(); + if(heightProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale height property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.Height = heightProperty.GetSingle(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - bounds.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - bounds.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - bounds.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["width"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("width"u8, out var widthProperty)) { - bounds.Width = jObject["width"].ToObject(); + if(widthProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale width property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.Width = widthProperty.GetSingle(); + } } - if (!jObject["x"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("x"u8, out var xProperty)) { - bounds.X = jObject["x"].ToObject(); + if(xProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale x property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.X = xProperty.GetSingle(); + } } - if (!jObject["y"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("y"u8, out var yProperty)) { - bounds.Y = jObject["y"].ToObject(); + if(yProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale y property of the bounds {id} is null", bounds.Iid); + } + else + { + bounds.Y = yProperty.GetSingle(); + } } return bounds; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs index 60c629a3c..3d8ff5028 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/BuiltInRuleVerificationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,130 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class BuiltInRuleVerificationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.BuiltInRuleVerification FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var builtInRuleVerification = new CDP4Common.DTO.BuiltInRuleVerification(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.BuiltInRuleVerification FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - builtInRuleVerification.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the BuiltInRuleVerificationResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - builtInRuleVerification.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var builtInRuleVerification = new CDP4Common.DTO.BuiltInRuleVerification(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - builtInRuleVerification.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + builtInRuleVerification.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["executedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - builtInRuleVerification.ExecutedOn = jObject["executedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + builtInRuleVerification.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isActive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("executedOn"u8, out var executedOnProperty)) { - builtInRuleVerification.IsActive = jObject["isActive"].ToObject(); + if(executedOnProperty.ValueKind == JsonValueKind.Null) + { + builtInRuleVerification.ExecutedOn = null; + } + else + { + builtInRuleVerification.ExecutedOn = executedOnProperty.GetDateTime(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isActive"u8, out var isActiveProperty)) { - builtInRuleVerification.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(isActiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isActive property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + } + else + { + builtInRuleVerification.IsActive = isActiveProperty.GetBoolean(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - builtInRuleVerification.Name = jObject["name"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + } + else + { + builtInRuleVerification.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - builtInRuleVerification.Status = jObject["status"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + } + else + { + builtInRuleVerification.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - builtInRuleVerification.ThingPreference = jObject["thingPreference"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + } + else + { + builtInRuleVerification.Status = RuleVerificationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["violation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - builtInRuleVerification.Violation.AddRange(jObject["violation"].ToObject>()); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the builtInRuleVerification {id} is null", builtInRuleVerification.Iid); + } + else + { + builtInRuleVerification.ThingPreference = thingPreferenceProperty.GetString(); + } } return builtInRuleVerification; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs index 2f6785e9d..cbbf71b32 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CategoryResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,101 +28,170 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class CategoryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Category FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Category FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var category = new CDP4Common.DTO.Category(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the CategoryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - category.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var category = new CDP4Common.DTO.Category(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - category.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + category.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - category.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + category.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - category.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + category.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - category.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + category.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - category.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + category.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isAbstract"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) { - category.IsAbstract = jObject["isAbstract"].ToObject(); + if(isAbstractProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isAbstract property of the category {id} is null", category.Iid); + } + else + { + category.IsAbstract = isAbstractProperty.GetBoolean(); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - category.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the category {id} is null", category.Iid); + } + else + { + category.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - category.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the category {id} is null", category.Iid); + } + else + { + category.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - category.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the category {id} is null", category.Iid); + } + else + { + category.Name = nameProperty.GetString(); + } } - if (!jObject["permissibleClass"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("permissibleClass"u8, out var permissibleClassProperty) && permissibleClassProperty.ValueKind != JsonValueKind.Null) { - category.PermissibleClass.AddRange(jObject["permissibleClass"].ToObject>()); + foreach(var element in permissibleClassProperty.EnumerateArray()) + { + category.PermissibleClass.Add(ClassKindDeserializer.Deserialize(element)); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - category.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the category {id} is null", category.Iid); + } + else + { + category.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["superCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("superCategory"u8, out var superCategoryProperty) && superCategoryProperty.ValueKind != JsonValueKind.Null) { - category.SuperCategory.AddRange(jObject["superCategory"].ToObject>()); + foreach(var element in superCategoryProperty.EnumerateArray()) + { + category.SuperCategory.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - category.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the category {id} is null", category.Iid); + } + else + { + category.ThingPreference = thingPreferenceProperty.GetString(); + } } return category; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs index a19595710..80d7e9470 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeProposalResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,136 +28,254 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ChangeProposalResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ChangeProposal FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ChangeProposal FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var changeProposal = new CDP4Common.DTO.ChangeProposal(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ChangeProposalResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - changeProposal.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var changeProposal = new CDP4Common.DTO.ChangeProposal(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - changeProposal.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + changeProposal.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - changeProposal.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - changeProposal.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + changeProposal.Category.Add(element.GetGuid()); + } } - if (!jObject["changeRequest"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("changeRequest"u8, out var changeRequestProperty)) { - changeProposal.ChangeRequest = jObject["changeRequest"].ToObject(); + if(changeRequestProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale changeRequest property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.ChangeRequest = changeRequestProperty.GetGuid(); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - changeProposal.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale classification property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - changeProposal.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - changeProposal.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - changeProposal.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + changeProposal.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - changeProposal.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + changeProposal.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - changeProposal.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + changeProposal.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - changeProposal.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - changeProposal.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - changeProposal.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - changeProposal.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + changeProposal.PrimaryAnnotatedThing = null; + } + else + { + changeProposal.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - changeProposal.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + changeProposal.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - changeProposal.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - changeProposal.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + changeProposal.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - changeProposal.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - changeProposal.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - changeProposal.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale title property of the changeProposal {id} is null", changeProposal.Iid); + } + else + { + changeProposal.Title = titleProperty.GetString(); + } } return changeProposal; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs index 43d6c202f..a0ed550a1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ChangeRequestResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,131 +28,242 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ChangeRequestResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ChangeRequest FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ChangeRequest FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var changeRequest = new CDP4Common.DTO.ChangeRequest(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ChangeRequestResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - changeRequest.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var changeRequest = new CDP4Common.DTO.ChangeRequest(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - changeRequest.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + changeRequest.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - changeRequest.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - changeRequest.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + changeRequest.Category.Add(element.GetGuid()); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - changeRequest.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale classification property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - changeRequest.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - changeRequest.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - changeRequest.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + changeRequest.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - changeRequest.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + changeRequest.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - changeRequest.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + changeRequest.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - changeRequest.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - changeRequest.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - changeRequest.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - changeRequest.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + changeRequest.PrimaryAnnotatedThing = null; + } + else + { + changeRequest.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - changeRequest.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + changeRequest.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - changeRequest.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - changeRequest.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + changeRequest.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - changeRequest.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - changeRequest.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - changeRequest.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale title property of the changeRequest {id} is null", changeRequest.Iid); + } + else + { + changeRequest.Title = titleProperty.GetString(); + } } return changeRequest; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs index 18098e9ab..31ff11912 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CitationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,142 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class CitationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Citation FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Citation FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var citation = new CDP4Common.DTO.Citation(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the CitationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - citation.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var citation = new CDP4Common.DTO.Citation(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - citation.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + citation.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - citation.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + citation.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isAdaptation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isAdaptation"u8, out var isAdaptationProperty)) { - citation.IsAdaptation = jObject["isAdaptation"].ToObject(); + if(isAdaptationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isAdaptation property of the citation {id} is null", citation.Iid); + } + else + { + citation.IsAdaptation = isAdaptationProperty.GetBoolean(); + } } - if (!jObject["location"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("location"u8, out var locationProperty)) { - citation.Location = jObject["location"].ToObject(); + if(locationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale location property of the citation {id} is null", citation.Iid); + } + else + { + citation.Location = locationProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - citation.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the citation {id} is null", citation.Iid); + } + else + { + citation.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["remark"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("remark"u8, out var remarkProperty)) { - citation.Remark = jObject["remark"].ToObject(); + if(remarkProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale remark property of the citation {id} is null", citation.Iid); + } + else + { + citation.Remark = remarkProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - citation.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the citation {id} is null", citation.Iid); + } + else + { + citation.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["source"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("source"u8, out var sourceProperty)) { - citation.Source = jObject["source"].ToObject(); + if(sourceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale source property of the citation {id} is null", citation.Iid); + } + else + { + citation.Source = sourceProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - citation.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the citation {id} is null", citation.Iid); + } + else + { + citation.ThingPreference = thingPreferenceProperty.GetString(); + } } return citation; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs index 4b0355c98..6425b478e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ColorResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,76 +28,130 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ColorResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Color FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Color FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var color = new CDP4Common.DTO.Color(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ColorResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - color.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["blue"].IsNullOrEmpty()) + var color = new CDP4Common.DTO.Color(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("blue"u8, out var blueProperty)) { - color.Blue = jObject["blue"].ToObject(); + if(blueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale blue property of the color {id} is null", color.Iid); + } + else + { + color.Blue = blueProperty.GetInt32(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - color.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + color.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - color.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + color.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["green"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("green"u8, out var greenProperty)) { - color.Green = jObject["green"].ToObject(); + if(greenProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale green property of the color {id} is null", color.Iid); + } + else + { + color.Green = greenProperty.GetInt32(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - color.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the color {id} is null", color.Iid); + } + else + { + color.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - color.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the color {id} is null", color.Iid); + } + else + { + color.Name = nameProperty.GetString(); + } } - if (!jObject["red"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("red"u8, out var redProperty)) { - color.Red = jObject["red"].ToObject(); + if(redProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale red property of the color {id} is null", color.Iid); + } + else + { + color.Red = redProperty.GetInt32(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - color.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the color {id} is null", color.Iid); + } + else + { + color.ThingPreference = thingPreferenceProperty.GetString(); + } } return color; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs index 329f0ee97..0474e8556 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CommonFileStoreResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,134 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class CommonFileStoreResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.CommonFileStore FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.CommonFileStore FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var commonFileStore = new CDP4Common.DTO.CommonFileStore(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the CommonFileStoreResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - commonFileStore.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["createdOn"].IsNullOrEmpty()) + var commonFileStore = new CDP4Common.DTO.CommonFileStore(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - commonFileStore.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the commonFileStore {id} is null", commonFileStore.Iid); + } + else + { + commonFileStore.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - commonFileStore.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + commonFileStore.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - commonFileStore.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + commonFileStore.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["file"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("file"u8, out var fileProperty) && fileProperty.ValueKind != JsonValueKind.Null) { - commonFileStore.File.AddRange(jObject["file"].ToObject>()); + foreach(var element in fileProperty.EnumerateArray()) + { + commonFileStore.File.Add(element.GetGuid()); + } } - if (!jObject["folder"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("folder"u8, out var folderProperty) && folderProperty.ValueKind != JsonValueKind.Null) { - commonFileStore.Folder.AddRange(jObject["folder"].ToObject>()); + foreach(var element in folderProperty.EnumerateArray()) + { + commonFileStore.Folder.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - commonFileStore.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the commonFileStore {id} is null", commonFileStore.Iid); + } + else + { + commonFileStore.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - commonFileStore.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the commonFileStore {id} is null", commonFileStore.Iid); + } + else + { + commonFileStore.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - commonFileStore.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the commonFileStore {id} is null", commonFileStore.Iid); + } + else + { + commonFileStore.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - commonFileStore.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the commonFileStore {id} is null", commonFileStore.Iid); + } + else + { + commonFileStore.ThingPreference = thingPreferenceProperty.GetString(); + } } return commonFileStore; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs index a2f2e6026..429f85a86 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CompoundParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,106 +28,179 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class CompoundParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.CompoundParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.CompoundParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var compoundParameterType = new CDP4Common.DTO.CompoundParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the CompoundParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - compoundParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var compoundParameterType = new CDP4Common.DTO.CompoundParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + compoundParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + compoundParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["component"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("component"u8, out var componentProperty)) { - compoundParameterType.Component.AddRange(jObject["component"].ToOrderedItemCollection()); + compoundParameterType.Component.AddRange(componentProperty.ToOrderedItemCollection()); } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + compoundParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + compoundParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + compoundParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - compoundParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + compoundParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - compoundParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isFinalized"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isFinalized"u8, out var isFinalizedProperty)) { - compoundParameterType.IsFinalized = jObject["isFinalized"].ToObject(); + if(isFinalizedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isFinalized property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.IsFinalized = isFinalizedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - compoundParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - compoundParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - compoundParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - compoundParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - compoundParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the compoundParameterType {id} is null", compoundParameterType.Iid); + } + else + { + compoundParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return compoundParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs index 498bde5a1..c45d2664b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ConstantResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,106 +28,191 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ConstantResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Constant FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var constant = new CDP4Common.DTO.Constant(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Constant FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - constant.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the ConstantResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["alias"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - constant.Alias.AddRange(jObject["alias"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var constant = new CDP4Common.DTO.Constant(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - constant.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + constant.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - constant.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + constant.Category.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - constant.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + constant.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - constant.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + constant.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - constant.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + constant.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - constant.IsDeprecated = jObject["isDeprecated"].ToObject(); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + constant.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - constant.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the constant {id} is null", constant.Iid); + } + else + { + constant.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - constant.Name = jObject["name"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the constant {id} is null", constant.Iid); + } + else + { + constant.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - constant.ParameterType = jObject["parameterType"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the constant {id} is null", constant.Iid); + } + else + { + constant.Name = nameProperty.GetString(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - constant.Scale = jObject["scale"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the constant {id} is null", constant.Iid); + } + else + { + constant.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - constant.ShortName = jObject["shortName"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + constant.Scale = null; + } + else + { + constant.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - constant.ThingPreference = jObject["thingPreference"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the constant {id} is null", constant.Iid); + } + else + { + constant.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) + { + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the constant {id} is null", constant.Iid); + } + else + { + constant.ThingPreference = thingPreferenceProperty.GetString(); + } + } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - constant.Value = SerializerHelper.ToValueArray(jObject["value"].ToString()); + if (valueProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in valueProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + constant.Value = new ValueArray(newValueArrayItems); + } + else + { + constant.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); + } } return constant; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs index 099c36b58..25e95b05e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ContractChangeNoticeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,136 +28,254 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ContractChangeNoticeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ContractChangeNotice FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var contractChangeNotice = new CDP4Common.DTO.ContractChangeNotice(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ContractChangeNoticeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - contractChangeNotice.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var contractChangeNotice = new CDP4Common.DTO.ContractChangeNotice(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + contractChangeNotice.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - contractChangeNotice.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + contractChangeNotice.Category.Add(element.GetGuid()); + } } - if (!jObject["changeProposal"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("changeProposal"u8, out var changeProposalProperty)) { - contractChangeNotice.ChangeProposal = jObject["changeProposal"].ToObject(); + if(changeProposalProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale changeProposal property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.ChangeProposal = changeProposalProperty.GetGuid(); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - contractChangeNotice.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale classification property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - contractChangeNotice.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - contractChangeNotice.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + contractChangeNotice.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + contractChangeNotice.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + contractChangeNotice.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - contractChangeNotice.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - contractChangeNotice.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - contractChangeNotice.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - contractChangeNotice.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + contractChangeNotice.PrimaryAnnotatedThing = null; + } + else + { + contractChangeNotice.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + contractChangeNotice.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - contractChangeNotice.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - contractChangeNotice.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + contractChangeNotice.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - contractChangeNotice.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - contractChangeNotice.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - contractChangeNotice.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale title property of the contractChangeNotice {id} is null", contractChangeNotice.Iid); + } + else + { + contractChangeNotice.Title = titleProperty.GetString(); + } } return contractChangeNotice; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs index 38c59f764..1adf7095c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/CyclicRatioScaleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,141 +28,266 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class CyclicRatioScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.CyclicRatioScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var cyclicRatioScale = new CDP4Common.DTO.CyclicRatioScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the CyclicRatioScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - cyclicRatioScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var cyclicRatioScale = new CDP4Common.DTO.CyclicRatioScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + cyclicRatioScale.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + cyclicRatioScale.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + cyclicRatioScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + cyclicRatioScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + cyclicRatioScale.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - cyclicRatioScale.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isMaximumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMaximumInclusive"u8, out var isMaximumInclusiveProperty)) { - cyclicRatioScale.IsMaximumInclusive = jObject["isMaximumInclusive"].ToObject(); + if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMaximumInclusive property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.IsMaximumInclusive = isMaximumInclusiveProperty.GetBoolean(); + } } - if (!jObject["isMinimumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMinimumInclusive"u8, out var isMinimumInclusiveProperty)) { - cyclicRatioScale.IsMinimumInclusive = jObject["isMinimumInclusive"].ToObject(); + if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMinimumInclusive property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.IsMinimumInclusive = isMinimumInclusiveProperty.GetBoolean(); + } } - if (!jObject["mappingToReferenceScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("mappingToReferenceScale"u8, out var mappingToReferenceScaleProperty) && mappingToReferenceScaleProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.MappingToReferenceScale.AddRange(jObject["mappingToReferenceScale"].ToObject>()); + foreach(var element in mappingToReferenceScaleProperty.EnumerateArray()) + { + cyclicRatioScale.MappingToReferenceScale.Add(element.GetGuid()); + } } - if (!jObject["maximumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maximumPermissibleValue"u8, out var maximumPermissibleValueProperty)) { - cyclicRatioScale.MaximumPermissibleValue = jObject["maximumPermissibleValue"].ToObject(); + if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale maximumPermissibleValue property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.MaximumPermissibleValue = maximumPermissibleValueProperty.GetString(); + } } - if (!jObject["minimumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minimumPermissibleValue"u8, out var minimumPermissibleValueProperty)) { - cyclicRatioScale.MinimumPermissibleValue = jObject["minimumPermissibleValue"].ToObject(); + if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale minimumPermissibleValue property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.MinimumPermissibleValue = minimumPermissibleValueProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - cyclicRatioScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["modulus"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modulus"u8, out var modulusProperty)) { - cyclicRatioScale.Modulus = jObject["modulus"].ToObject(); + if(modulusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modulus property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.Modulus = modulusProperty.GetString(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - cyclicRatioScale.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.Name = nameProperty.GetString(); + } } - if (!jObject["negativeValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("negativeValueConnotation"u8, out var negativeValueConnotationProperty)) { - cyclicRatioScale.NegativeValueConnotation = jObject["negativeValueConnotation"].ToObject(); + if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale negativeValueConnotation property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.NegativeValueConnotation = negativeValueConnotationProperty.GetString(); + } } - if (!jObject["numberSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("numberSet"u8, out var numberSetProperty)) { - cyclicRatioScale.NumberSet = jObject["numberSet"].ToObject(); + if(numberSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale numberSet property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.NumberSet = NumberSetKindDeserializer.Deserialize(numberSetProperty); + } } - if (!jObject["positiveValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("positiveValueConnotation"u8, out var positiveValueConnotationProperty)) { - cyclicRatioScale.PositiveValueConnotation = jObject["positiveValueConnotation"].ToObject(); + if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale positiveValueConnotation property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.PositiveValueConnotation = positiveValueConnotationProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - cyclicRatioScale.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - cyclicRatioScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - cyclicRatioScale.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale unit property of the cyclicRatioScale {id} is null", cyclicRatioScale.Iid); + } + else + { + cyclicRatioScale.Unit = unitProperty.GetGuid(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty) && valueDefinitionProperty.ValueKind != JsonValueKind.Null) { - cyclicRatioScale.ValueDefinition.AddRange(jObject["valueDefinition"].ToObject>()); + foreach(var element in valueDefinitionProperty.EnumerateArray()) + { + cyclicRatioScale.ValueDefinition.Add(element.GetGuid()); + } } return cyclicRatioScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs index 71c492f1c..5cbc1b5cb 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,162 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DateParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DateParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DateParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var dateParameterType = new CDP4Common.DTO.DateParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DateParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - dateParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var dateParameterType = new CDP4Common.DTO.DateParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + dateParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + dateParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + dateParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + dateParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + dateParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - dateParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + dateParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - dateParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - dateParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - dateParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - dateParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - dateParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - dateParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the dateParameterType {id} is null", dateParameterType.Iid); + } + else + { + dateParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return dateParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs index 09b106e7f..4633e4089 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DateTimeParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,162 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DateTimeParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DateTimeParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DateTimeParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var dateTimeParameterType = new CDP4Common.DTO.DateTimeParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DateTimeParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - dateTimeParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var dateTimeParameterType = new CDP4Common.DTO.DateTimeParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + dateTimeParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + dateTimeParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + dateTimeParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + dateTimeParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + dateTimeParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - dateTimeParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + dateTimeParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - dateTimeParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - dateTimeParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - dateTimeParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - dateTimeParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - dateTimeParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - dateTimeParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the dateTimeParameterType {id} is null", dateTimeParameterType.Iid); + } + else + { + dateTimeParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return dateTimeParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs index 126fa16dd..f45fcb366 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DecompositionRuleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,106 +28,186 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DecompositionRuleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DecompositionRule FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DecompositionRule FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var decompositionRule = new CDP4Common.DTO.DecompositionRule(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DecompositionRuleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - decompositionRule.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var decompositionRule = new CDP4Common.DTO.DecompositionRule(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + decompositionRule.Alias.Add(element.GetGuid()); + } } - if (!jObject["containedCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("containedCategory"u8, out var containedCategoryProperty) && containedCategoryProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.ContainedCategory.AddRange(jObject["containedCategory"].ToObject>()); + foreach(var element in containedCategoryProperty.EnumerateArray()) + { + decompositionRule.ContainedCategory.Add(element.GetGuid()); + } } - if (!jObject["containingCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("containingCategory"u8, out var containingCategoryProperty)) { - decompositionRule.ContainingCategory = jObject["containingCategory"].ToObject(); + if(containingCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale containingCategory property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.ContainingCategory = containingCategoryProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + decompositionRule.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + decompositionRule.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + decompositionRule.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - decompositionRule.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + decompositionRule.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - decompositionRule.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["maxContained"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maxContained"u8, out var maxContainedProperty)) { - decompositionRule.MaxContained = jObject["maxContained"].ToObject(); + if(maxContainedProperty.ValueKind == JsonValueKind.Null) + { + decompositionRule.MaxContained = null; + } + else + { + decompositionRule.MaxContained = maxContainedProperty.GetInt32(); + } } - if (!jObject["minContained"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minContained"u8, out var minContainedProperty)) { - decompositionRule.MinContained = jObject["minContained"].ToObject(); + if(minContainedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale minContained property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.MinContained = minContainedProperty.GetInt32(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - decompositionRule.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - decompositionRule.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - decompositionRule.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - decompositionRule.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the decompositionRule {id} is null", decompositionRule.Iid); + } + else + { + decompositionRule.ThingPreference = thingPreferenceProperty.GetString(); + } } return decompositionRule; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs index 9cdbcf60a..712225614 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DefinitionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,124 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DefinitionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Definition FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Definition FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var definition = new CDP4Common.DTO.Definition(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DefinitionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - definition.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["citation"].IsNullOrEmpty()) + var definition = new CDP4Common.DTO.Definition(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("citation"u8, out var citationProperty) && citationProperty.ValueKind != JsonValueKind.Null) { - definition.Citation.AddRange(jObject["citation"].ToObject>()); + foreach(var element in citationProperty.EnumerateArray()) + { + definition.Citation.Add(element.GetGuid()); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - definition.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the definition {id} is null", definition.Iid); + } + else + { + definition.Content = contentProperty.GetString(); + } } - if (!jObject["example"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("example"u8, out var exampleProperty)) { - definition.Example.AddRange(jObject["example"].ToOrderedItemCollection()); + definition.Example.AddRange(exampleProperty.ToOrderedItemCollection()); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - definition.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + definition.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - definition.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + definition.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - definition.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the definition {id} is null", definition.Iid); + } + else + { + definition.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - definition.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the definition {id} is null", definition.Iid); + } + else + { + definition.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["note"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("note"u8, out var noteProperty)) { - definition.Note.AddRange(jObject["note"].ToOrderedItemCollection()); + definition.Note.AddRange(noteProperty.ToOrderedItemCollection()); } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - definition.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the definition {id} is null", definition.Iid); + } + else + { + definition.ThingPreference = thingPreferenceProperty.GetString(); + } } return definition; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs index 4ee74b7a7..a0d427660 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DependentParameterTypeAssignmentResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,106 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DependentParameterTypeAssignmentResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DependentParameterTypeAssignment FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DependentParameterTypeAssignment FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var dependentParameterTypeAssignment = new CDP4Common.DTO.DependentParameterTypeAssignment(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DependentParameterTypeAssignmentResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - dependentParameterTypeAssignment.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var dependentParameterTypeAssignment = new CDP4Common.DTO.DependentParameterTypeAssignment(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - dependentParameterTypeAssignment.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + dependentParameterTypeAssignment.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - dependentParameterTypeAssignment.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + dependentParameterTypeAssignment.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["measurementScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("measurementScale"u8, out var measurementScaleProperty)) { - dependentParameterTypeAssignment.MeasurementScale = jObject["measurementScale"].ToObject(); + if(measurementScaleProperty.ValueKind == JsonValueKind.Null) + { + dependentParameterTypeAssignment.MeasurementScale = null; + } + else + { + dependentParameterTypeAssignment.MeasurementScale = measurementScaleProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - dependentParameterTypeAssignment.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the dependentParameterTypeAssignment {id} is null", dependentParameterTypeAssignment.Iid); + } + else + { + dependentParameterTypeAssignment.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - dependentParameterTypeAssignment.ParameterType = jObject["parameterType"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the dependentParameterTypeAssignment {id} is null", dependentParameterTypeAssignment.Iid); + } + else + { + dependentParameterTypeAssignment.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - dependentParameterTypeAssignment.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the dependentParameterTypeAssignment {id} is null", dependentParameterTypeAssignment.Iid); + } + else + { + dependentParameterTypeAssignment.ThingPreference = thingPreferenceProperty.GetString(); + } } return dependentParameterTypeAssignment; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs index cf14ccdf5..f157236d3 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedQuantityKindResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,116 +28,199 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DerivedQuantityKindResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DerivedQuantityKind FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DerivedQuantityKind FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var derivedQuantityKind = new CDP4Common.DTO.DerivedQuantityKind(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DerivedQuantityKindResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - derivedQuantityKind.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var derivedQuantityKind = new CDP4Common.DTO.DerivedQuantityKind(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + derivedQuantityKind.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + derivedQuantityKind.Category.Add(element.GetGuid()); + } } - if (!jObject["defaultScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultScale"u8, out var defaultScaleProperty)) { - derivedQuantityKind.DefaultScale = jObject["defaultScale"].ToObject(); + if(defaultScaleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale defaultScale property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.DefaultScale = defaultScaleProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + derivedQuantityKind.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + derivedQuantityKind.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + derivedQuantityKind.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + derivedQuantityKind.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - derivedQuantityKind.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - derivedQuantityKind.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - derivedQuantityKind.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.Name = nameProperty.GetString(); + } } - if (!jObject["possibleScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleScale"u8, out var possibleScaleProperty) && possibleScaleProperty.ValueKind != JsonValueKind.Null) { - derivedQuantityKind.PossibleScale.AddRange(jObject["possibleScale"].ToObject>()); + foreach(var element in possibleScaleProperty.EnumerateArray()) + { + derivedQuantityKind.PossibleScale.Add(element.GetGuid()); + } } - if (!jObject["quantityDimensionSymbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("quantityDimensionSymbol"u8, out var quantityDimensionSymbolProperty)) { - derivedQuantityKind.QuantityDimensionSymbol = jObject["quantityDimensionSymbol"].ToObject(); + if(quantityDimensionSymbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale quantityDimensionSymbol property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.QuantityDimensionSymbol = quantityDimensionSymbolProperty.GetString(); + } } - if (!jObject["quantityKindFactor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("quantityKindFactor"u8, out var quantityKindFactorProperty)) { - derivedQuantityKind.QuantityKindFactor.AddRange(jObject["quantityKindFactor"].ToOrderedItemCollection()); + derivedQuantityKind.QuantityKindFactor.AddRange(quantityKindFactorProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - derivedQuantityKind.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - derivedQuantityKind.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - derivedQuantityKind.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the derivedQuantityKind {id} is null", derivedQuantityKind.Iid); + } + else + { + derivedQuantityKind.ThingPreference = thingPreferenceProperty.GetString(); + } } return derivedQuantityKind; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs index e48190dac..102e572e4 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DerivedUnitResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,147 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DerivedUnitResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DerivedUnit FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DerivedUnit FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var derivedUnit = new CDP4Common.DTO.DerivedUnit(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DerivedUnitResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - derivedUnit.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var derivedUnit = new CDP4Common.DTO.DerivedUnit(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - derivedUnit.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + derivedUnit.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - derivedUnit.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + derivedUnit.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - derivedUnit.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + derivedUnit.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - derivedUnit.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + derivedUnit.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - derivedUnit.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + derivedUnit.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - derivedUnit.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the derivedUnit {id} is null", derivedUnit.Iid); + } + else + { + derivedUnit.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - derivedUnit.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the derivedUnit {id} is null", derivedUnit.Iid); + } + else + { + derivedUnit.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - derivedUnit.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the derivedUnit {id} is null", derivedUnit.Iid); + } + else + { + derivedUnit.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - derivedUnit.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the derivedUnit {id} is null", derivedUnit.Iid); + } + else + { + derivedUnit.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - derivedUnit.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the derivedUnit {id} is null", derivedUnit.Iid); + } + else + { + derivedUnit.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unitFactor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unitFactor"u8, out var unitFactorProperty)) { - derivedUnit.UnitFactor.AddRange(jObject["unitFactor"].ToOrderedItemCollection()); + derivedUnit.UnitFactor.AddRange(unitFactorProperty.ToOrderedItemCollection()); } return derivedUnit; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs index 36d78c868..2b1080899 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramCanvasResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,76 +28,122 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DiagramCanvasResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DiagramCanvas FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DiagramCanvas FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var diagramCanvas = new CDP4Common.DTO.DiagramCanvas(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DiagramCanvasResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - diagramCanvas.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["bounds"].IsNullOrEmpty()) + var diagramCanvas = new CDP4Common.DTO.DiagramCanvas(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("bounds"u8, out var boundsProperty) && boundsProperty.ValueKind != JsonValueKind.Null) { - diagramCanvas.Bounds.AddRange(jObject["bounds"].ToObject>()); + foreach(var element in boundsProperty.EnumerateArray()) + { + diagramCanvas.Bounds.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - diagramCanvas.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the diagramCanvas {id} is null", diagramCanvas.Iid); + } + else + { + diagramCanvas.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["diagramElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("diagramElement"u8, out var diagramElementProperty) && diagramElementProperty.ValueKind != JsonValueKind.Null) { - diagramCanvas.DiagramElement.AddRange(jObject["diagramElement"].ToObject>()); + foreach(var element in diagramElementProperty.EnumerateArray()) + { + diagramCanvas.DiagramElement.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - diagramCanvas.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + diagramCanvas.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - diagramCanvas.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + diagramCanvas.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - diagramCanvas.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the diagramCanvas {id} is null", diagramCanvas.Iid); + } + else + { + diagramCanvas.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - diagramCanvas.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the diagramCanvas {id} is null", diagramCanvas.Iid); + } + else + { + diagramCanvas.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - diagramCanvas.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the diagramCanvas {id} is null", diagramCanvas.Iid); + } + else + { + diagramCanvas.ThingPreference = thingPreferenceProperty.GetString(); + } } return diagramCanvas; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs index d4aba04df..acbae661d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramEdgeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,101 +28,171 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DiagramEdgeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DiagramEdge FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DiagramEdge FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var diagramEdge = new CDP4Common.DTO.DiagramEdge(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DiagramEdgeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - diagramEdge.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["bounds"].IsNullOrEmpty()) + var diagramEdge = new CDP4Common.DTO.DiagramEdge(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("bounds"u8, out var boundsProperty) && boundsProperty.ValueKind != JsonValueKind.Null) { - diagramEdge.Bounds.AddRange(jObject["bounds"].ToObject>()); + foreach(var element in boundsProperty.EnumerateArray()) + { + diagramEdge.Bounds.Add(element.GetGuid()); + } } - if (!jObject["depictedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("depictedThing"u8, out var depictedThingProperty)) { - diagramEdge.DepictedThing = jObject["depictedThing"].ToObject(); + if(depictedThingProperty.ValueKind == JsonValueKind.Null) + { + diagramEdge.DepictedThing = null; + } + else + { + diagramEdge.DepictedThing = depictedThingProperty.GetGuid(); + } } - if (!jObject["diagramElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("diagramElement"u8, out var diagramElementProperty) && diagramElementProperty.ValueKind != JsonValueKind.Null) { - diagramEdge.DiagramElement.AddRange(jObject["diagramElement"].ToObject>()); + foreach(var element in diagramElementProperty.EnumerateArray()) + { + diagramEdge.DiagramElement.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - diagramEdge.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + diagramEdge.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - diagramEdge.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + diagramEdge.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["localStyle"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("localStyle"u8, out var localStyleProperty) && localStyleProperty.ValueKind != JsonValueKind.Null) { - diagramEdge.LocalStyle.AddRange(jObject["localStyle"].ToObject>()); + foreach(var element in localStyleProperty.EnumerateArray()) + { + diagramEdge.LocalStyle.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - diagramEdge.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the diagramEdge {id} is null", diagramEdge.Iid); + } + else + { + diagramEdge.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - diagramEdge.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the diagramEdge {id} is null", diagramEdge.Iid); + } + else + { + diagramEdge.Name = nameProperty.GetString(); + } } - if (!jObject["point"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("point"u8, out var pointProperty)) { - diagramEdge.Point.AddRange(jObject["point"].ToOrderedItemCollection()); + diagramEdge.Point.AddRange(pointProperty.ToOrderedItemCollection()); } - if (!jObject["sharedStyle"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sharedStyle"u8, out var sharedStyleProperty)) { - diagramEdge.SharedStyle = jObject["sharedStyle"].ToObject(); + if(sharedStyleProperty.ValueKind == JsonValueKind.Null) + { + diagramEdge.SharedStyle = null; + } + else + { + diagramEdge.SharedStyle = sharedStyleProperty.GetGuid(); + } } - if (!jObject["source"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("source"u8, out var sourceProperty)) { - diagramEdge.Source = jObject["source"].ToObject(); + if(sourceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale source property of the diagramEdge {id} is null", diagramEdge.Iid); + } + else + { + diagramEdge.Source = sourceProperty.GetGuid(); + } } - if (!jObject["target"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("target"u8, out var targetProperty)) { - diagramEdge.Target = jObject["target"].ToObject(); + if(targetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale target property of the diagramEdge {id} is null", diagramEdge.Iid); + } + else + { + diagramEdge.Target = targetProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - diagramEdge.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the diagramEdge {id} is null", diagramEdge.Iid); + } + else + { + diagramEdge.ThingPreference = thingPreferenceProperty.GetString(); + } } return diagramEdge; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs index c492282e5..e22f2ba6c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DiagramObjectResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,166 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DiagramObjectResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DiagramObject FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DiagramObject FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var diagramObject = new CDP4Common.DTO.DiagramObject(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DiagramObjectResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - diagramObject.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["bounds"].IsNullOrEmpty()) + var diagramObject = new CDP4Common.DTO.DiagramObject(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("bounds"u8, out var boundsProperty) && boundsProperty.ValueKind != JsonValueKind.Null) { - diagramObject.Bounds.AddRange(jObject["bounds"].ToObject>()); + foreach(var element in boundsProperty.EnumerateArray()) + { + diagramObject.Bounds.Add(element.GetGuid()); + } } - if (!jObject["depictedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("depictedThing"u8, out var depictedThingProperty)) { - diagramObject.DepictedThing = jObject["depictedThing"].ToObject(); + if(depictedThingProperty.ValueKind == JsonValueKind.Null) + { + diagramObject.DepictedThing = null; + } + else + { + diagramObject.DepictedThing = depictedThingProperty.GetGuid(); + } } - if (!jObject["diagramElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("diagramElement"u8, out var diagramElementProperty) && diagramElementProperty.ValueKind != JsonValueKind.Null) { - diagramObject.DiagramElement.AddRange(jObject["diagramElement"].ToObject>()); + foreach(var element in diagramElementProperty.EnumerateArray()) + { + diagramObject.DiagramElement.Add(element.GetGuid()); + } } - if (!jObject["documentation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("documentation"u8, out var documentationProperty)) { - diagramObject.Documentation = jObject["documentation"].ToObject(); + if(documentationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale documentation property of the diagramObject {id} is null", diagramObject.Iid); + } + else + { + diagramObject.Documentation = documentationProperty.GetString(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - diagramObject.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + diagramObject.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - diagramObject.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + diagramObject.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["localStyle"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("localStyle"u8, out var localStyleProperty) && localStyleProperty.ValueKind != JsonValueKind.Null) { - diagramObject.LocalStyle.AddRange(jObject["localStyle"].ToObject>()); + foreach(var element in localStyleProperty.EnumerateArray()) + { + diagramObject.LocalStyle.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - diagramObject.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the diagramObject {id} is null", diagramObject.Iid); + } + else + { + diagramObject.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - diagramObject.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the diagramObject {id} is null", diagramObject.Iid); + } + else + { + diagramObject.Name = nameProperty.GetString(); + } } - if (!jObject["resolution"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("resolution"u8, out var resolutionProperty)) { - diagramObject.Resolution = jObject["resolution"].ToObject(); + if(resolutionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale resolution property of the diagramObject {id} is null", diagramObject.Iid); + } + else + { + diagramObject.Resolution = resolutionProperty.GetSingle(); + } } - if (!jObject["sharedStyle"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sharedStyle"u8, out var sharedStyleProperty)) { - diagramObject.SharedStyle = jObject["sharedStyle"].ToObject(); + if(sharedStyleProperty.ValueKind == JsonValueKind.Null) + { + diagramObject.SharedStyle = null; + } + else + { + diagramObject.SharedStyle = sharedStyleProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - diagramObject.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the diagramObject {id} is null", diagramObject.Iid); + } + else + { + diagramObject.ThingPreference = thingPreferenceProperty.GetString(); + } } return diagramObject; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs index 156902fd2..de5efff51 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainFileStoreResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,146 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DomainFileStoreResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DomainFileStore FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DomainFileStore FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var domainFileStore = new CDP4Common.DTO.DomainFileStore(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DomainFileStoreResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - domainFileStore.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["createdOn"].IsNullOrEmpty()) + var domainFileStore = new CDP4Common.DTO.DomainFileStore(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - domainFileStore.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - domainFileStore.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + domainFileStore.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - domainFileStore.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + domainFileStore.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["file"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("file"u8, out var fileProperty) && fileProperty.ValueKind != JsonValueKind.Null) { - domainFileStore.File.AddRange(jObject["file"].ToObject>()); + foreach(var element in fileProperty.EnumerateArray()) + { + domainFileStore.File.Add(element.GetGuid()); + } } - if (!jObject["folder"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("folder"u8, out var folderProperty) && folderProperty.ValueKind != JsonValueKind.Null) { - domainFileStore.Folder.AddRange(jObject["folder"].ToObject>()); + foreach(var element in folderProperty.EnumerateArray()) + { + domainFileStore.Folder.Add(element.GetGuid()); + } } - if (!jObject["isHidden"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isHidden"u8, out var isHiddenProperty)) { - domainFileStore.IsHidden = jObject["isHidden"].ToObject(); + if(isHiddenProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isHidden property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.IsHidden = isHiddenProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - domainFileStore.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - domainFileStore.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - domainFileStore.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - domainFileStore.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the domainFileStore {id} is null", domainFileStore.Iid); + } + else + { + domainFileStore.ThingPreference = thingPreferenceProperty.GetString(); + } } return domainFileStore; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs index 73de42982..a69fab53b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseGroupResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,150 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DomainOfExpertiseGroupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DomainOfExpertiseGroup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DomainOfExpertiseGroup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var domainOfExpertiseGroup = new CDP4Common.DTO.DomainOfExpertiseGroup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DomainOfExpertiseGroupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - domainOfExpertiseGroup.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var domainOfExpertiseGroup = new CDP4Common.DTO.DomainOfExpertiseGroup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + domainOfExpertiseGroup.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + domainOfExpertiseGroup.Definition.Add(element.GetGuid()); + } } - if (!jObject["domain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("domain"u8, out var domainProperty) && domainProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.Domain.AddRange(jObject["domain"].ToObject>()); + foreach(var element in domainProperty.EnumerateArray()) + { + domainOfExpertiseGroup.Domain.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + domainOfExpertiseGroup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + domainOfExpertiseGroup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertiseGroup.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + domainOfExpertiseGroup.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - domainOfExpertiseGroup.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + } + else + { + domainOfExpertiseGroup.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - domainOfExpertiseGroup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + } + else + { + domainOfExpertiseGroup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - domainOfExpertiseGroup.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + } + else + { + domainOfExpertiseGroup.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - domainOfExpertiseGroup.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + } + else + { + domainOfExpertiseGroup.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - domainOfExpertiseGroup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the domainOfExpertiseGroup {id} is null", domainOfExpertiseGroup.Iid); + } + else + { + domainOfExpertiseGroup.ThingPreference = thingPreferenceProperty.GetString(); + } } return domainOfExpertiseGroup; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs index f963450d4..041a2e065 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DomainOfExpertiseResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,150 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class DomainOfExpertiseResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.DomainOfExpertise FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.DomainOfExpertise FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var domainOfExpertise = new CDP4Common.DTO.DomainOfExpertise(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the DomainOfExpertiseResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - domainOfExpertise.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var domainOfExpertise = new CDP4Common.DTO.DomainOfExpertise(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + domainOfExpertise.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + domainOfExpertise.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + domainOfExpertise.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + domainOfExpertise.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + domainOfExpertise.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - domainOfExpertise.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + domainOfExpertise.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - domainOfExpertise.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + } + else + { + domainOfExpertise.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - domainOfExpertise.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + } + else + { + domainOfExpertise.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - domainOfExpertise.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + } + else + { + domainOfExpertise.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - domainOfExpertise.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + } + else + { + domainOfExpertise.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - domainOfExpertise.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the domainOfExpertise {id} is null", domainOfExpertise.Iid); + } + else + { + domainOfExpertise.ThingPreference = thingPreferenceProperty.GetString(); + } } return domainOfExpertise; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs index 093dde44f..bd03a4487 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/DtoFactory.cs @@ -2,18 +2,16 @@ // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar +// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Jaime Bernar // -// This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! +// This file is part of CDP4-COMET-SDK Community Edition // -// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// The CDP4-COMET-SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. // -// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// The CDP4-COMET-SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. @@ -31,11 +29,10 @@ namespace CDP4JsonSerializer { using System; using System.Collections.Generic; - - using CDP4Common.DTO; - - using Newtonsoft.Json.Linq; - + using System.Text.Json; + + using CDP4Common.DTO; + /// /// Utility class that is responsible for instantiating a /// @@ -44,7 +41,7 @@ public static class DtoFactory /// /// The type to Constructor map /// - private static readonly Dictionary> DtoConstructorMap = new Dictionary> + private static readonly Dictionary> DtoConstructorMap = new() { { "ActionItem", ActionItemResolver.FromJsonObject }, { "ActualFiniteState", ActualFiniteStateResolver.FromJsonObject }, @@ -195,20 +192,20 @@ public static class DtoFactory }; /// - /// Instantiates a new from a + /// Instantiates a new from a /// - /// The containing the data + /// The containing the data /// The to instantiate - public static Thing ToDto(this JObject dataObject) + public static Thing ToDto(this JsonElement dataObject) { - var classKind = dataObject["classKind"].ToString(); - Func constructor; - if (!DtoConstructorMap.TryGetValue(classKind, out constructor)) + var classKind = dataObject.GetProperty("classKind").ToString(); + + if(!DtoConstructorMap.TryGetValue(classKind, out var constructor)) { throw new InvalidOperationException($"The dto resolver was not found for {classKind}"); } - return constructor(dataObject); + return constructor.Invoke(dataObject); } } } diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs index c5b2b68e1..8a238983a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementDefinitionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,116 +28,190 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ElementDefinitionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ElementDefinition FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ElementDefinition FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var elementDefinition = new CDP4Common.DTO.ElementDefinition(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ElementDefinitionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - elementDefinition.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var elementDefinition = new CDP4Common.DTO.ElementDefinition(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + elementDefinition.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + elementDefinition.Category.Add(element.GetGuid()); + } } - if (!jObject["containedElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("containedElement"u8, out var containedElementProperty) && containedElementProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.ContainedElement.AddRange(jObject["containedElement"].ToObject>()); + foreach(var element in containedElementProperty.EnumerateArray()) + { + elementDefinition.ContainedElement.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + elementDefinition.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + elementDefinition.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + elementDefinition.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + elementDefinition.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - elementDefinition.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the elementDefinition {id} is null", elementDefinition.Iid); + } + else + { + elementDefinition.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - elementDefinition.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the elementDefinition {id} is null", elementDefinition.Iid); + } + else + { + elementDefinition.Name = nameProperty.GetString(); + } } - if (!jObject["organizationalParticipant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organizationalParticipant"u8, out var organizationalParticipantProperty) && organizationalParticipantProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.OrganizationalParticipant.AddRange(jObject["organizationalParticipant"].ToObject>()); + foreach(var element in organizationalParticipantProperty.EnumerateArray()) + { + elementDefinition.OrganizationalParticipant.Add(element.GetGuid()); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - elementDefinition.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the elementDefinition {id} is null", elementDefinition.Iid); + } + else + { + elementDefinition.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameter"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameter"u8, out var parameterProperty) && parameterProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.Parameter.AddRange(jObject["parameter"].ToObject>()); + foreach(var element in parameterProperty.EnumerateArray()) + { + elementDefinition.Parameter.Add(element.GetGuid()); + } } - if (!jObject["parameterGroup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterGroup"u8, out var parameterGroupProperty) && parameterGroupProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.ParameterGroup.AddRange(jObject["parameterGroup"].ToObject>()); + foreach(var element in parameterGroupProperty.EnumerateArray()) + { + elementDefinition.ParameterGroup.Add(element.GetGuid()); + } } - if (!jObject["referencedElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedElement"u8, out var referencedElementProperty) && referencedElementProperty.ValueKind != JsonValueKind.Null) { - elementDefinition.ReferencedElement.AddRange(jObject["referencedElement"].ToObject>()); + foreach(var element in referencedElementProperty.EnumerateArray()) + { + elementDefinition.ReferencedElement.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - elementDefinition.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the elementDefinition {id} is null", elementDefinition.Iid); + } + else + { + elementDefinition.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - elementDefinition.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the elementDefinition {id} is null", elementDefinition.Iid); + } + else + { + elementDefinition.ThingPreference = thingPreferenceProperty.GetString(); + } } return elementDefinition; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs index 8304d5c3e..07fc39549 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ElementUsageResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,111 +28,190 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ElementUsageResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ElementUsage FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ElementUsage FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var elementUsage = new CDP4Common.DTO.ElementUsage(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ElementUsageResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - elementUsage.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var elementUsage = new CDP4Common.DTO.ElementUsage(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - elementUsage.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + elementUsage.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - elementUsage.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + elementUsage.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - elementUsage.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + elementUsage.Definition.Add(element.GetGuid()); + } } - if (!jObject["elementDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("elementDefinition"u8, out var elementDefinitionProperty)) { - elementUsage.ElementDefinition = jObject["elementDefinition"].ToObject(); + if(elementDefinitionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale elementDefinition property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.ElementDefinition = elementDefinitionProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - elementUsage.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + elementUsage.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - elementUsage.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + elementUsage.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["excludeOption"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludeOption"u8, out var excludeOptionProperty) && excludeOptionProperty.ValueKind != JsonValueKind.Null) { - elementUsage.ExcludeOption.AddRange(jObject["excludeOption"].ToObject>()); + foreach(var element in excludeOptionProperty.EnumerateArray()) + { + elementUsage.ExcludeOption.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - elementUsage.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + elementUsage.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["interfaceEnd"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("interfaceEnd"u8, out var interfaceEndProperty)) { - elementUsage.InterfaceEnd = jObject["interfaceEnd"].ToObject(); + if(interfaceEndProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale interfaceEnd property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.InterfaceEnd = InterfaceEndKindDeserializer.Deserialize(interfaceEndProperty); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - elementUsage.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - elementUsage.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - elementUsage.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterOverride"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterOverride"u8, out var parameterOverrideProperty) && parameterOverrideProperty.ValueKind != JsonValueKind.Null) { - elementUsage.ParameterOverride.AddRange(jObject["parameterOverride"].ToObject>()); + foreach(var element in parameterOverrideProperty.EnumerateArray()) + { + elementUsage.ParameterOverride.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - elementUsage.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - elementUsage.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the elementUsage {id} is null", elementUsage.Iid); + } + else + { + elementUsage.ThingPreference = thingPreferenceProperty.GetString(); + } } return elementUsage; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs index 7ff870419..e832f7d07 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EmailAddressResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,106 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EmailAddressResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EmailAddress FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EmailAddress FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var emailAddress = new CDP4Common.DTO.EmailAddress(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EmailAddressResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - emailAddress.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var emailAddress = new CDP4Common.DTO.EmailAddress(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - emailAddress.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + emailAddress.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - emailAddress.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + emailAddress.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - emailAddress.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the emailAddress {id} is null", emailAddress.Iid); + } + else + { + emailAddress.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - emailAddress.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the emailAddress {id} is null", emailAddress.Iid); + } + else + { + emailAddress.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - emailAddress.Value = jObject["value"].ToObject(); + if(valueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale value property of the emailAddress {id} is null", emailAddress.Iid); + } + else + { + emailAddress.Value = valueProperty.GetString(); + } } - if (!jObject["vcardType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("vcardType"u8, out var vcardTypeProperty)) { - emailAddress.VcardType = jObject["vcardType"].ToObject(); + if(vcardTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale vcardType property of the emailAddress {id} is null", emailAddress.Iid); + } + else + { + emailAddress.VcardType = VcardEmailAddressKindDeserializer.Deserialize(vcardTypeProperty); + } } return emailAddress; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs index e1b8bf451..e9d3be319 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataDiscussionItemResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,142 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EngineeringModelDataDiscussionItemResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EngineeringModelDataDiscussionItem FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EngineeringModelDataDiscussionItem FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var engineeringModelDataDiscussionItem = new CDP4Common.DTO.EngineeringModelDataDiscussionItem(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EngineeringModelDataDiscussionItemResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - engineeringModelDataDiscussionItem.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var engineeringModelDataDiscussionItem = new CDP4Common.DTO.EngineeringModelDataDiscussionItem(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - engineeringModelDataDiscussionItem.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.Author = authorProperty.GetGuid(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - engineeringModelDataDiscussionItem.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - engineeringModelDataDiscussionItem.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataDiscussionItem.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + engineeringModelDataDiscussionItem.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataDiscussionItem.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + engineeringModelDataDiscussionItem.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - engineeringModelDataDiscussionItem.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - engineeringModelDataDiscussionItem.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["replyTo"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("replyTo"u8, out var replyToProperty)) { - engineeringModelDataDiscussionItem.ReplyTo = jObject["replyTo"].ToObject(); + if(replyToProperty.ValueKind == JsonValueKind.Null) + { + engineeringModelDataDiscussionItem.ReplyTo = null; + } + else + { + engineeringModelDataDiscussionItem.ReplyTo = replyToProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - engineeringModelDataDiscussionItem.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the engineeringModelDataDiscussionItem {id} is null", engineeringModelDataDiscussionItem.Iid); + } + else + { + engineeringModelDataDiscussionItem.ThingPreference = thingPreferenceProperty.GetString(); + } } return engineeringModelDataDiscussionItem; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs index 9f56bd581..0b3b320cd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelDataNoteResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,158 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EngineeringModelDataNoteResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EngineeringModelDataNote FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EngineeringModelDataNote FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var engineeringModelDataNote = new CDP4Common.DTO.EngineeringModelDataNote(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EngineeringModelDataNoteResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - engineeringModelDataNote.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var engineeringModelDataNote = new CDP4Common.DTO.EngineeringModelDataNote(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - engineeringModelDataNote.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.Author = authorProperty.GetGuid(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - engineeringModelDataNote.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - engineeringModelDataNote.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataNote.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + engineeringModelDataNote.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataNote.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + engineeringModelDataNote.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataNote.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + engineeringModelDataNote.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - engineeringModelDataNote.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - engineeringModelDataNote.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - engineeringModelDataNote.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + engineeringModelDataNote.PrimaryAnnotatedThing = null; + } + else + { + engineeringModelDataNote.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - engineeringModelDataNote.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + engineeringModelDataNote.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - engineeringModelDataNote.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the engineeringModelDataNote {id} is null", engineeringModelDataNote.Iid); + } + else + { + engineeringModelDataNote.ThingPreference = thingPreferenceProperty.GetString(); + } } return engineeringModelDataNote; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs index 8eacdcadd..8b6eba2b9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,151 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EngineeringModelResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EngineeringModel FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EngineeringModel FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var engineeringModel = new CDP4Common.DTO.EngineeringModel(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EngineeringModelResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - engineeringModel.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["book"].IsNullOrEmpty()) + var engineeringModel = new CDP4Common.DTO.EngineeringModel(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("book"u8, out var bookProperty)) { - engineeringModel.Book.AddRange(jObject["book"].ToOrderedItemCollection()); + engineeringModel.Book.AddRange(bookProperty.ToOrderedItemCollection()); } - if (!jObject["commonFileStore"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("commonFileStore"u8, out var commonFileStoreProperty) && commonFileStoreProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.CommonFileStore.AddRange(jObject["commonFileStore"].ToObject>()); + foreach(var element in commonFileStoreProperty.EnumerateArray()) + { + engineeringModel.CommonFileStore.Add(element.GetGuid()); + } } - if (!jObject["engineeringModelSetup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("engineeringModelSetup"u8, out var engineeringModelSetupProperty)) { - engineeringModel.EngineeringModelSetup = jObject["engineeringModelSetup"].ToObject(); + if(engineeringModelSetupProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale engineeringModelSetup property of the engineeringModel {id} is null", engineeringModel.Iid); + } + else + { + engineeringModel.EngineeringModelSetup = engineeringModelSetupProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + engineeringModel.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + engineeringModel.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["genericNote"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("genericNote"u8, out var genericNoteProperty) && genericNoteProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.GenericNote.AddRange(jObject["genericNote"].ToObject>()); + foreach(var element in genericNoteProperty.EnumerateArray()) + { + engineeringModel.GenericNote.Add(element.GetGuid()); + } } - if (!jObject["iteration"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("iteration"u8, out var iterationProperty) && iterationProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.Iteration.AddRange(jObject["iteration"].ToObject>()); + foreach(var element in iterationProperty.EnumerateArray()) + { + engineeringModel.Iteration.Add(element.GetGuid()); + } } - if (!jObject["lastModifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("lastModifiedOn"u8, out var lastModifiedOnProperty)) { - engineeringModel.LastModifiedOn = jObject["lastModifiedOn"].ToObject(); + if(lastModifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale lastModifiedOn property of the engineeringModel {id} is null", engineeringModel.Iid); + } + else + { + engineeringModel.LastModifiedOn = lastModifiedOnProperty.GetDateTime(); + } } - if (!jObject["logEntry"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("logEntry"u8, out var logEntryProperty) && logEntryProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.LogEntry.AddRange(jObject["logEntry"].ToObject>()); + foreach(var element in logEntryProperty.EnumerateArray()) + { + engineeringModel.LogEntry.Add(element.GetGuid()); + } } - if (!jObject["modellingAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modellingAnnotation"u8, out var modellingAnnotationProperty) && modellingAnnotationProperty.ValueKind != JsonValueKind.Null) { - engineeringModel.ModellingAnnotation.AddRange(jObject["modellingAnnotation"].ToObject>()); + foreach(var element in modellingAnnotationProperty.EnumerateArray()) + { + engineeringModel.ModellingAnnotation.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - engineeringModel.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the engineeringModel {id} is null", engineeringModel.Iid); + } + else + { + engineeringModel.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - engineeringModel.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the engineeringModel {id} is null", engineeringModel.Iid); + } + else + { + engineeringModel.ThingPreference = thingPreferenceProperty.GetString(); + } } return engineeringModel; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs index 3b1a4fe15..9c21ab1f1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EngineeringModelSetupResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,131 +28,230 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EngineeringModelSetupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EngineeringModelSetup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EngineeringModelSetup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var engineeringModelSetup = new CDP4Common.DTO.EngineeringModelSetup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EngineeringModelSetupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["activeDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - engineeringModelSetup.ActiveDomain.AddRange(jObject["activeDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actor"].IsNullOrEmpty()) + var engineeringModelSetup = new CDP4Common.DTO.EngineeringModelSetup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("activeDomain"u8, out var activeDomainProperty) && activeDomainProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.Actor = jObject["actor"].ToObject(); + foreach(var element in activeDomainProperty.EnumerateArray()) + { + engineeringModelSetup.ActiveDomain.Add(element.GetGuid()); + } } - if (!jObject["alias"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + engineeringModelSetup.Alias.Add(element.GetGuid()); + } } - if (!jObject["defaultOrganizationalParticipant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultOrganizationalParticipant"u8, out var defaultOrganizationalParticipantProperty)) { - engineeringModelSetup.DefaultOrganizationalParticipant = jObject["defaultOrganizationalParticipant"].ToObject(); + if(defaultOrganizationalParticipantProperty.ValueKind == JsonValueKind.Null) + { + engineeringModelSetup.DefaultOrganizationalParticipant = null; + } + else + { + engineeringModelSetup.DefaultOrganizationalParticipant = defaultOrganizationalParticipantProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + engineeringModelSetup.Definition.Add(element.GetGuid()); + } } - if (!jObject["engineeringModelIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("engineeringModelIid"u8, out var engineeringModelIidProperty)) { - engineeringModelSetup.EngineeringModelIid = jObject["engineeringModelIid"].ToObject(); + if(engineeringModelIidProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale engineeringModelIid property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.EngineeringModelIid = engineeringModelIidProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + engineeringModelSetup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + engineeringModelSetup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + engineeringModelSetup.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["iterationSetup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("iterationSetup"u8, out var iterationSetupProperty) && iterationSetupProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.IterationSetup.AddRange(jObject["iterationSetup"].ToObject>()); + foreach(var element in iterationSetupProperty.EnumerateArray()) + { + engineeringModelSetup.IterationSetup.Add(element.GetGuid()); + } } - if (!jObject["kind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("kind"u8, out var kindProperty)) { - engineeringModelSetup.Kind = jObject["kind"].ToObject(); + if(kindProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale kind property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.Kind = EngineeringModelKindDeserializer.Deserialize(kindProperty); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - engineeringModelSetup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - engineeringModelSetup.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.Name = nameProperty.GetString(); + } } - if (!jObject["organizationalParticipant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organizationalParticipant"u8, out var organizationalParticipantProperty) && organizationalParticipantProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.OrganizationalParticipant.AddRange(jObject["organizationalParticipant"].ToObject>()); + foreach(var element in organizationalParticipantProperty.EnumerateArray()) + { + engineeringModelSetup.OrganizationalParticipant.Add(element.GetGuid()); + } } - if (!jObject["participant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("participant"u8, out var participantProperty) && participantProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.Participant.AddRange(jObject["participant"].ToObject>()); + foreach(var element in participantProperty.EnumerateArray()) + { + engineeringModelSetup.Participant.Add(element.GetGuid()); + } } - if (!jObject["requiredRdl"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requiredRdl"u8, out var requiredRdlProperty) && requiredRdlProperty.ValueKind != JsonValueKind.Null) { - engineeringModelSetup.RequiredRdl.AddRange(jObject["requiredRdl"].ToObject>()); + foreach(var element in requiredRdlProperty.EnumerateArray()) + { + engineeringModelSetup.RequiredRdl.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - engineeringModelSetup.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceEngineeringModelSetupIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceEngineeringModelSetupIid"u8, out var sourceEngineeringModelSetupIidProperty)) { - engineeringModelSetup.SourceEngineeringModelSetupIid = jObject["sourceEngineeringModelSetupIid"].ToObject(); + if(sourceEngineeringModelSetupIidProperty.ValueKind == JsonValueKind.Null) + { + engineeringModelSetup.SourceEngineeringModelSetupIid = null; + } + else + { + engineeringModelSetup.SourceEngineeringModelSetupIid = sourceEngineeringModelSetupIidProperty.GetGuid(); + } } - if (!jObject["studyPhase"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("studyPhase"u8, out var studyPhaseProperty)) { - engineeringModelSetup.StudyPhase = jObject["studyPhase"].ToObject(); + if(studyPhaseProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale studyPhase property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.StudyPhase = StudyPhaseKindDeserializer.Deserialize(studyPhaseProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - engineeringModelSetup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the engineeringModelSetup {id} is null", engineeringModelSetup.Iid); + } + else + { + engineeringModelSetup.ThingPreference = thingPreferenceProperty.GetString(); + } } return engineeringModelSetup; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs index a6f30859f..d11b4fabc 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,106 +28,179 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EnumerationParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EnumerationParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EnumerationParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var enumerationParameterType = new CDP4Common.DTO.EnumerationParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EnumerationParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - enumerationParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var enumerationParameterType = new CDP4Common.DTO.EnumerationParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + enumerationParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["allowMultiSelect"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("allowMultiSelect"u8, out var allowMultiSelectProperty)) { - enumerationParameterType.AllowMultiSelect = jObject["allowMultiSelect"].ToObject(); + if(allowMultiSelectProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale allowMultiSelect property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.AllowMultiSelect = allowMultiSelectProperty.GetBoolean(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + enumerationParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + enumerationParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + enumerationParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + enumerationParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - enumerationParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + enumerationParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - enumerationParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - enumerationParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - enumerationParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - enumerationParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - enumerationParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - enumerationParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the enumerationParameterType {id} is null", enumerationParameterType.Iid); + } + else + { + enumerationParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty)) { - enumerationParameterType.ValueDefinition.AddRange(jObject["valueDefinition"].ToOrderedItemCollection()); + enumerationParameterType.ValueDefinition.AddRange(valueDefinitionProperty.ToOrderedItemCollection()); } return enumerationParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs index bb9df663f..7f41d597b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/EnumerationValueDefinitionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,130 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class EnumerationValueDefinitionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.EnumerationValueDefinition FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.EnumerationValueDefinition FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var enumerationValueDefinition = new CDP4Common.DTO.EnumerationValueDefinition(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the EnumerationValueDefinitionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - enumerationValueDefinition.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var enumerationValueDefinition = new CDP4Common.DTO.EnumerationValueDefinition(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - enumerationValueDefinition.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + enumerationValueDefinition.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - enumerationValueDefinition.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + enumerationValueDefinition.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - enumerationValueDefinition.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + enumerationValueDefinition.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - enumerationValueDefinition.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + enumerationValueDefinition.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - enumerationValueDefinition.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + enumerationValueDefinition.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - enumerationValueDefinition.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); + } + else + { + enumerationValueDefinition.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - enumerationValueDefinition.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); + } + else + { + enumerationValueDefinition.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - enumerationValueDefinition.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); + } + else + { + enumerationValueDefinition.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - enumerationValueDefinition.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the enumerationValueDefinition {id} is null", enumerationValueDefinition.Iid); + } + else + { + enumerationValueDefinition.ThingPreference = thingPreferenceProperty.GetString(); + } } return enumerationValueDefinition; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs index c1d3c2fe5..950fef19b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExclusiveOrExpressionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,61 +28,90 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ExclusiveOrExpressionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ExclusiveOrExpression FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ExclusiveOrExpression FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var exclusiveOrExpression = new CDP4Common.DTO.ExclusiveOrExpression(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ExclusiveOrExpressionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - exclusiveOrExpression.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var exclusiveOrExpression = new CDP4Common.DTO.ExclusiveOrExpression(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - exclusiveOrExpression.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + exclusiveOrExpression.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - exclusiveOrExpression.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + exclusiveOrExpression.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - exclusiveOrExpression.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the exclusiveOrExpression {id} is null", exclusiveOrExpression.Iid); + } + else + { + exclusiveOrExpression.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["term"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("term"u8, out var termProperty) && termProperty.ValueKind != JsonValueKind.Null) { - exclusiveOrExpression.Term.AddRange(jObject["term"].ToObject>()); + foreach(var element in termProperty.EnumerateArray()) + { + exclusiveOrExpression.Term.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - exclusiveOrExpression.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the exclusiveOrExpression {id} is null", exclusiveOrExpression.Iid); + } + else + { + exclusiveOrExpression.ThingPreference = thingPreferenceProperty.GetString(); + } } return exclusiveOrExpression; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs index 68ed0909c..2283d6bc8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ExternalIdentifierMapResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,162 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ExternalIdentifierMapResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ExternalIdentifierMap FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ExternalIdentifierMap FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var externalIdentifierMap = new CDP4Common.DTO.ExternalIdentifierMap(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ExternalIdentifierMapResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - externalIdentifierMap.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["correspondence"].IsNullOrEmpty()) + var externalIdentifierMap = new CDP4Common.DTO.ExternalIdentifierMap(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("correspondence"u8, out var correspondenceProperty) && correspondenceProperty.ValueKind != JsonValueKind.Null) { - externalIdentifierMap.Correspondence.AddRange(jObject["correspondence"].ToObject>()); + foreach(var element in correspondenceProperty.EnumerateArray()) + { + externalIdentifierMap.Correspondence.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - externalIdentifierMap.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + externalIdentifierMap.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - externalIdentifierMap.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + externalIdentifierMap.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["externalFormat"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalFormat"u8, out var externalFormatProperty)) { - externalIdentifierMap.ExternalFormat = jObject["externalFormat"].ToObject(); + if(externalFormatProperty.ValueKind == JsonValueKind.Null) + { + externalIdentifierMap.ExternalFormat = null; + } + else + { + externalIdentifierMap.ExternalFormat = externalFormatProperty.GetGuid(); + } } - if (!jObject["externalModelName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalModelName"u8, out var externalModelNameProperty)) { - externalIdentifierMap.ExternalModelName = jObject["externalModelName"].ToObject(); + if(externalModelNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale externalModelName property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.ExternalModelName = externalModelNameProperty.GetString(); + } } - if (!jObject["externalToolName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalToolName"u8, out var externalToolNameProperty)) { - externalIdentifierMap.ExternalToolName = jObject["externalToolName"].ToObject(); + if(externalToolNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale externalToolName property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.ExternalToolName = externalToolNameProperty.GetString(); + } } - if (!jObject["externalToolVersion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalToolVersion"u8, out var externalToolVersionProperty)) { - externalIdentifierMap.ExternalToolVersion = jObject["externalToolVersion"].ToObject(); + if(externalToolVersionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale externalToolVersion property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.ExternalToolVersion = externalToolVersionProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - externalIdentifierMap.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - externalIdentifierMap.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - externalIdentifierMap.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - externalIdentifierMap.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the externalIdentifierMap {id} is null", externalIdentifierMap.Iid); + } + else + { + externalIdentifierMap.ThingPreference = thingPreferenceProperty.GetString(); + } } return externalIdentifierMap; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs index ccd2777e4..3a1760d00 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,76 +28,122 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class FileResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.File FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.File FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var file = new CDP4Common.DTO.File(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the FileResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - file.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var file = new CDP4Common.DTO.File(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - file.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + file.Category.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - file.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + file.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - file.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + file.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fileRevision"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fileRevision"u8, out var fileRevisionProperty) && fileRevisionProperty.ValueKind != JsonValueKind.Null) { - file.FileRevision.AddRange(jObject["fileRevision"].ToObject>()); + foreach(var element in fileRevisionProperty.EnumerateArray()) + { + file.FileRevision.Add(element.GetGuid()); + } } - if (!jObject["lockedBy"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("lockedBy"u8, out var lockedByProperty)) { - file.LockedBy = jObject["lockedBy"].ToObject(); + if(lockedByProperty.ValueKind == JsonValueKind.Null) + { + file.LockedBy = null; + } + else + { + file.LockedBy = lockedByProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - file.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the file {id} is null", file.Iid); + } + else + { + file.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - file.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the file {id} is null", file.Iid); + } + else + { + file.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - file.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the file {id} is null", file.Iid); + } + else + { + file.ThingPreference = thingPreferenceProperty.GetString(); + } } return file; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs index 50725bbf8..8043ec649 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileRevisionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,147 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class FileRevisionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.FileRevision FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.FileRevision FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var fileRevision = new CDP4Common.DTO.FileRevision(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the FileRevisionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - fileRevision.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["containingFolder"].IsNullOrEmpty()) + var fileRevision = new CDP4Common.DTO.FileRevision(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("containingFolder"u8, out var containingFolderProperty)) { - fileRevision.ContainingFolder = jObject["containingFolder"].ToObject(); + if(containingFolderProperty.ValueKind == JsonValueKind.Null) + { + fileRevision.ContainingFolder = null; + } + else + { + fileRevision.ContainingFolder = containingFolderProperty.GetGuid(); + } } - if (!jObject["contentHash"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("contentHash"u8, out var contentHashProperty)) { - fileRevision.ContentHash = jObject["contentHash"].ToObject(); + if(contentHashProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale contentHash property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.ContentHash = contentHashProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - fileRevision.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["creator"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("creator"u8, out var creatorProperty)) { - fileRevision.Creator = jObject["creator"].ToObject(); + if(creatorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale creator property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.Creator = creatorProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - fileRevision.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + fileRevision.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - fileRevision.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + fileRevision.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fileType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fileType"u8, out var fileTypeProperty)) { - fileRevision.FileType.AddRange(jObject["fileType"].ToOrderedItemCollection()); + fileRevision.FileType.AddRange(fileTypeProperty.ToOrderedItemCollection()); } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - fileRevision.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - fileRevision.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - fileRevision.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the fileRevision {id} is null", fileRevision.Iid); + } + else + { + fileRevision.ThingPreference = thingPreferenceProperty.GetString(); + } } return fileRevision; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs index 79bc00a1f..a645e5341 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FileTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,162 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class FileTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.FileType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.FileType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var fileType = new CDP4Common.DTO.FileType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the FileTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - fileType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var fileType = new CDP4Common.DTO.FileType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - fileType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + fileType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - fileType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + fileType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - fileType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + fileType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - fileType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + fileType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - fileType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + fileType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["extension"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("extension"u8, out var extensionProperty)) { - fileType.Extension = jObject["extension"].ToObject(); + if(extensionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale extension property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.Extension = extensionProperty.GetString(); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - fileType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + fileType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - fileType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - fileType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - fileType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - fileType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - fileType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the fileType {id} is null", fileType.Iid); + } + else + { + fileType.ThingPreference = thingPreferenceProperty.GetString(); + } } return fileType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs index 7666608a3..63f9f95d5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/FolderResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,142 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class FolderResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Folder FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Folder FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var folder = new CDP4Common.DTO.Folder(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the FolderResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - folder.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["containingFolder"].IsNullOrEmpty()) + var folder = new CDP4Common.DTO.Folder(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("containingFolder"u8, out var containingFolderProperty)) { - folder.ContainingFolder = jObject["containingFolder"].ToObject(); + if(containingFolderProperty.ValueKind == JsonValueKind.Null) + { + folder.ContainingFolder = null; + } + else + { + folder.ContainingFolder = containingFolderProperty.GetGuid(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - folder.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the folder {id} is null", folder.Iid); + } + else + { + folder.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["creator"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("creator"u8, out var creatorProperty)) { - folder.Creator = jObject["creator"].ToObject(); + if(creatorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale creator property of the folder {id} is null", folder.Iid); + } + else + { + folder.Creator = creatorProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - folder.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + folder.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - folder.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + folder.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - folder.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the folder {id} is null", folder.Iid); + } + else + { + folder.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - folder.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the folder {id} is null", folder.Iid); + } + else + { + folder.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - folder.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the folder {id} is null", folder.Iid); + } + else + { + folder.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - folder.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the folder {id} is null", folder.Iid); + } + else + { + folder.ThingPreference = thingPreferenceProperty.GetString(); + } } return folder; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs index 216ffe26c..da5022e50 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/GlossaryResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,158 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class GlossaryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Glossary FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Glossary FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var glossary = new CDP4Common.DTO.Glossary(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the GlossaryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - glossary.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var glossary = new CDP4Common.DTO.Glossary(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - glossary.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + glossary.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - glossary.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + glossary.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - glossary.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + glossary.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - glossary.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + glossary.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - glossary.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + glossary.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - glossary.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + glossary.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - glossary.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the glossary {id} is null", glossary.Iid); + } + else + { + glossary.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - glossary.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the glossary {id} is null", glossary.Iid); + } + else + { + glossary.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - glossary.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the glossary {id} is null", glossary.Iid); + } + else + { + glossary.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - glossary.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the glossary {id} is null", glossary.Iid); + } + else + { + glossary.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["term"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("term"u8, out var termProperty) && termProperty.ValueKind != JsonValueKind.Null) { - glossary.Term.AddRange(jObject["term"].ToObject>()); + foreach(var element in termProperty.EnumerateArray()) + { + glossary.Term.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - glossary.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the glossary {id} is null", glossary.Iid); + } + else + { + glossary.ThingPreference = thingPreferenceProperty.GetString(); + } } return glossary; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs index 49e10b6a9..a37b35c01 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/GoalResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,138 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class GoalResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Goal FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Goal FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var goal = new CDP4Common.DTO.Goal(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the GoalResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - goal.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var goal = new CDP4Common.DTO.Goal(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - goal.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + goal.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - goal.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + goal.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - goal.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + goal.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - goal.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + goal.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - goal.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + goal.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - goal.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + goal.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - goal.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the goal {id} is null", goal.Iid); + } + else + { + goal.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - goal.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the goal {id} is null", goal.Iid); + } + else + { + goal.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - goal.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the goal {id} is null", goal.Iid); + } + else + { + goal.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - goal.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the goal {id} is null", goal.Iid); + } + else + { + goal.ThingPreference = thingPreferenceProperty.GetString(); + } } return goal; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs index c9aeb8e77..d94fbce3d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/HyperLinkResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,118 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class HyperLinkResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.HyperLink FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.HyperLink FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var hyperLink = new CDP4Common.DTO.HyperLink(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the HyperLinkResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - hyperLink.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["content"].IsNullOrEmpty()) + var hyperLink = new CDP4Common.DTO.HyperLink(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - hyperLink.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the hyperLink {id} is null", hyperLink.Iid); + } + else + { + hyperLink.Content = contentProperty.GetString(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - hyperLink.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + hyperLink.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - hyperLink.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + hyperLink.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - hyperLink.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the hyperLink {id} is null", hyperLink.Iid); + } + else + { + hyperLink.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - hyperLink.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the hyperLink {id} is null", hyperLink.Iid); + } + else + { + hyperLink.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - hyperLink.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the hyperLink {id} is null", hyperLink.Iid); + } + else + { + hyperLink.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["uri"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("uri"u8, out var uriProperty)) { - hyperLink.Uri = jObject["uri"].ToObject(); + if(uriProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale uri property of the hyperLink {id} is null", hyperLink.Iid); + } + else + { + hyperLink.Uri = uriProperty.GetString(); + } } return hyperLink; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs index bbcebe19a..d87de4344 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IdCorrespondenceResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,106 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class IdCorrespondenceResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.IdCorrespondence FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.IdCorrespondence FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var idCorrespondence = new CDP4Common.DTO.IdCorrespondence(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the IdCorrespondenceResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - idCorrespondence.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var idCorrespondence = new CDP4Common.DTO.IdCorrespondence(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - idCorrespondence.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + idCorrespondence.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - idCorrespondence.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + idCorrespondence.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["externalId"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalId"u8, out var externalIdProperty)) { - idCorrespondence.ExternalId = jObject["externalId"].ToObject(); + if(externalIdProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale externalId property of the idCorrespondence {id} is null", idCorrespondence.Iid); + } + else + { + idCorrespondence.ExternalId = externalIdProperty.GetString(); + } } - if (!jObject["internalThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("internalThing"u8, out var internalThingProperty)) { - idCorrespondence.InternalThing = jObject["internalThing"].ToObject(); + if(internalThingProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale internalThing property of the idCorrespondence {id} is null", idCorrespondence.Iid); + } + else + { + idCorrespondence.InternalThing = internalThingProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - idCorrespondence.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the idCorrespondence {id} is null", idCorrespondence.Iid); + } + else + { + idCorrespondence.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - idCorrespondence.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the idCorrespondence {id} is null", idCorrespondence.Iid); + } + else + { + idCorrespondence.ThingPreference = thingPreferenceProperty.GetString(); + } } return idCorrespondence; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs index bfb676f0b..0617d32e9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IndependentParameterTypeAssignmentResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,106 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class IndependentParameterTypeAssignmentResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.IndependentParameterTypeAssignment FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.IndependentParameterTypeAssignment FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var independentParameterTypeAssignment = new CDP4Common.DTO.IndependentParameterTypeAssignment(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the IndependentParameterTypeAssignmentResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - independentParameterTypeAssignment.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var independentParameterTypeAssignment = new CDP4Common.DTO.IndependentParameterTypeAssignment(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - independentParameterTypeAssignment.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + independentParameterTypeAssignment.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - independentParameterTypeAssignment.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + independentParameterTypeAssignment.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["measurementScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("measurementScale"u8, out var measurementScaleProperty)) { - independentParameterTypeAssignment.MeasurementScale = jObject["measurementScale"].ToObject(); + if(measurementScaleProperty.ValueKind == JsonValueKind.Null) + { + independentParameterTypeAssignment.MeasurementScale = null; + } + else + { + independentParameterTypeAssignment.MeasurementScale = measurementScaleProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - independentParameterTypeAssignment.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the independentParameterTypeAssignment {id} is null", independentParameterTypeAssignment.Iid); + } + else + { + independentParameterTypeAssignment.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - independentParameterTypeAssignment.ParameterType = jObject["parameterType"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the independentParameterTypeAssignment {id} is null", independentParameterTypeAssignment.Iid); + } + else + { + independentParameterTypeAssignment.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - independentParameterTypeAssignment.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the independentParameterTypeAssignment {id} is null", independentParameterTypeAssignment.Iid); + } + else + { + independentParameterTypeAssignment.ThingPreference = thingPreferenceProperty.GetString(); + } } return independentParameterTypeAssignment; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs index 7a18d3c5b..2ee94f5ed 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IntervalScaleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,136 +28,254 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class IntervalScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.IntervalScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.IntervalScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var intervalScale = new CDP4Common.DTO.IntervalScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the IntervalScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - intervalScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var intervalScale = new CDP4Common.DTO.IntervalScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - intervalScale.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + intervalScale.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - intervalScale.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + intervalScale.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - intervalScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + intervalScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - intervalScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + intervalScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - intervalScale.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + intervalScale.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - intervalScale.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isMaximumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMaximumInclusive"u8, out var isMaximumInclusiveProperty)) { - intervalScale.IsMaximumInclusive = jObject["isMaximumInclusive"].ToObject(); + if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMaximumInclusive property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.IsMaximumInclusive = isMaximumInclusiveProperty.GetBoolean(); + } } - if (!jObject["isMinimumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMinimumInclusive"u8, out var isMinimumInclusiveProperty)) { - intervalScale.IsMinimumInclusive = jObject["isMinimumInclusive"].ToObject(); + if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMinimumInclusive property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.IsMinimumInclusive = isMinimumInclusiveProperty.GetBoolean(); + } } - if (!jObject["mappingToReferenceScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("mappingToReferenceScale"u8, out var mappingToReferenceScaleProperty) && mappingToReferenceScaleProperty.ValueKind != JsonValueKind.Null) { - intervalScale.MappingToReferenceScale.AddRange(jObject["mappingToReferenceScale"].ToObject>()); + foreach(var element in mappingToReferenceScaleProperty.EnumerateArray()) + { + intervalScale.MappingToReferenceScale.Add(element.GetGuid()); + } } - if (!jObject["maximumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maximumPermissibleValue"u8, out var maximumPermissibleValueProperty)) { - intervalScale.MaximumPermissibleValue = jObject["maximumPermissibleValue"].ToObject(); + if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale maximumPermissibleValue property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.MaximumPermissibleValue = maximumPermissibleValueProperty.GetString(); + } } - if (!jObject["minimumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minimumPermissibleValue"u8, out var minimumPermissibleValueProperty)) { - intervalScale.MinimumPermissibleValue = jObject["minimumPermissibleValue"].ToObject(); + if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale minimumPermissibleValue property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.MinimumPermissibleValue = minimumPermissibleValueProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - intervalScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - intervalScale.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.Name = nameProperty.GetString(); + } } - if (!jObject["negativeValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("negativeValueConnotation"u8, out var negativeValueConnotationProperty)) { - intervalScale.NegativeValueConnotation = jObject["negativeValueConnotation"].ToObject(); + if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale negativeValueConnotation property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.NegativeValueConnotation = negativeValueConnotationProperty.GetString(); + } } - if (!jObject["numberSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("numberSet"u8, out var numberSetProperty)) { - intervalScale.NumberSet = jObject["numberSet"].ToObject(); + if(numberSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale numberSet property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.NumberSet = NumberSetKindDeserializer.Deserialize(numberSetProperty); + } } - if (!jObject["positiveValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("positiveValueConnotation"u8, out var positiveValueConnotationProperty)) { - intervalScale.PositiveValueConnotation = jObject["positiveValueConnotation"].ToObject(); + if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale positiveValueConnotation property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.PositiveValueConnotation = positiveValueConnotationProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - intervalScale.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - intervalScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - intervalScale.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale unit property of the intervalScale {id} is null", intervalScale.Iid); + } + else + { + intervalScale.Unit = unitProperty.GetGuid(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty) && valueDefinitionProperty.ValueKind != JsonValueKind.Null) { - intervalScale.ValueDefinition.AddRange(jObject["valueDefinition"].ToObject>()); + foreach(var element in valueDefinitionProperty.EnumerateArray()) + { + intervalScale.ValueDefinition.Add(element.GetGuid()); + } } return intervalScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs index 61728e3fb..4a0ff8ff6 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,161 +28,263 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class IterationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Iteration FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Iteration FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var iteration = new CDP4Common.DTO.Iteration(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the IterationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - iteration.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actualFiniteStateList"].IsNullOrEmpty()) + var iteration = new CDP4Common.DTO.Iteration(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("actualFiniteStateList"u8, out var actualFiniteStateListProperty) && actualFiniteStateListProperty.ValueKind != JsonValueKind.Null) { - iteration.ActualFiniteStateList.AddRange(jObject["actualFiniteStateList"].ToObject>()); + foreach(var element in actualFiniteStateListProperty.EnumerateArray()) + { + iteration.ActualFiniteStateList.Add(element.GetGuid()); + } } - if (!jObject["defaultOption"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultOption"u8, out var defaultOptionProperty)) { - iteration.DefaultOption = jObject["defaultOption"].ToObject(); + if(defaultOptionProperty.ValueKind == JsonValueKind.Null) + { + iteration.DefaultOption = null; + } + else + { + iteration.DefaultOption = defaultOptionProperty.GetGuid(); + } } - if (!jObject["diagramCanvas"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("diagramCanvas"u8, out var diagramCanvasProperty) && diagramCanvasProperty.ValueKind != JsonValueKind.Null) { - iteration.DiagramCanvas.AddRange(jObject["diagramCanvas"].ToObject>()); + foreach(var element in diagramCanvasProperty.EnumerateArray()) + { + iteration.DiagramCanvas.Add(element.GetGuid()); + } } - if (!jObject["domainFileStore"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("domainFileStore"u8, out var domainFileStoreProperty) && domainFileStoreProperty.ValueKind != JsonValueKind.Null) { - iteration.DomainFileStore.AddRange(jObject["domainFileStore"].ToObject>()); + foreach(var element in domainFileStoreProperty.EnumerateArray()) + { + iteration.DomainFileStore.Add(element.GetGuid()); + } } - if (!jObject["element"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("element"u8, out var elementProperty) && elementProperty.ValueKind != JsonValueKind.Null) { - iteration.Element.AddRange(jObject["element"].ToObject>()); + foreach(var element in elementProperty.EnumerateArray()) + { + iteration.Element.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - iteration.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + iteration.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - iteration.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + iteration.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["externalIdentifierMap"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("externalIdentifierMap"u8, out var externalIdentifierMapProperty) && externalIdentifierMapProperty.ValueKind != JsonValueKind.Null) { - iteration.ExternalIdentifierMap.AddRange(jObject["externalIdentifierMap"].ToObject>()); + foreach(var element in externalIdentifierMapProperty.EnumerateArray()) + { + iteration.ExternalIdentifierMap.Add(element.GetGuid()); + } } - if (!jObject["goal"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("goal"u8, out var goalProperty) && goalProperty.ValueKind != JsonValueKind.Null) { - iteration.Goal.AddRange(jObject["goal"].ToObject>()); + foreach(var element in goalProperty.EnumerateArray()) + { + iteration.Goal.Add(element.GetGuid()); + } } - if (!jObject["iterationSetup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("iterationSetup"u8, out var iterationSetupProperty)) { - iteration.IterationSetup = jObject["iterationSetup"].ToObject(); + if(iterationSetupProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale iterationSetup property of the iteration {id} is null", iteration.Iid); + } + else + { + iteration.IterationSetup = iterationSetupProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - iteration.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the iteration {id} is null", iteration.Iid); + } + else + { + iteration.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["option"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("option"u8, out var optionProperty)) { - iteration.Option.AddRange(jObject["option"].ToOrderedItemCollection()); + iteration.Option.AddRange(optionProperty.ToOrderedItemCollection()); } - if (!jObject["possibleFiniteStateList"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleFiniteStateList"u8, out var possibleFiniteStateListProperty) && possibleFiniteStateListProperty.ValueKind != JsonValueKind.Null) { - iteration.PossibleFiniteStateList.AddRange(jObject["possibleFiniteStateList"].ToObject>()); + foreach(var element in possibleFiniteStateListProperty.EnumerateArray()) + { + iteration.PossibleFiniteStateList.Add(element.GetGuid()); + } } - if (!jObject["publication"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("publication"u8, out var publicationProperty) && publicationProperty.ValueKind != JsonValueKind.Null) { - iteration.Publication.AddRange(jObject["publication"].ToObject>()); + foreach(var element in publicationProperty.EnumerateArray()) + { + iteration.Publication.Add(element.GetGuid()); + } } - if (!jObject["relationship"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relationship"u8, out var relationshipProperty) && relationshipProperty.ValueKind != JsonValueKind.Null) { - iteration.Relationship.AddRange(jObject["relationship"].ToObject>()); + foreach(var element in relationshipProperty.EnumerateArray()) + { + iteration.Relationship.Add(element.GetGuid()); + } } - if (!jObject["requirementsSpecification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requirementsSpecification"u8, out var requirementsSpecificationProperty) && requirementsSpecificationProperty.ValueKind != JsonValueKind.Null) { - iteration.RequirementsSpecification.AddRange(jObject["requirementsSpecification"].ToObject>()); + foreach(var element in requirementsSpecificationProperty.EnumerateArray()) + { + iteration.RequirementsSpecification.Add(element.GetGuid()); + } } - if (!jObject["ruleVerificationList"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("ruleVerificationList"u8, out var ruleVerificationListProperty) && ruleVerificationListProperty.ValueKind != JsonValueKind.Null) { - iteration.RuleVerificationList.AddRange(jObject["ruleVerificationList"].ToObject>()); + foreach(var element in ruleVerificationListProperty.EnumerateArray()) + { + iteration.RuleVerificationList.Add(element.GetGuid()); + } } - if (!jObject["sharedDiagramStyle"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sharedDiagramStyle"u8, out var sharedDiagramStyleProperty) && sharedDiagramStyleProperty.ValueKind != JsonValueKind.Null) { - iteration.SharedDiagramStyle.AddRange(jObject["sharedDiagramStyle"].ToObject>()); + foreach(var element in sharedDiagramStyleProperty.EnumerateArray()) + { + iteration.SharedDiagramStyle.Add(element.GetGuid()); + } } - if (!jObject["sourceIterationIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceIterationIid"u8, out var sourceIterationIidProperty)) { - iteration.SourceIterationIid = jObject["sourceIterationIid"].ToObject(); + if(sourceIterationIidProperty.ValueKind == JsonValueKind.Null) + { + iteration.SourceIterationIid = null; + } + else + { + iteration.SourceIterationIid = sourceIterationIidProperty.GetGuid(); + } } - if (!jObject["stakeholder"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholder"u8, out var stakeholderProperty) && stakeholderProperty.ValueKind != JsonValueKind.Null) { - iteration.Stakeholder.AddRange(jObject["stakeholder"].ToObject>()); + foreach(var element in stakeholderProperty.EnumerateArray()) + { + iteration.Stakeholder.Add(element.GetGuid()); + } } - if (!jObject["stakeholderValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholderValue"u8, out var stakeholderValueProperty) && stakeholderValueProperty.ValueKind != JsonValueKind.Null) { - iteration.StakeholderValue.AddRange(jObject["stakeholderValue"].ToObject>()); + foreach(var element in stakeholderValueProperty.EnumerateArray()) + { + iteration.StakeholderValue.Add(element.GetGuid()); + } } - if (!jObject["stakeholderValueMap"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholderValueMap"u8, out var stakeholderValueMapProperty) && stakeholderValueMapProperty.ValueKind != JsonValueKind.Null) { - iteration.StakeholderValueMap.AddRange(jObject["stakeholderValueMap"].ToObject>()); + foreach(var element in stakeholderValueMapProperty.EnumerateArray()) + { + iteration.StakeholderValueMap.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - iteration.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the iteration {id} is null", iteration.Iid); + } + else + { + iteration.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["topElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("topElement"u8, out var topElementProperty)) { - iteration.TopElement = jObject["topElement"].ToObject(); + if(topElementProperty.ValueKind == JsonValueKind.Null) + { + iteration.TopElement = null; + } + else + { + iteration.TopElement = topElementProperty.GetGuid(); + } } - if (!jObject["valueGroup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueGroup"u8, out var valueGroupProperty) && valueGroupProperty.ValueKind != JsonValueKind.Null) { - iteration.ValueGroup.AddRange(jObject["valueGroup"].ToObject>()); + foreach(var element in valueGroupProperty.EnumerateArray()) + { + iteration.ValueGroup.Add(element.GetGuid()); + } } return iteration; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs index acd9be70a..b19ad1c80 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/IterationSetupResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,166 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class IterationSetupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.IterationSetup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.IterationSetup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var iterationSetup = new CDP4Common.DTO.IterationSetup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the IterationSetupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - iterationSetup.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["createdOn"].IsNullOrEmpty()) + var iterationSetup = new CDP4Common.DTO.IterationSetup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - iterationSetup.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["description"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("description"u8, out var descriptionProperty)) { - iterationSetup.Description = jObject["description"].ToObject(); + if(descriptionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale description property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.Description = descriptionProperty.GetString(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - iterationSetup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + iterationSetup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - iterationSetup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + iterationSetup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["frozenOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("frozenOn"u8, out var frozenOnProperty)) { - iterationSetup.FrozenOn = jObject["frozenOn"].ToObject(); + if(frozenOnProperty.ValueKind == JsonValueKind.Null) + { + iterationSetup.FrozenOn = null; + } + else + { + iterationSetup.FrozenOn = frozenOnProperty.GetDateTime(); + } } - if (!jObject["isDeleted"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeleted"u8, out var isDeletedProperty)) { - iterationSetup.IsDeleted = jObject["isDeleted"].ToObject(); + if(isDeletedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeleted property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.IsDeleted = isDeletedProperty.GetBoolean(); + } } - if (!jObject["iterationIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("iterationIid"u8, out var iterationIidProperty)) { - iterationSetup.IterationIid = jObject["iterationIid"].ToObject(); + if(iterationIidProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale iterationIid property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.IterationIid = iterationIidProperty.GetGuid(); + } } - if (!jObject["iterationNumber"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("iterationNumber"u8, out var iterationNumberProperty)) { - iterationSetup.IterationNumber = jObject["iterationNumber"].ToObject(); + if(iterationNumberProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale iterationNumber property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.IterationNumber = iterationNumberProperty.GetInt32(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - iterationSetup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["sourceIterationSetup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceIterationSetup"u8, out var sourceIterationSetupProperty)) { - iterationSetup.SourceIterationSetup = jObject["sourceIterationSetup"].ToObject(); + if(sourceIterationSetupProperty.ValueKind == JsonValueKind.Null) + { + iterationSetup.SourceIterationSetup = null; + } + else + { + iterationSetup.SourceIterationSetup = sourceIterationSetupProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - iterationSetup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the iterationSetup {id} is null", iterationSetup.Iid); + } + else + { + iterationSetup.ThingPreference = thingPreferenceProperty.GetString(); + } } return iterationSetup; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs index b94f3d8e0..16f446464 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LinearConversionUnitResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,166 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class LinearConversionUnitResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.LinearConversionUnit FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.LinearConversionUnit FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var linearConversionUnit = new CDP4Common.DTO.LinearConversionUnit(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the LinearConversionUnitResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - linearConversionUnit.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var linearConversionUnit = new CDP4Common.DTO.LinearConversionUnit(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - linearConversionUnit.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + linearConversionUnit.Alias.Add(element.GetGuid()); + } } - if (!jObject["conversionFactor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("conversionFactor"u8, out var conversionFactorProperty)) { - linearConversionUnit.ConversionFactor = jObject["conversionFactor"].ToObject(); + if(conversionFactorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale conversionFactor property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.ConversionFactor = conversionFactorProperty.GetString(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - linearConversionUnit.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + linearConversionUnit.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - linearConversionUnit.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + linearConversionUnit.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - linearConversionUnit.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + linearConversionUnit.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - linearConversionUnit.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + linearConversionUnit.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - linearConversionUnit.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - linearConversionUnit.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - linearConversionUnit.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.Name = nameProperty.GetString(); + } } - if (!jObject["referenceUnit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceUnit"u8, out var referenceUnitProperty)) { - linearConversionUnit.ReferenceUnit = jObject["referenceUnit"].ToObject(); + if(referenceUnitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referenceUnit property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.ReferenceUnit = referenceUnitProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - linearConversionUnit.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - linearConversionUnit.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the linearConversionUnit {id} is null", linearConversionUnit.Iid); + } + else + { + linearConversionUnit.ThingPreference = thingPreferenceProperty.GetString(); + } } return linearConversionUnit; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs index 480ae3e55..509d2322e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogEntryChangelogItemResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,76 +28,126 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class LogEntryChangelogItemResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.LogEntryChangelogItem FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.LogEntryChangelogItem FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var logEntryChangelogItem = new CDP4Common.DTO.LogEntryChangelogItem(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the LogEntryChangelogItemResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - logEntryChangelogItem.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["affectedItemIid"].IsNullOrEmpty()) + var logEntryChangelogItem = new CDP4Common.DTO.LogEntryChangelogItem(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("affectedItemIid"u8, out var affectedItemIidProperty)) { - logEntryChangelogItem.AffectedItemIid = jObject["affectedItemIid"].ToObject(); + if(affectedItemIidProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale affectedItemIid property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + } + else + { + logEntryChangelogItem.AffectedItemIid = affectedItemIidProperty.GetGuid(); + } } - if (!jObject["affectedReferenceIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("affectedReferenceIid"u8, out var affectedReferenceIidProperty) && affectedReferenceIidProperty.ValueKind != JsonValueKind.Null) { - logEntryChangelogItem.AffectedReferenceIid.AddRange(jObject["affectedReferenceIid"].ToObject>()); + foreach(var element in affectedReferenceIidProperty.EnumerateArray()) + { + logEntryChangelogItem.AffectedReferenceIid.Add(element.GetGuid()); + } } - if (!jObject["changeDescription"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("changeDescription"u8, out var changeDescriptionProperty)) { - logEntryChangelogItem.ChangeDescription = jObject["changeDescription"].ToObject(); + if(changeDescriptionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale changeDescription property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + } + else + { + logEntryChangelogItem.ChangeDescription = changeDescriptionProperty.GetString(); + } } - if (!jObject["changelogKind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("changelogKind"u8, out var changelogKindProperty)) { - logEntryChangelogItem.ChangelogKind = jObject["changelogKind"].ToObject(); + if(changelogKindProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale changelogKind property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + } + else + { + logEntryChangelogItem.ChangelogKind = LogEntryChangelogItemKindDeserializer.Deserialize(changelogKindProperty); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - logEntryChangelogItem.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + logEntryChangelogItem.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - logEntryChangelogItem.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + logEntryChangelogItem.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - logEntryChangelogItem.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + } + else + { + logEntryChangelogItem.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - logEntryChangelogItem.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the logEntryChangelogItem {id} is null", logEntryChangelogItem.Iid); + } + else + { + logEntryChangelogItem.ThingPreference = thingPreferenceProperty.GetString(); + } } return logEntryChangelogItem; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs index 5af4cfd53..7564addd3 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/LogarithmicScaleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,161 +28,310 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class LogarithmicScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.LogarithmicScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var logarithmicScale = new CDP4Common.DTO.LogarithmicScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the LogarithmicScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - logarithmicScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var logarithmicScale = new CDP4Common.DTO.LogarithmicScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + logarithmicScale.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + logarithmicScale.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + logarithmicScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + logarithmicScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["exponent"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("exponent"u8, out var exponentProperty)) { - logarithmicScale.Exponent = jObject["exponent"].ToObject(); + if(exponentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale exponent property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.Exponent = exponentProperty.GetString(); + } } - if (!jObject["factor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("factor"u8, out var factorProperty)) { - logarithmicScale.Factor = jObject["factor"].ToObject(); + if(factorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale factor property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.Factor = factorProperty.GetString(); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + logarithmicScale.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - logarithmicScale.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isMaximumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMaximumInclusive"u8, out var isMaximumInclusiveProperty)) { - logarithmicScale.IsMaximumInclusive = jObject["isMaximumInclusive"].ToObject(); + if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMaximumInclusive property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.IsMaximumInclusive = isMaximumInclusiveProperty.GetBoolean(); + } } - if (!jObject["isMinimumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMinimumInclusive"u8, out var isMinimumInclusiveProperty)) { - logarithmicScale.IsMinimumInclusive = jObject["isMinimumInclusive"].ToObject(); + if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMinimumInclusive property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.IsMinimumInclusive = isMinimumInclusiveProperty.GetBoolean(); + } } - if (!jObject["logarithmBase"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("logarithmBase"u8, out var logarithmBaseProperty)) { - logarithmicScale.LogarithmBase = jObject["logarithmBase"].ToObject(); + if(logarithmBaseProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale logarithmBase property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.LogarithmBase = LogarithmBaseKindDeserializer.Deserialize(logarithmBaseProperty); + } } - if (!jObject["mappingToReferenceScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("mappingToReferenceScale"u8, out var mappingToReferenceScaleProperty) && mappingToReferenceScaleProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.MappingToReferenceScale.AddRange(jObject["mappingToReferenceScale"].ToObject>()); + foreach(var element in mappingToReferenceScaleProperty.EnumerateArray()) + { + logarithmicScale.MappingToReferenceScale.Add(element.GetGuid()); + } } - if (!jObject["maximumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maximumPermissibleValue"u8, out var maximumPermissibleValueProperty)) { - logarithmicScale.MaximumPermissibleValue = jObject["maximumPermissibleValue"].ToObject(); + if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale maximumPermissibleValue property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.MaximumPermissibleValue = maximumPermissibleValueProperty.GetString(); + } } - if (!jObject["minimumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minimumPermissibleValue"u8, out var minimumPermissibleValueProperty)) { - logarithmicScale.MinimumPermissibleValue = jObject["minimumPermissibleValue"].ToObject(); + if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale minimumPermissibleValue property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.MinimumPermissibleValue = minimumPermissibleValueProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - logarithmicScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - logarithmicScale.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.Name = nameProperty.GetString(); + } } - if (!jObject["negativeValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("negativeValueConnotation"u8, out var negativeValueConnotationProperty)) { - logarithmicScale.NegativeValueConnotation = jObject["negativeValueConnotation"].ToObject(); + if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale negativeValueConnotation property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.NegativeValueConnotation = negativeValueConnotationProperty.GetString(); + } } - if (!jObject["numberSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("numberSet"u8, out var numberSetProperty)) { - logarithmicScale.NumberSet = jObject["numberSet"].ToObject(); + if(numberSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale numberSet property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.NumberSet = NumberSetKindDeserializer.Deserialize(numberSetProperty); + } } - if (!jObject["positiveValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("positiveValueConnotation"u8, out var positiveValueConnotationProperty)) { - logarithmicScale.PositiveValueConnotation = jObject["positiveValueConnotation"].ToObject(); + if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale positiveValueConnotation property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.PositiveValueConnotation = positiveValueConnotationProperty.GetString(); + } } - if (!jObject["referenceQuantityKind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceQuantityKind"u8, out var referenceQuantityKindProperty)) { - logarithmicScale.ReferenceQuantityKind = jObject["referenceQuantityKind"].ToObject(); + if(referenceQuantityKindProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referenceQuantityKind property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.ReferenceQuantityKind = referenceQuantityKindProperty.GetGuid(); + } } - if (!jObject["referenceQuantityValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceQuantityValue"u8, out var referenceQuantityValueProperty) && referenceQuantityValueProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.ReferenceQuantityValue.AddRange(jObject["referenceQuantityValue"].ToObject>()); + foreach(var element in referenceQuantityValueProperty.EnumerateArray()) + { + logarithmicScale.ReferenceQuantityValue.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - logarithmicScale.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - logarithmicScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - logarithmicScale.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale unit property of the logarithmicScale {id} is null", logarithmicScale.Iid); + } + else + { + logarithmicScale.Unit = unitProperty.GetGuid(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty) && valueDefinitionProperty.ValueKind != JsonValueKind.Null) { - logarithmicScale.ValueDefinition.AddRange(jObject["valueDefinition"].ToObject>()); + foreach(var element in valueDefinitionProperty.EnumerateArray()) + { + logarithmicScale.ValueDefinition.Add(element.GetGuid()); + } } return logarithmicScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs index c0c596590..ea925bbb0 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MappingToReferenceScaleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,106 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class MappingToReferenceScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.MappingToReferenceScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.MappingToReferenceScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var mappingToReferenceScale = new CDP4Common.DTO.MappingToReferenceScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the MappingToReferenceScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - mappingToReferenceScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["dependentScaleValue"].IsNullOrEmpty()) + var mappingToReferenceScale = new CDP4Common.DTO.MappingToReferenceScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("dependentScaleValue"u8, out var dependentScaleValueProperty)) { - mappingToReferenceScale.DependentScaleValue = jObject["dependentScaleValue"].ToObject(); + if(dependentScaleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale dependentScaleValue property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); + } + else + { + mappingToReferenceScale.DependentScaleValue = dependentScaleValueProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - mappingToReferenceScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + mappingToReferenceScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - mappingToReferenceScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + mappingToReferenceScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - mappingToReferenceScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); + } + else + { + mappingToReferenceScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["referenceScaleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceScaleValue"u8, out var referenceScaleValueProperty)) { - mappingToReferenceScale.ReferenceScaleValue = jObject["referenceScaleValue"].ToObject(); + if(referenceScaleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referenceScaleValue property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); + } + else + { + mappingToReferenceScale.ReferenceScaleValue = referenceScaleValueProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - mappingToReferenceScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the mappingToReferenceScale {id} is null", mappingToReferenceScale.Iid); + } + else + { + mappingToReferenceScale.ThingPreference = thingPreferenceProperty.GetString(); + } } return mappingToReferenceScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs index 16a131cd2..9124eebf8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelLogEntryResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,101 +28,174 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ModelLogEntryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ModelLogEntry FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ModelLogEntry FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var modelLogEntry = new CDP4Common.DTO.ModelLogEntry(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ModelLogEntryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - modelLogEntry.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["affectedDomainIid"].IsNullOrEmpty()) + var modelLogEntry = new CDP4Common.DTO.ModelLogEntry(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("affectedDomainIid"u8, out var affectedDomainIidProperty) && affectedDomainIidProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.AffectedDomainIid.AddRange(jObject["affectedDomainIid"].ToObject>()); + foreach(var element in affectedDomainIidProperty.EnumerateArray()) + { + modelLogEntry.AffectedDomainIid.Add(element.GetGuid()); + } } - if (!jObject["affectedItemIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("affectedItemIid"u8, out var affectedItemIidProperty) && affectedItemIidProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.AffectedItemIid.AddRange(jObject["affectedItemIid"].ToObject>()); + foreach(var element in affectedItemIidProperty.EnumerateArray()) + { + modelLogEntry.AffectedItemIid.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - modelLogEntry.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + modelLogEntry.Author = null; + } + else + { + modelLogEntry.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + modelLogEntry.Category.Add(element.GetGuid()); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - modelLogEntry.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - modelLogEntry.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + modelLogEntry.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + modelLogEntry.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - modelLogEntry.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["level"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("level"u8, out var levelProperty)) { - modelLogEntry.Level = jObject["level"].ToObject(); + if(levelProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale level property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.Level = LogLevelKindDeserializer.Deserialize(levelProperty); + } } - if (!jObject["logEntryChangelogItem"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("logEntryChangelogItem"u8, out var logEntryChangelogItemProperty) && logEntryChangelogItemProperty.ValueKind != JsonValueKind.Null) { - modelLogEntry.LogEntryChangelogItem.AddRange(jObject["logEntryChangelogItem"].ToObject>()); + foreach(var element in logEntryChangelogItemProperty.EnumerateArray()) + { + modelLogEntry.LogEntryChangelogItem.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - modelLogEntry.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - modelLogEntry.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the modelLogEntry {id} is null", modelLogEntry.Iid); + } + else + { + modelLogEntry.ThingPreference = thingPreferenceProperty.GetString(); + } } return modelLogEntry; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs index 6ed0e590d..b7f39f2b9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModelReferenceDataLibraryResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,146 +28,235 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ModelReferenceDataLibraryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ModelReferenceDataLibrary FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ModelReferenceDataLibrary FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var modelReferenceDataLibrary = new CDP4Common.DTO.ModelReferenceDataLibrary(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ModelReferenceDataLibraryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - modelReferenceDataLibrary.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var modelReferenceDataLibrary = new CDP4Common.DTO.ModelReferenceDataLibrary(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Alias.Add(element.GetGuid()); + } } - if (!jObject["baseQuantityKind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("baseQuantityKind"u8, out var baseQuantityKindProperty)) { - modelReferenceDataLibrary.BaseQuantityKind.AddRange(jObject["baseQuantityKind"].ToOrderedItemCollection()); + modelReferenceDataLibrary.BaseQuantityKind.AddRange(baseQuantityKindProperty.ToOrderedItemCollection()); } - if (!jObject["baseUnit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("baseUnit"u8, out var baseUnitProperty) && baseUnitProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.BaseUnit.AddRange(jObject["baseUnit"].ToObject>()); + foreach(var element in baseUnitProperty.EnumerateArray()) + { + modelReferenceDataLibrary.BaseUnit.Add(element.GetGuid()); + } } - if (!jObject["constant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("constant"u8, out var constantProperty) && constantProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Constant.AddRange(jObject["constant"].ToObject>()); + foreach(var element in constantProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Constant.Add(element.GetGuid()); + } } - if (!jObject["definedCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definedCategory"u8, out var definedCategoryProperty) && definedCategoryProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.DefinedCategory.AddRange(jObject["definedCategory"].ToObject>()); + foreach(var element in definedCategoryProperty.EnumerateArray()) + { + modelReferenceDataLibrary.DefinedCategory.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + modelReferenceDataLibrary.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + modelReferenceDataLibrary.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fileType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fileType"u8, out var fileTypeProperty) && fileTypeProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.FileType.AddRange(jObject["fileType"].ToObject>()); + foreach(var element in fileTypeProperty.EnumerateArray()) + { + modelReferenceDataLibrary.FileType.Add(element.GetGuid()); + } } - if (!jObject["glossary"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("glossary"u8, out var glossaryProperty) && glossaryProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Glossary.AddRange(jObject["glossary"].ToObject>()); + foreach(var element in glossaryProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Glossary.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + modelReferenceDataLibrary.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - modelReferenceDataLibrary.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); + } + else + { + modelReferenceDataLibrary.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - modelReferenceDataLibrary.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); + } + else + { + modelReferenceDataLibrary.Name = nameProperty.GetString(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty) && parameterTypeProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.ParameterType.AddRange(jObject["parameterType"].ToObject>()); + foreach(var element in parameterTypeProperty.EnumerateArray()) + { + modelReferenceDataLibrary.ParameterType.Add(element.GetGuid()); + } } - if (!jObject["referenceSource"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceSource"u8, out var referenceSourceProperty) && referenceSourceProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.ReferenceSource.AddRange(jObject["referenceSource"].ToObject>()); + foreach(var element in referenceSourceProperty.EnumerateArray()) + { + modelReferenceDataLibrary.ReferenceSource.Add(element.GetGuid()); + } } - if (!jObject["requiredRdl"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requiredRdl"u8, out var requiredRdlProperty)) { - modelReferenceDataLibrary.RequiredRdl = jObject["requiredRdl"].ToObject(); + if(requiredRdlProperty.ValueKind == JsonValueKind.Null) + { + modelReferenceDataLibrary.RequiredRdl = null; + } + else + { + modelReferenceDataLibrary.RequiredRdl = requiredRdlProperty.GetGuid(); + } } - if (!jObject["rule"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("rule"u8, out var ruleProperty) && ruleProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Rule.AddRange(jObject["rule"].ToObject>()); + foreach(var element in ruleProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Rule.Add(element.GetGuid()); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty) && scaleProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Scale.AddRange(jObject["scale"].ToObject>()); + foreach(var element in scaleProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Scale.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - modelReferenceDataLibrary.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); + } + else + { + modelReferenceDataLibrary.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - modelReferenceDataLibrary.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the modelReferenceDataLibrary {id} is null", modelReferenceDataLibrary.Iid); + } + else + { + modelReferenceDataLibrary.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty) && unitProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.Unit.AddRange(jObject["unit"].ToObject>()); + foreach(var element in unitProperty.EnumerateArray()) + { + modelReferenceDataLibrary.Unit.Add(element.GetGuid()); + } } - if (!jObject["unitPrefix"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unitPrefix"u8, out var unitPrefixProperty) && unitPrefixProperty.ValueKind != JsonValueKind.Null) { - modelReferenceDataLibrary.UnitPrefix.AddRange(jObject["unitPrefix"].ToObject>()); + foreach(var element in unitPrefixProperty.EnumerateArray()) + { + modelReferenceDataLibrary.UnitPrefix.Add(element.GetGuid()); + } } return modelReferenceDataLibrary; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs index b14060ed0..309492a58 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ModellingThingReferenceResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,106 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ModellingThingReferenceResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ModellingThingReference FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ModellingThingReference FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var modellingThingReference = new CDP4Common.DTO.ModellingThingReference(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ModellingThingReferenceResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - modellingThingReference.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var modellingThingReference = new CDP4Common.DTO.ModellingThingReference(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - modellingThingReference.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + modellingThingReference.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - modellingThingReference.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + modellingThingReference.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - modellingThingReference.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the modellingThingReference {id} is null", modellingThingReference.Iid); + } + else + { + modellingThingReference.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["referencedRevisionNumber"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedRevisionNumber"u8, out var referencedRevisionNumberProperty)) { - modellingThingReference.ReferencedRevisionNumber = jObject["referencedRevisionNumber"].ToObject(); + if(referencedRevisionNumberProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referencedRevisionNumber property of the modellingThingReference {id} is null", modellingThingReference.Iid); + } + else + { + modellingThingReference.ReferencedRevisionNumber = referencedRevisionNumberProperty.GetInt32(); + } } - if (!jObject["referencedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedThing"u8, out var referencedThingProperty)) { - modellingThingReference.ReferencedThing = jObject["referencedThing"].ToObject(); + if(referencedThingProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referencedThing property of the modellingThingReference {id} is null", modellingThingReference.Iid); + } + else + { + modellingThingReference.ReferencedThing = referencedThingProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - modellingThingReference.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the modellingThingReference {id} is null", modellingThingReference.Iid); + } + else + { + modellingThingReference.ThingPreference = thingPreferenceProperty.GetString(); + } } return modellingThingReference; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs index b4f701b14..70cd05c15 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,130 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class MultiRelationshipResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.MultiRelationship FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.MultiRelationship FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var multiRelationship = new CDP4Common.DTO.MultiRelationship(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the MultiRelationshipResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - multiRelationship.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var multiRelationship = new CDP4Common.DTO.MultiRelationship(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - multiRelationship.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + multiRelationship.Category.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - multiRelationship.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + multiRelationship.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - multiRelationship.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + multiRelationship.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - multiRelationship.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the multiRelationship {id} is null", multiRelationship.Iid); + } + else + { + multiRelationship.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - multiRelationship.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the multiRelationship {id} is null", multiRelationship.Iid); + } + else + { + multiRelationship.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - multiRelationship.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the multiRelationship {id} is null", multiRelationship.Iid); + } + else + { + multiRelationship.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValue"u8, out var parameterValueProperty) && parameterValueProperty.ValueKind != JsonValueKind.Null) { - multiRelationship.ParameterValue.AddRange(jObject["parameterValue"].ToObject>()); + foreach(var element in parameterValueProperty.EnumerateArray()) + { + multiRelationship.ParameterValue.Add(element.GetGuid()); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - multiRelationship.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + multiRelationship.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - multiRelationship.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the multiRelationship {id} is null", multiRelationship.Iid); + } + else + { + multiRelationship.ThingPreference = thingPreferenceProperty.GetString(); + } } return multiRelationship; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs index 1488aece5..c1643d61d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/MultiRelationshipRuleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,106 +28,186 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class MultiRelationshipRuleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.MultiRelationshipRule FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.MultiRelationshipRule FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var multiRelationshipRule = new CDP4Common.DTO.MultiRelationshipRule(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the MultiRelationshipRuleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - multiRelationshipRule.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var multiRelationshipRule = new CDP4Common.DTO.MultiRelationshipRule(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + multiRelationshipRule.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + multiRelationshipRule.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + multiRelationshipRule.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + multiRelationshipRule.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + multiRelationshipRule.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - multiRelationshipRule.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["maxRelated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maxRelated"u8, out var maxRelatedProperty)) { - multiRelationshipRule.MaxRelated = jObject["maxRelated"].ToObject(); + if(maxRelatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale maxRelated property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.MaxRelated = maxRelatedProperty.GetInt32(); + } } - if (!jObject["minRelated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minRelated"u8, out var minRelatedProperty)) { - multiRelationshipRule.MinRelated = jObject["minRelated"].ToObject(); + if(minRelatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale minRelated property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.MinRelated = minRelatedProperty.GetInt32(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - multiRelationshipRule.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - multiRelationshipRule.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.Name = nameProperty.GetString(); + } } - if (!jObject["relatedCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedCategory"u8, out var relatedCategoryProperty) && relatedCategoryProperty.ValueKind != JsonValueKind.Null) { - multiRelationshipRule.RelatedCategory.AddRange(jObject["relatedCategory"].ToObject>()); + foreach(var element in relatedCategoryProperty.EnumerateArray()) + { + multiRelationshipRule.RelatedCategory.Add(element.GetGuid()); + } } - if (!jObject["relationshipCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relationshipCategory"u8, out var relationshipCategoryProperty)) { - multiRelationshipRule.RelationshipCategory = jObject["relationshipCategory"].ToObject(); + if(relationshipCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale relationshipCategory property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.RelationshipCategory = relationshipCategoryProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - multiRelationshipRule.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - multiRelationshipRule.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the multiRelationshipRule {id} is null", multiRelationshipRule.Iid); + } + else + { + multiRelationshipRule.ThingPreference = thingPreferenceProperty.GetString(); + } } return multiRelationshipRule; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs index 1c30bd63b..ad46d4314 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NaturalLanguageResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,118 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class NaturalLanguageResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.NaturalLanguage FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.NaturalLanguage FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var naturalLanguage = new CDP4Common.DTO.NaturalLanguage(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the NaturalLanguageResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - naturalLanguage.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var naturalLanguage = new CDP4Common.DTO.NaturalLanguage(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - naturalLanguage.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + naturalLanguage.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - naturalLanguage.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + naturalLanguage.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - naturalLanguage.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the naturalLanguage {id} is null", naturalLanguage.Iid); + } + else + { + naturalLanguage.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - naturalLanguage.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the naturalLanguage {id} is null", naturalLanguage.Iid); + } + else + { + naturalLanguage.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - naturalLanguage.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the naturalLanguage {id} is null", naturalLanguage.Iid); + } + else + { + naturalLanguage.Name = nameProperty.GetString(); + } } - if (!jObject["nativeName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("nativeName"u8, out var nativeNameProperty)) { - naturalLanguage.NativeName = jObject["nativeName"].ToObject(); + if(nativeNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale nativeName property of the naturalLanguage {id} is null", naturalLanguage.Iid); + } + else + { + naturalLanguage.NativeName = nativeNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - naturalLanguage.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the naturalLanguage {id} is null", naturalLanguage.Iid); + } + else + { + naturalLanguage.ThingPreference = thingPreferenceProperty.GetString(); + } } return naturalLanguage; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs index 2d06345ca..2610a3117 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedElementResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,76 +28,119 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class NestedElementResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.NestedElement FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.NestedElement FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var nestedElement = new CDP4Common.DTO.NestedElement(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the NestedElementResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - nestedElement.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["elementUsage"].IsNullOrEmpty()) + var nestedElement = new CDP4Common.DTO.NestedElement(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("elementUsage"u8, out var elementUsageProperty)) { - nestedElement.ElementUsage.AddRange(jObject["elementUsage"].ToOrderedItemCollection()); + nestedElement.ElementUsage.AddRange(elementUsageProperty.ToOrderedItemCollection()); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - nestedElement.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + nestedElement.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - nestedElement.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + nestedElement.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isVolatile"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isVolatile"u8, out var isVolatileProperty)) { - nestedElement.IsVolatile = jObject["isVolatile"].ToObject(); + if(isVolatileProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isVolatile property of the nestedElement {id} is null", nestedElement.Iid); + } + else + { + nestedElement.IsVolatile = isVolatileProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - nestedElement.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the nestedElement {id} is null", nestedElement.Iid); + } + else + { + nestedElement.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["nestedParameter"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("nestedParameter"u8, out var nestedParameterProperty) && nestedParameterProperty.ValueKind != JsonValueKind.Null) { - nestedElement.NestedParameter.AddRange(jObject["nestedParameter"].ToObject>()); + foreach(var element in nestedParameterProperty.EnumerateArray()) + { + nestedElement.NestedParameter.Add(element.GetGuid()); + } } - if (!jObject["rootElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("rootElement"u8, out var rootElementProperty)) { - nestedElement.RootElement = jObject["rootElement"].ToObject(); + if(rootElementProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale rootElement property of the nestedElement {id} is null", nestedElement.Iid); + } + else + { + nestedElement.RootElement = rootElementProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - nestedElement.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the nestedElement {id} is null", nestedElement.Iid); + } + else + { + nestedElement.ThingPreference = thingPreferenceProperty.GetString(); + } } return nestedElement; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs index cbd235bf5..b40cbbcb2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NestedParameterResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,154 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class NestedParameterResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.NestedParameter FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.NestedParameter FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var nestedParameter = new CDP4Common.DTO.NestedParameter(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the NestedParameterResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - nestedParameter.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actualState"].IsNullOrEmpty()) + var nestedParameter = new CDP4Common.DTO.NestedParameter(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("actualState"u8, out var actualStateProperty)) { - nestedParameter.ActualState = jObject["actualState"].ToObject(); + if(actualStateProperty.ValueKind == JsonValueKind.Null) + { + nestedParameter.ActualState = null; + } + else + { + nestedParameter.ActualState = actualStateProperty.GetGuid(); + } } - if (!jObject["actualValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("actualValue"u8, out var actualValueProperty)) { - nestedParameter.ActualValue = jObject["actualValue"].ToObject(); + if(actualValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale actualValue property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.ActualValue = actualValueProperty.GetString(); + } } - if (!jObject["associatedParameter"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("associatedParameter"u8, out var associatedParameterProperty)) { - nestedParameter.AssociatedParameter = jObject["associatedParameter"].ToObject(); + if(associatedParameterProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale associatedParameter property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.AssociatedParameter = associatedParameterProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - nestedParameter.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + nestedParameter.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - nestedParameter.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + nestedParameter.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["formula"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("formula"u8, out var formulaProperty)) { - nestedParameter.Formula = jObject["formula"].ToObject(); + if(formulaProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale formula property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.Formula = formulaProperty.GetString(); + } } - if (!jObject["isVolatile"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isVolatile"u8, out var isVolatileProperty)) { - nestedParameter.IsVolatile = jObject["isVolatile"].ToObject(); + if(isVolatileProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isVolatile property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.IsVolatile = isVolatileProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - nestedParameter.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - nestedParameter.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - nestedParameter.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the nestedParameter {id} is null", nestedParameter.Iid); + } + else + { + nestedParameter.ThingPreference = thingPreferenceProperty.GetString(); + } } return nestedParameter; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs index aed83415d..c0e9d99de 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/NotExpressionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,61 +28,94 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class NotExpressionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.NotExpression FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.NotExpression FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var notExpression = new CDP4Common.DTO.NotExpression(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the NotExpressionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - notExpression.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var notExpression = new CDP4Common.DTO.NotExpression(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - notExpression.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + notExpression.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - notExpression.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + notExpression.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - notExpression.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the notExpression {id} is null", notExpression.Iid); + } + else + { + notExpression.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["term"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("term"u8, out var termProperty)) { - notExpression.Term = jObject["term"].ToObject(); + if(termProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale term property of the notExpression {id} is null", notExpression.Iid); + } + else + { + notExpression.Term = termProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - notExpression.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the notExpression {id} is null", notExpression.Iid); + } + else + { + notExpression.ThingPreference = thingPreferenceProperty.GetString(); + } } return notExpression; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs index 11e136c9a..a6f71f8ac 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OptionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,146 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OptionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Option FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Option FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var option = new CDP4Common.DTO.Option(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OptionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - option.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var option = new CDP4Common.DTO.Option(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - option.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + option.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - option.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + option.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - option.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + option.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - option.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + option.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - option.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + option.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - option.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + option.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - option.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the option {id} is null", option.Iid); + } + else + { + option.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - option.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the option {id} is null", option.Iid); + } + else + { + option.Name = nameProperty.GetString(); + } } - if (!jObject["nestedElement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("nestedElement"u8, out var nestedElementProperty) && nestedElementProperty.ValueKind != JsonValueKind.Null) { - option.NestedElement.AddRange(jObject["nestedElement"].ToObject>()); + foreach(var element in nestedElementProperty.EnumerateArray()) + { + option.NestedElement.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - option.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the option {id} is null", option.Iid); + } + else + { + option.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - option.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the option {id} is null", option.Iid); + } + else + { + option.ThingPreference = thingPreferenceProperty.GetString(); + } } return option; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs index b6a513532..b04c2cbc9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrExpressionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,61 +28,90 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OrExpressionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.OrExpression FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.OrExpression FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var orExpression = new CDP4Common.DTO.OrExpression(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OrExpressionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - orExpression.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var orExpression = new CDP4Common.DTO.OrExpression(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - orExpression.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + orExpression.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - orExpression.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + orExpression.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - orExpression.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the orExpression {id} is null", orExpression.Iid); + } + else + { + orExpression.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["term"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("term"u8, out var termProperty) && termProperty.ValueKind != JsonValueKind.Null) { - orExpression.Term.AddRange(jObject["term"].ToObject>()); + foreach(var element in termProperty.EnumerateArray()) + { + orExpression.Term.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - orExpression.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the orExpression {id} is null", orExpression.Iid); + } + else + { + orExpression.ThingPreference = thingPreferenceProperty.GetString(); + } } return orExpression; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs index d4361272f..0252036c5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrdinalScaleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,141 +28,266 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OrdinalScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.OrdinalScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.OrdinalScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var ordinalScale = new CDP4Common.DTO.OrdinalScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OrdinalScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - ordinalScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var ordinalScale = new CDP4Common.DTO.OrdinalScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + ordinalScale.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + ordinalScale.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + ordinalScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + ordinalScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + ordinalScale.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - ordinalScale.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isMaximumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMaximumInclusive"u8, out var isMaximumInclusiveProperty)) { - ordinalScale.IsMaximumInclusive = jObject["isMaximumInclusive"].ToObject(); + if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMaximumInclusive property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.IsMaximumInclusive = isMaximumInclusiveProperty.GetBoolean(); + } } - if (!jObject["isMinimumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMinimumInclusive"u8, out var isMinimumInclusiveProperty)) { - ordinalScale.IsMinimumInclusive = jObject["isMinimumInclusive"].ToObject(); + if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMinimumInclusive property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.IsMinimumInclusive = isMinimumInclusiveProperty.GetBoolean(); + } } - if (!jObject["mappingToReferenceScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("mappingToReferenceScale"u8, out var mappingToReferenceScaleProperty) && mappingToReferenceScaleProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.MappingToReferenceScale.AddRange(jObject["mappingToReferenceScale"].ToObject>()); + foreach(var element in mappingToReferenceScaleProperty.EnumerateArray()) + { + ordinalScale.MappingToReferenceScale.Add(element.GetGuid()); + } } - if (!jObject["maximumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maximumPermissibleValue"u8, out var maximumPermissibleValueProperty)) { - ordinalScale.MaximumPermissibleValue = jObject["maximumPermissibleValue"].ToObject(); + if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale maximumPermissibleValue property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.MaximumPermissibleValue = maximumPermissibleValueProperty.GetString(); + } } - if (!jObject["minimumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minimumPermissibleValue"u8, out var minimumPermissibleValueProperty)) { - ordinalScale.MinimumPermissibleValue = jObject["minimumPermissibleValue"].ToObject(); + if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale minimumPermissibleValue property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.MinimumPermissibleValue = minimumPermissibleValueProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - ordinalScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - ordinalScale.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.Name = nameProperty.GetString(); + } } - if (!jObject["negativeValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("negativeValueConnotation"u8, out var negativeValueConnotationProperty)) { - ordinalScale.NegativeValueConnotation = jObject["negativeValueConnotation"].ToObject(); + if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale negativeValueConnotation property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.NegativeValueConnotation = negativeValueConnotationProperty.GetString(); + } } - if (!jObject["numberSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("numberSet"u8, out var numberSetProperty)) { - ordinalScale.NumberSet = jObject["numberSet"].ToObject(); + if(numberSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale numberSet property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.NumberSet = NumberSetKindDeserializer.Deserialize(numberSetProperty); + } } - if (!jObject["positiveValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("positiveValueConnotation"u8, out var positiveValueConnotationProperty)) { - ordinalScale.PositiveValueConnotation = jObject["positiveValueConnotation"].ToObject(); + if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale positiveValueConnotation property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.PositiveValueConnotation = positiveValueConnotationProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - ordinalScale.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - ordinalScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - ordinalScale.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale unit property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.Unit = unitProperty.GetGuid(); + } } - if (!jObject["useShortNameValues"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("useShortNameValues"u8, out var useShortNameValuesProperty)) { - ordinalScale.UseShortNameValues = jObject["useShortNameValues"].ToObject(); + if(useShortNameValuesProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale useShortNameValues property of the ordinalScale {id} is null", ordinalScale.Iid); + } + else + { + ordinalScale.UseShortNameValues = useShortNameValuesProperty.GetBoolean(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty) && valueDefinitionProperty.ValueKind != JsonValueKind.Null) { - ordinalScale.ValueDefinition.AddRange(jObject["valueDefinition"].ToObject>()); + foreach(var element in valueDefinitionProperty.EnumerateArray()) + { + ordinalScale.ValueDefinition.Add(element.GetGuid()); + } } return ordinalScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs index 2b6c03580..a06136294 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,118 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OrganizationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Organization FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Organization FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var organization = new CDP4Common.DTO.Organization(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OrganizationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - organization.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var organization = new CDP4Common.DTO.Organization(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - organization.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + organization.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - organization.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + organization.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - organization.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the organization {id} is null", organization.Iid); + } + else + { + organization.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - organization.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the organization {id} is null", organization.Iid); + } + else + { + organization.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - organization.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the organization {id} is null", organization.Iid); + } + else + { + organization.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - organization.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the organization {id} is null", organization.Iid); + } + else + { + organization.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - organization.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the organization {id} is null", organization.Iid); + } + else + { + organization.ThingPreference = thingPreferenceProperty.GetString(); + } } return organization; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs index cc457aa9b..0b70c326f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OrganizationalParticipantResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,61 +28,94 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OrganizationalParticipantResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.OrganizationalParticipant FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.OrganizationalParticipant FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var organizationalParticipant = new CDP4Common.DTO.OrganizationalParticipant(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OrganizationalParticipantResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - organizationalParticipant.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var organizationalParticipant = new CDP4Common.DTO.OrganizationalParticipant(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - organizationalParticipant.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + organizationalParticipant.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - organizationalParticipant.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + organizationalParticipant.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - organizationalParticipant.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the organizationalParticipant {id} is null", organizationalParticipant.Iid); + } + else + { + organizationalParticipant.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["organization"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organization"u8, out var organizationProperty)) { - organizationalParticipant.Organization = jObject["organization"].ToObject(); + if(organizationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale organization property of the organizationalParticipant {id} is null", organizationalParticipant.Iid); + } + else + { + organizationalParticipant.Organization = organizationProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - organizationalParticipant.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the organizationalParticipant {id} is null", organizationalParticipant.Iid); + } + else + { + organizationalParticipant.ThingPreference = thingPreferenceProperty.GetString(); + } } return organizationalParticipant; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs index ce85879f0..4882e5f6a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/OwnedStyleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,126 +28,246 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class OwnedStyleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.OwnedStyle FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.OwnedStyle FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var ownedStyle = new CDP4Common.DTO.OwnedStyle(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the OwnedStyleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - ownedStyle.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var ownedStyle = new CDP4Common.DTO.OwnedStyle(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - ownedStyle.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + ownedStyle.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - ownedStyle.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + ownedStyle.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fillColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fillColor"u8, out var fillColorProperty)) { - ownedStyle.FillColor = jObject["fillColor"].ToObject(); + if(fillColorProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FillColor = null; + } + else + { + ownedStyle.FillColor = fillColorProperty.GetGuid(); + } } - if (!jObject["fillOpacity"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fillOpacity"u8, out var fillOpacityProperty)) { - ownedStyle.FillOpacity = jObject["fillOpacity"].ToObject(); + if(fillOpacityProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FillOpacity = null; + } + else + { + ownedStyle.FillOpacity = fillOpacityProperty.GetSingle(); + } } - if (!jObject["fontBold"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontBold"u8, out var fontBoldProperty)) { - ownedStyle.FontBold = jObject["fontBold"].ToObject(); + if(fontBoldProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontBold = null; + } + else + { + ownedStyle.FontBold = fontBoldProperty.GetBoolean(); + } } - if (!jObject["fontColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontColor"u8, out var fontColorProperty)) { - ownedStyle.FontColor = jObject["fontColor"].ToObject(); + if(fontColorProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontColor = null; + } + else + { + ownedStyle.FontColor = fontColorProperty.GetGuid(); + } } - if (!jObject["fontItalic"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontItalic"u8, out var fontItalicProperty)) { - ownedStyle.FontItalic = jObject["fontItalic"].ToObject(); + if(fontItalicProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontItalic = null; + } + else + { + ownedStyle.FontItalic = fontItalicProperty.GetBoolean(); + } } - if (!jObject["fontName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontName"u8, out var fontNameProperty)) { - ownedStyle.FontName = jObject["fontName"].ToObject(); + if(fontNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale fontName property of the ownedStyle {id} is null", ownedStyle.Iid); + } + else + { + ownedStyle.FontName = fontNameProperty.GetString(); + } } - if (!jObject["fontSize"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontSize"u8, out var fontSizeProperty)) { - ownedStyle.FontSize = jObject["fontSize"].ToObject(); + if(fontSizeProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontSize = null; + } + else + { + ownedStyle.FontSize = fontSizeProperty.GetSingle(); + } } - if (!jObject["fontStrokeThrough"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontStrokeThrough"u8, out var fontStrokeThroughProperty)) { - ownedStyle.FontStrokeThrough = jObject["fontStrokeThrough"].ToObject(); + if(fontStrokeThroughProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontStrokeThrough = null; + } + else + { + ownedStyle.FontStrokeThrough = fontStrokeThroughProperty.GetBoolean(); + } } - if (!jObject["fontUnderline"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontUnderline"u8, out var fontUnderlineProperty)) { - ownedStyle.FontUnderline = jObject["fontUnderline"].ToObject(); + if(fontUnderlineProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.FontUnderline = null; + } + else + { + ownedStyle.FontUnderline = fontUnderlineProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - ownedStyle.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the ownedStyle {id} is null", ownedStyle.Iid); + } + else + { + ownedStyle.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - ownedStyle.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the ownedStyle {id} is null", ownedStyle.Iid); + } + else + { + ownedStyle.Name = nameProperty.GetString(); + } } - if (!jObject["strokeColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeColor"u8, out var strokeColorProperty)) { - ownedStyle.StrokeColor = jObject["strokeColor"].ToObject(); + if(strokeColorProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.StrokeColor = null; + } + else + { + ownedStyle.StrokeColor = strokeColorProperty.GetGuid(); + } } - if (!jObject["strokeOpacity"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeOpacity"u8, out var strokeOpacityProperty)) { - ownedStyle.StrokeOpacity = jObject["strokeOpacity"].ToObject(); + if(strokeOpacityProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.StrokeOpacity = null; + } + else + { + ownedStyle.StrokeOpacity = strokeOpacityProperty.GetSingle(); + } } - if (!jObject["strokeWidth"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeWidth"u8, out var strokeWidthProperty)) { - ownedStyle.StrokeWidth = jObject["strokeWidth"].ToObject(); + if(strokeWidthProperty.ValueKind == JsonValueKind.Null) + { + ownedStyle.StrokeWidth = null; + } + else + { + ownedStyle.StrokeWidth = strokeWidthProperty.GetSingle(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - ownedStyle.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the ownedStyle {id} is null", ownedStyle.Iid); + } + else + { + ownedStyle.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["usedColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("usedColor"u8, out var usedColorProperty) && usedColorProperty.ValueKind != JsonValueKind.Null) { - ownedStyle.UsedColor.AddRange(jObject["usedColor"].ToObject>()); + foreach(var element in usedColorProperty.EnumerateArray()) + { + ownedStyle.UsedColor.Add(element.GetGuid()); + } } return ownedStyle; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs index dc9da33cc..af5258df7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PageResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,143 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PageResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Page FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Page FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var page = new CDP4Common.DTO.Page(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PageResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - page.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var page = new CDP4Common.DTO.Page(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - page.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + page.Category.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - page.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the page {id} is null", page.Iid); + } + else + { + page.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - page.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + page.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - page.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + page.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - page.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the page {id} is null", page.Iid); + } + else + { + page.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - page.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the page {id} is null", page.Iid); + } + else + { + page.Name = nameProperty.GetString(); + } } - if (!jObject["note"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("note"u8, out var noteProperty)) { - page.Note.AddRange(jObject["note"].ToOrderedItemCollection()); + page.Note.AddRange(noteProperty.ToOrderedItemCollection()); } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - page.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the page {id} is null", page.Iid); + } + else + { + page.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - page.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the page {id} is null", page.Iid); + } + else + { + page.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - page.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the page {id} is null", page.Iid); + } + else + { + page.ThingPreference = thingPreferenceProperty.GetString(); + } } return page; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs index 33a7e1b0d..5ad816d24 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterGroupResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,106 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterGroupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterGroup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterGroup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterGroup = new CDP4Common.DTO.ParameterGroup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterGroupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterGroup.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["containingGroup"].IsNullOrEmpty()) + var parameterGroup = new CDP4Common.DTO.ParameterGroup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("containingGroup"u8, out var containingGroupProperty)) { - parameterGroup.ContainingGroup = jObject["containingGroup"].ToObject(); + if(containingGroupProperty.ValueKind == JsonValueKind.Null) + { + parameterGroup.ContainingGroup = null; + } + else + { + parameterGroup.ContainingGroup = containingGroupProperty.GetGuid(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterGroup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterGroup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterGroup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterGroup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterGroup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameterGroup {id} is null", parameterGroup.Iid); + } + else + { + parameterGroup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - parameterGroup.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the parameterGroup {id} is null", parameterGroup.Iid); + } + else + { + parameterGroup.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterGroup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameterGroup {id} is null", parameterGroup.Iid); + } + else + { + parameterGroup.ThingPreference = thingPreferenceProperty.GetString(); + } } return parameterGroup; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs index dbef7ca82..510ee80dc 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,76 +28,122 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterOverrideResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterOverride FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterOverride FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterOverride = new CDP4Common.DTO.ParameterOverride(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterOverrideResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterOverride.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var parameterOverride = new CDP4Common.DTO.ParameterOverride(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterOverride.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterOverride.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterOverride.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterOverride.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterOverride.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameterOverride {id} is null", parameterOverride.Iid); + } + else + { + parameterOverride.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - parameterOverride.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the parameterOverride {id} is null", parameterOverride.Iid); + } + else + { + parameterOverride.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameter"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameter"u8, out var parameterProperty)) { - parameterOverride.Parameter = jObject["parameter"].ToObject(); + if(parameterProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameter property of the parameterOverride {id} is null", parameterOverride.Iid); + } + else + { + parameterOverride.Parameter = parameterProperty.GetGuid(); + } } - if (!jObject["parameterSubscription"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterSubscription"u8, out var parameterSubscriptionProperty) && parameterSubscriptionProperty.ValueKind != JsonValueKind.Null) { - parameterOverride.ParameterSubscription.AddRange(jObject["parameterSubscription"].ToObject>()); + foreach(var element in parameterSubscriptionProperty.EnumerateArray()) + { + parameterOverride.ParameterSubscription.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterOverride.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameterOverride {id} is null", parameterOverride.Iid); + } + else + { + parameterOverride.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSet"u8, out var valueSetProperty) && valueSetProperty.ValueKind != JsonValueKind.Null) { - parameterOverride.ValueSet.AddRange(jObject["valueSet"].ToObject>()); + foreach(var element in valueSetProperty.EnumerateArray()) + { + parameterOverride.ValueSet.Add(element.GetGuid()); + } } return parameterOverride; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs index f03080fa1..11c8b3d14 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterOverrideValueSetResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,192 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterOverrideValueSetResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterOverrideValueSet = new CDP4Common.DTO.ParameterOverrideValueSet(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterOverrideValueSet FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - parameterOverrideValueSet.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the ParameterOverrideValueSetResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["computed"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterOverrideValueSet.Computed = SerializerHelper.ToValueArray(jObject["computed"].ToString()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var parameterOverrideValueSet = new CDP4Common.DTO.ParameterOverrideValueSet(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("computed"u8, out var computedProperty)) { - parameterOverrideValueSet.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + if (computedProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in computedProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterOverrideValueSet.Computed = new ValueArray(newValueArrayItems); + } + else + { + parameterOverrideValueSet.Computed = SerializerHelper.ToValueArray(computedProperty.GetString()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterOverrideValueSet.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterOverrideValueSet.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["formula"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterOverrideValueSet.Formula = SerializerHelper.ToValueArray(jObject["formula"].ToString()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterOverrideValueSet.ExcludedPerson.Add(element.GetGuid()); + } } - - if (!jObject["manual"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("formula"u8, out var formulaProperty)) { - parameterOverrideValueSet.Manual = SerializerHelper.ToValueArray(jObject["manual"].ToString()); + if (formulaProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in formulaProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterOverrideValueSet.Formula = new ValueArray(newValueArrayItems); + } + else + { + parameterOverrideValueSet.Formula = SerializerHelper.ToValueArray(formulaProperty.GetString()); + } } - - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("manual"u8, out var manualProperty)) { - parameterOverrideValueSet.ModifiedOn = jObject["modifiedOn"].ToObject(); + if (manualProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in manualProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterOverrideValueSet.Manual = new ValueArray(newValueArrayItems); + } + else + { + parameterOverrideValueSet.Manual = SerializerHelper.ToValueArray(manualProperty.GetString()); + } } - if (!jObject["parameterValueSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterOverrideValueSet.ParameterValueSet = jObject["parameterValueSet"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); + } + else + { + parameterOverrideValueSet.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["published"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValueSet"u8, out var parameterValueSetProperty)) { - parameterOverrideValueSet.Published = SerializerHelper.ToValueArray(jObject["published"].ToString()); + if(parameterValueSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterValueSet property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); + } + else + { + parameterOverrideValueSet.ParameterValueSet = parameterValueSetProperty.GetGuid(); + } } - - if (!jObject["reference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("published"u8, out var publishedProperty)) + { + if (publishedProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in publishedProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterOverrideValueSet.Published = new ValueArray(newValueArrayItems); + } + else + { + parameterOverrideValueSet.Published = SerializerHelper.ToValueArray(publishedProperty.GetString()); + } + } + if (jsonElement.TryGetProperty("reference"u8, out var referenceProperty)) { - parameterOverrideValueSet.Reference = SerializerHelper.ToValueArray(jObject["reference"].ToString()); + if (referenceProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in referenceProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterOverrideValueSet.Reference = new ValueArray(newValueArrayItems); + } + else + { + parameterOverrideValueSet.Reference = SerializerHelper.ToValueArray(referenceProperty.GetString()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterOverrideValueSet.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); + } + else + { + parameterOverrideValueSet.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSwitch"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSwitch"u8, out var valueSwitchProperty)) { - parameterOverrideValueSet.ValueSwitch = jObject["valueSwitch"].ToObject(); + if(valueSwitchProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale valueSwitch property of the parameterOverrideValueSet {id} is null", parameterOverrideValueSet.Iid); + } + else + { + parameterOverrideValueSet.ValueSwitch = ParameterSwitchKindDeserializer.Deserialize(valueSwitchProperty); + } } return parameterOverrideValueSet; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs index b1322dfc7..90f13c303 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,111 +28,206 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Parameter FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Parameter FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameter = new CDP4Common.DTO.Parameter(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameter.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["allowDifferentOwnerOfOverride"].IsNullOrEmpty()) + var parameter = new CDP4Common.DTO.Parameter(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("allowDifferentOwnerOfOverride"u8, out var allowDifferentOwnerOfOverrideProperty)) { - parameter.AllowDifferentOwnerOfOverride = jObject["allowDifferentOwnerOfOverride"].ToObject(); + if(allowDifferentOwnerOfOverrideProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale allowDifferentOwnerOfOverride property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.AllowDifferentOwnerOfOverride = allowDifferentOwnerOfOverrideProperty.GetBoolean(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameter.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameter.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameter.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameter.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["expectsOverride"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("expectsOverride"u8, out var expectsOverrideProperty)) { - parameter.ExpectsOverride = jObject["expectsOverride"].ToObject(); + if(expectsOverrideProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale expectsOverride property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.ExpectsOverride = expectsOverrideProperty.GetBoolean(); + } } - if (!jObject["group"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("group"u8, out var groupProperty)) { - parameter.Group = jObject["group"].ToObject(); + if(groupProperty.ValueKind == JsonValueKind.Null) + { + parameter.Group = null; + } + else + { + parameter.Group = groupProperty.GetGuid(); + } } - if (!jObject["isOptionDependent"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isOptionDependent"u8, out var isOptionDependentProperty)) { - parameter.IsOptionDependent = jObject["isOptionDependent"].ToObject(); + if(isOptionDependentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isOptionDependent property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.IsOptionDependent = isOptionDependentProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameter.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - parameter.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterSubscription"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterSubscription"u8, out var parameterSubscriptionProperty) && parameterSubscriptionProperty.ValueKind != JsonValueKind.Null) { - parameter.ParameterSubscription.AddRange(jObject["parameterSubscription"].ToObject>()); + foreach(var element in parameterSubscriptionProperty.EnumerateArray()) + { + parameter.ParameterSubscription.Add(element.GetGuid()); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - parameter.ParameterType = jObject["parameterType"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["requestedBy"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requestedBy"u8, out var requestedByProperty)) { - parameter.RequestedBy = jObject["requestedBy"].ToObject(); + if(requestedByProperty.ValueKind == JsonValueKind.Null) + { + parameter.RequestedBy = null; + } + else + { + parameter.RequestedBy = requestedByProperty.GetGuid(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - parameter.Scale = jObject["scale"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + parameter.Scale = null; + } + else + { + parameter.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["stateDependence"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stateDependence"u8, out var stateDependenceProperty)) { - parameter.StateDependence = jObject["stateDependence"].ToObject(); + if(stateDependenceProperty.ValueKind == JsonValueKind.Null) + { + parameter.StateDependence = null; + } + else + { + parameter.StateDependence = stateDependenceProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameter.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameter {id} is null", parameter.Iid); + } + else + { + parameter.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSet"u8, out var valueSetProperty) && valueSetProperty.ValueKind != JsonValueKind.Null) { - parameter.ValueSet.AddRange(jObject["valueSet"].ToObject>()); + foreach(var element in valueSetProperty.EnumerateArray()) + { + parameter.ValueSet.Add(element.GetGuid()); + } } return parameter; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs index 73cba783c..036b50d15 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,102 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterSubscriptionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterSubscription FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterSubscription FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterSubscription = new CDP4Common.DTO.ParameterSubscription(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterSubscriptionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterSubscription.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var parameterSubscription = new CDP4Common.DTO.ParameterSubscription(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterSubscription.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterSubscription.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterSubscription.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterSubscription.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterSubscription.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameterSubscription {id} is null", parameterSubscription.Iid); + } + else + { + parameterSubscription.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - parameterSubscription.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the parameterSubscription {id} is null", parameterSubscription.Iid); + } + else + { + parameterSubscription.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterSubscription.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameterSubscription {id} is null", parameterSubscription.Iid); + } + else + { + parameterSubscription.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSet"u8, out var valueSetProperty) && valueSetProperty.ValueKind != JsonValueKind.Null) { - parameterSubscription.ValueSet.AddRange(jObject["valueSet"].ToObject>()); + foreach(var element in valueSetProperty.EnumerateArray()) + { + parameterSubscription.ValueSet.Add(element.GetGuid()); + } } return parameterSubscription; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs index be56c333b..fbfa4450b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterSubscriptionValueSetResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,123 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterSubscriptionValueSetResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterSubscriptionValueSet FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterSubscriptionValueSet = new CDP4Common.DTO.ParameterSubscriptionValueSet(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterSubscriptionValueSet FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - parameterSubscriptionValueSet.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the ParameterSubscriptionValueSetResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterSubscriptionValueSet.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var parameterSubscriptionValueSet = new CDP4Common.DTO.ParameterSubscriptionValueSet(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterSubscriptionValueSet.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterSubscriptionValueSet.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["manual"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterSubscriptionValueSet.Manual = SerializerHelper.ToValueArray(jObject["manual"].ToString()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterSubscriptionValueSet.ExcludedPerson.Add(element.GetGuid()); + } + } + if (jsonElement.TryGetProperty("manual"u8, out var manualProperty)) + { + if (manualProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in manualProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterSubscriptionValueSet.Manual = new ValueArray(newValueArrayItems); + } + else + { + parameterSubscriptionValueSet.Manual = SerializerHelper.ToValueArray(manualProperty.GetString()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterSubscriptionValueSet.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); + } + else + { + parameterSubscriptionValueSet.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["subscribedValueSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("subscribedValueSet"u8, out var subscribedValueSetProperty)) { - parameterSubscriptionValueSet.SubscribedValueSet = jObject["subscribedValueSet"].ToObject(); + if(subscribedValueSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale subscribedValueSet property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); + } + else + { + parameterSubscriptionValueSet.SubscribedValueSet = subscribedValueSetProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterSubscriptionValueSet.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); + } + else + { + parameterSubscriptionValueSet.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSwitch"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSwitch"u8, out var valueSwitchProperty)) { - parameterSubscriptionValueSet.ValueSwitch = jObject["valueSwitch"].ToObject(); + if(valueSwitchProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale valueSwitch property of the parameterSubscriptionValueSet {id} is null", parameterSubscriptionValueSet.Iid); + } + else + { + parameterSubscriptionValueSet.ValueSwitch = ParameterSwitchKindDeserializer.Deserialize(valueSwitchProperty); + } } return parameterSubscriptionValueSet; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs index 4702a193d..4a650859d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterTypeComponentResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,118 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterTypeComponentResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterTypeComponent FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterTypeComponent FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterTypeComponent = new CDP4Common.DTO.ParameterTypeComponent(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterTypeComponentResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterTypeComponent.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var parameterTypeComponent = new CDP4Common.DTO.ParameterTypeComponent(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterTypeComponent.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterTypeComponent.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterTypeComponent.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterTypeComponent.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterTypeComponent.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); + } + else + { + parameterTypeComponent.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - parameterTypeComponent.ParameterType = jObject["parameterType"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); + } + else + { + parameterTypeComponent.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - parameterTypeComponent.Scale = jObject["scale"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + parameterTypeComponent.Scale = null; + } + else + { + parameterTypeComponent.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - parameterTypeComponent.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); + } + else + { + parameterTypeComponent.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterTypeComponent.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameterTypeComponent {id} is null", parameterTypeComponent.Iid); + } + else + { + parameterTypeComponent.ThingPreference = thingPreferenceProperty.GetString(); + } } return parameterTypeComponent; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs index 9d6770045..a9d4a4410 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterValueSetResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,203 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterValueSetResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterValueSet FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterValueSet = new CDP4Common.DTO.ParameterValueSet(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterValueSet FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - parameterValueSet.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the ParameterValueSetResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["actualOption"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterValueSet.ActualOption = jObject["actualOption"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actualState"].IsNullOrEmpty()) + var parameterValueSet = new CDP4Common.DTO.ParameterValueSet(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("actualOption"u8, out var actualOptionProperty)) { - parameterValueSet.ActualState = jObject["actualState"].ToObject(); + if(actualOptionProperty.ValueKind == JsonValueKind.Null) + { + parameterValueSet.ActualOption = null; + } + else + { + parameterValueSet.ActualOption = actualOptionProperty.GetGuid(); + } } - if (!jObject["computed"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("actualState"u8, out var actualStateProperty)) { - parameterValueSet.Computed = SerializerHelper.ToValueArray(jObject["computed"].ToString()); + if(actualStateProperty.ValueKind == JsonValueKind.Null) + { + parameterValueSet.ActualState = null; + } + else + { + parameterValueSet.ActualState = actualStateProperty.GetGuid(); + } } - - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("computed"u8, out var computedProperty)) { - parameterValueSet.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + if (computedProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in computedProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterValueSet.Computed = new ValueArray(newValueArrayItems); + } + else + { + parameterValueSet.Computed = SerializerHelper.ToValueArray(computedProperty.GetString()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterValueSet.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterValueSet.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["formula"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterValueSet.Formula = SerializerHelper.ToValueArray(jObject["formula"].ToString()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterValueSet.ExcludedPerson.Add(element.GetGuid()); + } } - - if (!jObject["manual"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("formula"u8, out var formulaProperty)) { - parameterValueSet.Manual = SerializerHelper.ToValueArray(jObject["manual"].ToString()); + if (formulaProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in formulaProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterValueSet.Formula = new ValueArray(newValueArrayItems); + } + else + { + parameterValueSet.Formula = SerializerHelper.ToValueArray(formulaProperty.GetString()); + } } - - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("manual"u8, out var manualProperty)) { - parameterValueSet.ModifiedOn = jObject["modifiedOn"].ToObject(); + if (manualProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in manualProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterValueSet.Manual = new ValueArray(newValueArrayItems); + } + else + { + parameterValueSet.Manual = SerializerHelper.ToValueArray(manualProperty.GetString()); + } } - if (!jObject["published"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterValueSet.Published = SerializerHelper.ToValueArray(jObject["published"].ToString()); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameterValueSet {id} is null", parameterValueSet.Iid); + } + else + { + parameterValueSet.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - - if (!jObject["reference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("published"u8, out var publishedProperty)) + { + if (publishedProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in publishedProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterValueSet.Published = new ValueArray(newValueArrayItems); + } + else + { + parameterValueSet.Published = SerializerHelper.ToValueArray(publishedProperty.GetString()); + } + } + if (jsonElement.TryGetProperty("reference"u8, out var referenceProperty)) { - parameterValueSet.Reference = SerializerHelper.ToValueArray(jObject["reference"].ToString()); + if (referenceProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in referenceProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + parameterValueSet.Reference = new ValueArray(newValueArrayItems); + } + else + { + parameterValueSet.Reference = SerializerHelper.ToValueArray(referenceProperty.GetString()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterValueSet.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameterValueSet {id} is null", parameterValueSet.Iid); + } + else + { + parameterValueSet.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueSwitch"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueSwitch"u8, out var valueSwitchProperty)) { - parameterValueSet.ValueSwitch = jObject["valueSwitch"].ToObject(); + if(valueSwitchProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale valueSwitch property of the parameterValueSet {id} is null", parameterValueSet.Iid); + } + else + { + parameterValueSet.ValueSwitch = ParameterSwitchKindDeserializer.Deserialize(valueSwitchProperty); + } } return parameterValueSet; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs index d700d006a..6fb4e5d0a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParameterizedCategoryRuleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,162 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParameterizedCategoryRuleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParameterizedCategoryRule FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParameterizedCategoryRule FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parameterizedCategoryRule = new CDP4Common.DTO.ParameterizedCategoryRule(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParameterizedCategoryRuleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parameterizedCategoryRule.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var parameterizedCategoryRule = new CDP4Common.DTO.ParameterizedCategoryRule(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + parameterizedCategoryRule.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty)) { - parameterizedCategoryRule.Category = jObject["category"].ToObject(); + if(categoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale category property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.Category = categoryProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + parameterizedCategoryRule.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parameterizedCategoryRule.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parameterizedCategoryRule.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + parameterizedCategoryRule.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - parameterizedCategoryRule.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parameterizedCategoryRule.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - parameterizedCategoryRule.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.Name = nameProperty.GetString(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty) && parameterTypeProperty.ValueKind != JsonValueKind.Null) { - parameterizedCategoryRule.ParameterType.AddRange(jObject["parameterType"].ToObject>()); + foreach(var element in parameterTypeProperty.EnumerateArray()) + { + parameterizedCategoryRule.ParameterType.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - parameterizedCategoryRule.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parameterizedCategoryRule.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parameterizedCategoryRule {id} is null", parameterizedCategoryRule.Iid); + } + else + { + parameterizedCategoryRule.ThingPreference = thingPreferenceProperty.GetString(); + } } return parameterizedCategoryRule; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs index 67140eb4c..5ddce38d7 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParametricConstraintResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,102 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParametricConstraintResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParametricConstraint FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParametricConstraint FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var parametricConstraint = new CDP4Common.DTO.ParametricConstraint(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParametricConstraintResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - parametricConstraint.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var parametricConstraint = new CDP4Common.DTO.ParametricConstraint(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - parametricConstraint.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + parametricConstraint.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - parametricConstraint.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + parametricConstraint.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["expression"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("expression"u8, out var expressionProperty) && expressionProperty.ValueKind != JsonValueKind.Null) { - parametricConstraint.Expression.AddRange(jObject["expression"].ToObject>()); + foreach(var element in expressionProperty.EnumerateArray()) + { + parametricConstraint.Expression.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - parametricConstraint.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the parametricConstraint {id} is null", parametricConstraint.Iid); + } + else + { + parametricConstraint.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - parametricConstraint.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the parametricConstraint {id} is null", parametricConstraint.Iid); + } + else + { + parametricConstraint.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["topExpression"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("topExpression"u8, out var topExpressionProperty)) { - parametricConstraint.TopExpression = jObject["topExpression"].ToObject(); + if(topExpressionProperty.ValueKind == JsonValueKind.Null) + { + parametricConstraint.TopExpression = null; + } + else + { + parametricConstraint.TopExpression = topExpressionProperty.GetGuid(); + } } return parametricConstraint; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs index d116aee28..b58ecf48d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantPermissionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,118 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParticipantPermissionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParticipantPermission FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParticipantPermission FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var participantPermission = new CDP4Common.DTO.ParticipantPermission(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParticipantPermissionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["accessRight"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - participantPermission.AccessRight = jObject["accessRight"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actor"].IsNullOrEmpty()) + var participantPermission = new CDP4Common.DTO.ParticipantPermission(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("accessRight"u8, out var accessRightProperty)) { - participantPermission.Actor = jObject["actor"].ToObject(); + if(accessRightProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale accessRight property of the participantPermission {id} is null", participantPermission.Iid); + } + else + { + participantPermission.AccessRight = ParticipantAccessRightKindDeserializer.Deserialize(accessRightProperty); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - participantPermission.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + participantPermission.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - participantPermission.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + participantPermission.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - participantPermission.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the participantPermission {id} is null", participantPermission.Iid); + } + else + { + participantPermission.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - participantPermission.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the participantPermission {id} is null", participantPermission.Iid); + } + else + { + participantPermission.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["objectClass"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("objectClass"u8, out var objectClassProperty)) { - participantPermission.ObjectClass = jObject["objectClass"].ToObject(); + if(objectClassProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale objectClass property of the participantPermission {id} is null", participantPermission.Iid); + } + else + { + participantPermission.ObjectClass = ClassKindDeserializer.Deserialize(objectClassProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - participantPermission.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the participantPermission {id} is null", participantPermission.Iid); + } + else + { + participantPermission.ThingPreference = thingPreferenceProperty.GetString(); + } } return participantPermission; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs index 45113f2bb..820b963ca 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,138 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParticipantResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Participant FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Participant FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var participant = new CDP4Common.DTO.Participant(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParticipantResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - participant.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["domain"].IsNullOrEmpty()) + var participant = new CDP4Common.DTO.Participant(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("domain"u8, out var domainProperty) && domainProperty.ValueKind != JsonValueKind.Null) { - participant.Domain.AddRange(jObject["domain"].ToObject>()); + foreach(var element in domainProperty.EnumerateArray()) + { + participant.Domain.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - participant.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + participant.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - participant.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + participant.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isActive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isActive"u8, out var isActiveProperty)) { - participant.IsActive = jObject["isActive"].ToObject(); + if(isActiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isActive property of the participant {id} is null", participant.Iid); + } + else + { + participant.IsActive = isActiveProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - participant.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the participant {id} is null", participant.Iid); + } + else + { + participant.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["person"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("person"u8, out var personProperty)) { - participant.Person = jObject["person"].ToObject(); + if(personProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale person property of the participant {id} is null", participant.Iid); + } + else + { + participant.Person = personProperty.GetGuid(); + } } - if (!jObject["role"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("role"u8, out var roleProperty)) { - participant.Role = jObject["role"].ToObject(); + if(roleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale role property of the participant {id} is null", participant.Iid); + } + else + { + participant.Role = roleProperty.GetGuid(); + } } - if (!jObject["selectedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("selectedDomain"u8, out var selectedDomainProperty)) { - participant.SelectedDomain = jObject["selectedDomain"].ToObject(); + if(selectedDomainProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale selectedDomain property of the participant {id} is null", participant.Iid); + } + else + { + participant.SelectedDomain = selectedDomainProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - participant.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the participant {id} is null", participant.Iid); + } + else + { + participant.ThingPreference = thingPreferenceProperty.GetString(); + } } return participant; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs index 27ba6921c..2742ae225 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ParticipantRoleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,150 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ParticipantRoleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ParticipantRole FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ParticipantRole FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var participantRole = new CDP4Common.DTO.ParticipantRole(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ParticipantRoleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - participantRole.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var participantRole = new CDP4Common.DTO.ParticipantRole(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - participantRole.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + participantRole.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - participantRole.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + participantRole.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - participantRole.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + participantRole.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - participantRole.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + participantRole.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - participantRole.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + participantRole.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - participantRole.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the participantRole {id} is null", participantRole.Iid); + } + else + { + participantRole.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - participantRole.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the participantRole {id} is null", participantRole.Iid); + } + else + { + participantRole.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - participantRole.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the participantRole {id} is null", participantRole.Iid); + } + else + { + participantRole.Name = nameProperty.GetString(); + } } - if (!jObject["participantPermission"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("participantPermission"u8, out var participantPermissionProperty) && participantPermissionProperty.ValueKind != JsonValueKind.Null) { - participantRole.ParticipantPermission.AddRange(jObject["participantPermission"].ToObject>()); + foreach(var element in participantPermissionProperty.EnumerateArray()) + { + participantRole.ParticipantPermission.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - participantRole.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the participantRole {id} is null", participantRole.Iid); + } + else + { + participantRole.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - participantRole.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the participantRole {id} is null", participantRole.Iid); + } + else + { + participantRole.ThingPreference = thingPreferenceProperty.GetString(); + } } return participantRole; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs index 55a189b68..2d03a89d5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonPermissionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,118 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PersonPermissionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.PersonPermission FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.PersonPermission FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var personPermission = new CDP4Common.DTO.PersonPermission(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PersonPermissionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["accessRight"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - personPermission.AccessRight = jObject["accessRight"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["actor"].IsNullOrEmpty()) + var personPermission = new CDP4Common.DTO.PersonPermission(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("accessRight"u8, out var accessRightProperty)) { - personPermission.Actor = jObject["actor"].ToObject(); + if(accessRightProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale accessRight property of the personPermission {id} is null", personPermission.Iid); + } + else + { + personPermission.AccessRight = PersonAccessRightKindDeserializer.Deserialize(accessRightProperty); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - personPermission.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + personPermission.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - personPermission.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + personPermission.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - personPermission.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the personPermission {id} is null", personPermission.Iid); + } + else + { + personPermission.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - personPermission.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the personPermission {id} is null", personPermission.Iid); + } + else + { + personPermission.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["objectClass"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("objectClass"u8, out var objectClassProperty)) { - personPermission.ObjectClass = jObject["objectClass"].ToObject(); + if(objectClassProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale objectClass property of the personPermission {id} is null", personPermission.Iid); + } + else + { + personPermission.ObjectClass = ClassKindDeserializer.Deserialize(objectClassProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - personPermission.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the personPermission {id} is null", personPermission.Iid); + } + else + { + personPermission.ThingPreference = thingPreferenceProperty.GetString(); + } } return personPermission; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs index 49e6895de..f0ba867fa 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,131 +28,250 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PersonResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Person FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Person FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var person = new CDP4Common.DTO.Person(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PersonResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - person.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["defaultDomain"].IsNullOrEmpty()) + var person = new CDP4Common.DTO.Person(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("defaultDomain"u8, out var defaultDomainProperty)) { - person.DefaultDomain = jObject["defaultDomain"].ToObject(); + if(defaultDomainProperty.ValueKind == JsonValueKind.Null) + { + person.DefaultDomain = null; + } + else + { + person.DefaultDomain = defaultDomainProperty.GetGuid(); + } } - if (!jObject["defaultEmailAddress"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultEmailAddress"u8, out var defaultEmailAddressProperty)) { - person.DefaultEmailAddress = jObject["defaultEmailAddress"].ToObject(); + if(defaultEmailAddressProperty.ValueKind == JsonValueKind.Null) + { + person.DefaultEmailAddress = null; + } + else + { + person.DefaultEmailAddress = defaultEmailAddressProperty.GetGuid(); + } } - if (!jObject["defaultTelephoneNumber"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultTelephoneNumber"u8, out var defaultTelephoneNumberProperty)) { - person.DefaultTelephoneNumber = jObject["defaultTelephoneNumber"].ToObject(); + if(defaultTelephoneNumberProperty.ValueKind == JsonValueKind.Null) + { + person.DefaultTelephoneNumber = null; + } + else + { + person.DefaultTelephoneNumber = defaultTelephoneNumberProperty.GetGuid(); + } } - if (!jObject["emailAddress"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("emailAddress"u8, out var emailAddressProperty) && emailAddressProperty.ValueKind != JsonValueKind.Null) { - person.EmailAddress.AddRange(jObject["emailAddress"].ToObject>()); + foreach(var element in emailAddressProperty.EnumerateArray()) + { + person.EmailAddress.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - person.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + person.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - person.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + person.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["givenName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("givenName"u8, out var givenNameProperty)) { - person.GivenName = jObject["givenName"].ToObject(); + if(givenNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale givenName property of the person {id} is null", person.Iid); + } + else + { + person.GivenName = givenNameProperty.GetString(); + } } - if (!jObject["isActive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isActive"u8, out var isActiveProperty)) { - person.IsActive = jObject["isActive"].ToObject(); + if(isActiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isActive property of the person {id} is null", person.Iid); + } + else + { + person.IsActive = isActiveProperty.GetBoolean(); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - person.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the person {id} is null", person.Iid); + } + else + { + person.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - person.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the person {id} is null", person.Iid); + } + else + { + person.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["organization"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organization"u8, out var organizationProperty)) { - person.Organization = jObject["organization"].ToObject(); + if(organizationProperty.ValueKind == JsonValueKind.Null) + { + person.Organization = null; + } + else + { + person.Organization = organizationProperty.GetGuid(); + } } - if (!jObject["organizationalUnit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organizationalUnit"u8, out var organizationalUnitProperty)) { - person.OrganizationalUnit = jObject["organizationalUnit"].ToObject(); + if(organizationalUnitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale organizationalUnit property of the person {id} is null", person.Iid); + } + else + { + person.OrganizationalUnit = organizationalUnitProperty.GetString(); + } } - if (!jObject["password"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("password"u8, out var passwordProperty)) { - person.Password = jObject["password"].ToObject(); + if(passwordProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale password property of the person {id} is null", person.Iid); + } + else + { + person.Password = passwordProperty.GetString(); + } } - if (!jObject["role"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("role"u8, out var roleProperty)) { - person.Role = jObject["role"].ToObject(); + if(roleProperty.ValueKind == JsonValueKind.Null) + { + person.Role = null; + } + else + { + person.Role = roleProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - person.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the person {id} is null", person.Iid); + } + else + { + person.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["surname"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("surname"u8, out var surnameProperty)) { - person.Surname = jObject["surname"].ToObject(); + if(surnameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale surname property of the person {id} is null", person.Iid); + } + else + { + person.Surname = surnameProperty.GetString(); + } } - if (!jObject["telephoneNumber"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("telephoneNumber"u8, out var telephoneNumberProperty) && telephoneNumberProperty.ValueKind != JsonValueKind.Null) { - person.TelephoneNumber.AddRange(jObject["telephoneNumber"].ToObject>()); + foreach(var element in telephoneNumberProperty.EnumerateArray()) + { + person.TelephoneNumber.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - person.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the person {id} is null", person.Iid); + } + else + { + person.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["userPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("userPreference"u8, out var userPreferenceProperty) && userPreferenceProperty.ValueKind != JsonValueKind.Null) { - person.UserPreference.AddRange(jObject["userPreference"].ToObject>()); + foreach(var element in userPreferenceProperty.EnumerateArray()) + { + person.UserPreference.Add(element.GetGuid()); + } } return person; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs index 9ec5daba8..063e6dbea 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PersonRoleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,150 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PersonRoleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.PersonRole FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.PersonRole FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var personRole = new CDP4Common.DTO.PersonRole(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PersonRoleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - personRole.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var personRole = new CDP4Common.DTO.PersonRole(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - personRole.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + personRole.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - personRole.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + personRole.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - personRole.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + personRole.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - personRole.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + personRole.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - personRole.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + personRole.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - personRole.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the personRole {id} is null", personRole.Iid); + } + else + { + personRole.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - personRole.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the personRole {id} is null", personRole.Iid); + } + else + { + personRole.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - personRole.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the personRole {id} is null", personRole.Iid); + } + else + { + personRole.Name = nameProperty.GetString(); + } } - if (!jObject["personPermission"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("personPermission"u8, out var personPermissionProperty) && personPermissionProperty.ValueKind != JsonValueKind.Null) { - personRole.PersonPermission.AddRange(jObject["personPermission"].ToObject>()); + foreach(var element in personPermissionProperty.EnumerateArray()) + { + personRole.PersonPermission.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - personRole.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the personRole {id} is null", personRole.Iid); + } + else + { + personRole.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - personRole.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the personRole {id} is null", personRole.Iid); + } + else + { + personRole.ThingPreference = thingPreferenceProperty.GetString(); + } } return personRole; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs index 44cacac81..a9cdd608d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PointResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,118 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PointResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Point FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Point FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var point = new CDP4Common.DTO.Point(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PointResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - point.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var point = new CDP4Common.DTO.Point(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - point.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + point.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - point.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + point.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - point.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the point {id} is null", point.Iid); + } + else + { + point.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - point.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the point {id} is null", point.Iid); + } + else + { + point.Name = nameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - point.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the point {id} is null", point.Iid); + } + else + { + point.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["x"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("x"u8, out var xProperty)) { - point.X = jObject["x"].ToObject(); + if(xProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale x property of the point {id} is null", point.Iid); + } + else + { + point.X = xProperty.GetSingle(); + } } - if (!jObject["y"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("y"u8, out var yProperty)) { - point.Y = jObject["y"].ToObject(); + if(yProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale y property of the point {id} is null", point.Iid); + } + else + { + point.Y = yProperty.GetSingle(); + } } return point; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs index 7172ea9ea..dea8d31e8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateListResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,101 +28,167 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PossibleFiniteStateListResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.PossibleFiniteStateList FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.PossibleFiniteStateList FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var possibleFiniteStateList = new CDP4Common.DTO.PossibleFiniteStateList(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PossibleFiniteStateListResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - possibleFiniteStateList.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var possibleFiniteStateList = new CDP4Common.DTO.PossibleFiniteStateList(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + possibleFiniteStateList.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + possibleFiniteStateList.Category.Add(element.GetGuid()); + } } - if (!jObject["defaultState"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultState"u8, out var defaultStateProperty)) { - possibleFiniteStateList.DefaultState = jObject["defaultState"].ToObject(); + if(defaultStateProperty.ValueKind == JsonValueKind.Null) + { + possibleFiniteStateList.DefaultState = null; + } + else + { + possibleFiniteStateList.DefaultState = defaultStateProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + possibleFiniteStateList.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + possibleFiniteStateList.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + possibleFiniteStateList.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteStateList.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + possibleFiniteStateList.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - possibleFiniteStateList.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + } + else + { + possibleFiniteStateList.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - possibleFiniteStateList.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + } + else + { + possibleFiniteStateList.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - possibleFiniteStateList.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + } + else + { + possibleFiniteStateList.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["possibleState"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleState"u8, out var possibleStateProperty)) { - possibleFiniteStateList.PossibleState.AddRange(jObject["possibleState"].ToOrderedItemCollection()); + possibleFiniteStateList.PossibleState.AddRange(possibleStateProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - possibleFiniteStateList.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + } + else + { + possibleFiniteStateList.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - possibleFiniteStateList.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the possibleFiniteStateList {id} is null", possibleFiniteStateList.Iid); + } + else + { + possibleFiniteStateList.ThingPreference = thingPreferenceProperty.GetString(); + } } return possibleFiniteStateList; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs index a381d03d8..5e55f886c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PossibleFiniteStateResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,130 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PossibleFiniteStateResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.PossibleFiniteState FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.PossibleFiniteState FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var possibleFiniteState = new CDP4Common.DTO.PossibleFiniteState(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PossibleFiniteStateResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - possibleFiniteState.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var possibleFiniteState = new CDP4Common.DTO.PossibleFiniteState(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteState.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + possibleFiniteState.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteState.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + possibleFiniteState.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteState.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + possibleFiniteState.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteState.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + possibleFiniteState.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - possibleFiniteState.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + possibleFiniteState.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - possibleFiniteState.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); + } + else + { + possibleFiniteState.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - possibleFiniteState.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); + } + else + { + possibleFiniteState.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - possibleFiniteState.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); + } + else + { + possibleFiniteState.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - possibleFiniteState.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the possibleFiniteState {id} is null", possibleFiniteState.Iid); + } + else + { + possibleFiniteState.ThingPreference = thingPreferenceProperty.GetString(); + } } return possibleFiniteState; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs index c5eb961c8..28d53a0bd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PrefixedUnitResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,142 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PrefixedUnitResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.PrefixedUnit FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.PrefixedUnit FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var prefixedUnit = new CDP4Common.DTO.PrefixedUnit(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PrefixedUnitResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - prefixedUnit.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var prefixedUnit = new CDP4Common.DTO.PrefixedUnit(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - prefixedUnit.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + prefixedUnit.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - prefixedUnit.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + prefixedUnit.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - prefixedUnit.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + prefixedUnit.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - prefixedUnit.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + prefixedUnit.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - prefixedUnit.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + prefixedUnit.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - prefixedUnit.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the prefixedUnit {id} is null", prefixedUnit.Iid); + } + else + { + prefixedUnit.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - prefixedUnit.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the prefixedUnit {id} is null", prefixedUnit.Iid); + } + else + { + prefixedUnit.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["prefix"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("prefix"u8, out var prefixProperty)) { - prefixedUnit.Prefix = jObject["prefix"].ToObject(); + if(prefixProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale prefix property of the prefixedUnit {id} is null", prefixedUnit.Iid); + } + else + { + prefixedUnit.Prefix = prefixProperty.GetGuid(); + } } - if (!jObject["referenceUnit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceUnit"u8, out var referenceUnitProperty)) { - prefixedUnit.ReferenceUnit = jObject["referenceUnit"].ToObject(); + if(referenceUnitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referenceUnit property of the prefixedUnit {id} is null", prefixedUnit.Iid); + } + else + { + prefixedUnit.ReferenceUnit = referenceUnitProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - prefixedUnit.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the prefixedUnit {id} is null", prefixedUnit.Iid); + } + else + { + prefixedUnit.ThingPreference = thingPreferenceProperty.GetString(); + } } return prefixedUnit; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs index 84ebf4f51..d46a326c5 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/PublicationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,110 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class PublicationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Publication FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Publication FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var publication = new CDP4Common.DTO.Publication(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the PublicationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - publication.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["createdOn"].IsNullOrEmpty()) + var publication = new CDP4Common.DTO.Publication(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - publication.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the publication {id} is null", publication.Iid); + } + else + { + publication.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["domain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("domain"u8, out var domainProperty) && domainProperty.ValueKind != JsonValueKind.Null) { - publication.Domain.AddRange(jObject["domain"].ToObject>()); + foreach(var element in domainProperty.EnumerateArray()) + { + publication.Domain.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - publication.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + publication.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - publication.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + publication.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - publication.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the publication {id} is null", publication.Iid); + } + else + { + publication.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["publishedParameter"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("publishedParameter"u8, out var publishedParameterProperty) && publishedParameterProperty.ValueKind != JsonValueKind.Null) { - publication.PublishedParameter.AddRange(jObject["publishedParameter"].ToObject>()); + foreach(var element in publishedParameterProperty.EnumerateArray()) + { + publication.PublishedParameter.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - publication.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the publication {id} is null", publication.Iid); + } + else + { + publication.ThingPreference = thingPreferenceProperty.GetString(); + } } return publication; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs index 0997ef62d..2406fcbd1 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/QuantityKindFactorResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,106 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class QuantityKindFactorResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.QuantityKindFactor FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.QuantityKindFactor FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var quantityKindFactor = new CDP4Common.DTO.QuantityKindFactor(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the QuantityKindFactorResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - quantityKindFactor.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var quantityKindFactor = new CDP4Common.DTO.QuantityKindFactor(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - quantityKindFactor.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + quantityKindFactor.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - quantityKindFactor.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + quantityKindFactor.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["exponent"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("exponent"u8, out var exponentProperty)) { - quantityKindFactor.Exponent = jObject["exponent"].ToObject(); + if(exponentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale exponent property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); + } + else + { + quantityKindFactor.Exponent = exponentProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - quantityKindFactor.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); + } + else + { + quantityKindFactor.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["quantityKind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("quantityKind"u8, out var quantityKindProperty)) { - quantityKindFactor.QuantityKind = jObject["quantityKind"].ToObject(); + if(quantityKindProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale quantityKind property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); + } + else + { + quantityKindFactor.QuantityKind = quantityKindProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - quantityKindFactor.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the quantityKindFactor {id} is null", quantityKindFactor.Iid); + } + else + { + quantityKindFactor.ThingPreference = thingPreferenceProperty.GetString(); + } } return quantityKindFactor; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs index 5dd7af283..bf4d97a07 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RatioScaleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,136 +28,254 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RatioScaleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RatioScale FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RatioScale FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var ratioScale = new CDP4Common.DTO.RatioScale(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RatioScaleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - ratioScale.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var ratioScale = new CDP4Common.DTO.RatioScale(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - ratioScale.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + ratioScale.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - ratioScale.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + ratioScale.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - ratioScale.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + ratioScale.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - ratioScale.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + ratioScale.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - ratioScale.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + ratioScale.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - ratioScale.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["isMaximumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMaximumInclusive"u8, out var isMaximumInclusiveProperty)) { - ratioScale.IsMaximumInclusive = jObject["isMaximumInclusive"].ToObject(); + if(isMaximumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMaximumInclusive property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.IsMaximumInclusive = isMaximumInclusiveProperty.GetBoolean(); + } } - if (!jObject["isMinimumInclusive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isMinimumInclusive"u8, out var isMinimumInclusiveProperty)) { - ratioScale.IsMinimumInclusive = jObject["isMinimumInclusive"].ToObject(); + if(isMinimumInclusiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isMinimumInclusive property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.IsMinimumInclusive = isMinimumInclusiveProperty.GetBoolean(); + } } - if (!jObject["mappingToReferenceScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("mappingToReferenceScale"u8, out var mappingToReferenceScaleProperty) && mappingToReferenceScaleProperty.ValueKind != JsonValueKind.Null) { - ratioScale.MappingToReferenceScale.AddRange(jObject["mappingToReferenceScale"].ToObject>()); + foreach(var element in mappingToReferenceScaleProperty.EnumerateArray()) + { + ratioScale.MappingToReferenceScale.Add(element.GetGuid()); + } } - if (!jObject["maximumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maximumPermissibleValue"u8, out var maximumPermissibleValueProperty)) { - ratioScale.MaximumPermissibleValue = jObject["maximumPermissibleValue"].ToObject(); + if(maximumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale maximumPermissibleValue property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.MaximumPermissibleValue = maximumPermissibleValueProperty.GetString(); + } } - if (!jObject["minimumPermissibleValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minimumPermissibleValue"u8, out var minimumPermissibleValueProperty)) { - ratioScale.MinimumPermissibleValue = jObject["minimumPermissibleValue"].ToObject(); + if(minimumPermissibleValueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale minimumPermissibleValue property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.MinimumPermissibleValue = minimumPermissibleValueProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - ratioScale.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - ratioScale.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.Name = nameProperty.GetString(); + } } - if (!jObject["negativeValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("negativeValueConnotation"u8, out var negativeValueConnotationProperty)) { - ratioScale.NegativeValueConnotation = jObject["negativeValueConnotation"].ToObject(); + if(negativeValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale negativeValueConnotation property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.NegativeValueConnotation = negativeValueConnotationProperty.GetString(); + } } - if (!jObject["numberSet"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("numberSet"u8, out var numberSetProperty)) { - ratioScale.NumberSet = jObject["numberSet"].ToObject(); + if(numberSetProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale numberSet property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.NumberSet = NumberSetKindDeserializer.Deserialize(numberSetProperty); + } } - if (!jObject["positiveValueConnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("positiveValueConnotation"u8, out var positiveValueConnotationProperty)) { - ratioScale.PositiveValueConnotation = jObject["positiveValueConnotation"].ToObject(); + if(positiveValueConnotationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale positiveValueConnotation property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.PositiveValueConnotation = positiveValueConnotationProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - ratioScale.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - ratioScale.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - ratioScale.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale unit property of the ratioScale {id} is null", ratioScale.Iid); + } + else + { + ratioScale.Unit = unitProperty.GetGuid(); + } } - if (!jObject["valueDefinition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueDefinition"u8, out var valueDefinitionProperty) && valueDefinitionProperty.ValueKind != JsonValueKind.Null) { - ratioScale.ValueDefinition.AddRange(jObject["valueDefinition"].ToObject>()); + foreach(var element in valueDefinitionProperty.EnumerateArray()) + { + ratioScale.ValueDefinition.Add(element.GetGuid()); + } } return ratioScale; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs index 75cfcb127..55ebb5eb9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferenceSourceResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,126 +28,234 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ReferenceSourceResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ReferenceSource FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ReferenceSource FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var referenceSource = new CDP4Common.DTO.ReferenceSource(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ReferenceSourceResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - referenceSource.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var referenceSource = new CDP4Common.DTO.ReferenceSource(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - referenceSource.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + referenceSource.Alias.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - referenceSource.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.Author = authorProperty.GetString(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - referenceSource.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + referenceSource.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - referenceSource.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + referenceSource.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - referenceSource.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + referenceSource.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - referenceSource.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + referenceSource.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - referenceSource.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + referenceSource.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - referenceSource.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["language"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("language"u8, out var languageProperty)) { - referenceSource.Language = jObject["language"].ToObject(); + if(languageProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale language property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.Language = languageProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - referenceSource.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - referenceSource.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.Name = nameProperty.GetString(); + } } - if (!jObject["publicationYear"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("publicationYear"u8, out var publicationYearProperty)) { - referenceSource.PublicationYear = jObject["publicationYear"].ToObject(); + if(publicationYearProperty.ValueKind == JsonValueKind.Null) + { + referenceSource.PublicationYear = null; + } + else + { + referenceSource.PublicationYear = publicationYearProperty.GetInt32(); + } } - if (!jObject["publishedIn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("publishedIn"u8, out var publishedInProperty)) { - referenceSource.PublishedIn = jObject["publishedIn"].ToObject(); + if(publishedInProperty.ValueKind == JsonValueKind.Null) + { + referenceSource.PublishedIn = null; + } + else + { + referenceSource.PublishedIn = publishedInProperty.GetGuid(); + } } - if (!jObject["publisher"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("publisher"u8, out var publisherProperty)) { - referenceSource.Publisher = jObject["publisher"].ToObject(); + if(publisherProperty.ValueKind == JsonValueKind.Null) + { + referenceSource.Publisher = null; + } + else + { + referenceSource.Publisher = publisherProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - referenceSource.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - referenceSource.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["versionDate"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("versionDate"u8, out var versionDateProperty)) { - referenceSource.VersionDate = jObject["versionDate"].ToObject(); + if(versionDateProperty.ValueKind == JsonValueKind.Null) + { + referenceSource.VersionDate = null; + } + else + { + referenceSource.VersionDate = versionDateProperty.GetDateTime(); + } } - if (!jObject["versionIdentifier"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("versionIdentifier"u8, out var versionIdentifierProperty)) { - referenceSource.VersionIdentifier = jObject["versionIdentifier"].ToObject(); + if(versionIdentifierProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale versionIdentifier property of the referenceSource {id} is null", referenceSource.Iid); + } + else + { + referenceSource.VersionIdentifier = versionIdentifierProperty.GetString(); + } } return referenceSource; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs index b2e36e75f..d3a473077 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReferencerRuleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,106 +28,186 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ReferencerRuleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ReferencerRule FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ReferencerRule FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var referencerRule = new CDP4Common.DTO.ReferencerRule(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ReferencerRuleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - referencerRule.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var referencerRule = new CDP4Common.DTO.ReferencerRule(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - referencerRule.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + referencerRule.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - referencerRule.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + referencerRule.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - referencerRule.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + referencerRule.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - referencerRule.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + referencerRule.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - referencerRule.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + referencerRule.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - referencerRule.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["maxReferenced"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("maxReferenced"u8, out var maxReferencedProperty)) { - referencerRule.MaxReferenced = jObject["maxReferenced"].ToObject(); + if(maxReferencedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale maxReferenced property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.MaxReferenced = maxReferencedProperty.GetInt32(); + } } - if (!jObject["minReferenced"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("minReferenced"u8, out var minReferencedProperty)) { - referencerRule.MinReferenced = jObject["minReferenced"].ToObject(); + if(minReferencedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale minReferenced property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.MinReferenced = minReferencedProperty.GetInt32(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - referencerRule.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - referencerRule.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.Name = nameProperty.GetString(); + } } - if (!jObject["referencedCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedCategory"u8, out var referencedCategoryProperty) && referencedCategoryProperty.ValueKind != JsonValueKind.Null) { - referencerRule.ReferencedCategory.AddRange(jObject["referencedCategory"].ToObject>()); + foreach(var element in referencedCategoryProperty.EnumerateArray()) + { + referencerRule.ReferencedCategory.Add(element.GetGuid()); + } } - if (!jObject["referencingCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencingCategory"u8, out var referencingCategoryProperty)) { - referencerRule.ReferencingCategory = jObject["referencingCategory"].ToObject(); + if(referencingCategoryProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referencingCategory property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.ReferencingCategory = referencingCategoryProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - referencerRule.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - referencerRule.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the referencerRule {id} is null", referencerRule.Iid); + } + else + { + referencerRule.ThingPreference = thingPreferenceProperty.GetString(); + } } return referencerRule; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs index 08282a325..912798d55 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationalExpressionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,76 +28,135 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RelationalExpressionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RelationalExpression FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var relationalExpression = new CDP4Common.DTO.RelationalExpression(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RelationalExpression FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - relationalExpression.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the RelationalExpressionResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - relationalExpression.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var relationalExpression = new CDP4Common.DTO.RelationalExpression(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - relationalExpression.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + relationalExpression.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - relationalExpression.ModifiedOn = jObject["modifiedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + relationalExpression.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - relationalExpression.ParameterType = jObject["parameterType"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the relationalExpression {id} is null", relationalExpression.Iid); + } + else + { + relationalExpression.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["relationalOperator"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - relationalExpression.RelationalOperator = jObject["relationalOperator"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the relationalExpression {id} is null", relationalExpression.Iid); + } + else + { + relationalExpression.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relationalOperator"u8, out var relationalOperatorProperty)) { - relationalExpression.Scale = jObject["scale"].ToObject(); + if(relationalOperatorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale relationalOperator property of the relationalExpression {id} is null", relationalExpression.Iid); + } + else + { + relationalExpression.RelationalOperator = RelationalOperatorKindDeserializer.Deserialize(relationalOperatorProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - relationalExpression.ThingPreference = jObject["thingPreference"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + relationalExpression.Scale = null; + } + else + { + relationalExpression.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) + { + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the relationalExpression {id} is null", relationalExpression.Iid); + } + else + { + relationalExpression.ThingPreference = thingPreferenceProperty.GetString(); + } + } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - relationalExpression.Value = SerializerHelper.ToValueArray(jObject["value"].ToString()); + if (valueProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in valueProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + relationalExpression.Value = new ValueArray(newValueArrayItems); + } + else + { + relationalExpression.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); + } } return relationalExpression; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs index e53d645a3..08cf24540 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RelationshipParameterValueResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,123 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RelationshipParameterValueResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RelationshipParameterValue FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var relationshipParameterValue = new CDP4Common.DTO.RelationshipParameterValue(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RelationshipParameterValue FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - relationshipParameterValue.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the RelationshipParameterValueResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - relationshipParameterValue.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var relationshipParameterValue = new CDP4Common.DTO.RelationshipParameterValue(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - relationshipParameterValue.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + relationshipParameterValue.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - relationshipParameterValue.ModifiedOn = jObject["modifiedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + relationshipParameterValue.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - relationshipParameterValue.ParameterType = jObject["parameterType"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the relationshipParameterValue {id} is null", relationshipParameterValue.Iid); + } + else + { + relationshipParameterValue.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - relationshipParameterValue.Scale = jObject["scale"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the relationshipParameterValue {id} is null", relationshipParameterValue.Iid); + } + else + { + relationshipParameterValue.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - relationshipParameterValue.ThingPreference = jObject["thingPreference"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + relationshipParameterValue.Scale = null; + } + else + { + relationshipParameterValue.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - relationshipParameterValue.Value = SerializerHelper.ToValueArray(jObject["value"].ToString()); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the relationshipParameterValue {id} is null", relationshipParameterValue.Iid); + } + else + { + relationshipParameterValue.ThingPreference = thingPreferenceProperty.GetString(); + } + } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) + { + if (valueProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in valueProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + relationshipParameterValue.Value = new ValueArray(newValueArrayItems); + } + else + { + relationshipParameterValue.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); + } } return relationshipParameterValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs index 7bb113a57..210eae8b8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForDeviationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,131 +28,242 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequestForDeviationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RequestForDeviation FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RequestForDeviation FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requestForDeviation = new CDP4Common.DTO.RequestForDeviation(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RequestForDeviationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requestForDeviation.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var requestForDeviation = new CDP4Common.DTO.RequestForDeviation(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + requestForDeviation.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - requestForDeviation.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + requestForDeviation.Category.Add(element.GetGuid()); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - requestForDeviation.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale classification property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - requestForDeviation.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - requestForDeviation.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + requestForDeviation.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requestForDeviation.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requestForDeviation.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - requestForDeviation.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requestForDeviation.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - requestForDeviation.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - requestForDeviation.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + requestForDeviation.PrimaryAnnotatedThing = null; + } + else + { + requestForDeviation.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + requestForDeviation.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - requestForDeviation.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - requestForDeviation.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + requestForDeviation.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - requestForDeviation.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - requestForDeviation.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - requestForDeviation.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale title property of the requestForDeviation {id} is null", requestForDeviation.Iid); + } + else + { + requestForDeviation.Title = titleProperty.GetString(); + } } return requestForDeviation; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs index b8e642cd2..3e3ee4989 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequestForWaiverResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,131 +28,242 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequestForWaiverResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RequestForWaiver FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RequestForWaiver FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requestForWaiver = new CDP4Common.DTO.RequestForWaiver(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RequestForWaiverResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requestForWaiver.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var requestForWaiver = new CDP4Common.DTO.RequestForWaiver(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + requestForWaiver.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - requestForWaiver.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + requestForWaiver.Category.Add(element.GetGuid()); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - requestForWaiver.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale classification property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - requestForWaiver.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - requestForWaiver.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + requestForWaiver.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requestForWaiver.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requestForWaiver.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - requestForWaiver.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requestForWaiver.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - requestForWaiver.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - requestForWaiver.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + requestForWaiver.PrimaryAnnotatedThing = null; + } + else + { + requestForWaiver.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + requestForWaiver.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - requestForWaiver.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - requestForWaiver.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + requestForWaiver.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - requestForWaiver.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - requestForWaiver.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - requestForWaiver.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale title property of the requestForWaiver {id} is null", requestForWaiver.Iid); + } + else + { + requestForWaiver.Title = titleProperty.GetString(); + } } return requestForWaiver; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs index 06b574a11..83fe79d50 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,111 +28,187 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequirementResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Requirement FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Requirement FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requirement = new CDP4Common.DTO.Requirement(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RequirementResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requirement.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var requirement = new CDP4Common.DTO.Requirement(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - requirement.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + requirement.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - requirement.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + requirement.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - requirement.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + requirement.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requirement.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requirement.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requirement.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requirement.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["group"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("group"u8, out var groupProperty)) { - requirement.Group = jObject["group"].ToObject(); + if(groupProperty.ValueKind == JsonValueKind.Null) + { + requirement.Group = null; + } + else + { + requirement.Group = groupProperty.GetGuid(); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - requirement.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + requirement.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - requirement.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requirement.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - requirement.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - requirement.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValue"u8, out var parameterValueProperty) && parameterValueProperty.ValueKind != JsonValueKind.Null) { - requirement.ParameterValue.AddRange(jObject["parameterValue"].ToObject>()); + foreach(var element in parameterValueProperty.EnumerateArray()) + { + requirement.ParameterValue.Add(element.GetGuid()); + } } - if (!jObject["parametricConstraint"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parametricConstraint"u8, out var parametricConstraintProperty)) { - requirement.ParametricConstraint.AddRange(jObject["parametricConstraint"].ToOrderedItemCollection()); + requirement.ParametricConstraint.AddRange(parametricConstraintProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - requirement.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - requirement.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the requirement {id} is null", requirement.Iid); + } + else + { + requirement.ThingPreference = thingPreferenceProperty.GetString(); + } } return requirement; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs index 2a9b998fd..4a3416cfd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsContainerParameterValueResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,123 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequirementsContainerParameterValueResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RequirementsContainerParameterValue FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requirementsContainerParameterValue = new CDP4Common.DTO.RequirementsContainerParameterValue(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RequirementsContainerParameterValue FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - requirementsContainerParameterValue.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the RequirementsContainerParameterValueResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requirementsContainerParameterValue.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var requirementsContainerParameterValue = new CDP4Common.DTO.RequirementsContainerParameterValue(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requirementsContainerParameterValue.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requirementsContainerParameterValue.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requirementsContainerParameterValue.ModifiedOn = jObject["modifiedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requirementsContainerParameterValue.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requirementsContainerParameterValue.ParameterType = jObject["parameterType"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the requirementsContainerParameterValue {id} is null", requirementsContainerParameterValue.Iid); + } + else + { + requirementsContainerParameterValue.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - requirementsContainerParameterValue.Scale = jObject["scale"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the requirementsContainerParameterValue {id} is null", requirementsContainerParameterValue.Iid); + } + else + { + requirementsContainerParameterValue.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - requirementsContainerParameterValue.ThingPreference = jObject["thingPreference"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + requirementsContainerParameterValue.Scale = null; + } + else + { + requirementsContainerParameterValue.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - requirementsContainerParameterValue.Value = SerializerHelper.ToValueArray(jObject["value"].ToString()); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the requirementsContainerParameterValue {id} is null", requirementsContainerParameterValue.Iid); + } + else + { + requirementsContainerParameterValue.ThingPreference = thingPreferenceProperty.GetString(); + } + } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) + { + if (valueProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in valueProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + requirementsContainerParameterValue.Value = new ValueArray(newValueArrayItems); + } + else + { + requirementsContainerParameterValue.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); + } } return requirementsContainerParameterValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs index ab333a3b0..00474c7a8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsGroupResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,101 +28,166 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequirementsGroupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RequirementsGroup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RequirementsGroup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requirementsGroup = new CDP4Common.DTO.RequirementsGroup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RequirementsGroupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requirementsGroup.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var requirementsGroup = new CDP4Common.DTO.RequirementsGroup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + requirementsGroup.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + requirementsGroup.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + requirementsGroup.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requirementsGroup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requirementsGroup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["group"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("group"u8, out var groupProperty) && groupProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.Group.AddRange(jObject["group"].ToObject>()); + foreach(var element in groupProperty.EnumerateArray()) + { + requirementsGroup.Group.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + requirementsGroup.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requirementsGroup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the requirementsGroup {id} is null", requirementsGroup.Iid); + } + else + { + requirementsGroup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - requirementsGroup.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the requirementsGroup {id} is null", requirementsGroup.Iid); + } + else + { + requirementsGroup.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - requirementsGroup.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the requirementsGroup {id} is null", requirementsGroup.Iid); + } + else + { + requirementsGroup.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValue"u8, out var parameterValueProperty) && parameterValueProperty.ValueKind != JsonValueKind.Null) { - requirementsGroup.ParameterValue.AddRange(jObject["parameterValue"].ToObject>()); + foreach(var element in parameterValueProperty.EnumerateArray()) + { + requirementsGroup.ParameterValue.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - requirementsGroup.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the requirementsGroup {id} is null", requirementsGroup.Iid); + } + else + { + requirementsGroup.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - requirementsGroup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the requirementsGroup {id} is null", requirementsGroup.Iid); + } + else + { + requirementsGroup.ThingPreference = thingPreferenceProperty.GetString(); + } } return requirementsGroup; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs index 5b8809297..88be8d42b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RequirementsSpecificationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,111 +28,186 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RequirementsSpecificationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RequirementsSpecification FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RequirementsSpecification FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var requirementsSpecification = new CDP4Common.DTO.RequirementsSpecification(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RequirementsSpecificationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - requirementsSpecification.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var requirementsSpecification = new CDP4Common.DTO.RequirementsSpecification(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + requirementsSpecification.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + requirementsSpecification.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + requirementsSpecification.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + requirementsSpecification.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + requirementsSpecification.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["group"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("group"u8, out var groupProperty) && groupProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.Group.AddRange(jObject["group"].ToObject>()); + foreach(var element in groupProperty.EnumerateArray()) + { + requirementsSpecification.Group.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + requirementsSpecification.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - requirementsSpecification.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - requirementsSpecification.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - requirementsSpecification.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - requirementsSpecification.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["parameterValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterValue"u8, out var parameterValueProperty) && parameterValueProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.ParameterValue.AddRange(jObject["parameterValue"].ToObject>()); + foreach(var element in parameterValueProperty.EnumerateArray()) + { + requirementsSpecification.ParameterValue.Add(element.GetGuid()); + } } - if (!jObject["requirement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requirement"u8, out var requirementProperty) && requirementProperty.ValueKind != JsonValueKind.Null) { - requirementsSpecification.Requirement.AddRange(jObject["requirement"].ToObject>()); + foreach(var element in requirementProperty.EnumerateArray()) + { + requirementsSpecification.Requirement.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - requirementsSpecification.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - requirementsSpecification.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the requirementsSpecification {id} is null", requirementsSpecification.Iid); + } + else + { + requirementsSpecification.ThingPreference = thingPreferenceProperty.GetString(); + } } return requirementsSpecification; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs index 57a009935..84139d605 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ReviewItemDiscrepancyResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,136 +28,250 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ReviewItemDiscrepancyResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ReviewItemDiscrepancy FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ReviewItemDiscrepancy FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var reviewItemDiscrepancy = new CDP4Common.DTO.ReviewItemDiscrepancy(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ReviewItemDiscrepancyResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - reviewItemDiscrepancy.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["approvedBy"].IsNullOrEmpty()) + var reviewItemDiscrepancy = new CDP4Common.DTO.ReviewItemDiscrepancy(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("approvedBy"u8, out var approvedByProperty) && approvedByProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.ApprovedBy.AddRange(jObject["approvedBy"].ToObject>()); + foreach(var element in approvedByProperty.EnumerateArray()) + { + reviewItemDiscrepancy.ApprovedBy.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - reviewItemDiscrepancy.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + reviewItemDiscrepancy.Category.Add(element.GetGuid()); + } } - if (!jObject["classification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("classification"u8, out var classificationProperty)) { - reviewItemDiscrepancy.Classification = jObject["classification"].ToObject(); + if(classificationProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale classification property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Classification = AnnotationClassificationKindDeserializer.Deserialize(classificationProperty); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - reviewItemDiscrepancy.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - reviewItemDiscrepancy.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + reviewItemDiscrepancy.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + reviewItemDiscrepancy.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + reviewItemDiscrepancy.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - reviewItemDiscrepancy.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - reviewItemDiscrepancy.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - reviewItemDiscrepancy.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - reviewItemDiscrepancy.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + reviewItemDiscrepancy.PrimaryAnnotatedThing = null; + } + else + { + reviewItemDiscrepancy.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + reviewItemDiscrepancy.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - reviewItemDiscrepancy.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["solution"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("solution"u8, out var solutionProperty) && solutionProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.Solution.AddRange(jObject["solution"].ToObject>()); + foreach(var element in solutionProperty.EnumerateArray()) + { + reviewItemDiscrepancy.Solution.Add(element.GetGuid()); + } } - if (!jObject["sourceAnnotation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("sourceAnnotation"u8, out var sourceAnnotationProperty) && sourceAnnotationProperty.ValueKind != JsonValueKind.Null) { - reviewItemDiscrepancy.SourceAnnotation.AddRange(jObject["sourceAnnotation"].ToObject>()); + foreach(var element in sourceAnnotationProperty.EnumerateArray()) + { + reviewItemDiscrepancy.SourceAnnotation.Add(element.GetGuid()); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - reviewItemDiscrepancy.Status = jObject["status"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Status = AnnotationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - reviewItemDiscrepancy.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["title"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("title"u8, out var titleProperty)) { - reviewItemDiscrepancy.Title = jObject["title"].ToObject(); + if(titleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale title property of the reviewItemDiscrepancy {id} is null", reviewItemDiscrepancy.Iid); + } + else + { + reviewItemDiscrepancy.Title = titleProperty.GetString(); + } } return reviewItemDiscrepancy; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs index ac0a0809d..b7f82649b 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleVerificationListResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,147 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RuleVerificationListResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RuleVerificationList FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RuleVerificationList FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var ruleVerificationList = new CDP4Common.DTO.RuleVerificationList(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RuleVerificationListResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - ruleVerificationList.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var ruleVerificationList = new CDP4Common.DTO.RuleVerificationList(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - ruleVerificationList.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + ruleVerificationList.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - ruleVerificationList.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + ruleVerificationList.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - ruleVerificationList.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + ruleVerificationList.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - ruleVerificationList.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + ruleVerificationList.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - ruleVerificationList.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + ruleVerificationList.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - ruleVerificationList.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + } + else + { + ruleVerificationList.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - ruleVerificationList.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + } + else + { + ruleVerificationList.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - ruleVerificationList.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + } + else + { + ruleVerificationList.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["ruleVerification"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("ruleVerification"u8, out var ruleVerificationProperty)) { - ruleVerificationList.RuleVerification.AddRange(jObject["ruleVerification"].ToOrderedItemCollection()); + ruleVerificationList.RuleVerification.AddRange(ruleVerificationProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - ruleVerificationList.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + } + else + { + ruleVerificationList.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - ruleVerificationList.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the ruleVerificationList {id} is null", ruleVerificationList.Iid); + } + else + { + ruleVerificationList.ThingPreference = thingPreferenceProperty.GetString(); + } } return ruleVerificationList; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs index 9ba38c9ff..42e18210f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/RuleViolationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,102 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class RuleViolationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.RuleViolation FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.RuleViolation FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var ruleViolation = new CDP4Common.DTO.RuleViolation(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the RuleViolationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - ruleViolation.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["description"].IsNullOrEmpty()) + var ruleViolation = new CDP4Common.DTO.RuleViolation(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("description"u8, out var descriptionProperty)) { - ruleViolation.Description = jObject["description"].ToObject(); + if(descriptionProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale description property of the ruleViolation {id} is null", ruleViolation.Iid); + } + else + { + ruleViolation.Description = descriptionProperty.GetString(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - ruleViolation.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + ruleViolation.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - ruleViolation.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + ruleViolation.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - ruleViolation.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the ruleViolation {id} is null", ruleViolation.Iid); + } + else + { + ruleViolation.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - ruleViolation.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the ruleViolation {id} is null", ruleViolation.Iid); + } + else + { + ruleViolation.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["violatingThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("violatingThing"u8, out var violatingThingProperty) && violatingThingProperty.ValueKind != JsonValueKind.Null) { - ruleViolation.ViolatingThing.AddRange(jObject["violatingThing"].ToObject>()); + foreach(var element in violatingThingProperty.EnumerateArray()) + { + ruleViolation.ViolatingThing.Add(element.GetGuid()); + } } return ruleViolation; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs index 5fc183341..9b29fd145 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SampledFunctionParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,116 +28,201 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SampledFunctionParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SampledFunctionParameterType FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var sampledFunctionParameterType = new CDP4Common.DTO.SampledFunctionParameterType(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SampledFunctionParameterType FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - sampledFunctionParameterType.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the SampledFunctionParameterTypeResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["alias"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - sampledFunctionParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var sampledFunctionParameterType = new CDP4Common.DTO.SampledFunctionParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + sampledFunctionParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + sampledFunctionParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["degreeOfInterpolation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.DegreeOfInterpolation = jObject["degreeOfInterpolation"].ToObject(); + foreach(var element in definitionProperty.EnumerateArray()) + { + sampledFunctionParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["dependentParameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("degreeOfInterpolation"u8, out var degreeOfInterpolationProperty)) { - sampledFunctionParameterType.DependentParameterType.AddRange(jObject["dependentParameterType"].ToOrderedItemCollection()); + if(degreeOfInterpolationProperty.ValueKind == JsonValueKind.Null) + { + sampledFunctionParameterType.DegreeOfInterpolation = null; + } + else + { + sampledFunctionParameterType.DegreeOfInterpolation = degreeOfInterpolationProperty.GetInt32(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("dependentParameterType"u8, out var dependentParameterTypeProperty)) { - sampledFunctionParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + sampledFunctionParameterType.DependentParameterType.AddRange(dependentParameterTypeProperty.ToOrderedItemCollection()); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + sampledFunctionParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + sampledFunctionParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["independentParameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - sampledFunctionParameterType.IndependentParameterType.AddRange(jObject["independentParameterType"].ToOrderedItemCollection()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + sampledFunctionParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["interpolationPeriod"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("independentParameterType"u8, out var independentParameterTypeProperty)) { - sampledFunctionParameterType.InterpolationPeriod = SerializerHelper.ToValueArray(jObject["interpolationPeriod"].ToString()); + sampledFunctionParameterType.IndependentParameterType.AddRange(independentParameterTypeProperty.ToOrderedItemCollection()); + } + if (jsonElement.TryGetProperty("interpolationPeriod"u8, out var interpolationPeriodProperty)) + { + if (interpolationPeriodProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in interpolationPeriodProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + sampledFunctionParameterType.InterpolationPeriod = new ValueArray(newValueArrayItems); + } + else + { + sampledFunctionParameterType.InterpolationPeriod = SerializerHelper.ToValueArray(interpolationPeriodProperty.GetString()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - sampledFunctionParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - sampledFunctionParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - sampledFunctionParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - sampledFunctionParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - sampledFunctionParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - sampledFunctionParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the sampledFunctionParameterType {id} is null", sampledFunctionParameterType.Iid); + } + else + { + sampledFunctionParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return sampledFunctionParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs index c174b94af..b9a29a9fc 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleReferenceQuantityValueResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,106 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ScaleReferenceQuantityValueResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ScaleReferenceQuantityValue FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ScaleReferenceQuantityValue FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var scaleReferenceQuantityValue = new CDP4Common.DTO.ScaleReferenceQuantityValue(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ScaleReferenceQuantityValueResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - scaleReferenceQuantityValue.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var scaleReferenceQuantityValue = new CDP4Common.DTO.ScaleReferenceQuantityValue(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - scaleReferenceQuantityValue.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + scaleReferenceQuantityValue.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - scaleReferenceQuantityValue.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + scaleReferenceQuantityValue.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - scaleReferenceQuantityValue.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); + } + else + { + scaleReferenceQuantityValue.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - scaleReferenceQuantityValue.Scale = jObject["scale"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale scale property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); + } + else + { + scaleReferenceQuantityValue.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - scaleReferenceQuantityValue.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); + } + else + { + scaleReferenceQuantityValue.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - scaleReferenceQuantityValue.Value = jObject["value"].ToObject(); + if(valueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale value property of the scaleReferenceQuantityValue {id} is null", scaleReferenceQuantityValue.Iid); + } + else + { + scaleReferenceQuantityValue.Value = valueProperty.GetString(); + } } return scaleReferenceQuantityValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs index ea7fb849c..48bd0fbf2 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ScaleValueDefinitionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,142 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ScaleValueDefinitionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ScaleValueDefinition FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ScaleValueDefinition FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var scaleValueDefinition = new CDP4Common.DTO.ScaleValueDefinition(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ScaleValueDefinitionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - scaleValueDefinition.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var scaleValueDefinition = new CDP4Common.DTO.ScaleValueDefinition(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - scaleValueDefinition.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + scaleValueDefinition.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - scaleValueDefinition.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + scaleValueDefinition.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - scaleValueDefinition.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + scaleValueDefinition.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - scaleValueDefinition.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + scaleValueDefinition.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - scaleValueDefinition.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + scaleValueDefinition.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - scaleValueDefinition.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + } + else + { + scaleValueDefinition.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - scaleValueDefinition.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + } + else + { + scaleValueDefinition.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - scaleValueDefinition.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + } + else + { + scaleValueDefinition.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - scaleValueDefinition.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + } + else + { + scaleValueDefinition.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - scaleValueDefinition.Value = jObject["value"].ToObject(); + if(valueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale value property of the scaleValueDefinition {id} is null", scaleValueDefinition.Iid); + } + else + { + scaleValueDefinition.Value = valueProperty.GetString(); + } } return scaleValueDefinition; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs index 326050662..6ac9398e4 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SectionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,143 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SectionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Section FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Section FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var section = new CDP4Common.DTO.Section(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SectionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - section.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var section = new CDP4Common.DTO.Section(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - section.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + section.Category.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - section.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the section {id} is null", section.Iid); + } + else + { + section.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - section.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + section.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - section.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + section.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - section.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the section {id} is null", section.Iid); + } + else + { + section.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - section.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the section {id} is null", section.Iid); + } + else + { + section.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - section.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the section {id} is null", section.Iid); + } + else + { + section.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["page"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("page"u8, out var pageProperty)) { - section.Page.AddRange(jObject["page"].ToOrderedItemCollection()); + section.Page.AddRange(pageProperty.ToOrderedItemCollection()); } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - section.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the section {id} is null", section.Iid); + } + else + { + section.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - section.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the section {id} is null", section.Iid); + } + else + { + section.ThingPreference = thingPreferenceProperty.GetString(); + } } return section; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs index c027c93b0..a3718665f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SharedStyleResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,126 +28,246 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SharedStyleResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SharedStyle FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SharedStyle FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var sharedStyle = new CDP4Common.DTO.SharedStyle(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SharedStyleResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - sharedStyle.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var sharedStyle = new CDP4Common.DTO.SharedStyle(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - sharedStyle.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + sharedStyle.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - sharedStyle.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + sharedStyle.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fillColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fillColor"u8, out var fillColorProperty)) { - sharedStyle.FillColor = jObject["fillColor"].ToObject(); + if(fillColorProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FillColor = null; + } + else + { + sharedStyle.FillColor = fillColorProperty.GetGuid(); + } } - if (!jObject["fillOpacity"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fillOpacity"u8, out var fillOpacityProperty)) { - sharedStyle.FillOpacity = jObject["fillOpacity"].ToObject(); + if(fillOpacityProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FillOpacity = null; + } + else + { + sharedStyle.FillOpacity = fillOpacityProperty.GetSingle(); + } } - if (!jObject["fontBold"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontBold"u8, out var fontBoldProperty)) { - sharedStyle.FontBold = jObject["fontBold"].ToObject(); + if(fontBoldProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontBold = null; + } + else + { + sharedStyle.FontBold = fontBoldProperty.GetBoolean(); + } } - if (!jObject["fontColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontColor"u8, out var fontColorProperty)) { - sharedStyle.FontColor = jObject["fontColor"].ToObject(); + if(fontColorProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontColor = null; + } + else + { + sharedStyle.FontColor = fontColorProperty.GetGuid(); + } } - if (!jObject["fontItalic"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontItalic"u8, out var fontItalicProperty)) { - sharedStyle.FontItalic = jObject["fontItalic"].ToObject(); + if(fontItalicProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontItalic = null; + } + else + { + sharedStyle.FontItalic = fontItalicProperty.GetBoolean(); + } } - if (!jObject["fontName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontName"u8, out var fontNameProperty)) { - sharedStyle.FontName = jObject["fontName"].ToObject(); + if(fontNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale fontName property of the sharedStyle {id} is null", sharedStyle.Iid); + } + else + { + sharedStyle.FontName = fontNameProperty.GetString(); + } } - if (!jObject["fontSize"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontSize"u8, out var fontSizeProperty)) { - sharedStyle.FontSize = jObject["fontSize"].ToObject(); + if(fontSizeProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontSize = null; + } + else + { + sharedStyle.FontSize = fontSizeProperty.GetSingle(); + } } - if (!jObject["fontStrokeThrough"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontStrokeThrough"u8, out var fontStrokeThroughProperty)) { - sharedStyle.FontStrokeThrough = jObject["fontStrokeThrough"].ToObject(); + if(fontStrokeThroughProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontStrokeThrough = null; + } + else + { + sharedStyle.FontStrokeThrough = fontStrokeThroughProperty.GetBoolean(); + } } - if (!jObject["fontUnderline"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fontUnderline"u8, out var fontUnderlineProperty)) { - sharedStyle.FontUnderline = jObject["fontUnderline"].ToObject(); + if(fontUnderlineProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.FontUnderline = null; + } + else + { + sharedStyle.FontUnderline = fontUnderlineProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - sharedStyle.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the sharedStyle {id} is null", sharedStyle.Iid); + } + else + { + sharedStyle.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - sharedStyle.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the sharedStyle {id} is null", sharedStyle.Iid); + } + else + { + sharedStyle.Name = nameProperty.GetString(); + } } - if (!jObject["strokeColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeColor"u8, out var strokeColorProperty)) { - sharedStyle.StrokeColor = jObject["strokeColor"].ToObject(); + if(strokeColorProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.StrokeColor = null; + } + else + { + sharedStyle.StrokeColor = strokeColorProperty.GetGuid(); + } } - if (!jObject["strokeOpacity"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeOpacity"u8, out var strokeOpacityProperty)) { - sharedStyle.StrokeOpacity = jObject["strokeOpacity"].ToObject(); + if(strokeOpacityProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.StrokeOpacity = null; + } + else + { + sharedStyle.StrokeOpacity = strokeOpacityProperty.GetSingle(); + } } - if (!jObject["strokeWidth"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("strokeWidth"u8, out var strokeWidthProperty)) { - sharedStyle.StrokeWidth = jObject["strokeWidth"].ToObject(); + if(strokeWidthProperty.ValueKind == JsonValueKind.Null) + { + sharedStyle.StrokeWidth = null; + } + else + { + sharedStyle.StrokeWidth = strokeWidthProperty.GetSingle(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - sharedStyle.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the sharedStyle {id} is null", sharedStyle.Iid); + } + else + { + sharedStyle.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["usedColor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("usedColor"u8, out var usedColorProperty) && usedColorProperty.ValueKind != JsonValueKind.Null) { - sharedStyle.UsedColor.AddRange(jObject["usedColor"].ToObject>()); + foreach(var element in usedColorProperty.EnumerateArray()) + { + sharedStyle.UsedColor.Add(element.GetGuid()); + } } return sharedStyle; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs index 0dce0d358..e417f203d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleParameterValueResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,123 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SimpleParameterValueResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SimpleParameterValue FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var simpleParameterValue = new CDP4Common.DTO.SimpleParameterValue(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SimpleParameterValue FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - simpleParameterValue.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the SimpleParameterValueResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - simpleParameterValue.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var simpleParameterValue = new CDP4Common.DTO.SimpleParameterValue(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - simpleParameterValue.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + simpleParameterValue.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - simpleParameterValue.ModifiedOn = jObject["modifiedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + simpleParameterValue.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - simpleParameterValue.ParameterType = jObject["parameterType"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the simpleParameterValue {id} is null", simpleParameterValue.Iid); + } + else + { + simpleParameterValue.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty)) { - simpleParameterValue.Scale = jObject["scale"].ToObject(); + if(parameterTypeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale parameterType property of the simpleParameterValue {id} is null", simpleParameterValue.Iid); + } + else + { + simpleParameterValue.ParameterType = parameterTypeProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty)) { - simpleParameterValue.ThingPreference = jObject["thingPreference"].ToObject(); + if(scaleProperty.ValueKind == JsonValueKind.Null) + { + simpleParameterValue.Scale = null; + } + else + { + simpleParameterValue.Scale = scaleProperty.GetGuid(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - simpleParameterValue.Value = SerializerHelper.ToValueArray(jObject["value"].ToString()); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the simpleParameterValue {id} is null", simpleParameterValue.Iid); + } + else + { + simpleParameterValue.ThingPreference = thingPreferenceProperty.GetString(); + } + } + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) + { + if (valueProperty.ValueKind == JsonValueKind.Array) + { + var newValueArrayItems = new List(); + + foreach(var element in valueProperty.EnumerateArray()) + { + newValueArrayItems.Add(element.GetString()); + } + simpleParameterValue.Value = new ValueArray(newValueArrayItems); + } + else + { + simpleParameterValue.Value = SerializerHelper.ToValueArray(valueProperty.GetString()); + } } return simpleParameterValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs index 44eb3d022..4983d1647 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleQuantityKindResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,111 +28,194 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SimpleQuantityKindResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SimpleQuantityKind FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SimpleQuantityKind FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var simpleQuantityKind = new CDP4Common.DTO.SimpleQuantityKind(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SimpleQuantityKindResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - simpleQuantityKind.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var simpleQuantityKind = new CDP4Common.DTO.SimpleQuantityKind(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + simpleQuantityKind.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + simpleQuantityKind.Category.Add(element.GetGuid()); + } } - if (!jObject["defaultScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultScale"u8, out var defaultScaleProperty)) { - simpleQuantityKind.DefaultScale = jObject["defaultScale"].ToObject(); + if(defaultScaleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale defaultScale property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.DefaultScale = defaultScaleProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + simpleQuantityKind.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + simpleQuantityKind.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + simpleQuantityKind.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + simpleQuantityKind.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - simpleQuantityKind.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - simpleQuantityKind.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - simpleQuantityKind.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.Name = nameProperty.GetString(); + } } - if (!jObject["possibleScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleScale"u8, out var possibleScaleProperty) && possibleScaleProperty.ValueKind != JsonValueKind.Null) { - simpleQuantityKind.PossibleScale.AddRange(jObject["possibleScale"].ToObject>()); + foreach(var element in possibleScaleProperty.EnumerateArray()) + { + simpleQuantityKind.PossibleScale.Add(element.GetGuid()); + } } - if (!jObject["quantityDimensionSymbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("quantityDimensionSymbol"u8, out var quantityDimensionSymbolProperty)) { - simpleQuantityKind.QuantityDimensionSymbol = jObject["quantityDimensionSymbol"].ToObject(); + if(quantityDimensionSymbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale quantityDimensionSymbol property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.QuantityDimensionSymbol = quantityDimensionSymbolProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - simpleQuantityKind.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - simpleQuantityKind.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - simpleQuantityKind.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the simpleQuantityKind {id} is null", simpleQuantityKind.Iid); + } + else + { + simpleQuantityKind.ThingPreference = thingPreferenceProperty.GetString(); + } } return simpleQuantityKind; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs index 35413600a..758253cac 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SimpleUnitResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,142 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SimpleUnitResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SimpleUnit FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SimpleUnit FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var simpleUnit = new CDP4Common.DTO.SimpleUnit(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SimpleUnitResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - simpleUnit.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var simpleUnit = new CDP4Common.DTO.SimpleUnit(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - simpleUnit.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + simpleUnit.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - simpleUnit.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + simpleUnit.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - simpleUnit.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + simpleUnit.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - simpleUnit.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + simpleUnit.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - simpleUnit.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + simpleUnit.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - simpleUnit.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the simpleUnit {id} is null", simpleUnit.Iid); + } + else + { + simpleUnit.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - simpleUnit.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the simpleUnit {id} is null", simpleUnit.Iid); + } + else + { + simpleUnit.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - simpleUnit.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the simpleUnit {id} is null", simpleUnit.Iid); + } + else + { + simpleUnit.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - simpleUnit.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the simpleUnit {id} is null", simpleUnit.Iid); + } + else + { + simpleUnit.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - simpleUnit.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the simpleUnit {id} is null", simpleUnit.Iid); + } + else + { + simpleUnit.ThingPreference = thingPreferenceProperty.GetString(); + } } return simpleUnit; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs index c6dea9921..f06dc09f9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataAnnotationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,158 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteDirectoryDataAnnotationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteDirectoryDataAnnotation FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteDirectoryDataAnnotation FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteDirectoryDataAnnotation = new CDP4Common.DTO.SiteDirectoryDataAnnotation(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteDirectoryDataAnnotationResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteDirectoryDataAnnotation.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var siteDirectoryDataAnnotation = new CDP4Common.DTO.SiteDirectoryDataAnnotation(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - siteDirectoryDataAnnotation.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.Author = authorProperty.GetGuid(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - siteDirectoryDataAnnotation.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - siteDirectoryDataAnnotation.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["discussion"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("discussion"u8, out var discussionProperty) && discussionProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataAnnotation.Discussion.AddRange(jObject["discussion"].ToObject>()); + foreach(var element in discussionProperty.EnumerateArray()) + { + siteDirectoryDataAnnotation.Discussion.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataAnnotation.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteDirectoryDataAnnotation.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataAnnotation.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteDirectoryDataAnnotation.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - siteDirectoryDataAnnotation.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteDirectoryDataAnnotation.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["primaryAnnotatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("primaryAnnotatedThing"u8, out var primaryAnnotatedThingProperty)) { - siteDirectoryDataAnnotation.PrimaryAnnotatedThing = jObject["primaryAnnotatedThing"].ToObject(); + if(primaryAnnotatedThingProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale primaryAnnotatedThing property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.PrimaryAnnotatedThing = primaryAnnotatedThingProperty.GetGuid(); + } } - if (!jObject["relatedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("relatedThing"u8, out var relatedThingProperty) && relatedThingProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataAnnotation.RelatedThing.AddRange(jObject["relatedThing"].ToObject>()); + foreach(var element in relatedThingProperty.EnumerateArray()) + { + siteDirectoryDataAnnotation.RelatedThing.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteDirectoryDataAnnotation.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the siteDirectoryDataAnnotation {id} is null", siteDirectoryDataAnnotation.Iid); + } + else + { + siteDirectoryDataAnnotation.ThingPreference = thingPreferenceProperty.GetString(); + } } return siteDirectoryDataAnnotation; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs index 03794401c..5380d655a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryDataDiscussionItemResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,142 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteDirectoryDataDiscussionItemResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteDirectoryDataDiscussionItem FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteDirectoryDataDiscussionItem FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteDirectoryDataDiscussionItem = new CDP4Common.DTO.SiteDirectoryDataDiscussionItem(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteDirectoryDataDiscussionItemResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteDirectoryDataDiscussionItem.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var siteDirectoryDataDiscussionItem = new CDP4Common.DTO.SiteDirectoryDataDiscussionItem(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - siteDirectoryDataDiscussionItem.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.Author = authorProperty.GetGuid(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - siteDirectoryDataDiscussionItem.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - siteDirectoryDataDiscussionItem.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataDiscussionItem.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteDirectoryDataDiscussionItem.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryDataDiscussionItem.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteDirectoryDataDiscussionItem.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - siteDirectoryDataDiscussionItem.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteDirectoryDataDiscussionItem.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["replyTo"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("replyTo"u8, out var replyToProperty)) { - siteDirectoryDataDiscussionItem.ReplyTo = jObject["replyTo"].ToObject(); + if(replyToProperty.ValueKind == JsonValueKind.Null) + { + siteDirectoryDataDiscussionItem.ReplyTo = null; + } + else + { + siteDirectoryDataDiscussionItem.ReplyTo = replyToProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteDirectoryDataDiscussionItem.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the siteDirectoryDataDiscussionItem {id} is null", siteDirectoryDataDiscussionItem.Iid); + } + else + { + siteDirectoryDataDiscussionItem.ThingPreference = thingPreferenceProperty.GetString(); + } } return siteDirectoryDataDiscussionItem; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs index add3d1f0f..a1b7aefc8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,141 +28,242 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteDirectoryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteDirectory FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteDirectory FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteDirectory = new CDP4Common.DTO.SiteDirectory(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteDirectoryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteDirectory.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["annotation"].IsNullOrEmpty()) + var siteDirectory = new CDP4Common.DTO.SiteDirectory(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("annotation"u8, out var annotationProperty) && annotationProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.Annotation.AddRange(jObject["annotation"].ToObject>()); + foreach(var element in annotationProperty.EnumerateArray()) + { + siteDirectory.Annotation.Add(element.GetGuid()); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - siteDirectory.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["defaultParticipantRole"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultParticipantRole"u8, out var defaultParticipantRoleProperty)) { - siteDirectory.DefaultParticipantRole = jObject["defaultParticipantRole"].ToObject(); + if(defaultParticipantRoleProperty.ValueKind == JsonValueKind.Null) + { + siteDirectory.DefaultParticipantRole = null; + } + else + { + siteDirectory.DefaultParticipantRole = defaultParticipantRoleProperty.GetGuid(); + } } - if (!jObject["defaultPersonRole"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultPersonRole"u8, out var defaultPersonRoleProperty)) { - siteDirectory.DefaultPersonRole = jObject["defaultPersonRole"].ToObject(); + if(defaultPersonRoleProperty.ValueKind == JsonValueKind.Null) + { + siteDirectory.DefaultPersonRole = null; + } + else + { + siteDirectory.DefaultPersonRole = defaultPersonRoleProperty.GetGuid(); + } } - if (!jObject["domain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("domain"u8, out var domainProperty) && domainProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.Domain.AddRange(jObject["domain"].ToObject>()); + foreach(var element in domainProperty.EnumerateArray()) + { + siteDirectory.Domain.Add(element.GetGuid()); + } } - if (!jObject["domainGroup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("domainGroup"u8, out var domainGroupProperty) && domainGroupProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.DomainGroup.AddRange(jObject["domainGroup"].ToObject>()); + foreach(var element in domainGroupProperty.EnumerateArray()) + { + siteDirectory.DomainGroup.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteDirectory.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteDirectory.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["lastModifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("lastModifiedOn"u8, out var lastModifiedOnProperty)) { - siteDirectory.LastModifiedOn = jObject["lastModifiedOn"].ToObject(); + if(lastModifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale lastModifiedOn property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.LastModifiedOn = lastModifiedOnProperty.GetDateTime(); + } } - if (!jObject["logEntry"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("logEntry"u8, out var logEntryProperty) && logEntryProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.LogEntry.AddRange(jObject["logEntry"].ToObject>()); + foreach(var element in logEntryProperty.EnumerateArray()) + { + siteDirectory.LogEntry.Add(element.GetGuid()); + } } - if (!jObject["model"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("model"u8, out var modelProperty) && modelProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.Model.AddRange(jObject["model"].ToObject>()); + foreach(var element in modelProperty.EnumerateArray()) + { + siteDirectory.Model.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteDirectory.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - siteDirectory.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.Name = nameProperty.GetString(); + } } - if (!jObject["naturalLanguage"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("naturalLanguage"u8, out var naturalLanguageProperty) && naturalLanguageProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.NaturalLanguage.AddRange(jObject["naturalLanguage"].ToObject>()); + foreach(var element in naturalLanguageProperty.EnumerateArray()) + { + siteDirectory.NaturalLanguage.Add(element.GetGuid()); + } } - if (!jObject["organization"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("organization"u8, out var organizationProperty) && organizationProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.Organization.AddRange(jObject["organization"].ToObject>()); + foreach(var element in organizationProperty.EnumerateArray()) + { + siteDirectory.Organization.Add(element.GetGuid()); + } } - if (!jObject["participantRole"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("participantRole"u8, out var participantRoleProperty) && participantRoleProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.ParticipantRole.AddRange(jObject["participantRole"].ToObject>()); + foreach(var element in participantRoleProperty.EnumerateArray()) + { + siteDirectory.ParticipantRole.Add(element.GetGuid()); + } } - if (!jObject["person"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("person"u8, out var personProperty) && personProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.Person.AddRange(jObject["person"].ToObject>()); + foreach(var element in personProperty.EnumerateArray()) + { + siteDirectory.Person.Add(element.GetGuid()); + } } - if (!jObject["personRole"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("personRole"u8, out var personRoleProperty) && personRoleProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.PersonRole.AddRange(jObject["personRole"].ToObject>()); + foreach(var element in personRoleProperty.EnumerateArray()) + { + siteDirectory.PersonRole.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - siteDirectory.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["siteReferenceDataLibrary"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("siteReferenceDataLibrary"u8, out var siteReferenceDataLibraryProperty) && siteReferenceDataLibraryProperty.ValueKind != JsonValueKind.Null) { - siteDirectory.SiteReferenceDataLibrary.AddRange(jObject["siteReferenceDataLibrary"].ToObject>()); + foreach(var element in siteReferenceDataLibraryProperty.EnumerateArray()) + { + siteDirectory.SiteReferenceDataLibrary.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteDirectory.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the siteDirectory {id} is null", siteDirectory.Iid); + } + else + { + siteDirectory.ThingPreference = thingPreferenceProperty.GetString(); + } } return siteDirectory; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs index 93f9951fd..73ca4f387 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteDirectoryThingReferenceResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,106 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteDirectoryThingReferenceResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteDirectoryThingReference FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteDirectoryThingReference FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteDirectoryThingReference = new CDP4Common.DTO.SiteDirectoryThingReference(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteDirectoryThingReferenceResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteDirectoryThingReference.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var siteDirectoryThingReference = new CDP4Common.DTO.SiteDirectoryThingReference(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryThingReference.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteDirectoryThingReference.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteDirectoryThingReference.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteDirectoryThingReference.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteDirectoryThingReference.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); + } + else + { + siteDirectoryThingReference.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["referencedRevisionNumber"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedRevisionNumber"u8, out var referencedRevisionNumberProperty)) { - siteDirectoryThingReference.ReferencedRevisionNumber = jObject["referencedRevisionNumber"].ToObject(); + if(referencedRevisionNumberProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referencedRevisionNumber property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); + } + else + { + siteDirectoryThingReference.ReferencedRevisionNumber = referencedRevisionNumberProperty.GetInt32(); + } } - if (!jObject["referencedThing"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referencedThing"u8, out var referencedThingProperty)) { - siteDirectoryThingReference.ReferencedThing = jObject["referencedThing"].ToObject(); + if(referencedThingProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale referencedThing property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); + } + else + { + siteDirectoryThingReference.ReferencedThing = referencedThingProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteDirectoryThingReference.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the siteDirectoryThingReference {id} is null", siteDirectoryThingReference.Iid); + } + else + { + siteDirectoryThingReference.ThingPreference = thingPreferenceProperty.GetString(); + } } return siteDirectoryThingReference; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs index a812d610f..17876d3eb 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteLogEntryResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,101 +28,174 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteLogEntryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteLogEntry FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteLogEntry FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteLogEntry = new CDP4Common.DTO.SiteLogEntry(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteLogEntryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteLogEntry.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["affectedDomainIid"].IsNullOrEmpty()) + var siteLogEntry = new CDP4Common.DTO.SiteLogEntry(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("affectedDomainIid"u8, out var affectedDomainIidProperty) && affectedDomainIidProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.AffectedDomainIid.AddRange(jObject["affectedDomainIid"].ToObject>()); + foreach(var element in affectedDomainIidProperty.EnumerateArray()) + { + siteLogEntry.AffectedDomainIid.Add(element.GetGuid()); + } } - if (!jObject["affectedItemIid"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("affectedItemIid"u8, out var affectedItemIidProperty) && affectedItemIidProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.AffectedItemIid.AddRange(jObject["affectedItemIid"].ToObject>()); + foreach(var element in affectedItemIidProperty.EnumerateArray()) + { + siteLogEntry.AffectedItemIid.Add(element.GetGuid()); + } } - if (!jObject["author"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - siteLogEntry.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + siteLogEntry.Author = null; + } + else + { + siteLogEntry.Author = authorProperty.GetGuid(); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + siteLogEntry.Category.Add(element.GetGuid()); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - siteLogEntry.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - siteLogEntry.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteLogEntry.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteLogEntry.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - siteLogEntry.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["level"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("level"u8, out var levelProperty)) { - siteLogEntry.Level = jObject["level"].ToObject(); + if(levelProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale level property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.Level = LogLevelKindDeserializer.Deserialize(levelProperty); + } } - if (!jObject["logEntryChangelogItem"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("logEntryChangelogItem"u8, out var logEntryChangelogItemProperty) && logEntryChangelogItemProperty.ValueKind != JsonValueKind.Null) { - siteLogEntry.LogEntryChangelogItem.AddRange(jObject["logEntryChangelogItem"].ToObject>()); + foreach(var element in logEntryChangelogItemProperty.EnumerateArray()) + { + siteLogEntry.LogEntryChangelogItem.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteLogEntry.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteLogEntry.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the siteLogEntry {id} is null", siteLogEntry.Iid); + } + else + { + siteLogEntry.ThingPreference = thingPreferenceProperty.GetString(); + } } return siteLogEntry; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs index a692f08e7..b52c064a8 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SiteReferenceDataLibraryResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,151 +28,247 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SiteReferenceDataLibraryResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SiteReferenceDataLibrary FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SiteReferenceDataLibrary FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var siteReferenceDataLibrary = new CDP4Common.DTO.SiteReferenceDataLibrary(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SiteReferenceDataLibraryResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - siteReferenceDataLibrary.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var siteReferenceDataLibrary = new CDP4Common.DTO.SiteReferenceDataLibrary(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Alias.Add(element.GetGuid()); + } } - if (!jObject["baseQuantityKind"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("baseQuantityKind"u8, out var baseQuantityKindProperty)) { - siteReferenceDataLibrary.BaseQuantityKind.AddRange(jObject["baseQuantityKind"].ToOrderedItemCollection()); + siteReferenceDataLibrary.BaseQuantityKind.AddRange(baseQuantityKindProperty.ToOrderedItemCollection()); } - if (!jObject["baseUnit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("baseUnit"u8, out var baseUnitProperty) && baseUnitProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.BaseUnit.AddRange(jObject["baseUnit"].ToObject>()); + foreach(var element in baseUnitProperty.EnumerateArray()) + { + siteReferenceDataLibrary.BaseUnit.Add(element.GetGuid()); + } } - if (!jObject["constant"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("constant"u8, out var constantProperty) && constantProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Constant.AddRange(jObject["constant"].ToObject>()); + foreach(var element in constantProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Constant.Add(element.GetGuid()); + } } - if (!jObject["definedCategory"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definedCategory"u8, out var definedCategoryProperty) && definedCategoryProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.DefinedCategory.AddRange(jObject["definedCategory"].ToObject>()); + foreach(var element in definedCategoryProperty.EnumerateArray()) + { + siteReferenceDataLibrary.DefinedCategory.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + siteReferenceDataLibrary.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + siteReferenceDataLibrary.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["fileType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("fileType"u8, out var fileTypeProperty) && fileTypeProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.FileType.AddRange(jObject["fileType"].ToObject>()); + foreach(var element in fileTypeProperty.EnumerateArray()) + { + siteReferenceDataLibrary.FileType.Add(element.GetGuid()); + } } - if (!jObject["glossary"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("glossary"u8, out var glossaryProperty) && glossaryProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Glossary.AddRange(jObject["glossary"].ToObject>()); + foreach(var element in glossaryProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Glossary.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + siteReferenceDataLibrary.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - siteReferenceDataLibrary.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + } + else + { + siteReferenceDataLibrary.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - siteReferenceDataLibrary.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + } + else + { + siteReferenceDataLibrary.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - siteReferenceDataLibrary.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + } + else + { + siteReferenceDataLibrary.Name = nameProperty.GetString(); + } } - if (!jObject["parameterType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("parameterType"u8, out var parameterTypeProperty) && parameterTypeProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.ParameterType.AddRange(jObject["parameterType"].ToObject>()); + foreach(var element in parameterTypeProperty.EnumerateArray()) + { + siteReferenceDataLibrary.ParameterType.Add(element.GetGuid()); + } } - if (!jObject["referenceSource"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("referenceSource"u8, out var referenceSourceProperty) && referenceSourceProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.ReferenceSource.AddRange(jObject["referenceSource"].ToObject>()); + foreach(var element in referenceSourceProperty.EnumerateArray()) + { + siteReferenceDataLibrary.ReferenceSource.Add(element.GetGuid()); + } } - if (!jObject["requiredRdl"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requiredRdl"u8, out var requiredRdlProperty)) { - siteReferenceDataLibrary.RequiredRdl = jObject["requiredRdl"].ToObject(); + if(requiredRdlProperty.ValueKind == JsonValueKind.Null) + { + siteReferenceDataLibrary.RequiredRdl = null; + } + else + { + siteReferenceDataLibrary.RequiredRdl = requiredRdlProperty.GetGuid(); + } } - if (!jObject["rule"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("rule"u8, out var ruleProperty) && ruleProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Rule.AddRange(jObject["rule"].ToObject>()); + foreach(var element in ruleProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Rule.Add(element.GetGuid()); + } } - if (!jObject["scale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("scale"u8, out var scaleProperty) && scaleProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Scale.AddRange(jObject["scale"].ToObject>()); + foreach(var element in scaleProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Scale.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - siteReferenceDataLibrary.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + } + else + { + siteReferenceDataLibrary.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - siteReferenceDataLibrary.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the siteReferenceDataLibrary {id} is null", siteReferenceDataLibrary.Iid); + } + else + { + siteReferenceDataLibrary.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty) && unitProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.Unit.AddRange(jObject["unit"].ToObject>()); + foreach(var element in unitProperty.EnumerateArray()) + { + siteReferenceDataLibrary.Unit.Add(element.GetGuid()); + } } - if (!jObject["unitPrefix"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unitPrefix"u8, out var unitPrefixProperty) && unitPrefixProperty.ValueKind != JsonValueKind.Null) { - siteReferenceDataLibrary.UnitPrefix.AddRange(jObject["unitPrefix"].ToObject>()); + foreach(var element in unitPrefixProperty.EnumerateArray()) + { + siteReferenceDataLibrary.UnitPrefix.Add(element.GetGuid()); + } } return siteReferenceDataLibrary; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs index 3c324f8a8..19a9367db 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SolutionResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,142 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SolutionResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Solution FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Solution FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var solution = new CDP4Common.DTO.Solution(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SolutionResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - solution.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["author"].IsNullOrEmpty()) + var solution = new CDP4Common.DTO.Solution(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("author"u8, out var authorProperty)) { - solution.Author = jObject["author"].ToObject(); + if(authorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale author property of the solution {id} is null", solution.Iid); + } + else + { + solution.Author = authorProperty.GetGuid(); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - solution.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the solution {id} is null", solution.Iid); + } + else + { + solution.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - solution.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the solution {id} is null", solution.Iid); + } + else + { + solution.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - solution.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + solution.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - solution.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + solution.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - solution.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the solution {id} is null", solution.Iid); + } + else + { + solution.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - solution.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the solution {id} is null", solution.Iid); + } + else + { + solution.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - solution.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the solution {id} is null", solution.Iid); + } + else + { + solution.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - solution.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the solution {id} is null", solution.Iid); + } + else + { + solution.ThingPreference = thingPreferenceProperty.GetString(); + } } return solution; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs index ba26de924..30ddf36aa 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/SpecializedQuantityKindResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,116 +28,206 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class SpecializedQuantityKindResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.SpecializedQuantityKind FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.SpecializedQuantityKind FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var specializedQuantityKind = new CDP4Common.DTO.SpecializedQuantityKind(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the SpecializedQuantityKindResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - specializedQuantityKind.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var specializedQuantityKind = new CDP4Common.DTO.SpecializedQuantityKind(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + specializedQuantityKind.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + specializedQuantityKind.Category.Add(element.GetGuid()); + } } - if (!jObject["defaultScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("defaultScale"u8, out var defaultScaleProperty)) { - specializedQuantityKind.DefaultScale = jObject["defaultScale"].ToObject(); + if(defaultScaleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale defaultScale property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.DefaultScale = defaultScaleProperty.GetGuid(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + specializedQuantityKind.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + specializedQuantityKind.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + specializedQuantityKind.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["general"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("general"u8, out var generalProperty)) { - specializedQuantityKind.General = jObject["general"].ToObject(); + if(generalProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale general property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.General = generalProperty.GetGuid(); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + specializedQuantityKind.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - specializedQuantityKind.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - specializedQuantityKind.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - specializedQuantityKind.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.Name = nameProperty.GetString(); + } } - if (!jObject["possibleScale"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("possibleScale"u8, out var possibleScaleProperty) && possibleScaleProperty.ValueKind != JsonValueKind.Null) { - specializedQuantityKind.PossibleScale.AddRange(jObject["possibleScale"].ToObject>()); + foreach(var element in possibleScaleProperty.EnumerateArray()) + { + specializedQuantityKind.PossibleScale.Add(element.GetGuid()); + } } - if (!jObject["quantityDimensionSymbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("quantityDimensionSymbol"u8, out var quantityDimensionSymbolProperty)) { - specializedQuantityKind.QuantityDimensionSymbol = jObject["quantityDimensionSymbol"].ToObject(); + if(quantityDimensionSymbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale quantityDimensionSymbol property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.QuantityDimensionSymbol = quantityDimensionSymbolProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - specializedQuantityKind.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - specializedQuantityKind.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - specializedQuantityKind.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the specializedQuantityKind {id} is null", specializedQuantityKind.Iid); + } + else + { + specializedQuantityKind.ThingPreference = thingPreferenceProperty.GetString(); + } } return specializedQuantityKind; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs index 30eb2536f..b18dbb25c 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,111 +28,178 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class StakeHolderValueMapResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.StakeHolderValueMap FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.StakeHolderValueMap FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var stakeHolderValueMap = new CDP4Common.DTO.StakeHolderValueMap(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the StakeHolderValueMapResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - stakeHolderValueMap.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var stakeHolderValueMap = new CDP4Common.DTO.StakeHolderValueMap(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + stakeHolderValueMap.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + stakeHolderValueMap.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + stakeHolderValueMap.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + stakeHolderValueMap.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + stakeHolderValueMap.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["goal"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("goal"u8, out var goalProperty) && goalProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Goal.AddRange(jObject["goal"].ToObject>()); + foreach(var element in goalProperty.EnumerateArray()) + { + stakeHolderValueMap.Goal.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + stakeHolderValueMap.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - stakeHolderValueMap.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); + } + else + { + stakeHolderValueMap.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - stakeHolderValueMap.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); + } + else + { + stakeHolderValueMap.Name = nameProperty.GetString(); + } } - if (!jObject["requirement"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("requirement"u8, out var requirementProperty) && requirementProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Requirement.AddRange(jObject["requirement"].ToObject>()); + foreach(var element in requirementProperty.EnumerateArray()) + { + stakeHolderValueMap.Requirement.Add(element.GetGuid()); + } } - if (!jObject["settings"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("settings"u8, out var settingsProperty) && settingsProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.Settings.AddRange(jObject["settings"].ToObject>()); + foreach(var element in settingsProperty.EnumerateArray()) + { + stakeHolderValueMap.Settings.Add(element.GetGuid()); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - stakeHolderValueMap.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); + } + else + { + stakeHolderValueMap.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["stakeholderValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholderValue"u8, out var stakeholderValueProperty) && stakeholderValueProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.StakeholderValue.AddRange(jObject["stakeholderValue"].ToObject>()); + foreach(var element in stakeholderValueProperty.EnumerateArray()) + { + stakeHolderValueMap.StakeholderValue.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - stakeHolderValueMap.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the stakeHolderValueMap {id} is null", stakeHolderValueMap.Iid); + } + else + { + stakeHolderValueMap.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueGroup"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueGroup"u8, out var valueGroupProperty) && valueGroupProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMap.ValueGroup.AddRange(jObject["valueGroup"].ToObject>()); + foreach(var element in valueGroupProperty.EnumerateArray()) + { + stakeHolderValueMap.ValueGroup.Add(element.GetGuid()); + } } return stakeHolderValueMap; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs index 3df77b640..642ca5a28 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeHolderValueMapSettingsResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,71 +28,118 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class StakeHolderValueMapSettingsResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.StakeHolderValueMapSettings FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.StakeHolderValueMapSettings FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var stakeHolderValueMapSettings = new CDP4Common.DTO.StakeHolderValueMapSettings(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the StakeHolderValueMapSettingsResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - stakeHolderValueMapSettings.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var stakeHolderValueMapSettings = new CDP4Common.DTO.StakeHolderValueMapSettings(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMapSettings.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + stakeHolderValueMapSettings.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - stakeHolderValueMapSettings.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + stakeHolderValueMapSettings.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["goalToValueGroupRelationship"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("goalToValueGroupRelationship"u8, out var goalToValueGroupRelationshipProperty)) { - stakeHolderValueMapSettings.GoalToValueGroupRelationship = jObject["goalToValueGroupRelationship"].ToObject(); + if(goalToValueGroupRelationshipProperty.ValueKind == JsonValueKind.Null) + { + stakeHolderValueMapSettings.GoalToValueGroupRelationship = null; + } + else + { + stakeHolderValueMapSettings.GoalToValueGroupRelationship = goalToValueGroupRelationshipProperty.GetGuid(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - stakeHolderValueMapSettings.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the stakeHolderValueMapSettings {id} is null", stakeHolderValueMapSettings.Iid); + } + else + { + stakeHolderValueMapSettings.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["stakeholderValueToRequirementRelationship"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholderValueToRequirementRelationship"u8, out var stakeholderValueToRequirementRelationshipProperty)) { - stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship = jObject["stakeholderValueToRequirementRelationship"].ToObject(); + if(stakeholderValueToRequirementRelationshipProperty.ValueKind == JsonValueKind.Null) + { + stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship = null; + } + else + { + stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship = stakeholderValueToRequirementRelationshipProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - stakeHolderValueMapSettings.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the stakeHolderValueMapSettings {id} is null", stakeHolderValueMapSettings.Iid); + } + else + { + stakeHolderValueMapSettings.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["valueGroupToStakeholderValueRelationship"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("valueGroupToStakeholderValueRelationship"u8, out var valueGroupToStakeholderValueRelationshipProperty)) { - stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship = jObject["valueGroupToStakeholderValueRelationship"].ToObject(); + if(valueGroupToStakeholderValueRelationshipProperty.ValueKind == JsonValueKind.Null) + { + stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship = null; + } + else + { + stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship = valueGroupToStakeholderValueRelationshipProperty.GetGuid(); + } } return stakeHolderValueMapSettings; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs index d7e472e93..c5874af63 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,146 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class StakeholderResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Stakeholder FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Stakeholder FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var stakeholder = new CDP4Common.DTO.Stakeholder(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the StakeholderResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - stakeholder.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var stakeholder = new CDP4Common.DTO.Stakeholder(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - stakeholder.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + stakeholder.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - stakeholder.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + stakeholder.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - stakeholder.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + stakeholder.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - stakeholder.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + stakeholder.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - stakeholder.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + stakeholder.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - stakeholder.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + stakeholder.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - stakeholder.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the stakeholder {id} is null", stakeholder.Iid); + } + else + { + stakeholder.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - stakeholder.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the stakeholder {id} is null", stakeholder.Iid); + } + else + { + stakeholder.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - stakeholder.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the stakeholder {id} is null", stakeholder.Iid); + } + else + { + stakeholder.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["stakeholderValue"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("stakeholderValue"u8, out var stakeholderValueProperty) && stakeholderValueProperty.ValueKind != JsonValueKind.Null) { - stakeholder.StakeholderValue.AddRange(jObject["stakeholderValue"].ToObject>()); + foreach(var element in stakeholderValueProperty.EnumerateArray()) + { + stakeholder.StakeholderValue.Add(element.GetGuid()); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - stakeholder.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the stakeholder {id} is null", stakeholder.Iid); + } + else + { + stakeholder.ThingPreference = thingPreferenceProperty.GetString(); + } } return stakeholder; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs index 243b084ba..8f9e1ec73 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/StakeholderValueResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,138 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class StakeholderValueResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.StakeholderValue FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.StakeholderValue FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var stakeholderValue = new CDP4Common.DTO.StakeholderValue(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the StakeholderValueResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - stakeholderValue.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var stakeholderValue = new CDP4Common.DTO.StakeholderValue(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + stakeholderValue.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + stakeholderValue.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + stakeholderValue.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + stakeholderValue.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + stakeholderValue.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - stakeholderValue.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + stakeholderValue.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - stakeholderValue.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the stakeholderValue {id} is null", stakeholderValue.Iid); + } + else + { + stakeholderValue.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - stakeholderValue.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the stakeholderValue {id} is null", stakeholderValue.Iid); + } + else + { + stakeholderValue.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - stakeholderValue.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the stakeholderValue {id} is null", stakeholderValue.Iid); + } + else + { + stakeholderValue.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - stakeholderValue.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the stakeholderValue {id} is null", stakeholderValue.Iid); + } + else + { + stakeholderValue.ThingPreference = thingPreferenceProperty.GetString(); + } } return stakeholderValue; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs index 814d54d53..2b0e4aa74 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TelephoneNumberResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,102 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class TelephoneNumberResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.TelephoneNumber FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.TelephoneNumber FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var telephoneNumber = new CDP4Common.DTO.TelephoneNumber(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the TelephoneNumberResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - telephoneNumber.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var telephoneNumber = new CDP4Common.DTO.TelephoneNumber(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - telephoneNumber.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + telephoneNumber.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - telephoneNumber.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + telephoneNumber.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - telephoneNumber.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the telephoneNumber {id} is null", telephoneNumber.Iid); + } + else + { + telephoneNumber.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - telephoneNumber.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the telephoneNumber {id} is null", telephoneNumber.Iid); + } + else + { + telephoneNumber.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - telephoneNumber.Value = jObject["value"].ToObject(); + if(valueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale value property of the telephoneNumber {id} is null", telephoneNumber.Iid); + } + else + { + telephoneNumber.Value = valueProperty.GetString(); + } } - if (!jObject["vcardType"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("vcardType"u8, out var vcardTypeProperty) && vcardTypeProperty.ValueKind != JsonValueKind.Null) { - telephoneNumber.VcardType.AddRange(jObject["vcardType"].ToObject>()); + foreach(var element in vcardTypeProperty.EnumerateArray()) + { + telephoneNumber.VcardType.Add(VcardTelephoneNumberKindDeserializer.Deserialize(element)); + } } return telephoneNumber; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs index 529bbcb2a..57b74e4e9 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TermResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,142 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class TermResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.Term FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.Term FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var term = new CDP4Common.DTO.Term(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the TermResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - term.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var term = new CDP4Common.DTO.Term(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - term.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + term.Alias.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - term.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + term.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - term.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + term.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - term.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + term.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - term.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + term.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - term.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the term {id} is null", term.Iid); + } + else + { + term.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - term.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the term {id} is null", term.Iid); + } + else + { + term.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - term.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the term {id} is null", term.Iid); + } + else + { + term.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - term.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the term {id} is null", term.Iid); + } + else + { + term.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - term.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the term {id} is null", term.Iid); + } + else + { + term.ThingPreference = thingPreferenceProperty.GetString(); + } } return term; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs index d81e72ab5..399c53b81 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,162 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class TextParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.TextParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.TextParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var textParameterType = new CDP4Common.DTO.TextParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the TextParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - textParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var textParameterType = new CDP4Common.DTO.TextParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - textParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + textParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - textParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + textParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - textParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + textParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - textParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + textParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - textParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + textParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - textParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + textParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - textParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - textParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - textParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - textParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - textParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - textParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the textParameterType {id} is null", textParameterType.Iid); + } + else + { + textParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return textParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs index 9680281f8..af6462a4f 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TextualNoteResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,162 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class TextualNoteResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.TextualNote FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.TextualNote FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var textualNote = new CDP4Common.DTO.TextualNote(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the TextualNoteResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - textualNote.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["category"].IsNullOrEmpty()) + var textualNote = new CDP4Common.DTO.TextualNote(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - textualNote.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + textualNote.Category.Add(element.GetGuid()); + } } - if (!jObject["content"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("content"u8, out var contentProperty)) { - textualNote.Content = jObject["content"].ToObject(); + if(contentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale content property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.Content = contentProperty.GetString(); + } } - if (!jObject["createdOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("createdOn"u8, out var createdOnProperty)) { - textualNote.CreatedOn = jObject["createdOn"].ToObject(); + if(createdOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale createdOn property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.CreatedOn = createdOnProperty.GetDateTime(); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - textualNote.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + textualNote.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - textualNote.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + textualNote.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["languageCode"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("languageCode"u8, out var languageCodeProperty)) { - textualNote.LanguageCode = jObject["languageCode"].ToObject(); + if(languageCodeProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale languageCode property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.LanguageCode = languageCodeProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - textualNote.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - textualNote.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.Name = nameProperty.GetString(); + } } - if (!jObject["owner"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("owner"u8, out var ownerProperty)) { - textualNote.Owner = jObject["owner"].ToObject(); + if(ownerProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale owner property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.Owner = ownerProperty.GetGuid(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - textualNote.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - textualNote.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the textualNote {id} is null", textualNote.Iid); + } + else + { + textualNote.ThingPreference = thingPreferenceProperty.GetString(); + } } return textualNote; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs index a9d1a9464..de4d14105 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/TimeOfDayParameterTypeResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,96 +28,162 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class TimeOfDayParameterTypeResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.TimeOfDayParameterType FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.TimeOfDayParameterType FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var timeOfDayParameterType = new CDP4Common.DTO.TimeOfDayParameterType(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the TimeOfDayParameterTypeResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - timeOfDayParameterType.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var timeOfDayParameterType = new CDP4Common.DTO.TimeOfDayParameterType(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + timeOfDayParameterType.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + timeOfDayParameterType.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + timeOfDayParameterType.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + timeOfDayParameterType.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + timeOfDayParameterType.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - timeOfDayParameterType.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + timeOfDayParameterType.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - timeOfDayParameterType.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - timeOfDayParameterType.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - timeOfDayParameterType.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - timeOfDayParameterType.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["symbol"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("symbol"u8, out var symbolProperty)) { - timeOfDayParameterType.Symbol = jObject["symbol"].ToObject(); + if(symbolProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale symbol property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.Symbol = symbolProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - timeOfDayParameterType.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the timeOfDayParameterType {id} is null", timeOfDayParameterType.Iid); + } + else + { + timeOfDayParameterType.ThingPreference = thingPreferenceProperty.GetString(); + } } return timeOfDayParameterType; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs index 2b9b8af79..9d57e4e8a 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitFactorResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,106 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class UnitFactorResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.UnitFactor FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.UnitFactor FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var unitFactor = new CDP4Common.DTO.UnitFactor(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the UnitFactorResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - unitFactor.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var unitFactor = new CDP4Common.DTO.UnitFactor(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - unitFactor.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + unitFactor.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - unitFactor.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + unitFactor.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["exponent"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("exponent"u8, out var exponentProperty)) { - unitFactor.Exponent = jObject["exponent"].ToObject(); + if(exponentProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale exponent property of the unitFactor {id} is null", unitFactor.Iid); + } + else + { + unitFactor.Exponent = exponentProperty.GetString(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - unitFactor.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the unitFactor {id} is null", unitFactor.Iid); + } + else + { + unitFactor.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - unitFactor.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the unitFactor {id} is null", unitFactor.Iid); + } + else + { + unitFactor.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["unit"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("unit"u8, out var unitProperty)) { - unitFactor.Unit = jObject["unit"].ToObject(); + if(unitProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale unit property of the unitFactor {id} is null", unitFactor.Iid); + } + else + { + unitFactor.Unit = unitProperty.GetGuid(); + } } return unitFactor; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs index 149a3f653..f936da37d 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UnitPrefixResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,91 +28,154 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class UnitPrefixResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.UnitPrefix FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.UnitPrefix FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var unitPrefix = new CDP4Common.DTO.UnitPrefix(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the UnitPrefixResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - unitPrefix.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var unitPrefix = new CDP4Common.DTO.UnitPrefix(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - unitPrefix.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + unitPrefix.Alias.Add(element.GetGuid()); + } } - if (!jObject["conversionFactor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("conversionFactor"u8, out var conversionFactorProperty)) { - unitPrefix.ConversionFactor = jObject["conversionFactor"].ToObject(); + if(conversionFactorProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale conversionFactor property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.ConversionFactor = conversionFactorProperty.GetString(); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - unitPrefix.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + unitPrefix.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - unitPrefix.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + unitPrefix.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - unitPrefix.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + unitPrefix.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - unitPrefix.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + unitPrefix.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["isDeprecated"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isDeprecated"u8, out var isDeprecatedProperty)) { - unitPrefix.IsDeprecated = jObject["isDeprecated"].ToObject(); + if(isDeprecatedProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isDeprecated property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.IsDeprecated = isDeprecatedProperty.GetBoolean(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - unitPrefix.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - unitPrefix.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - unitPrefix.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - unitPrefix.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the unitPrefix {id} is null", unitPrefix.Iid); + } + else + { + unitPrefix.ThingPreference = thingPreferenceProperty.GetString(); + } } return unitPrefix; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs index 04e26203e..44fe0a53e 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserPreferenceResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,66 +28,106 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class UserPreferenceResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.UserPreference FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.UserPreference FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var userPreference = new CDP4Common.DTO.UserPreference(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the UserPreferenceResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - userPreference.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + var userPreference = new CDP4Common.DTO.UserPreference(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - userPreference.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + userPreference.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - userPreference.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + userPreference.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - userPreference.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the userPreference {id} is null", userPreference.Iid); + } + else + { + userPreference.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - userPreference.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the userPreference {id} is null", userPreference.Iid); + } + else + { + userPreference.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - userPreference.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the userPreference {id} is null", userPreference.Iid); + } + else + { + userPreference.ThingPreference = thingPreferenceProperty.GetString(); + } } - if (!jObject["value"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) { - userPreference.Value = jObject["value"].ToObject(); + if(valueProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale value property of the userPreference {id} is null", userPreference.Iid); + } + else + { + userPreference.Value = valueProperty.GetString(); + } } return userPreference; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs index b7f77c8b2..71ed3e2fd 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/UserRuleVerificationResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,81 +28,130 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class UserRuleVerificationResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.UserRuleVerification FromJsonObject(JObject jObject) - { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var userRuleVerification = new CDP4Common.DTO.UserRuleVerification(iid, revisionNumber); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - if (!jObject["actor"].IsNullOrEmpty()) + /// + /// Instantiate and deserialize the properties of a + /// + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.UserRuleVerification FromJsonObject(JsonElement jsonElement) + { + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) { - userRuleVerification.Actor = jObject["actor"].ToObject(); + throw new DeSerializationException("the mandatory iid property is not available, the UserRuleVerificationResolver cannot be used to deserialize this JsonElement"); } + + var revisionNumberValue = 0; - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - userRuleVerification.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + var userRuleVerification = new CDP4Common.DTO.UserRuleVerification(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - userRuleVerification.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + userRuleVerification.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["executedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - userRuleVerification.ExecutedOn = jObject["executedOn"].ToObject(); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + userRuleVerification.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["isActive"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("executedOn"u8, out var executedOnProperty)) { - userRuleVerification.IsActive = jObject["isActive"].ToObject(); + if(executedOnProperty.ValueKind == JsonValueKind.Null) + { + userRuleVerification.ExecutedOn = null; + } + else + { + userRuleVerification.ExecutedOn = executedOnProperty.GetDateTime(); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("isActive"u8, out var isActiveProperty)) { - userRuleVerification.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(isActiveProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale isActive property of the userRuleVerification {id} is null", userRuleVerification.Iid); + } + else + { + userRuleVerification.IsActive = isActiveProperty.GetBoolean(); + } } - if (!jObject["rule"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - userRuleVerification.Rule = jObject["rule"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the userRuleVerification {id} is null", userRuleVerification.Iid); + } + else + { + userRuleVerification.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["status"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("rule"u8, out var ruleProperty)) { - userRuleVerification.Status = jObject["status"].ToObject(); + if(ruleProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale rule property of the userRuleVerification {id} is null", userRuleVerification.Iid); + } + else + { + userRuleVerification.Rule = ruleProperty.GetGuid(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("status"u8, out var statusProperty)) { - userRuleVerification.ThingPreference = jObject["thingPreference"].ToObject(); + if(statusProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale status property of the userRuleVerification {id} is null", userRuleVerification.Iid); + } + else + { + userRuleVerification.Status = RuleVerificationStatusKindDeserializer.Deserialize(statusProperty); + } } - if (!jObject["violation"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - userRuleVerification.Violation.AddRange(jObject["violation"].ToObject>()); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the userRuleVerification {id} is null", userRuleVerification.Iid); + } + else + { + userRuleVerification.ThingPreference = thingPreferenceProperty.GetString(); + } } return userRuleVerification; diff --git a/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs b/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs index d979b91e6..903e15289 100644 --- a/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs +++ b/CDP4JsonSerializer/AutoGenDtoDeserializer/ValueGroupResolver.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -29,86 +28,138 @@ namespace CDP4JsonSerializer { - using System; using System.Collections.Generic; + using System.Text.Json; - using CDP4Common.CommonData; - using CDP4Common.DiagramData; - using CDP4Common.EngineeringModelData; - using CDP4Common.ReportingData; - using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; /// - /// The purpose of the is to deserialize a JSON object to a + /// The purpose of the is to deserialize a JSON object to a /// public static class ValueGroupResolver { /// - /// Instantiate and deserialize the properties of a + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Instantiate and deserialize the properties of a /// - /// The containing the data - /// The to instantiate - public static CDP4Common.DTO.ValueGroup FromJsonObject(JObject jObject) + /// The containing the data + /// The to instantiate + public static CDP4Common.DTO.ValueGroup FromJsonObject(JsonElement jsonElement) { - var iid = jObject["iid"].ToObject(); - var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject(); - var valueGroup = new CDP4Common.DTO.ValueGroup(iid, revisionNumber); + if (!jsonElement.TryGetProperty("iid"u8, out var iid)) + { + throw new DeSerializationException("the mandatory iid property is not available, the ValueGroupResolver cannot be used to deserialize this JsonElement"); + } + + var revisionNumberValue = 0; - if (!jObject["actor"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("revisionNumber"u8, out var revisionNumber)) { - valueGroup.Actor = jObject["actor"].ToObject(); + revisionNumberValue = revisionNumber.GetInt32(); } - if (!jObject["alias"].IsNullOrEmpty()) + var valueGroup = new CDP4Common.DTO.ValueGroup(iid.GetGuid(), revisionNumberValue); + + if (jsonElement.TryGetProperty("alias"u8, out var aliasProperty) && aliasProperty.ValueKind != JsonValueKind.Null) { - valueGroup.Alias.AddRange(jObject["alias"].ToObject>()); + foreach(var element in aliasProperty.EnumerateArray()) + { + valueGroup.Alias.Add(element.GetGuid()); + } } - if (!jObject["category"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("category"u8, out var categoryProperty) && categoryProperty.ValueKind != JsonValueKind.Null) { - valueGroup.Category.AddRange(jObject["category"].ToObject>()); + foreach(var element in categoryProperty.EnumerateArray()) + { + valueGroup.Category.Add(element.GetGuid()); + } } - if (!jObject["definition"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("definition"u8, out var definitionProperty) && definitionProperty.ValueKind != JsonValueKind.Null) { - valueGroup.Definition.AddRange(jObject["definition"].ToObject>()); + foreach(var element in definitionProperty.EnumerateArray()) + { + valueGroup.Definition.Add(element.GetGuid()); + } } - if (!jObject["excludedDomain"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedDomain"u8, out var excludedDomainProperty) && excludedDomainProperty.ValueKind != JsonValueKind.Null) { - valueGroup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject>()); + foreach(var element in excludedDomainProperty.EnumerateArray()) + { + valueGroup.ExcludedDomain.Add(element.GetGuid()); + } } - if (!jObject["excludedPerson"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("excludedPerson"u8, out var excludedPersonProperty) && excludedPersonProperty.ValueKind != JsonValueKind.Null) { - valueGroup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject>()); + foreach(var element in excludedPersonProperty.EnumerateArray()) + { + valueGroup.ExcludedPerson.Add(element.GetGuid()); + } } - if (!jObject["hyperLink"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("hyperLink"u8, out var hyperLinkProperty) && hyperLinkProperty.ValueKind != JsonValueKind.Null) { - valueGroup.HyperLink.AddRange(jObject["hyperLink"].ToObject>()); + foreach(var element in hyperLinkProperty.EnumerateArray()) + { + valueGroup.HyperLink.Add(element.GetGuid()); + } } - if (!jObject["modifiedOn"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("modifiedOn"u8, out var modifiedOnProperty)) { - valueGroup.ModifiedOn = jObject["modifiedOn"].ToObject(); + if(modifiedOnProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale modifiedOn property of the valueGroup {id} is null", valueGroup.Iid); + } + else + { + valueGroup.ModifiedOn = modifiedOnProperty.GetDateTime(); + } } - if (!jObject["name"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("name"u8, out var nameProperty)) { - valueGroup.Name = jObject["name"].ToObject(); + if(nameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale name property of the valueGroup {id} is null", valueGroup.Iid); + } + else + { + valueGroup.Name = nameProperty.GetString(); + } } - if (!jObject["shortName"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("shortName"u8, out var shortNameProperty)) { - valueGroup.ShortName = jObject["shortName"].ToObject(); + if(shortNameProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale shortName property of the valueGroup {id} is null", valueGroup.Iid); + } + else + { + valueGroup.ShortName = shortNameProperty.GetString(); + } } - if (!jObject["thingPreference"].IsNullOrEmpty()) + if (jsonElement.TryGetProperty("thingPreference"u8, out var thingPreferenceProperty)) { - valueGroup.ThingPreference = jObject["thingPreference"].ToObject(); + if(thingPreferenceProperty.ValueKind == JsonValueKind.Null) + { + Logger.Trace("The non-nullabale thingPreference property of the valueGroup {id} is null", valueGroup.Iid); + } + else + { + valueGroup.ThingPreference = thingPreferenceProperty.GetString(); + } } return valueGroup; diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs index b47d536d7..adf25b96a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActionItemSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ActionItem = CDP4Common.DTO.ActionItem; /// /// The purpose of the class is to provide a specific serializer @@ -45,104 +50,998 @@ namespace CDP4JsonSerializer public class ActionItemSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actionee", actionee => new JValue(actionee) }, - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "closeOutDate", closeOutDate => new JValue(closeOutDate != null ? ((DateTime)closeOutDate).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") : null) }, - { "closeOutStatement", closeOutStatement => new JValue(closeOutStatement) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "dueDate", dueDate => new JValue(((DateTime)dueDate).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ActionItem actionItem) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("actionee", this.PropertySerializerMap["actionee"](actionItem.Actionee)); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](actionItem.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](actionItem.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](actionItem.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), actionItem.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), actionItem.ClassKind))); - jsonObject.Add("closeOutDate", this.PropertySerializerMap["closeOutDate"](actionItem.CloseOutDate)); - jsonObject.Add("closeOutStatement", this.PropertySerializerMap["closeOutStatement"](actionItem.CloseOutStatement)); - jsonObject.Add("content", this.PropertySerializerMap["content"](actionItem.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](actionItem.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](actionItem.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("dueDate", this.PropertySerializerMap["dueDate"](actionItem.DueDate)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](actionItem.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](actionItem.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](actionItem.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](actionItem.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](actionItem.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](actionItem.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](actionItem.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](actionItem.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](actionItem.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](actionItem.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](actionItem.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), actionItem.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](actionItem.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](actionItem.Title)); - return jsonObject; + if (thing is not ActionItem actionItem) + { + throw new ArgumentException("The thing shall be a ActionItem", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ActionItem."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ActionItem since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ActionItem for Version 1.1.0"); + writer.WritePropertyName("actionee"u8); + writer.WriteStringValue(actionItem.Actionee); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(actionItem.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(actionItem.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actionItem.ClassKind.ToString()); + writer.WritePropertyName("closeOutDate"u8); + + if (actionItem.CloseOutDate.HasValue) + { + writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("closeOutStatement"u8); + writer.WriteStringValue(actionItem.CloseOutStatement); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(actionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("dueDate"u8); + writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(actionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actionItem.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (actionItem.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actionItem.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(actionItem.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(actionItem.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(actionItem.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ActionItem for Version 1.2.0"); + writer.WritePropertyName("actionee"u8); + writer.WriteStringValue(actionItem.Actionee); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(actionItem.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(actionItem.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actionItem.ClassKind.ToString()); + writer.WritePropertyName("closeOutDate"u8); + + if (actionItem.CloseOutDate.HasValue) + { + writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("closeOutStatement"u8); + writer.WriteStringValue(actionItem.CloseOutStatement); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(actionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("dueDate"u8); + writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(actionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actionItem.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (actionItem.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actionItem.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(actionItem.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(actionItem.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actionItem.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(actionItem.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ActionItem for Version 1.3.0"); + writer.WritePropertyName("actionee"u8); + writer.WriteStringValue(actionItem.Actionee); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(actionItem.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(actionItem.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actionItem.ClassKind.ToString()); + writer.WritePropertyName("closeOutDate"u8); + + if (actionItem.CloseOutDate.HasValue) + { + writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("closeOutStatement"u8); + writer.WriteStringValue(actionItem.CloseOutStatement); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(actionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("dueDate"u8); + writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(actionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actionItem.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (actionItem.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actionItem.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(actionItem.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(actionItem.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actionItem.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(actionItem.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ActionItem actionItem) + { + throw new ArgumentException("The thing shall be a ActionItem", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("actionee"u8); + writer.WriteStringValue(actionItem.Actionee); + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in actionItem.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(actionItem.Author); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in actionItem.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(actionItem.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actionItem.ClassKind.ToString()); + writer.WritePropertyName("closeOutDate"u8); + + if (actionItem.CloseOutDate.HasValue) + { + writer.WriteStringValue(actionItem.CloseOutDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("closeOutStatement"u8); + writer.WriteStringValue(actionItem.CloseOutStatement); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(actionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(actionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in actionItem.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("dueDate"u8); + writer.WriteStringValue(actionItem.DueDate.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(actionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actionItem.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (actionItem.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(actionItem.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in actionItem.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actionItem.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(actionItem.ShortName); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in actionItem.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(actionItem.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actionItem.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(actionItem.Title); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var actionItem = thing as ActionItem; - if (actionItem == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ActionItem."); - } + case "actionee": + writer.WritePropertyName("actionee"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "approvedby": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) + { + writer.WriteStartArray("approvedBy"u8); - return this.Serialize(actionItem); + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + writer.WriteEndArray(); + } + break; + case "author": + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classification": + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "closeoutdate": + writer.WritePropertyName("closeOutDate"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "closeoutstatement": + writer.WritePropertyName("closeOutStatement"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) + { + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + writer.WriteEndArray(); + } + break; + case "duedate": + writer.WritePropertyName("dueDate"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) + { + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) + { + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + writer.WriteEndArray(); + } + break; + case "status": + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ActionItem"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actionee", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "closeOutDate", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "closeOutStatement", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "dueDate", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs index 6df1d9164..be6b270da 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateListSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ActualFiniteStateList = CDP4Common.DTO.ActualFiniteStateList; /// /// The purpose of the class is to provide a specific serializer @@ -45,74 +50,568 @@ namespace CDP4JsonSerializer public class ActualFiniteStateListSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "actualState", actualState => new JArray(actualState) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "excludeOption", excludeOption => new JArray(excludeOption) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "possibleFiniteStateList", possibleFiniteStateList => new JArray(((IEnumerable)possibleFiniteStateList).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(ActualFiniteStateList actualFiniteStateList) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("actualState", this.PropertySerializerMap["actualState"](actualFiniteStateList.ActualState.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), actualFiniteStateList.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludeOption", this.PropertySerializerMap["excludeOption"](actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](actualFiniteStateList.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](actualFiniteStateList.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](actualFiniteStateList.Owner)); - jsonObject.Add("possibleFiniteStateList", this.PropertySerializerMap["possibleFiniteStateList"](actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](actualFiniteStateList.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](actualFiniteStateList.ThingPreference)); - return jsonObject; + if (thing is not ActualFiniteStateList actualFiniteStateList) + { + throw new ArgumentException("The thing shall be a ActualFiniteStateList", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ActualFiniteStateList."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ActualFiniteStateList since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.0.0"); + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteStateList.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actualFiniteStateList.Owner); + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.1.0"); + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actualFiniteStateList.Owner); + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.2.0"); + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actualFiniteStateList.Owner); + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteStateList.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteStateList for Version 1.3.0"); + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actualFiniteStateList.Owner); + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteStateList.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ActualFiniteStateList actualFiniteStateList) + { + throw new ArgumentException("The thing shall be a ActualFiniteStateList", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in actualFiniteStateList.ActualState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteStateList.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in actualFiniteStateList.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(actualFiniteStateList.Owner); + + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in actualFiniteStateList.PossibleFiniteStateList.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteStateList.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteStateList.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var actualFiniteStateList = thing as ActualFiniteStateList; - if (actualFiniteStateList == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ActualFiniteStateList."); - } + case "actualstate": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListActualState && objectListActualState.Any()) + { + writer.WriteStartArray("actualState"u8); + + foreach(var actualStateItem in objectListActualState.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualStateItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "excludeoption": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludeOption && objectListExcludeOption.Any()) + { + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in objectListExcludeOption.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(actualFiniteStateList); + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblefinitestatelist": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListPossibleFiniteStateList && objectListPossibleFiniteStateList.Any()) + { + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in objectListPossibleFiniteStateList.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleFiniteStateListItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ActualFiniteStateList"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "actualState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludeOption", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleFiniteStateList", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs index 40f2f6eed..456920b39 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ActualFiniteStateSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ActualFiniteState = CDP4Common.DTO.ActualFiniteState; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +50,441 @@ namespace CDP4JsonSerializer public class ActualFiniteStateSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "kind", kind => new JValue(kind.ToString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "possibleState", possibleState => new JArray(possibleState) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ActualFiniteState actualFiniteState) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), actualFiniteState.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](actualFiniteState.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](actualFiniteState.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](actualFiniteState.Iid)); - jsonObject.Add("kind", this.PropertySerializerMap["kind"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.ActualFiniteStateKind), actualFiniteState.Kind))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](actualFiniteState.ModifiedOn)); - jsonObject.Add("possibleState", this.PropertySerializerMap["possibleState"](actualFiniteState.PossibleState.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](actualFiniteState.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](actualFiniteState.ThingPreference)); - return jsonObject; + if (thing is not ActualFiniteState actualFiniteState) + { + throw new ArgumentException("The thing shall be a ActualFiniteState", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ActualFiniteState."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ActualFiniteState since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteState for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteState for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteState for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteState.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ActualFiniteState for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteState.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ActualFiniteState actualFiniteState) + { + throw new ArgumentException("The thing shall be a ActualFiniteState", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(actualFiniteState.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in actualFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in actualFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(actualFiniteState.Iid); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(actualFiniteState.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(actualFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in actualFiniteState.PossibleState.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(actualFiniteState.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(actualFiniteState.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var actualFiniteState = thing as ActualFiniteState; - if (actualFiniteState == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ActualFiniteState."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "kind": + writer.WritePropertyName("kind"u8); + + if(value != null) + { + writer.WriteStringValue(((ActualFiniteStateKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblestate": + if (value == null) + { + break; + } - return this.Serialize(actualFiniteState); + if (value is IEnumerable objectListPossibleState && objectListPossibleState.Any()) + { + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in objectListPossibleState.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleStateItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ActualFiniteState"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "kind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs index 15f35aa61..fcd77ae92 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AliasSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Alias = CDP4Common.DTO.Alias; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +50,425 @@ namespace CDP4JsonSerializer public class AliasSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isSynonym", isSynonym => new JValue(isSynonym) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(Alias alias) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), alias.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](alias.Content)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](alias.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](alias.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](alias.Iid)); - jsonObject.Add("isSynonym", this.PropertySerializerMap["isSynonym"](alias.IsSynonym)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](alias.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](alias.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](alias.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](alias.ThingPreference)); - return jsonObject; + if (thing is not Alias alias) + { + throw new ArgumentException("The thing shall be a Alias", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Alias."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Alias since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Alias for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Alias for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(alias.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Alias for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(alias.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(alias.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Alias for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(alias.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(alias.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Alias alias) + { + throw new ArgumentException("The thing shall be a Alias", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(alias.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(alias.Content); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in alias.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in alias.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(alias.Iid); + writer.WritePropertyName("isSynonym"u8); + writer.WriteBooleanValue(alias.IsSynonym); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(alias.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(alias.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(alias.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(alias.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var alias = thing as Alias; - if (alias == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Alias."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(alias); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "issynonym": + writer.WritePropertyName("isSynonym"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Alias"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isSynonym", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs index 01328a0cb..99a5d4989 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/AndExpressionSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using AndExpression = CDP4Common.DTO.AndExpression; /// /// The purpose of the class is to provide a specific serializer @@ -45,68 +50,417 @@ namespace CDP4JsonSerializer public class AndExpressionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "term", term => new JArray(term) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(AndExpression andExpression) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), andExpression.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](andExpression.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](andExpression.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](andExpression.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](andExpression.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](andExpression.RevisionNumber)); - jsonObject.Add("term", this.PropertySerializerMap["term"](andExpression.Term.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](andExpression.ThingPreference)); - return jsonObject; + if (thing is not AndExpression andExpression) + { + throw new ArgumentException("The thing shall be a AndExpression", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of AndExpression."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of AndExpression since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing AndExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing AndExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing AndExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(andExpression.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing AndExpression for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(andExpression.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not AndExpression andExpression) + { + throw new ArgumentException("The thing shall be a AndExpression", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(andExpression.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in andExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in andExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(andExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(andExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(andExpression.RevisionNumber); + + writer.WriteStartArray("term"u8); + + foreach(var termItem in andExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(andExpression.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var andExpression = thing as AndExpression; - if (andExpression == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a AndExpression."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(andExpression); + break; + case "term": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListTerm && objectListTerm.Any()) + { + writer.WriteStartArray("term"u8); + + foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + writer.WriteEndArray(); + } + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the AndExpression"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "term", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs index 6b46febad..00a6c5a3b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ApprovalSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Approval = CDP4Common.DTO.Approval; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +50,476 @@ namespace CDP4JsonSerializer public class ApprovalSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(Approval approval) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](approval.Author)); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationApprovalKind), approval.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), approval.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](approval.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](approval.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](approval.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](approval.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](approval.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](approval.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](approval.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](approval.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](approval.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](approval.ThingPreference)); - return jsonObject; + if (thing is not Approval approval) + { + throw new ArgumentException("The thing shall be a Approval", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Approval."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Approval since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Approval for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(approval.Author); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(approval.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(approval.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(approval.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(approval.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(approval.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(approval.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(approval.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(approval.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Approval for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(approval.Author); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(approval.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(approval.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(approval.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(approval.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(approval.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(approval.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(approval.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(approval.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(approval.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Approval for Version 1.3.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(approval.Author); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(approval.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(approval.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(approval.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(approval.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(approval.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(approval.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(approval.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(approval.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(approval.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Approval approval) + { + throw new ArgumentException("The thing shall be a Approval", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(approval.Author); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(approval.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(approval.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(approval.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(approval.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in approval.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in approval.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(approval.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(approval.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(approval.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(approval.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(approval.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(approval.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var approval = thing as Approval; - if (approval == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Approval."); - } + case "author": + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classification": + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationApprovalKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(approval); + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Approval"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs index 0826099da..ebfb29ed4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ArrayParameterTypeSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ArrayParameterType = CDP4Common.DTO.ArrayParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,90 +50,880 @@ namespace CDP4JsonSerializer public class ArrayParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "component", component => new JArray(((IEnumerable)component).Cast().Select(x => x.ToJsonObject())) }, - { "definition", definition => new JArray(definition) }, - { "dimension", dimension => new JArray(((IEnumerable)dimension).Cast().Select(x => x.ToJsonObject())) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isFinalized", isFinalized => new JValue(isFinalized) }, - { "isTensor", isTensor => new JValue(isTensor) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ArrayParameterType arrayParameterType) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](arrayParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](arrayParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), arrayParameterType.ClassKind))); - jsonObject.Add("component", this.PropertySerializerMap["component"](arrayParameterType.Component.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](arrayParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("dimension", this.PropertySerializerMap["dimension"](arrayParameterType.Dimension.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](arrayParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](arrayParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](arrayParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](arrayParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](arrayParameterType.IsDeprecated)); - jsonObject.Add("isFinalized", this.PropertySerializerMap["isFinalized"](arrayParameterType.IsFinalized)); - jsonObject.Add("isTensor", this.PropertySerializerMap["isTensor"](arrayParameterType.IsTensor)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](arrayParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](arrayParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](arrayParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](arrayParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](arrayParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](arrayParameterType.ThingPreference)); - return jsonObject; + if (thing is not ArrayParameterType arrayParameterType) + { + throw new ArgumentException("The thing shall be a ArrayParameterType", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ArrayParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ArrayParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(arrayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(arrayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(arrayParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ArrayParameterType for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(arrayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(arrayParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ArrayParameterType arrayParameterType) + { + throw new ArgumentException("The thing shall be a ArrayParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in arrayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in arrayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(arrayParameterType.ClassKind.ToString()); + + writer.WriteStartArray("component"u8); + + foreach(var componentItem in arrayParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in arrayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in arrayParameterType.Dimension.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in arrayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in arrayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in arrayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(arrayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(arrayParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(arrayParameterType.IsFinalized); + writer.WritePropertyName("isTensor"u8); + writer.WriteBooleanValue(arrayParameterType.IsTensor); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(arrayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(arrayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(arrayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(arrayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(arrayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(arrayParameterType.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var arrayParameterType = thing as ArrayParameterType; - if (arrayParameterType == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ArrayParameterType."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "component": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListComponent && objectListComponent.Any()) + { + writer.WriteStartArray("component"u8); + + foreach(var componentItem in objectListComponent.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + writer.WriteEndArray(); + } + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "dimension": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDimension && objectListDimension.Any()) + { + writer.WriteStartArray("dimension"u8); + + foreach(var dimensionItem in objectListDimension.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dimensionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(arrayParameterType); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isfinalized": + writer.WritePropertyName("isFinalized"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "istensor": + writer.WritePropertyName("isTensor"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ArrayParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "component", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "dimension", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isFinalized", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isTensor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs index 2f44fc8f9..53960e843 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryNoteSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using BinaryNote = CDP4Common.DTO.BinaryNote; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +50,531 @@ namespace CDP4JsonSerializer public class BinaryNoteSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "caption", caption => new JValue(caption) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fileType", fileType => new JValue(fileType) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(BinaryNote binaryNote) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("caption", this.PropertySerializerMap["caption"](binaryNote.Caption)); - jsonObject.Add("category", this.PropertySerializerMap["category"](binaryNote.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), binaryNote.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](binaryNote.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](binaryNote.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](binaryNote.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fileType", this.PropertySerializerMap["fileType"](binaryNote.FileType)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](binaryNote.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](binaryNote.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](binaryNote.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](binaryNote.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](binaryNote.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](binaryNote.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](binaryNote.ThingPreference)); - return jsonObject; + if (thing is not BinaryNote binaryNote) + { + throw new ArgumentException("The thing shall be a BinaryNote", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of BinaryNote."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of BinaryNote since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryNote for Version 1.1.0"); + writer.WritePropertyName("caption"u8); + writer.WriteStringValue(binaryNote.Caption); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryNote.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fileType"u8); + writer.WriteStringValue(binaryNote.FileType); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryNote.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryNote.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryNote for Version 1.2.0"); + writer.WritePropertyName("caption"u8); + writer.WriteStringValue(binaryNote.Caption); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryNote.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fileType"u8); + writer.WriteStringValue(binaryNote.FileType); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryNote.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryNote.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryNote for Version 1.3.0"); + writer.WritePropertyName("caption"u8); + writer.WriteStringValue(binaryNote.Caption); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryNote.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fileType"u8); + writer.WriteStringValue(binaryNote.FileType); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryNote.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryNote.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not BinaryNote binaryNote) + { + throw new ArgumentException("The thing shall be a BinaryNote", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("caption"u8); + writer.WriteStringValue(binaryNote.Caption); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryNote.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(binaryNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fileType"u8); + writer.WriteStringValue(binaryNote.FileType); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryNote.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryNote.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var binaryNote = thing as BinaryNote; - if (binaryNote == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a BinaryNote."); - } + case "caption": + writer.WritePropertyName("caption"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); - return this.Serialize(binaryNote); + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "filetype": + writer.WritePropertyName("fileType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the BinaryNote"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "caption", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fileType", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs index c86f94811..ebef7ecd8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipRuleSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using BinaryRelationshipRule = CDP4Common.DTO.BinaryRelationshipRule; /// /// The purpose of the class is to provide a specific serializer @@ -45,88 +50,736 @@ namespace CDP4JsonSerializer public class BinaryRelationshipRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "forwardRelationshipName", forwardRelationshipName => new JValue(forwardRelationshipName) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "inverseRelationshipName", inverseRelationshipName => new JValue(inverseRelationshipName) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "relationshipCategory", relationshipCategory => new JValue(relationshipCategory) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceCategory", sourceCategory => new JValue(sourceCategory) }, - { "targetCategory", targetCategory => new JValue(targetCategory) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(BinaryRelationshipRule binaryRelationshipRule) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](binaryRelationshipRule.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), binaryRelationshipRule.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](binaryRelationshipRule.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("forwardRelationshipName", this.PropertySerializerMap["forwardRelationshipName"](binaryRelationshipRule.ForwardRelationshipName)); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](binaryRelationshipRule.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](binaryRelationshipRule.Iid)); - jsonObject.Add("inverseRelationshipName", this.PropertySerializerMap["inverseRelationshipName"](binaryRelationshipRule.InverseRelationshipName)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](binaryRelationshipRule.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](binaryRelationshipRule.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](binaryRelationshipRule.Name)); - jsonObject.Add("relationshipCategory", this.PropertySerializerMap["relationshipCategory"](binaryRelationshipRule.RelationshipCategory)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](binaryRelationshipRule.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](binaryRelationshipRule.ShortName)); - jsonObject.Add("sourceCategory", this.PropertySerializerMap["sourceCategory"](binaryRelationshipRule.SourceCategory)); - jsonObject.Add("targetCategory", this.PropertySerializerMap["targetCategory"](binaryRelationshipRule.TargetCategory)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](binaryRelationshipRule.ThingPreference)); - return jsonObject; + if (thing is not BinaryRelationshipRule binaryRelationshipRule) + { + throw new ArgumentException("The thing shall be a BinaryRelationshipRule", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of BinaryRelationshipRule."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of BinaryRelationshipRule since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationshipRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationshipRule for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationshipRule.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not BinaryRelationshipRule binaryRelationshipRule) + { + throw new ArgumentException("The thing shall be a BinaryRelationshipRule", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in binaryRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationshipRule.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in binaryRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("forwardRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.ForwardRelationshipName); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in binaryRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationshipRule.Iid); + writer.WritePropertyName("inverseRelationshipName"u8); + writer.WriteStringValue(binaryRelationshipRule.InverseRelationshipName); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(binaryRelationshipRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationshipRule.Name); + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(binaryRelationshipRule.ShortName); + writer.WritePropertyName("sourceCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.SourceCategory); + writer.WritePropertyName("targetCategory"u8); + writer.WriteStringValue(binaryRelationshipRule.TargetCategory); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationshipRule.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var binaryRelationshipRule = thing as BinaryRelationshipRule; - if (binaryRelationshipRule == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a BinaryRelationshipRule."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); - return this.Serialize(binaryRelationshipRule); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "forwardrelationshipname": + writer.WritePropertyName("forwardRelationshipName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "inverserelationshipname": + writer.WritePropertyName("inverseRelationshipName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relationshipcategory": + writer.WritePropertyName("relationshipCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourcecategory": + writer.WritePropertyName("sourceCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "targetcategory": + writer.WritePropertyName("targetCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the BinaryRelationshipRule"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "forwardRelationshipName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "inverseRelationshipName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "relationshipCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "targetCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs index a2de5d468..f438c50cd 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BinaryRelationshipSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using BinaryRelationship = CDP4Common.DTO.BinaryRelationship; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +50,563 @@ namespace CDP4JsonSerializer public class BinaryRelationshipSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterValue", parameterValue => new JArray(parameterValue) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "source", source => new JValue(source) }, - { "target", target => new JValue(target) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(BinaryRelationship binaryRelationship) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](binaryRelationship.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), binaryRelationship.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](binaryRelationship.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](binaryRelationship.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](binaryRelationship.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](binaryRelationship.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](binaryRelationship.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](binaryRelationship.Owner)); - jsonObject.Add("parameterValue", this.PropertySerializerMap["parameterValue"](binaryRelationship.ParameterValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](binaryRelationship.RevisionNumber)); - jsonObject.Add("source", this.PropertySerializerMap["source"](binaryRelationship.Source)); - jsonObject.Add("target", this.PropertySerializerMap["target"](binaryRelationship.Target)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](binaryRelationship.ThingPreference)); - return jsonObject; + if (thing is not BinaryRelationship binaryRelationship) + { + throw new ArgumentException("The thing shall be a BinaryRelationship", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of BinaryRelationship."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of BinaryRelationship since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.0.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationship.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing BinaryRelationship for Version 1.3.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationship.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not BinaryRelationship binaryRelationship) + { + throw new ArgumentException("The thing shall be a BinaryRelationship", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in binaryRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(binaryRelationship.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in binaryRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in binaryRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(binaryRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(binaryRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(binaryRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(binaryRelationship.Owner); + + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in binaryRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(binaryRelationship.RevisionNumber); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(binaryRelationship.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(binaryRelationship.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(binaryRelationship.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var binaryRelationship = thing as BinaryRelationship; - if (binaryRelationship == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a BinaryRelationship."); - } + case "category": + if (value == null) + { + break; + } - return this.Serialize(binaryRelationship); + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametervalue": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListParameterValue && objectListParameterValue.Any()) + { + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "source": + writer.WritePropertyName("source"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "target": + writer.WritePropertyName("target"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the BinaryRelationship"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "source", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "target", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs index f8fa879fb..74f223206 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BookSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Book = CDP4Common.DTO.Book; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +50,541 @@ namespace CDP4JsonSerializer public class BookSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "section", section => new JArray(((IEnumerable)section).Cast().Select(x => x.ToJsonObject())) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(Book book) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](book.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), book.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](book.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](book.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](book.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](book.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](book.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](book.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](book.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](book.RevisionNumber)); - jsonObject.Add("section", this.PropertySerializerMap["section"](book.Section.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](book.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](book.ThingPreference)); - return jsonObject; + if (thing is not Book book) + { + throw new ArgumentException("The thing shall be a Book", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Book."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Book since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Book for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(book.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(book.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(book.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(book.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(book.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(book.RevisionNumber); + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(sectionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(book.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Book for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(book.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(book.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(book.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(book.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(book.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(book.RevisionNumber); + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(sectionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(book.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(book.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Book for Version 1.3.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(book.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(book.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(book.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(book.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(book.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(book.RevisionNumber); + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(sectionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(book.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(book.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Book book) + { + throw new ArgumentException("The thing shall be a Book", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in book.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(book.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(book.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in book.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in book.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(book.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(book.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(book.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(book.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(book.RevisionNumber); + + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in book.Section.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(sectionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(book.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(book.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var book = thing as Book; - if (book == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Book."); - } + case "category": + if (value == null) + { + break; + } - return this.Serialize(book); + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "section": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListSection && objectListSection.Any()) + { + writer.WriteStartArray("section"u8); + + foreach(var sectionItem in objectListSection.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(sectionItem); + } + writer.WriteEndArray(); + } + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Book"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "section", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs index 4deab3491..5c50a5978 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BooleanParameterTypeSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using BooleanParameterType = CDP4Common.DTO.BooleanParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +50,704 @@ namespace CDP4JsonSerializer public class BooleanParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(BooleanParameterType booleanParameterType) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](booleanParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](booleanParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), booleanParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](booleanParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](booleanParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](booleanParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](booleanParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](booleanParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](booleanParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](booleanParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](booleanParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](booleanParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](booleanParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](booleanParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](booleanParameterType.ThingPreference)); - return jsonObject; + if (thing is not BooleanParameterType booleanParameterType) + { + throw new ArgumentException("The thing shall be a BooleanParameterType", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of BooleanParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of BooleanParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(booleanParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(booleanParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(booleanParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing BooleanParameterType for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(booleanParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(booleanParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not BooleanParameterType booleanParameterType) + { + throw new ArgumentException("The thing shall be a BooleanParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in booleanParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in booleanParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(booleanParameterType.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in booleanParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in booleanParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in booleanParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in booleanParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(booleanParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(booleanParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(booleanParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(booleanParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(booleanParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(booleanParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(booleanParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(booleanParameterType.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var booleanParameterType = thing as BooleanParameterType; - if (booleanParameterType == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a BooleanParameterType."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); - return this.Serialize(booleanParameterType); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the BooleanParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs index cdf0514ef..e2693e974 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BoundsSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Bounds = CDP4Common.DTO.Bounds; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +50,454 @@ namespace CDP4JsonSerializer public class BoundsSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "height", height => new JValue(height) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "width", width => new JValue(width) }, - { "x", x => new JValue(x) }, - { "y", y => new JValue(y) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(Bounds bounds) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), bounds.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](bounds.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](bounds.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("height", this.PropertySerializerMap["height"](bounds.Height)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](bounds.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](bounds.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](bounds.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](bounds.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](bounds.ThingPreference)); - jsonObject.Add("width", this.PropertySerializerMap["width"](bounds.Width)); - jsonObject.Add("x", this.PropertySerializerMap["x"](bounds.X)); - jsonObject.Add("y", this.PropertySerializerMap["y"](bounds.Y)); - return jsonObject; + if (thing is not Bounds bounds) + { + throw new ArgumentException("The thing shall be a Bounds", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Bounds."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Bounds since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Bounds for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(bounds.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("height"u8); + writer.WriteNumberValue(bounds.Height); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(bounds.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(bounds.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(bounds.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(bounds.RevisionNumber); + writer.WritePropertyName("width"u8); + writer.WriteNumberValue(bounds.Width); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(bounds.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(bounds.Y); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Bounds for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(bounds.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("height"u8); + writer.WriteNumberValue(bounds.Height); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(bounds.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(bounds.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(bounds.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(bounds.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(bounds.ThingPreference); + writer.WritePropertyName("width"u8); + writer.WriteNumberValue(bounds.Width); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(bounds.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(bounds.Y); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Bounds for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(bounds.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("height"u8); + writer.WriteNumberValue(bounds.Height); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(bounds.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(bounds.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(bounds.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(bounds.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(bounds.ThingPreference); + writer.WritePropertyName("width"u8); + writer.WriteNumberValue(bounds.Width); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(bounds.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(bounds.Y); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Bounds bounds) + { + throw new ArgumentException("The thing shall be a Bounds", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(bounds.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in bounds.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in bounds.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("height"u8); + writer.WriteNumberValue(bounds.Height); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(bounds.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(bounds.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(bounds.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(bounds.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(bounds.ThingPreference); + writer.WritePropertyName("width"u8); + writer.WriteNumberValue(bounds.Width); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(bounds.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(bounds.Y); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var bounds = thing as Bounds; - if (bounds == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Bounds."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); - return this.Serialize(bounds); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "height": + writer.WritePropertyName("height"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "width": + writer.WritePropertyName("width"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "x": + writer.WritePropertyName("x"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "y": + writer.WritePropertyName("y"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Bounds"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "height", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "width", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "x", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "y", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs index 4901aa921..fe05b68a0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/BuiltInRuleVerificationSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using BuiltInRuleVerification = CDP4Common.DTO.BuiltInRuleVerification; /// /// The purpose of the class is to provide a specific serializer @@ -45,75 +50,495 @@ namespace CDP4JsonSerializer public class BuiltInRuleVerificationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "executedOn", executedOn => new JValue(executedOn != null ? ((DateTime)executedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") : null) }, - { "iid", iid => new JValue(iid) }, - { "isActive", isActive => new JValue(isActive) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "violation", violation => new JArray(violation) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(BuiltInRuleVerification builtInRuleVerification) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), builtInRuleVerification.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("executedOn", this.PropertySerializerMap["executedOn"](builtInRuleVerification.ExecutedOn)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](builtInRuleVerification.Iid)); - jsonObject.Add("isActive", this.PropertySerializerMap["isActive"](builtInRuleVerification.IsActive)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](builtInRuleVerification.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](builtInRuleVerification.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](builtInRuleVerification.RevisionNumber)); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.RuleVerificationStatusKind), builtInRuleVerification.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](builtInRuleVerification.ThingPreference)); - return jsonObject; + if (thing is not BuiltInRuleVerification builtInRuleVerification) + { + throw new ArgumentException("The thing shall be a BuiltInRuleVerification", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of BuiltInRuleVerification."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of BuiltInRuleVerification since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing BuiltInRuleVerification for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WritePropertyName("executedOn"u8); + + if (builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing BuiltInRuleVerification for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if (builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(builtInRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing BuiltInRuleVerification for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if (builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(builtInRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(builtInRuleVerification.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing BuiltInRuleVerification for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if (builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(builtInRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(builtInRuleVerification.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not BuiltInRuleVerification builtInRuleVerification) + { + throw new ArgumentException("The thing shall be a BuiltInRuleVerification", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(builtInRuleVerification.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in builtInRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in builtInRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if (builtInRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(builtInRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(builtInRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(builtInRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(builtInRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(builtInRuleVerification.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(builtInRuleVerification.RevisionNumber); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(builtInRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(builtInRuleVerification.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var builtInRuleVerification = thing as BuiltInRuleVerification; - if (builtInRuleVerification == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a BuiltInRuleVerification."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "executedon": + writer.WritePropertyName("executedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isactive": + writer.WritePropertyName("isActive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(builtInRuleVerification); + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "status": + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((RuleVerificationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the BuiltInRuleVerification"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "executedOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isActive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "violation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs index d96c7a383..cc55acb33 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CategorySerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Category = CDP4Common.DTO.Category; /// /// The purpose of the class is to provide a specific serializer @@ -45,84 +50,768 @@ namespace CDP4JsonSerializer public class CategorySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isAbstract", isAbstract => new JValue(isAbstract) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "permissibleClass", permissibleClass => new JArray(permissibleClass) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "superCategory", superCategory => new JArray(superCategory) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(Category category) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](category.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), category.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](category.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](category.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](category.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](category.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](category.Iid)); - jsonObject.Add("isAbstract", this.PropertySerializerMap["isAbstract"](category.IsAbstract)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](category.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](category.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](category.Name)); - jsonObject.Add("permissibleClass", this.PropertySerializerMap["permissibleClass"](category.PermissibleClass.Select(e => Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), e)))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](category.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](category.ShortName)); - jsonObject.Add("superCategory", this.PropertySerializerMap["superCategory"](category.SuperCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](category.ThingPreference)); - return jsonObject; + if (thing is not Category category) + { + throw new ArgumentException("The thing shall be a Category", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Category."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Category since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(category.Iid); + writer.WritePropertyName("isAbstract"u8); + writer.WriteBooleanValue(category.IsAbstract); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(category.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); + + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(category.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(category.Iid); + writer.WritePropertyName("isAbstract"u8); + writer.WriteBooleanValue(category.IsAbstract); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(category.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); + + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(category.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(category.Iid); + writer.WritePropertyName("isAbstract"u8); + writer.WriteBooleanValue(category.IsAbstract); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(category.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); + + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(category.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(category.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Category for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(category.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(category.Iid); + writer.WritePropertyName("isAbstract"u8); + writer.WriteBooleanValue(category.IsAbstract); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(category.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(category.Name); + writer.WriteStartArray("permissibleClass"u8); + + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(category.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(category.ShortName); + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(category.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Category category) + { + throw new ArgumentException("The thing shall be a Category", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in category.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(category.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in category.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in category.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in category.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in category.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(category.Iid); + writer.WritePropertyName("isAbstract"u8); + writer.WriteBooleanValue(category.IsAbstract); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(category.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(category.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(category.Name); + + writer.WriteStartArray("permissibleClass"u8); + + foreach(var permissibleClassItem in category.PermissibleClass) + { + writer.WriteStringValue(permissibleClassItem.ToString()); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(category.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(category.ShortName); + + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in category.SuperCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(category.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var category = thing as Category; - if (category == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Category."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isabstract": + writer.WritePropertyName("isAbstract"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(category); + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "permissibleclass": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListPermissibleClass && objectListPermissibleClass.Any()) + { + writer.WriteStartArray("permissibleClass"u8); + + foreach (var permissibleClassItem in objectListPermissibleClass) + { + writer.WriteStringValue(((ClassKind)permissibleClassItem).ToString()); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "supercategory": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListSuperCategory && objectListSuperCategory.Any()) + { + writer.WriteStartArray("superCategory"u8); + + foreach(var superCategoryItem in objectListSuperCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(superCategoryItem); + } + writer.WriteEndArray(); + } + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Category"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isAbstract", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "permissibleClass", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "superCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs index d0b700b5f..1ce320507 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeProposalSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ChangeProposal = CDP4Common.DTO.ChangeProposal; /// /// The purpose of the class is to provide a specific serializer @@ -45,98 +50,895 @@ namespace CDP4JsonSerializer public class ChangeProposalSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "changeRequest", changeRequest => new JValue(changeRequest) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(ChangeProposal changeProposal) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](changeProposal.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](changeProposal.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](changeProposal.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("changeRequest", this.PropertySerializerMap["changeRequest"](changeProposal.ChangeRequest)); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), changeProposal.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), changeProposal.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](changeProposal.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](changeProposal.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](changeProposal.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](changeProposal.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](changeProposal.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](changeProposal.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](changeProposal.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](changeProposal.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](changeProposal.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](changeProposal.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](changeProposal.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](changeProposal.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](changeProposal.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](changeProposal.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), changeProposal.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](changeProposal.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](changeProposal.Title)); - return jsonObject; + if (thing is not ChangeProposal changeProposal) + { + throw new ArgumentException("The thing shall be a ChangeProposal", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ChangeProposal."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ChangeProposal since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeProposal for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeProposal.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeRequest"u8); + writer.WriteStringValue(changeProposal.ChangeRequest); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeProposal.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeProposal.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeProposal.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeProposal.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeProposal.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeProposal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeProposal.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (changeProposal.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeProposal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeProposal.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeProposal.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeProposal.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeProposal for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeProposal.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeRequest"u8); + writer.WriteStringValue(changeProposal.ChangeRequest); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeProposal.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeProposal.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeProposal.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeProposal.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeProposal.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeProposal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeProposal.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (changeProposal.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeProposal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeProposal.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeProposal.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeProposal.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeProposal.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeProposal for Version 1.3.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeProposal.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeRequest"u8); + writer.WriteStringValue(changeProposal.ChangeRequest); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeProposal.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeProposal.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeProposal.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeProposal.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeProposal.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeProposal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeProposal.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (changeProposal.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeProposal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeProposal.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeProposal.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeProposal.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeProposal.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ChangeProposal changeProposal) + { + throw new ArgumentException("The thing shall be a ChangeProposal", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeProposal.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeProposal.Author); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeProposal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeRequest"u8); + writer.WriteStringValue(changeProposal.ChangeRequest); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeProposal.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeProposal.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeProposal.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeProposal.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeProposal.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeProposal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeProposal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeProposal.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeProposal.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeProposal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeProposal.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (changeProposal.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeProposal.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeProposal.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeProposal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeProposal.ShortName); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeProposal.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeProposal.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeProposal.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeProposal.Title); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var changeProposal = thing as ChangeProposal; - if (changeProposal == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ChangeProposal."); - } + case "approvedby": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) + { + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + writer.WriteEndArray(); + } + break; + case "author": + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(changeProposal); + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "changerequest": + writer.WritePropertyName("changeRequest"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classification": + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) + { + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) + { + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) + { + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + writer.WriteEndArray(); + } + break; + case "status": + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ChangeProposal"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "changeRequest", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs index e5ac3ab78..a6f60e1fc 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ChangeRequestSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ChangeRequest = CDP4Common.DTO.ChangeRequest; /// /// The purpose of the class is to provide a specific serializer @@ -45,96 +50,873 @@ namespace CDP4JsonSerializer public class ChangeRequestSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(ChangeRequest changeRequest) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](changeRequest.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](changeRequest.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](changeRequest.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), changeRequest.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), changeRequest.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](changeRequest.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](changeRequest.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](changeRequest.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](changeRequest.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](changeRequest.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](changeRequest.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](changeRequest.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](changeRequest.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](changeRequest.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](changeRequest.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](changeRequest.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](changeRequest.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](changeRequest.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](changeRequest.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), changeRequest.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](changeRequest.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](changeRequest.Title)); - return jsonObject; + if (thing is not ChangeRequest changeRequest) + { + throw new ArgumentException("The thing shall be a ChangeRequest", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ChangeRequest."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ChangeRequest since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeRequest for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeRequest.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeRequest.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeRequest.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeRequest.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeRequest.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeRequest.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeRequest.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeRequest.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (changeRequest.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeRequest.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeRequest.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeRequest.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeRequest.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeRequest for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeRequest.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeRequest.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeRequest.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeRequest.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeRequest.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeRequest.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeRequest.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeRequest.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (changeRequest.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeRequest.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeRequest.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeRequest.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeRequest.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeRequest.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ChangeRequest for Version 1.3.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeRequest.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeRequest.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeRequest.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeRequest.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeRequest.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeRequest.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeRequest.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeRequest.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (changeRequest.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeRequest.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeRequest.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeRequest.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeRequest.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeRequest.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ChangeRequest changeRequest) + { + throw new ArgumentException("The thing shall be a ChangeRequest", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in changeRequest.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(changeRequest.Author); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in changeRequest.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(changeRequest.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(changeRequest.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(changeRequest.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(changeRequest.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in changeRequest.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in changeRequest.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in changeRequest.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(changeRequest.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(changeRequest.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(changeRequest.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(changeRequest.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (changeRequest.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(changeRequest.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in changeRequest.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(changeRequest.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(changeRequest.ShortName); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in changeRequest.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(changeRequest.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(changeRequest.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(changeRequest.Title); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var changeRequest = thing as ChangeRequest; - if (changeRequest == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ChangeRequest."); - } + case "approvedby": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) + { + writer.WriteStartArray("approvedBy"u8); - return this.Serialize(changeRequest); + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + writer.WriteEndArray(); + } + break; + case "author": + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classification": + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) + { + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) + { + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) + { + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + writer.WriteEndArray(); + } + break; + case "status": + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ChangeRequest"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs index e1d25a099..9c255fc30 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CitationSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Citation = CDP4Common.DTO.Citation; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +50,473 @@ namespace CDP4JsonSerializer public class CitationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isAdaptation", isAdaptation => new JValue(isAdaptation) }, - { "location", location => new JValue(location) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "remark", remark => new JValue(remark) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "source", source => new JValue(source) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(Citation citation) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), citation.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](citation.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](citation.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](citation.Iid)); - jsonObject.Add("isAdaptation", this.PropertySerializerMap["isAdaptation"](citation.IsAdaptation)); - jsonObject.Add("location", this.PropertySerializerMap["location"](citation.Location)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](citation.ModifiedOn)); - jsonObject.Add("remark", this.PropertySerializerMap["remark"](citation.Remark)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](citation.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](citation.ShortName)); - jsonObject.Add("source", this.PropertySerializerMap["source"](citation.Source)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](citation.ThingPreference)); - return jsonObject; + if (thing is not Citation citation) + { + throw new ArgumentException("The thing shall be a Citation", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Citation."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Citation since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Citation for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Citation for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(citation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Citation for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(citation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(citation.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Citation for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(citation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(citation.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Citation citation) + { + throw new ArgumentException("The thing shall be a Citation", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(citation.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in citation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in citation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(citation.Iid); + writer.WritePropertyName("isAdaptation"u8); + writer.WriteBooleanValue(citation.IsAdaptation); + writer.WritePropertyName("location"u8); + writer.WriteStringValue(citation.Location); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(citation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("remark"u8); + writer.WriteStringValue(citation.Remark); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(citation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(citation.ShortName); + writer.WritePropertyName("source"u8); + writer.WriteStringValue(citation.Source); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(citation.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var citation = thing as Citation; - if (citation == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Citation."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); - return this.Serialize(citation); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isadaptation": + writer.WritePropertyName("isAdaptation"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "location": + writer.WritePropertyName("location"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "remark": + writer.WritePropertyName("remark"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "source": + writer.WritePropertyName("source"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Citation"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isAdaptation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "location", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "remark", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "source", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs index 2db0a4d15..a30ee38eb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ColorSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Color = CDP4Common.DTO.Color; /// /// The purpose of the class is to provide a specific serializer @@ -45,74 +50,449 @@ namespace CDP4JsonSerializer public class ColorSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "blue", blue => new JValue(blue) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "green", green => new JValue(green) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "red", red => new JValue(red) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(Color color) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("blue", this.PropertySerializerMap["blue"](color.Blue)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), color.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](color.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](color.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("green", this.PropertySerializerMap["green"](color.Green)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](color.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](color.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](color.Name)); - jsonObject.Add("red", this.PropertySerializerMap["red"](color.Red)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](color.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](color.ThingPreference)); - return jsonObject; + if (thing is not Color color) + { + throw new ArgumentException("The thing shall be a Color", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Color."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Color since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Color for Version 1.0.0"); + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Color for Version 1.1.0"); + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(color.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Color for Version 1.2.0"); + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(color.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(color.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Color for Version 1.3.0"); + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(color.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(color.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Color color) + { + throw new ArgumentException("The thing shall be a Color", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("blue"u8); + writer.WriteNumberValue(color.Blue); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(color.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in color.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in color.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("green"u8); + writer.WriteNumberValue(color.Green); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(color.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(color.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(color.Name); + writer.WritePropertyName("red"u8); + writer.WriteNumberValue(color.Red); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(color.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(color.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var color = thing as Color; - if (color == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Color."); - } + case "blue": + writer.WritePropertyName("blue"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } - return this.Serialize(color); + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "green": + writer.WritePropertyName("green"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "red": + writer.WritePropertyName("red"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Color"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "blue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "green", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "red", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs index 4b381bcb0..6bd8f03fb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CommonFileStoreSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using CommonFileStore = CDP4Common.DTO.CommonFileStore; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +50,553 @@ namespace CDP4JsonSerializer public class CommonFileStoreSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "file", file => new JArray(file) }, - { "folder", folder => new JArray(folder) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(CommonFileStore commonFileStore) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), commonFileStore.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](commonFileStore.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](commonFileStore.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](commonFileStore.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("file", this.PropertySerializerMap["file"](commonFileStore.File.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("folder", this.PropertySerializerMap["folder"](commonFileStore.Folder.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](commonFileStore.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](commonFileStore.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](commonFileStore.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](commonFileStore.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](commonFileStore.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](commonFileStore.ThingPreference)); - return jsonObject; + if (thing is not CommonFileStore commonFileStore) + { + throw new ArgumentException("The thing shall be a CommonFileStore", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of CommonFileStore."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of CommonFileStore since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing CommonFileStore for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing CommonFileStore for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(commonFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing CommonFileStore for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(commonFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(commonFileStore.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing CommonFileStore for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(commonFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(commonFileStore.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not CommonFileStore commonFileStore) + { + throw new ArgumentException("The thing shall be a CommonFileStore", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(commonFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(commonFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in commonFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in commonFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in commonFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in commonFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(commonFileStore.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(commonFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(commonFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(commonFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(commonFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(commonFileStore.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var commonFileStore = thing as CommonFileStore; - if (commonFileStore == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a CommonFileStore."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "file": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListFile && objectListFile.Any()) + { + writer.WriteStartArray("file"u8); + + foreach(var fileItem in objectListFile.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + writer.WriteEndArray(); + } + break; + case "folder": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListFolder && objectListFolder.Any()) + { + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in objectListFolder.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(commonFileStore); + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the CommonFileStore"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "file", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "folder", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs index d34112269..a21a5318c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CompoundParameterTypeSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using CompoundParameterType = CDP4Common.DTO.CompoundParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,86 +50,792 @@ namespace CDP4JsonSerializer public class CompoundParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "component", component => new JArray(((IEnumerable)component).Cast().Select(x => x.ToJsonObject())) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isFinalized", isFinalized => new JValue(isFinalized) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(CompoundParameterType compoundParameterType) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](compoundParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](compoundParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), compoundParameterType.ClassKind))); - jsonObject.Add("component", this.PropertySerializerMap["component"](compoundParameterType.Component.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](compoundParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](compoundParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](compoundParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](compoundParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](compoundParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](compoundParameterType.IsDeprecated)); - jsonObject.Add("isFinalized", this.PropertySerializerMap["isFinalized"](compoundParameterType.IsFinalized)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](compoundParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](compoundParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](compoundParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](compoundParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](compoundParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](compoundParameterType.ThingPreference)); - return jsonObject; + if (thing is not CompoundParameterType compoundParameterType) + { + throw new ArgumentException("The thing shall be a CompoundParameterType", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of CompoundParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of CompoundParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(compoundParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(compoundParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(compoundParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing CompoundParameterType for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(compoundParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(compoundParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not CompoundParameterType compoundParameterType) + { + throw new ArgumentException("The thing shall be a CompoundParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in compoundParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in compoundParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(compoundParameterType.ClassKind.ToString()); + + writer.WriteStartArray("component"u8); + + foreach(var componentItem in compoundParameterType.Component.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in compoundParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in compoundParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in compoundParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in compoundParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(compoundParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(compoundParameterType.IsDeprecated); + writer.WritePropertyName("isFinalized"u8); + writer.WriteBooleanValue(compoundParameterType.IsFinalized); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(compoundParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(compoundParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(compoundParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(compoundParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(compoundParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(compoundParameterType.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var compoundParameterType = thing as CompoundParameterType; - if (compoundParameterType == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a CompoundParameterType."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "component": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListComponent && objectListComponent.Any()) + { + writer.WriteStartArray("component"u8); + + foreach(var componentItem in objectListComponent.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(componentItem); + } + writer.WriteEndArray(); + } + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } - return this.Serialize(compoundParameterType); + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isfinalized": + writer.WritePropertyName("isFinalized"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the CompoundParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "component", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isFinalized", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs index 63f11b496..66e881da0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ConstantSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Constant = CDP4Common.DTO.Constant; /// /// The purpose of the class is to provide a specific serializer @@ -45,86 +50,782 @@ namespace CDP4JsonSerializer public class ConstantSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(((ValueArray)value).ToJsonString()) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(Constant constant) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](constant.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](constant.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), constant.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](constant.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](constant.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](constant.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](constant.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](constant.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](constant.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](constant.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](constant.Name)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](constant.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](constant.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](constant.Scale)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](constant.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](constant.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](constant.Value)); - return jsonObject; + if (thing is not Constant constant) + { + throw new ArgumentException("The thing shall be a Constant", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Constant."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Constant since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (constant.Scale.HasValue) + { + writer.WriteStringValue(constant.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WriteString("value"u8, constant.Value.ToJsonString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(constant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (constant.Scale.HasValue) + { + writer.WriteStringValue(constant.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WriteString("value"u8, constant.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(constant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (constant.Scale.HasValue) + { + writer.WriteStringValue(constant.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(constant.ThingPreference); + writer.WriteString("value"u8, constant.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Constant for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(constant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (constant.Scale.HasValue) + { + writer.WriteStringValue(constant.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(constant.ThingPreference); + writer.WriteString("value"u8, constant.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Constant constant) + { + throw new ArgumentException("The thing shall be a Constant", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in constant.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in constant.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(constant.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in constant.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in constant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in constant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in constant.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(constant.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(constant.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(constant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(constant.Name); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(constant.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(constant.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (constant.Scale.HasValue) + { + writer.WriteStringValue(constant.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(constant.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(constant.ThingPreference); + writer.WriteString("value"u8, constant.Value.ToJsonString()); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var constant = thing as Constant; - if (constant == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Constant."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } - return this.Serialize(constant); + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Constant"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs index 9fad3d594..1c39b5553 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ContractChangeNoticeSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ContractChangeNotice = CDP4Common.DTO.ContractChangeNotice; /// /// The purpose of the class is to provide a specific serializer @@ -45,98 +50,895 @@ namespace CDP4JsonSerializer public class ContractChangeNoticeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "changeProposal", changeProposal => new JValue(changeProposal) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(ContractChangeNotice contractChangeNotice) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](contractChangeNotice.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](contractChangeNotice.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](contractChangeNotice.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("changeProposal", this.PropertySerializerMap["changeProposal"](contractChangeNotice.ChangeProposal)); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), contractChangeNotice.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), contractChangeNotice.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](contractChangeNotice.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](contractChangeNotice.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](contractChangeNotice.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](contractChangeNotice.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](contractChangeNotice.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](contractChangeNotice.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](contractChangeNotice.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](contractChangeNotice.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](contractChangeNotice.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](contractChangeNotice.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](contractChangeNotice.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), contractChangeNotice.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](contractChangeNotice.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](contractChangeNotice.Title)); - return jsonObject; + if (thing is not ContractChangeNotice contractChangeNotice) + { + throw new ArgumentException("The thing shall be a ContractChangeNotice", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ContractChangeNotice."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ContractChangeNotice since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ContractChangeNotice for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(contractChangeNotice.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeProposal"u8); + writer.WriteStringValue(contractChangeNotice.ChangeProposal); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(contractChangeNotice.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(contractChangeNotice.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(contractChangeNotice.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(contractChangeNotice.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(contractChangeNotice.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(contractChangeNotice.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(contractChangeNotice.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (contractChangeNotice.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(contractChangeNotice.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(contractChangeNotice.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(contractChangeNotice.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(contractChangeNotice.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ContractChangeNotice for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(contractChangeNotice.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeProposal"u8); + writer.WriteStringValue(contractChangeNotice.ChangeProposal); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(contractChangeNotice.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(contractChangeNotice.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(contractChangeNotice.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(contractChangeNotice.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(contractChangeNotice.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(contractChangeNotice.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(contractChangeNotice.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (contractChangeNotice.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(contractChangeNotice.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(contractChangeNotice.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(contractChangeNotice.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(contractChangeNotice.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(contractChangeNotice.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ContractChangeNotice for Version 1.3.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(contractChangeNotice.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeProposal"u8); + writer.WriteStringValue(contractChangeNotice.ChangeProposal); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(contractChangeNotice.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(contractChangeNotice.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(contractChangeNotice.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(contractChangeNotice.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(contractChangeNotice.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(contractChangeNotice.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(contractChangeNotice.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (contractChangeNotice.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(contractChangeNotice.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(contractChangeNotice.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(contractChangeNotice.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(contractChangeNotice.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(contractChangeNotice.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ContractChangeNotice contractChangeNotice) + { + throw new ArgumentException("The thing shall be a ContractChangeNotice", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in contractChangeNotice.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(contractChangeNotice.Author); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in contractChangeNotice.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeProposal"u8); + writer.WriteStringValue(contractChangeNotice.ChangeProposal); + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(contractChangeNotice.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(contractChangeNotice.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(contractChangeNotice.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(contractChangeNotice.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in contractChangeNotice.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in contractChangeNotice.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in contractChangeNotice.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(contractChangeNotice.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(contractChangeNotice.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(contractChangeNotice.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(contractChangeNotice.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (contractChangeNotice.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(contractChangeNotice.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in contractChangeNotice.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(contractChangeNotice.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(contractChangeNotice.ShortName); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in contractChangeNotice.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(contractChangeNotice.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(contractChangeNotice.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(contractChangeNotice.Title); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var contractChangeNotice = thing as ContractChangeNotice; - if (contractChangeNotice == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ContractChangeNotice."); - } + case "approvedby": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) + { + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + writer.WriteEndArray(); + } + break; + case "author": + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(contractChangeNotice); + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "changeproposal": + writer.WritePropertyName("changeProposal"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classification": + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) + { + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) + { + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) + { + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + writer.WriteEndArray(); + } + break; + case "status": + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ContractChangeNotice"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "changeProposal", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs index d84dd99e9..45824187c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/CyclicRatioScaleSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using CyclicRatioScale = CDP4Common.DTO.CyclicRatioScale; /// /// The purpose of the class is to provide a specific serializer @@ -45,100 +50,960 @@ namespace CDP4JsonSerializer public class CyclicRatioScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isMaximumInclusive", isMaximumInclusive => new JValue(isMaximumInclusive) }, - { "isMinimumInclusive", isMinimumInclusive => new JValue(isMinimumInclusive) }, - { "mappingToReferenceScale", mappingToReferenceScale => new JArray(mappingToReferenceScale) }, - { "maximumPermissibleValue", maximumPermissibleValue => new JValue(maximumPermissibleValue) }, - { "minimumPermissibleValue", minimumPermissibleValue => new JValue(minimumPermissibleValue) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "modulus", modulus => new JValue(modulus) }, - { "name", name => new JValue(name) }, - { "negativeValueConnotation", negativeValueConnotation => new JValue(negativeValueConnotation) }, - { "numberSet", numberSet => new JValue(numberSet.ToString()) }, - { "positiveValueConnotation", positiveValueConnotation => new JValue(positiveValueConnotation) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - { "valueDefinition", valueDefinition => new JArray(valueDefinition) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(CyclicRatioScale cyclicRatioScale) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](cyclicRatioScale.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), cyclicRatioScale.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](cyclicRatioScale.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](cyclicRatioScale.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](cyclicRatioScale.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](cyclicRatioScale.IsDeprecated)); - jsonObject.Add("isMaximumInclusive", this.PropertySerializerMap["isMaximumInclusive"](cyclicRatioScale.IsMaximumInclusive)); - jsonObject.Add("isMinimumInclusive", this.PropertySerializerMap["isMinimumInclusive"](cyclicRatioScale.IsMinimumInclusive)); - jsonObject.Add("mappingToReferenceScale", this.PropertySerializerMap["mappingToReferenceScale"](cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("maximumPermissibleValue", this.PropertySerializerMap["maximumPermissibleValue"](cyclicRatioScale.MaximumPermissibleValue)); - jsonObject.Add("minimumPermissibleValue", this.PropertySerializerMap["minimumPermissibleValue"](cyclicRatioScale.MinimumPermissibleValue)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](cyclicRatioScale.ModifiedOn)); - jsonObject.Add("modulus", this.PropertySerializerMap["modulus"](cyclicRatioScale.Modulus)); - jsonObject.Add("name", this.PropertySerializerMap["name"](cyclicRatioScale.Name)); - jsonObject.Add("negativeValueConnotation", this.PropertySerializerMap["negativeValueConnotation"](cyclicRatioScale.NegativeValueConnotation)); - jsonObject.Add("numberSet", this.PropertySerializerMap["numberSet"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.NumberSetKind), cyclicRatioScale.NumberSet))); - jsonObject.Add("positiveValueConnotation", this.PropertySerializerMap["positiveValueConnotation"](cyclicRatioScale.PositiveValueConnotation)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](cyclicRatioScale.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](cyclicRatioScale.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](cyclicRatioScale.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](cyclicRatioScale.Unit)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.guidComparer))); - return jsonObject; + if (thing is not CyclicRatioScale cyclicRatioScale) + { + throw new ArgumentException("The thing shall be a CyclicRatioScale", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of CyclicRatioScale."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of CyclicRatioScale since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(cyclicRatioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(cyclicRatioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(cyclicRatioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing CyclicRatioScale for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(cyclicRatioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(cyclicRatioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not CyclicRatioScale cyclicRatioScale) + { + throw new ArgumentException("The thing shall be a CyclicRatioScale", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in cyclicRatioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(cyclicRatioScale.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in cyclicRatioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in cyclicRatioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in cyclicRatioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in cyclicRatioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(cyclicRatioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(cyclicRatioScale.IsMinimumInclusive); + + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in cyclicRatioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(cyclicRatioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(cyclicRatioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("modulus"u8); + writer.WriteStringValue(cyclicRatioScale.Modulus); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(cyclicRatioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(cyclicRatioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(cyclicRatioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(cyclicRatioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(cyclicRatioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(cyclicRatioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(cyclicRatioScale.Unit); + + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in cyclicRatioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var cyclicRatioScale = thing as CyclicRatioScale; - if (cyclicRatioScale == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a CyclicRatioScale."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(cyclicRatioScale); + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ismaximuminclusive": + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mappingtoreferencescale": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListMappingToReferenceScale && objectListMappingToReferenceScale.Any()) + { + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + writer.WriteEndArray(); + } + break; + case "maximumpermissiblevalue": + writer.WritePropertyName("maximumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minimumpermissiblevalue": + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modulus": + writer.WritePropertyName("modulus"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "negativevalueconnotation": + writer.WritePropertyName("negativeValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "numberset": + writer.WritePropertyName("numberSet"u8); + + if(value != null) + { + writer.WriteStringValue(((NumberSetKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "positivevalueconnotation": + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) + { + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the CyclicRatioScale"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMaximumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMinimumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "mappingToReferenceScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maximumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minimumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modulus", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "negativeValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "numberSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "positiveValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs index 3d0909bda..4310262d9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateParameterTypeSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DateParameterType = CDP4Common.DTO.DateParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +50,704 @@ namespace CDP4JsonSerializer public class DateParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(DateParameterType dateParameterType) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](dateParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](dateParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), dateParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](dateParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](dateParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](dateParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](dateParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](dateParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](dateParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](dateParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](dateParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](dateParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](dateParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](dateParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](dateParameterType.ThingPreference)); - return jsonObject; + if (thing is not DateParameterType dateParameterType) + { + throw new ArgumentException("The thing shall be a DateParameterType", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DateParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DateParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DateParameterType for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not DateParameterType dateParameterType) + { + throw new ArgumentException("The thing shall be a DateParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateParameterType.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateParameterType.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var dateParameterType = thing as DateParameterType; - if (dateParameterType == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DateParameterType."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); - return this.Serialize(dateParameterType); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DateParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs index c2d3264cf..382ccc97b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DateTimeParameterTypeSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DateTimeParameterType = CDP4Common.DTO.DateTimeParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +50,704 @@ namespace CDP4JsonSerializer public class DateTimeParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(DateTimeParameterType dateTimeParameterType) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](dateTimeParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](dateTimeParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), dateTimeParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](dateTimeParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](dateTimeParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](dateTimeParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](dateTimeParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](dateTimeParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](dateTimeParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](dateTimeParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](dateTimeParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](dateTimeParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](dateTimeParameterType.ThingPreference)); - return jsonObject; + if (thing is not DateTimeParameterType dateTimeParameterType) + { + throw new ArgumentException("The thing shall be a DateTimeParameterType", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DateTimeParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DateTimeParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateTimeParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateTimeParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateTimeParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DateTimeParameterType for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateTimeParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateTimeParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not DateTimeParameterType dateTimeParameterType) + { + throw new ArgumentException("The thing shall be a DateTimeParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in dateTimeParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in dateTimeParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dateTimeParameterType.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in dateTimeParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dateTimeParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dateTimeParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in dateTimeParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dateTimeParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(dateTimeParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dateTimeParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(dateTimeParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dateTimeParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(dateTimeParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(dateTimeParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dateTimeParameterType.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var dateTimeParameterType = thing as DateTimeParameterType; - if (dateTimeParameterType == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DateTimeParameterType."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); - return this.Serialize(dateTimeParameterType); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DateTimeParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs index d0bf402ec..e0c22aaf4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DecompositionRuleSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DecompositionRule = CDP4Common.DTO.DecompositionRule; /// /// The purpose of the class is to provide a specific serializer @@ -45,86 +50,797 @@ namespace CDP4JsonSerializer public class DecompositionRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "containedCategory", containedCategory => new JArray(containedCategory) }, - { "containingCategory", containingCategory => new JValue(containingCategory) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "maxContained", maxContained => new JValue(maxContained) }, - { "minContained", minContained => new JValue(minContained) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(DecompositionRule decompositionRule) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](decompositionRule.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), decompositionRule.ClassKind))); - jsonObject.Add("containedCategory", this.PropertySerializerMap["containedCategory"](decompositionRule.ContainedCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("containingCategory", this.PropertySerializerMap["containingCategory"](decompositionRule.ContainingCategory)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](decompositionRule.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](decompositionRule.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](decompositionRule.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](decompositionRule.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](decompositionRule.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](decompositionRule.IsDeprecated)); - jsonObject.Add("maxContained", this.PropertySerializerMap["maxContained"](decompositionRule.MaxContained)); - jsonObject.Add("minContained", this.PropertySerializerMap["minContained"](decompositionRule.MinContained)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](decompositionRule.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](decompositionRule.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](decompositionRule.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](decompositionRule.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](decompositionRule.ThingPreference)); - return jsonObject; + if (thing is not DecompositionRule decompositionRule) + { + throw new ArgumentException("The thing shall be a DecompositionRule", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DecompositionRule."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DecompositionRule since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); + + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); + + if (decompositionRule.MaxContained.HasValue) + { + writer.WriteNumberValue(decompositionRule.MaxContained.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); + + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); + + if (decompositionRule.MaxContained.HasValue) + { + writer.WriteNumberValue(decompositionRule.MaxContained.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(decompositionRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); + + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); + + if (decompositionRule.MaxContained.HasValue) + { + writer.WriteNumberValue(decompositionRule.MaxContained.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(decompositionRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(decompositionRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DecompositionRule for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + writer.WriteStartArray("containedCategory"u8); + + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); + + if (decompositionRule.MaxContained.HasValue) + { + writer.WriteNumberValue(decompositionRule.MaxContained.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(decompositionRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(decompositionRule.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not DecompositionRule decompositionRule) + { + throw new ArgumentException("The thing shall be a DecompositionRule", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in decompositionRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(decompositionRule.ClassKind.ToString()); + + writer.WriteStartArray("containedCategory"u8); + + foreach(var containedCategoryItem in decompositionRule.ContainedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("containingCategory"u8); + writer.WriteStringValue(decompositionRule.ContainingCategory); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in decompositionRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in decompositionRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in decompositionRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in decompositionRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(decompositionRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(decompositionRule.IsDeprecated); + writer.WritePropertyName("maxContained"u8); + + if (decompositionRule.MaxContained.HasValue) + { + writer.WriteNumberValue(decompositionRule.MaxContained.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("minContained"u8); + writer.WriteNumberValue(decompositionRule.MinContained); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(decompositionRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(decompositionRule.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(decompositionRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(decompositionRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(decompositionRule.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var decompositionRule = thing as DecompositionRule; - if (decompositionRule == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DecompositionRule."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "containedcategory": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListContainedCategory && objectListContainedCategory.Any()) + { + writer.WriteStartArray("containedCategory"u8); + + foreach(var containedCategoryItem in objectListContainedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedCategoryItem); + } + writer.WriteEndArray(); + } + break; + case "containingcategory": + writer.WritePropertyName("containingCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } - return this.Serialize(decompositionRule); + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "maxcontained": + writer.WritePropertyName("maxContained"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mincontained": + writer.WritePropertyName("minContained"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DecompositionRule"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containedCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containingCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maxContained", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minContained", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs index 85bb31058..fadd0fa6f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DefinitionSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Definition = CDP4Common.DTO.Definition; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +50,592 @@ namespace CDP4JsonSerializer public class DefinitionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "citation", citation => new JArray(citation) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "example", example => new JArray(((IEnumerable)example).Cast().Select(x => x.ToJsonObject())) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "note", note => new JArray(((IEnumerable)note).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(Definition definition) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("citation", this.PropertySerializerMap["citation"](definition.Citation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), definition.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](definition.Content)); - jsonObject.Add("example", this.PropertySerializerMap["example"](definition.Example.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](definition.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](definition.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](definition.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](definition.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](definition.ModifiedOn)); - jsonObject.Add("note", this.PropertySerializerMap["note"](definition.Note.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](definition.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](definition.ThingPreference)); - return jsonObject; + if (thing is not Definition definition) + { + throw new ArgumentException("The thing shall be a Definition", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Definition."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Definition since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.0.0"); + writer.WriteStartArray("citation"u8); + + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(definition.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(definition.Content); + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(definition.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(definition.LanguageCode); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(definition.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.1.0"); + writer.WriteStartArray("citation"u8); + + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(definition.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(definition.Content); + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(definition.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(definition.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(definition.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.2.0"); + writer.WriteStartArray("citation"u8); + + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(definition.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(definition.Content); + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(definition.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(definition.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(definition.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(definition.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Definition for Version 1.3.0"); + writer.WriteStartArray("citation"u8); + + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(definition.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(definition.Content); + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(definition.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(definition.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(definition.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(definition.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Definition definition) + { + throw new ArgumentException("The thing shall be a Definition", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("citation"u8); + + foreach(var citationItem in definition.Citation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(definition.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(definition.Content); + + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in definition.Example.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in definition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in definition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(definition.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(definition.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(definition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("note"u8); + + foreach(var noteItem in definition.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(definition.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(definition.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var definition = thing as Definition; - if (definition == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Definition."); - } + case "citation": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCitation && objectListCitation.Any()) + { + writer.WriteStartArray("citation"u8); + + foreach(var citationItem in objectListCitation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(citationItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "example": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExample && objectListExample.Any()) + { + writer.WriteStartArray("example"u8); + + foreach(var exampleItem in objectListExample.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(exampleItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(definition); + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "note": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListNote && objectListNote.Any()) + { + writer.WriteStartArray("note"u8); + + foreach(var noteItem in objectListNote.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Definition"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "citation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "example", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "note", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs index 62f0f45ec..4e97b8ed9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DependentParameterTypeAssignmentSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DependentParameterTypeAssignment = CDP4Common.DTO.DependentParameterTypeAssignment; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +50,382 @@ namespace CDP4JsonSerializer public class DependentParameterTypeAssignmentSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "measurementScale", measurementScale => new JValue(measurementScale) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(DependentParameterTypeAssignment dependentParameterTypeAssignment) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.2.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), dependentParameterTypeAssignment.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](dependentParameterTypeAssignment.Iid)); - jsonObject.Add("measurementScale", this.PropertySerializerMap["measurementScale"](dependentParameterTypeAssignment.MeasurementScale)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](dependentParameterTypeAssignment.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](dependentParameterTypeAssignment.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](dependentParameterTypeAssignment.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](dependentParameterTypeAssignment.ThingPreference)); - return jsonObject; + if (thing is not DependentParameterTypeAssignment dependentParameterTypeAssignment) + { + throw new ArgumentException("The thing shall be a DependentParameterTypeAssignment", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DependentParameterTypeAssignment."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DependentParameterTypeAssignment since Version is below 1.2.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DependentParameterTypeAssignment for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if (dependentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(dependentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dependentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DependentParameterTypeAssignment for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if (dependentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(dependentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dependentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not DependentParameterTypeAssignment dependentParameterTypeAssignment) + { + throw new ArgumentException("The thing shall be a DependentParameterTypeAssignment", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in dependentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in dependentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if (dependentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(dependentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(dependentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(dependentParameterTypeAssignment.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var dependentParameterTypeAssignment = thing as DependentParameterTypeAssignment; - if (dependentParameterTypeAssignment == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DependentParameterTypeAssignment."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(dependentParameterTypeAssignment); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "measurementscale": + writer.WritePropertyName("measurementScale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DependentParameterTypeAssignment"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.2.0", "1.3.0" }}, + { "measurementScale", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs index 2c7858062..059c6ed9d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedQuantityKindSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DerivedQuantityKind = CDP4Common.DTO.DerivedQuantityKind; /// /// The purpose of the class is to provide a specific serializer @@ -45,90 +50,880 @@ namespace CDP4JsonSerializer public class DerivedQuantityKindSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultScale", defaultScale => new JValue(defaultScale) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "possibleScale", possibleScale => new JArray(possibleScale) }, - { "quantityDimensionSymbol", quantityDimensionSymbol => new JValue(quantityDimensionSymbol) }, - { "quantityKindFactor", quantityKindFactor => new JArray(((IEnumerable)quantityKindFactor).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(DerivedQuantityKind derivedQuantityKind) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](derivedQuantityKind.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](derivedQuantityKind.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), derivedQuantityKind.ClassKind))); - jsonObject.Add("defaultScale", this.PropertySerializerMap["defaultScale"](derivedQuantityKind.DefaultScale)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](derivedQuantityKind.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](derivedQuantityKind.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](derivedQuantityKind.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](derivedQuantityKind.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](derivedQuantityKind.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](derivedQuantityKind.Name)); - jsonObject.Add("possibleScale", this.PropertySerializerMap["possibleScale"](derivedQuantityKind.PossibleScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("quantityDimensionSymbol", this.PropertySerializerMap["quantityDimensionSymbol"](derivedQuantityKind.QuantityDimensionSymbol)); - jsonObject.Add("quantityKindFactor", this.PropertySerializerMap["quantityKindFactor"](derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](derivedQuantityKind.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](derivedQuantityKind.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](derivedQuantityKind.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](derivedQuantityKind.ThingPreference)); - return jsonObject; + if (thing is not DerivedQuantityKind derivedQuantityKind) + { + throw new ArgumentException("The thing shall be a DerivedQuantityKind", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DerivedQuantityKind."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DerivedQuantityKind since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedQuantityKind.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedQuantityKind for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedQuantityKind.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not DerivedQuantityKind derivedQuantityKind) + { + throw new ArgumentException("The thing shall be a DerivedQuantityKind", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in derivedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(derivedQuantityKind.DefaultScale); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedQuantityKind.Name); + + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in derivedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(derivedQuantityKind.QuantityDimensionSymbol); + + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in derivedQuantityKind.QuantityKindFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(derivedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedQuantityKind.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var derivedQuantityKind = thing as DerivedQuantityKind; - if (derivedQuantityKind == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DerivedQuantityKind."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultscale": + writer.WritePropertyName("defaultScale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(derivedQuantityKind); + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblescale": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListPossibleScale && objectListPossibleScale.Any()) + { + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + writer.WriteEndArray(); + } + break; + case "quantitydimensionsymbol": + writer.WritePropertyName("quantityDimensionSymbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "quantitykindfactor": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListQuantityKindFactor && objectListQuantityKindFactor.Any()) + { + writer.WriteStartArray("quantityKindFactor"u8); + + foreach(var quantityKindFactorItem in objectListQuantityKindFactor.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(quantityKindFactorItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DerivedQuantityKind"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "quantityDimensionSymbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "quantityKindFactor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs index d9aee87fa..c112d9b7f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DerivedUnitSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DerivedUnit = CDP4Common.DTO.DerivedUnit; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +50,680 @@ namespace CDP4JsonSerializer public class DerivedUnitSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unitFactor", unitFactor => new JArray(((IEnumerable)unitFactor).Cast().Select(x => x.ToJsonObject())) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(DerivedUnit derivedUnit) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](derivedUnit.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), derivedUnit.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](derivedUnit.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](derivedUnit.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](derivedUnit.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](derivedUnit.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](derivedUnit.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](derivedUnit.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](derivedUnit.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](derivedUnit.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](derivedUnit.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](derivedUnit.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](derivedUnit.ThingPreference)); - jsonObject.Add("unitFactor", this.PropertySerializerMap["unitFactor"](derivedUnit.UnitFactor.OrderBy(x => x, this.orderedItemComparer))); - return jsonObject; + if (thing is not DerivedUnit derivedUnit) + { + throw new ArgumentException("The thing shall be a DerivedUnit", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DerivedUnit."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DerivedUnit since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedUnit.ThingPreference); + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DerivedUnit for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedUnit.ThingPreference); + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not DerivedUnit derivedUnit) + { + throw new ArgumentException("The thing shall be a DerivedUnit", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in derivedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(derivedUnit.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in derivedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in derivedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in derivedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in derivedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(derivedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(derivedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(derivedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(derivedUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(derivedUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(derivedUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(derivedUnit.ThingPreference); + + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in derivedUnit.UnitFactor.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var derivedUnit = thing as DerivedUnit; - if (derivedUnit == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DerivedUnit."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(derivedUnit); + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unitfactor": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListUnitFactor && objectListUnitFactor.Any()) + { + writer.WriteStartArray("unitFactor"u8); + + foreach(var unitFactorItem in objectListUnitFactor.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(unitFactorItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DerivedUnit"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unitFactor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs index 773c02c82..917889ad2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramCanvasSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DiagramCanvas = CDP4Common.DTO.DiagramCanvas; /// /// The purpose of the class is to provide a specific serializer @@ -45,74 +50,497 @@ namespace CDP4JsonSerializer public class DiagramCanvasSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "bounds", bounds => new JArray(bounds) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "diagramElement", diagramElement => new JArray(diagramElement) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(DiagramCanvas diagramCanvas) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("bounds", this.PropertySerializerMap["bounds"](diagramCanvas.Bounds)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), diagramCanvas.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](diagramCanvas.CreatedOn)); - jsonObject.Add("diagramElement", this.PropertySerializerMap["diagramElement"](diagramCanvas.DiagramElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](diagramCanvas.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](diagramCanvas.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](diagramCanvas.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](diagramCanvas.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](diagramCanvas.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](diagramCanvas.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](diagramCanvas.ThingPreference)); - return jsonObject; + if (thing is not DiagramCanvas diagramCanvas) + { + throw new ArgumentException("The thing shall be a DiagramCanvas", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DiagramCanvas."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DiagramCanvas since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramCanvas for Version 1.1.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramCanvas.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramCanvas.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramCanvas.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramCanvas.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramCanvas for Version 1.2.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramCanvas.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramCanvas.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramCanvas.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramCanvas.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramCanvas.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramCanvas for Version 1.3.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramCanvas.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramCanvas.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramCanvas.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramCanvas.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramCanvas.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not DiagramCanvas diagramCanvas) + { + throw new ArgumentException("The thing shall be a DiagramCanvas", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramCanvas.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramCanvas.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(diagramCanvas.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramCanvas.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramCanvas.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramCanvas.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramCanvas.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramCanvas.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramCanvas.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramCanvas.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramCanvas.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var diagramCanvas = thing as DiagramCanvas; - if (diagramCanvas == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DiagramCanvas."); - } + case "bounds": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListBounds && objectListBounds.Any()) + { + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in objectListBounds.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "diagramelement": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDiagramElement && objectListDiagramElement.Any()) + { + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in objectListDiagramElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(diagramCanvas); + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DiagramCanvas"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "bounds", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "diagramElement", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs index 9c1806bf5..8e4d6061f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramEdgeSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DiagramEdge = CDP4Common.DTO.DiagramEdge; /// /// The purpose of the class is to provide a specific serializer @@ -45,84 +50,744 @@ namespace CDP4JsonSerializer public class DiagramEdgeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "bounds", bounds => new JArray(bounds) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "depictedThing", depictedThing => new JValue(depictedThing) }, - { "diagramElement", diagramElement => new JArray(diagramElement) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "localStyle", localStyle => new JArray(localStyle) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "point", point => new JArray(((IEnumerable)point).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "sharedStyle", sharedStyle => new JValue(sharedStyle) }, - { "source", source => new JValue(source) }, - { "target", target => new JValue(target) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(DiagramEdge diagramEdge) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("bounds", this.PropertySerializerMap["bounds"](diagramEdge.Bounds)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), diagramEdge.ClassKind))); - jsonObject.Add("depictedThing", this.PropertySerializerMap["depictedThing"](diagramEdge.DepictedThing)); - jsonObject.Add("diagramElement", this.PropertySerializerMap["diagramElement"](diagramEdge.DiagramElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](diagramEdge.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](diagramEdge.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](diagramEdge.Iid)); - jsonObject.Add("localStyle", this.PropertySerializerMap["localStyle"](diagramEdge.LocalStyle)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](diagramEdge.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](diagramEdge.Name)); - jsonObject.Add("point", this.PropertySerializerMap["point"](diagramEdge.Point.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](diagramEdge.RevisionNumber)); - jsonObject.Add("sharedStyle", this.PropertySerializerMap["sharedStyle"](diagramEdge.SharedStyle)); - jsonObject.Add("source", this.PropertySerializerMap["source"](diagramEdge.Source)); - jsonObject.Add("target", this.PropertySerializerMap["target"](diagramEdge.Target)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](diagramEdge.ThingPreference)); - return jsonObject; + if (thing is not DiagramEdge diagramEdge) + { + throw new ArgumentException("The thing shall be a DiagramEdge", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DiagramEdge."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DiagramEdge since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramEdge for Version 1.1.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramEdge.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if (diagramEdge.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramEdge.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramEdge.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramEdge.Name); + writer.WriteStartArray("point"u8); + + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pointItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramEdge.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if (diagramEdge.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramEdge.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("source"u8); + writer.WriteStringValue(diagramEdge.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(diagramEdge.Target); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramEdge for Version 1.2.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramEdge.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if (diagramEdge.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramEdge.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramEdge.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramEdge.Name); + writer.WriteStartArray("point"u8); + + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pointItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramEdge.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if (diagramEdge.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramEdge.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("source"u8); + writer.WriteStringValue(diagramEdge.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(diagramEdge.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramEdge.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramEdge for Version 1.3.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramEdge.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if (diagramEdge.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramEdge.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramEdge.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramEdge.Name); + writer.WriteStartArray("point"u8); + + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pointItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramEdge.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if (diagramEdge.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramEdge.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("source"u8); + writer.WriteStringValue(diagramEdge.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(diagramEdge.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramEdge.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not DiagramEdge diagramEdge) + { + throw new ArgumentException("The thing shall be a DiagramEdge", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramEdge.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramEdge.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if (diagramEdge.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramEdge.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramEdge.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramEdge.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramEdge.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramEdge.Iid); + + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramEdge.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramEdge.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramEdge.Name); + + writer.WriteStartArray("point"u8); + + foreach(var pointItem in diagramEdge.Point.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pointItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramEdge.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if (diagramEdge.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramEdge.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("source"u8); + writer.WriteStringValue(diagramEdge.Source); + writer.WritePropertyName("target"u8); + writer.WriteStringValue(diagramEdge.Target); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramEdge.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var diagramEdge = thing as DiagramEdge; - if (diagramEdge == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DiagramEdge."); - } + case "bounds": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListBounds && objectListBounds.Any()) + { + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in objectListBounds.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "depictedthing": + writer.WritePropertyName("depictedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "diagramelement": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDiagramElement && objectListDiagramElement.Any()) + { + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in objectListDiagramElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "localstyle": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListLocalStyle && objectListLocalStyle.Any()) + { + writer.WriteStartArray("localStyle"u8); - return this.Serialize(diagramEdge); + foreach(var localStyleItem in objectListLocalStyle.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + writer.WriteEndArray(); + } + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "point": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListPoint && objectListPoint.Any()) + { + writer.WriteStartArray("point"u8); + + foreach(var pointItem in objectListPoint.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pointItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sharedstyle": + writer.WritePropertyName("sharedStyle"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "source": + writer.WritePropertyName("source"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "target": + writer.WritePropertyName("target"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DiagramEdge"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "bounds", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "depictedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "diagramElement", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "localStyle", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "point", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sharedStyle", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "source", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "target", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs index 80b020c56..2f0ef799f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DiagramObjectSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DiagramObject = CDP4Common.DTO.DiagramObject; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +50,689 @@ namespace CDP4JsonSerializer public class DiagramObjectSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "bounds", bounds => new JArray(bounds) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "depictedThing", depictedThing => new JValue(depictedThing) }, - { "diagramElement", diagramElement => new JArray(diagramElement) }, - { "documentation", documentation => new JValue(documentation) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "localStyle", localStyle => new JArray(localStyle) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "resolution", resolution => new JValue(resolution) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "sharedStyle", sharedStyle => new JValue(sharedStyle) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(DiagramObject diagramObject) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("bounds", this.PropertySerializerMap["bounds"](diagramObject.Bounds)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), diagramObject.ClassKind))); - jsonObject.Add("depictedThing", this.PropertySerializerMap["depictedThing"](diagramObject.DepictedThing)); - jsonObject.Add("diagramElement", this.PropertySerializerMap["diagramElement"](diagramObject.DiagramElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("documentation", this.PropertySerializerMap["documentation"](diagramObject.Documentation)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](diagramObject.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](diagramObject.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](diagramObject.Iid)); - jsonObject.Add("localStyle", this.PropertySerializerMap["localStyle"](diagramObject.LocalStyle)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](diagramObject.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](diagramObject.Name)); - jsonObject.Add("resolution", this.PropertySerializerMap["resolution"](diagramObject.Resolution)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](diagramObject.RevisionNumber)); - jsonObject.Add("sharedStyle", this.PropertySerializerMap["sharedStyle"](diagramObject.SharedStyle)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](diagramObject.ThingPreference)); - return jsonObject; + if (thing is not DiagramObject diagramObject) + { + throw new ArgumentException("The thing shall be a DiagramObject", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DiagramObject."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DiagramObject since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramObject for Version 1.1.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramObject.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if (diagramObject.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramObject.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("documentation"u8); + writer.WriteStringValue(diagramObject.Documentation); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramObject.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramObject.Name); + writer.WritePropertyName("resolution"u8); + writer.WriteNumberValue(diagramObject.Resolution); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramObject.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if (diagramObject.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramObject.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramObject for Version 1.2.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramObject.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if (diagramObject.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramObject.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("documentation"u8); + writer.WriteStringValue(diagramObject.Documentation); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramObject.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramObject.Name); + writer.WritePropertyName("resolution"u8); + writer.WriteNumberValue(diagramObject.Resolution); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramObject.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if (diagramObject.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramObject.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramObject.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DiagramObject for Version 1.3.0"); + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramObject.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if (diagramObject.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramObject.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("documentation"u8); + writer.WriteStringValue(diagramObject.Documentation); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramObject.Iid); + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramObject.Name); + writer.WritePropertyName("resolution"u8); + writer.WriteNumberValue(diagramObject.Resolution); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramObject.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if (diagramObject.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramObject.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramObject.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not DiagramObject diagramObject) + { + throw new ArgumentException("The thing shall be a DiagramObject", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in diagramObject.Bounds.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(diagramObject.ClassKind.ToString()); + writer.WritePropertyName("depictedThing"u8); + + if (diagramObject.DepictedThing.HasValue) + { + writer.WriteStringValue(diagramObject.DepictedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in diagramObject.DiagramElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("documentation"u8); + writer.WriteStringValue(diagramObject.Documentation); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in diagramObject.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in diagramObject.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(diagramObject.Iid); + + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in diagramObject.LocalStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(diagramObject.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(diagramObject.Name); + writer.WritePropertyName("resolution"u8); + writer.WriteNumberValue(diagramObject.Resolution); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(diagramObject.RevisionNumber); + writer.WritePropertyName("sharedStyle"u8); + + if (diagramObject.SharedStyle.HasValue) + { + writer.WriteStringValue(diagramObject.SharedStyle.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(diagramObject.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var diagramObject = thing as DiagramObject; - if (diagramObject == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DiagramObject."); - } + case "bounds": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListBounds && objectListBounds.Any()) + { + writer.WriteStartArray("bounds"u8); + + foreach(var boundsItem in objectListBounds.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(boundsItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "depictedthing": + writer.WritePropertyName("depictedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "diagramelement": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDiagramElement && objectListDiagramElement.Any()) + { + writer.WriteStartArray("diagramElement"u8); + + foreach(var diagramElementItem in objectListDiagramElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramElementItem); + } + writer.WriteEndArray(); + } + break; + case "documentation": + writer.WritePropertyName("documentation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(diagramObject); + break; + case "localstyle": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListLocalStyle && objectListLocalStyle.Any()) + { + writer.WriteStartArray("localStyle"u8); + + foreach(var localStyleItem in objectListLocalStyle.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(localStyleItem); + } + writer.WriteEndArray(); + } + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "resolution": + writer.WritePropertyName("resolution"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sharedstyle": + writer.WritePropertyName("sharedStyle"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DiagramObject"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "bounds", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "depictedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "diagramElement", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "documentation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "localStyle", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "resolution", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sharedStyle", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs index b52b01732..5f19382a0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainFileStoreSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DomainFileStore = CDP4Common.DTO.DomainFileStore; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +50,577 @@ namespace CDP4JsonSerializer public class DomainFileStoreSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "file", file => new JArray(file) }, - { "folder", folder => new JArray(folder) }, - { "iid", iid => new JValue(iid) }, - { "isHidden", isHidden => new JValue(isHidden) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(DomainFileStore domainFileStore) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), domainFileStore.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](domainFileStore.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](domainFileStore.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](domainFileStore.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("file", this.PropertySerializerMap["file"](domainFileStore.File.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("folder", this.PropertySerializerMap["folder"](domainFileStore.Folder.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](domainFileStore.Iid)); - jsonObject.Add("isHidden", this.PropertySerializerMap["isHidden"](domainFileStore.IsHidden)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](domainFileStore.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](domainFileStore.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](domainFileStore.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](domainFileStore.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](domainFileStore.ThingPreference)); - return jsonObject; + if (thing is not DomainFileStore domainFileStore) + { + throw new ArgumentException("The thing shall be a DomainFileStore", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DomainFileStore."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DomainFileStore since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DomainFileStore for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DomainFileStore for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DomainFileStore for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainFileStore.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DomainFileStore for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainFileStore.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not DomainFileStore domainFileStore) + { + throw new ArgumentException("The thing shall be a DomainFileStore", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainFileStore.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(domainFileStore.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainFileStore.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainFileStore.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("file"u8); + + foreach(var fileItem in domainFileStore.File.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in domainFileStore.Folder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainFileStore.Iid); + writer.WritePropertyName("isHidden"u8); + writer.WriteBooleanValue(domainFileStore.IsHidden); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainFileStore.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainFileStore.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(domainFileStore.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainFileStore.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainFileStore.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var domainFileStore = thing as DomainFileStore; - if (domainFileStore == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DomainFileStore."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "file": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListFile && objectListFile.Any()) + { + writer.WriteStartArray("file"u8); + + foreach(var fileItem in objectListFile.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileItem); + } + writer.WriteEndArray(); + } + break; + case "folder": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListFolder && objectListFolder.Any()) + { + writer.WriteStartArray("folder"u8); + + foreach(var folderItem in objectListFolder.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(folderItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ishidden": + writer.WritePropertyName("isHidden"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(domainFileStore); + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DomainFileStore"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "file", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "folder", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isHidden", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs index bce3425b1..b74c9795a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseGroupSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DomainOfExpertiseGroup = CDP4Common.DTO.DomainOfExpertiseGroup; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +50,680 @@ namespace CDP4JsonSerializer public class DomainOfExpertiseGroupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "domain", domain => new JArray(domain) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(DomainOfExpertiseGroup domainOfExpertiseGroup) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](domainOfExpertiseGroup.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), domainOfExpertiseGroup.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](domainOfExpertiseGroup.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("domain", this.PropertySerializerMap["domain"](domainOfExpertiseGroup.Domain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](domainOfExpertiseGroup.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](domainOfExpertiseGroup.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](domainOfExpertiseGroup.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](domainOfExpertiseGroup.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](domainOfExpertiseGroup.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](domainOfExpertiseGroup.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](domainOfExpertiseGroup.ThingPreference)); - return jsonObject; + if (thing is not DomainOfExpertiseGroup domainOfExpertiseGroup) + { + throw new ArgumentException("The thing shall be a DomainOfExpertiseGroup", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DomainOfExpertiseGroup."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DomainOfExpertiseGroup since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertiseGroup for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not DomainOfExpertiseGroup domainOfExpertiseGroup) + { + throw new ArgumentException("The thing shall be a DomainOfExpertiseGroup", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertiseGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertiseGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in domainOfExpertiseGroup.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertiseGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertiseGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertiseGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertiseGroup.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertiseGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertiseGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertiseGroup.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var domainOfExpertiseGroup = thing as DomainOfExpertiseGroup; - if (domainOfExpertiseGroup == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DomainOfExpertiseGroup."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "domain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDomain && objectListDomain.Any()) + { + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } - return this.Serialize(domainOfExpertiseGroup); + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DomainOfExpertiseGroup"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "domain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs index ad58a6e15..599285a67 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/DomainOfExpertiseSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using DomainOfExpertise = CDP4Common.DTO.DomainOfExpertise; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +50,680 @@ namespace CDP4JsonSerializer public class DomainOfExpertiseSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(DomainOfExpertise domainOfExpertise) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](domainOfExpertise.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](domainOfExpertise.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), domainOfExpertise.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](domainOfExpertise.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](domainOfExpertise.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](domainOfExpertise.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](domainOfExpertise.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](domainOfExpertise.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](domainOfExpertise.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](domainOfExpertise.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](domainOfExpertise.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](domainOfExpertise.ThingPreference)); - return jsonObject; + if (thing is not DomainOfExpertise domainOfExpertise) + { + throw new ArgumentException("The thing shall be a DomainOfExpertise", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of DomainOfExpertise."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of DomainOfExpertise since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertise.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertise.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertise.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing DomainOfExpertise for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertise.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertise.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not DomainOfExpertise domainOfExpertise) + { + throw new ArgumentException("The thing shall be a DomainOfExpertise", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in domainOfExpertise.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in domainOfExpertise.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(domainOfExpertise.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in domainOfExpertise.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in domainOfExpertise.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in domainOfExpertise.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in domainOfExpertise.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(domainOfExpertise.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(domainOfExpertise.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(domainOfExpertise.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(domainOfExpertise.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(domainOfExpertise.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(domainOfExpertise.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(domainOfExpertise.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var domainOfExpertise = thing as DomainOfExpertise; - if (domainOfExpertise == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a DomainOfExpertise."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } - return this.Serialize(domainOfExpertise); + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the DomainOfExpertise"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs index 50e97bc99..f59e87469 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementDefinitionSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ElementDefinition = CDP4Common.DTO.ElementDefinition; /// /// The purpose of the class is to provide a specific serializer @@ -45,90 +50,982 @@ namespace CDP4JsonSerializer public class ElementDefinitionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "containedElement", containedElement => new JArray(containedElement) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "organizationalParticipant", organizationalParticipant => new JArray(organizationalParticipant) }, - { "owner", owner => new JValue(owner) }, - { "parameter", parameter => new JArray(parameter) }, - { "parameterGroup", parameterGroup => new JArray(parameterGroup) }, - { "referencedElement", referencedElement => new JArray(referencedElement) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ElementDefinition elementDefinition) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](elementDefinition.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](elementDefinition.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), elementDefinition.ClassKind))); - jsonObject.Add("containedElement", this.PropertySerializerMap["containedElement"](elementDefinition.ContainedElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](elementDefinition.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](elementDefinition.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](elementDefinition.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](elementDefinition.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](elementDefinition.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](elementDefinition.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](elementDefinition.Name)); - jsonObject.Add("organizationalParticipant", this.PropertySerializerMap["organizationalParticipant"](elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](elementDefinition.Owner)); - jsonObject.Add("parameter", this.PropertySerializerMap["parameter"](elementDefinition.Parameter.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("parameterGroup", this.PropertySerializerMap["parameterGroup"](elementDefinition.ParameterGroup.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("referencedElement", this.PropertySerializerMap["referencedElement"](elementDefinition.ReferencedElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](elementDefinition.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](elementDefinition.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](elementDefinition.ThingPreference)); - return jsonObject; + if (thing is not ElementDefinition elementDefinition) + { + throw new ArgumentException("The thing shall be a ElementDefinition", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ElementDefinition."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ElementDefinition since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); + + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("parameterGroup"u8); + + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referencedElement"u8); + + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); + + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("parameterGroup"u8); + + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referencedElement"u8); + + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); + + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("parameterGroup"u8); + + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referencedElement"u8); + + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementDefinition.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ElementDefinition for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + writer.WriteStartArray("containedElement"u8); + + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("parameterGroup"u8); + + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referencedElement"u8); + + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementDefinition.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ElementDefinition elementDefinition) + { + throw new ArgumentException("The thing shall be a ElementDefinition", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementDefinition.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementDefinition.ClassKind.ToString()); + + writer.WriteStartArray("containedElement"u8); + + foreach(var containedElementItem in elementDefinition.ContainedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementDefinition.Name); + + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in elementDefinition.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementDefinition.Owner); + + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in elementDefinition.Parameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("parameterGroup"u8); + + foreach(var parameterGroupItem in elementDefinition.ParameterGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("referencedElement"u8); + + foreach(var referencedElementItem in elementDefinition.ReferencedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementDefinition.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var elementDefinition = thing as ElementDefinition; - if (elementDefinition == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ElementDefinition."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "containedelement": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListContainedElement && objectListContainedElement.Any()) + { + writer.WriteStartArray("containedElement"u8); + + foreach(var containedElementItem in objectListContainedElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(containedElementItem); + } + writer.WriteEndArray(); + } + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } - return this.Serialize(elementDefinition); + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "organizationalparticipant": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListOrganizationalParticipant && objectListOrganizationalParticipant.Any()) + { + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in objectListOrganizationalParticipant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + writer.WriteEndArray(); + } + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parameter": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListParameter && objectListParameter.Any()) + { + writer.WriteStartArray("parameter"u8); + + foreach(var parameterItem in objectListParameter.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterItem); + } + writer.WriteEndArray(); + } + break; + case "parametergroup": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListParameterGroup && objectListParameterGroup.Any()) + { + writer.WriteStartArray("parameterGroup"u8); + + foreach(var parameterGroupItem in objectListParameterGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterGroupItem); + } + writer.WriteEndArray(); + } + break; + case "referencedelement": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListReferencedElement && objectListReferencedElement.Any()) + { + writer.WriteStartArray("referencedElement"u8); + + foreach(var referencedElementItem in objectListReferencedElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedElementItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ElementDefinition"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containedElement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "organizationalParticipant", new []{ "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameter", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterGroup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedElement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs index 37d4d6f01..7051b9913 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ElementUsageSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ElementUsage = CDP4Common.DTO.ElementUsage; /// /// The purpose of the class is to provide a specific serializer @@ -45,88 +50,856 @@ namespace CDP4JsonSerializer public class ElementUsageSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "elementDefinition", elementDefinition => new JValue(elementDefinition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "excludeOption", excludeOption => new JArray(excludeOption) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "interfaceEnd", interfaceEnd => new JValue(interfaceEnd.ToString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterOverride", parameterOverride => new JArray(parameterOverride) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ElementUsage elementUsage) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](elementUsage.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](elementUsage.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), elementUsage.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](elementUsage.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("elementDefinition", this.PropertySerializerMap["elementDefinition"](elementUsage.ElementDefinition)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](elementUsage.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](elementUsage.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludeOption", this.PropertySerializerMap["excludeOption"](elementUsage.ExcludeOption.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](elementUsage.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](elementUsage.Iid)); - jsonObject.Add("interfaceEnd", this.PropertySerializerMap["interfaceEnd"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.InterfaceEndKind), elementUsage.InterfaceEnd))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](elementUsage.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](elementUsage.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](elementUsage.Owner)); - jsonObject.Add("parameterOverride", this.PropertySerializerMap["parameterOverride"](elementUsage.ParameterOverride.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](elementUsage.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](elementUsage.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](elementUsage.ThingPreference)); - return jsonObject; + if (thing is not ElementUsage elementUsage) + { + throw new ArgumentException("The thing shall be a ElementUsage", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ElementUsage."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ElementUsage since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementUsage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementUsage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementUsage.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ElementUsage for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementUsage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementUsage.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ElementUsage elementUsage) + { + throw new ArgumentException("The thing shall be a ElementUsage", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in elementUsage.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in elementUsage.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(elementUsage.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in elementUsage.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("elementDefinition"u8); + writer.WriteStringValue(elementUsage.ElementDefinition); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in elementUsage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in elementUsage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludeOption"u8); + + foreach(var excludeOptionItem in elementUsage.ExcludeOption.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in elementUsage.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(elementUsage.Iid); + writer.WritePropertyName("interfaceEnd"u8); + writer.WriteStringValue(elementUsage.InterfaceEnd.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(elementUsage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(elementUsage.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(elementUsage.Owner); + + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in elementUsage.ParameterOverride.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(elementUsage.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(elementUsage.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(elementUsage.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var elementUsage = thing as ElementUsage; - if (elementUsage == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ElementUsage."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "elementdefinition": + writer.WritePropertyName("elementDefinition"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "excludeoption": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludeOption && objectListExcludeOption.Any()) + { + writer.WriteStartArray("excludeOption"u8); - return this.Serialize(elementUsage); + foreach(var excludeOptionItem in objectListExcludeOption.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludeOptionItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "interfaceend": + writer.WritePropertyName("interfaceEnd"u8); + + if(value != null) + { + writer.WriteStringValue(((InterfaceEndKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parameteroverride": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListParameterOverride && objectListParameterOverride.Any()) + { + writer.WriteStartArray("parameterOverride"u8); + + foreach(var parameterOverrideItem in objectListParameterOverride.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterOverrideItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ElementUsage"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "elementDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludeOption", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "interfaceEnd", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterOverride", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs index b0f73d2e7..f246bea4d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EmailAddressSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EmailAddress = CDP4Common.DTO.EmailAddress; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +50,401 @@ namespace CDP4JsonSerializer public class EmailAddressSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(value) }, - { "vcardType", vcardType => new JValue(vcardType.ToString()) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(EmailAddress emailAddress) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), emailAddress.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](emailAddress.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](emailAddress.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](emailAddress.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](emailAddress.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](emailAddress.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](emailAddress.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](emailAddress.Value)); - jsonObject.Add("vcardType", this.PropertySerializerMap["vcardType"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.VcardEmailAddressKind), emailAddress.VcardType))); - return jsonObject; + if (thing is not EmailAddress emailAddress) + { + throw new ArgumentException("The thing shall be a EmailAddress", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of EmailAddress."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EmailAddress since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing EmailAddress for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EmailAddress for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(emailAddress.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EmailAddress for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(emailAddress.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(emailAddress.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EmailAddress for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(emailAddress.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(emailAddress.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not EmailAddress emailAddress) + { + throw new ArgumentException("The thing shall be a EmailAddress", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(emailAddress.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in emailAddress.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in emailAddress.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(emailAddress.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(emailAddress.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(emailAddress.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(emailAddress.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(emailAddress.Value); + writer.WritePropertyName("vcardType"u8); + writer.WriteStringValue(emailAddress.VcardType.ToString()); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var emailAddress = thing as EmailAddress; - if (emailAddress == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a EmailAddress."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(emailAddress); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + writer.WritePropertyName("value"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "vcardtype": + writer.WritePropertyName("vcardType"u8); + + if(value != null) + { + writer.WriteStringValue(((VcardEmailAddressKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EmailAddress"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "vcardType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs index d2b25d1cd..f11e6531a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataDiscussionItemSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EngineeringModelDataDiscussionItem = CDP4Common.DTO.EngineeringModelDataDiscussionItem; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +50,490 @@ namespace CDP4JsonSerializer public class EngineeringModelDataDiscussionItemSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "replyTo", replyTo => new JValue(replyTo) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(EngineeringModelDataDiscussionItem engineeringModelDataDiscussionItem) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](engineeringModelDataDiscussionItem.Author)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), engineeringModelDataDiscussionItem.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](engineeringModelDataDiscussionItem.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](engineeringModelDataDiscussionItem.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](engineeringModelDataDiscussionItem.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](engineeringModelDataDiscussionItem.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](engineeringModelDataDiscussionItem.ModifiedOn)); - jsonObject.Add("replyTo", this.PropertySerializerMap["replyTo"](engineeringModelDataDiscussionItem.ReplyTo)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](engineeringModelDataDiscussionItem.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](engineeringModelDataDiscussionItem.ThingPreference)); - return jsonObject; + if (thing is not EngineeringModelDataDiscussionItem engineeringModelDataDiscussionItem) + { + throw new ArgumentException("The thing shall be a EngineeringModelDataDiscussionItem", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of EngineeringModelDataDiscussionItem."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelDataDiscussionItem since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataDiscussionItem for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if (engineeringModelDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataDiscussionItem.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataDiscussionItem for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if (engineeringModelDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataDiscussionItem for Version 1.3.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if (engineeringModelDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not EngineeringModelDataDiscussionItem engineeringModelDataDiscussionItem) + { + throw new ArgumentException("The thing shall be a EngineeringModelDataDiscussionItem", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if (engineeringModelDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(engineeringModelDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataDiscussionItem.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var engineeringModelDataDiscussionItem = thing as EngineeringModelDataDiscussionItem; - if (engineeringModelDataDiscussionItem == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a EngineeringModelDataDiscussionItem."); - } + case "author": + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(engineeringModelDataDiscussionItem); + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "replyto": + writer.WritePropertyName("replyTo"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EngineeringModelDataDiscussionItem"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "replyTo", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs index 229835157..82da9c1a9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelDataNoteSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EngineeringModelDataNote = CDP4Common.DTO.EngineeringModelDataNote; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +50,599 @@ namespace CDP4JsonSerializer public class EngineeringModelDataNoteSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(EngineeringModelDataNote engineeringModelDataNote) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](engineeringModelDataNote.Author)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), engineeringModelDataNote.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](engineeringModelDataNote.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](engineeringModelDataNote.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](engineeringModelDataNote.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](engineeringModelDataNote.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](engineeringModelDataNote.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](engineeringModelDataNote.ModifiedOn)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](engineeringModelDataNote.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](engineeringModelDataNote.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](engineeringModelDataNote.ThingPreference)); - return jsonObject; + if (thing is not EngineeringModelDataNote engineeringModelDataNote) + { + throw new ArgumentException("The thing shall be a EngineeringModelDataNote", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of EngineeringModelDataNote."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelDataNote since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataNote for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataNote.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataNote for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataNote.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataNote.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelDataNote for Version 1.3.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataNote.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataNote.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not EngineeringModelDataNote engineeringModelDataNote) + { + throw new ArgumentException("The thing shall be a EngineeringModelDataNote", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(engineeringModelDataNote.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelDataNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(engineeringModelDataNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(engineeringModelDataNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in engineeringModelDataNote.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelDataNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelDataNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelDataNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(engineeringModelDataNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelDataNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (engineeringModelDataNote.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(engineeringModelDataNote.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in engineeringModelDataNote.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelDataNote.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelDataNote.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var engineeringModelDataNote = thing as EngineeringModelDataNote; - if (engineeringModelDataNote == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a EngineeringModelDataNote."); - } + case "author": + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) + { + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(engineeringModelDataNote); + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) + { + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EngineeringModelDataNote"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs index 37cf96788..51c02e39a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EngineeringModel = CDP4Common.DTO.EngineeringModel; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +50,757 @@ namespace CDP4JsonSerializer public class EngineeringModelSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "book", book => new JArray(((IEnumerable)book).Cast().Select(x => x.ToJsonObject())) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "commonFileStore", commonFileStore => new JArray(commonFileStore) }, - { "engineeringModelSetup", engineeringModelSetup => new JValue(engineeringModelSetup) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "genericNote", genericNote => new JArray(genericNote) }, - { "iid", iid => new JValue(iid) }, - { "iteration", iteration => new JArray(iteration) }, - { "lastModifiedOn", lastModifiedOn => new JValue(((DateTime)lastModifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "logEntry", logEntry => new JArray(logEntry) }, - { "modellingAnnotation", modellingAnnotation => new JArray(modellingAnnotation) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(EngineeringModel engineeringModel) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("book", this.PropertySerializerMap["book"](engineeringModel.Book.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), engineeringModel.ClassKind))); - jsonObject.Add("commonFileStore", this.PropertySerializerMap["commonFileStore"](engineeringModel.CommonFileStore)); - jsonObject.Add("engineeringModelSetup", this.PropertySerializerMap["engineeringModelSetup"](engineeringModel.EngineeringModelSetup)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](engineeringModel.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](engineeringModel.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("genericNote", this.PropertySerializerMap["genericNote"](engineeringModel.GenericNote.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](engineeringModel.Iid)); - jsonObject.Add("iteration", this.PropertySerializerMap["iteration"](engineeringModel.Iteration.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("lastModifiedOn", this.PropertySerializerMap["lastModifiedOn"](engineeringModel.LastModifiedOn)); - jsonObject.Add("logEntry", this.PropertySerializerMap["logEntry"](engineeringModel.LogEntry.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("modellingAnnotation", this.PropertySerializerMap["modellingAnnotation"](engineeringModel.ModellingAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](engineeringModel.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](engineeringModel.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](engineeringModel.ThingPreference)); - return jsonObject; + if (thing is not EngineeringModel engineeringModel) + { + throw new ArgumentException("The thing shall be a EngineeringModel", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of EngineeringModel."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModel since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.1.0"); + writer.WriteStartArray("book"u8); + + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(bookItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("genericNote"u8); + + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("modellingAnnotation"u8); + + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.2.0"); + writer.WriteStartArray("book"u8); + + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(bookItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("genericNote"u8); + + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("modellingAnnotation"u8); + + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModel.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModel for Version 1.3.0"); + writer.WriteStartArray("book"u8); + + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(bookItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("genericNote"u8); + + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("modellingAnnotation"u8); + + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModel.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not EngineeringModel engineeringModel) + { + throw new ArgumentException("The thing shall be a EngineeringModel", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("book"u8); + + foreach(var bookItem in engineeringModel.Book.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(bookItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModel.ClassKind.ToString()); + + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in engineeringModel.CommonFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelSetup"u8); + writer.WriteStringValue(engineeringModel.EngineeringModelSetup); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModel.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModel.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("genericNote"u8); + + foreach(var genericNoteItem in engineeringModel.GenericNote.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModel.Iid); + + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in engineeringModel.Iteration.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(engineeringModel.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in engineeringModel.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("modellingAnnotation"u8); + + foreach(var modellingAnnotationItem in engineeringModel.ModellingAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModel.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModel.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModel.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var engineeringModel = thing as EngineeringModel; - if (engineeringModel == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a EngineeringModel."); - } + case "book": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListBook && objectListBook.Any()) + { + writer.WriteStartArray("book"u8); + + foreach(var bookItem in objectListBook.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(bookItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "commonfilestore": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCommonFileStore && objectListCommonFileStore.Any()) + { + writer.WriteStartArray("commonFileStore"u8); + + foreach(var commonFileStoreItem in objectListCommonFileStore.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(commonFileStoreItem); + } + writer.WriteEndArray(); + } + break; + case "engineeringmodelsetup": + writer.WritePropertyName("engineeringModelSetup"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "genericnote": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListGenericNote && objectListGenericNote.Any()) + { + writer.WriteStartArray("genericNote"u8); - return this.Serialize(engineeringModel); + foreach(var genericNoteItem in objectListGenericNote.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(genericNoteItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iteration": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListIteration && objectListIteration.Any()) + { + writer.WriteStartArray("iteration"u8); + + foreach(var iterationItem in objectListIteration.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationItem); + } + writer.WriteEndArray(); + } + break; + case "lastmodifiedon": + writer.WritePropertyName("lastModifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "logentry": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListLogEntry && objectListLogEntry.Any()) + { + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in objectListLogEntry.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + writer.WriteEndArray(); + } + break; + case "modellingannotation": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListModellingAnnotation && objectListModellingAnnotation.Any()) + { + writer.WriteStartArray("modellingAnnotation"u8); + + foreach(var modellingAnnotationItem in objectListModellingAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modellingAnnotationItem); + } + writer.WriteEndArray(); + } + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EngineeringModel"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "book", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "commonFileStore", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "engineeringModelSetup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "genericNote", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iteration", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "lastModifiedOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "logEntry", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modellingAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs index b6c79aed6..b2744c810 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EngineeringModelSetupSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EngineeringModelSetup = CDP4Common.DTO.EngineeringModelSetup; /// /// The purpose of the class is to provide a specific serializer @@ -45,96 +50,1081 @@ namespace CDP4JsonSerializer public class EngineeringModelSetupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "activeDomain", activeDomain => new JArray(activeDomain) }, - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultOrganizationalParticipant", defaultOrganizationalParticipant => new JValue(defaultOrganizationalParticipant) }, - { "definition", definition => new JArray(definition) }, - { "engineeringModelIid", engineeringModelIid => new JValue(engineeringModelIid) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "iterationSetup", iterationSetup => new JArray(iterationSetup) }, - { "kind", kind => new JValue(kind.ToString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "organizationalParticipant", organizationalParticipant => new JArray(organizationalParticipant) }, - { "participant", participant => new JArray(participant) }, - { "requiredRdl", requiredRdl => new JArray(requiredRdl) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceEngineeringModelSetupIid", sourceEngineeringModelSetupIid => new JValue(sourceEngineeringModelSetupIid) }, - { "studyPhase", studyPhase => new JValue(studyPhase.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(EngineeringModelSetup engineeringModelSetup) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("activeDomain", this.PropertySerializerMap["activeDomain"](engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](engineeringModelSetup.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), engineeringModelSetup.ClassKind))); - jsonObject.Add("defaultOrganizationalParticipant", this.PropertySerializerMap["defaultOrganizationalParticipant"](engineeringModelSetup.DefaultOrganizationalParticipant)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](engineeringModelSetup.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("engineeringModelIid", this.PropertySerializerMap["engineeringModelIid"](engineeringModelSetup.EngineeringModelIid)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](engineeringModelSetup.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](engineeringModelSetup.Iid)); - jsonObject.Add("iterationSetup", this.PropertySerializerMap["iterationSetup"](engineeringModelSetup.IterationSetup.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("kind", this.PropertySerializerMap["kind"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.EngineeringModelKind), engineeringModelSetup.Kind))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](engineeringModelSetup.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](engineeringModelSetup.Name)); - jsonObject.Add("organizationalParticipant", this.PropertySerializerMap["organizationalParticipant"](engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("participant", this.PropertySerializerMap["participant"](engineeringModelSetup.Participant.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("requiredRdl", this.PropertySerializerMap["requiredRdl"](engineeringModelSetup.RequiredRdl)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](engineeringModelSetup.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](engineeringModelSetup.ShortName)); - jsonObject.Add("sourceEngineeringModelSetupIid", this.PropertySerializerMap["sourceEngineeringModelSetupIid"](engineeringModelSetup.SourceEngineeringModelSetupIid)); - jsonObject.Add("studyPhase", this.PropertySerializerMap["studyPhase"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.StudyPhaseKind), engineeringModelSetup.StudyPhase))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](engineeringModelSetup.ThingPreference)); - return jsonObject; + if (thing is not EngineeringModelSetup engineeringModelSetup) + { + throw new ArgumentException("The thing shall be a EngineeringModelSetup", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of EngineeringModelSetup."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EngineeringModelSetup since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.0.0"); + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("participant"u8); + + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if (engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.1.0"); + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("participant"u8); + + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if (engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.2.0"); + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WritePropertyName("defaultOrganizationalParticipant"u8); + + if (engineeringModelSetup.DefaultOrganizationalParticipant.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.DefaultOrganizationalParticipant.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("participant"u8); + + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if (engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelSetup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EngineeringModelSetup for Version 1.3.0"); + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WritePropertyName("defaultOrganizationalParticipant"u8); + + if (engineeringModelSetup.DefaultOrganizationalParticipant.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.DefaultOrganizationalParticipant.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("participant"u8); + + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if (engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelSetup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not EngineeringModelSetup engineeringModelSetup) + { + throw new ArgumentException("The thing shall be a EngineeringModelSetup", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in engineeringModelSetup.ActiveDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in engineeringModelSetup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(engineeringModelSetup.ClassKind.ToString()); + writer.WritePropertyName("defaultOrganizationalParticipant"u8); + + if (engineeringModelSetup.DefaultOrganizationalParticipant.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.DefaultOrganizationalParticipant.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in engineeringModelSetup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("engineeringModelIid"u8); + writer.WriteStringValue(engineeringModelSetup.EngineeringModelIid); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in engineeringModelSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in engineeringModelSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in engineeringModelSetup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(engineeringModelSetup.Iid); + + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in engineeringModelSetup.IterationSetup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(engineeringModelSetup.Kind.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(engineeringModelSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(engineeringModelSetup.Name); + + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in engineeringModelSetup.OrganizationalParticipant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("participant"u8); + + foreach(var participantItem in engineeringModelSetup.Participant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in engineeringModelSetup.RequiredRdl.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(engineeringModelSetup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(engineeringModelSetup.ShortName); + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if (engineeringModelSetup.SourceEngineeringModelSetupIid.HasValue) + { + writer.WriteStringValue(engineeringModelSetup.SourceEngineeringModelSetupIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("studyPhase"u8); + writer.WriteStringValue(engineeringModelSetup.StudyPhase.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(engineeringModelSetup.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var engineeringModelSetup = thing as EngineeringModelSetup; - if (engineeringModelSetup == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a EngineeringModelSetup."); - } + case "activedomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListActiveDomain && objectListActiveDomain.Any()) + { + writer.WriteStartArray("activeDomain"u8); + + foreach(var activeDomainItem in objectListActiveDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(activeDomainItem); + } + writer.WriteEndArray(); + } + break; + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultorganizationalparticipant": + writer.WritePropertyName("defaultOrganizationalParticipant"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "engineeringmodeliid": + writer.WritePropertyName("engineeringModelIid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); - return this.Serialize(engineeringModelSetup); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iterationsetup": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListIterationSetup && objectListIterationSetup.Any()) + { + writer.WriteStartArray("iterationSetup"u8); + + foreach(var iterationSetupItem in objectListIterationSetup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(iterationSetupItem); + } + writer.WriteEndArray(); + } + break; + case "kind": + writer.WritePropertyName("kind"u8); + + if(value != null) + { + writer.WriteStringValue(((EngineeringModelKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "organizationalparticipant": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListOrganizationalParticipant && objectListOrganizationalParticipant.Any()) + { + writer.WriteStartArray("organizationalParticipant"u8); + + foreach(var organizationalParticipantItem in objectListOrganizationalParticipant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationalParticipantItem); + } + writer.WriteEndArray(); + } + break; + case "participant": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListParticipant && objectListParticipant.Any()) + { + writer.WriteStartArray("participant"u8); + + foreach(var participantItem in objectListParticipant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantItem); + } + writer.WriteEndArray(); + } + break; + case "requiredrdl": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRequiredRdl && objectListRequiredRdl.Any()) + { + writer.WriteStartArray("requiredRdl"u8); + + foreach(var requiredRdlItem in objectListRequiredRdl.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requiredRdlItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceengineeringmodelsetupiid": + writer.WritePropertyName("sourceEngineeringModelSetupIid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "studyphase": + writer.WritePropertyName("studyPhase"u8); + + if(value != null) + { + writer.WriteStringValue(((StudyPhaseKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EngineeringModelSetup"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "activeDomain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultOrganizationalParticipant", new []{ "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "engineeringModelIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iterationSetup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "kind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "organizationalParticipant", new []{ "1.2.0", "1.3.0" }}, + { "participant", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "requiredRdl", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceEngineeringModelSetupIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "studyPhase", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs index 3dbbfa83f..baa824208 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationParameterTypeSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EnumerationParameterType = CDP4Common.DTO.EnumerationParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,86 +50,792 @@ namespace CDP4JsonSerializer public class EnumerationParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "allowMultiSelect", allowMultiSelect => new JValue(allowMultiSelect) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueDefinition", valueDefinition => new JArray(((IEnumerable)valueDefinition).Cast().Select(x => x.ToJsonObject())) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(EnumerationParameterType enumerationParameterType) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](enumerationParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("allowMultiSelect", this.PropertySerializerMap["allowMultiSelect"](enumerationParameterType.AllowMultiSelect)); - jsonObject.Add("category", this.PropertySerializerMap["category"](enumerationParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), enumerationParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](enumerationParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](enumerationParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](enumerationParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](enumerationParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](enumerationParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](enumerationParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](enumerationParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](enumerationParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](enumerationParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](enumerationParameterType.ThingPreference)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](enumerationParameterType.ValueDefinition.OrderBy(x => x, this.orderedItemComparer))); - return jsonObject; + if (thing is not EnumerationParameterType enumerationParameterType) + { + throw new ArgumentException("The thing shall be a EnumerationParameterType", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of EnumerationParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EnumerationParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationParameterType.ThingPreference); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationParameterType for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationParameterType.ThingPreference); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not EnumerationParameterType enumerationParameterType) + { + throw new ArgumentException("The thing shall be a EnumerationParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("allowMultiSelect"u8); + writer.WriteBooleanValue(enumerationParameterType.AllowMultiSelect); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in enumerationParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationParameterType.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(enumerationParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(enumerationParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationParameterType.ThingPreference); + + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in enumerationParameterType.ValueDefinition.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var enumerationParameterType = thing as EnumerationParameterType; - if (enumerationParameterType == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a EnumerationParameterType."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "allowmultiselect": + writer.WritePropertyName("allowMultiSelect"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); - return this.Serialize(enumerationParameterType); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) + { + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(valueDefinitionItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EnumerationParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "allowMultiSelect", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs index 7644a6b0a..d378b0aae 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/EnumerationValueDefinitionSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using EnumerationValueDefinition = CDP4Common.DTO.EnumerationValueDefinition; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +50,592 @@ namespace CDP4JsonSerializer public class EnumerationValueDefinitionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(EnumerationValueDefinition enumerationValueDefinition) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](enumerationValueDefinition.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), enumerationValueDefinition.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](enumerationValueDefinition.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](enumerationValueDefinition.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](enumerationValueDefinition.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](enumerationValueDefinition.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](enumerationValueDefinition.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](enumerationValueDefinition.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](enumerationValueDefinition.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](enumerationValueDefinition.ThingPreference)); - return jsonObject; + if (thing is not EnumerationValueDefinition enumerationValueDefinition) + { + throw new ArgumentException("The thing shall be a EnumerationValueDefinition", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of EnumerationValueDefinition."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of EnumerationValueDefinition since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationValueDefinition.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationValueDefinition.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationValueDefinition.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationValueDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationValueDefinition.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing EnumerationValueDefinition for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationValueDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationValueDefinition.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not EnumerationValueDefinition enumerationValueDefinition) + { + throw new ArgumentException("The thing shall be a EnumerationValueDefinition", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in enumerationValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(enumerationValueDefinition.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in enumerationValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in enumerationValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in enumerationValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in enumerationValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(enumerationValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(enumerationValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(enumerationValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(enumerationValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(enumerationValueDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(enumerationValueDefinition.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var enumerationValueDefinition = thing as EnumerationValueDefinition; - if (enumerationValueDefinition == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a EnumerationValueDefinition."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); - return this.Serialize(enumerationValueDefinition); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the EnumerationValueDefinition"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs index d02617125..3bb4ce09a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExclusiveOrExpressionSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ExclusiveOrExpression = CDP4Common.DTO.ExclusiveOrExpression; /// /// The purpose of the class is to provide a specific serializer @@ -45,68 +50,417 @@ namespace CDP4JsonSerializer public class ExclusiveOrExpressionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "term", term => new JArray(term) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ExclusiveOrExpression exclusiveOrExpression) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), exclusiveOrExpression.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](exclusiveOrExpression.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](exclusiveOrExpression.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](exclusiveOrExpression.RevisionNumber)); - jsonObject.Add("term", this.PropertySerializerMap["term"](exclusiveOrExpression.Term.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](exclusiveOrExpression.ThingPreference)); - return jsonObject; + if (thing is not ExclusiveOrExpression exclusiveOrExpression) + { + throw new ArgumentException("The thing shall be a ExclusiveOrExpression", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ExclusiveOrExpression."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ExclusiveOrExpression since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ExclusiveOrExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ExclusiveOrExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ExclusiveOrExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(exclusiveOrExpression.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ExclusiveOrExpression for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(exclusiveOrExpression.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ExclusiveOrExpression exclusiveOrExpression) + { + throw new ArgumentException("The thing shall be a ExclusiveOrExpression", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(exclusiveOrExpression.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in exclusiveOrExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in exclusiveOrExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(exclusiveOrExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(exclusiveOrExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(exclusiveOrExpression.RevisionNumber); + + writer.WriteStartArray("term"u8); + + foreach(var termItem in exclusiveOrExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(exclusiveOrExpression.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var exclusiveOrExpression = thing as ExclusiveOrExpression; - if (exclusiveOrExpression == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ExclusiveOrExpression."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(exclusiveOrExpression); + break; + case "term": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListTerm && objectListTerm.Any()) + { + writer.WriteStartArray("term"u8); + + foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + writer.WriteEndArray(); + } + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ExclusiveOrExpression"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "term", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs index 2ef79b40d..c267b5b5e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ExternalIdentifierMapSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ExternalIdentifierMap = CDP4Common.DTO.ExternalIdentifierMap; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +50,606 @@ namespace CDP4JsonSerializer public class ExternalIdentifierMapSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "correspondence", correspondence => new JArray(correspondence) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "externalFormat", externalFormat => new JValue(externalFormat) }, - { "externalModelName", externalModelName => new JValue(externalModelName) }, - { "externalToolName", externalToolName => new JValue(externalToolName) }, - { "externalToolVersion", externalToolVersion => new JValue(externalToolVersion) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ExternalIdentifierMap externalIdentifierMap) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), externalIdentifierMap.ClassKind))); - jsonObject.Add("correspondence", this.PropertySerializerMap["correspondence"](externalIdentifierMap.Correspondence.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("externalFormat", this.PropertySerializerMap["externalFormat"](externalIdentifierMap.ExternalFormat)); - jsonObject.Add("externalModelName", this.PropertySerializerMap["externalModelName"](externalIdentifierMap.ExternalModelName)); - jsonObject.Add("externalToolName", this.PropertySerializerMap["externalToolName"](externalIdentifierMap.ExternalToolName)); - jsonObject.Add("externalToolVersion", this.PropertySerializerMap["externalToolVersion"](externalIdentifierMap.ExternalToolVersion)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](externalIdentifierMap.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](externalIdentifierMap.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](externalIdentifierMap.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](externalIdentifierMap.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](externalIdentifierMap.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](externalIdentifierMap.ThingPreference)); - return jsonObject; + if (thing is not ExternalIdentifierMap externalIdentifierMap) + { + throw new ArgumentException("The thing shall be a ExternalIdentifierMap", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ExternalIdentifierMap."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ExternalIdentifierMap since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalFormat"u8); + + if (externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalFormat"u8); + + if (externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(externalIdentifierMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalFormat"u8); + + if (externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(externalIdentifierMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(externalIdentifierMap.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ExternalIdentifierMap for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalFormat"u8); + + if (externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(externalIdentifierMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(externalIdentifierMap.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ExternalIdentifierMap externalIdentifierMap) + { + throw new ArgumentException("The thing shall be a ExternalIdentifierMap", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(externalIdentifierMap.ClassKind.ToString()); + + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in externalIdentifierMap.Correspondence.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in externalIdentifierMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in externalIdentifierMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalFormat"u8); + + if (externalIdentifierMap.ExternalFormat.HasValue) + { + writer.WriteStringValue(externalIdentifierMap.ExternalFormat.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("externalModelName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalModelName); + writer.WritePropertyName("externalToolName"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolName); + writer.WritePropertyName("externalToolVersion"u8); + writer.WriteStringValue(externalIdentifierMap.ExternalToolVersion); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(externalIdentifierMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(externalIdentifierMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(externalIdentifierMap.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(externalIdentifierMap.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(externalIdentifierMap.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(externalIdentifierMap.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var externalIdentifierMap = thing as ExternalIdentifierMap; - if (externalIdentifierMap == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ExternalIdentifierMap."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "correspondence": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCorrespondence && objectListCorrespondence.Any()) + { + writer.WriteStartArray("correspondence"u8); + + foreach(var correspondenceItem in objectListCorrespondence.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(correspondenceItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "externalformat": + writer.WritePropertyName("externalFormat"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "externalmodelname": + writer.WritePropertyName("externalModelName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "externaltoolname": + writer.WritePropertyName("externalToolName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "externaltoolversion": + writer.WritePropertyName("externalToolVersion"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(externalIdentifierMap); + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ExternalIdentifierMap"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "correspondence", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "externalFormat", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "externalModelName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "externalToolName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "externalToolVersion", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs index d483fea95..d923a98bf 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileRevisionSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using FileRevision = CDP4Common.DTO.FileRevision; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +50,582 @@ namespace CDP4JsonSerializer public class FileRevisionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "containingFolder", containingFolder => new JValue(containingFolder) }, - { "contentHash", contentHash => new JValue(contentHash) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "creator", creator => new JValue(creator) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fileType", fileType => new JArray(((IEnumerable)fileType).Cast().Select(x => x.ToJsonObject())) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(FileRevision fileRevision) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), fileRevision.ClassKind))); - jsonObject.Add("containingFolder", this.PropertySerializerMap["containingFolder"](fileRevision.ContainingFolder)); - jsonObject.Add("contentHash", this.PropertySerializerMap["contentHash"](fileRevision.ContentHash)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](fileRevision.CreatedOn)); - jsonObject.Add("creator", this.PropertySerializerMap["creator"](fileRevision.Creator)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](fileRevision.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](fileRevision.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fileType", this.PropertySerializerMap["fileType"](fileRevision.FileType.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](fileRevision.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](fileRevision.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](fileRevision.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](fileRevision.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](fileRevision.ThingPreference)); - return jsonObject; + if (thing is not FileRevision fileRevision) + { + throw new ArgumentException("The thing shall be a FileRevision", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of FileRevision."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of FileRevision since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing FileRevision for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if (fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing FileRevision for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if (fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileRevision.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing FileRevision for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if (fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileRevision.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileRevision.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing FileRevision for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if (fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileRevision.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileRevision.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not FileRevision fileRevision) + { + throw new ArgumentException("The thing shall be a FileRevision", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileRevision.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if (fileRevision.ContainingFolder.HasValue) + { + writer.WriteStringValue(fileRevision.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("contentHash"u8); + writer.WriteStringValue(fileRevision.ContentHash); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(fileRevision.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(fileRevision.Creator); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileRevision.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileRevision.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in fileRevision.FileType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileRevision.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileRevision.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileRevision.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileRevision.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileRevision.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var fileRevision = thing as FileRevision; - if (fileRevision == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a FileRevision."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "containingfolder": + writer.WritePropertyName("containingFolder"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "contenthash": + writer.WritePropertyName("contentHash"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "creator": + writer.WritePropertyName("creator"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "filetype": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListFileType && objectListFileType.Any()) + { + writer.WriteStartArray("fileType"u8); - return this.Serialize(fileRevision); + foreach(var fileTypeItem in objectListFileType.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(fileTypeItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the FileRevision"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containingFolder", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "contentHash", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "creator", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fileType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs index 79e798a73..bdcdec3eb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using File = CDP4Common.DTO.File; /// /// The purpose of the class is to provide a specific serializer @@ -45,74 +50,573 @@ namespace CDP4JsonSerializer public class FileSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fileRevision", fileRevision => new JArray(fileRevision) }, - { "iid", iid => new JValue(iid) }, - { "lockedBy", lockedBy => new JValue(lockedBy) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(File file) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](file.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), file.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](file.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](file.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fileRevision", this.PropertySerializerMap["fileRevision"](file.FileRevision.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](file.Iid)); - jsonObject.Add("lockedBy", this.PropertySerializerMap["lockedBy"](file.LockedBy)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](file.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](file.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](file.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](file.ThingPreference)); - return jsonObject; + if (thing is not File file) + { + throw new ArgumentException("The thing shall be a File", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of File."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of File since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing File for Version 1.0.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(file.ClassKind.ToString()); + writer.WriteStartArray("fileRevision"u8); + + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(file.Iid); + writer.WritePropertyName("lockedBy"u8); + + if (file.LockedBy.HasValue) + { + writer.WriteStringValue(file.LockedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(file.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(file.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing File for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(file.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileRevision"u8); + + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(file.Iid); + writer.WritePropertyName("lockedBy"u8); + + if (file.LockedBy.HasValue) + { + writer.WriteStringValue(file.LockedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(file.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(file.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(file.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing File for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(file.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileRevision"u8); + + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(file.Iid); + writer.WritePropertyName("lockedBy"u8); + + if (file.LockedBy.HasValue) + { + writer.WriteStringValue(file.LockedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(file.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(file.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(file.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(file.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing File for Version 1.3.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(file.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileRevision"u8); + + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(file.Iid); + writer.WritePropertyName("lockedBy"u8); + + if (file.LockedBy.HasValue) + { + writer.WriteStringValue(file.LockedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(file.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(file.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(file.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(file.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not File file) + { + throw new ArgumentException("The thing shall be a File", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in file.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(file.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in file.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in file.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("fileRevision"u8); + + foreach(var fileRevisionItem in file.FileRevision.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(file.Iid); + writer.WritePropertyName("lockedBy"u8); + + if (file.LockedBy.HasValue) + { + writer.WriteStringValue(file.LockedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(file.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(file.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(file.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(file.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var file = thing as File; - if (file == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a File."); - } + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "filerevision": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListFileRevision && objectListFileRevision.Any()) + { + writer.WriteStartArray("fileRevision"u8); - return this.Serialize(file); + foreach(var fileRevisionItem in objectListFileRevision.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileRevisionItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "lockedby": + writer.WritePropertyName("lockedBy"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the File"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fileRevision", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "lockedBy", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs index 9ace1b27f..6e7a0c35f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FileTypeSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using FileType = CDP4Common.DTO.FileType; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +50,704 @@ namespace CDP4JsonSerializer public class FileTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "extension", extension => new JValue(extension) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(FileType fileType) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](fileType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](fileType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), fileType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](fileType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](fileType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](fileType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("extension", this.PropertySerializerMap["extension"](fileType.Extension)); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](fileType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](fileType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](fileType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](fileType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](fileType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](fileType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](fileType.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](fileType.ThingPreference)); - return jsonObject; + if (thing is not FileType fileType) + { + throw new ArgumentException("The thing shall be a FileType", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of FileType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of FileType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing FileType for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not FileType fileType) + { + throw new ArgumentException("The thing shall be a FileType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in fileType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in fileType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(fileType.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in fileType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in fileType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in fileType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("extension"u8); + writer.WriteStringValue(fileType.Extension); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in fileType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(fileType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(fileType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(fileType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(fileType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(fileType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(fileType.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(fileType.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var fileType = thing as FileType; - if (fileType == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a FileType."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "extension": + writer.WritePropertyName("extension"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "hyperlink": + if (value == null) + { + break; + } - return this.Serialize(fileType); + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the FileType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "extension", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs index 4c1ce3094..9adee42ae 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/FolderSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Folder = CDP4Common.DTO.Folder; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +50,518 @@ namespace CDP4JsonSerializer public class FolderSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "containingFolder", containingFolder => new JValue(containingFolder) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "creator", creator => new JValue(creator) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(Folder folder) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), folder.ClassKind))); - jsonObject.Add("containingFolder", this.PropertySerializerMap["containingFolder"](folder.ContainingFolder)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](folder.CreatedOn)); - jsonObject.Add("creator", this.PropertySerializerMap["creator"](folder.Creator)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](folder.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](folder.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](folder.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](folder.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](folder.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](folder.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](folder.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](folder.ThingPreference)); - return jsonObject; + if (thing is not Folder folder) + { + throw new ArgumentException("The thing shall be a Folder", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Folder."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Folder since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Folder for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if (folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Folder for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if (folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(folder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Folder for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if (folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(folder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(folder.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Folder for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if (folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(folder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(folder.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Folder folder) + { + throw new ArgumentException("The thing shall be a Folder", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(folder.ClassKind.ToString()); + writer.WritePropertyName("containingFolder"u8); + + if (folder.ContainingFolder.HasValue) + { + writer.WriteStringValue(folder.ContainingFolder.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(folder.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("creator"u8); + writer.WriteStringValue(folder.Creator); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in folder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in folder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(folder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(folder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(folder.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(folder.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(folder.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(folder.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var folder = thing as Folder; - if (folder == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Folder."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(folder); + break; + case "containingfolder": + writer.WritePropertyName("containingFolder"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "creator": + writer.WritePropertyName("creator"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Folder"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containingFolder", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "creator", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs index 6318bc35b..94db94404 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GlossarySerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Glossary = CDP4Common.DTO.Glossary; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +50,744 @@ namespace CDP4JsonSerializer public class GlossarySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "term", term => new JArray(term) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(Glossary glossary) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](glossary.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](glossary.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), glossary.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](glossary.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](glossary.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](glossary.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](glossary.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](glossary.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](glossary.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](glossary.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](glossary.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](glossary.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](glossary.ShortName)); - jsonObject.Add("term", this.PropertySerializerMap["term"](glossary.Term.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](glossary.ThingPreference)); - return jsonObject; + if (thing is not Glossary glossary) + { + throw new ArgumentException("The thing shall be a Glossary", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Glossary."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Glossary since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); + + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(glossary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); + + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(glossary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); + + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(glossary.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Glossary for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(glossary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + writer.WriteStartArray("term"u8); + + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(glossary.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Glossary glossary) + { + throw new ArgumentException("The thing shall be a Glossary", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in glossary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in glossary.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(glossary.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in glossary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in glossary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in glossary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in glossary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(glossary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(glossary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(glossary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(glossary.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(glossary.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(glossary.ShortName); + + writer.WriteStartArray("term"u8); + + foreach(var termItem in glossary.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(glossary.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var glossary = thing as Glossary; - if (glossary == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Glossary."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } - return this.Serialize(glossary); + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "term": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListTerm && objectListTerm.Any()) + { + writer.WriteStartArray("term"u8); + + foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + writer.WriteEndArray(); + } + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Glossary"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "term", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs index 0e9904633..75cd0cc56 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/GoalSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Goal = CDP4Common.DTO.Goal; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +50,607 @@ namespace CDP4JsonSerializer public class GoalSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(Goal goal) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](goal.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](goal.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), goal.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](goal.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](goal.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](goal.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](goal.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](goal.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](goal.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](goal.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](goal.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](goal.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](goal.ThingPreference)); - return jsonObject; + if (thing is not Goal goal) + { + throw new ArgumentException("The thing shall be a Goal", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Goal."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Goal since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Goal for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(goal.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(goal.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(goal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(goal.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(goal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(goal.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Goal for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(goal.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(goal.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(goal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(goal.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(goal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(goal.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(goal.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Goal for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(goal.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(goal.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(goal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(goal.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(goal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(goal.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(goal.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Goal goal) + { + throw new ArgumentException("The thing shall be a Goal", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in goal.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in goal.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(goal.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in goal.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in goal.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in goal.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in goal.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(goal.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(goal.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(goal.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(goal.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(goal.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(goal.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var goal = thing as Goal; - if (goal == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Goal."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } - return this.Serialize(goal); + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Goal"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs index 3a34e9acd..12ec0a0ab 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/HyperLinkSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using HyperLink = CDP4Common.DTO.HyperLink; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +50,425 @@ namespace CDP4JsonSerializer public class HyperLinkSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "uri", uri => new JValue(uri) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(HyperLink hyperLink) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), hyperLink.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](hyperLink.Content)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](hyperLink.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](hyperLink.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](hyperLink.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](hyperLink.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](hyperLink.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](hyperLink.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](hyperLink.ThingPreference)); - jsonObject.Add("uri", this.PropertySerializerMap["uri"](hyperLink.Uri)); - return jsonObject; + if (thing is not HyperLink hyperLink) + { + throw new ArgumentException("The thing shall be a HyperLink", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of HyperLink."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of HyperLink since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing HyperLink for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing HyperLink for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(hyperLink.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing HyperLink for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(hyperLink.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(hyperLink.ThingPreference); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing HyperLink for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(hyperLink.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(hyperLink.ThingPreference); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not HyperLink hyperLink) + { + throw new ArgumentException("The thing shall be a HyperLink", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(hyperLink.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(hyperLink.Content); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in hyperLink.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in hyperLink.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(hyperLink.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(hyperLink.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(hyperLink.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(hyperLink.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(hyperLink.ThingPreference); + writer.WritePropertyName("uri"u8); + writer.WriteStringValue(hyperLink.Uri); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var hyperLink = thing as HyperLink; - if (hyperLink == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a HyperLink."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(hyperLink); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "uri": + writer.WritePropertyName("uri"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the HyperLink"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "uri", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs index 70bfb8a60..facb617b4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IdCorrespondenceSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using IdCorrespondence = CDP4Common.DTO.IdCorrespondence; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +50,401 @@ namespace CDP4JsonSerializer public class IdCorrespondenceSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "externalId", externalId => new JValue(externalId) }, - { "iid", iid => new JValue(iid) }, - { "internalThing", internalThing => new JValue(internalThing) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(IdCorrespondence idCorrespondence) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), idCorrespondence.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](idCorrespondence.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](idCorrespondence.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("externalId", this.PropertySerializerMap["externalId"](idCorrespondence.ExternalId)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](idCorrespondence.Iid)); - jsonObject.Add("internalThing", this.PropertySerializerMap["internalThing"](idCorrespondence.InternalThing)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](idCorrespondence.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](idCorrespondence.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](idCorrespondence.ThingPreference)); - return jsonObject; + if (thing is not IdCorrespondence idCorrespondence) + { + throw new ArgumentException("The thing shall be a IdCorrespondence", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of IdCorrespondence."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of IdCorrespondence since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing IdCorrespondence for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing IdCorrespondence for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(idCorrespondence.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing IdCorrespondence for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(idCorrespondence.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(idCorrespondence.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing IdCorrespondence for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(idCorrespondence.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(idCorrespondence.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not IdCorrespondence idCorrespondence) + { + throw new ArgumentException("The thing shall be a IdCorrespondence", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(idCorrespondence.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in idCorrespondence.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in idCorrespondence.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("externalId"u8); + writer.WriteStringValue(idCorrespondence.ExternalId); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(idCorrespondence.Iid); + writer.WritePropertyName("internalThing"u8); + writer.WriteStringValue(idCorrespondence.InternalThing); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(idCorrespondence.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(idCorrespondence.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(idCorrespondence.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var idCorrespondence = thing as IdCorrespondence; - if (idCorrespondence == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a IdCorrespondence."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(idCorrespondence); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "externalid": + writer.WritePropertyName("externalId"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "internalthing": + writer.WritePropertyName("internalThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the IdCorrespondence"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "externalId", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "internalThing", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs index f836203f0..009036c37 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IndependentParameterTypeAssignmentSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using IndependentParameterTypeAssignment = CDP4Common.DTO.IndependentParameterTypeAssignment; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +50,382 @@ namespace CDP4JsonSerializer public class IndependentParameterTypeAssignmentSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "measurementScale", measurementScale => new JValue(measurementScale) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(IndependentParameterTypeAssignment independentParameterTypeAssignment) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.2.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), independentParameterTypeAssignment.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](independentParameterTypeAssignment.Iid)); - jsonObject.Add("measurementScale", this.PropertySerializerMap["measurementScale"](independentParameterTypeAssignment.MeasurementScale)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](independentParameterTypeAssignment.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](independentParameterTypeAssignment.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](independentParameterTypeAssignment.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](independentParameterTypeAssignment.ThingPreference)); - return jsonObject; + if (thing is not IndependentParameterTypeAssignment independentParameterTypeAssignment) + { + throw new ArgumentException("The thing shall be a IndependentParameterTypeAssignment", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of IndependentParameterTypeAssignment."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of IndependentParameterTypeAssignment since Version is below 1.2.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing IndependentParameterTypeAssignment for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(independentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if (independentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(independentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(independentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing IndependentParameterTypeAssignment for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(independentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if (independentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(independentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(independentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not IndependentParameterTypeAssignment independentParameterTypeAssignment) + { + throw new ArgumentException("The thing shall be a IndependentParameterTypeAssignment", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in independentParameterTypeAssignment.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in independentParameterTypeAssignment.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(independentParameterTypeAssignment.Iid); + writer.WritePropertyName("measurementScale"u8); + + if (independentParameterTypeAssignment.MeasurementScale.HasValue) + { + writer.WriteStringValue(independentParameterTypeAssignment.MeasurementScale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(independentParameterTypeAssignment.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(independentParameterTypeAssignment.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var independentParameterTypeAssignment = thing as IndependentParameterTypeAssignment; - if (independentParameterTypeAssignment == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a IndependentParameterTypeAssignment."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(independentParameterTypeAssignment); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "measurementscale": + writer.WritePropertyName("measurementScale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the IndependentParameterTypeAssignment"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.2.0", "1.3.0" }}, + { "measurementScale", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs index 0304f4c72..f342628ad 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IntervalScaleSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using IntervalScale = CDP4Common.DTO.IntervalScale; /// /// The purpose of the class is to provide a specific serializer @@ -45,98 +50,936 @@ namespace CDP4JsonSerializer public class IntervalScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isMaximumInclusive", isMaximumInclusive => new JValue(isMaximumInclusive) }, - { "isMinimumInclusive", isMinimumInclusive => new JValue(isMinimumInclusive) }, - { "mappingToReferenceScale", mappingToReferenceScale => new JArray(mappingToReferenceScale) }, - { "maximumPermissibleValue", maximumPermissibleValue => new JValue(maximumPermissibleValue) }, - { "minimumPermissibleValue", minimumPermissibleValue => new JValue(minimumPermissibleValue) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "negativeValueConnotation", negativeValueConnotation => new JValue(negativeValueConnotation) }, - { "numberSet", numberSet => new JValue(numberSet.ToString()) }, - { "positiveValueConnotation", positiveValueConnotation => new JValue(positiveValueConnotation) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - { "valueDefinition", valueDefinition => new JArray(valueDefinition) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(IntervalScale intervalScale) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](intervalScale.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), intervalScale.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](intervalScale.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](intervalScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](intervalScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](intervalScale.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](intervalScale.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](intervalScale.IsDeprecated)); - jsonObject.Add("isMaximumInclusive", this.PropertySerializerMap["isMaximumInclusive"](intervalScale.IsMaximumInclusive)); - jsonObject.Add("isMinimumInclusive", this.PropertySerializerMap["isMinimumInclusive"](intervalScale.IsMinimumInclusive)); - jsonObject.Add("mappingToReferenceScale", this.PropertySerializerMap["mappingToReferenceScale"](intervalScale.MappingToReferenceScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("maximumPermissibleValue", this.PropertySerializerMap["maximumPermissibleValue"](intervalScale.MaximumPermissibleValue)); - jsonObject.Add("minimumPermissibleValue", this.PropertySerializerMap["minimumPermissibleValue"](intervalScale.MinimumPermissibleValue)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](intervalScale.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](intervalScale.Name)); - jsonObject.Add("negativeValueConnotation", this.PropertySerializerMap["negativeValueConnotation"](intervalScale.NegativeValueConnotation)); - jsonObject.Add("numberSet", this.PropertySerializerMap["numberSet"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.NumberSetKind), intervalScale.NumberSet))); - jsonObject.Add("positiveValueConnotation", this.PropertySerializerMap["positiveValueConnotation"](intervalScale.PositiveValueConnotation)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](intervalScale.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](intervalScale.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](intervalScale.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](intervalScale.Unit)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](intervalScale.ValueDefinition.OrderBy(x => x, this.guidComparer))); - return jsonObject; + if (thing is not IntervalScale intervalScale) + { + throw new ArgumentException("The thing shall be a IntervalScale", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of IntervalScale."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of IntervalScale since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(intervalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(intervalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(intervalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing IntervalScale for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(intervalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(intervalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not IntervalScale intervalScale) + { + throw new ArgumentException("The thing shall be a IntervalScale", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in intervalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(intervalScale.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in intervalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in intervalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in intervalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in intervalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(intervalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(intervalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(intervalScale.IsMinimumInclusive); + + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in intervalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(intervalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(intervalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(intervalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(intervalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(intervalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(intervalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(intervalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(intervalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(intervalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(intervalScale.Unit); + + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in intervalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var intervalScale = thing as IntervalScale; - if (intervalScale == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a IntervalScale."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); - return this.Serialize(intervalScale); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ismaximuminclusive": + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mappingtoreferencescale": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListMappingToReferenceScale && objectListMappingToReferenceScale.Any()) + { + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + writer.WriteEndArray(); + } + break; + case "maximumpermissiblevalue": + writer.WritePropertyName("maximumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minimumpermissiblevalue": + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "negativevalueconnotation": + writer.WritePropertyName("negativeValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "numberset": + writer.WritePropertyName("numberSet"u8); + + if(value != null) + { + writer.WriteStringValue(((NumberSetKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "positivevalueconnotation": + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) + { + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the IntervalScale"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMaximumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMinimumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "mappingToReferenceScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maximumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minimumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "negativeValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "numberSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "positiveValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs index a5a4ed411..04e48b1dd 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Iteration = CDP4Common.DTO.Iteration; /// /// The purpose of the class is to provide a specific serializer @@ -45,108 +50,1605 @@ namespace CDP4JsonSerializer public class IterationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "actualFiniteStateList", actualFiniteStateList => new JArray(actualFiniteStateList) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultOption", defaultOption => new JValue(defaultOption) }, - { "diagramCanvas", diagramCanvas => new JArray(diagramCanvas) }, - { "domainFileStore", domainFileStore => new JArray(domainFileStore) }, - { "element", element => new JArray(element) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "externalIdentifierMap", externalIdentifierMap => new JArray(externalIdentifierMap) }, - { "goal", goal => new JArray(goal) }, - { "iid", iid => new JValue(iid) }, - { "iterationSetup", iterationSetup => new JValue(iterationSetup) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "option", option => new JArray(((IEnumerable)option).Cast().Select(x => x.ToJsonObject())) }, - { "possibleFiniteStateList", possibleFiniteStateList => new JArray(possibleFiniteStateList) }, - { "publication", publication => new JArray(publication) }, - { "relationship", relationship => new JArray(relationship) }, - { "requirementsSpecification", requirementsSpecification => new JArray(requirementsSpecification) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "ruleVerificationList", ruleVerificationList => new JArray(ruleVerificationList) }, - { "sharedDiagramStyle", sharedDiagramStyle => new JArray(sharedDiagramStyle) }, - { "sourceIterationIid", sourceIterationIid => new JValue(sourceIterationIid) }, - { "stakeholder", stakeholder => new JArray(stakeholder) }, - { "stakeholderValue", stakeholderValue => new JArray(stakeholderValue) }, - { "stakeholderValueMap", stakeholderValueMap => new JArray(stakeholderValueMap) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "topElement", topElement => new JValue(topElement) }, - { "valueGroup", valueGroup => new JArray(valueGroup) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(Iteration iteration) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("actualFiniteStateList", this.PropertySerializerMap["actualFiniteStateList"](iteration.ActualFiniteStateList.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), iteration.ClassKind))); - jsonObject.Add("defaultOption", this.PropertySerializerMap["defaultOption"](iteration.DefaultOption)); - jsonObject.Add("diagramCanvas", this.PropertySerializerMap["diagramCanvas"](iteration.DiagramCanvas.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("domainFileStore", this.PropertySerializerMap["domainFileStore"](iteration.DomainFileStore.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("element", this.PropertySerializerMap["element"](iteration.Element.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](iteration.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](iteration.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("externalIdentifierMap", this.PropertySerializerMap["externalIdentifierMap"](iteration.ExternalIdentifierMap.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("goal", this.PropertySerializerMap["goal"](iteration.Goal.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](iteration.Iid)); - jsonObject.Add("iterationSetup", this.PropertySerializerMap["iterationSetup"](iteration.IterationSetup)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](iteration.ModifiedOn)); - jsonObject.Add("option", this.PropertySerializerMap["option"](iteration.Option.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("possibleFiniteStateList", this.PropertySerializerMap["possibleFiniteStateList"](iteration.PossibleFiniteStateList.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("publication", this.PropertySerializerMap["publication"](iteration.Publication.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("relationship", this.PropertySerializerMap["relationship"](iteration.Relationship.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("requirementsSpecification", this.PropertySerializerMap["requirementsSpecification"](iteration.RequirementsSpecification.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](iteration.RevisionNumber)); - jsonObject.Add("ruleVerificationList", this.PropertySerializerMap["ruleVerificationList"](iteration.RuleVerificationList.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("sharedDiagramStyle", this.PropertySerializerMap["sharedDiagramStyle"](iteration.SharedDiagramStyle.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("sourceIterationIid", this.PropertySerializerMap["sourceIterationIid"](iteration.SourceIterationIid)); - jsonObject.Add("stakeholder", this.PropertySerializerMap["stakeholder"](iteration.Stakeholder.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("stakeholderValue", this.PropertySerializerMap["stakeholderValue"](iteration.StakeholderValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("stakeholderValueMap", this.PropertySerializerMap["stakeholderValueMap"](iteration.StakeholderValueMap.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](iteration.ThingPreference)); - jsonObject.Add("topElement", this.PropertySerializerMap["topElement"](iteration.TopElement)); - jsonObject.Add("valueGroup", this.PropertySerializerMap["valueGroup"](iteration.ValueGroup.OrderBy(x => x, this.guidComparer))); - return jsonObject; + if (thing is not Iteration iteration) + { + throw new ArgumentException("The thing shall be a Iteration", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Iteration."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Iteration since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.0.0"); + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iteration.ClassKind.ToString()); + writer.WritePropertyName("defaultOption"u8); + + if (iteration.DefaultOption.HasValue) + { + writer.WriteStringValue(iteration.DefaultOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("domainFileStore"u8); + + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("externalIdentifierMap"u8); + + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iteration.Iid); + writer.WritePropertyName("iterationSetup"u8); + writer.WriteStringValue(iteration.IterationSetup); + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("relationship"u8); + + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); + + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("sourceIterationIid"u8); + + if (iteration.SourceIterationIid.HasValue) + { + writer.WriteStringValue(iteration.SourceIterationIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("topElement"u8); + + if (iteration.TopElement.HasValue) + { + writer.WriteStringValue(iteration.TopElement.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.1.0"); + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iteration.ClassKind.ToString()); + writer.WritePropertyName("defaultOption"u8); + + if (iteration.DefaultOption.HasValue) + { + writer.WriteStringValue(iteration.DefaultOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramCanvas"u8); + + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domainFileStore"u8); + + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("externalIdentifierMap"u8); + + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iteration.Iid); + writer.WritePropertyName("iterationSetup"u8); + writer.WriteStringValue(iteration.IterationSetup); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("relationship"u8); + + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); + + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("sharedDiagramStyle"u8); + + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("sourceIterationIid"u8); + + if (iteration.SourceIterationIid.HasValue) + { + writer.WriteStringValue(iteration.SourceIterationIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("stakeholder"u8); + + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("stakeholderValueMap"u8); + + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("topElement"u8); + + if (iteration.TopElement.HasValue) + { + writer.WriteStringValue(iteration.TopElement.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.2.0"); + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iteration.ClassKind.ToString()); + writer.WritePropertyName("defaultOption"u8); + + if (iteration.DefaultOption.HasValue) + { + writer.WriteStringValue(iteration.DefaultOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramCanvas"u8); + + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domainFileStore"u8); + + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("externalIdentifierMap"u8); + + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iteration.Iid); + writer.WritePropertyName("iterationSetup"u8); + writer.WriteStringValue(iteration.IterationSetup); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("relationship"u8); + + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); + + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("sharedDiagramStyle"u8); + + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("sourceIterationIid"u8); + + if (iteration.SourceIterationIid.HasValue) + { + writer.WriteStringValue(iteration.SourceIterationIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("stakeholder"u8); + + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("stakeholderValueMap"u8); + + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iteration.ThingPreference); + writer.WritePropertyName("topElement"u8); + + if (iteration.TopElement.HasValue) + { + writer.WriteStringValue(iteration.TopElement.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Iteration for Version 1.3.0"); + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iteration.ClassKind.ToString()); + writer.WritePropertyName("defaultOption"u8); + + if (iteration.DefaultOption.HasValue) + { + writer.WriteStringValue(iteration.DefaultOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramCanvas"u8); + + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domainFileStore"u8); + + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("externalIdentifierMap"u8); + + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iteration.Iid); + writer.WritePropertyName("iterationSetup"u8); + writer.WriteStringValue(iteration.IterationSetup); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("relationship"u8); + + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iteration.RevisionNumber); + writer.WriteStartArray("ruleVerificationList"u8); + + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("sharedDiagramStyle"u8); + + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("sourceIterationIid"u8); + + if (iteration.SourceIterationIid.HasValue) + { + writer.WriteStringValue(iteration.SourceIterationIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("stakeholder"u8); + + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("stakeholderValueMap"u8); + + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iteration.ThingPreference); + writer.WritePropertyName("topElement"u8); + + if (iteration.TopElement.HasValue) + { + writer.WriteStringValue(iteration.TopElement.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Iteration iteration) + { + throw new ArgumentException("The thing shall be a Iteration", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in iteration.ActualFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iteration.ClassKind.ToString()); + writer.WritePropertyName("defaultOption"u8); + + if (iteration.DefaultOption.HasValue) + { + writer.WriteStringValue(iteration.DefaultOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("diagramCanvas"u8); + + foreach(var diagramCanvasItem in iteration.DiagramCanvas.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("domainFileStore"u8); + + foreach(var domainFileStoreItem in iteration.DomainFileStore.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("element"u8); + + foreach(var elementItem in iteration.Element.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iteration.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iteration.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("externalIdentifierMap"u8); + + foreach(var externalIdentifierMapItem in iteration.ExternalIdentifierMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in iteration.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iteration.Iid); + writer.WritePropertyName("iterationSetup"u8); + writer.WriteStringValue(iteration.IterationSetup); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iteration.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("option"u8); + + foreach(var optionItem in iteration.Option.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in iteration.PossibleFiniteStateList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in iteration.Publication.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("relationship"u8); + + foreach(var relationshipItem in iteration.Relationship.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in iteration.RequirementsSpecification.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iteration.RevisionNumber); + + writer.WriteStartArray("ruleVerificationList"u8); + + foreach(var ruleVerificationListItem in iteration.RuleVerificationList.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("sharedDiagramStyle"u8); + + foreach(var sharedDiagramStyleItem in iteration.SharedDiagramStyle.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("sourceIterationIid"u8); + + if (iteration.SourceIterationIid.HasValue) + { + writer.WriteStringValue(iteration.SourceIterationIid.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("stakeholder"u8); + + foreach(var stakeholderItem in iteration.Stakeholder.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in iteration.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("stakeholderValueMap"u8); + + foreach(var stakeholderValueMapItem in iteration.StakeholderValueMap.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iteration.ThingPreference); + writer.WritePropertyName("topElement"u8); + + if (iteration.TopElement.HasValue) + { + writer.WriteStringValue(iteration.TopElement.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in iteration.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var iteration = thing as Iteration; - if (iteration == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Iteration."); - } + case "actualfinitestatelist": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListActualFiniteStateList && objectListActualFiniteStateList.Any()) + { + writer.WriteStartArray("actualFiniteStateList"u8); + + foreach(var actualFiniteStateListItem in objectListActualFiniteStateList.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(actualFiniteStateListItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultoption": + writer.WritePropertyName("defaultOption"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "diagramcanvas": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDiagramCanvas && objectListDiagramCanvas.Any()) + { + writer.WriteStartArray("diagramCanvas"u8); + + foreach(var diagramCanvasItem in objectListDiagramCanvas.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(diagramCanvasItem); + } + writer.WriteEndArray(); + } + break; + case "domainfilestore": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDomainFileStore && objectListDomainFileStore.Any()) + { + writer.WriteStartArray("domainFileStore"u8); + + foreach(var domainFileStoreItem in objectListDomainFileStore.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainFileStoreItem); + } + writer.WriteEndArray(); + } + break; + case "element": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListElement && objectListElement.Any()) + { + writer.WriteStartArray("element"u8); + + foreach(var elementItem in objectListElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(elementItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "externalidentifiermap": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExternalIdentifierMap && objectListExternalIdentifierMap.Any()) + { + writer.WriteStartArray("externalIdentifierMap"u8); - return this.Serialize(iteration); + foreach(var externalIdentifierMapItem in objectListExternalIdentifierMap.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(externalIdentifierMapItem); + } + writer.WriteEndArray(); + } + break; + case "goal": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListGoal && objectListGoal.Any()) + { + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in objectListGoal.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iterationsetup": + writer.WritePropertyName("iterationSetup"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "option": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListOption && objectListOption.Any()) + { + writer.WriteStartArray("option"u8); + + foreach(var optionItem in objectListOption.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(optionItem); + } + writer.WriteEndArray(); + } + break; + case "possiblefinitestatelist": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListPossibleFiniteStateList && objectListPossibleFiniteStateList.Any()) + { + writer.WriteStartArray("possibleFiniteStateList"u8); + + foreach(var possibleFiniteStateListItem in objectListPossibleFiniteStateList.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleFiniteStateListItem); + } + writer.WriteEndArray(); + } + break; + case "publication": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListPublication && objectListPublication.Any()) + { + writer.WriteStartArray("publication"u8); + + foreach(var publicationItem in objectListPublication.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publicationItem); + } + writer.WriteEndArray(); + } + break; + case "relationship": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRelationship && objectListRelationship.Any()) + { + writer.WriteStartArray("relationship"u8); + + foreach(var relationshipItem in objectListRelationship.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relationshipItem); + } + writer.WriteEndArray(); + } + break; + case "requirementsspecification": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRequirementsSpecification && objectListRequirementsSpecification.Any()) + { + writer.WriteStartArray("requirementsSpecification"u8); + + foreach(var requirementsSpecificationItem in objectListRequirementsSpecification.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementsSpecificationItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ruleverificationlist": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRuleVerificationList && objectListRuleVerificationList.Any()) + { + writer.WriteStartArray("ruleVerificationList"u8); + + foreach(var ruleVerificationListItem in objectListRuleVerificationList.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleVerificationListItem); + } + writer.WriteEndArray(); + } + break; + case "shareddiagramstyle": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListSharedDiagramStyle && objectListSharedDiagramStyle.Any()) + { + writer.WriteStartArray("sharedDiagramStyle"u8); + + foreach(var sharedDiagramStyleItem in objectListSharedDiagramStyle.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sharedDiagramStyleItem); + } + writer.WriteEndArray(); + } + break; + case "sourceiterationiid": + writer.WritePropertyName("sourceIterationIid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "stakeholder": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListStakeholder && objectListStakeholder.Any()) + { + writer.WriteStartArray("stakeholder"u8); + + foreach(var stakeholderItem in objectListStakeholder.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderItem); + } + writer.WriteEndArray(); + } + break; + case "stakeholdervalue": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListStakeholderValue && objectListStakeholderValue.Any()) + { + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + writer.WriteEndArray(); + } + break; + case "stakeholdervaluemap": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListStakeholderValueMap && objectListStakeholderValueMap.Any()) + { + writer.WriteStartArray("stakeholderValueMap"u8); + + foreach(var stakeholderValueMapItem in objectListStakeholderValueMap.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueMapItem); + } + writer.WriteEndArray(); + } + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "topelement": + writer.WritePropertyName("topElement"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuegroup": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListValueGroup && objectListValueGroup.Any()) + { + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in objectListValueGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Iteration"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "actualFiniteStateList", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultOption", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "diagramCanvas", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "domainFileStore", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "element", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "externalIdentifierMap", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "goal", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iterationSetup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "option", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleFiniteStateList", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "publication", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "relationship", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "requirementsSpecification", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "ruleVerificationList", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "sharedDiagramStyle", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceIterationIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholder", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholderValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholderValueMap", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "topElement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueGroup", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs index ee7be73e7..dd1b513e5 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/IterationSetupSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using IterationSetup = CDP4Common.DTO.IterationSetup; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +50,611 @@ namespace CDP4JsonSerializer public class IterationSetupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "description", description => new JValue(description) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "frozenOn", frozenOn => new JValue(frozenOn != null ? ((DateTime)frozenOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") : null) }, - { "iid", iid => new JValue(iid) }, - { "isDeleted", isDeleted => new JValue(isDeleted) }, - { "iterationIid", iterationIid => new JValue(iterationIid) }, - { "iterationNumber", iterationNumber => new JValue(iterationNumber) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "sourceIterationSetup", sourceIterationSetup => new JValue(sourceIterationSetup) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(IterationSetup iterationSetup) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), iterationSetup.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](iterationSetup.CreatedOn)); - jsonObject.Add("description", this.PropertySerializerMap["description"](iterationSetup.Description)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](iterationSetup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](iterationSetup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("frozenOn", this.PropertySerializerMap["frozenOn"](iterationSetup.FrozenOn)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](iterationSetup.Iid)); - jsonObject.Add("isDeleted", this.PropertySerializerMap["isDeleted"](iterationSetup.IsDeleted)); - jsonObject.Add("iterationIid", this.PropertySerializerMap["iterationIid"](iterationSetup.IterationIid)); - jsonObject.Add("iterationNumber", this.PropertySerializerMap["iterationNumber"](iterationSetup.IterationNumber)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](iterationSetup.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](iterationSetup.RevisionNumber)); - jsonObject.Add("sourceIterationSetup", this.PropertySerializerMap["sourceIterationSetup"](iterationSetup.SourceIterationSetup)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](iterationSetup.ThingPreference)); - return jsonObject; + if (thing is not IterationSetup iterationSetup) + { + throw new ArgumentException("The thing shall be a IterationSetup", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of IterationSetup."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of IterationSetup since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing IterationSetup for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + writer.WritePropertyName("frozenOn"u8); + + if (iterationSetup.FrozenOn.HasValue) + { + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); + + if (iterationSetup.SourceIterationSetup.HasValue) + { + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing IterationSetup for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("frozenOn"u8); + + if (iterationSetup.FrozenOn.HasValue) + { + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iterationSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); + + if (iterationSetup.SourceIterationSetup.HasValue) + { + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing IterationSetup for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("frozenOn"u8); + + if (iterationSetup.FrozenOn.HasValue) + { + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iterationSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); + + if (iterationSetup.SourceIterationSetup.HasValue) + { + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iterationSetup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing IterationSetup for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("frozenOn"u8); + + if (iterationSetup.FrozenOn.HasValue) + { + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iterationSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); + + if (iterationSetup.SourceIterationSetup.HasValue) + { + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iterationSetup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not IterationSetup iterationSetup) + { + throw new ArgumentException("The thing shall be a IterationSetup", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(iterationSetup.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(iterationSetup.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(iterationSetup.Description); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in iterationSetup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in iterationSetup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("frozenOn"u8); + + if (iterationSetup.FrozenOn.HasValue) + { + writer.WriteStringValue(iterationSetup.FrozenOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(iterationSetup.Iid); + writer.WritePropertyName("isDeleted"u8); + writer.WriteBooleanValue(iterationSetup.IsDeleted); + writer.WritePropertyName("iterationIid"u8); + writer.WriteStringValue(iterationSetup.IterationIid); + writer.WritePropertyName("iterationNumber"u8); + writer.WriteNumberValue(iterationSetup.IterationNumber); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(iterationSetup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(iterationSetup.RevisionNumber); + writer.WritePropertyName("sourceIterationSetup"u8); + + if (iterationSetup.SourceIterationSetup.HasValue) + { + writer.WriteStringValue(iterationSetup.SourceIterationSetup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(iterationSetup.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var iterationSetup = thing as IterationSetup; - if (iterationSetup == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a IterationSetup."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "description": + writer.WritePropertyName("description"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "frozenon": + writer.WritePropertyName("frozenOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeleted": + writer.WritePropertyName("isDeleted"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iterationiid": + writer.WritePropertyName("iterationIid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(iterationSetup); + break; + case "iterationnumber": + writer.WritePropertyName("iterationNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceiterationsetup": + writer.WritePropertyName("sourceIterationSetup"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the IterationSetup"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "description", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "frozenOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeleted", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iterationIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iterationNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceIterationSetup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs index 1f6be53f3..9316266a9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LinearConversionUnitSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using LinearConversionUnit = CDP4Common.DTO.LinearConversionUnit; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +50,664 @@ namespace CDP4JsonSerializer public class LinearConversionUnitSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "conversionFactor", conversionFactor => new JValue(conversionFactor) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "referenceUnit", referenceUnit => new JValue(referenceUnit) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(LinearConversionUnit linearConversionUnit) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](linearConversionUnit.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), linearConversionUnit.ClassKind))); - jsonObject.Add("conversionFactor", this.PropertySerializerMap["conversionFactor"](linearConversionUnit.ConversionFactor)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](linearConversionUnit.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](linearConversionUnit.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](linearConversionUnit.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](linearConversionUnit.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](linearConversionUnit.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](linearConversionUnit.Name)); - jsonObject.Add("referenceUnit", this.PropertySerializerMap["referenceUnit"](linearConversionUnit.ReferenceUnit)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](linearConversionUnit.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](linearConversionUnit.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](linearConversionUnit.ThingPreference)); - return jsonObject; + if (thing is not LinearConversionUnit linearConversionUnit) + { + throw new ArgumentException("The thing shall be a LinearConversionUnit", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of LinearConversionUnit."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of LinearConversionUnit since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(linearConversionUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(linearConversionUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(linearConversionUnit.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing LinearConversionUnit for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(linearConversionUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(linearConversionUnit.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not LinearConversionUnit linearConversionUnit) + { + throw new ArgumentException("The thing shall be a LinearConversionUnit", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in linearConversionUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(linearConversionUnit.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(linearConversionUnit.ConversionFactor); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in linearConversionUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in linearConversionUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in linearConversionUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in linearConversionUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(linearConversionUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(linearConversionUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(linearConversionUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(linearConversionUnit.Name); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(linearConversionUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(linearConversionUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(linearConversionUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(linearConversionUnit.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var linearConversionUnit = thing as LinearConversionUnit; - if (linearConversionUnit == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a LinearConversionUnit."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "conversionfactor": + writer.WritePropertyName("conversionFactor"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(linearConversionUnit); + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referenceunit": + writer.WritePropertyName("referenceUnit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the LinearConversionUnit"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "conversionFactor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceUnit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs index 334db2960..aef472fe9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogEntryChangelogItemSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using LogEntryChangelogItem = CDP4Common.DTO.LogEntryChangelogItem; /// /// The purpose of the class is to provide a specific serializer @@ -45,74 +50,421 @@ namespace CDP4JsonSerializer public class LogEntryChangelogItemSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "affectedItemIid", affectedItemIid => new JValue(affectedItemIid) }, - { "affectedReferenceIid", affectedReferenceIid => new JArray(affectedReferenceIid) }, - { "changeDescription", changeDescription => new JValue(changeDescription) }, - { "changelogKind", changelogKind => new JValue(changelogKind.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(LogEntryChangelogItem logEntryChangelogItem) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.2.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("affectedItemIid", this.PropertySerializerMap["affectedItemIid"](logEntryChangelogItem.AffectedItemIid)); - jsonObject.Add("affectedReferenceIid", this.PropertySerializerMap["affectedReferenceIid"](logEntryChangelogItem.AffectedReferenceIid.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("changeDescription", this.PropertySerializerMap["changeDescription"](logEntryChangelogItem.ChangeDescription)); - jsonObject.Add("changelogKind", this.PropertySerializerMap["changelogKind"](Enum.GetName(typeof(CDP4Common.CommonData.LogEntryChangelogItemKind), logEntryChangelogItem.ChangelogKind))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), logEntryChangelogItem.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](logEntryChangelogItem.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](logEntryChangelogItem.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](logEntryChangelogItem.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](logEntryChangelogItem.ThingPreference)); - return jsonObject; + if (thing is not LogEntryChangelogItem logEntryChangelogItem) + { + throw new ArgumentException("The thing shall be a LogEntryChangelogItem", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of LogEntryChangelogItem."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of LogEntryChangelogItem since Version is below 1.2.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing LogEntryChangelogItem for Version 1.2.0"); + writer.WritePropertyName("affectedItemIid"u8); + writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); + writer.WriteStartArray("affectedReferenceIid"u8); + + foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) + { + writer.WriteStringValue(affectedReferenceIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeDescription"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); + writer.WritePropertyName("changelogKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangelogKind.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logEntryChangelogItem.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logEntryChangelogItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logEntryChangelogItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logEntryChangelogItem.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing LogEntryChangelogItem for Version 1.3.0"); + writer.WritePropertyName("affectedItemIid"u8); + writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); + writer.WriteStartArray("affectedReferenceIid"u8); + + foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) + { + writer.WriteStringValue(affectedReferenceIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeDescription"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); + writer.WritePropertyName("changelogKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangelogKind.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logEntryChangelogItem.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logEntryChangelogItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logEntryChangelogItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logEntryChangelogItem.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not LogEntryChangelogItem logEntryChangelogItem) + { + throw new ArgumentException("The thing shall be a LogEntryChangelogItem", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("affectedItemIid"u8); + writer.WriteStringValue(logEntryChangelogItem.AffectedItemIid); + + writer.WriteStartArray("affectedReferenceIid"u8); + + foreach(var affectedReferenceIidItem in logEntryChangelogItem.AffectedReferenceIid) + { + writer.WriteStringValue(affectedReferenceIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("changeDescription"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangeDescription); + writer.WritePropertyName("changelogKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ChangelogKind.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logEntryChangelogItem.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logEntryChangelogItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logEntryChangelogItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logEntryChangelogItem.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logEntryChangelogItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logEntryChangelogItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logEntryChangelogItem.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var logEntryChangelogItem = thing as LogEntryChangelogItem; - if (logEntryChangelogItem == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a LogEntryChangelogItem."); - } + case "affecteditemiid": + writer.WritePropertyName("affectedItemIid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "affectedreferenceiid": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAffectedReferenceIid && objectListAffectedReferenceIid.Any()) + { + writer.WriteStartArray("affectedReferenceIid"u8); - return this.Serialize(logEntryChangelogItem); + foreach (var affectedReferenceIidItem in objectListAffectedReferenceIid) + { + writer.WriteStringValue((Guid)affectedReferenceIidItem); + } + writer.WriteEndArray(); + } + break; + case "changedescription": + writer.WritePropertyName("changeDescription"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "changelogkind": + writer.WritePropertyName("changelogKind"u8); + + if(value != null) + { + writer.WriteStringValue(((LogEntryChangelogItemKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the LogEntryChangelogItem"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "affectedItemIid", new []{ "1.2.0", "1.3.0" }}, + { "affectedReferenceIid", new []{ "1.2.0", "1.3.0" }}, + { "changeDescription", new []{ "1.2.0", "1.3.0" }}, + { "changelogKind", new []{ "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs index e25bd97c4..1576215be 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/LogarithmicScaleSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using LogarithmicScale = CDP4Common.DTO.LogarithmicScale; /// /// The purpose of the class is to provide a specific serializer @@ -45,108 +50,1096 @@ namespace CDP4JsonSerializer public class LogarithmicScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "exponent", exponent => new JValue(exponent) }, - { "factor", factor => new JValue(factor) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isMaximumInclusive", isMaximumInclusive => new JValue(isMaximumInclusive) }, - { "isMinimumInclusive", isMinimumInclusive => new JValue(isMinimumInclusive) }, - { "logarithmBase", logarithmBase => new JValue(logarithmBase.ToString()) }, - { "mappingToReferenceScale", mappingToReferenceScale => new JArray(mappingToReferenceScale) }, - { "maximumPermissibleValue", maximumPermissibleValue => new JValue(maximumPermissibleValue) }, - { "minimumPermissibleValue", minimumPermissibleValue => new JValue(minimumPermissibleValue) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "negativeValueConnotation", negativeValueConnotation => new JValue(negativeValueConnotation) }, - { "numberSet", numberSet => new JValue(numberSet.ToString()) }, - { "positiveValueConnotation", positiveValueConnotation => new JValue(positiveValueConnotation) }, - { "referenceQuantityKind", referenceQuantityKind => new JValue(referenceQuantityKind) }, - { "referenceQuantityValue", referenceQuantityValue => new JArray(referenceQuantityValue) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - { "valueDefinition", valueDefinition => new JArray(valueDefinition) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(LogarithmicScale logarithmicScale) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](logarithmicScale.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), logarithmicScale.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](logarithmicScale.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](logarithmicScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](logarithmicScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("exponent", this.PropertySerializerMap["exponent"](logarithmicScale.Exponent)); - jsonObject.Add("factor", this.PropertySerializerMap["factor"](logarithmicScale.Factor)); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](logarithmicScale.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](logarithmicScale.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](logarithmicScale.IsDeprecated)); - jsonObject.Add("isMaximumInclusive", this.PropertySerializerMap["isMaximumInclusive"](logarithmicScale.IsMaximumInclusive)); - jsonObject.Add("isMinimumInclusive", this.PropertySerializerMap["isMinimumInclusive"](logarithmicScale.IsMinimumInclusive)); - jsonObject.Add("logarithmBase", this.PropertySerializerMap["logarithmBase"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.LogarithmBaseKind), logarithmicScale.LogarithmBase))); - jsonObject.Add("mappingToReferenceScale", this.PropertySerializerMap["mappingToReferenceScale"](logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("maximumPermissibleValue", this.PropertySerializerMap["maximumPermissibleValue"](logarithmicScale.MaximumPermissibleValue)); - jsonObject.Add("minimumPermissibleValue", this.PropertySerializerMap["minimumPermissibleValue"](logarithmicScale.MinimumPermissibleValue)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](logarithmicScale.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](logarithmicScale.Name)); - jsonObject.Add("negativeValueConnotation", this.PropertySerializerMap["negativeValueConnotation"](logarithmicScale.NegativeValueConnotation)); - jsonObject.Add("numberSet", this.PropertySerializerMap["numberSet"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.NumberSetKind), logarithmicScale.NumberSet))); - jsonObject.Add("positiveValueConnotation", this.PropertySerializerMap["positiveValueConnotation"](logarithmicScale.PositiveValueConnotation)); - jsonObject.Add("referenceQuantityKind", this.PropertySerializerMap["referenceQuantityKind"](logarithmicScale.ReferenceQuantityKind)); - jsonObject.Add("referenceQuantityValue", this.PropertySerializerMap["referenceQuantityValue"](logarithmicScale.ReferenceQuantityValue)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](logarithmicScale.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](logarithmicScale.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](logarithmicScale.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](logarithmicScale.Unit)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](logarithmicScale.ValueDefinition.OrderBy(x => x, this.guidComparer))); - return jsonObject; + if (thing is not LogarithmicScale logarithmicScale) + { + throw new ArgumentException("The thing shall be a LogarithmicScale", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of LogarithmicScale."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of LogarithmicScale since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logarithmicScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logarithmicScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logarithmicScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing LogarithmicScale for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logarithmicScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logarithmicScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not LogarithmicScale logarithmicScale) + { + throw new ArgumentException("The thing shall be a LogarithmicScale", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in logarithmicScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(logarithmicScale.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in logarithmicScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in logarithmicScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in logarithmicScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(logarithmicScale.Exponent); + writer.WritePropertyName("factor"u8); + writer.WriteStringValue(logarithmicScale.Factor); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in logarithmicScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(logarithmicScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(logarithmicScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(logarithmicScale.IsMinimumInclusive); + writer.WritePropertyName("logarithmBase"u8); + writer.WriteStringValue(logarithmicScale.LogarithmBase.ToString()); + + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in logarithmicScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(logarithmicScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(logarithmicScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(logarithmicScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(logarithmicScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(logarithmicScale.PositiveValueConnotation); + writer.WritePropertyName("referenceQuantityKind"u8); + writer.WriteStringValue(logarithmicScale.ReferenceQuantityKind); + + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in logarithmicScale.ReferenceQuantityValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(logarithmicScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(logarithmicScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(logarithmicScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(logarithmicScale.Unit); + + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in logarithmicScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var logarithmicScale = thing as LogarithmicScale; - if (logarithmicScale == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a LogarithmicScale."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } - return this.Serialize(logarithmicScale); + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "exponent": + writer.WritePropertyName("exponent"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "factor": + writer.WritePropertyName("factor"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ismaximuminclusive": + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "logarithmbase": + writer.WritePropertyName("logarithmBase"u8); + + if(value != null) + { + writer.WriteStringValue(((LogarithmBaseKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mappingtoreferencescale": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListMappingToReferenceScale && objectListMappingToReferenceScale.Any()) + { + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + writer.WriteEndArray(); + } + break; + case "maximumpermissiblevalue": + writer.WritePropertyName("maximumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minimumpermissiblevalue": + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "negativevalueconnotation": + writer.WritePropertyName("negativeValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "numberset": + writer.WritePropertyName("numberSet"u8); + + if(value != null) + { + writer.WriteStringValue(((NumberSetKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "positivevalueconnotation": + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencequantitykind": + writer.WritePropertyName("referenceQuantityKind"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencequantityvalue": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListReferenceQuantityValue && objectListReferenceQuantityValue.Any()) + { + writer.WriteStartArray("referenceQuantityValue"u8); + + foreach(var referenceQuantityValueItem in objectListReferenceQuantityValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceQuantityValueItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) + { + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the LogarithmicScale"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "exponent", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "factor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMaximumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMinimumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "logarithmBase", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "mappingToReferenceScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maximumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minimumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "negativeValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "numberSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "positiveValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceQuantityKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceQuantityValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs index d2fcf1775..43f6de80b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MappingToReferenceScaleSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using MappingToReferenceScale = CDP4Common.DTO.MappingToReferenceScale; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +50,401 @@ namespace CDP4JsonSerializer public class MappingToReferenceScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "dependentScaleValue", dependentScaleValue => new JValue(dependentScaleValue) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "referenceScaleValue", referenceScaleValue => new JValue(referenceScaleValue) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(MappingToReferenceScale mappingToReferenceScale) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), mappingToReferenceScale.ClassKind))); - jsonObject.Add("dependentScaleValue", this.PropertySerializerMap["dependentScaleValue"](mappingToReferenceScale.DependentScaleValue)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](mappingToReferenceScale.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](mappingToReferenceScale.ModifiedOn)); - jsonObject.Add("referenceScaleValue", this.PropertySerializerMap["referenceScaleValue"](mappingToReferenceScale.ReferenceScaleValue)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](mappingToReferenceScale.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](mappingToReferenceScale.ThingPreference)); - return jsonObject; + if (thing is not MappingToReferenceScale mappingToReferenceScale) + { + throw new ArgumentException("The thing shall be a MappingToReferenceScale", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of MappingToReferenceScale."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of MappingToReferenceScale since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing MappingToReferenceScale for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing MappingToReferenceScale for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(mappingToReferenceScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing MappingToReferenceScale for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(mappingToReferenceScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(mappingToReferenceScale.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing MappingToReferenceScale for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(mappingToReferenceScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(mappingToReferenceScale.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not MappingToReferenceScale mappingToReferenceScale) + { + throw new ArgumentException("The thing shall be a MappingToReferenceScale", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(mappingToReferenceScale.ClassKind.ToString()); + writer.WritePropertyName("dependentScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.DependentScaleValue); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in mappingToReferenceScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in mappingToReferenceScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(mappingToReferenceScale.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(mappingToReferenceScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referenceScaleValue"u8); + writer.WriteStringValue(mappingToReferenceScale.ReferenceScaleValue); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(mappingToReferenceScale.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(mappingToReferenceScale.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var mappingToReferenceScale = thing as MappingToReferenceScale; - if (mappingToReferenceScale == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a MappingToReferenceScale."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(mappingToReferenceScale); + break; + case "dependentscalevalue": + writer.WritePropertyName("dependentScaleValue"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencescalevalue": + writer.WritePropertyName("referenceScaleValue"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the MappingToReferenceScale"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "dependentScaleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceScaleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs index e3f2927ba..05cc1c703 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelLogEntrySerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ModelLogEntry = CDP4Common.DTO.ModelLogEntry; /// /// The purpose of the class is to provide a specific serializer @@ -45,84 +50,754 @@ namespace CDP4JsonSerializer public class ModelLogEntrySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "affectedDomainIid", affectedDomainIid => new JArray(affectedDomainIid) }, - { "affectedItemIid", affectedItemIid => new JArray(affectedItemIid) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "level", level => new JValue(level.ToString()) }, - { "logEntryChangelogItem", logEntryChangelogItem => new JArray(logEntryChangelogItem) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ModelLogEntry modelLogEntry) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("affectedDomainIid", this.PropertySerializerMap["affectedDomainIid"](modelLogEntry.AffectedDomainIid.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("affectedItemIid", this.PropertySerializerMap["affectedItemIid"](modelLogEntry.AffectedItemIid.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](modelLogEntry.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](modelLogEntry.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), modelLogEntry.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](modelLogEntry.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](modelLogEntry.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](modelLogEntry.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](modelLogEntry.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](modelLogEntry.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](modelLogEntry.LanguageCode)); - jsonObject.Add("level", this.PropertySerializerMap["level"](Enum.GetName(typeof(CDP4Common.CommonData.LogLevelKind), modelLogEntry.Level))); - jsonObject.Add("logEntryChangelogItem", this.PropertySerializerMap["logEntryChangelogItem"](modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](modelLogEntry.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](modelLogEntry.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](modelLogEntry.ThingPreference)); - return jsonObject; + if (thing is not ModelLogEntry modelLogEntry) + { + throw new ArgumentException("The thing shall be a ModelLogEntry", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ModelLogEntry."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ModelLogEntry since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.0.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if (modelLogEntry.Author.HasValue) + { + writer.WriteStringValue(modelLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.1.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if (modelLogEntry.Author.HasValue) + { + writer.WriteStringValue(modelLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.2.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if (modelLogEntry.Author.HasValue) + { + writer.WriteStringValue(modelLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelLogEntry.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ModelLogEntry for Version 1.3.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if (modelLogEntry.Author.HasValue) + { + writer.WriteStringValue(modelLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelLogEntry.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ModelLogEntry modelLogEntry) + { + throw new ArgumentException("The thing shall be a ModelLogEntry", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in modelLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in modelLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if (modelLogEntry.Author.HasValue) + { + writer.WriteStringValue(modelLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in modelLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(modelLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(modelLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(modelLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(modelLogEntry.Level.ToString()); + + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in modelLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelLogEntry.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var modelLogEntry = thing as ModelLogEntry; - if (modelLogEntry == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ModelLogEntry."); - } + case "affecteddomainiid": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAffectedDomainIid && objectListAffectedDomainIid.Any()) + { + writer.WriteStartArray("affectedDomainIid"u8); + + foreach (var affectedDomainIidItem in objectListAffectedDomainIid) + { + writer.WriteStringValue((Guid)affectedDomainIidItem); + } + writer.WriteEndArray(); + } + break; + case "affecteditemiid": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAffectedItemIid && objectListAffectedItemIid.Any()) + { + writer.WriteStartArray("affectedItemIid"u8); + + foreach (var affectedItemIidItem in objectListAffectedItemIid) + { + writer.WriteStringValue((Guid)affectedItemIidItem); + } + writer.WriteEndArray(); + } + break; + case "author": + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } - return this.Serialize(modelLogEntry); + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "level": + writer.WritePropertyName("level"u8); + + if(value != null) + { + writer.WriteStringValue(((LogLevelKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "logentrychangelogitem": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListLogEntryChangelogItem && objectListLogEntryChangelogItem.Any()) + { + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in objectListLogEntryChangelogItem.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + writer.WriteEndArray(); + } + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ModelLogEntry"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "affectedDomainIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "affectedItemIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "level", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "logEntryChangelogItem", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs index 89b20d876..e0c3ae6e4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModelReferenceDataLibrarySerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ModelReferenceDataLibrary = CDP4Common.DTO.ModelReferenceDataLibrary; /// /// The purpose of the class is to provide a specific serializer @@ -45,102 +50,1429 @@ namespace CDP4JsonSerializer public class ModelReferenceDataLibrarySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "baseQuantityKind", baseQuantityKind => new JArray(((IEnumerable)baseQuantityKind).Cast().Select(x => x.ToJsonObject())) }, - { "baseUnit", baseUnit => new JArray(baseUnit) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "constant", constant => new JArray(constant) }, - { "definedCategory", definedCategory => new JArray(definedCategory) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fileType", fileType => new JArray(fileType) }, - { "glossary", glossary => new JArray(glossary) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "parameterType", parameterType => new JArray(parameterType) }, - { "referenceSource", referenceSource => new JArray(referenceSource) }, - { "requiredRdl", requiredRdl => new JValue(requiredRdl) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "rule", rule => new JArray(rule) }, - { "scale", scale => new JArray(scale) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JArray(unit) }, - { "unitPrefix", unitPrefix => new JArray(unitPrefix) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(ModelReferenceDataLibrary modelReferenceDataLibrary) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](modelReferenceDataLibrary.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("baseQuantityKind", this.PropertySerializerMap["baseQuantityKind"](modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("baseUnit", this.PropertySerializerMap["baseUnit"](modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), modelReferenceDataLibrary.ClassKind))); - jsonObject.Add("constant", this.PropertySerializerMap["constant"](modelReferenceDataLibrary.Constant.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("definedCategory", this.PropertySerializerMap["definedCategory"](modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](modelReferenceDataLibrary.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fileType", this.PropertySerializerMap["fileType"](modelReferenceDataLibrary.FileType.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("glossary", this.PropertySerializerMap["glossary"](modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](modelReferenceDataLibrary.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](modelReferenceDataLibrary.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](modelReferenceDataLibrary.Name)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("referenceSource", this.PropertySerializerMap["referenceSource"](modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("requiredRdl", this.PropertySerializerMap["requiredRdl"](modelReferenceDataLibrary.RequiredRdl)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](modelReferenceDataLibrary.RevisionNumber)); - jsonObject.Add("rule", this.PropertySerializerMap["rule"](modelReferenceDataLibrary.Rule.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](modelReferenceDataLibrary.Scale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](modelReferenceDataLibrary.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](modelReferenceDataLibrary.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](modelReferenceDataLibrary.Unit.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("unitPrefix", this.PropertySerializerMap["unitPrefix"](modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.guidComparer))); - return jsonObject; + if (thing is not ModelReferenceDataLibrary modelReferenceDataLibrary) + { + throw new ArgumentException("The thing shall be a ModelReferenceDataLibrary", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ModelReferenceDataLibrary."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ModelReferenceDataLibrary since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if (modelReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if (modelReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if (modelReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ModelReferenceDataLibrary for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if (modelReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ModelReferenceDataLibrary modelReferenceDataLibrary) + { + throw new ArgumentException("The thing shall be a ModelReferenceDataLibrary", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in modelReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in modelReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in modelReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ClassKind.ToString()); + + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in modelReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in modelReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in modelReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modelReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modelReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in modelReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in modelReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in modelReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(modelReferenceDataLibrary.Name); + + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in modelReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in modelReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if (modelReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(modelReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modelReferenceDataLibrary.RevisionNumber); + + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in modelReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in modelReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modelReferenceDataLibrary.ThingPreference); + + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in modelReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in modelReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var modelReferenceDataLibrary = thing as ModelReferenceDataLibrary; - if (modelReferenceDataLibrary == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ModelReferenceDataLibrary."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "basequantitykind": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListBaseQuantityKind && objectListBaseQuantityKind.Any()) + { + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in objectListBaseQuantityKind.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + writer.WriteEndArray(); + } + break; + case "baseunit": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListBaseUnit && objectListBaseUnit.Any()) + { + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in objectListBaseUnit.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "constant": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListConstant && objectListConstant.Any()) + { + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in objectListConstant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + writer.WriteEndArray(); + } + break; + case "definedcategory": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinedCategory && objectListDefinedCategory.Any()) + { + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in objectListDefinedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + writer.WriteEndArray(); + } + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); - return this.Serialize(modelReferenceDataLibrary); + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "filetype": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListFileType && objectListFileType.Any()) + { + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in objectListFileType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + writer.WriteEndArray(); + } + break; + case "glossary": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListGlossary && objectListGlossary.Any()) + { + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in objectListGlossary.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListParameterType && objectListParameterType.Any()) + { + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + writer.WriteEndArray(); + } + break; + case "referencesource": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListReferenceSource && objectListReferenceSource.Any()) + { + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in objectListReferenceSource.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + writer.WriteEndArray(); + } + break; + case "requiredrdl": + writer.WritePropertyName("requiredRdl"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "rule": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRule && objectListRule.Any()) + { + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in objectListRule.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + writer.WriteEndArray(); + } + break; + case "scale": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListScale && objectListScale.Any()) + { + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in objectListScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + writer.WriteEndArray(); + } + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListUnit && objectListUnit.Any()) + { + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in objectListUnit.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + writer.WriteEndArray(); + } + break; + case "unitprefix": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListUnitPrefix && objectListUnitPrefix.Any()) + { + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in objectListUnitPrefix.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ModelReferenceDataLibrary"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "baseQuantityKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "baseUnit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "constant", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definedCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fileType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "glossary", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceSource", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "requiredRdl", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "rule", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "unitPrefix", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs index 2c4de11f9..cd8d424a4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ModellingThingReferenceSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ModellingThingReference = CDP4Common.DTO.ModellingThingReference; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +50,388 @@ namespace CDP4JsonSerializer public class ModellingThingReferenceSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "referencedRevisionNumber", referencedRevisionNumber => new JValue(referencedRevisionNumber) }, - { "referencedThing", referencedThing => new JValue(referencedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(ModellingThingReference modellingThingReference) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), modellingThingReference.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](modellingThingReference.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](modellingThingReference.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](modellingThingReference.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](modellingThingReference.ModifiedOn)); - jsonObject.Add("referencedRevisionNumber", this.PropertySerializerMap["referencedRevisionNumber"](modellingThingReference.ReferencedRevisionNumber)); - jsonObject.Add("referencedThing", this.PropertySerializerMap["referencedThing"](modellingThingReference.ReferencedThing)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](modellingThingReference.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](modellingThingReference.ThingPreference)); - return jsonObject; + if (thing is not ModellingThingReference modellingThingReference) + { + throw new ArgumentException("The thing shall be a ModellingThingReference", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ModellingThingReference."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ModellingThingReference since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ModellingThingReference for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modellingThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modellingThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(modellingThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ModellingThingReference for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modellingThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modellingThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(modellingThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modellingThingReference.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ModellingThingReference for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modellingThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modellingThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(modellingThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modellingThingReference.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ModellingThingReference modellingThingReference) + { + throw new ArgumentException("The thing shall be a ModellingThingReference", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(modellingThingReference.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in modellingThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in modellingThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(modellingThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(modellingThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(modellingThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(modellingThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(modellingThingReference.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var modellingThingReference = thing as ModellingThingReference; - if (modellingThingReference == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ModellingThingReference."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(modellingThingReference); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencedrevisionnumber": + writer.WritePropertyName("referencedRevisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencedthing": + writer.WritePropertyName("referencedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ModellingThingReference"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedRevisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs index c863de8e8..8cf6cca31 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipRuleSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using MultiRelationshipRule = CDP4Common.DTO.MultiRelationshipRule; /// /// The purpose of the class is to provide a specific serializer @@ -45,86 +50,752 @@ namespace CDP4JsonSerializer public class MultiRelationshipRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "maxRelated", maxRelated => new JValue(maxRelated) }, - { "minRelated", minRelated => new JValue(minRelated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "relatedCategory", relatedCategory => new JArray(relatedCategory) }, - { "relationshipCategory", relationshipCategory => new JValue(relationshipCategory) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(MultiRelationshipRule multiRelationshipRule) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](multiRelationshipRule.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), multiRelationshipRule.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](multiRelationshipRule.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](multiRelationshipRule.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](multiRelationshipRule.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](multiRelationshipRule.IsDeprecated)); - jsonObject.Add("maxRelated", this.PropertySerializerMap["maxRelated"](multiRelationshipRule.MaxRelated)); - jsonObject.Add("minRelated", this.PropertySerializerMap["minRelated"](multiRelationshipRule.MinRelated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](multiRelationshipRule.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](multiRelationshipRule.Name)); - jsonObject.Add("relatedCategory", this.PropertySerializerMap["relatedCategory"](multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("relationshipCategory", this.PropertySerializerMap["relationshipCategory"](multiRelationshipRule.RelationshipCategory)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](multiRelationshipRule.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](multiRelationshipRule.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](multiRelationshipRule.ThingPreference)); - return jsonObject; + if (thing is not MultiRelationshipRule multiRelationshipRule) + { + throw new ArgumentException("The thing shall be a MultiRelationshipRule", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of MultiRelationshipRule."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of MultiRelationshipRule since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationshipRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationshipRule for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationshipRule.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not MultiRelationshipRule multiRelationshipRule) + { + throw new ArgumentException("The thing shall be a MultiRelationshipRule", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in multiRelationshipRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationshipRule.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in multiRelationshipRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationshipRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationshipRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in multiRelationshipRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationshipRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(multiRelationshipRule.IsDeprecated); + writer.WritePropertyName("maxRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MaxRelated); + writer.WritePropertyName("minRelated"u8); + writer.WriteNumberValue(multiRelationshipRule.MinRelated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationshipRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationshipRule.Name); + + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in multiRelationshipRule.RelatedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("relationshipCategory"u8); + writer.WriteStringValue(multiRelationshipRule.RelationshipCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationshipRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(multiRelationshipRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationshipRule.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var multiRelationshipRule = thing as MultiRelationshipRule; - if (multiRelationshipRule == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a MultiRelationshipRule."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "maxrelated": + writer.WritePropertyName("maxRelated"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(multiRelationshipRule); + break; + case "minrelated": + writer.WritePropertyName("minRelated"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedcategory": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRelatedCategory && objectListRelatedCategory.Any()) + { + writer.WriteStartArray("relatedCategory"u8); + + foreach(var relatedCategoryItem in objectListRelatedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedCategoryItem); + } + writer.WriteEndArray(); + } + break; + case "relationshipcategory": + writer.WritePropertyName("relationshipCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the MultiRelationshipRule"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maxRelated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minRelated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "relationshipCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs index 42be8c406..c3900ad34 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/MultiRelationshipSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using MultiRelationship = CDP4Common.DTO.MultiRelationship; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +50,579 @@ namespace CDP4JsonSerializer public class MultiRelationshipSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterValue", parameterValue => new JArray(parameterValue) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(MultiRelationship multiRelationship) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](multiRelationship.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), multiRelationship.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](multiRelationship.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](multiRelationship.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](multiRelationship.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](multiRelationship.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](multiRelationship.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](multiRelationship.Owner)); - jsonObject.Add("parameterValue", this.PropertySerializerMap["parameterValue"](multiRelationship.ParameterValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](multiRelationship.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](multiRelationship.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](multiRelationship.ThingPreference)); - return jsonObject; + if (thing is not MultiRelationship multiRelationship) + { + throw new ArgumentException("The thing shall be a MultiRelationship", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of MultiRelationship."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of MultiRelationship since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.0.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationship.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing MultiRelationship for Version 1.3.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationship.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not MultiRelationship multiRelationship) + { + throw new ArgumentException("The thing shall be a MultiRelationship", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in multiRelationship.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(multiRelationship.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in multiRelationship.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in multiRelationship.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(multiRelationship.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(multiRelationship.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(multiRelationship.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(multiRelationship.Owner); + + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in multiRelationship.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in multiRelationship.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(multiRelationship.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(multiRelationship.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var multiRelationship = thing as MultiRelationship; - if (multiRelationship == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a MultiRelationship."); - } + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(multiRelationship); + break; + case "parametervalue": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListParameterValue && objectListParameterValue.Any()) + { + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + writer.WriteEndArray(); + } + break; + case "relatedthing": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) + { + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the MultiRelationship"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs index 2b50c8de3..65c9c7b5c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NaturalLanguageSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using NaturalLanguage = CDP4Common.DTO.NaturalLanguage; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +50,425 @@ namespace CDP4JsonSerializer public class NaturalLanguageSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "nativeName", nativeName => new JValue(nativeName) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(NaturalLanguage naturalLanguage) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), naturalLanguage.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](naturalLanguage.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](naturalLanguage.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](naturalLanguage.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](naturalLanguage.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](naturalLanguage.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](naturalLanguage.Name)); - jsonObject.Add("nativeName", this.PropertySerializerMap["nativeName"](naturalLanguage.NativeName)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](naturalLanguage.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](naturalLanguage.ThingPreference)); - return jsonObject; + if (thing is not NaturalLanguage naturalLanguage) + { + throw new ArgumentException("The thing shall be a NaturalLanguage", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of NaturalLanguage."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of NaturalLanguage since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing NaturalLanguage for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing NaturalLanguage for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(naturalLanguage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing NaturalLanguage for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(naturalLanguage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(naturalLanguage.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing NaturalLanguage for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(naturalLanguage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(naturalLanguage.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not NaturalLanguage naturalLanguage) + { + throw new ArgumentException("The thing shall be a NaturalLanguage", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(naturalLanguage.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in naturalLanguage.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in naturalLanguage.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(naturalLanguage.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(naturalLanguage.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(naturalLanguage.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(naturalLanguage.Name); + writer.WritePropertyName("nativeName"u8); + writer.WriteStringValue(naturalLanguage.NativeName); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(naturalLanguage.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(naturalLanguage.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var naturalLanguage = thing as NaturalLanguage; - if (naturalLanguage == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a NaturalLanguage."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } - return this.Serialize(naturalLanguage); + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "nativename": + writer.WritePropertyName("nativeName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the NaturalLanguage"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "nativeName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs index 2128e2ef7..84fd12866 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedElementSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using NestedElement = CDP4Common.DTO.NestedElement; /// /// The purpose of the class is to provide a specific serializer @@ -45,74 +50,529 @@ namespace CDP4JsonSerializer public class NestedElementSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "elementUsage", elementUsage => new JArray(((IEnumerable)elementUsage).Cast().Select(x => x.ToJsonObject())) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isVolatile", isVolatile => new JValue(isVolatile) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "nestedParameter", nestedParameter => new JArray(nestedParameter) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "rootElement", rootElement => new JValue(rootElement) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(NestedElement nestedElement) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), nestedElement.ClassKind))); - jsonObject.Add("elementUsage", this.PropertySerializerMap["elementUsage"](nestedElement.ElementUsage.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](nestedElement.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](nestedElement.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](nestedElement.Iid)); - jsonObject.Add("isVolatile", this.PropertySerializerMap["isVolatile"](nestedElement.IsVolatile)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](nestedElement.ModifiedOn)); - jsonObject.Add("nestedParameter", this.PropertySerializerMap["nestedParameter"](nestedElement.NestedParameter.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](nestedElement.RevisionNumber)); - jsonObject.Add("rootElement", this.PropertySerializerMap["rootElement"](nestedElement.RootElement)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](nestedElement.ThingPreference)); - return jsonObject; + if (thing is not NestedElement nestedElement) + { + throw new ArgumentException("The thing shall be a NestedElement", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of NestedElement."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of NestedElement since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedElement.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing NestedElement for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedElement.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not NestedElement nestedElement) + { + throw new ArgumentException("The thing shall be a NestedElement", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedElement.ClassKind.ToString()); + + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in nestedElement.ElementUsage.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedElement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedElement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedElement.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedElement.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedElement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in nestedElement.NestedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedElement.RevisionNumber); + writer.WritePropertyName("rootElement"u8); + writer.WriteStringValue(nestedElement.RootElement); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedElement.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var nestedElement = thing as NestedElement; - if (nestedElement == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a NestedElement."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "elementusage": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListElementUsage && objectListElementUsage.Any()) + { + writer.WriteStartArray("elementUsage"u8); + + foreach(var elementUsageItem in objectListElementUsage.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(elementUsageItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isvolatile": + writer.WritePropertyName("isVolatile"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(nestedElement); + break; + case "nestedparameter": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListNestedParameter && objectListNestedParameter.Any()) + { + writer.WriteStartArray("nestedParameter"u8); + + foreach(var nestedParameterItem in objectListNestedParameter.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedParameterItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "rootelement": + writer.WritePropertyName("rootElement"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the NestedElement"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "elementUsage", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isVolatile", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "nestedParameter", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "rootElement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs index e887dc06d..bc44d710e 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NestedParameterSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using NestedParameter = CDP4Common.DTO.NestedParameter; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +50,542 @@ namespace CDP4JsonSerializer public class NestedParameterSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "actualState", actualState => new JValue(actualState) }, - { "actualValue", actualValue => new JValue(actualValue) }, - { "associatedParameter", associatedParameter => new JValue(associatedParameter) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "formula", formula => new JValue(formula) }, - { "iid", iid => new JValue(iid) }, - { "isVolatile", isVolatile => new JValue(isVolatile) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(NestedParameter nestedParameter) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("actualState", this.PropertySerializerMap["actualState"](nestedParameter.ActualState)); - jsonObject.Add("actualValue", this.PropertySerializerMap["actualValue"](nestedParameter.ActualValue)); - jsonObject.Add("associatedParameter", this.PropertySerializerMap["associatedParameter"](nestedParameter.AssociatedParameter)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), nestedParameter.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](nestedParameter.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](nestedParameter.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("formula", this.PropertySerializerMap["formula"](nestedParameter.Formula)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](nestedParameter.Iid)); - jsonObject.Add("isVolatile", this.PropertySerializerMap["isVolatile"](nestedParameter.IsVolatile)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](nestedParameter.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](nestedParameter.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](nestedParameter.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](nestedParameter.ThingPreference)); - return jsonObject; + if (thing is not NestedParameter nestedParameter) + { + throw new ArgumentException("The thing shall be a NestedParameter", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of NestedParameter."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of NestedParameter since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing NestedParameter for Version 1.0.0"); + writer.WritePropertyName("actualState"u8); + + if (nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing NestedParameter for Version 1.1.0"); + writer.WritePropertyName("actualState"u8); + + if (nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedParameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing NestedParameter for Version 1.2.0"); + writer.WritePropertyName("actualState"u8); + + if (nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedParameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedParameter.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing NestedParameter for Version 1.3.0"); + writer.WritePropertyName("actualState"u8); + + if (nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedParameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedParameter.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not NestedParameter nestedParameter) + { + throw new ArgumentException("The thing shall be a NestedParameter", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("actualState"u8); + + if (nestedParameter.ActualState.HasValue) + { + writer.WriteStringValue(nestedParameter.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualValue"u8); + writer.WriteStringValue(nestedParameter.ActualValue); + writer.WritePropertyName("associatedParameter"u8); + writer.WriteStringValue(nestedParameter.AssociatedParameter); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(nestedParameter.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in nestedParameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in nestedParameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("formula"u8); + writer.WriteStringValue(nestedParameter.Formula); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(nestedParameter.Iid); + writer.WritePropertyName("isVolatile"u8); + writer.WriteBooleanValue(nestedParameter.IsVolatile); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(nestedParameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(nestedParameter.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(nestedParameter.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(nestedParameter.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var nestedParameter = thing as NestedParameter; - if (nestedParameter == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a NestedParameter."); - } + case "actualstate": + writer.WritePropertyName("actualState"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actualvalue": + writer.WritePropertyName("actualValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(nestedParameter); + break; + case "associatedparameter": + writer.WritePropertyName("associatedParameter"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "formula": + writer.WritePropertyName("formula"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isvolatile": + writer.WritePropertyName("isVolatile"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the NestedParameter"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "actualState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "actualValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "associatedParameter", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "formula", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isVolatile", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs index 274f67880..02753f1f6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/NotExpressionSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using NotExpression = CDP4Common.DTO.NotExpression; /// /// The purpose of the class is to provide a specific serializer @@ -45,68 +50,377 @@ namespace CDP4JsonSerializer public class NotExpressionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "term", term => new JValue(term) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(NotExpression notExpression) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), notExpression.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](notExpression.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](notExpression.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](notExpression.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](notExpression.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](notExpression.RevisionNumber)); - jsonObject.Add("term", this.PropertySerializerMap["term"](notExpression.Term)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](notExpression.ThingPreference)); - return jsonObject; + if (thing is not NotExpression notExpression) + { + throw new ArgumentException("The thing shall be a NotExpression", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of NotExpression."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of NotExpression since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing NotExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing NotExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(notExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing NotExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(notExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(notExpression.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing NotExpression for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(notExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(notExpression.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not NotExpression notExpression) + { + throw new ArgumentException("The thing shall be a NotExpression", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(notExpression.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in notExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in notExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(notExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(notExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(notExpression.RevisionNumber); + writer.WritePropertyName("term"u8); + writer.WriteStringValue(notExpression.Term); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(notExpression.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var notExpression = thing as NotExpression; - if (notExpression == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a NotExpression."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(notExpression); + break; + case "term": + writer.WritePropertyName("term"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the NotExpression"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "term", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs index 617b5d033..e7ccabf15 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OptionSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Option = CDP4Common.DTO.Option; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +50,720 @@ namespace CDP4JsonSerializer public class OptionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "nestedElement", nestedElement => new JArray(nestedElement) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(Option option) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](option.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](option.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), option.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](option.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](option.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](option.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](option.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](option.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](option.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](option.Name)); - jsonObject.Add("nestedElement", this.PropertySerializerMap["nestedElement"](option.NestedElement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](option.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](option.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](option.ThingPreference)); - return jsonObject; + if (thing is not Option option) + { + throw new ArgumentException("The thing shall be a Option", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Option."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Option since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); + + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); + + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); + + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(option.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Option for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); + writer.WriteStartArray("nestedElement"u8); + + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(option.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Option option) + { + throw new ArgumentException("The thing shall be a Option", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in option.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in option.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(option.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in option.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in option.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in option.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in option.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(option.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(option.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(option.Name); + + writer.WriteStartArray("nestedElement"u8); + + foreach(var nestedElementItem in option.NestedElement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(option.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(option.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(option.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var option = thing as Option; - if (option == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Option."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(option); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "nestedelement": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListNestedElement && objectListNestedElement.Any()) + { + writer.WriteStartArray("nestedElement"u8); + + foreach(var nestedElementItem in objectListNestedElement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(nestedElementItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Option"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "nestedElement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs index 18bd07fd6..b3d2f6768 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrExpressionSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using OrExpression = CDP4Common.DTO.OrExpression; /// /// The purpose of the class is to provide a specific serializer @@ -45,68 +50,417 @@ namespace CDP4JsonSerializer public class OrExpressionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "term", term => new JArray(term) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(OrExpression orExpression) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), orExpression.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](orExpression.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](orExpression.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](orExpression.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](orExpression.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](orExpression.RevisionNumber)); - jsonObject.Add("term", this.PropertySerializerMap["term"](orExpression.Term.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](orExpression.ThingPreference)); - return jsonObject; + if (thing is not OrExpression orExpression) + { + throw new ArgumentException("The thing shall be a OrExpression", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of OrExpression."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of OrExpression since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing OrExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing OrExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing OrExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(orExpression.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing OrExpression for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(orExpression.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not OrExpression orExpression) + { + throw new ArgumentException("The thing shall be a OrExpression", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(orExpression.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in orExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in orExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(orExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(orExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(orExpression.RevisionNumber); + + writer.WriteStartArray("term"u8); + + foreach(var termItem in orExpression.Term.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(orExpression.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var orExpression = thing as OrExpression; - if (orExpression == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a OrExpression."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(orExpression); + break; + case "term": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListTerm && objectListTerm.Any()) + { + writer.WriteStartArray("term"u8); + + foreach(var termItem in objectListTerm.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(termItem); + } + writer.WriteEndArray(); + } + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the OrExpression"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "term", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs index 88c02416e..e45f32f7d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrdinalScaleSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using OrdinalScale = CDP4Common.DTO.OrdinalScale; /// /// The purpose of the class is to provide a specific serializer @@ -45,100 +50,960 @@ namespace CDP4JsonSerializer public class OrdinalScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isMaximumInclusive", isMaximumInclusive => new JValue(isMaximumInclusive) }, - { "isMinimumInclusive", isMinimumInclusive => new JValue(isMinimumInclusive) }, - { "mappingToReferenceScale", mappingToReferenceScale => new JArray(mappingToReferenceScale) }, - { "maximumPermissibleValue", maximumPermissibleValue => new JValue(maximumPermissibleValue) }, - { "minimumPermissibleValue", minimumPermissibleValue => new JValue(minimumPermissibleValue) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "negativeValueConnotation", negativeValueConnotation => new JValue(negativeValueConnotation) }, - { "numberSet", numberSet => new JValue(numberSet.ToString()) }, - { "positiveValueConnotation", positiveValueConnotation => new JValue(positiveValueConnotation) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - { "useShortNameValues", useShortNameValues => new JValue(useShortNameValues) }, - { "valueDefinition", valueDefinition => new JArray(valueDefinition) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(OrdinalScale ordinalScale) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](ordinalScale.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), ordinalScale.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](ordinalScale.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](ordinalScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](ordinalScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](ordinalScale.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](ordinalScale.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](ordinalScale.IsDeprecated)); - jsonObject.Add("isMaximumInclusive", this.PropertySerializerMap["isMaximumInclusive"](ordinalScale.IsMaximumInclusive)); - jsonObject.Add("isMinimumInclusive", this.PropertySerializerMap["isMinimumInclusive"](ordinalScale.IsMinimumInclusive)); - jsonObject.Add("mappingToReferenceScale", this.PropertySerializerMap["mappingToReferenceScale"](ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("maximumPermissibleValue", this.PropertySerializerMap["maximumPermissibleValue"](ordinalScale.MaximumPermissibleValue)); - jsonObject.Add("minimumPermissibleValue", this.PropertySerializerMap["minimumPermissibleValue"](ordinalScale.MinimumPermissibleValue)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](ordinalScale.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](ordinalScale.Name)); - jsonObject.Add("negativeValueConnotation", this.PropertySerializerMap["negativeValueConnotation"](ordinalScale.NegativeValueConnotation)); - jsonObject.Add("numberSet", this.PropertySerializerMap["numberSet"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.NumberSetKind), ordinalScale.NumberSet))); - jsonObject.Add("positiveValueConnotation", this.PropertySerializerMap["positiveValueConnotation"](ordinalScale.PositiveValueConnotation)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](ordinalScale.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](ordinalScale.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](ordinalScale.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](ordinalScale.Unit)); - jsonObject.Add("useShortNameValues", this.PropertySerializerMap["useShortNameValues"](ordinalScale.UseShortNameValues)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](ordinalScale.ValueDefinition.OrderBy(x => x, this.guidComparer))); - return jsonObject; + if (thing is not OrdinalScale ordinalScale) + { + throw new ArgumentException("The thing shall be a OrdinalScale", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of OrdinalScale."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of OrdinalScale since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ordinalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ordinalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ordinalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing OrdinalScale for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ordinalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ordinalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not OrdinalScale ordinalScale) + { + throw new ArgumentException("The thing shall be a OrdinalScale", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ordinalScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ordinalScale.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ordinalScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ordinalScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ordinalScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ordinalScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ordinalScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ordinalScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ordinalScale.IsMinimumInclusive); + + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ordinalScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ordinalScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ordinalScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ordinalScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ordinalScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ordinalScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ordinalScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ordinalScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ordinalScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ordinalScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ordinalScale.Unit); + writer.WritePropertyName("useShortNameValues"u8); + writer.WriteBooleanValue(ordinalScale.UseShortNameValues); + + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ordinalScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var ordinalScale = thing as OrdinalScale; - if (ordinalScale == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a OrdinalScale."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(ordinalScale); + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ismaximuminclusive": + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mappingtoreferencescale": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListMappingToReferenceScale && objectListMappingToReferenceScale.Any()) + { + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + writer.WriteEndArray(); + } + break; + case "maximumpermissiblevalue": + writer.WritePropertyName("maximumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minimumpermissiblevalue": + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "negativevalueconnotation": + writer.WritePropertyName("negativeValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "numberset": + writer.WritePropertyName("numberSet"u8); + + if(value != null) + { + writer.WriteStringValue(((NumberSetKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "positivevalueconnotation": + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "useshortnamevalues": + writer.WritePropertyName("useShortNameValues"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) + { + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the OrdinalScale"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMaximumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMinimumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "mappingToReferenceScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maximumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minimumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "negativeValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "numberSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "positiveValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "useShortNameValues", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs index 8e79f2781..03e301618 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Organization = CDP4Common.DTO.Organization; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +50,425 @@ namespace CDP4JsonSerializer public class OrganizationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(Organization organization) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), organization.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](organization.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](organization.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](organization.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](organization.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](organization.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](organization.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](organization.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](organization.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](organization.ThingPreference)); - return jsonObject; + if (thing is not Organization organization) + { + throw new ArgumentException("The thing shall be a Organization", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Organization."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Organization since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Organization for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Organization for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organization.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Organization for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organization.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organization.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Organization for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organization.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organization.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Organization organization) + { + throw new ArgumentException("The thing shall be a Organization", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organization.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organization.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organization.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organization.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(organization.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organization.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(organization.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organization.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(organization.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organization.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var organization = thing as Organization; - if (organization == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Organization."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } - return this.Serialize(organization); + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Organization"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs index 90998e961..41882f887 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OrganizationalParticipantSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using OrganizationalParticipant = CDP4Common.DTO.OrganizationalParticipant; /// /// The purpose of the class is to provide a specific serializer @@ -45,68 +50,335 @@ namespace CDP4JsonSerializer public class OrganizationalParticipantSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "organization", organization => new JValue(organization) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.2.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(OrganizationalParticipant organizationalParticipant) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), organizationalParticipant.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](organizationalParticipant.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](organizationalParticipant.ModifiedOn)); - jsonObject.Add("organization", this.PropertySerializerMap["organization"](organizationalParticipant.Organization)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](organizationalParticipant.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](organizationalParticipant.ThingPreference)); - return jsonObject; + if (thing is not OrganizationalParticipant organizationalParticipant) + { + throw new ArgumentException("The thing shall be a OrganizationalParticipant", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of OrganizationalParticipant."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of OrganizationalParticipant since Version is below 1.2.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing OrganizationalParticipant for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organizationalParticipant.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organizationalParticipant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + writer.WriteStringValue(organizationalParticipant.Organization); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organizationalParticipant.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organizationalParticipant.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing OrganizationalParticipant for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organizationalParticipant.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organizationalParticipant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + writer.WriteStringValue(organizationalParticipant.Organization); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organizationalParticipant.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organizationalParticipant.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not OrganizationalParticipant organizationalParticipant) + { + throw new ArgumentException("The thing shall be a OrganizationalParticipant", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(organizationalParticipant.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in organizationalParticipant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in organizationalParticipant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(organizationalParticipant.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(organizationalParticipant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + writer.WriteStringValue(organizationalParticipant.Organization); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(organizationalParticipant.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(organizationalParticipant.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var organizationalParticipant = thing as OrganizationalParticipant; - if (organizationalParticipant == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a OrganizationalParticipant."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(organizationalParticipant); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "organization": + writer.WritePropertyName("organization"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the OrganizationalParticipant"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "organization", new []{ "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs index 1ecec9d6e..97065e4ca 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/OwnedStyleSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using OwnedStyle = CDP4Common.DTO.OwnedStyle; /// /// The purpose of the class is to provide a specific serializer @@ -45,94 +50,1081 @@ namespace CDP4JsonSerializer public class OwnedStyleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fillColor", fillColor => new JValue(fillColor) }, - { "fillOpacity", fillOpacity => new JValue(fillOpacity) }, - { "fontBold", fontBold => new JValue(fontBold) }, - { "fontColor", fontColor => new JValue(fontColor) }, - { "fontItalic", fontItalic => new JValue(fontItalic) }, - { "fontName", fontName => new JValue(fontName) }, - { "fontSize", fontSize => new JValue(fontSize) }, - { "fontStrokeThrough", fontStrokeThrough => new JValue(fontStrokeThrough) }, - { "fontUnderline", fontUnderline => new JValue(fontUnderline) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "strokeColor", strokeColor => new JValue(strokeColor) }, - { "strokeOpacity", strokeOpacity => new JValue(strokeOpacity) }, - { "strokeWidth", strokeWidth => new JValue(strokeWidth) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "usedColor", usedColor => new JArray(usedColor) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(OwnedStyle ownedStyle) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), ownedStyle.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](ownedStyle.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](ownedStyle.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fillColor", this.PropertySerializerMap["fillColor"](ownedStyle.FillColor)); - jsonObject.Add("fillOpacity", this.PropertySerializerMap["fillOpacity"](ownedStyle.FillOpacity)); - jsonObject.Add("fontBold", this.PropertySerializerMap["fontBold"](ownedStyle.FontBold)); - jsonObject.Add("fontColor", this.PropertySerializerMap["fontColor"](ownedStyle.FontColor)); - jsonObject.Add("fontItalic", this.PropertySerializerMap["fontItalic"](ownedStyle.FontItalic)); - jsonObject.Add("fontName", this.PropertySerializerMap["fontName"](ownedStyle.FontName)); - jsonObject.Add("fontSize", this.PropertySerializerMap["fontSize"](ownedStyle.FontSize)); - jsonObject.Add("fontStrokeThrough", this.PropertySerializerMap["fontStrokeThrough"](ownedStyle.FontStrokeThrough)); - jsonObject.Add("fontUnderline", this.PropertySerializerMap["fontUnderline"](ownedStyle.FontUnderline)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](ownedStyle.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](ownedStyle.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](ownedStyle.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](ownedStyle.RevisionNumber)); - jsonObject.Add("strokeColor", this.PropertySerializerMap["strokeColor"](ownedStyle.StrokeColor)); - jsonObject.Add("strokeOpacity", this.PropertySerializerMap["strokeOpacity"](ownedStyle.StrokeOpacity)); - jsonObject.Add("strokeWidth", this.PropertySerializerMap["strokeWidth"](ownedStyle.StrokeWidth)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](ownedStyle.ThingPreference)); - jsonObject.Add("usedColor", this.PropertySerializerMap["usedColor"](ownedStyle.UsedColor.OrderBy(x => x, this.guidComparer))); - return jsonObject; + if (thing is not OwnedStyle ownedStyle) + { + throw new ArgumentException("The thing shall be a OwnedStyle", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of OwnedStyle."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of OwnedStyle since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing OwnedStyle for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ownedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fillColor"u8); + + if (ownedStyle.FillColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if (ownedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if (ownedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if (ownedStyle.FontColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if (ownedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(ownedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if (ownedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(ownedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if (ownedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if (ownedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ownedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ownedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ownedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ownedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if (ownedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(ownedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if (ownedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if (ownedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing OwnedStyle for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ownedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fillColor"u8); + + if (ownedStyle.FillColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if (ownedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if (ownedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if (ownedStyle.FontColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if (ownedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(ownedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if (ownedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(ownedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if (ownedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if (ownedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ownedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ownedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ownedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ownedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if (ownedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(ownedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if (ownedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if (ownedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ownedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing OwnedStyle for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ownedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fillColor"u8); + + if (ownedStyle.FillColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if (ownedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if (ownedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if (ownedStyle.FontColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if (ownedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(ownedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if (ownedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(ownedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if (ownedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if (ownedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ownedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ownedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ownedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ownedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if (ownedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(ownedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if (ownedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if (ownedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ownedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not OwnedStyle ownedStyle) + { + throw new ArgumentException("The thing shall be a OwnedStyle", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ownedStyle.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ownedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ownedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fillColor"u8); + + if (ownedStyle.FillColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if (ownedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if (ownedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if (ownedStyle.FontColor.HasValue) + { + writer.WriteStringValue(ownedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if (ownedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(ownedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if (ownedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(ownedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if (ownedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if (ownedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(ownedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ownedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ownedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ownedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ownedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if (ownedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(ownedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if (ownedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if (ownedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(ownedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ownedStyle.ThingPreference); + + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in ownedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var ownedStyle = thing as OwnedStyle; - if (ownedStyle == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a OwnedStyle."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "fillcolor": + writer.WritePropertyName("fillColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fillopacity": + writer.WritePropertyName("fillOpacity"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontbold": + writer.WritePropertyName("fontBold"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontcolor": + writer.WritePropertyName("fontColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(ownedStyle); + break; + case "fontitalic": + writer.WritePropertyName("fontItalic"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontname": + writer.WritePropertyName("fontName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontsize": + writer.WritePropertyName("fontSize"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontstrokethrough": + writer.WritePropertyName("fontStrokeThrough"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontunderline": + writer.WritePropertyName("fontUnderline"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokecolor": + writer.WritePropertyName("strokeColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokeopacity": + writer.WritePropertyName("strokeOpacity"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokewidth": + writer.WritePropertyName("strokeWidth"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "usedcolor": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListUsedColor && objectListUsedColor.Any()) + { + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in objectListUsedColor.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the OwnedStyle"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fillColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fillOpacity", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontBold", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontItalic", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontSize", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontStrokeThrough", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontUnderline", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeOpacity", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeWidth", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "usedColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs index 13aff4683..0145b989b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PageSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Page = CDP4Common.DTO.Page; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +50,541 @@ namespace CDP4JsonSerializer public class PageSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "note", note => new JArray(((IEnumerable)note).Cast().Select(x => x.ToJsonObject())) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(Page page) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](page.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), page.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](page.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](page.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](page.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](page.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](page.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](page.Name)); - jsonObject.Add("note", this.PropertySerializerMap["note"](page.Note.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](page.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](page.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](page.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](page.ThingPreference)); - return jsonObject; + if (thing is not Page page) + { + throw new ArgumentException("The thing shall be a Page", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Page."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Page since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Page for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(page.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(page.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(page.Name); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(page.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(page.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(page.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Page for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(page.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(page.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(page.Name); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(page.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(page.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(page.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(page.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Page for Version 1.3.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(page.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(page.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(page.Name); + writer.WriteStartArray("note"u8); + + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(page.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(page.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(page.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(page.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Page page) + { + throw new ArgumentException("The thing shall be a Page", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in page.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(page.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(page.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in page.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in page.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(page.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(page.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(page.Name); + + writer.WriteStartArray("note"u8); + + foreach(var noteItem in page.Note.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(page.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(page.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(page.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(page.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var page = thing as Page; - if (page == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Page."); - } + case "category": + if (value == null) + { + break; + } - return this.Serialize(page); + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "note": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListNote && objectListNote.Any()) + { + writer.WriteStartArray("note"u8); + + foreach(var noteItem in objectListNote.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(noteItem); + } + writer.WriteEndArray(); + } + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Page"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "note", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs index bdf558c4c..1b5766f96 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterGroupSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterGroup = CDP4Common.DTO.ParameterGroup; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +50,445 @@ namespace CDP4JsonSerializer public class ParameterGroupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "containingGroup", containingGroup => new JValue(containingGroup) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ParameterGroup parameterGroup) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterGroup.ClassKind))); - jsonObject.Add("containingGroup", this.PropertySerializerMap["containingGroup"](parameterGroup.ContainingGroup)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterGroup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterGroup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterGroup.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterGroup.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](parameterGroup.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterGroup.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterGroup.ThingPreference)); - return jsonObject; + if (thing is not ParameterGroup parameterGroup) + { + throw new ArgumentException("The thing shall be a ParameterGroup", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParameterGroup."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterGroup since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterGroup for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if (parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterGroup for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if (parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterGroup for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if (parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterGroup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterGroup for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if (parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterGroup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ParameterGroup parameterGroup) + { + throw new ArgumentException("The thing shall be a ParameterGroup", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterGroup.ClassKind.ToString()); + writer.WritePropertyName("containingGroup"u8); + + if (parameterGroup.ContainingGroup.HasValue) + { + writer.WriteStringValue(parameterGroup.ContainingGroup.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterGroup.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterGroup.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var parameterGroup = thing as ParameterGroup; - if (parameterGroup == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParameterGroup."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "containinggroup": + writer.WritePropertyName("containingGroup"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(parameterGroup); + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterGroup"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "containingGroup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs index 9ae30cfd9..bd885dd9d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterOverride = CDP4Common.DTO.ParameterOverride; /// /// The purpose of the class is to provide a specific serializer @@ -45,74 +50,529 @@ namespace CDP4JsonSerializer public class ParameterOverrideSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "parameter", parameter => new JValue(parameter) }, - { "parameterSubscription", parameterSubscription => new JArray(parameterSubscription) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSet", valueSet => new JArray(valueSet) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ParameterOverride parameterOverride) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterOverride.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterOverride.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterOverride.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterOverride.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterOverride.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](parameterOverride.Owner)); - jsonObject.Add("parameter", this.PropertySerializerMap["parameter"](parameterOverride.Parameter)); - jsonObject.Add("parameterSubscription", this.PropertySerializerMap["parameterSubscription"](parameterOverride.ParameterSubscription.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterOverride.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterOverride.ThingPreference)); - jsonObject.Add("valueSet", this.PropertySerializerMap["valueSet"](parameterOverride.ValueSet.OrderBy(x => x, this.guidComparer))); - return jsonObject; + if (thing is not ParameterOverride parameterOverride) + { + throw new ArgumentException("The thing shall be a ParameterOverride", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParameterOverride."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterOverride since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverride for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverride for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverride.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverride for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverride.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverride.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverride for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverride.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverride.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ParameterOverride parameterOverride) + { + throw new ArgumentException("The thing shall be a ParameterOverride", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverride.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverride.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverride.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverride.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverride.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterOverride.Owner); + writer.WritePropertyName("parameter"u8); + writer.WriteStringValue(parameterOverride.Parameter); + + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameterOverride.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverride.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverride.ThingPreference); + + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterOverride.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var parameterOverride = thing as ParameterOverride; - if (parameterOverride == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParameterOverride."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parameter": + writer.WritePropertyName("parameter"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametersubscription": + if (value == null) + { + break; + } - return this.Serialize(parameterOverride); + if (value is IEnumerable objectListParameterSubscription && objectListParameterSubscription.Any()) + { + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in objectListParameterSubscription.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueset": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListValueSet && objectListValueSet.Any()) + { + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in objectListValueSet.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterOverride"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameter", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterSubscription", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs index a9140eb2f..6df67a5b7 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterOverrideValueSetSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterOverrideValueSet = CDP4Common.DTO.ParameterOverrideValueSet; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +50,446 @@ namespace CDP4JsonSerializer public class ParameterOverrideValueSetSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "computed", computed => new JValue(((ValueArray)computed).ToJsonString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "formula", formula => new JValue(((ValueArray)formula).ToJsonString()) }, - { "iid", iid => new JValue(iid) }, - { "manual", manual => new JValue(((ValueArray)manual).ToJsonString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterValueSet", parameterValueSet => new JValue(parameterValueSet) }, - { "published", published => new JValue(((ValueArray)published).ToJsonString()) }, - { "reference", reference => new JValue(((ValueArray)reference).ToJsonString()) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSwitch", valueSwitch => new JValue(valueSwitch.ToString()) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(ParameterOverrideValueSet parameterOverrideValueSet) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterOverrideValueSet.ClassKind))); - jsonObject.Add("computed", this.PropertySerializerMap["computed"](parameterOverrideValueSet.Computed)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("formula", this.PropertySerializerMap["formula"](parameterOverrideValueSet.Formula)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterOverrideValueSet.Iid)); - jsonObject.Add("manual", this.PropertySerializerMap["manual"](parameterOverrideValueSet.Manual)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterOverrideValueSet.ModifiedOn)); - jsonObject.Add("parameterValueSet", this.PropertySerializerMap["parameterValueSet"](parameterOverrideValueSet.ParameterValueSet)); - jsonObject.Add("published", this.PropertySerializerMap["published"](parameterOverrideValueSet.Published)); - jsonObject.Add("reference", this.PropertySerializerMap["reference"](parameterOverrideValueSet.Reference)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterOverrideValueSet.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterOverrideValueSet.ThingPreference)); - jsonObject.Add("valueSwitch", this.PropertySerializerMap["valueSwitch"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.ParameterSwitchKind), parameterOverrideValueSet.ValueSwitch))); - return jsonObject; + if (thing is not ParameterOverrideValueSet parameterOverrideValueSet) + { + throw new ArgumentException("The thing shall be a ParameterOverrideValueSet", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParameterOverrideValueSet."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterOverrideValueSet since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverrideValueSet for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverrideValueSet for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverrideValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverrideValueSet for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverrideValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverrideValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterOverrideValueSet for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverrideValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverrideValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ParameterOverrideValueSet parameterOverrideValueSet) + { + throw new ArgumentException("The thing shall be a ParameterOverrideValueSet", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterOverrideValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterOverrideValueSet.Computed.ToJsonString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterOverrideValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterOverrideValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterOverrideValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterOverrideValueSet.Iid); + writer.WriteString("manual"u8, parameterOverrideValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterOverrideValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterValueSet"u8); + writer.WriteStringValue(parameterOverrideValueSet.ParameterValueSet); + writer.WriteString("published"u8, parameterOverrideValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterOverrideValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterOverrideValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterOverrideValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterOverrideValueSet.ValueSwitch.ToString()); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var parameterOverrideValueSet = thing as ParameterOverrideValueSet; - if (parameterOverrideValueSet == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParameterOverrideValueSet."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(parameterOverrideValueSet); + break; + case "computed": + writer.WriteString("computed"u8, ((ValueArray)value).ToJsonString()); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "formula": + writer.WriteString("formula"u8, ((ValueArray)value).ToJsonString()); + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "manual": + writer.WriteString("manual"u8, ((ValueArray)value).ToJsonString()); + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametervalueset": + writer.WritePropertyName("parameterValueSet"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "published": + writer.WriteString("published"u8, ((ValueArray)value).ToJsonString()); + break; + case "reference": + writer.WriteString("reference"u8, ((ValueArray)value).ToJsonString()); + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueswitch": + writer.WritePropertyName("valueSwitch"u8); + + if(value != null) + { + writer.WriteStringValue(((ParameterSwitchKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterOverrideValueSet"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "computed", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "formula", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "manual", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValueSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "published", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "reference", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSwitch", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs index 442cb4ac5..745cd888d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Parameter = CDP4Common.DTO.Parameter; /// /// The purpose of the class is to provide a specific serializer @@ -45,88 +50,877 @@ namespace CDP4JsonSerializer public class ParameterSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "allowDifferentOwnerOfOverride", allowDifferentOwnerOfOverride => new JValue(allowDifferentOwnerOfOverride) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "expectsOverride", expectsOverride => new JValue(expectsOverride) }, - { "group", group => new JValue(group) }, - { "iid", iid => new JValue(iid) }, - { "isOptionDependent", isOptionDependent => new JValue(isOptionDependent) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "parameterSubscription", parameterSubscription => new JArray(parameterSubscription) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "requestedBy", requestedBy => new JValue(requestedBy) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "stateDependence", stateDependence => new JValue(stateDependence) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSet", valueSet => new JArray(valueSet) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(Parameter parameter) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("allowDifferentOwnerOfOverride", this.PropertySerializerMap["allowDifferentOwnerOfOverride"](parameter.AllowDifferentOwnerOfOverride)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameter.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameter.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameter.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("expectsOverride", this.PropertySerializerMap["expectsOverride"](parameter.ExpectsOverride)); - jsonObject.Add("group", this.PropertySerializerMap["group"](parameter.Group)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameter.Iid)); - jsonObject.Add("isOptionDependent", this.PropertySerializerMap["isOptionDependent"](parameter.IsOptionDependent)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameter.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](parameter.Owner)); - jsonObject.Add("parameterSubscription", this.PropertySerializerMap["parameterSubscription"](parameter.ParameterSubscription.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](parameter.ParameterType)); - jsonObject.Add("requestedBy", this.PropertySerializerMap["requestedBy"](parameter.RequestedBy)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameter.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](parameter.Scale)); - jsonObject.Add("stateDependence", this.PropertySerializerMap["stateDependence"](parameter.StateDependence)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameter.ThingPreference)); - jsonObject.Add("valueSet", this.PropertySerializerMap["valueSet"](parameter.ValueSet.OrderBy(x => x, this.guidComparer))); - return jsonObject; + if (thing is not Parameter parameter) + { + throw new ArgumentException("The thing shall be a Parameter", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Parameter."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Parameter since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Parameter for Version 1.0.0"); + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WritePropertyName("expectsOverride"u8); + writer.WriteBooleanValue(parameter.ExpectsOverride); + writer.WritePropertyName("group"u8); + + if (parameter.Group.HasValue) + { + writer.WriteStringValue(parameter.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameter.Iid); + writer.WritePropertyName("isOptionDependent"u8); + writer.WriteBooleanValue(parameter.IsOptionDependent); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameter.Owner); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameter.ParameterType); + writer.WritePropertyName("requestedBy"u8); + + if (parameter.RequestedBy.HasValue) + { + writer.WriteStringValue(parameter.RequestedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameter.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (parameter.Scale.HasValue) + { + writer.WriteStringValue(parameter.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("stateDependence"u8); + + if (parameter.StateDependence.HasValue) + { + writer.WriteStringValue(parameter.StateDependence.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Parameter for Version 1.1.0"); + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("expectsOverride"u8); + writer.WriteBooleanValue(parameter.ExpectsOverride); + writer.WritePropertyName("group"u8); + + if (parameter.Group.HasValue) + { + writer.WriteStringValue(parameter.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameter.Iid); + writer.WritePropertyName("isOptionDependent"u8); + writer.WriteBooleanValue(parameter.IsOptionDependent); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameter.Owner); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameter.ParameterType); + writer.WritePropertyName("requestedBy"u8); + + if (parameter.RequestedBy.HasValue) + { + writer.WriteStringValue(parameter.RequestedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameter.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (parameter.Scale.HasValue) + { + writer.WriteStringValue(parameter.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("stateDependence"u8); + + if (parameter.StateDependence.HasValue) + { + writer.WriteStringValue(parameter.StateDependence.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Parameter for Version 1.2.0"); + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("expectsOverride"u8); + writer.WriteBooleanValue(parameter.ExpectsOverride); + writer.WritePropertyName("group"u8); + + if (parameter.Group.HasValue) + { + writer.WriteStringValue(parameter.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameter.Iid); + writer.WritePropertyName("isOptionDependent"u8); + writer.WriteBooleanValue(parameter.IsOptionDependent); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameter.Owner); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameter.ParameterType); + writer.WritePropertyName("requestedBy"u8); + + if (parameter.RequestedBy.HasValue) + { + writer.WriteStringValue(parameter.RequestedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameter.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (parameter.Scale.HasValue) + { + writer.WriteStringValue(parameter.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("stateDependence"u8); + + if (parameter.StateDependence.HasValue) + { + writer.WriteStringValue(parameter.StateDependence.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameter.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Parameter for Version 1.3.0"); + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameter.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("expectsOverride"u8); + writer.WriteBooleanValue(parameter.ExpectsOverride); + writer.WritePropertyName("group"u8); + + if (parameter.Group.HasValue) + { + writer.WriteStringValue(parameter.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameter.Iid); + writer.WritePropertyName("isOptionDependent"u8); + writer.WriteBooleanValue(parameter.IsOptionDependent); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameter.Owner); + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameter.ParameterType); + writer.WritePropertyName("requestedBy"u8); + + if (parameter.RequestedBy.HasValue) + { + writer.WriteStringValue(parameter.RequestedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameter.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (parameter.Scale.HasValue) + { + writer.WriteStringValue(parameter.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("stateDependence"u8); + + if (parameter.StateDependence.HasValue) + { + writer.WriteStringValue(parameter.StateDependence.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameter.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Parameter parameter) + { + throw new ArgumentException("The thing shall be a Parameter", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + writer.WriteBooleanValue(parameter.AllowDifferentOwnerOfOverride); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameter.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameter.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameter.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("expectsOverride"u8); + writer.WriteBooleanValue(parameter.ExpectsOverride); + writer.WritePropertyName("group"u8); + + if (parameter.Group.HasValue) + { + writer.WriteStringValue(parameter.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameter.Iid); + writer.WritePropertyName("isOptionDependent"u8); + writer.WriteBooleanValue(parameter.IsOptionDependent); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameter.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameter.Owner); + + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in parameter.ParameterSubscription.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameter.ParameterType); + writer.WritePropertyName("requestedBy"u8); + + if (parameter.RequestedBy.HasValue) + { + writer.WriteStringValue(parameter.RequestedBy.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameter.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (parameter.Scale.HasValue) + { + writer.WriteStringValue(parameter.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("stateDependence"u8); + + if (parameter.StateDependence.HasValue) + { + writer.WriteStringValue(parameter.StateDependence.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameter.ThingPreference); + + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameter.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var parameter = thing as Parameter; - if (parameter == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Parameter."); - } + case "allowdifferentownerofoverride": + writer.WritePropertyName("allowDifferentOwnerOfOverride"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "expectsoverride": + writer.WritePropertyName("expectsOverride"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "group": + writer.WritePropertyName("group"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isoptiondependent": + writer.WritePropertyName("isOptionDependent"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(parameter); + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametersubscription": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListParameterSubscription && objectListParameterSubscription.Any()) + { + writer.WriteStartArray("parameterSubscription"u8); + + foreach(var parameterSubscriptionItem in objectListParameterSubscription.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterSubscriptionItem); + } + writer.WriteEndArray(); + } + break; + case "parametertype": + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "requestedby": + writer.WritePropertyName("requestedBy"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "statedependence": + writer.WritePropertyName("stateDependence"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueset": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListValueSet && objectListValueSet.Any()) + { + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in objectListValueSet.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Parameter"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "allowDifferentOwnerOfOverride", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "expectsOverride", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "group", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isOptionDependent", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterSubscription", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "requestedBy", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "stateDependence", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs index 410339886..31843c6c3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterSubscription = CDP4Common.DTO.ParameterSubscription; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +50,441 @@ namespace CDP4JsonSerializer public class ParameterSubscriptionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSet", valueSet => new JArray(valueSet) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ParameterSubscription parameterSubscription) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterSubscription.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterSubscription.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterSubscription.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterSubscription.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterSubscription.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](parameterSubscription.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterSubscription.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterSubscription.ThingPreference)); - jsonObject.Add("valueSet", this.PropertySerializerMap["valueSet"](parameterSubscription.ValueSet.OrderBy(x => x, this.guidComparer))); - return jsonObject; + if (thing is not ParameterSubscription parameterSubscription) + { + throw new ArgumentException("The thing shall be a ParameterSubscription", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParameterSubscription."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterSubscription since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscription for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscription for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscription.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscription for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscription.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscription.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscription for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscription.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscription.ThingPreference); + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ParameterSubscription parameterSubscription) + { + throw new ArgumentException("The thing shall be a ParameterSubscription", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscription.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscription.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscription.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscription.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscription.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(parameterSubscription.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscription.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscription.ThingPreference); + + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in parameterSubscription.ValueSet.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var parameterSubscription = thing as ParameterSubscription; - if (parameterSubscription == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParameterSubscription."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(parameterSubscription); + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueset": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListValueSet && objectListValueSet.Any()) + { + writer.WriteStartArray("valueSet"u8); + + foreach(var valueSetItem in objectListValueSet.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueSetItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterSubscription"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs index ec882c012..702f1096c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterSubscriptionValueSetSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterSubscriptionValueSet = CDP4Common.DTO.ParameterSubscriptionValueSet; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +50,410 @@ namespace CDP4JsonSerializer public class ParameterSubscriptionValueSetSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "manual", manual => new JValue(((ValueArray)manual).ToJsonString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "subscribedValueSet", subscribedValueSet => new JValue(subscribedValueSet) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSwitch", valueSwitch => new JValue(valueSwitch.ToString()) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(ParameterSubscriptionValueSet parameterSubscriptionValueSet) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterSubscriptionValueSet.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterSubscriptionValueSet.Iid)); - jsonObject.Add("manual", this.PropertySerializerMap["manual"](parameterSubscriptionValueSet.Manual)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterSubscriptionValueSet.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterSubscriptionValueSet.RevisionNumber)); - jsonObject.Add("subscribedValueSet", this.PropertySerializerMap["subscribedValueSet"](parameterSubscriptionValueSet.SubscribedValueSet)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterSubscriptionValueSet.ThingPreference)); - jsonObject.Add("valueSwitch", this.PropertySerializerMap["valueSwitch"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.ParameterSwitchKind), parameterSubscriptionValueSet.ValueSwitch))); - return jsonObject; + if (thing is not ParameterSubscriptionValueSet parameterSubscriptionValueSet) + { + throw new ArgumentException("The thing shall be a ParameterSubscriptionValueSet", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParameterSubscriptionValueSet."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterSubscriptionValueSet since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscriptionValueSet for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscriptionValueSet for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscriptionValueSet for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterSubscriptionValueSet for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ParameterSubscriptionValueSet parameterSubscriptionValueSet) + { + throw new ArgumentException("The thing shall be a ParameterSubscriptionValueSet", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterSubscriptionValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterSubscriptionValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.Iid); + writer.WriteString("manual"u8, parameterSubscriptionValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterSubscriptionValueSet.RevisionNumber); + writer.WritePropertyName("subscribedValueSet"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.SubscribedValueSet); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterSubscriptionValueSet.ValueSwitch.ToString()); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var parameterSubscriptionValueSet = thing as ParameterSubscriptionValueSet; - if (parameterSubscriptionValueSet == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParameterSubscriptionValueSet."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(parameterSubscriptionValueSet); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "manual": + writer.WriteString("manual"u8, ((ValueArray)value).ToJsonString()); + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "subscribedvalueset": + writer.WritePropertyName("subscribedValueSet"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueswitch": + writer.WritePropertyName("valueSwitch"u8); + + if(value != null) + { + writer.WriteStringValue(((ParameterSwitchKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterSubscriptionValueSet"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "manual", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "subscribedValueSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSwitch", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs index 6f50b7afc..af143ec3c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterTypeComponentSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterTypeComponent = CDP4Common.DTO.ParameterTypeComponent; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +50,470 @@ namespace CDP4JsonSerializer public class ParameterTypeComponentSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ParameterTypeComponent parameterTypeComponent) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterTypeComponent.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterTypeComponent.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterTypeComponent.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](parameterTypeComponent.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterTypeComponent.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](parameterTypeComponent.Scale)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](parameterTypeComponent.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterTypeComponent.ThingPreference)); - return jsonObject; + if (thing is not ParameterTypeComponent parameterTypeComponent) + { + throw new ArgumentException("The thing shall be a ParameterTypeComponent", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParameterTypeComponent."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterTypeComponent since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterTypeComponent for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterTypeComponent for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterTypeComponent.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterTypeComponent for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterTypeComponent.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterTypeComponent.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterTypeComponent for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterTypeComponent.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterTypeComponent.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ParameterTypeComponent parameterTypeComponent) + { + throw new ArgumentException("The thing shall be a ParameterTypeComponent", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterTypeComponent.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterTypeComponent.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterTypeComponent.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterTypeComponent.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterTypeComponent.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(parameterTypeComponent.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterTypeComponent.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (parameterTypeComponent.Scale.HasValue) + { + writer.WriteStringValue(parameterTypeComponent.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterTypeComponent.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterTypeComponent.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var parameterTypeComponent = thing as ParameterTypeComponent; - if (parameterTypeComponent == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParameterTypeComponent."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(parameterTypeComponent); + break; + case "scale": + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterTypeComponent"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs index a38d0e214..bdf128dfa 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterValueSetSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterValueSet = CDP4Common.DTO.ParameterValueSet; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +50,560 @@ namespace CDP4JsonSerializer public class ParameterValueSetSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "actualOption", actualOption => new JValue(actualOption) }, - { "actualState", actualState => new JValue(actualState) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "computed", computed => new JValue(((ValueArray)computed).ToJsonString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "formula", formula => new JValue(((ValueArray)formula).ToJsonString()) }, - { "iid", iid => new JValue(iid) }, - { "manual", manual => new JValue(((ValueArray)manual).ToJsonString()) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "published", published => new JValue(((ValueArray)published).ToJsonString()) }, - { "reference", reference => new JValue(((ValueArray)reference).ToJsonString()) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueSwitch", valueSwitch => new JValue(valueSwitch.ToString()) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ParameterValueSet parameterValueSet) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("actualOption", this.PropertySerializerMap["actualOption"](parameterValueSet.ActualOption)); - jsonObject.Add("actualState", this.PropertySerializerMap["actualState"](parameterValueSet.ActualState)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterValueSet.ClassKind))); - jsonObject.Add("computed", this.PropertySerializerMap["computed"](parameterValueSet.Computed)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterValueSet.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterValueSet.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("formula", this.PropertySerializerMap["formula"](parameterValueSet.Formula)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterValueSet.Iid)); - jsonObject.Add("manual", this.PropertySerializerMap["manual"](parameterValueSet.Manual)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterValueSet.ModifiedOn)); - jsonObject.Add("published", this.PropertySerializerMap["published"](parameterValueSet.Published)); - jsonObject.Add("reference", this.PropertySerializerMap["reference"](parameterValueSet.Reference)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterValueSet.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterValueSet.ThingPreference)); - jsonObject.Add("valueSwitch", this.PropertySerializerMap["valueSwitch"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.ParameterSwitchKind), parameterValueSet.ValueSwitch))); - return jsonObject; + if (thing is not ParameterValueSet parameterValueSet) + { + throw new ArgumentException("The thing shall be a ParameterValueSet", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParameterValueSet."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterValueSet since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterValueSet for Version 1.0.0"); + writer.WritePropertyName("actualOption"u8); + + if (parameterValueSet.ActualOption.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualState"u8); + + if (parameterValueSet.ActualState.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); + writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterValueSet.Iid); + writer.WriteString("manual"u8, parameterValueSet.Manual.ToJsonString()); + writer.WriteString("published"u8, parameterValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterValueSet.RevisionNumber); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterValueSet.ValueSwitch.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterValueSet for Version 1.1.0"); + writer.WritePropertyName("actualOption"u8); + + if (parameterValueSet.ActualOption.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualState"u8); + + if (parameterValueSet.ActualState.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterValueSet.Iid); + writer.WriteString("manual"u8, parameterValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteString("published"u8, parameterValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterValueSet.RevisionNumber); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterValueSet.ValueSwitch.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterValueSet for Version 1.2.0"); + writer.WritePropertyName("actualOption"u8); + + if (parameterValueSet.ActualOption.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualState"u8); + + if (parameterValueSet.ActualState.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterValueSet.Iid); + writer.WriteString("manual"u8, parameterValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteString("published"u8, parameterValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterValueSet.ValueSwitch.ToString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterValueSet for Version 1.3.0"); + writer.WritePropertyName("actualOption"u8); + + if (parameterValueSet.ActualOption.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualState"u8); + + if (parameterValueSet.ActualState.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterValueSet.Iid); + writer.WriteString("manual"u8, parameterValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteString("published"u8, parameterValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterValueSet.ValueSwitch.ToString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ParameterValueSet parameterValueSet) + { + throw new ArgumentException("The thing shall be a ParameterValueSet", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("actualOption"u8); + + if (parameterValueSet.ActualOption.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualOption.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("actualState"u8); + + if (parameterValueSet.ActualState.HasValue) + { + writer.WriteStringValue(parameterValueSet.ActualState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterValueSet.ClassKind.ToString()); + writer.WriteString("computed"u8, parameterValueSet.Computed.ToJsonString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterValueSet.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterValueSet.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteString("formula"u8, parameterValueSet.Formula.ToJsonString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterValueSet.Iid); + writer.WriteString("manual"u8, parameterValueSet.Manual.ToJsonString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterValueSet.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteString("published"u8, parameterValueSet.Published.ToJsonString()); + writer.WriteString("reference"u8, parameterValueSet.Reference.ToJsonString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterValueSet.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterValueSet.ThingPreference); + writer.WritePropertyName("valueSwitch"u8); + writer.WriteStringValue(parameterValueSet.ValueSwitch.ToString()); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var parameterValueSet = thing as ParameterValueSet; - if (parameterValueSet == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParameterValueSet."); - } + case "actualoption": + writer.WritePropertyName("actualOption"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "actualstate": + writer.WritePropertyName("actualState"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "computed": + writer.WriteString("computed"u8, ((ValueArray)value).ToJsonString()); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "formula": + writer.WriteString("formula"u8, ((ValueArray)value).ToJsonString()); + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(parameterValueSet); + break; + case "manual": + writer.WriteString("manual"u8, ((ValueArray)value).ToJsonString()); + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "published": + writer.WriteString("published"u8, ((ValueArray)value).ToJsonString()); + break; + case "reference": + writer.WriteString("reference"u8, ((ValueArray)value).ToJsonString()); + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valueswitch": + writer.WritePropertyName("valueSwitch"u8); + + if(value != null) + { + writer.WriteStringValue(((ParameterSwitchKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterValueSet"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "actualOption", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "actualState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "computed", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "formula", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "manual", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "published", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "reference", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueSwitch", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs index bca9f2207..ff1f730c2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParameterizedCategoryRuleSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParameterizedCategoryRule = CDP4Common.DTO.ParameterizedCategoryRule; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +50,704 @@ namespace CDP4JsonSerializer public class ParameterizedCategoryRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JValue(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "parameterType", parameterType => new JArray(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ParameterizedCategoryRule parameterizedCategoryRule) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](parameterizedCategoryRule.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](parameterizedCategoryRule.Category)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parameterizedCategoryRule.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](parameterizedCategoryRule.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parameterizedCategoryRule.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](parameterizedCategoryRule.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parameterizedCategoryRule.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](parameterizedCategoryRule.Name)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parameterizedCategoryRule.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](parameterizedCategoryRule.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parameterizedCategoryRule.ThingPreference)); - return jsonObject; + if (thing is not ParameterizedCategoryRule parameterizedCategoryRule) + { + throw new ArgumentException("The thing shall be a ParameterizedCategoryRule", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParameterizedCategoryRule."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParameterizedCategoryRule since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterizedCategoryRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParameterizedCategoryRule for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterizedCategoryRule.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ParameterizedCategoryRule parameterizedCategoryRule) + { + throw new ArgumentException("The thing shall be a ParameterizedCategoryRule", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in parameterizedCategoryRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("category"u8); + writer.WriteStringValue(parameterizedCategoryRule.Category); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parameterizedCategoryRule.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in parameterizedCategoryRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parameterizedCategoryRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parameterizedCategoryRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in parameterizedCategoryRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parameterizedCategoryRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(parameterizedCategoryRule.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parameterizedCategoryRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(parameterizedCategoryRule.Name); + + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in parameterizedCategoryRule.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parameterizedCategoryRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(parameterizedCategoryRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parameterizedCategoryRule.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var parameterizedCategoryRule = thing as ParameterizedCategoryRule; - if (parameterizedCategoryRule == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParameterizedCategoryRule."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + writer.WritePropertyName("category"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(parameterizedCategoryRule); + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListParameterType && objectListParameterType.Any()) + { + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParameterizedCategoryRule"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs index 89fc9fc6b..c9f9a5616 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParametricConstraintSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParametricConstraint = CDP4Common.DTO.ParametricConstraint; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +50,485 @@ namespace CDP4JsonSerializer public class ParametricConstraintSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "expression", expression => new JArray(expression) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "topExpression", topExpression => new JValue(topExpression) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ParametricConstraint parametricConstraint) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), parametricConstraint.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](parametricConstraint.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](parametricConstraint.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("expression", this.PropertySerializerMap["expression"](parametricConstraint.Expression.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](parametricConstraint.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](parametricConstraint.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](parametricConstraint.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](parametricConstraint.ThingPreference)); - jsonObject.Add("topExpression", this.PropertySerializerMap["topExpression"](parametricConstraint.TopExpression)); - return jsonObject; + if (thing is not ParametricConstraint parametricConstraint) + { + throw new ArgumentException("The thing shall be a ParametricConstraint", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParametricConstraint."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParametricConstraint since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + writer.WriteStartArray("expression"u8); + + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parametricConstraint.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parametricConstraint.RevisionNumber); + writer.WritePropertyName("topExpression"u8); + + if (parametricConstraint.TopExpression.HasValue) + { + writer.WriteStringValue(parametricConstraint.TopExpression.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("expression"u8); + + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parametricConstraint.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parametricConstraint.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parametricConstraint.RevisionNumber); + writer.WritePropertyName("topExpression"u8); + + if (parametricConstraint.TopExpression.HasValue) + { + writer.WriteStringValue(parametricConstraint.TopExpression.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("expression"u8); + + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parametricConstraint.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parametricConstraint.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parametricConstraint.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parametricConstraint.ThingPreference); + writer.WritePropertyName("topExpression"u8); + + if (parametricConstraint.TopExpression.HasValue) + { + writer.WriteStringValue(parametricConstraint.TopExpression.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParametricConstraint for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("expression"u8); + + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parametricConstraint.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parametricConstraint.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parametricConstraint.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parametricConstraint.ThingPreference); + writer.WritePropertyName("topExpression"u8); + + if (parametricConstraint.TopExpression.HasValue) + { + writer.WriteStringValue(parametricConstraint.TopExpression.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ParametricConstraint parametricConstraint) + { + throw new ArgumentException("The thing shall be a ParametricConstraint", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(parametricConstraint.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in parametricConstraint.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in parametricConstraint.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("expression"u8); + + foreach(var expressionItem in parametricConstraint.Expression.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(parametricConstraint.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(parametricConstraint.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(parametricConstraint.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(parametricConstraint.ThingPreference); + writer.WritePropertyName("topExpression"u8); + + if (parametricConstraint.TopExpression.HasValue) + { + writer.WriteStringValue(parametricConstraint.TopExpression.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var parametricConstraint = thing as ParametricConstraint; - if (parametricConstraint == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParametricConstraint."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "expression": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExpression && objectListExpression.Any()) + { + writer.WriteStartArray("expression"u8); + + foreach(var expressionItem in objectListExpression.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(expressionItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(parametricConstraint); + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "topexpression": + writer.WritePropertyName("topExpression"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParametricConstraint"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "expression", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "topExpression", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs index 2365de57a..8ae023350 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantPermissionSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParticipantPermission = CDP4Common.DTO.ParticipantPermission; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +50,425 @@ namespace CDP4JsonSerializer public class ParticipantPermissionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "accessRight", accessRight => new JValue(accessRight.ToString()) }, - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "objectClass", objectClass => new JValue(objectClass.ToString()) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(ParticipantPermission participantPermission) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("accessRight", this.PropertySerializerMap["accessRight"](Enum.GetName(typeof(CDP4Common.CommonData.ParticipantAccessRightKind), participantPermission.AccessRight))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), participantPermission.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](participantPermission.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](participantPermission.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](participantPermission.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](participantPermission.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](participantPermission.ModifiedOn)); - jsonObject.Add("objectClass", this.PropertySerializerMap["objectClass"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), participantPermission.ObjectClass))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](participantPermission.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](participantPermission.ThingPreference)); - return jsonObject; + if (thing is not ParticipantPermission participantPermission) + { + throw new ArgumentException("The thing shall be a ParticipantPermission", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParticipantPermission."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParticipantPermission since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantPermission for Version 1.0.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantPermission for Version 1.1.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantPermission for Version 1.2.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantPermission.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantPermission for Version 1.3.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantPermission.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ParticipantPermission participantPermission) + { + throw new ArgumentException("The thing shall be a ParticipantPermission", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(participantPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantPermission.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(participantPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantPermission.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var participantPermission = thing as ParticipantPermission; - if (participantPermission == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParticipantPermission."); - } + case "accessright": + writer.WritePropertyName("accessRight"u8); + + if(value != null) + { + writer.WriteStringValue(((ParticipantAccessRightKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(participantPermission); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "objectclass": + writer.WritePropertyName("objectClass"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParticipantPermission"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "accessRight", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "objectClass", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs index 5448bd2c0..20c6912cf 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantRoleSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ParticipantRole = CDP4Common.DTO.ParticipantRole; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +50,680 @@ namespace CDP4JsonSerializer public class ParticipantRoleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "participantPermission", participantPermission => new JArray(participantPermission) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ParticipantRole participantRole) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](participantRole.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), participantRole.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](participantRole.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](participantRole.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](participantRole.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](participantRole.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](participantRole.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](participantRole.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](participantRole.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](participantRole.Name)); - jsonObject.Add("participantPermission", this.PropertySerializerMap["participantPermission"](participantRole.ParticipantPermission.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](participantRole.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](participantRole.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](participantRole.ThingPreference)); - return jsonObject; + if (thing is not ParticipantRole participantRole) + { + throw new ArgumentException("The thing shall be a ParticipantRole", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ParticipantRole."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ParticipantRole since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantRole.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ParticipantRole for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantRole.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ParticipantRole participantRole) + { + throw new ArgumentException("The thing shall be a ParticipantRole", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in participantRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participantRole.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in participantRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participantRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participantRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in participantRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participantRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(participantRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participantRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(participantRole.Name); + + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in participantRole.ParticipantPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participantRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(participantRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participantRole.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var participantRole = thing as ParticipantRole; - if (participantRole == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ParticipantRole."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(participantRole); + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "participantpermission": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListParticipantPermission && objectListParticipantPermission.Any()) + { + writer.WriteStartArray("participantPermission"u8); + + foreach(var participantPermissionItem in objectListParticipantPermission.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantPermissionItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ParticipantRole"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "participantPermission", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs index 55b6e0d5f..e6a1ac2c9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ParticipantSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Participant = CDP4Common.DTO.Participant; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +50,513 @@ namespace CDP4JsonSerializer public class ParticipantSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "domain", domain => new JArray(domain) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isActive", isActive => new JValue(isActive) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "person", person => new JValue(person) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "role", role => new JValue(role) }, - { "selectedDomain", selectedDomain => new JValue(selectedDomain) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(Participant participant) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), participant.ClassKind))); - jsonObject.Add("domain", this.PropertySerializerMap["domain"](participant.Domain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](participant.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](participant.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](participant.Iid)); - jsonObject.Add("isActive", this.PropertySerializerMap["isActive"](participant.IsActive)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](participant.ModifiedOn)); - jsonObject.Add("person", this.PropertySerializerMap["person"](participant.Person)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](participant.RevisionNumber)); - jsonObject.Add("role", this.PropertySerializerMap["role"](participant.Role)); - jsonObject.Add("selectedDomain", this.PropertySerializerMap["selectedDomain"](participant.SelectedDomain)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](participant.ThingPreference)); - return jsonObject; + if (thing is not Participant participant) + { + throw new ArgumentException("The thing shall be a Participant", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Participant."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Participant since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participant.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Participant for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participant.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Participant participant) + { + throw new ArgumentException("The thing shall be a Participant", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(participant.ClassKind.ToString()); + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in participant.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in participant.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in participant.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(participant.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(participant.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(participant.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("person"u8); + writer.WriteStringValue(participant.Person); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(participant.RevisionNumber); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(participant.Role); + writer.WritePropertyName("selectedDomain"u8); + writer.WriteStringValue(participant.SelectedDomain); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(participant.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var participant = thing as Participant; - if (participant == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Participant."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(participant); + break; + case "domain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDomain && objectListDomain.Any()) + { + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isactive": + writer.WritePropertyName("isActive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "person": + writer.WritePropertyName("person"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "role": + writer.WritePropertyName("role"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "selecteddomain": + writer.WritePropertyName("selectedDomain"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Participant"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "domain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isActive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "person", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "role", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "selectedDomain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs index b7523c936..d9e5e85b8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonPermissionSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using PersonPermission = CDP4Common.DTO.PersonPermission; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +50,425 @@ namespace CDP4JsonSerializer public class PersonPermissionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "accessRight", accessRight => new JValue(accessRight.ToString()) }, - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "objectClass", objectClass => new JValue(objectClass.ToString()) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(PersonPermission personPermission) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("accessRight", this.PropertySerializerMap["accessRight"](Enum.GetName(typeof(CDP4Common.CommonData.PersonAccessRightKind), personPermission.AccessRight))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), personPermission.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](personPermission.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](personPermission.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](personPermission.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](personPermission.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](personPermission.ModifiedOn)); - jsonObject.Add("objectClass", this.PropertySerializerMap["objectClass"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), personPermission.ObjectClass))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](personPermission.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](personPermission.ThingPreference)); - return jsonObject; + if (thing is not PersonPermission personPermission) + { + throw new ArgumentException("The thing shall be a PersonPermission", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of PersonPermission."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of PersonPermission since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing PersonPermission for Version 1.0.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing PersonPermission for Version 1.1.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing PersonPermission for Version 1.2.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personPermission.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing PersonPermission for Version 1.3.0"); + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personPermission.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not PersonPermission personPermission) + { + throw new ArgumentException("The thing shall be a PersonPermission", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("accessRight"u8); + writer.WriteStringValue(personPermission.AccessRight.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personPermission.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personPermission.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personPermission.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personPermission.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personPermission.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personPermission.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("objectClass"u8); + writer.WriteStringValue(personPermission.ObjectClass.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personPermission.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personPermission.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var personPermission = thing as PersonPermission; - if (personPermission == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a PersonPermission."); - } + case "accessright": + writer.WritePropertyName("accessRight"u8); + + if(value != null) + { + writer.WriteStringValue(((PersonAccessRightKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(personPermission); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "objectclass": + writer.WritePropertyName("objectClass"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the PersonPermission"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "accessRight", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "objectClass", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs index 913c625f5..9f95cfae6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonRoleSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using PersonRole = CDP4Common.DTO.PersonRole; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +50,680 @@ namespace CDP4JsonSerializer public class PersonRoleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "personPermission", personPermission => new JArray(personPermission) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(PersonRole personRole) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](personRole.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), personRole.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](personRole.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](personRole.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](personRole.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](personRole.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](personRole.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](personRole.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](personRole.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](personRole.Name)); - jsonObject.Add("personPermission", this.PropertySerializerMap["personPermission"](personRole.PersonPermission.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](personRole.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](personRole.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](personRole.ThingPreference)); - return jsonObject; + if (thing is not PersonRole personRole) + { + throw new ArgumentException("The thing shall be a PersonRole", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of PersonRole."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of PersonRole since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personRole.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing PersonRole for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personRole.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not PersonRole personRole) + { + throw new ArgumentException("The thing shall be a PersonRole", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in personRole.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(personRole.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in personRole.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in personRole.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in personRole.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in personRole.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(personRole.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(personRole.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(personRole.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(personRole.Name); + + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in personRole.PersonPermission.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(personRole.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(personRole.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(personRole.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var personRole = thing as PersonRole; - if (personRole == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a PersonRole."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(personRole); + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "personpermission": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListPersonPermission && objectListPersonPermission.Any()) + { + writer.WriteStartArray("personPermission"u8); + + foreach(var personPermissionItem in objectListPersonPermission.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personPermissionItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the PersonRole"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "personPermission", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs index badf6622e..d442f541b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PersonSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Person = CDP4Common.DTO.Person; /// /// The purpose of the class is to provide a specific serializer @@ -45,96 +50,1057 @@ namespace CDP4JsonSerializer public class PersonSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultDomain", defaultDomain => new JValue(defaultDomain) }, - { "defaultEmailAddress", defaultEmailAddress => new JValue(defaultEmailAddress) }, - { "defaultTelephoneNumber", defaultTelephoneNumber => new JValue(defaultTelephoneNumber) }, - { "emailAddress", emailAddress => new JArray(emailAddress) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "givenName", givenName => new JValue(givenName) }, - { "iid", iid => new JValue(iid) }, - { "isActive", isActive => new JValue(isActive) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "organization", organization => new JValue(organization) }, - { "organizationalUnit", organizationalUnit => new JValue(organizationalUnit) }, - { "password", password => new JValue(password) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "role", role => new JValue(role) }, - { "shortName", shortName => new JValue(shortName) }, - { "surname", surname => new JValue(surname) }, - { "telephoneNumber", telephoneNumber => new JArray(telephoneNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "userPreference", userPreference => new JArray(userPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(Person person) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), person.ClassKind))); - jsonObject.Add("defaultDomain", this.PropertySerializerMap["defaultDomain"](person.DefaultDomain)); - jsonObject.Add("defaultEmailAddress", this.PropertySerializerMap["defaultEmailAddress"](person.DefaultEmailAddress)); - jsonObject.Add("defaultTelephoneNumber", this.PropertySerializerMap["defaultTelephoneNumber"](person.DefaultTelephoneNumber)); - jsonObject.Add("emailAddress", this.PropertySerializerMap["emailAddress"](person.EmailAddress.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](person.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](person.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("givenName", this.PropertySerializerMap["givenName"](person.GivenName)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](person.Iid)); - jsonObject.Add("isActive", this.PropertySerializerMap["isActive"](person.IsActive)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](person.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](person.ModifiedOn)); - jsonObject.Add("organization", this.PropertySerializerMap["organization"](person.Organization)); - jsonObject.Add("organizationalUnit", this.PropertySerializerMap["organizationalUnit"](person.OrganizationalUnit)); - jsonObject.Add("password", this.PropertySerializerMap["password"](person.Password)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](person.RevisionNumber)); - jsonObject.Add("role", this.PropertySerializerMap["role"](person.Role)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](person.ShortName)); - jsonObject.Add("surname", this.PropertySerializerMap["surname"](person.Surname)); - jsonObject.Add("telephoneNumber", this.PropertySerializerMap["telephoneNumber"](person.TelephoneNumber.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](person.ThingPreference)); - jsonObject.Add("userPreference", this.PropertySerializerMap["userPreference"](person.UserPreference.OrderBy(x => x, this.guidComparer))); - return jsonObject; + if (thing is not Person person) + { + throw new ArgumentException("The thing shall be a Person", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Person."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Person since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Person for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(person.ClassKind.ToString()); + writer.WritePropertyName("defaultDomain"u8); + + if (person.DefaultDomain.HasValue) + { + writer.WriteStringValue(person.DefaultDomain.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultEmailAddress"u8); + + if (person.DefaultEmailAddress.HasValue) + { + writer.WriteStringValue(person.DefaultEmailAddress.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if (person.DefaultTelephoneNumber.HasValue) + { + writer.WriteStringValue(person.DefaultTelephoneNumber.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("givenName"u8); + writer.WriteStringValue(person.GivenName); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(person.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(person.IsActive); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(person.IsDeprecated); + writer.WritePropertyName("organization"u8); + + if (person.Organization.HasValue) + { + writer.WriteStringValue(person.Organization.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("organizationalUnit"u8); + writer.WriteStringValue(person.OrganizationalUnit); + writer.WritePropertyName("password"u8); + writer.WriteStringValue(person.Password); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(person.RevisionNumber); + writer.WritePropertyName("role"u8); + + if (person.Role.HasValue) + { + writer.WriteStringValue(person.Role.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(person.ShortName); + writer.WritePropertyName("surname"u8); + writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Person for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(person.ClassKind.ToString()); + writer.WritePropertyName("defaultDomain"u8); + + if (person.DefaultDomain.HasValue) + { + writer.WriteStringValue(person.DefaultDomain.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultEmailAddress"u8); + + if (person.DefaultEmailAddress.HasValue) + { + writer.WriteStringValue(person.DefaultEmailAddress.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if (person.DefaultTelephoneNumber.HasValue) + { + writer.WriteStringValue(person.DefaultTelephoneNumber.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("givenName"u8); + writer.WriteStringValue(person.GivenName); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(person.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(person.IsActive); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(person.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + + if (person.Organization.HasValue) + { + writer.WriteStringValue(person.Organization.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("organizationalUnit"u8); + writer.WriteStringValue(person.OrganizationalUnit); + writer.WritePropertyName("password"u8); + writer.WriteStringValue(person.Password); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(person.RevisionNumber); + writer.WritePropertyName("role"u8); + + if (person.Role.HasValue) + { + writer.WriteStringValue(person.Role.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(person.ShortName); + writer.WritePropertyName("surname"u8); + writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Person for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(person.ClassKind.ToString()); + writer.WritePropertyName("defaultDomain"u8); + + if (person.DefaultDomain.HasValue) + { + writer.WriteStringValue(person.DefaultDomain.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultEmailAddress"u8); + + if (person.DefaultEmailAddress.HasValue) + { + writer.WriteStringValue(person.DefaultEmailAddress.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if (person.DefaultTelephoneNumber.HasValue) + { + writer.WriteStringValue(person.DefaultTelephoneNumber.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("givenName"u8); + writer.WriteStringValue(person.GivenName); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(person.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(person.IsActive); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(person.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + + if (person.Organization.HasValue) + { + writer.WriteStringValue(person.Organization.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("organizationalUnit"u8); + writer.WriteStringValue(person.OrganizationalUnit); + writer.WritePropertyName("password"u8); + writer.WriteStringValue(person.Password); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(person.RevisionNumber); + writer.WritePropertyName("role"u8); + + if (person.Role.HasValue) + { + writer.WriteStringValue(person.Role.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(person.ShortName); + writer.WritePropertyName("surname"u8); + writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(person.ThingPreference); + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Person for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(person.ClassKind.ToString()); + writer.WritePropertyName("defaultDomain"u8); + + if (person.DefaultDomain.HasValue) + { + writer.WriteStringValue(person.DefaultDomain.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultEmailAddress"u8); + + if (person.DefaultEmailAddress.HasValue) + { + writer.WriteStringValue(person.DefaultEmailAddress.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if (person.DefaultTelephoneNumber.HasValue) + { + writer.WriteStringValue(person.DefaultTelephoneNumber.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("givenName"u8); + writer.WriteStringValue(person.GivenName); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(person.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(person.IsActive); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(person.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + + if (person.Organization.HasValue) + { + writer.WriteStringValue(person.Organization.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("organizationalUnit"u8); + writer.WriteStringValue(person.OrganizationalUnit); + writer.WritePropertyName("password"u8); + writer.WriteStringValue(person.Password); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(person.RevisionNumber); + writer.WritePropertyName("role"u8); + + if (person.Role.HasValue) + { + writer.WriteStringValue(person.Role.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(person.ShortName); + writer.WritePropertyName("surname"u8); + writer.WriteStringValue(person.Surname); + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(person.ThingPreference); + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Person person) + { + throw new ArgumentException("The thing shall be a Person", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(person.ClassKind.ToString()); + writer.WritePropertyName("defaultDomain"u8); + + if (person.DefaultDomain.HasValue) + { + writer.WriteStringValue(person.DefaultDomain.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultEmailAddress"u8); + + if (person.DefaultEmailAddress.HasValue) + { + writer.WriteStringValue(person.DefaultEmailAddress.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if (person.DefaultTelephoneNumber.HasValue) + { + writer.WriteStringValue(person.DefaultTelephoneNumber.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in person.EmailAddress.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in person.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in person.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("givenName"u8); + writer.WriteStringValue(person.GivenName); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(person.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(person.IsActive); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(person.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(person.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("organization"u8); + + if (person.Organization.HasValue) + { + writer.WriteStringValue(person.Organization.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("organizationalUnit"u8); + writer.WriteStringValue(person.OrganizationalUnit); + writer.WritePropertyName("password"u8); + writer.WriteStringValue(person.Password); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(person.RevisionNumber); + writer.WritePropertyName("role"u8); + + if (person.Role.HasValue) + { + writer.WriteStringValue(person.Role.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(person.ShortName); + writer.WritePropertyName("surname"u8); + writer.WriteStringValue(person.Surname); + + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in person.TelephoneNumber.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(person.ThingPreference); + + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in person.UserPreference.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var person = thing as Person; - if (person == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Person."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultdomain": + writer.WritePropertyName("defaultDomain"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultemailaddress": + writer.WritePropertyName("defaultEmailAddress"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaulttelephonenumber": + writer.WritePropertyName("defaultTelephoneNumber"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "emailaddress": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListEmailAddress && objectListEmailAddress.Any()) + { + writer.WriteStartArray("emailAddress"u8); + + foreach(var emailAddressItem in objectListEmailAddress.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(emailAddressItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "givenname": + writer.WritePropertyName("givenName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isactive": + writer.WritePropertyName("isActive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(person); + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "organization": + writer.WritePropertyName("organization"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "organizationalunit": + writer.WritePropertyName("organizationalUnit"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "password": + writer.WritePropertyName("password"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "role": + writer.WritePropertyName("role"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "surname": + writer.WritePropertyName("surname"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "telephonenumber": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListTelephoneNumber && objectListTelephoneNumber.Any()) + { + writer.WriteStartArray("telephoneNumber"u8); + + foreach(var telephoneNumberItem in objectListTelephoneNumber.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(telephoneNumberItem); + } + writer.WriteEndArray(); + } + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "userpreference": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListUserPreference && objectListUserPreference.Any()) + { + writer.WriteStartArray("userPreference"u8); + + foreach(var userPreferenceItem in objectListUserPreference.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(userPreferenceItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Person"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultDomain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultEmailAddress", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultTelephoneNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "emailAddress", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "givenName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isActive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "organization", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "organizationalUnit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "password", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "role", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "surname", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "telephoneNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "userPreference", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs index a6761fa54..b5fa7ed99 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PointSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Point = CDP4Common.DTO.Point; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +50,410 @@ namespace CDP4JsonSerializer public class PointSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "x", x => new JValue(x) }, - { "y", y => new JValue(y) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(Point point) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), point.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](point.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](point.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](point.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](point.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](point.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](point.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](point.ThingPreference)); - jsonObject.Add("x", this.PropertySerializerMap["x"](point.X)); - jsonObject.Add("y", this.PropertySerializerMap["y"](point.Y)); - return jsonObject; + if (thing is not Point point) + { + throw new ArgumentException("The thing shall be a Point", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Point."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Point since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Point for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(point.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(point.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(point.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(point.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(point.RevisionNumber); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(point.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(point.Y); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Point for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(point.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(point.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(point.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(point.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(point.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(point.ThingPreference); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(point.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(point.Y); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Point for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(point.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(point.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(point.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(point.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(point.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(point.ThingPreference); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(point.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(point.Y); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Point point) + { + throw new ArgumentException("The thing shall be a Point", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(point.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in point.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in point.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(point.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(point.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(point.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(point.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(point.ThingPreference); + writer.WritePropertyName("x"u8); + writer.WriteNumberValue(point.X); + writer.WritePropertyName("y"u8); + writer.WriteNumberValue(point.Y); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var point = thing as Point; - if (point == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Point."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } - return this.Serialize(point); + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "x": + writer.WritePropertyName("x"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "y": + writer.WritePropertyName("y"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Point"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "x", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "y", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs index 485e31580..b37eb8983 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateListSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using PossibleFiniteStateList = CDP4Common.DTO.PossibleFiniteStateList; /// /// The purpose of the class is to provide a specific serializer @@ -45,84 +50,812 @@ namespace CDP4JsonSerializer public class PossibleFiniteStateListSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultState", defaultState => new JValue(defaultState) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "possibleState", possibleState => new JArray(((IEnumerable)possibleState).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(PossibleFiniteStateList possibleFiniteStateList) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](possibleFiniteStateList.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](possibleFiniteStateList.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), possibleFiniteStateList.ClassKind))); - jsonObject.Add("defaultState", this.PropertySerializerMap["defaultState"](possibleFiniteStateList.DefaultState)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](possibleFiniteStateList.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](possibleFiniteStateList.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](possibleFiniteStateList.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](possibleFiniteStateList.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](possibleFiniteStateList.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](possibleFiniteStateList.Owner)); - jsonObject.Add("possibleState", this.PropertySerializerMap["possibleState"](possibleFiniteStateList.PossibleState.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](possibleFiniteStateList.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](possibleFiniteStateList.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](possibleFiniteStateList.ThingPreference)); - return jsonObject; + if (thing is not PossibleFiniteStateList possibleFiniteStateList) + { + throw new ArgumentException("The thing shall be a PossibleFiniteStateList", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of PossibleFiniteStateList."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of PossibleFiniteStateList since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); + writer.WritePropertyName("defaultState"u8); + + if (possibleFiniteStateList.DefaultState.HasValue) + { + writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteStateList.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteStateList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteStateList.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); + writer.WritePropertyName("defaultState"u8); + + if (possibleFiniteStateList.DefaultState.HasValue) + { + writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteStateList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteStateList.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); + writer.WritePropertyName("defaultState"u8); + + if (possibleFiniteStateList.DefaultState.HasValue) + { + writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteStateList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteStateList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteStateList.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteStateList for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); + writer.WritePropertyName("defaultState"u8); + + if (possibleFiniteStateList.DefaultState.HasValue) + { + writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteStateList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(possibleFiniteStateList.Owner); + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteStateList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteStateList.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not PossibleFiniteStateList possibleFiniteStateList) + { + throw new ArgumentException("The thing shall be a PossibleFiniteStateList", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteStateList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in possibleFiniteStateList.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteStateList.ClassKind.ToString()); + writer.WritePropertyName("defaultState"u8); + + if (possibleFiniteStateList.DefaultState.HasValue) + { + writer.WriteStringValue(possibleFiniteStateList.DefaultState.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteStateList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteStateList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteStateList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteStateList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteStateList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteStateList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteStateList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(possibleFiniteStateList.Owner); + + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in possibleFiniteStateList.PossibleState.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteStateList.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteStateList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteStateList.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var possibleFiniteStateList = thing as PossibleFiniteStateList; - if (possibleFiniteStateList == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a PossibleFiniteStateList."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultstate": + writer.WritePropertyName("defaultState"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); - return this.Serialize(possibleFiniteStateList); + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblestate": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListPossibleState && objectListPossibleState.Any()) + { + writer.WriteStartArray("possibleState"u8); + + foreach(var possibleStateItem in objectListPossibleState.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(possibleStateItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the PossibleFiniteStateList"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleState", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs index 972d0f21f..a420eaaa3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PossibleFiniteStateSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using PossibleFiniteState = CDP4Common.DTO.PossibleFiniteState; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +50,592 @@ namespace CDP4JsonSerializer public class PossibleFiniteStateSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(PossibleFiniteState possibleFiniteState) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](possibleFiniteState.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), possibleFiniteState.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](possibleFiniteState.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](possibleFiniteState.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](possibleFiniteState.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](possibleFiniteState.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](possibleFiniteState.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](possibleFiniteState.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](possibleFiniteState.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](possibleFiniteState.ThingPreference)); - return jsonObject; + if (thing is not PossibleFiniteState possibleFiniteState) + { + throw new ArgumentException("The thing shall be a PossibleFiniteState", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of PossibleFiniteState."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of PossibleFiniteState since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteState.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteState.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteState.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteState.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteState.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteState.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteState.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteState.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteState.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteState.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteState.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteState.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteState.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing PossibleFiniteState for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteState.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteState.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteState.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteState.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteState.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not PossibleFiniteState possibleFiniteState) + { + throw new ArgumentException("The thing shall be a PossibleFiniteState", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in possibleFiniteState.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(possibleFiniteState.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in possibleFiniteState.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in possibleFiniteState.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in possibleFiniteState.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in possibleFiniteState.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(possibleFiniteState.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(possibleFiniteState.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(possibleFiniteState.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(possibleFiniteState.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(possibleFiniteState.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(possibleFiniteState.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var possibleFiniteState = thing as PossibleFiniteState; - if (possibleFiniteState == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a PossibleFiniteState."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); - return this.Serialize(possibleFiniteState); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the PossibleFiniteState"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs index 5c81c9c14..68d70bb57 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PrefixedUnitSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using PrefixedUnit = CDP4Common.DTO.PrefixedUnit; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +50,616 @@ namespace CDP4JsonSerializer public class PrefixedUnitSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "prefix", prefix => new JValue(prefix) }, - { "referenceUnit", referenceUnit => new JValue(referenceUnit) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(PrefixedUnit prefixedUnit) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](prefixedUnit.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), prefixedUnit.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](prefixedUnit.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](prefixedUnit.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](prefixedUnit.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](prefixedUnit.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](prefixedUnit.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](prefixedUnit.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](prefixedUnit.ModifiedOn)); - jsonObject.Add("prefix", this.PropertySerializerMap["prefix"](prefixedUnit.Prefix)); - jsonObject.Add("referenceUnit", this.PropertySerializerMap["referenceUnit"](prefixedUnit.ReferenceUnit)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](prefixedUnit.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](prefixedUnit.ThingPreference)); - return jsonObject; + if (thing is not PrefixedUnit prefixedUnit) + { + throw new ArgumentException("The thing shall be a PrefixedUnit", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of PrefixedUnit."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of PrefixedUnit since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(prefixedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(prefixedUnit.IsDeprecated); + writer.WritePropertyName("prefix"u8); + writer.WriteStringValue(prefixedUnit.Prefix); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(prefixedUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(prefixedUnit.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(prefixedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(prefixedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(prefixedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("prefix"u8); + writer.WriteStringValue(prefixedUnit.Prefix); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(prefixedUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(prefixedUnit.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(prefixedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(prefixedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(prefixedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("prefix"u8); + writer.WriteStringValue(prefixedUnit.Prefix); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(prefixedUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(prefixedUnit.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(prefixedUnit.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing PrefixedUnit for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(prefixedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(prefixedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(prefixedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("prefix"u8); + writer.WriteStringValue(prefixedUnit.Prefix); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(prefixedUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(prefixedUnit.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(prefixedUnit.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not PrefixedUnit prefixedUnit) + { + throw new ArgumentException("The thing shall be a PrefixedUnit", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in prefixedUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(prefixedUnit.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in prefixedUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in prefixedUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in prefixedUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in prefixedUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(prefixedUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(prefixedUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(prefixedUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("prefix"u8); + writer.WriteStringValue(prefixedUnit.Prefix); + writer.WritePropertyName("referenceUnit"u8); + writer.WriteStringValue(prefixedUnit.ReferenceUnit); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(prefixedUnit.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(prefixedUnit.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var prefixedUnit = thing as PrefixedUnit; - if (prefixedUnit == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a PrefixedUnit."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); - return this.Serialize(prefixedUnit); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "prefix": + writer.WritePropertyName("prefix"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referenceunit": + writer.WritePropertyName("referenceUnit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the PrefixedUnit"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "prefix", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceUnit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs index e30e92353..10c69f263 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/PublicationSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Publication = CDP4Common.DTO.Publication; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +50,505 @@ namespace CDP4JsonSerializer public class PublicationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "domain", domain => new JArray(domain) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "publishedParameter", publishedParameter => new JArray(publishedParameter) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(Publication publication) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), publication.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](publication.CreatedOn)); - jsonObject.Add("domain", this.PropertySerializerMap["domain"](publication.Domain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](publication.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](publication.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](publication.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](publication.ModifiedOn)); - jsonObject.Add("publishedParameter", this.PropertySerializerMap["publishedParameter"](publication.PublishedParameter.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](publication.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](publication.ThingPreference)); - return jsonObject; + if (thing is not Publication publication) + { + throw new ArgumentException("The thing shall be a Publication", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Publication."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Publication since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Publication for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Publication for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Publication for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(publication.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Publication for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(publication.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Publication publication) + { + throw new ArgumentException("The thing shall be a Publication", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(publication.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(publication.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in publication.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in publication.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in publication.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(publication.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(publication.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in publication.PublishedParameter.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(publication.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(publication.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var publication = thing as Publication; - if (publication == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Publication."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "domain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDomain && objectListDomain.Any()) + { + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(publication); + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "publishedparameter": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListPublishedParameter && objectListPublishedParameter.Any()) + { + writer.WriteStartArray("publishedParameter"u8); + + foreach(var publishedParameterItem in objectListPublishedParameter.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(publishedParameterItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Publication"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "domain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "publishedParameter", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs index 7cfaf72ac..2a15e45d8 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/QuantityKindFactorSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using QuantityKindFactor = CDP4Common.DTO.QuantityKindFactor; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +50,401 @@ namespace CDP4JsonSerializer public class QuantityKindFactorSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "exponent", exponent => new JValue(exponent) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "quantityKind", quantityKind => new JValue(quantityKind) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(QuantityKindFactor quantityKindFactor) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), quantityKindFactor.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("exponent", this.PropertySerializerMap["exponent"](quantityKindFactor.Exponent)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](quantityKindFactor.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](quantityKindFactor.ModifiedOn)); - jsonObject.Add("quantityKind", this.PropertySerializerMap["quantityKind"](quantityKindFactor.QuantityKind)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](quantityKindFactor.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](quantityKindFactor.ThingPreference)); - return jsonObject; + if (thing is not QuantityKindFactor quantityKindFactor) + { + throw new ArgumentException("The thing shall be a QuantityKindFactor", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of QuantityKindFactor."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of QuantityKindFactor since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing QuantityKindFactor for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing QuantityKindFactor for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(quantityKindFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing QuantityKindFactor for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(quantityKindFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(quantityKindFactor.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing QuantityKindFactor for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(quantityKindFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(quantityKindFactor.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not QuantityKindFactor quantityKindFactor) + { + throw new ArgumentException("The thing shall be a QuantityKindFactor", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(quantityKindFactor.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in quantityKindFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in quantityKindFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(quantityKindFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(quantityKindFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(quantityKindFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("quantityKind"u8); + writer.WriteStringValue(quantityKindFactor.QuantityKind); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(quantityKindFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(quantityKindFactor.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var quantityKindFactor = thing as QuantityKindFactor; - if (quantityKindFactor == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a QuantityKindFactor."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(quantityKindFactor); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "exponent": + writer.WritePropertyName("exponent"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "quantitykind": + writer.WritePropertyName("quantityKind"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the QuantityKindFactor"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "exponent", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "quantityKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs index d1cda6de1..2b09acc5c 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RatioScaleSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RatioScale = CDP4Common.DTO.RatioScale; /// /// The purpose of the class is to provide a specific serializer @@ -45,98 +50,936 @@ namespace CDP4JsonSerializer public class RatioScaleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "isMaximumInclusive", isMaximumInclusive => new JValue(isMaximumInclusive) }, - { "isMinimumInclusive", isMinimumInclusive => new JValue(isMinimumInclusive) }, - { "mappingToReferenceScale", mappingToReferenceScale => new JArray(mappingToReferenceScale) }, - { "maximumPermissibleValue", maximumPermissibleValue => new JValue(maximumPermissibleValue) }, - { "minimumPermissibleValue", minimumPermissibleValue => new JValue(minimumPermissibleValue) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "negativeValueConnotation", negativeValueConnotation => new JValue(negativeValueConnotation) }, - { "numberSet", numberSet => new JValue(numberSet.ToString()) }, - { "positiveValueConnotation", positiveValueConnotation => new JValue(positiveValueConnotation) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - { "valueDefinition", valueDefinition => new JArray(valueDefinition) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(RatioScale ratioScale) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](ratioScale.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), ratioScale.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](ratioScale.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](ratioScale.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](ratioScale.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](ratioScale.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](ratioScale.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](ratioScale.IsDeprecated)); - jsonObject.Add("isMaximumInclusive", this.PropertySerializerMap["isMaximumInclusive"](ratioScale.IsMaximumInclusive)); - jsonObject.Add("isMinimumInclusive", this.PropertySerializerMap["isMinimumInclusive"](ratioScale.IsMinimumInclusive)); - jsonObject.Add("mappingToReferenceScale", this.PropertySerializerMap["mappingToReferenceScale"](ratioScale.MappingToReferenceScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("maximumPermissibleValue", this.PropertySerializerMap["maximumPermissibleValue"](ratioScale.MaximumPermissibleValue)); - jsonObject.Add("minimumPermissibleValue", this.PropertySerializerMap["minimumPermissibleValue"](ratioScale.MinimumPermissibleValue)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](ratioScale.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](ratioScale.Name)); - jsonObject.Add("negativeValueConnotation", this.PropertySerializerMap["negativeValueConnotation"](ratioScale.NegativeValueConnotation)); - jsonObject.Add("numberSet", this.PropertySerializerMap["numberSet"](Enum.GetName(typeof(CDP4Common.SiteDirectoryData.NumberSetKind), ratioScale.NumberSet))); - jsonObject.Add("positiveValueConnotation", this.PropertySerializerMap["positiveValueConnotation"](ratioScale.PositiveValueConnotation)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](ratioScale.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](ratioScale.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](ratioScale.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](ratioScale.Unit)); - jsonObject.Add("valueDefinition", this.PropertySerializerMap["valueDefinition"](ratioScale.ValueDefinition.OrderBy(x => x, this.guidComparer))); - return jsonObject; + if (thing is not RatioScale ratioScale) + { + throw new ArgumentException("The thing shall be a RatioScale", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RatioScale."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RatioScale since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ratioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ratioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ratioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RatioScale for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ratioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ratioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not RatioScale ratioScale) + { + throw new ArgumentException("The thing shall be a RatioScale", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ratioScale.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ratioScale.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ratioScale.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ratioScale.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ratioScale.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ratioScale.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ratioScale.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(ratioScale.IsDeprecated); + writer.WritePropertyName("isMaximumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMaximumInclusive); + writer.WritePropertyName("isMinimumInclusive"u8); + writer.WriteBooleanValue(ratioScale.IsMinimumInclusive); + + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in ratioScale.MappingToReferenceScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("maximumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MaximumPermissibleValue); + writer.WritePropertyName("minimumPermissibleValue"u8); + writer.WriteStringValue(ratioScale.MinimumPermissibleValue); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ratioScale.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ratioScale.Name); + writer.WritePropertyName("negativeValueConnotation"u8); + writer.WriteStringValue(ratioScale.NegativeValueConnotation); + writer.WritePropertyName("numberSet"u8); + writer.WriteStringValue(ratioScale.NumberSet.ToString()); + writer.WritePropertyName("positiveValueConnotation"u8); + writer.WriteStringValue(ratioScale.PositiveValueConnotation); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ratioScale.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ratioScale.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ratioScale.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(ratioScale.Unit); + + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in ratioScale.ValueDefinition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var ratioScale = thing as RatioScale; - if (ratioScale == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RatioScale."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); - return this.Serialize(ratioScale); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ismaximuminclusive": + writer.WritePropertyName("isMaximumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isminimuminclusive": + writer.WritePropertyName("isMinimumInclusive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "mappingtoreferencescale": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListMappingToReferenceScale && objectListMappingToReferenceScale.Any()) + { + writer.WriteStartArray("mappingToReferenceScale"u8); + + foreach(var mappingToReferenceScaleItem in objectListMappingToReferenceScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(mappingToReferenceScaleItem); + } + writer.WriteEndArray(); + } + break; + case "maximumpermissiblevalue": + writer.WritePropertyName("maximumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "minimumpermissiblevalue": + writer.WritePropertyName("minimumPermissibleValue"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "negativevalueconnotation": + writer.WritePropertyName("negativeValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "numberset": + writer.WritePropertyName("numberSet"u8); + + if(value != null) + { + writer.WriteStringValue(((NumberSetKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "positivevalueconnotation": + writer.WritePropertyName("positiveValueConnotation"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuedefinition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListValueDefinition && objectListValueDefinition.Any()) + { + writer.WriteStartArray("valueDefinition"u8); + + foreach(var valueDefinitionItem in objectListValueDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueDefinitionItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RatioScale"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMaximumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isMinimumInclusive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "mappingToReferenceScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maximumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minimumPermissibleValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "negativeValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "numberSet", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "positiveValueConnotation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "valueDefinition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs index 8e7cbe70a..29ed4961f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferenceSourceSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ReferenceSource = CDP4Common.DTO.ReferenceSource; /// /// The purpose of the class is to provide a specific serializer @@ -45,94 +50,1028 @@ namespace CDP4JsonSerializer public class ReferenceSourceSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "language", language => new JValue(language) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "publicationYear", publicationYear => new JValue(publicationYear) }, - { "publishedIn", publishedIn => new JValue(publishedIn) }, - { "publisher", publisher => new JValue(publisher) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "versionDate", versionDate => new JValue(versionDate != null ? ((DateTime)versionDate).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") : null) }, - { "versionIdentifier", versionIdentifier => new JValue(versionIdentifier) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ReferenceSource referenceSource) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](referenceSource.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](referenceSource.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](referenceSource.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), referenceSource.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](referenceSource.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](referenceSource.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](referenceSource.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](referenceSource.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](referenceSource.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](referenceSource.IsDeprecated)); - jsonObject.Add("language", this.PropertySerializerMap["language"](referenceSource.Language)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](referenceSource.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](referenceSource.Name)); - jsonObject.Add("publicationYear", this.PropertySerializerMap["publicationYear"](referenceSource.PublicationYear)); - jsonObject.Add("publishedIn", this.PropertySerializerMap["publishedIn"](referenceSource.PublishedIn)); - jsonObject.Add("publisher", this.PropertySerializerMap["publisher"](referenceSource.Publisher)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](referenceSource.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](referenceSource.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](referenceSource.ThingPreference)); - jsonObject.Add("versionDate", this.PropertySerializerMap["versionDate"](referenceSource.VersionDate)); - jsonObject.Add("versionIdentifier", this.PropertySerializerMap["versionIdentifier"](referenceSource.VersionIdentifier)); - return jsonObject; + if (thing is not ReferenceSource referenceSource) + { + throw new ArgumentException("The thing shall be a ReferenceSource", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ReferenceSource."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ReferenceSource since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(referenceSource.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referenceSource.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referenceSource.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referenceSource.IsDeprecated); + writer.WritePropertyName("language"u8); + writer.WriteStringValue(referenceSource.Language); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referenceSource.Name); + writer.WritePropertyName("publicationYear"u8); + + if (referenceSource.PublicationYear.HasValue) + { + writer.WriteNumberValue(referenceSource.PublicationYear.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publishedIn"u8); + + if (referenceSource.PublishedIn.HasValue) + { + writer.WriteStringValue(referenceSource.PublishedIn.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publisher"u8); + + if (referenceSource.Publisher.HasValue) + { + writer.WriteStringValue(referenceSource.Publisher.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referenceSource.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("versionDate"u8); + + if (referenceSource.VersionDate.HasValue) + { + writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("versionIdentifier"u8); + writer.WriteStringValue(referenceSource.VersionIdentifier); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(referenceSource.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referenceSource.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referenceSource.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referenceSource.IsDeprecated); + writer.WritePropertyName("language"u8); + writer.WriteStringValue(referenceSource.Language); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referenceSource.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referenceSource.Name); + writer.WritePropertyName("publicationYear"u8); + + if (referenceSource.PublicationYear.HasValue) + { + writer.WriteNumberValue(referenceSource.PublicationYear.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publishedIn"u8); + + if (referenceSource.PublishedIn.HasValue) + { + writer.WriteStringValue(referenceSource.PublishedIn.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publisher"u8); + + if (referenceSource.Publisher.HasValue) + { + writer.WriteStringValue(referenceSource.Publisher.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referenceSource.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("versionDate"u8); + + if (referenceSource.VersionDate.HasValue) + { + writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("versionIdentifier"u8); + writer.WriteStringValue(referenceSource.VersionIdentifier); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(referenceSource.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referenceSource.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referenceSource.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referenceSource.IsDeprecated); + writer.WritePropertyName("language"u8); + writer.WriteStringValue(referenceSource.Language); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referenceSource.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referenceSource.Name); + writer.WritePropertyName("publicationYear"u8); + + if (referenceSource.PublicationYear.HasValue) + { + writer.WriteNumberValue(referenceSource.PublicationYear.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publishedIn"u8); + + if (referenceSource.PublishedIn.HasValue) + { + writer.WriteStringValue(referenceSource.PublishedIn.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publisher"u8); + + if (referenceSource.Publisher.HasValue) + { + writer.WriteStringValue(referenceSource.Publisher.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referenceSource.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referenceSource.ThingPreference); + writer.WritePropertyName("versionDate"u8); + + if (referenceSource.VersionDate.HasValue) + { + writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("versionIdentifier"u8); + writer.WriteStringValue(referenceSource.VersionIdentifier); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ReferenceSource for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(referenceSource.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referenceSource.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referenceSource.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referenceSource.IsDeprecated); + writer.WritePropertyName("language"u8); + writer.WriteStringValue(referenceSource.Language); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referenceSource.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referenceSource.Name); + writer.WritePropertyName("publicationYear"u8); + + if (referenceSource.PublicationYear.HasValue) + { + writer.WriteNumberValue(referenceSource.PublicationYear.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publishedIn"u8); + + if (referenceSource.PublishedIn.HasValue) + { + writer.WriteStringValue(referenceSource.PublishedIn.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publisher"u8); + + if (referenceSource.Publisher.HasValue) + { + writer.WriteStringValue(referenceSource.Publisher.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referenceSource.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referenceSource.ThingPreference); + writer.WritePropertyName("versionDate"u8); + + if (referenceSource.VersionDate.HasValue) + { + writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("versionIdentifier"u8); + writer.WriteStringValue(referenceSource.VersionIdentifier); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ReferenceSource referenceSource) + { + throw new ArgumentException("The thing shall be a ReferenceSource", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referenceSource.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(referenceSource.Author); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in referenceSource.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referenceSource.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referenceSource.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referenceSource.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referenceSource.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referenceSource.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referenceSource.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referenceSource.IsDeprecated); + writer.WritePropertyName("language"u8); + writer.WriteStringValue(referenceSource.Language); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referenceSource.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referenceSource.Name); + writer.WritePropertyName("publicationYear"u8); + + if (referenceSource.PublicationYear.HasValue) + { + writer.WriteNumberValue(referenceSource.PublicationYear.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publishedIn"u8); + + if (referenceSource.PublishedIn.HasValue) + { + writer.WriteStringValue(referenceSource.PublishedIn.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("publisher"u8); + + if (referenceSource.Publisher.HasValue) + { + writer.WriteStringValue(referenceSource.Publisher.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referenceSource.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referenceSource.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referenceSource.ThingPreference); + writer.WritePropertyName("versionDate"u8); + + if (referenceSource.VersionDate.HasValue) + { + writer.WriteStringValue(referenceSource.VersionDate.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("versionIdentifier"u8); + writer.WriteStringValue(referenceSource.VersionIdentifier); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var referenceSource = thing as ReferenceSource; - if (referenceSource == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ReferenceSource."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "author": + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } - return this.Serialize(referenceSource); + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "language": + writer.WritePropertyName("language"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "publicationyear": + writer.WritePropertyName("publicationYear"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "publishedin": + writer.WritePropertyName("publishedIn"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "publisher": + writer.WritePropertyName("publisher"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "versiondate": + writer.WritePropertyName("versionDate"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "versionidentifier": + writer.WritePropertyName("versionIdentifier"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ReferenceSource"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "language", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "publicationYear", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "publishedIn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "publisher", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "versionDate", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "versionIdentifier", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs index d0202ae49..cc796d870 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReferencerRuleSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ReferencerRule = CDP4Common.DTO.ReferencerRule; /// /// The purpose of the class is to provide a specific serializer @@ -45,86 +50,752 @@ namespace CDP4JsonSerializer public class ReferencerRuleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "maxReferenced", maxReferenced => new JValue(maxReferenced) }, - { "minReferenced", minReferenced => new JValue(minReferenced) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "referencedCategory", referencedCategory => new JArray(referencedCategory) }, - { "referencingCategory", referencingCategory => new JValue(referencingCategory) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ReferencerRule referencerRule) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](referencerRule.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), referencerRule.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](referencerRule.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](referencerRule.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](referencerRule.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](referencerRule.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](referencerRule.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](referencerRule.IsDeprecated)); - jsonObject.Add("maxReferenced", this.PropertySerializerMap["maxReferenced"](referencerRule.MaxReferenced)); - jsonObject.Add("minReferenced", this.PropertySerializerMap["minReferenced"](referencerRule.MinReferenced)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](referencerRule.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](referencerRule.Name)); - jsonObject.Add("referencedCategory", this.PropertySerializerMap["referencedCategory"](referencerRule.ReferencedCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("referencingCategory", this.PropertySerializerMap["referencingCategory"](referencerRule.ReferencingCategory)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](referencerRule.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](referencerRule.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](referencerRule.ThingPreference)); - return jsonObject; + if (thing is not ReferencerRule referencerRule) + { + throw new ArgumentException("The thing shall be a ReferencerRule", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ReferencerRule."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ReferencerRule since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referencerRule.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ReferencerRule for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referencerRule.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ReferencerRule referencerRule) + { + throw new ArgumentException("The thing shall be a ReferencerRule", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in referencerRule.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(referencerRule.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in referencerRule.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in referencerRule.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in referencerRule.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in referencerRule.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(referencerRule.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(referencerRule.IsDeprecated); + writer.WritePropertyName("maxReferenced"u8); + writer.WriteNumberValue(referencerRule.MaxReferenced); + writer.WritePropertyName("minReferenced"u8); + writer.WriteNumberValue(referencerRule.MinReferenced); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(referencerRule.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(referencerRule.Name); + + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in referencerRule.ReferencedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("referencingCategory"u8); + writer.WriteStringValue(referencerRule.ReferencingCategory); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(referencerRule.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(referencerRule.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(referencerRule.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var referencerRule = thing as ReferencerRule; - if (referencerRule == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ReferencerRule."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "maxreferenced": + writer.WritePropertyName("maxReferenced"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(referencerRule); + break; + case "minreferenced": + writer.WritePropertyName("minReferenced"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencedcategory": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListReferencedCategory && objectListReferencedCategory.Any()) + { + writer.WriteStartArray("referencedCategory"u8); + + foreach(var referencedCategoryItem in objectListReferencedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referencedCategoryItem); + } + writer.WriteEndArray(); + } + break; + case "referencingcategory": + writer.WritePropertyName("referencingCategory"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ReferencerRule"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "maxReferenced", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "minReferenced", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referencingCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs index 43ff2ed07..091764438 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationalExpressionSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RelationalExpression = CDP4Common.DTO.RelationalExpression; /// /// The purpose of the class is to provide a specific serializer @@ -45,74 +50,479 @@ namespace CDP4JsonSerializer public class RelationalExpressionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "relationalOperator", relationalOperator => new JValue(relationalOperator.ToString()) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(((ValueArray)value).ToJsonString()) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(RelationalExpression relationalExpression) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), relationalExpression.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](relationalExpression.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](relationalExpression.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](relationalExpression.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](relationalExpression.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](relationalExpression.ParameterType)); - jsonObject.Add("relationalOperator", this.PropertySerializerMap["relationalOperator"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.RelationalOperatorKind), relationalExpression.RelationalOperator))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](relationalExpression.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](relationalExpression.Scale)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](relationalExpression.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](relationalExpression.Value)); - return jsonObject; + if (thing is not RelationalExpression relationalExpression) + { + throw new ArgumentException("The thing shall be a RelationalExpression", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RelationalExpression."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RelationalExpression since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RelationalExpression for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RelationalExpression for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationalExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RelationalExpression for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationalExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationalExpression.ThingPreference); + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RelationalExpression for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationalExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationalExpression.ThingPreference); + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not RelationalExpression relationalExpression) + { + throw new ArgumentException("The thing shall be a RelationalExpression", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationalExpression.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationalExpression.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationalExpression.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationalExpression.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationalExpression.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationalExpression.ParameterType); + writer.WritePropertyName("relationalOperator"u8); + writer.WriteStringValue(relationalExpression.RelationalOperator.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationalExpression.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (relationalExpression.Scale.HasValue) + { + writer.WriteStringValue(relationalExpression.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationalExpression.ThingPreference); + writer.WriteString("value"u8, relationalExpression.Value.ToJsonString()); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var relationalExpression = thing as RelationalExpression; - if (relationalExpression == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RelationalExpression."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relationaloperator": + writer.WritePropertyName("relationalOperator"u8); + + if(value != null) + { + writer.WriteStringValue(((RelationalOperatorKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(relationalExpression); + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RelationalExpression"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "relationalOperator", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs index 5c9a70191..98d7b841b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RelationshipParameterValueSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RelationshipParameterValue = CDP4Common.DTO.RelationshipParameterValue; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +50,432 @@ namespace CDP4JsonSerializer public class RelationshipParameterValueSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(((ValueArray)value).ToJsonString()) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(RelationshipParameterValue relationshipParameterValue) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), relationshipParameterValue.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](relationshipParameterValue.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](relationshipParameterValue.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](relationshipParameterValue.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](relationshipParameterValue.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](relationshipParameterValue.Scale)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](relationshipParameterValue.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](relationshipParameterValue.Value)); - return jsonObject; + if (thing is not RelationshipParameterValue relationshipParameterValue) + { + throw new ArgumentException("The thing shall be a RelationshipParameterValue", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RelationshipParameterValue."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RelationshipParameterValue since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RelationshipParameterValue for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationshipParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationshipParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationshipParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (relationshipParameterValue.Scale.HasValue) + { + writer.WriteStringValue(relationshipParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, relationshipParameterValue.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RelationshipParameterValue for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationshipParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationshipParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationshipParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (relationshipParameterValue.Scale.HasValue) + { + writer.WriteStringValue(relationshipParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationshipParameterValue.ThingPreference); + writer.WriteString("value"u8, relationshipParameterValue.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RelationshipParameterValue for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationshipParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationshipParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationshipParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (relationshipParameterValue.Scale.HasValue) + { + writer.WriteStringValue(relationshipParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationshipParameterValue.ThingPreference); + writer.WriteString("value"u8, relationshipParameterValue.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not RelationshipParameterValue relationshipParameterValue) + { + throw new ArgumentException("The thing shall be a RelationshipParameterValue", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(relationshipParameterValue.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in relationshipParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in relationshipParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(relationshipParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(relationshipParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(relationshipParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(relationshipParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (relationshipParameterValue.Scale.HasValue) + { + writer.WriteStringValue(relationshipParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(relationshipParameterValue.ThingPreference); + writer.WriteString("value"u8, relationshipParameterValue.Value.ToJsonString()); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var relationshipParameterValue = thing as RelationshipParameterValue; - if (relationshipParameterValue == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RelationshipParameterValue."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(relationshipParameterValue); + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RelationshipParameterValue"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs index 26a0ac910..7ea791a3f 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForDeviationSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RequestForDeviation = CDP4Common.DTO.RequestForDeviation; /// /// The purpose of the class is to provide a specific serializer @@ -45,96 +50,873 @@ namespace CDP4JsonSerializer public class RequestForDeviationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(RequestForDeviation requestForDeviation) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](requestForDeviation.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](requestForDeviation.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](requestForDeviation.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), requestForDeviation.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requestForDeviation.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](requestForDeviation.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](requestForDeviation.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](requestForDeviation.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requestForDeviation.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requestForDeviation.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requestForDeviation.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](requestForDeviation.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requestForDeviation.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](requestForDeviation.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](requestForDeviation.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](requestForDeviation.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requestForDeviation.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](requestForDeviation.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](requestForDeviation.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), requestForDeviation.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requestForDeviation.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](requestForDeviation.Title)); - return jsonObject; + if (thing is not RequestForDeviation requestForDeviation) + { + throw new ArgumentException("The thing shall be a RequestForDeviation", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RequestForDeviation."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RequestForDeviation since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForDeviation for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForDeviation.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForDeviation.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForDeviation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForDeviation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForDeviation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForDeviation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForDeviation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForDeviation.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (requestForDeviation.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForDeviation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForDeviation.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForDeviation.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForDeviation.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForDeviation for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForDeviation.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForDeviation.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForDeviation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForDeviation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForDeviation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForDeviation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForDeviation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForDeviation.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (requestForDeviation.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForDeviation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForDeviation.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForDeviation.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForDeviation.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForDeviation.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForDeviation for Version 1.3.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForDeviation.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForDeviation.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForDeviation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForDeviation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForDeviation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForDeviation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForDeviation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForDeviation.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (requestForDeviation.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForDeviation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForDeviation.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForDeviation.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForDeviation.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForDeviation.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not RequestForDeviation requestForDeviation) + { + throw new ArgumentException("The thing shall be a RequestForDeviation", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForDeviation.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForDeviation.Author); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForDeviation.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForDeviation.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForDeviation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForDeviation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForDeviation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForDeviation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForDeviation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForDeviation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForDeviation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForDeviation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForDeviation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForDeviation.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (requestForDeviation.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForDeviation.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForDeviation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForDeviation.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForDeviation.ShortName); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForDeviation.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForDeviation.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForDeviation.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForDeviation.Title); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var requestForDeviation = thing as RequestForDeviation; - if (requestForDeviation == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RequestForDeviation."); - } + case "approvedby": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) + { + writer.WriteStartArray("approvedBy"u8); - return this.Serialize(requestForDeviation); + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + writer.WriteEndArray(); + } + break; + case "author": + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classification": + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) + { + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) + { + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) + { + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + writer.WriteEndArray(); + } + break; + case "status": + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequestForDeviation"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs index b958f63de..129663b11 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequestForWaiverSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RequestForWaiver = CDP4Common.DTO.RequestForWaiver; /// /// The purpose of the class is to provide a specific serializer @@ -45,96 +50,873 @@ namespace CDP4JsonSerializer public class RequestForWaiverSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(RequestForWaiver requestForWaiver) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](requestForWaiver.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](requestForWaiver.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](requestForWaiver.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), requestForWaiver.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requestForWaiver.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](requestForWaiver.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](requestForWaiver.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](requestForWaiver.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requestForWaiver.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requestForWaiver.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requestForWaiver.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](requestForWaiver.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requestForWaiver.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](requestForWaiver.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](requestForWaiver.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](requestForWaiver.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requestForWaiver.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](requestForWaiver.ShortName)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](requestForWaiver.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), requestForWaiver.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requestForWaiver.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](requestForWaiver.Title)); - return jsonObject; + if (thing is not RequestForWaiver requestForWaiver) + { + throw new ArgumentException("The thing shall be a RequestForWaiver", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RequestForWaiver."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RequestForWaiver since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForWaiver for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForWaiver.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForWaiver.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForWaiver.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForWaiver.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForWaiver.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForWaiver.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForWaiver.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForWaiver.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (requestForWaiver.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForWaiver.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForWaiver.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForWaiver.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForWaiver.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForWaiver for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForWaiver.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForWaiver.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForWaiver.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForWaiver.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForWaiver.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForWaiver.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForWaiver.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForWaiver.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (requestForWaiver.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForWaiver.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForWaiver.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForWaiver.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForWaiver.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForWaiver.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RequestForWaiver for Version 1.3.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForWaiver.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForWaiver.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForWaiver.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForWaiver.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForWaiver.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForWaiver.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForWaiver.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForWaiver.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (requestForWaiver.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForWaiver.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForWaiver.ShortName); + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForWaiver.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForWaiver.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForWaiver.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not RequestForWaiver requestForWaiver) + { + throw new ArgumentException("The thing shall be a RequestForWaiver", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in requestForWaiver.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(requestForWaiver.Author); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requestForWaiver.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(requestForWaiver.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requestForWaiver.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(requestForWaiver.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(requestForWaiver.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in requestForWaiver.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requestForWaiver.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requestForWaiver.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requestForWaiver.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(requestForWaiver.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requestForWaiver.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requestForWaiver.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (requestForWaiver.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(requestForWaiver.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in requestForWaiver.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requestForWaiver.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requestForWaiver.ShortName); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in requestForWaiver.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(requestForWaiver.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requestForWaiver.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(requestForWaiver.Title); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var requestForWaiver = thing as RequestForWaiver; - if (requestForWaiver == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RequestForWaiver."); - } + case "approvedby": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) + { + writer.WriteStartArray("approvedBy"u8); - return this.Serialize(requestForWaiver); + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + writer.WriteEndArray(); + } + break; + case "author": + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classification": + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) + { + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) + { + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sourceannotation": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) + { + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + writer.WriteEndArray(); + } + break; + case "status": + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequestForWaiver"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs index d7be703a3..2b8c1a8e0 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Requirement = CDP4Common.DTO.Requirement; /// /// The purpose of the class is to provide a specific serializer @@ -45,88 +50,900 @@ namespace CDP4JsonSerializer public class RequirementSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "group", group => new JValue(group) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterValue", parameterValue => new JArray(parameterValue) }, - { "parametricConstraint", parametricConstraint => new JArray(((IEnumerable)parametricConstraint).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(Requirement requirement) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](requirement.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](requirement.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requirement.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](requirement.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requirement.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requirement.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("group", this.PropertySerializerMap["group"](requirement.Group)); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](requirement.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requirement.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](requirement.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requirement.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](requirement.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](requirement.Owner)); - jsonObject.Add("parameterValue", this.PropertySerializerMap["parameterValue"](requirement.ParameterValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("parametricConstraint", this.PropertySerializerMap["parametricConstraint"](requirement.ParametricConstraint.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requirement.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](requirement.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requirement.ThingPreference)); - return jsonObject; + if (thing is not Requirement requirement) + { + throw new ArgumentException("The thing shall be a Requirement", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Requirement."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Requirement since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("group"u8); + + if (requirement.Group.HasValue) + { + writer.WriteStringValue(requirement.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("group"u8); + + if (requirement.Group.HasValue) + { + writer.WriteStringValue(requirement.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("group"u8); + + if (requirement.Group.HasValue) + { + writer.WriteStringValue(requirement.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirement.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Requirement for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("group"u8); + + if (requirement.Group.HasValue) + { + writer.WriteStringValue(requirement.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirement.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Requirement requirement) + { + throw new ArgumentException("The thing shall be a Requirement", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirement.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirement.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirement.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirement.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirement.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirement.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("group"u8); + + if (requirement.Group.HasValue) + { + writer.WriteStringValue(requirement.Group.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirement.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirement.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirement.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirement.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirement.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirement.Owner); + + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirement.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in requirement.ParametricConstraint.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirement.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirement.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirement.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var requirement = thing as Requirement; - if (requirement == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Requirement."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "group": + writer.WritePropertyName("group"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "hyperlink": + if (value == null) + { + break; + } - return this.Serialize(requirement); + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametervalue": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListParameterValue && objectListParameterValue.Any()) + { + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + writer.WriteEndArray(); + } + break; + case "parametricconstraint": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListParametricConstraint && objectListParametricConstraint.Any()) + { + writer.WriteStartArray("parametricConstraint"u8); + + foreach(var parametricConstraintItem in objectListParametricConstraint.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(parametricConstraintItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Requirement"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "group", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValue", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parametricConstraint", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs index f231c7807..cb5df63b2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsContainerParameterValueSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RequirementsContainerParameterValue = CDP4Common.DTO.RequirementsContainerParameterValue; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +50,432 @@ namespace CDP4JsonSerializer public class RequirementsContainerParameterValueSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(((ValueArray)value).ToJsonString()) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(RequirementsContainerParameterValue requirementsContainerParameterValue) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requirementsContainerParameterValue.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requirementsContainerParameterValue.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requirementsContainerParameterValue.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](requirementsContainerParameterValue.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requirementsContainerParameterValue.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](requirementsContainerParameterValue.Scale)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requirementsContainerParameterValue.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](requirementsContainerParameterValue.Value)); - return jsonObject; + if (thing is not RequirementsContainerParameterValue requirementsContainerParameterValue) + { + throw new ArgumentException("The thing shall be a RequirementsContainerParameterValue", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RequirementsContainerParameterValue."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsContainerParameterValue since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsContainerParameterValue for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsContainerParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (requirementsContainerParameterValue.Scale.HasValue) + { + writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, requirementsContainerParameterValue.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsContainerParameterValue for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsContainerParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (requirementsContainerParameterValue.Scale.HasValue) + { + writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ThingPreference); + writer.WriteString("value"u8, requirementsContainerParameterValue.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsContainerParameterValue for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsContainerParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (requirementsContainerParameterValue.Scale.HasValue) + { + writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ThingPreference); + writer.WriteString("value"u8, requirementsContainerParameterValue.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not RequirementsContainerParameterValue requirementsContainerParameterValue) + { + throw new ArgumentException("The thing shall be a RequirementsContainerParameterValue", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsContainerParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsContainerParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (requirementsContainerParameterValue.Scale.HasValue) + { + writer.WriteStringValue(requirementsContainerParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsContainerParameterValue.ThingPreference); + writer.WriteString("value"u8, requirementsContainerParameterValue.Value.ToJsonString()); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var requirementsContainerParameterValue = thing as RequirementsContainerParameterValue; - if (requirementsContainerParameterValue == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RequirementsContainerParameterValue."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(requirementsContainerParameterValue); + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequirementsContainerParameterValue"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs index 5f5755eb2..f32a253ca 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsGroupSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RequirementsGroup = CDP4Common.DTO.RequirementsGroup; /// /// The purpose of the class is to provide a specific serializer @@ -45,84 +50,790 @@ namespace CDP4JsonSerializer public class RequirementsGroupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "group", group => new JArray(group) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterValue", parameterValue => new JArray(parameterValue) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(RequirementsGroup requirementsGroup) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](requirementsGroup.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](requirementsGroup.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requirementsGroup.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](requirementsGroup.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requirementsGroup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requirementsGroup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("group", this.PropertySerializerMap["group"](requirementsGroup.Group.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](requirementsGroup.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requirementsGroup.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requirementsGroup.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](requirementsGroup.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](requirementsGroup.Owner)); - jsonObject.Add("parameterValue", this.PropertySerializerMap["parameterValue"](requirementsGroup.ParameterValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requirementsGroup.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](requirementsGroup.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requirementsGroup.ThingPreference)); - return jsonObject; + if (thing is not RequirementsGroup requirementsGroup) + { + throw new ArgumentException("The thing shall be a RequirementsGroup", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RequirementsGroup."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsGroup since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsGroup.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsGroup.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsGroup.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsGroup.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsGroup.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsGroup.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsGroup.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsGroup.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsGroup.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsGroup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsGroup for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsGroup.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsGroup.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsGroup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not RequirementsGroup requirementsGroup) + { + throw new ArgumentException("The thing shall be a RequirementsGroup", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsGroup.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsGroup.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsGroup.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsGroup.Owner); + + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsGroup.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsGroup.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var requirementsGroup = thing as RequirementsGroup; - if (requirementsGroup == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RequirementsGroup."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "group": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListGroup && objectListGroup.Any()) + { + writer.WriteStartArray("group"u8); - return this.Serialize(requirementsGroup); + foreach(var groupItem in objectListGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametervalue": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListParameterValue && objectListParameterValue.Any()) + { + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequirementsGroup"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "group", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs index 68aa0f9a3..62cf715f3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RequirementsSpecificationSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RequirementsSpecification = CDP4Common.DTO.RequirementsSpecification; /// /// The purpose of the class is to provide a specific serializer @@ -45,88 +50,878 @@ namespace CDP4JsonSerializer public class RequirementsSpecificationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "group", group => new JArray(group) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "parameterValue", parameterValue => new JArray(parameterValue) }, - { "requirement", requirement => new JArray(requirement) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(RequirementsSpecification requirementsSpecification) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](requirementsSpecification.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](requirementsSpecification.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requirementsSpecification.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](requirementsSpecification.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("group", this.PropertySerializerMap["group"](requirementsSpecification.Group.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](requirementsSpecification.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](requirementsSpecification.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](requirementsSpecification.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requirementsSpecification.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](requirementsSpecification.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](requirementsSpecification.Owner)); - jsonObject.Add("parameterValue", this.PropertySerializerMap["parameterValue"](requirementsSpecification.ParameterValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("requirement", this.PropertySerializerMap["requirement"](requirementsSpecification.Requirement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requirementsSpecification.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](requirementsSpecification.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requirementsSpecification.ThingPreference)); - return jsonObject; + if (thing is not RequirementsSpecification requirementsSpecification) + { + throw new ArgumentException("The thing shall be a RequirementsSpecification", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RequirementsSpecification."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RequirementsSpecification since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsSpecification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsSpecification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsSpecification.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RequirementsSpecification for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsSpecification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsSpecification.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not RequirementsSpecification requirementsSpecification) + { + throw new ArgumentException("The thing shall be a RequirementsSpecification", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in requirementsSpecification.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in requirementsSpecification.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(requirementsSpecification.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in requirementsSpecification.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in requirementsSpecification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in requirementsSpecification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("group"u8); + + foreach(var groupItem in requirementsSpecification.Group.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in requirementsSpecification.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(requirementsSpecification.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(requirementsSpecification.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(requirementsSpecification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(requirementsSpecification.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(requirementsSpecification.Owner); + + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in requirementsSpecification.ParameterValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in requirementsSpecification.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(requirementsSpecification.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(requirementsSpecification.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(requirementsSpecification.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var requirementsSpecification = thing as RequirementsSpecification; - if (requirementsSpecification == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RequirementsSpecification."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "group": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListGroup && objectListGroup.Any()) + { + writer.WriteStartArray("group"u8); + + foreach(var groupItem in objectListGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(groupItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } - return this.Serialize(requirementsSpecification); + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametervalue": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListParameterValue && objectListParameterValue.Any()) + { + writer.WriteStartArray("parameterValue"u8); + + foreach(var parameterValueItem in objectListParameterValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterValueItem); + } + writer.WriteEndArray(); + } + break; + case "requirement": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRequirement && objectListRequirement.Any()) + { + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in objectListRequirement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RequirementsSpecification"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "group", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "requirement", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs index b82dec136..12711c378 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ReviewItemDiscrepancySerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ReviewItemDiscrepancy = CDP4Common.DTO.ReviewItemDiscrepancy; /// /// The purpose of the class is to provide a specific serializer @@ -45,98 +50,928 @@ namespace CDP4JsonSerializer public class ReviewItemDiscrepancySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "approvedBy", approvedBy => new JArray(approvedBy) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classification", classification => new JValue(classification.ToString()) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "solution", solution => new JArray(solution) }, - { "sourceAnnotation", sourceAnnotation => new JArray(sourceAnnotation) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "title", title => new JValue(title) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(ReviewItemDiscrepancy reviewItemDiscrepancy) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("approvedBy", this.PropertySerializerMap["approvedBy"](reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](reviewItemDiscrepancy.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](reviewItemDiscrepancy.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classification", this.PropertySerializerMap["classification"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationClassificationKind), reviewItemDiscrepancy.Classification))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), reviewItemDiscrepancy.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](reviewItemDiscrepancy.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](reviewItemDiscrepancy.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](reviewItemDiscrepancy.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](reviewItemDiscrepancy.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](reviewItemDiscrepancy.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](reviewItemDiscrepancy.Owner)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](reviewItemDiscrepancy.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](reviewItemDiscrepancy.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](reviewItemDiscrepancy.ShortName)); - jsonObject.Add("solution", this.PropertySerializerMap["solution"](reviewItemDiscrepancy.Solution)); - jsonObject.Add("sourceAnnotation", this.PropertySerializerMap["sourceAnnotation"](reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.ReportingData.AnnotationStatusKind), reviewItemDiscrepancy.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](reviewItemDiscrepancy.ThingPreference)); - jsonObject.Add("title", this.PropertySerializerMap["title"](reviewItemDiscrepancy.Title)); - return jsonObject; + if (thing is not ReviewItemDiscrepancy reviewItemDiscrepancy) + { + throw new ArgumentException("The thing shall be a ReviewItemDiscrepancy", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ReviewItemDiscrepancy."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ReviewItemDiscrepancy since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ReviewItemDiscrepancy for Version 1.1.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(reviewItemDiscrepancy.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ShortName); + writer.WriteStartArray("solution"u8); + + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Title); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ReviewItemDiscrepancy for Version 1.2.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(reviewItemDiscrepancy.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ShortName); + writer.WriteStartArray("solution"u8); + + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Title); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ReviewItemDiscrepancy for Version 1.3.0"); + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Author); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(reviewItemDiscrepancy.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ShortName); + writer.WriteStartArray("solution"u8); + + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Title); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ReviewItemDiscrepancy reviewItemDiscrepancy) + { + throw new ArgumentException("The thing shall be a ReviewItemDiscrepancy", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in reviewItemDiscrepancy.ApprovedBy.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Author); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in reviewItemDiscrepancy.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classification"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Classification.ToString()); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in reviewItemDiscrepancy.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in reviewItemDiscrepancy.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in reviewItemDiscrepancy.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(reviewItemDiscrepancy.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Owner); + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if (reviewItemDiscrepancy.PrimaryAnnotatedThing.HasValue) + { + writer.WriteStringValue(reviewItemDiscrepancy.PrimaryAnnotatedThing.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in reviewItemDiscrepancy.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(reviewItemDiscrepancy.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ShortName); + + writer.WriteStartArray("solution"u8); + + foreach(var solutionItem in reviewItemDiscrepancy.Solution.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in reviewItemDiscrepancy.SourceAnnotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("status"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(reviewItemDiscrepancy.ThingPreference); + writer.WritePropertyName("title"u8); + writer.WriteStringValue(reviewItemDiscrepancy.Title); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var reviewItemDiscrepancy = thing as ReviewItemDiscrepancy; - if (reviewItemDiscrepancy == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ReviewItemDiscrepancy."); - } + case "approvedby": + if (value == null) + { + break; + } - return this.Serialize(reviewItemDiscrepancy); + if (value is IEnumerable objectListApprovedBy && objectListApprovedBy.Any()) + { + writer.WriteStartArray("approvedBy"u8); + + foreach(var approvedByItem in objectListApprovedBy.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(approvedByItem); + } + writer.WriteEndArray(); + } + break; + case "author": + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classification": + writer.WritePropertyName("classification"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationClassificationKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) + { + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) + { + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "solution": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListSolution && objectListSolution.Any()) + { + writer.WriteStartArray("solution"u8); + + foreach(var solutionItem in objectListSolution.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(solutionItem); + } + writer.WriteEndArray(); + } + break; + case "sourceannotation": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListSourceAnnotation && objectListSourceAnnotation.Any()) + { + writer.WriteStartArray("sourceAnnotation"u8); + + foreach(var sourceAnnotationItem in objectListSourceAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(sourceAnnotationItem); + } + writer.WriteEndArray(); + } + break; + case "status": + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((AnnotationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "title": + writer.WritePropertyName("title"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ReviewItemDiscrepancy"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "approvedBy", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classification", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "solution", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "sourceAnnotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "title", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs index 5b84f0ec5..fba32f31b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleVerificationListSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RuleVerificationList = CDP4Common.DTO.RuleVerificationList; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +50,680 @@ namespace CDP4JsonSerializer public class RuleVerificationListSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "ruleVerification", ruleVerification => new JArray(((IEnumerable)ruleVerification).Cast().Select(x => x.ToJsonObject())) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(RuleVerificationList ruleVerificationList) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](ruleVerificationList.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), ruleVerificationList.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](ruleVerificationList.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](ruleVerificationList.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](ruleVerificationList.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](ruleVerificationList.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](ruleVerificationList.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](ruleVerificationList.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](ruleVerificationList.RevisionNumber)); - jsonObject.Add("ruleVerification", this.PropertySerializerMap["ruleVerification"](ruleVerificationList.RuleVerification.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](ruleVerificationList.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](ruleVerificationList.ThingPreference)); - return jsonObject; + if (thing is not RuleVerificationList ruleVerificationList) + { + throw new ArgumentException("The thing shall be a RuleVerificationList", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RuleVerificationList."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RuleVerificationList since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleVerificationList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleVerificationList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleVerificationList.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RuleVerificationList for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleVerificationList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleVerificationList.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not RuleVerificationList ruleVerificationList) + { + throw new ArgumentException("The thing shall be a RuleVerificationList", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in ruleVerificationList.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleVerificationList.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in ruleVerificationList.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleVerificationList.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleVerificationList.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in ruleVerificationList.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleVerificationList.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleVerificationList.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(ruleVerificationList.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(ruleVerificationList.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleVerificationList.RevisionNumber); + + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in ruleVerificationList.RuleVerification.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(ruleVerificationList.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleVerificationList.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var ruleVerificationList = thing as RuleVerificationList; - if (ruleVerificationList == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RuleVerificationList."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(ruleVerificationList); + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "ruleverification": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRuleVerification && objectListRuleVerification.Any()) + { + writer.WriteStartArray("ruleVerification"u8); + + foreach(var ruleVerificationItem in objectListRuleVerification.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(ruleVerificationItem); + } + writer.WriteEndArray(); + } + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RuleVerificationList"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "ruleVerification", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs index cd42eb719..a598e3763 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/RuleViolationSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using RuleViolation = CDP4Common.DTO.RuleViolation; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +50,441 @@ namespace CDP4JsonSerializer public class RuleViolationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "description", description => new JValue(description) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "violatingThing", violatingThing => new JArray(violatingThing) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(RuleViolation ruleViolation) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), ruleViolation.ClassKind))); - jsonObject.Add("description", this.PropertySerializerMap["description"](ruleViolation.Description)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](ruleViolation.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](ruleViolation.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](ruleViolation.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](ruleViolation.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](ruleViolation.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](ruleViolation.ThingPreference)); - jsonObject.Add("violatingThing", this.PropertySerializerMap["violatingThing"](ruleViolation.ViolatingThing.OrderBy(x => x, this.guidComparer))); - return jsonObject; + if (thing is not RuleViolation ruleViolation) + { + throw new ArgumentException("The thing shall be a RuleViolation", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of RuleViolation."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of RuleViolation since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing RuleViolation for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing RuleViolation for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing RuleViolation for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleViolation.ThingPreference); + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing RuleViolation for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleViolation.ThingPreference); + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not RuleViolation ruleViolation) + { + throw new ArgumentException("The thing shall be a RuleViolation", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(ruleViolation.ClassKind.ToString()); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(ruleViolation.Description); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in ruleViolation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in ruleViolation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(ruleViolation.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(ruleViolation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(ruleViolation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(ruleViolation.ThingPreference); + + writer.WriteStartArray("violatingThing"u8); + + foreach(var violatingThingItem in ruleViolation.ViolatingThing) + { + writer.WriteStringValue(violatingThingItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var ruleViolation = thing as RuleViolation; - if (ruleViolation == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a RuleViolation."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "description": + writer.WritePropertyName("description"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(ruleViolation); + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "violatingthing": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListViolatingThing && objectListViolatingThing.Any()) + { + writer.WriteStartArray("violatingThing"u8); + + foreach (var violatingThingItem in objectListViolatingThing) + { + writer.WriteStringValue((Guid)violatingThingItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the RuleViolation"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "description", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "violatingThing", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs index 70fc7237e..2e08bba00 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SampledFunctionParameterTypeSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SampledFunctionParameterType = CDP4Common.DTO.SampledFunctionParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,90 +50,723 @@ namespace CDP4JsonSerializer public class SampledFunctionParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "degreeOfInterpolation", degreeOfInterpolation => new JValue(degreeOfInterpolation) }, - { "dependentParameterType", dependentParameterType => new JArray(((IEnumerable)dependentParameterType).Cast().Select(x => x.ToJsonObject())) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "independentParameterType", independentParameterType => new JArray(((IEnumerable)independentParameterType).Cast().Select(x => x.ToJsonObject())) }, - { "interpolationPeriod", interpolationPeriod => new JValue(((ValueArray)interpolationPeriod).ToJsonString()) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.2.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(SampledFunctionParameterType sampledFunctionParameterType) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](sampledFunctionParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](sampledFunctionParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), sampledFunctionParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](sampledFunctionParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("degreeOfInterpolation", this.PropertySerializerMap["degreeOfInterpolation"](sampledFunctionParameterType.DegreeOfInterpolation)); - jsonObject.Add("dependentParameterType", this.PropertySerializerMap["dependentParameterType"](sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](sampledFunctionParameterType.Iid)); - jsonObject.Add("independentParameterType", this.PropertySerializerMap["independentParameterType"](sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("interpolationPeriod", this.PropertySerializerMap["interpolationPeriod"](sampledFunctionParameterType.InterpolationPeriod)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](sampledFunctionParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](sampledFunctionParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](sampledFunctionParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](sampledFunctionParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](sampledFunctionParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](sampledFunctionParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](sampledFunctionParameterType.ThingPreference)); - return jsonObject; + if (thing is not SampledFunctionParameterType sampledFunctionParameterType) + { + throw new ArgumentException("The thing shall be a SampledFunctionParameterType", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SampledFunctionParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SampledFunctionParameterType since Version is below 1.2.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SampledFunctionParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("degreeOfInterpolation"u8); + + if (sampledFunctionParameterType.DegreeOfInterpolation.HasValue) + { + writer.WriteNumberValue(sampledFunctionParameterType.DegreeOfInterpolation.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("dependentParameterType"u8); + + foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dependentParameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sampledFunctionParameterType.Iid); + writer.WriteStartArray("independentParameterType"u8); + + foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(independentParameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(sampledFunctionParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sampledFunctionParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sampledFunctionParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sampledFunctionParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(sampledFunctionParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(sampledFunctionParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sampledFunctionParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SampledFunctionParameterType for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("degreeOfInterpolation"u8); + + if (sampledFunctionParameterType.DegreeOfInterpolation.HasValue) + { + writer.WriteNumberValue(sampledFunctionParameterType.DegreeOfInterpolation.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("dependentParameterType"u8); + + foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dependentParameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sampledFunctionParameterType.Iid); + writer.WriteStartArray("independentParameterType"u8); + + foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(independentParameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(sampledFunctionParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sampledFunctionParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sampledFunctionParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sampledFunctionParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(sampledFunctionParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(sampledFunctionParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sampledFunctionParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not SampledFunctionParameterType sampledFunctionParameterType) + { + throw new ArgumentException("The thing shall be a SampledFunctionParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in sampledFunctionParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in sampledFunctionParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sampledFunctionParameterType.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in sampledFunctionParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("degreeOfInterpolation"u8); + + if (sampledFunctionParameterType.DegreeOfInterpolation.HasValue) + { + writer.WriteNumberValue(sampledFunctionParameterType.DegreeOfInterpolation.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("dependentParameterType"u8); + + foreach(var dependentParameterTypeItem in sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dependentParameterTypeItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sampledFunctionParameterType.Iid); + + writer.WriteStartArray("independentParameterType"u8); + + foreach(var independentParameterTypeItem in sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(independentParameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteString("interpolationPeriod"u8, sampledFunctionParameterType.InterpolationPeriod.ToJsonString()); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(sampledFunctionParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sampledFunctionParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sampledFunctionParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sampledFunctionParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(sampledFunctionParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(sampledFunctionParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sampledFunctionParameterType.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var sampledFunctionParameterType = thing as SampledFunctionParameterType; - if (sampledFunctionParameterType == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SampledFunctionParameterType."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); - return this.Serialize(sampledFunctionParameterType); + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "degreeofinterpolation": + writer.WritePropertyName("degreeOfInterpolation"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "dependentparametertype": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDependentParameterType && objectListDependentParameterType.Any()) + { + writer.WriteStartArray("dependentParameterType"u8); + + foreach(var dependentParameterTypeItem in objectListDependentParameterType.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(dependentParameterTypeItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "independentparametertype": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListIndependentParameterType && objectListIndependentParameterType.Any()) + { + writer.WriteStartArray("independentParameterType"u8); + + foreach(var independentParameterTypeItem in objectListIndependentParameterType.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(independentParameterTypeItem); + } + writer.WriteEndArray(); + } + break; + case "interpolationperiod": + writer.WriteString("interpolationPeriod"u8, ((ValueArray)value).ToJsonString()); + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SampledFunctionParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.2.0", "1.3.0" }}, + { "category", new []{ "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.2.0", "1.3.0" }}, + { "degreeOfInterpolation", new []{ "1.2.0", "1.3.0" }}, + { "dependentParameterType", new []{ "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.2.0", "1.3.0" }}, + { "independentParameterType", new []{ "1.2.0", "1.3.0" }}, + { "interpolationPeriod", new []{ "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs index 28ac8fcba..2cc11f6a2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleReferenceQuantityValueSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ScaleReferenceQuantityValue = CDP4Common.DTO.ScaleReferenceQuantityValue; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +50,401 @@ namespace CDP4JsonSerializer public class ScaleReferenceQuantityValueSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(value) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(ScaleReferenceQuantityValue scaleReferenceQuantityValue) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), scaleReferenceQuantityValue.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](scaleReferenceQuantityValue.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](scaleReferenceQuantityValue.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](scaleReferenceQuantityValue.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](scaleReferenceQuantityValue.Scale)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](scaleReferenceQuantityValue.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](scaleReferenceQuantityValue.Value)); - return jsonObject; + if (thing is not ScaleReferenceQuantityValue scaleReferenceQuantityValue) + { + throw new ArgumentException("The thing shall be a ScaleReferenceQuantityValue", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ScaleReferenceQuantityValue."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ScaleReferenceQuantityValue since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleReferenceQuantityValue for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleReferenceQuantityValue for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleReferenceQuantityValue for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleReferenceQuantityValue for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ScaleReferenceQuantityValue scaleReferenceQuantityValue) + { + throw new ArgumentException("The thing shall be a ScaleReferenceQuantityValue", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleReferenceQuantityValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleReferenceQuantityValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleReferenceQuantityValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Scale); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleReferenceQuantityValue.Value); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var scaleReferenceQuantityValue = thing as ScaleReferenceQuantityValue; - if (scaleReferenceQuantityValue == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ScaleReferenceQuantityValue."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(scaleReferenceQuantityValue); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + writer.WritePropertyName("value"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ScaleReferenceQuantityValue"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs index ee7e18806..dd161dafb 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ScaleValueDefinitionSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ScaleValueDefinition = CDP4Common.DTO.ScaleValueDefinition; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +50,616 @@ namespace CDP4JsonSerializer public class ScaleValueDefinitionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(value) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(ScaleValueDefinition scaleValueDefinition) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](scaleValueDefinition.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), scaleValueDefinition.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](scaleValueDefinition.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](scaleValueDefinition.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](scaleValueDefinition.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](scaleValueDefinition.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](scaleValueDefinition.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](scaleValueDefinition.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](scaleValueDefinition.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](scaleValueDefinition.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](scaleValueDefinition.Value)); - return jsonObject; + if (thing is not ScaleValueDefinition scaleValueDefinition) + { + throw new ArgumentException("The thing shall be a ScaleValueDefinition", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ScaleValueDefinition."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ScaleValueDefinition since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleValueDefinition.Iid); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(scaleValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(scaleValueDefinition.ShortName); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleValueDefinition.Value); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(scaleValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(scaleValueDefinition.ShortName); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleValueDefinition.Value); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(scaleValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(scaleValueDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleValueDefinition.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleValueDefinition.Value); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ScaleValueDefinition for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(scaleValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(scaleValueDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleValueDefinition.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleValueDefinition.Value); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ScaleValueDefinition scaleValueDefinition) + { + throw new ArgumentException("The thing shall be a ScaleValueDefinition", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in scaleValueDefinition.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(scaleValueDefinition.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in scaleValueDefinition.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in scaleValueDefinition.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in scaleValueDefinition.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in scaleValueDefinition.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(scaleValueDefinition.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(scaleValueDefinition.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(scaleValueDefinition.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(scaleValueDefinition.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(scaleValueDefinition.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(scaleValueDefinition.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(scaleValueDefinition.Value); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var scaleValueDefinition = thing as ScaleValueDefinition; - if (scaleValueDefinition == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ScaleValueDefinition."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); - return this.Serialize(scaleValueDefinition); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + writer.WritePropertyName("value"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ScaleValueDefinition"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs index 6898f9908..2037b6b5b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SectionSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Section = CDP4Common.DTO.Section; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +50,541 @@ namespace CDP4JsonSerializer public class SectionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "page", page => new JArray(((IEnumerable)page).Cast().Select(x => x.ToJsonObject())) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(Section section) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](section.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), section.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](section.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](section.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](section.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](section.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](section.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](section.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](section.Owner)); - jsonObject.Add("page", this.PropertySerializerMap["page"](section.Page.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](section.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](section.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](section.ThingPreference)); - return jsonObject; + if (thing is not Section section) + { + throw new ArgumentException("The thing shall be a Section", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Section."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Section since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Section for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(section.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(section.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(section.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(section.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(section.Owner); + writer.WriteStartArray("page"u8); + + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pageItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(section.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(section.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Section for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(section.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(section.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(section.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(section.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(section.Owner); + writer.WriteStartArray("page"u8); + + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pageItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(section.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(section.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(section.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Section for Version 1.3.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(section.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(section.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(section.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(section.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(section.Owner); + writer.WriteStartArray("page"u8); + + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pageItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(section.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(section.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(section.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Section section) + { + throw new ArgumentException("The thing shall be a Section", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in section.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(section.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(section.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in section.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in section.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(section.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(section.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(section.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(section.Owner); + + writer.WriteStartArray("page"u8); + + foreach(var pageItem in section.Page.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pageItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(section.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(section.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(section.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var section = thing as Section; - if (section == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Section."); - } + case "category": + if (value == null) + { + break; + } - return this.Serialize(section); + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "page": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListPage && objectListPage.Any()) + { + writer.WriteStartArray("page"u8); + + foreach(var pageItem in objectListPage.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(pageItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Section"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "page", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SerializerProvider.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SerializerProvider.cs index 648e2387f..619ff85f6 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SerializerProvider.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SerializerProvider.cs @@ -1,27 +1,26 @@ -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -31,14 +30,15 @@ namespace CDP4JsonSerializer { using System; using System.Collections.Generic; - + using System.IO; + using System.Text; + using System.Text.Json; + using CDP4Common; using CDP4Common.DTO; - + using CDP4JsonSerializer.Helper; - using Newtonsoft.Json.Linq; - /// /// A static class that provides method to serialize a or a /// @@ -47,7 +47,7 @@ public static class SerializerProvider /// /// The map containing the Serializers /// - private static readonly Dictionary SerializerMap = new Dictionary + private static readonly Dictionary SerializerMap = new() { { "ActionItem", new ActionItemSerializer() }, { "ActualFiniteState", new ActualFiniteStateSerializer() }, @@ -198,42 +198,100 @@ public static class SerializerProvider }; /// - /// Serialize a + /// Serialize a into an /// /// The - /// The - public static JObject ToJsonObject(this Thing thing) + /// The + /// The that has been requested for the serialization + public static void SerializeThing(this Thing thing, Utf8JsonWriter writer, Version requestedVersion) { - IThingSerializer serializer; - if(!SerializerMap.TryGetValue(thing.ClassKind.ToString(), out serializer)) + if(!SerializerMap.TryGetValue(thing.ClassKind.ToString(), out var serializer)) { throw new NotSupportedException($"The {thing.ClassKind} class is not registered"); } - - return serializer.Serialize(thing); + + serializer.Serialize(thing, writer, requestedVersion); } - + /// - /// Serialize a + /// Serialize a into an /// /// The - /// The - public static JObject ToJsonObject(this ClasslessDTO classlessDto) + /// The + /// The that has been requested for the serialization + public static void SerializeClasslessDto(this ClasslessDTO classlessDto, Utf8JsonWriter writer, Version requestedVersion) { - IThingSerializer serializer; - if(!SerializerMap.TryGetValue(classlessDto["ClassKind"].ToString(), out serializer)) + if(!SerializerMap.TryGetValue(classlessDto["ClassKind"].ToString(), out var serializer)) { throw new NotSupportedException($"The {classlessDto["ClassKind"]} class is not registered"); } - var jsonObject = new JObject(); + writer.WriteStartObject(); + foreach (var keyValue in classlessDto) { var key = Utils.LowercaseFirstLetter(keyValue.Key); - jsonObject.Add(key, serializer.PropertySerializerMap[key](keyValue.Value)); + serializer.SerializeProperty(key, keyValue.Value, writer, requestedVersion); } - return jsonObject; + writer.WriteEndObject(); + } + + /// + /// Serialize a into an + /// + /// The + /// A json representation of the + public static string ToJsonString(this Thing thing) + { + if(!SerializerMap.TryGetValue(thing.ClassKind.ToString(), out var serializer)) + { + throw new NotSupportedException($"The {thing.ClassKind} class is not registered"); + } + + using (var stream = new MemoryStream()) + { + using (var writer = new Utf8JsonWriter(stream)) + { + serializer.Serialize(thing, writer); + writer.Flush(); + stream.Flush(); + return Encoding.UTF8.GetString(stream.ToArray()); + } + } + } + + /// + /// Serialize a into an + /// + /// The + /// A json representation of the + public static string ToJsonString(this ClasslessDTO classlessDto) + { + if(!SerializerMap.TryGetValue(classlessDto["ClassKind"].ToString(), out var serializer)) + { + throw new NotSupportedException($"The {classlessDto["ClassKind"]} class is not registered"); + } + + using (var stream = new MemoryStream()) + { + using (var writer = new Utf8JsonWriter(stream)) + { + writer.WriteStartObject(); + + foreach (var keyValue in classlessDto) + { + var key = Utils.LowercaseFirstLetter(keyValue.Key); + serializer.SerializeProperty(key, keyValue.Value, writer); + } + + writer.WriteEndObject(); + + writer.Flush(); + stream.Flush(); + return Encoding.UTF8.GetString(stream.ToArray()); + } + } } } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs index beb6b015a..ee765f6d4 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SharedStyleSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SharedStyle = CDP4Common.DTO.SharedStyle; /// /// The purpose of the class is to provide a specific serializer @@ -45,94 +50,1081 @@ namespace CDP4JsonSerializer public class SharedStyleSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fillColor", fillColor => new JValue(fillColor) }, - { "fillOpacity", fillOpacity => new JValue(fillOpacity) }, - { "fontBold", fontBold => new JValue(fontBold) }, - { "fontColor", fontColor => new JValue(fontColor) }, - { "fontItalic", fontItalic => new JValue(fontItalic) }, - { "fontName", fontName => new JValue(fontName) }, - { "fontSize", fontSize => new JValue(fontSize) }, - { "fontStrokeThrough", fontStrokeThrough => new JValue(fontStrokeThrough) }, - { "fontUnderline", fontUnderline => new JValue(fontUnderline) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "strokeColor", strokeColor => new JValue(strokeColor) }, - { "strokeOpacity", strokeOpacity => new JValue(strokeOpacity) }, - { "strokeWidth", strokeWidth => new JValue(strokeWidth) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "usedColor", usedColor => new JArray(usedColor) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(SharedStyle sharedStyle) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), sharedStyle.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](sharedStyle.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](sharedStyle.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fillColor", this.PropertySerializerMap["fillColor"](sharedStyle.FillColor)); - jsonObject.Add("fillOpacity", this.PropertySerializerMap["fillOpacity"](sharedStyle.FillOpacity)); - jsonObject.Add("fontBold", this.PropertySerializerMap["fontBold"](sharedStyle.FontBold)); - jsonObject.Add("fontColor", this.PropertySerializerMap["fontColor"](sharedStyle.FontColor)); - jsonObject.Add("fontItalic", this.PropertySerializerMap["fontItalic"](sharedStyle.FontItalic)); - jsonObject.Add("fontName", this.PropertySerializerMap["fontName"](sharedStyle.FontName)); - jsonObject.Add("fontSize", this.PropertySerializerMap["fontSize"](sharedStyle.FontSize)); - jsonObject.Add("fontStrokeThrough", this.PropertySerializerMap["fontStrokeThrough"](sharedStyle.FontStrokeThrough)); - jsonObject.Add("fontUnderline", this.PropertySerializerMap["fontUnderline"](sharedStyle.FontUnderline)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](sharedStyle.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](sharedStyle.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](sharedStyle.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](sharedStyle.RevisionNumber)); - jsonObject.Add("strokeColor", this.PropertySerializerMap["strokeColor"](sharedStyle.StrokeColor)); - jsonObject.Add("strokeOpacity", this.PropertySerializerMap["strokeOpacity"](sharedStyle.StrokeOpacity)); - jsonObject.Add("strokeWidth", this.PropertySerializerMap["strokeWidth"](sharedStyle.StrokeWidth)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](sharedStyle.ThingPreference)); - jsonObject.Add("usedColor", this.PropertySerializerMap["usedColor"](sharedStyle.UsedColor.OrderBy(x => x, this.guidComparer))); - return jsonObject; + if (thing is not SharedStyle sharedStyle) + { + throw new ArgumentException("The thing shall be a SharedStyle", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SharedStyle."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SharedStyle since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SharedStyle for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sharedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fillColor"u8); + + if (sharedStyle.FillColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if (sharedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if (sharedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if (sharedStyle.FontColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if (sharedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(sharedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if (sharedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(sharedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if (sharedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if (sharedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sharedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sharedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sharedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sharedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if (sharedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(sharedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if (sharedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if (sharedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SharedStyle for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sharedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fillColor"u8); + + if (sharedStyle.FillColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if (sharedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if (sharedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if (sharedStyle.FontColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if (sharedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(sharedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if (sharedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(sharedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if (sharedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if (sharedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sharedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sharedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sharedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sharedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if (sharedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(sharedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if (sharedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if (sharedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sharedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SharedStyle for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sharedStyle.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fillColor"u8); + + if (sharedStyle.FillColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if (sharedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if (sharedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if (sharedStyle.FontColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if (sharedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(sharedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if (sharedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(sharedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if (sharedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if (sharedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sharedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sharedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sharedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sharedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if (sharedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(sharedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if (sharedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if (sharedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sharedStyle.ThingPreference); + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not SharedStyle sharedStyle) + { + throw new ArgumentException("The thing shall be a SharedStyle", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(sharedStyle.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in sharedStyle.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in sharedStyle.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("fillColor"u8); + + if (sharedStyle.FillColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FillColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fillOpacity"u8); + + if (sharedStyle.FillOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.FillOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontBold"u8); + + if (sharedStyle.FontBold.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontBold.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontColor"u8); + + if (sharedStyle.FontColor.HasValue) + { + writer.WriteStringValue(sharedStyle.FontColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontItalic"u8); + + if (sharedStyle.FontItalic.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontItalic.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontName"u8); + writer.WriteStringValue(sharedStyle.FontName); + writer.WritePropertyName("fontSize"u8); + + if (sharedStyle.FontSize.HasValue) + { + writer.WriteNumberValue(sharedStyle.FontSize.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontStrokeThrough"u8); + + if (sharedStyle.FontStrokeThrough.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontStrokeThrough.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("fontUnderline"u8); + + if (sharedStyle.FontUnderline.HasValue) + { + writer.WriteBooleanValue(sharedStyle.FontUnderline.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(sharedStyle.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(sharedStyle.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(sharedStyle.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(sharedStyle.RevisionNumber); + writer.WritePropertyName("strokeColor"u8); + + if (sharedStyle.StrokeColor.HasValue) + { + writer.WriteStringValue(sharedStyle.StrokeColor.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeOpacity"u8); + + if (sharedStyle.StrokeOpacity.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeOpacity.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("strokeWidth"u8); + + if (sharedStyle.StrokeWidth.HasValue) + { + writer.WriteNumberValue(sharedStyle.StrokeWidth.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(sharedStyle.ThingPreference); + + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in sharedStyle.UsedColor.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var sharedStyle = thing as SharedStyle; - if (sharedStyle == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SharedStyle."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "fillcolor": + writer.WritePropertyName("fillColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fillopacity": + writer.WritePropertyName("fillOpacity"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontbold": + writer.WritePropertyName("fontBold"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontcolor": + writer.WritePropertyName("fontColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(sharedStyle); + break; + case "fontitalic": + writer.WritePropertyName("fontItalic"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontname": + writer.WritePropertyName("fontName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontsize": + writer.WritePropertyName("fontSize"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontstrokethrough": + writer.WritePropertyName("fontStrokeThrough"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "fontunderline": + writer.WritePropertyName("fontUnderline"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokecolor": + writer.WritePropertyName("strokeColor"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokeopacity": + writer.WritePropertyName("strokeOpacity"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "strokewidth": + writer.WritePropertyName("strokeWidth"u8); + + if(value != null) + { + writer.WriteNumberValue((float)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "usedcolor": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListUsedColor && objectListUsedColor.Any()) + { + writer.WriteStartArray("usedColor"u8); + + foreach(var usedColorItem in objectListUsedColor.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(usedColorItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SharedStyle"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fillColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fillOpacity", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontBold", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontItalic", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontSize", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontStrokeThrough", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fontUnderline", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeOpacity", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "strokeWidth", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "usedColor", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs index 90423aaf9..116186b66 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleParameterValueSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SimpleParameterValue = CDP4Common.DTO.SimpleParameterValue; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +50,455 @@ namespace CDP4JsonSerializer public class SimpleParameterValueSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "parameterType", parameterType => new JValue(parameterType) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "scale", scale => new JValue(scale) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(((ValueArray)value).ToJsonString()) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(SimpleParameterValue simpleParameterValue) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), simpleParameterValue.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](simpleParameterValue.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](simpleParameterValue.ModifiedOn)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](simpleParameterValue.ParameterType)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](simpleParameterValue.RevisionNumber)); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](simpleParameterValue.Scale)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](simpleParameterValue.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](simpleParameterValue.Value)); - return jsonObject; + if (thing is not SimpleParameterValue simpleParameterValue) + { + throw new ArgumentException("The thing shall be a SimpleParameterValue", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SimpleParameterValue."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SimpleParameterValue since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleParameterValue for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleParameterValue for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleParameterValue for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleParameterValue.ThingPreference); + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleParameterValue for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleParameterValue.ThingPreference); + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not SimpleParameterValue simpleParameterValue) + { + throw new ArgumentException("The thing shall be a SimpleParameterValue", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleParameterValue.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleParameterValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleParameterValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleParameterValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleParameterValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("parameterType"u8); + writer.WriteStringValue(simpleParameterValue.ParameterType); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleParameterValue.RevisionNumber); + writer.WritePropertyName("scale"u8); + + if (simpleParameterValue.Scale.HasValue) + { + writer.WriteStringValue(simpleParameterValue.Scale.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleParameterValue.ThingPreference); + writer.WriteString("value"u8, simpleParameterValue.Value.ToJsonString()); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var simpleParameterValue = thing as SimpleParameterValue; - if (simpleParameterValue == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SimpleParameterValue."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + writer.WritePropertyName("parameterType"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(simpleParameterValue); + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "scale": + writer.WritePropertyName("scale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + writer.WriteString("value"u8, ((ValueArray)value).ToJsonString()); + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SimpleParameterValue"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs index f054c44dc..d5da8cfc2 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleQuantityKindSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SimpleQuantityKind = CDP4Common.DTO.SimpleQuantityKind; /// /// The purpose of the class is to provide a specific serializer @@ -45,88 +50,816 @@ namespace CDP4JsonSerializer public class SimpleQuantityKindSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultScale", defaultScale => new JValue(defaultScale) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "possibleScale", possibleScale => new JArray(possibleScale) }, - { "quantityDimensionSymbol", quantityDimensionSymbol => new JValue(quantityDimensionSymbol) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(SimpleQuantityKind simpleQuantityKind) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](simpleQuantityKind.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](simpleQuantityKind.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), simpleQuantityKind.ClassKind))); - jsonObject.Add("defaultScale", this.PropertySerializerMap["defaultScale"](simpleQuantityKind.DefaultScale)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](simpleQuantityKind.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](simpleQuantityKind.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](simpleQuantityKind.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](simpleQuantityKind.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](simpleQuantityKind.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](simpleQuantityKind.Name)); - jsonObject.Add("possibleScale", this.PropertySerializerMap["possibleScale"](simpleQuantityKind.PossibleScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("quantityDimensionSymbol", this.PropertySerializerMap["quantityDimensionSymbol"](simpleQuantityKind.QuantityDimensionSymbol)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](simpleQuantityKind.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](simpleQuantityKind.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](simpleQuantityKind.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](simpleQuantityKind.ThingPreference)); - return jsonObject; + if (thing is not SimpleQuantityKind simpleQuantityKind) + { + throw new ArgumentException("The thing shall be a SimpleQuantityKind", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SimpleQuantityKind."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SimpleQuantityKind since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleQuantityKind.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleQuantityKind for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleQuantityKind.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not SimpleQuantityKind simpleQuantityKind) + { + throw new ArgumentException("The thing shall be a SimpleQuantityKind", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in simpleQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(simpleQuantityKind.DefaultScale); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleQuantityKind.Name); + + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in simpleQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(simpleQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(simpleQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleQuantityKind.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var simpleQuantityKind = thing as SimpleQuantityKind; - if (simpleQuantityKind == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SimpleQuantityKind."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultscale": + writer.WritePropertyName("defaultScale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(simpleQuantityKind); + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblescale": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListPossibleScale && objectListPossibleScale.Any()) + { + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + writer.WriteEndArray(); + } + break; + case "quantitydimensionsymbol": + writer.WritePropertyName("quantityDimensionSymbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SimpleQuantityKind"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "quantityDimensionSymbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs index 1dc7043c0..33fc3b205 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SimpleUnitSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SimpleUnit = CDP4Common.DTO.SimpleUnit; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +50,616 @@ namespace CDP4JsonSerializer public class SimpleUnitSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(SimpleUnit simpleUnit) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](simpleUnit.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), simpleUnit.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](simpleUnit.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](simpleUnit.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](simpleUnit.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](simpleUnit.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](simpleUnit.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](simpleUnit.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](simpleUnit.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](simpleUnit.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](simpleUnit.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](simpleUnit.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](simpleUnit.ThingPreference)); - return jsonObject; + if (thing is not SimpleUnit simpleUnit) + { + throw new ArgumentException("The thing shall be a SimpleUnit", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SimpleUnit."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SimpleUnit since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleUnit.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleUnit.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleUnit.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleUnit.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SimpleUnit for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleUnit.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not SimpleUnit simpleUnit) + { + throw new ArgumentException("The thing shall be a SimpleUnit", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in simpleUnit.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(simpleUnit.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in simpleUnit.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in simpleUnit.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in simpleUnit.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in simpleUnit.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(simpleUnit.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(simpleUnit.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(simpleUnit.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(simpleUnit.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(simpleUnit.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(simpleUnit.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(simpleUnit.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var simpleUnit = thing as SimpleUnit; - if (simpleUnit == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SimpleUnit."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); - return this.Serialize(simpleUnit); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SimpleUnit"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs index 404eb26b5..f725f429b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataAnnotationSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteDirectoryDataAnnotation = CDP4Common.DTO.SiteDirectoryDataAnnotation; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +50,564 @@ namespace CDP4JsonSerializer public class SiteDirectoryDataAnnotationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "discussion", discussion => new JArray(discussion) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "primaryAnnotatedThing", primaryAnnotatedThing => new JValue(primaryAnnotatedThing) }, - { "relatedThing", relatedThing => new JArray(relatedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(SiteDirectoryDataAnnotation siteDirectoryDataAnnotation) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](siteDirectoryDataAnnotation.Author)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteDirectoryDataAnnotation.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](siteDirectoryDataAnnotation.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](siteDirectoryDataAnnotation.CreatedOn)); - jsonObject.Add("discussion", this.PropertySerializerMap["discussion"](siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteDirectoryDataAnnotation.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](siteDirectoryDataAnnotation.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteDirectoryDataAnnotation.ModifiedOn)); - jsonObject.Add("primaryAnnotatedThing", this.PropertySerializerMap["primaryAnnotatedThing"](siteDirectoryDataAnnotation.PrimaryAnnotatedThing)); - jsonObject.Add("relatedThing", this.PropertySerializerMap["relatedThing"](siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteDirectoryDataAnnotation.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteDirectoryDataAnnotation.ThingPreference)); - return jsonObject; + if (thing is not SiteDirectoryDataAnnotation siteDirectoryDataAnnotation) + { + throw new ArgumentException("The thing shall be a SiteDirectoryDataAnnotation", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SiteDirectoryDataAnnotation."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryDataAnnotation since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataAnnotation for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataAnnotation for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataAnnotation for Version 1.3.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not SiteDirectoryDataAnnotation siteDirectoryDataAnnotation) + { + throw new ArgumentException("The thing shall be a SiteDirectoryDataAnnotation", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in siteDirectoryDataAnnotation.Discussion.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataAnnotation.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataAnnotation.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("primaryAnnotatedThing"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.PrimaryAnnotatedThing); + + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in siteDirectoryDataAnnotation.RelatedThing.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataAnnotation.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataAnnotation.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var siteDirectoryDataAnnotation = thing as SiteDirectoryDataAnnotation; - if (siteDirectoryDataAnnotation == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SiteDirectoryDataAnnotation."); - } + case "author": + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(siteDirectoryDataAnnotation); + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "discussion": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDiscussion && objectListDiscussion.Any()) + { + writer.WriteStartArray("discussion"u8); + + foreach(var discussionItem in objectListDiscussion.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(discussionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "primaryannotatedthing": + writer.WritePropertyName("primaryAnnotatedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "relatedthing": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRelatedThing && objectListRelatedThing.Any()) + { + writer.WriteStartArray("relatedThing"u8); + + foreach(var relatedThingItem in objectListRelatedThing.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(relatedThingItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteDirectoryDataAnnotation"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "discussion", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "primaryAnnotatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "relatedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs index b5288bb8d..abe659e53 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryDataDiscussionItemSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteDirectoryDataDiscussionItem = CDP4Common.DTO.SiteDirectoryDataDiscussionItem; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +50,490 @@ namespace CDP4JsonSerializer public class SiteDirectoryDataDiscussionItemSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "replyTo", replyTo => new JValue(replyTo) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(SiteDirectoryDataDiscussionItem siteDirectoryDataDiscussionItem) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](siteDirectoryDataDiscussionItem.Author)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteDirectoryDataDiscussionItem.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](siteDirectoryDataDiscussionItem.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](siteDirectoryDataDiscussionItem.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteDirectoryDataDiscussionItem.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](siteDirectoryDataDiscussionItem.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteDirectoryDataDiscussionItem.ModifiedOn)); - jsonObject.Add("replyTo", this.PropertySerializerMap["replyTo"](siteDirectoryDataDiscussionItem.ReplyTo)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteDirectoryDataDiscussionItem.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteDirectoryDataDiscussionItem.ThingPreference)); - return jsonObject; + if (thing is not SiteDirectoryDataDiscussionItem siteDirectoryDataDiscussionItem) + { + throw new ArgumentException("The thing shall be a SiteDirectoryDataDiscussionItem", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SiteDirectoryDataDiscussionItem."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryDataDiscussionItem since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataDiscussionItem for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if (siteDirectoryDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataDiscussionItem.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataDiscussionItem for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if (siteDirectoryDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryDataDiscussionItem for Version 1.3.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if (siteDirectoryDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not SiteDirectoryDataDiscussionItem siteDirectoryDataDiscussionItem) + { + throw new ArgumentException("The thing shall be a SiteDirectoryDataDiscussionItem", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryDataDiscussionItem.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryDataDiscussionItem.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("replyTo"u8); + + if (siteDirectoryDataDiscussionItem.ReplyTo.HasValue) + { + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ReplyTo.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryDataDiscussionItem.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryDataDiscussionItem.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var siteDirectoryDataDiscussionItem = thing as SiteDirectoryDataDiscussionItem; - if (siteDirectoryDataDiscussionItem == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SiteDirectoryDataDiscussionItem."); - } + case "author": + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(siteDirectoryDataDiscussionItem); + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "replyto": + writer.WritePropertyName("replyTo"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteDirectoryDataDiscussionItem"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "replyTo", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs index ceb881080..a8e87fb3d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectorySerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteDirectory = CDP4Common.DTO.SiteDirectory; /// /// The purpose of the class is to provide a specific serializer @@ -45,100 +50,1280 @@ namespace CDP4JsonSerializer public class SiteDirectorySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "annotation", annotation => new JArray(annotation) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "defaultParticipantRole", defaultParticipantRole => new JValue(defaultParticipantRole) }, - { "defaultPersonRole", defaultPersonRole => new JValue(defaultPersonRole) }, - { "domain", domain => new JArray(domain) }, - { "domainGroup", domainGroup => new JArray(domainGroup) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "lastModifiedOn", lastModifiedOn => new JValue(((DateTime)lastModifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "logEntry", logEntry => new JArray(logEntry) }, - { "model", model => new JArray(model) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "naturalLanguage", naturalLanguage => new JArray(naturalLanguage) }, - { "organization", organization => new JArray(organization) }, - { "participantRole", participantRole => new JArray(participantRole) }, - { "person", person => new JArray(person) }, - { "personRole", personRole => new JArray(personRole) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "siteReferenceDataLibrary", siteReferenceDataLibrary => new JArray(siteReferenceDataLibrary) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(SiteDirectory siteDirectory) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("annotation", this.PropertySerializerMap["annotation"](siteDirectory.Annotation.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteDirectory.ClassKind))); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](siteDirectory.CreatedOn)); - jsonObject.Add("defaultParticipantRole", this.PropertySerializerMap["defaultParticipantRole"](siteDirectory.DefaultParticipantRole)); - jsonObject.Add("defaultPersonRole", this.PropertySerializerMap["defaultPersonRole"](siteDirectory.DefaultPersonRole)); - jsonObject.Add("domain", this.PropertySerializerMap["domain"](siteDirectory.Domain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("domainGroup", this.PropertySerializerMap["domainGroup"](siteDirectory.DomainGroup.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteDirectory.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteDirectory.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteDirectory.Iid)); - jsonObject.Add("lastModifiedOn", this.PropertySerializerMap["lastModifiedOn"](siteDirectory.LastModifiedOn)); - jsonObject.Add("logEntry", this.PropertySerializerMap["logEntry"](siteDirectory.LogEntry.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("model", this.PropertySerializerMap["model"](siteDirectory.Model.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteDirectory.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](siteDirectory.Name)); - jsonObject.Add("naturalLanguage", this.PropertySerializerMap["naturalLanguage"](siteDirectory.NaturalLanguage.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("organization", this.PropertySerializerMap["organization"](siteDirectory.Organization.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("participantRole", this.PropertySerializerMap["participantRole"](siteDirectory.ParticipantRole.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("person", this.PropertySerializerMap["person"](siteDirectory.Person.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("personRole", this.PropertySerializerMap["personRole"](siteDirectory.PersonRole.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteDirectory.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](siteDirectory.ShortName)); - jsonObject.Add("siteReferenceDataLibrary", this.PropertySerializerMap["siteReferenceDataLibrary"](siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteDirectory.ThingPreference)); - return jsonObject; + if (thing is not SiteDirectory siteDirectory) + { + throw new ArgumentException("The thing shall be a SiteDirectory", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SiteDirectory."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectory since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectory.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("defaultParticipantRole"u8); + + if (siteDirectory.DefaultParticipantRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultPersonRole"u8); + + if (siteDirectory.DefaultPersonRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domainGroup"u8); + + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectory.Iid); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("model"u8); + + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); + + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("organization"u8); + + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("participantRole"u8); + + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("person"u8); + + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectory.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.1.0"); + writer.WriteStartArray("annotation"u8); + + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectory.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("defaultParticipantRole"u8); + + if (siteDirectory.DefaultParticipantRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultPersonRole"u8); + + if (siteDirectory.DefaultPersonRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domainGroup"u8); + + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectory.Iid); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("model"u8); + + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); + + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("organization"u8); + + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("participantRole"u8); + + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("person"u8); + + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectory.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.2.0"); + writer.WriteStartArray("annotation"u8); + + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectory.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("defaultParticipantRole"u8); + + if (siteDirectory.DefaultParticipantRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultPersonRole"u8); + + if (siteDirectory.DefaultPersonRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domainGroup"u8); + + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectory.Iid); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("model"u8); + + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); + + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("organization"u8); + + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("participantRole"u8); + + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("person"u8); + + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectory.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectory.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectory for Version 1.3.0"); + writer.WriteStartArray("annotation"u8); + + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectory.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("defaultParticipantRole"u8); + + if (siteDirectory.DefaultParticipantRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultPersonRole"u8); + + if (siteDirectory.DefaultPersonRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("domainGroup"u8); + + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectory.Iid); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("model"u8); + + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteDirectory.Name); + writer.WriteStartArray("naturalLanguage"u8); + + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("organization"u8); + + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("participantRole"u8); + + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("person"u8); + + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectory.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteDirectory.ShortName); + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectory.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not SiteDirectory siteDirectory) + { + throw new ArgumentException("The thing shall be a SiteDirectory", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("annotation"u8); + + foreach(var annotationItem in siteDirectory.Annotation.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectory.ClassKind.ToString()); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteDirectory.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("defaultParticipantRole"u8); + + if (siteDirectory.DefaultParticipantRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultParticipantRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("defaultPersonRole"u8); + + if (siteDirectory.DefaultPersonRole.HasValue) + { + writer.WriteStringValue(siteDirectory.DefaultPersonRole.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in siteDirectory.Domain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("domainGroup"u8); + + foreach(var domainGroupItem in siteDirectory.DomainGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectory.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectory.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectory.Iid); + writer.WritePropertyName("lastModifiedOn"u8); + writer.WriteStringValue(siteDirectory.LastModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in siteDirectory.LogEntry.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("model"u8); + + foreach(var modelItem in siteDirectory.Model.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectory.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteDirectory.Name); + + writer.WriteStartArray("naturalLanguage"u8); + + foreach(var naturalLanguageItem in siteDirectory.NaturalLanguage.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("organization"u8); + + foreach(var organizationItem in siteDirectory.Organization.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("participantRole"u8); + + foreach(var participantRoleItem in siteDirectory.ParticipantRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("person"u8); + + foreach(var personItem in siteDirectory.Person.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in siteDirectory.PersonRole.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectory.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteDirectory.ShortName); + + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in siteDirectory.SiteReferenceDataLibrary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectory.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var siteDirectory = thing as SiteDirectory; - if (siteDirectory == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SiteDirectory."); - } + case "annotation": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAnnotation && objectListAnnotation.Any()) + { + writer.WriteStartArray("annotation"u8); + + foreach(var annotationItem in objectListAnnotation.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(annotationItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultparticipantrole": + writer.WritePropertyName("defaultParticipantRole"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultpersonrole": + writer.WritePropertyName("defaultPersonRole"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "domain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDomain && objectListDomain.Any()) + { + writer.WriteStartArray("domain"u8); + + foreach(var domainItem in objectListDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainItem); + } + writer.WriteEndArray(); + } + break; + case "domaingroup": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDomainGroup && objectListDomainGroup.Any()) + { + writer.WriteStartArray("domainGroup"u8); + + foreach(var domainGroupItem in objectListDomainGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(domainGroupItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(siteDirectory); + break; + case "lastmodifiedon": + writer.WritePropertyName("lastModifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "logentry": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListLogEntry && objectListLogEntry.Any()) + { + writer.WriteStartArray("logEntry"u8); + + foreach(var logEntryItem in objectListLogEntry.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryItem); + } + writer.WriteEndArray(); + } + break; + case "model": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListModel && objectListModel.Any()) + { + writer.WriteStartArray("model"u8); + + foreach(var modelItem in objectListModel.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(modelItem); + } + writer.WriteEndArray(); + } + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "naturallanguage": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListNaturalLanguage && objectListNaturalLanguage.Any()) + { + writer.WriteStartArray("naturalLanguage"u8); + + foreach(var naturalLanguageItem in objectListNaturalLanguage.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(naturalLanguageItem); + } + writer.WriteEndArray(); + } + break; + case "organization": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListOrganization && objectListOrganization.Any()) + { + writer.WriteStartArray("organization"u8); + + foreach(var organizationItem in objectListOrganization.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(organizationItem); + } + writer.WriteEndArray(); + } + break; + case "participantrole": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListParticipantRole && objectListParticipantRole.Any()) + { + writer.WriteStartArray("participantRole"u8); + + foreach(var participantRoleItem in objectListParticipantRole.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(participantRoleItem); + } + writer.WriteEndArray(); + } + break; + case "person": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListPerson && objectListPerson.Any()) + { + writer.WriteStartArray("person"u8); + + foreach(var personItem in objectListPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personItem); + } + writer.WriteEndArray(); + } + break; + case "personrole": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListPersonRole && objectListPersonRole.Any()) + { + writer.WriteStartArray("personRole"u8); + + foreach(var personRoleItem in objectListPersonRole.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(personRoleItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "sitereferencedatalibrary": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListSiteReferenceDataLibrary && objectListSiteReferenceDataLibrary.Any()) + { + writer.WriteStartArray("siteReferenceDataLibrary"u8); + + foreach(var siteReferenceDataLibraryItem in objectListSiteReferenceDataLibrary.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(siteReferenceDataLibraryItem); + } + writer.WriteEndArray(); + } + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteDirectory"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "annotation", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultParticipantRole", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultPersonRole", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "domain", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "domainGroup", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "lastModifiedOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "logEntry", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "model", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "naturalLanguage", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "organization", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "participantRole", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "person", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "personRole", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "siteReferenceDataLibrary", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs index 09e8f6335..7a6992584 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteDirectoryThingReferenceSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteDirectoryThingReference = CDP4Common.DTO.SiteDirectoryThingReference; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +50,388 @@ namespace CDP4JsonSerializer public class SiteDirectoryThingReferenceSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "referencedRevisionNumber", referencedRevisionNumber => new JValue(referencedRevisionNumber) }, - { "referencedThing", referencedThing => new JValue(referencedThing) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(SiteDirectoryThingReference siteDirectoryThingReference) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteDirectoryThingReference.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteDirectoryThingReference.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteDirectoryThingReference.ModifiedOn)); - jsonObject.Add("referencedRevisionNumber", this.PropertySerializerMap["referencedRevisionNumber"](siteDirectoryThingReference.ReferencedRevisionNumber)); - jsonObject.Add("referencedThing", this.PropertySerializerMap["referencedThing"](siteDirectoryThingReference.ReferencedThing)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteDirectoryThingReference.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteDirectoryThingReference.ThingPreference)); - return jsonObject; + if (thing is not SiteDirectoryThingReference siteDirectoryThingReference) + { + throw new ArgumentException("The thing shall be a SiteDirectoryThingReference", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SiteDirectoryThingReference."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SiteDirectoryThingReference since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryThingReference for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(siteDirectoryThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryThingReference for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(siteDirectoryThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryThingReference.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteDirectoryThingReference for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(siteDirectoryThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryThingReference.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not SiteDirectoryThingReference siteDirectoryThingReference) + { + throw new ArgumentException("The thing shall be a SiteDirectoryThingReference", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteDirectoryThingReference.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteDirectoryThingReference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteDirectoryThingReference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteDirectoryThingReference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteDirectoryThingReference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("referencedRevisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.ReferencedRevisionNumber); + writer.WritePropertyName("referencedThing"u8); + writer.WriteStringValue(siteDirectoryThingReference.ReferencedThing); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteDirectoryThingReference.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteDirectoryThingReference.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var siteDirectoryThingReference = thing as SiteDirectoryThingReference; - if (siteDirectoryThingReference == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SiteDirectoryThingReference."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(siteDirectoryThingReference); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencedrevisionnumber": + writer.WritePropertyName("referencedRevisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "referencedthing": + writer.WritePropertyName("referencedThing"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteDirectoryThingReference"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedRevisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "referencedThing", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs index 72020995e..3bea41e37 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteLogEntrySerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteLogEntry = CDP4Common.DTO.SiteLogEntry; /// /// The purpose of the class is to provide a specific serializer @@ -45,84 +50,754 @@ namespace CDP4JsonSerializer public class SiteLogEntrySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "affectedDomainIid", affectedDomainIid => new JArray(affectedDomainIid) }, - { "affectedItemIid", affectedItemIid => new JArray(affectedItemIid) }, - { "author", author => new JValue(author) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "level", level => new JValue(level.ToString()) }, - { "logEntryChangelogItem", logEntryChangelogItem => new JArray(logEntryChangelogItem) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(SiteLogEntry siteLogEntry) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("affectedDomainIid", this.PropertySerializerMap["affectedDomainIid"](siteLogEntry.AffectedDomainIid.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("affectedItemIid", this.PropertySerializerMap["affectedItemIid"](siteLogEntry.AffectedItemIid.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("author", this.PropertySerializerMap["author"](siteLogEntry.Author)); - jsonObject.Add("category", this.PropertySerializerMap["category"](siteLogEntry.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteLogEntry.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](siteLogEntry.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](siteLogEntry.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteLogEntry.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteLogEntry.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteLogEntry.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](siteLogEntry.LanguageCode)); - jsonObject.Add("level", this.PropertySerializerMap["level"](Enum.GetName(typeof(CDP4Common.CommonData.LogLevelKind), siteLogEntry.Level))); - jsonObject.Add("logEntryChangelogItem", this.PropertySerializerMap["logEntryChangelogItem"](siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteLogEntry.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteLogEntry.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteLogEntry.ThingPreference)); - return jsonObject; + if (thing is not SiteLogEntry siteLogEntry) + { + throw new ArgumentException("The thing shall be a SiteLogEntry", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SiteLogEntry."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SiteLogEntry since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.0.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if (siteLogEntry.Author.HasValue) + { + writer.WriteStringValue(siteLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.1.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if (siteLogEntry.Author.HasValue) + { + writer.WriteStringValue(siteLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.2.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if (siteLogEntry.Author.HasValue) + { + writer.WriteStringValue(siteLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteLogEntry.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteLogEntry for Version 1.3.0"); + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if (siteLogEntry.Author.HasValue) + { + writer.WriteStringValue(siteLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteLogEntry.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not SiteLogEntry siteLogEntry) + { + throw new ArgumentException("The thing shall be a SiteLogEntry", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("affectedDomainIid"u8); + + foreach(var affectedDomainIidItem in siteLogEntry.AffectedDomainIid) + { + writer.WriteStringValue(affectedDomainIidItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("affectedItemIid"u8); + + foreach(var affectedItemIidItem in siteLogEntry.AffectedItemIid) + { + writer.WriteStringValue(affectedItemIidItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("author"u8); + + if (siteLogEntry.Author.HasValue) + { + writer.WriteStringValue(siteLogEntry.Author.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in siteLogEntry.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteLogEntry.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(siteLogEntry.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(siteLogEntry.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteLogEntry.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteLogEntry.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteLogEntry.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(siteLogEntry.LanguageCode); + writer.WritePropertyName("level"u8); + writer.WriteStringValue(siteLogEntry.Level.ToString()); + + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in siteLogEntry.LogEntryChangelogItem.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteLogEntry.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteLogEntry.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteLogEntry.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var siteLogEntry = thing as SiteLogEntry; - if (siteLogEntry == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SiteLogEntry."); - } + case "affecteddomainiid": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAffectedDomainIid && objectListAffectedDomainIid.Any()) + { + writer.WriteStartArray("affectedDomainIid"u8); + + foreach (var affectedDomainIidItem in objectListAffectedDomainIid) + { + writer.WriteStringValue((Guid)affectedDomainIidItem); + } + writer.WriteEndArray(); + } + break; + case "affecteditemiid": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAffectedItemIid && objectListAffectedItemIid.Any()) + { + writer.WriteStartArray("affectedItemIid"u8); + + foreach (var affectedItemIidItem in objectListAffectedItemIid) + { + writer.WriteStringValue((Guid)affectedItemIidItem); + } + writer.WriteEndArray(); + } + break; + case "author": + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } - return this.Serialize(siteLogEntry); + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "level": + writer.WritePropertyName("level"u8); + + if(value != null) + { + writer.WriteStringValue(((LogLevelKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "logentrychangelogitem": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListLogEntryChangelogItem && objectListLogEntryChangelogItem.Any()) + { + writer.WriteStartArray("logEntryChangelogItem"u8); + + foreach(var logEntryChangelogItemItem in objectListLogEntryChangelogItem.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(logEntryChangelogItemItem); + } + writer.WriteEndArray(); + } + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteLogEntry"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "affectedDomainIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "affectedItemIid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "author", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "level", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "logEntryChangelogItem", new []{ "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs index e8b0db415..a2f153e66 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SiteReferenceDataLibrarySerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SiteReferenceDataLibrary = CDP4Common.DTO.SiteReferenceDataLibrary; /// /// The purpose of the class is to provide a specific serializer @@ -45,104 +50,1453 @@ namespace CDP4JsonSerializer public class SiteReferenceDataLibrarySerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "baseQuantityKind", baseQuantityKind => new JArray(((IEnumerable)baseQuantityKind).Cast().Select(x => x.ToJsonObject())) }, - { "baseUnit", baseUnit => new JArray(baseUnit) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "constant", constant => new JArray(constant) }, - { "definedCategory", definedCategory => new JArray(definedCategory) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "fileType", fileType => new JArray(fileType) }, - { "glossary", glossary => new JArray(glossary) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "parameterType", parameterType => new JArray(parameterType) }, - { "referenceSource", referenceSource => new JArray(referenceSource) }, - { "requiredRdl", requiredRdl => new JValue(requiredRdl) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "rule", rule => new JArray(rule) }, - { "scale", scale => new JArray(scale) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JArray(unit) }, - { "unitPrefix", unitPrefix => new JArray(unitPrefix) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(SiteReferenceDataLibrary siteReferenceDataLibrary) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](siteReferenceDataLibrary.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("baseQuantityKind", this.PropertySerializerMap["baseQuantityKind"](siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.orderedItemComparer))); - jsonObject.Add("baseUnit", this.PropertySerializerMap["baseUnit"](siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), siteReferenceDataLibrary.ClassKind))); - jsonObject.Add("constant", this.PropertySerializerMap["constant"](siteReferenceDataLibrary.Constant.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("definedCategory", this.PropertySerializerMap["definedCategory"](siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](siteReferenceDataLibrary.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("fileType", this.PropertySerializerMap["fileType"](siteReferenceDataLibrary.FileType.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("glossary", this.PropertySerializerMap["glossary"](siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](siteReferenceDataLibrary.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](siteReferenceDataLibrary.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](siteReferenceDataLibrary.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](siteReferenceDataLibrary.Name)); - jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("referenceSource", this.PropertySerializerMap["referenceSource"](siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("requiredRdl", this.PropertySerializerMap["requiredRdl"](siteReferenceDataLibrary.RequiredRdl)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](siteReferenceDataLibrary.RevisionNumber)); - jsonObject.Add("rule", this.PropertySerializerMap["rule"](siteReferenceDataLibrary.Rule.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("scale", this.PropertySerializerMap["scale"](siteReferenceDataLibrary.Scale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](siteReferenceDataLibrary.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](siteReferenceDataLibrary.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](siteReferenceDataLibrary.Unit.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("unitPrefix", this.PropertySerializerMap["unitPrefix"](siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.guidComparer))); - return jsonObject; + if (thing is not SiteReferenceDataLibrary siteReferenceDataLibrary) + { + throw new ArgumentException("The thing shall be a SiteReferenceDataLibrary", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SiteReferenceDataLibrary."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SiteReferenceDataLibrary since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if (siteReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if (siteReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if (siteReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SiteReferenceDataLibrary for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Name); + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if (siteReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not SiteReferenceDataLibrary siteReferenceDataLibrary) + { + throw new ArgumentException("The thing shall be a SiteReferenceDataLibrary", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in siteReferenceDataLibrary.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in siteReferenceDataLibrary.BaseQuantityKind.OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in siteReferenceDataLibrary.BaseUnit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ClassKind.ToString()); + + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in siteReferenceDataLibrary.Constant.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in siteReferenceDataLibrary.DefinedCategory.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in siteReferenceDataLibrary.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in siteReferenceDataLibrary.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in siteReferenceDataLibrary.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in siteReferenceDataLibrary.FileType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in siteReferenceDataLibrary.Glossary.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in siteReferenceDataLibrary.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(siteReferenceDataLibrary.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(siteReferenceDataLibrary.Name); + + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in siteReferenceDataLibrary.ParameterType.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in siteReferenceDataLibrary.ReferenceSource.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("requiredRdl"u8); + + if (siteReferenceDataLibrary.RequiredRdl.HasValue) + { + writer.WriteStringValue(siteReferenceDataLibrary.RequiredRdl.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(siteReferenceDataLibrary.RevisionNumber); + + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in siteReferenceDataLibrary.Rule.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in siteReferenceDataLibrary.Scale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(siteReferenceDataLibrary.ThingPreference); + + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in siteReferenceDataLibrary.Unit.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in siteReferenceDataLibrary.UnitPrefix.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var siteReferenceDataLibrary = thing as SiteReferenceDataLibrary; - if (siteReferenceDataLibrary == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SiteReferenceDataLibrary."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "basequantitykind": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListBaseQuantityKind && objectListBaseQuantityKind.Any()) + { + writer.WriteStartArray("baseQuantityKind"u8); + + foreach(var baseQuantityKindItem in objectListBaseQuantityKind.OfType().OrderBy(x => x, this.OrderedItemComparer)) + { + writer.WriteOrderedItem(baseQuantityKindItem); + } + writer.WriteEndArray(); + } + break; + case "baseunit": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListBaseUnit && objectListBaseUnit.Any()) + { + writer.WriteStartArray("baseUnit"u8); + + foreach(var baseUnitItem in objectListBaseUnit.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(baseUnitItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "constant": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListConstant && objectListConstant.Any()) + { + writer.WriteStartArray("constant"u8); + + foreach(var constantItem in objectListConstant.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(constantItem); + } + writer.WriteEndArray(); + } + break; + case "definedcategory": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinedCategory && objectListDefinedCategory.Any()) + { + writer.WriteStartArray("definedCategory"u8); + + foreach(var definedCategoryItem in objectListDefinedCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definedCategoryItem); + } + writer.WriteEndArray(); + } + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } - return this.Serialize(siteReferenceDataLibrary); + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "filetype": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListFileType && objectListFileType.Any()) + { + writer.WriteStartArray("fileType"u8); + + foreach(var fileTypeItem in objectListFileType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(fileTypeItem); + } + writer.WriteEndArray(); + } + break; + case "glossary": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListGlossary && objectListGlossary.Any()) + { + writer.WriteStartArray("glossary"u8); + + foreach(var glossaryItem in objectListGlossary.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(glossaryItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "parametertype": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListParameterType && objectListParameterType.Any()) + { + writer.WriteStartArray("parameterType"u8); + + foreach(var parameterTypeItem in objectListParameterType.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(parameterTypeItem); + } + writer.WriteEndArray(); + } + break; + case "referencesource": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListReferenceSource && objectListReferenceSource.Any()) + { + writer.WriteStartArray("referenceSource"u8); + + foreach(var referenceSourceItem in objectListReferenceSource.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(referenceSourceItem); + } + writer.WriteEndArray(); + } + break; + case "requiredrdl": + writer.WritePropertyName("requiredRdl"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "rule": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRule && objectListRule.Any()) + { + writer.WriteStartArray("rule"u8); + + foreach(var ruleItem in objectListRule.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(ruleItem); + } + writer.WriteEndArray(); + } + break; + case "scale": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListScale && objectListScale.Any()) + { + writer.WriteStartArray("scale"u8); + + foreach(var scaleItem in objectListScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(scaleItem); + } + writer.WriteEndArray(); + } + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListUnit && objectListUnit.Any()) + { + writer.WriteStartArray("unit"u8); + + foreach(var unitItem in objectListUnit.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitItem); + } + writer.WriteEndArray(); + } + break; + case "unitprefix": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListUnitPrefix && objectListUnitPrefix.Any()) + { + writer.WriteStartArray("unitPrefix"u8); + + foreach(var unitPrefixItem in objectListUnitPrefix.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(unitPrefixItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SiteReferenceDataLibrary"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "baseQuantityKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "baseUnit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "constant", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definedCategory", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "fileType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "glossary", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "parameterType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "referenceSource", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "requiredRdl", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "rule", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "scale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "unitPrefix", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs index b4d922433..211260c1a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SolutionSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Solution = CDP4Common.DTO.Solution; /// /// The purpose of the class is to provide a specific serializer @@ -45,76 +50,454 @@ namespace CDP4JsonSerializer public class SolutionSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "author", author => new JValue(author) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(Solution solution) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("author", this.PropertySerializerMap["author"](solution.Author)); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), solution.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](solution.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](solution.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](solution.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](solution.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](solution.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](solution.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](solution.ModifiedOn)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](solution.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](solution.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](solution.ThingPreference)); - return jsonObject; + if (thing is not Solution solution) + { + throw new ArgumentException("The thing shall be a Solution", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Solution."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Solution since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Solution for Version 1.1.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(solution.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(solution.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(solution.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(solution.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(solution.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(solution.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(solution.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(solution.RevisionNumber); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Solution for Version 1.2.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(solution.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(solution.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(solution.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(solution.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(solution.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(solution.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(solution.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(solution.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(solution.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Solution for Version 1.3.0"); + writer.WritePropertyName("author"u8); + writer.WriteStringValue(solution.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(solution.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(solution.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(solution.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(solution.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(solution.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(solution.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(solution.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(solution.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Solution solution) + { + throw new ArgumentException("The thing shall be a Solution", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("author"u8); + writer.WriteStringValue(solution.Author); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(solution.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(solution.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(solution.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in solution.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in solution.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(solution.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(solution.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(solution.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(solution.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(solution.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(solution.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var solution = thing as Solution; - if (solution == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Solution."); - } + case "author": + writer.WritePropertyName("author"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(solution); + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Solution"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "author", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs index ef87f7738..3a100859b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/SpecializedQuantityKindSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using SpecializedQuantityKind = CDP4Common.DTO.SpecializedQuantityKind; /// /// The purpose of the class is to provide a specific serializer @@ -45,90 +50,840 @@ namespace CDP4JsonSerializer public class SpecializedQuantityKindSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "defaultScale", defaultScale => new JValue(defaultScale) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "general", general => new JValue(general) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "possibleScale", possibleScale => new JArray(possibleScale) }, - { "quantityDimensionSymbol", quantityDimensionSymbol => new JValue(quantityDimensionSymbol) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(SpecializedQuantityKind specializedQuantityKind) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](specializedQuantityKind.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](specializedQuantityKind.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), specializedQuantityKind.ClassKind))); - jsonObject.Add("defaultScale", this.PropertySerializerMap["defaultScale"](specializedQuantityKind.DefaultScale)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](specializedQuantityKind.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("general", this.PropertySerializerMap["general"](specializedQuantityKind.General)); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](specializedQuantityKind.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](specializedQuantityKind.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](specializedQuantityKind.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](specializedQuantityKind.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](specializedQuantityKind.Name)); - jsonObject.Add("possibleScale", this.PropertySerializerMap["possibleScale"](specializedQuantityKind.PossibleScale.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("quantityDimensionSymbol", this.PropertySerializerMap["quantityDimensionSymbol"](specializedQuantityKind.QuantityDimensionSymbol)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](specializedQuantityKind.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](specializedQuantityKind.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](specializedQuantityKind.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](specializedQuantityKind.ThingPreference)); - return jsonObject; + if (thing is not SpecializedQuantityKind specializedQuantityKind) + { + throw new ArgumentException("The thing shall be a SpecializedQuantityKind", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of SpecializedQuantityKind."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of SpecializedQuantityKind since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(specializedQuantityKind.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing SpecializedQuantityKind for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(specializedQuantityKind.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not SpecializedQuantityKind specializedQuantityKind) + { + throw new ArgumentException("The thing shall be a SpecializedQuantityKind", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in specializedQuantityKind.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in specializedQuantityKind.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(specializedQuantityKind.ClassKind.ToString()); + writer.WritePropertyName("defaultScale"u8); + writer.WriteStringValue(specializedQuantityKind.DefaultScale); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in specializedQuantityKind.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("general"u8); + writer.WriteStringValue(specializedQuantityKind.General); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in specializedQuantityKind.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(specializedQuantityKind.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(specializedQuantityKind.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(specializedQuantityKind.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(specializedQuantityKind.Name); + + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in specializedQuantityKind.PossibleScale.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("quantityDimensionSymbol"u8); + writer.WriteStringValue(specializedQuantityKind.QuantityDimensionSymbol); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(specializedQuantityKind.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(specializedQuantityKind.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(specializedQuantityKind.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(specializedQuantityKind.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var specializedQuantityKind = thing as SpecializedQuantityKind; - if (specializedQuantityKind == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a SpecializedQuantityKind."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "defaultscale": + writer.WritePropertyName("defaultScale"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "general": + writer.WritePropertyName("general"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(specializedQuantityKind); + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "possiblescale": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListPossibleScale && objectListPossibleScale.Any()) + { + writer.WriteStartArray("possibleScale"u8); + + foreach(var possibleScaleItem in objectListPossibleScale.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(possibleScaleItem); + } + writer.WriteEndArray(); + } + break; + case "quantitydimensionsymbol": + writer.WritePropertyName("quantityDimensionSymbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the SpecializedQuantityKind"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "defaultScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "general", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "possibleScale", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "quantityDimensionSymbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs index 8103951a9..a129ffbc1 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using StakeHolderValueMap = CDP4Common.DTO.StakeHolderValueMap; /// /// The purpose of the class is to provide a specific serializer @@ -45,88 +50,882 @@ namespace CDP4JsonSerializer public class StakeHolderValueMapSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "goal", goal => new JArray(goal) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "requirement", requirement => new JArray(requirement) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "settings", settings => new JArray(settings) }, - { "shortName", shortName => new JValue(shortName) }, - { "stakeholderValue", stakeholderValue => new JArray(stakeholderValue) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueGroup", valueGroup => new JArray(valueGroup) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(StakeHolderValueMap stakeHolderValueMap) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](stakeHolderValueMap.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](stakeHolderValueMap.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), stakeHolderValueMap.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](stakeHolderValueMap.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("goal", this.PropertySerializerMap["goal"](stakeHolderValueMap.Goal.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](stakeHolderValueMap.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](stakeHolderValueMap.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](stakeHolderValueMap.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](stakeHolderValueMap.Name)); - jsonObject.Add("requirement", this.PropertySerializerMap["requirement"](stakeHolderValueMap.Requirement.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](stakeHolderValueMap.RevisionNumber)); - jsonObject.Add("settings", this.PropertySerializerMap["settings"](stakeHolderValueMap.Settings)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](stakeHolderValueMap.ShortName)); - jsonObject.Add("stakeholderValue", this.PropertySerializerMap["stakeholderValue"](stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](stakeHolderValueMap.ThingPreference)); - jsonObject.Add("valueGroup", this.PropertySerializerMap["valueGroup"](stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.guidComparer))); - return jsonObject; + if (thing is not StakeHolderValueMap stakeHolderValueMap) + { + throw new ArgumentException("The thing shall be a StakeHolderValueMap", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of StakeHolderValueMap."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of StakeHolderValueMap since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMap for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeHolderValueMap.Name); + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); + writer.WriteStartArray("settings"u8); + + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeHolderValueMap.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMap for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeHolderValueMap.Name); + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); + writer.WriteStartArray("settings"u8); + + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeHolderValueMap.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMap.ThingPreference); + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMap for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeHolderValueMap.Name); + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); + writer.WriteStartArray("settings"u8); + + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeHolderValueMap.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMap.ThingPreference); + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not StakeHolderValueMap stakeHolderValueMap) + { + throw new ArgumentException("The thing shall be a StakeHolderValueMap", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeHolderValueMap.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeHolderValueMap.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMap.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeHolderValueMap.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMap.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMap.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in stakeHolderValueMap.Goal.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeHolderValueMap.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMap.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMap.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeHolderValueMap.Name); + + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in stakeHolderValueMap.Requirement.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMap.RevisionNumber); + + writer.WriteStartArray("settings"u8); + + foreach(var settingsItem in stakeHolderValueMap.Settings.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeHolderValueMap.ShortName); + + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeHolderValueMap.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMap.ThingPreference); + + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in stakeHolderValueMap.ValueGroup.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var stakeHolderValueMap = thing as StakeHolderValueMap; - if (stakeHolderValueMap == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a StakeHolderValueMap."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "goal": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListGoal && objectListGoal.Any()) + { + writer.WriteStartArray("goal"u8); + + foreach(var goalItem in objectListGoal.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(goalItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); - return this.Serialize(stakeHolderValueMap); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "requirement": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListRequirement && objectListRequirement.Any()) + { + writer.WriteStartArray("requirement"u8); + + foreach(var requirementItem in objectListRequirement.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(requirementItem); + } + writer.WriteEndArray(); + } + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "settings": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListSettings && objectListSettings.Any()) + { + writer.WriteStartArray("settings"u8); + + foreach(var settingsItem in objectListSettings.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(settingsItem); + } + writer.WriteEndArray(); + } + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "stakeholdervalue": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListStakeholderValue && objectListStakeholderValue.Any()) + { + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + writer.WriteEndArray(); + } + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuegroup": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListValueGroup && objectListValueGroup.Any()) + { + writer.WriteStartArray("valueGroup"u8); + + foreach(var valueGroupItem in objectListValueGroup.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(valueGroupItem); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the StakeHolderValueMap"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "goal", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "requirement", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "settings", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholderValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueGroup", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs index 9d424947f..2210e26f9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeHolderValueMapSettingsSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using StakeHolderValueMapSettings = CDP4Common.DTO.StakeHolderValueMapSettings; /// /// The purpose of the class is to provide a specific serializer @@ -45,72 +50,517 @@ namespace CDP4JsonSerializer public class StakeHolderValueMapSettingsSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "goalToValueGroupRelationship", goalToValueGroupRelationship => new JValue(goalToValueGroupRelationship) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "stakeholderValueToRequirementRelationship", stakeholderValueToRequirementRelationship => new JValue(stakeholderValueToRequirementRelationship) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "valueGroupToStakeholderValueRelationship", valueGroupToStakeholderValueRelationship => new JValue(valueGroupToStakeholderValueRelationship) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(StakeHolderValueMapSettings stakeHolderValueMapSettings) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), stakeHolderValueMapSettings.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("goalToValueGroupRelationship", this.PropertySerializerMap["goalToValueGroupRelationship"](stakeHolderValueMapSettings.GoalToValueGroupRelationship)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](stakeHolderValueMapSettings.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](stakeHolderValueMapSettings.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](stakeHolderValueMapSettings.RevisionNumber)); - jsonObject.Add("stakeholderValueToRequirementRelationship", this.PropertySerializerMap["stakeholderValueToRequirementRelationship"](stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](stakeHolderValueMapSettings.ThingPreference)); - jsonObject.Add("valueGroupToStakeholderValueRelationship", this.PropertySerializerMap["valueGroupToStakeholderValueRelationship"](stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship)); - return jsonObject; + if (thing is not StakeHolderValueMapSettings stakeHolderValueMapSettings) + { + throw new ArgumentException("The thing shall be a StakeHolderValueMapSettings", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of StakeHolderValueMapSettings."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of StakeHolderValueMapSettings since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMapSettings for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("goalToValueGroupRelationship"u8); + + if (stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.GoalToValueGroupRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMapSettings.RevisionNumber); + writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); + + if (stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); + + if (stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMapSettings for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("goalToValueGroupRelationship"u8); + + if (stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.GoalToValueGroupRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMapSettings.RevisionNumber); + writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); + + if (stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ThingPreference); + writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); + + if (stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing StakeHolderValueMapSettings for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("goalToValueGroupRelationship"u8); + + if (stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.GoalToValueGroupRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMapSettings.RevisionNumber); + writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); + + if (stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ThingPreference); + writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); + + if (stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not StakeHolderValueMapSettings stakeHolderValueMapSettings) + { + throw new ArgumentException("The thing shall be a StakeHolderValueMapSettings", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeHolderValueMapSettings.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeHolderValueMapSettings.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("goalToValueGroupRelationship"u8); + + if (stakeHolderValueMapSettings.GoalToValueGroupRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.GoalToValueGroupRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeHolderValueMapSettings.RevisionNumber); + writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); + + if (stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.StakeholderValueToRequirementRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeHolderValueMapSettings.ThingPreference); + writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); + + if (stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.HasValue) + { + writer.WriteStringValue(stakeHolderValueMapSettings.ValueGroupToStakeholderValueRelationship.Value); + } + else + { + writer.WriteNullValue(); + } + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var stakeHolderValueMapSettings = thing as StakeHolderValueMapSettings; - if (stakeHolderValueMapSettings == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a StakeHolderValueMapSettings."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "goaltovaluegrouprelationship": + writer.WritePropertyName("goalToValueGroupRelationship"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(stakeHolderValueMapSettings); + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "stakeholdervaluetorequirementrelationship": + writer.WritePropertyName("stakeholderValueToRequirementRelationship"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "valuegrouptostakeholdervaluerelationship": + writer.WritePropertyName("valueGroupToStakeholderValueRelationship"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the StakeHolderValueMapSettings"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "goalToValueGroupRelationship", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholderValueToRequirementRelationship", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "valueGroupToStakeholderValueRelationship", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs index 7d46ac59c..906ba8d0d 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Stakeholder = CDP4Common.DTO.Stakeholder; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +50,662 @@ namespace CDP4JsonSerializer public class StakeholderSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "stakeholderValue", stakeholderValue => new JArray(stakeholderValue) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(Stakeholder stakeholder) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](stakeholder.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](stakeholder.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), stakeholder.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](stakeholder.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](stakeholder.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](stakeholder.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](stakeholder.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](stakeholder.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](stakeholder.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](stakeholder.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](stakeholder.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](stakeholder.ShortName)); - jsonObject.Add("stakeholderValue", this.PropertySerializerMap["stakeholderValue"](stakeholder.StakeholderValue.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](stakeholder.ThingPreference)); - return jsonObject; + if (thing is not Stakeholder stakeholder) + { + throw new ArgumentException("The thing shall be a Stakeholder", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Stakeholder."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Stakeholder since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Stakeholder for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholder.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholder.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholder.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholder.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Stakeholder for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholder.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholder.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholder.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholder.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholder.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Stakeholder for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholder.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholder.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholder.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholder.ShortName); + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholder.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Stakeholder stakeholder) + { + throw new ArgumentException("The thing shall be a Stakeholder", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholder.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholder.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholder.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholder.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholder.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholder.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholder.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholder.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholder.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholder.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholder.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholder.ShortName); + + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in stakeholder.StakeholderValue.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholder.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var stakeholder = thing as Stakeholder; - if (stakeholder == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Stakeholder."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); - return this.Serialize(stakeholder); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "stakeholdervalue": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListStakeholderValue && objectListStakeholderValue.Any()) + { + writer.WriteStartArray("stakeholderValue"u8); + + foreach(var stakeholderValueItem in objectListStakeholderValue.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(stakeholderValueItem); + } + writer.WriteEndArray(); + } + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Stakeholder"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "stakeholderValue", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs index 6d2a41808..87a1b966a 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/StakeholderValueSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using StakeholderValue = CDP4Common.DTO.StakeholderValue; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +50,607 @@ namespace CDP4JsonSerializer public class StakeholderValueSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(StakeholderValue stakeholderValue) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](stakeholderValue.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](stakeholderValue.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), stakeholderValue.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](stakeholderValue.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](stakeholderValue.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](stakeholderValue.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](stakeholderValue.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](stakeholderValue.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](stakeholderValue.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](stakeholderValue.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](stakeholderValue.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](stakeholderValue.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](stakeholderValue.ThingPreference)); - return jsonObject; + if (thing is not StakeholderValue stakeholderValue) + { + throw new ArgumentException("The thing shall be a StakeholderValue", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of StakeholderValue."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of StakeholderValue since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing StakeholderValue for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholderValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholderValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholderValue.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholderValue.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholderValue.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing StakeholderValue for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholderValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholderValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholderValue.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholderValue.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholderValue.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholderValue.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing StakeholderValue for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholderValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholderValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholderValue.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholderValue.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholderValue.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholderValue.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not StakeholderValue stakeholderValue) + { + throw new ArgumentException("The thing shall be a StakeholderValue", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in stakeholderValue.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in stakeholderValue.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(stakeholderValue.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in stakeholderValue.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in stakeholderValue.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in stakeholderValue.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in stakeholderValue.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(stakeholderValue.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(stakeholderValue.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(stakeholderValue.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(stakeholderValue.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(stakeholderValue.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(stakeholderValue.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var stakeholderValue = thing as StakeholderValue; - if (stakeholderValue == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a StakeholderValue."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } - return this.Serialize(stakeholderValue); + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the StakeholderValue"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs index e4ddfde5e..099bba9d3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TelephoneNumberSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using TelephoneNumber = CDP4Common.DTO.TelephoneNumber; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +50,441 @@ namespace CDP4JsonSerializer public class TelephoneNumberSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(value) }, - { "vcardType", vcardType => new JArray(vcardType) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(TelephoneNumber telephoneNumber) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), telephoneNumber.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](telephoneNumber.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](telephoneNumber.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](telephoneNumber.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](telephoneNumber.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](telephoneNumber.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](telephoneNumber.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](telephoneNumber.Value)); - jsonObject.Add("vcardType", this.PropertySerializerMap["vcardType"](telephoneNumber.VcardType.Select(e => Enum.GetName(typeof(CDP4Common.SiteDirectoryData.VcardTelephoneNumberKind), e)))); - return jsonObject; + if (thing is not TelephoneNumber telephoneNumber) + { + throw new ArgumentException("The thing shall be a TelephoneNumber", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of TelephoneNumber."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of TelephoneNumber since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing TelephoneNumber for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing TelephoneNumber for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(telephoneNumber.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing TelephoneNumber for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(telephoneNumber.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(telephoneNumber.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing TelephoneNumber for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(telephoneNumber.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(telephoneNumber.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not TelephoneNumber telephoneNumber) + { + throw new ArgumentException("The thing shall be a TelephoneNumber", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(telephoneNumber.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in telephoneNumber.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in telephoneNumber.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(telephoneNumber.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(telephoneNumber.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(telephoneNumber.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(telephoneNumber.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(telephoneNumber.Value); + + writer.WriteStartArray("vcardType"u8); + + foreach(var vcardTypeItem in telephoneNumber.VcardType) + { + writer.WriteStringValue(vcardTypeItem.ToString()); + } + + writer.WriteEndArray(); + + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var telephoneNumber = thing as TelephoneNumber; - if (telephoneNumber == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a TelephoneNumber."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(telephoneNumber); + break; + case "value": + writer.WritePropertyName("value"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "vcardtype": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListVcardType && objectListVcardType.Any()) + { + writer.WriteStartArray("vcardType"u8); + + foreach (var vcardTypeItem in objectListVcardType) + { + writer.WriteStringValue(((VcardTelephoneNumberKind)vcardTypeItem).ToString()); + } + writer.WriteEndArray(); + } + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the TelephoneNumber"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "vcardType", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs index 0fac1a897..8211cb823 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TermSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using Term = CDP4Common.DTO.Term; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +50,616 @@ namespace CDP4JsonSerializer public class TermSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(Term term) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](term.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), term.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](term.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](term.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](term.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](term.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](term.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](term.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](term.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](term.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](term.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](term.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](term.ThingPreference)); - return jsonObject; + if (thing is not Term term) + { + throw new ArgumentException("The thing shall be a Term", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of Term."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of Term since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(term.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(term.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(term.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(term.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(term.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(term.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(term.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(term.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(term.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(term.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(term.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(term.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(term.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(term.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(term.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(term.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(term.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(term.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(term.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(term.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(term.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing Term for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(term.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(term.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(term.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(term.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(term.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(term.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(term.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(term.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not Term term) + { + throw new ArgumentException("The thing shall be a Term", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in term.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(term.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in term.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in term.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in term.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in term.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(term.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(term.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(term.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(term.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(term.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(term.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(term.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var term = thing as Term; - if (term == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a Term."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); - return this.Serialize(term); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the Term"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs index ff548fa02..7d47a3e64 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextParameterTypeSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using TextParameterType = CDP4Common.DTO.TextParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +50,704 @@ namespace CDP4JsonSerializer public class TextParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(TextParameterType textParameterType) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](textParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](textParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), textParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](textParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](textParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](textParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](textParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](textParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](textParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](textParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](textParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](textParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](textParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](textParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](textParameterType.ThingPreference)); - return jsonObject; + if (thing is not TextParameterType textParameterType) + { + throw new ArgumentException("The thing shall be a TextParameterType", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of TextParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of TextParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing TextParameterType for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not TextParameterType textParameterType) + { + throw new ArgumentException("The thing shall be a TextParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in textParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textParameterType.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in textParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in textParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(textParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(textParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textParameterType.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var textParameterType = thing as TextParameterType; - if (textParameterType == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a TextParameterType."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); - return this.Serialize(textParameterType); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the TextParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs index a17ccf915..78f665b94 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TextualNoteSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using TextualNote = CDP4Common.DTO.TextualNote; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +50,530 @@ namespace CDP4JsonSerializer public class TextualNoteSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "content", content => new JValue(content) }, - { "createdOn", createdOn => new JValue(((DateTime)createdOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "languageCode", languageCode => new JValue(languageCode) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "owner", owner => new JValue(owner) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(TextualNote textualNote) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("category", this.PropertySerializerMap["category"](textualNote.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), textualNote.ClassKind))); - jsonObject.Add("content", this.PropertySerializerMap["content"](textualNote.Content)); - jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](textualNote.CreatedOn)); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](textualNote.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](textualNote.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](textualNote.Iid)); - jsonObject.Add("languageCode", this.PropertySerializerMap["languageCode"](textualNote.LanguageCode)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](textualNote.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](textualNote.Name)); - jsonObject.Add("owner", this.PropertySerializerMap["owner"](textualNote.Owner)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](textualNote.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](textualNote.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](textualNote.ThingPreference)); - return jsonObject; + if (thing is not TextualNote textualNote) + { + throw new ArgumentException("The thing shall be a TextualNote", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of TextualNote."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of TextualNote since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing TextualNote for Version 1.1.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textualNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(textualNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textualNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(textualNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textualNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textualNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(textualNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textualNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textualNote.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing TextualNote for Version 1.2.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textualNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(textualNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textualNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(textualNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textualNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textualNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(textualNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textualNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textualNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textualNote.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing TextualNote for Version 1.3.0"); + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textualNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(textualNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textualNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(textualNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textualNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textualNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(textualNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textualNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textualNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textualNote.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not TextualNote textualNote) + { + throw new ArgumentException("The thing shall be a TextualNote", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in textualNote.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(textualNote.ClassKind.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStringValue(textualNote.Content); + writer.WritePropertyName("createdOn"u8); + writer.WriteStringValue(textualNote.CreatedOn.ToString(SerializerHelper.DateTimeFormat)); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in textualNote.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in textualNote.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(textualNote.Iid); + writer.WritePropertyName("languageCode"u8); + writer.WriteStringValue(textualNote.LanguageCode); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(textualNote.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(textualNote.Name); + writer.WritePropertyName("owner"u8); + writer.WriteStringValue(textualNote.Owner); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(textualNote.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(textualNote.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(textualNote.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var textualNote = thing as TextualNote; - if (textualNote == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a TextualNote."); - } + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "content": + writer.WritePropertyName("content"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(textualNote); + break; + case "createdon": + writer.WritePropertyName("createdOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "languagecode": + writer.WritePropertyName("languageCode"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "owner": + writer.WritePropertyName("owner"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the TextualNote"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "content", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "createdOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "languageCode", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "owner", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs index f04cdb6e4..c66f62fe3 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/TimeOfDayParameterTypeSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using TimeOfDayParameterType = CDP4Common.DTO.TimeOfDayParameterType; /// /// The purpose of the class is to provide a specific serializer @@ -45,82 +50,704 @@ namespace CDP4JsonSerializer public class TimeOfDayParameterTypeSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "symbol", symbol => new JValue(symbol) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(TimeOfDayParameterType timeOfDayParameterType) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](timeOfDayParameterType.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](timeOfDayParameterType.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), timeOfDayParameterType.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](timeOfDayParameterType.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](timeOfDayParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](timeOfDayParameterType.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](timeOfDayParameterType.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](timeOfDayParameterType.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](timeOfDayParameterType.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](timeOfDayParameterType.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](timeOfDayParameterType.ShortName)); - jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](timeOfDayParameterType.Symbol)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](timeOfDayParameterType.ThingPreference)); - return jsonObject; + if (thing is not TimeOfDayParameterType timeOfDayParameterType) + { + throw new ArgumentException("The thing shall be a TimeOfDayParameterType", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of TimeOfDayParameterType."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of TimeOfDayParameterType since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(timeOfDayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(timeOfDayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(timeOfDayParameterType.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing TimeOfDayParameterType for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(timeOfDayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(timeOfDayParameterType.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not TimeOfDayParameterType timeOfDayParameterType) + { + throw new ArgumentException("The thing shall be a TimeOfDayParameterType", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in timeOfDayParameterType.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in timeOfDayParameterType.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(timeOfDayParameterType.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in timeOfDayParameterType.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in timeOfDayParameterType.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in timeOfDayParameterType.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in timeOfDayParameterType.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(timeOfDayParameterType.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(timeOfDayParameterType.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(timeOfDayParameterType.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(timeOfDayParameterType.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(timeOfDayParameterType.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(timeOfDayParameterType.ShortName); + writer.WritePropertyName("symbol"u8); + writer.WriteStringValue(timeOfDayParameterType.Symbol); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(timeOfDayParameterType.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var timeOfDayParameterType = thing as TimeOfDayParameterType; - if (timeOfDayParameterType == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a TimeOfDayParameterType."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); - return this.Serialize(timeOfDayParameterType); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "symbol": + writer.WritePropertyName("symbol"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the TimeOfDayParameterType"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "symbol", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs index ec3683e88..63ae81ea9 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitFactorSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using UnitFactor = CDP4Common.DTO.UnitFactor; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +50,401 @@ namespace CDP4JsonSerializer public class UnitFactorSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "exponent", exponent => new JValue(exponent) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "unit", unit => new JValue(unit) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(UnitFactor unitFactor) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), unitFactor.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](unitFactor.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](unitFactor.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("exponent", this.PropertySerializerMap["exponent"](unitFactor.Exponent)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](unitFactor.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](unitFactor.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](unitFactor.RevisionNumber)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](unitFactor.ThingPreference)); - jsonObject.Add("unit", this.PropertySerializerMap["unit"](unitFactor.Unit)); - return jsonObject; + if (thing is not UnitFactor unitFactor) + { + throw new ArgumentException("The thing shall be a UnitFactor", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of UnitFactor."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of UnitFactor since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing UnitFactor for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing UnitFactor for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing UnitFactor for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitFactor.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing UnitFactor for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitFactor.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not UnitFactor unitFactor) + { + throw new ArgumentException("The thing shall be a UnitFactor", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitFactor.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitFactor.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitFactor.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("exponent"u8); + writer.WriteStringValue(unitFactor.Exponent); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitFactor.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitFactor.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitFactor.RevisionNumber); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitFactor.ThingPreference); + writer.WritePropertyName("unit"u8); + writer.WriteStringValue(unitFactor.Unit); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var unitFactor = thing as UnitFactor; - if (unitFactor == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a UnitFactor."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(unitFactor); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "exponent": + writer.WritePropertyName("exponent"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "unit": + writer.WritePropertyName("unit"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the UnitFactor"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "exponent", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "unit", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs index 0f7d773d6..5a48c7584 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UnitPrefixSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using UnitPrefix = CDP4Common.DTO.UnitPrefix; /// /// The purpose of the class is to provide a specific serializer @@ -45,80 +50,640 @@ namespace CDP4JsonSerializer public class UnitPrefixSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "conversionFactor", conversionFactor => new JValue(conversionFactor) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "isDeprecated", isDeprecated => new JValue(isDeprecated) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(UnitPrefix unitPrefix) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](unitPrefix.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), unitPrefix.ClassKind))); - jsonObject.Add("conversionFactor", this.PropertySerializerMap["conversionFactor"](unitPrefix.ConversionFactor)); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](unitPrefix.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](unitPrefix.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](unitPrefix.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](unitPrefix.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](unitPrefix.Iid)); - jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](unitPrefix.IsDeprecated)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](unitPrefix.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](unitPrefix.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](unitPrefix.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](unitPrefix.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](unitPrefix.ThingPreference)); - return jsonObject; + if (thing is not UnitPrefix unitPrefix) + { + throw new ArgumentException("The thing shall be a UnitPrefix", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of UnitPrefix."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of UnitPrefix since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.0.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitPrefix.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitPrefix.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitPrefix.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing UnitPrefix for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitPrefix.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitPrefix.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not UnitPrefix unitPrefix) + { + throw new ArgumentException("The thing shall be a UnitPrefix", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in unitPrefix.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(unitPrefix.ClassKind.ToString()); + writer.WritePropertyName("conversionFactor"u8); + writer.WriteStringValue(unitPrefix.ConversionFactor); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in unitPrefix.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in unitPrefix.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in unitPrefix.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in unitPrefix.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(unitPrefix.Iid); + writer.WritePropertyName("isDeprecated"u8); + writer.WriteBooleanValue(unitPrefix.IsDeprecated); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(unitPrefix.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(unitPrefix.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(unitPrefix.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(unitPrefix.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(unitPrefix.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var unitPrefix = thing as UnitPrefix; - if (unitPrefix == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a UnitPrefix."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "conversionfactor": + writer.WritePropertyName("conversionFactor"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); - return this.Serialize(unitPrefix); + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isdeprecated": + writer.WritePropertyName("isDeprecated"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the UnitPrefix"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "conversionFactor", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isDeprecated", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs index 8135775aa..600843cfa 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserPreferenceSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using UserPreference = CDP4Common.DTO.UserPreference; /// /// The purpose of the class is to provide a specific serializer @@ -45,70 +50,401 @@ namespace CDP4JsonSerializer public class UserPreferenceSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "value", value => new JValue(value) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(UserPreference userPreference) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), userPreference.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](userPreference.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](userPreference.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](userPreference.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](userPreference.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](userPreference.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](userPreference.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](userPreference.ThingPreference)); - jsonObject.Add("value", this.PropertySerializerMap["value"](userPreference.Value)); - return jsonObject; + if (thing is not UserPreference userPreference) + { + throw new ArgumentException("The thing shall be a UserPreference", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of UserPreference."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of UserPreference since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing UserPreference for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing UserPreference for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userPreference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing UserPreference for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userPreference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userPreference.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing UserPreference for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userPreference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userPreference.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not UserPreference userPreference) + { + throw new ArgumentException("The thing shall be a UserPreference", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userPreference.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userPreference.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userPreference.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userPreference.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userPreference.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userPreference.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(userPreference.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userPreference.ThingPreference); + writer.WritePropertyName("value"u8); + writer.WriteStringValue(userPreference.Value); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var userPreference = thing as UserPreference; - if (userPreference == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a UserPreference."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(userPreference); + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "value": + writer.WritePropertyName("value"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the UserPreference"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "value", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs index 89559bfca..78fbfa20b 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/UserRuleVerificationSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using UserRuleVerification = CDP4Common.DTO.UserRuleVerification; /// /// The purpose of the class is to provide a specific serializer @@ -45,75 +50,495 @@ namespace CDP4JsonSerializer public class UserRuleVerificationSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "executedOn", executedOn => new JValue(executedOn != null ? ((DateTime)executedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") : null) }, - { "iid", iid => new JValue(iid) }, - { "isActive", isActive => new JValue(isActive) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "rule", rule => new JValue(rule) }, - { "status", status => new JValue(status.ToString()) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - { "violation", violation => new JArray(violation) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); + + /// + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. + /// + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - private JObject Serialize(UserRuleVerification userRuleVerification) + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), userRuleVerification.ClassKind))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](userRuleVerification.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](userRuleVerification.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("executedOn", this.PropertySerializerMap["executedOn"](userRuleVerification.ExecutedOn)); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](userRuleVerification.Iid)); - jsonObject.Add("isActive", this.PropertySerializerMap["isActive"](userRuleVerification.IsActive)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](userRuleVerification.ModifiedOn)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](userRuleVerification.RevisionNumber)); - jsonObject.Add("rule", this.PropertySerializerMap["rule"](userRuleVerification.Rule)); - jsonObject.Add("status", this.PropertySerializerMap["status"](Enum.GetName(typeof(CDP4Common.EngineeringModelData.RuleVerificationStatusKind), userRuleVerification.Status))); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](userRuleVerification.ThingPreference)); - return jsonObject; + if (thing is not UserRuleVerification userRuleVerification) + { + throw new ArgumentException("The thing shall be a UserRuleVerification", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of UserRuleVerification."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of UserRuleVerification since Version is below 1.0.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.0.0": + Logger.Log(LogLevel.Trace, "Serializing UserRuleVerification for Version 1.0.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WritePropertyName("executedOn"u8); + + if (userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + break; + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing UserRuleVerification for Version 1.1.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if (userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing UserRuleVerification for Version 1.2.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if (userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userRuleVerification.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing UserRuleVerification for Version 1.3.0"); + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if (userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userRuleVerification.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not UserRuleVerification userRuleVerification) + { + throw new ArgumentException("The thing shall be a UserRuleVerification", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(userRuleVerification.ClassKind.ToString()); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in userRuleVerification.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in userRuleVerification.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("executedOn"u8); + + if (userRuleVerification.ExecutedOn.HasValue) + { + writer.WriteStringValue(userRuleVerification.ExecutedOn.Value.ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(userRuleVerification.Iid); + writer.WritePropertyName("isActive"u8); + writer.WriteBooleanValue(userRuleVerification.IsActive); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(userRuleVerification.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(userRuleVerification.RevisionNumber); + writer.WritePropertyName("rule"u8); + writer.WriteStringValue(userRuleVerification.Rule); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(userRuleVerification.Status.ToString()); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(userRuleVerification.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var userRuleVerification = thing as UserRuleVerification; - if (userRuleVerification == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a UserRuleVerification."); - } + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "executedon": + writer.WritePropertyName("executedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "isactive": + writer.WritePropertyName("isActive"u8); + + if(value != null) + { + writer.WriteBooleanValue((bool)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } - return this.Serialize(userRuleVerification); + break; + case "rule": + writer.WritePropertyName("rule"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "status": + writer.WritePropertyName("status"u8); + + if(value != null) + { + writer.WriteStringValue(((RuleVerificationStatusKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the UserRuleVerification"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "classKind", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "executedOn", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "isActive", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "rule", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "status", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + { "violation", new []{ "1.0.0", "1.1.0", "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs index 8dab8e54f..24dfcbd78 100644 --- a/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs +++ b/CDP4JsonSerializer/AutoGenDtoSerializer/ValueGroupSerializer.cs @@ -1,27 +1,25 @@ -// -------------------------------------------------------------------------------------------------------------------- -// +// -------------------------------------------------------------------------------------------------------------------------------// // Copyright (c) 2015-2024 Starion Group S.A. -// -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, -// Antoine Théate, Omar Elebiary, Jaime Bernar -// +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// // This file is part of CDP4-COMET SDK Community Edition -// This is an auto-generated class. Any manual changes to this file will be overwritten! -// +// // The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// +// // The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -------------------------------------------------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------ // --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- @@ -30,14 +28,21 @@ namespace CDP4JsonSerializer { using System; - using System.Collections; using System.Collections.Generic; using System.Linq; + using System.Text.Json; - using CDP4Common.DTO; + using CDP4Common; + using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; + using CDP4Common.ReportingData; + using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using Newtonsoft.Json.Linq; + using NLog; + + using Thing = CDP4Common.DTO.Thing; + using ValueGroup = CDP4Common.DTO.ValueGroup; /// /// The purpose of the class is to provide a specific serializer @@ -45,78 +50,607 @@ namespace CDP4JsonSerializer public class ValueGroupSerializer : BaseThingSerializer, IThingSerializer { /// - /// The map containing the serialization methods + /// The minimal that is allowed for serialization of a . + /// An error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - private readonly Dictionary> propertySerializerMap = new Dictionary> - { - { "actor", actor => new JValue(actor) }, - { "alias", alias => new JArray(alias) }, - { "category", category => new JArray(category) }, - { "classKind", classKind => new JValue(classKind.ToString()) }, - { "definition", definition => new JArray(definition) }, - { "excludedDomain", excludedDomain => new JArray(excludedDomain) }, - { "excludedPerson", excludedPerson => new JArray(excludedPerson) }, - { "hyperLink", hyperLink => new JArray(hyperLink) }, - { "iid", iid => new JValue(iid) }, - { "modifiedOn", modifiedOn => new JValue(((DateTime)modifiedOn).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")) }, - { "name", name => new JValue(name) }, - { "revisionNumber", revisionNumber => new JValue(revisionNumber) }, - { "shortName", shortName => new JValue(shortName) }, - { "thingPreference", thingPreference => new JValue(thingPreference) }, - }; + private static Version minimalAllowedDataModelVersion = Version.Parse("1.0.0"); /// - /// Serialize the + /// The minimal that is allowed for serialization of a . + /// When a Requested Data Model version for Serialization is lower than this, the object will not be Serialized, just ignored. + /// NO error will be thrown when a Requested Data Model version for Serialization is lower than this. /// - /// The to serialize - /// The - private JObject Serialize(ValueGroup valueGroup) + private static Version thingMinimalAllowedDataModelVersion = Version.Parse("1.1.0"); + + /// + /// Serializes a into an + /// + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + /// If the provided is not an + /// If the provided is not supported + public void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion) { - var jsonObject = new JObject(); - jsonObject.Add("alias", this.PropertySerializerMap["alias"](valueGroup.Alias.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("category", this.PropertySerializerMap["category"](valueGroup.Category.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), valueGroup.ClassKind))); - jsonObject.Add("definition", this.PropertySerializerMap["definition"](valueGroup.Definition.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](valueGroup.ExcludedDomain.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](valueGroup.ExcludedPerson.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](valueGroup.HyperLink.OrderBy(x => x, this.guidComparer))); - jsonObject.Add("iid", this.PropertySerializerMap["iid"](valueGroup.Iid)); - jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](valueGroup.ModifiedOn)); - jsonObject.Add("name", this.PropertySerializerMap["name"](valueGroup.Name)); - jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](valueGroup.RevisionNumber)); - jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](valueGroup.ShortName)); - jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](valueGroup.ThingPreference)); - return jsonObject; + if (thing is not ValueGroup valueGroup) + { + throw new ArgumentException("The thing shall be a ValueGroup", nameof(thing)); + } + + if (requestedDataModelVersion < minimalAllowedDataModelVersion) + { + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported for serialization of ValueGroup."); + } + + if (requestedDataModelVersion < thingMinimalAllowedDataModelVersion) + { + Logger.Log(LogLevel.Info, "Skipping serialization of ValueGroup since Version is below 1.1.0"); + return; + } + + writer.WriteStartObject(); + + switch(requestedDataModelVersion.ToString(3)) + { + case "1.1.0": + Logger.Log(LogLevel.Trace, "Serializing ValueGroup for Version 1.1.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(valueGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(valueGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(valueGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(valueGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(valueGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(valueGroup.ShortName); + break; + case "1.2.0": + Logger.Log(LogLevel.Trace, "Serializing ValueGroup for Version 1.2.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(valueGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(valueGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(valueGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(valueGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(valueGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(valueGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(valueGroup.ThingPreference); + break; + case "1.3.0": + Logger.Log(LogLevel.Trace, "Serializing ValueGroup for Version 1.3.0"); + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(valueGroup.ClassKind.ToString()); + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(valueGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(valueGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(valueGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(valueGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(valueGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(valueGroup.ThingPreference); + break; + default: + throw new NotSupportedException($"The provided version {requestedDataModelVersion.ToString(3)} is not supported"); + } + + writer.WriteEndObject(); } /// - /// Gets the map containing the serialization method for each property of the class. + /// Serializes a into an /// - public IReadOnlyDictionary> PropertySerializerMap + /// The that have to be serialized + /// The + /// If the provided is not an + public void Serialize(Thing thing, Utf8JsonWriter writer) { - get { return this.propertySerializerMap; } + if (thing is not ValueGroup valueGroup) + { + throw new ArgumentException("The thing shall be a ValueGroup", nameof(thing)); + } + + writer.WriteStartObject(); + + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in valueGroup.Alias.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in valueGroup.Category.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("classKind"u8); + writer.WriteStringValue(valueGroup.ClassKind.ToString()); + + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in valueGroup.Definition.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in valueGroup.ExcludedDomain.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in valueGroup.ExcludedPerson.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + + writer.WriteEndArray(); + + + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in valueGroup.HyperLink.OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + + writer.WriteEndArray(); + + writer.WritePropertyName("iid"u8); + writer.WriteStringValue(valueGroup.Iid); + writer.WritePropertyName("modifiedOn"u8); + writer.WriteStringValue(valueGroup.ModifiedOn.ToString(SerializerHelper.DateTimeFormat)); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(valueGroup.Name); + writer.WritePropertyName("revisionNumber"u8); + writer.WriteNumberValue(valueGroup.RevisionNumber); + writer.WritePropertyName("shortName"u8); + writer.WriteStringValue(valueGroup.ShortName); + writer.WritePropertyName("thingPreference"u8); + writer.WriteStringValue(valueGroup.ThingPreference); + + writer.WriteEndObject(); } /// - /// Serialize the to JObject + /// Serialize a value for a property into a /// - /// The to serialize - /// The - public JObject Serialize(Thing thing) + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion) { - if (thing == null) + var requestedVersion = requestedDataModelVersion.ToString(3); + + if(!AllowedVersionsPerProperty[propertyName].Contains(requestedVersion)) { - throw new ArgumentNullException($"The {nameof(thing)} may not be null.", nameof(thing)); + return; } - var valueGroup = thing as ValueGroup; - if (valueGroup == null) + this.SerializeProperty(propertyName, value, writer); + } + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// This method should only be used in the scope of serializing a + public void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer) + { + switch(propertyName.ToLower()) { - throw new InvalidOperationException("The thing is not a ValueGroup."); - } + case "alias": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListAlias && objectListAlias.Any()) + { + writer.WriteStartArray("alias"u8); + + foreach(var aliasItem in objectListAlias.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(aliasItem); + } + writer.WriteEndArray(); + } + break; + case "category": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListCategory && objectListCategory.Any()) + { + writer.WriteStartArray("category"u8); + + foreach(var categoryItem in objectListCategory.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(categoryItem); + } + writer.WriteEndArray(); + } + break; + case "classkind": + writer.WritePropertyName("classKind"u8); + + if(value != null) + { + writer.WriteStringValue(((ClassKind)value).ToString()); + } + else + { + writer.WriteNullValue(); + } + + break; + case "definition": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListDefinition && objectListDefinition.Any()) + { + writer.WriteStartArray("definition"u8); + + foreach(var definitionItem in objectListDefinition.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(definitionItem); + } + writer.WriteEndArray(); + } + break; + case "excludeddomain": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedDomain && objectListExcludedDomain.Any()) + { + writer.WriteStartArray("excludedDomain"u8); + + foreach(var excludedDomainItem in objectListExcludedDomain.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedDomainItem); + } + writer.WriteEndArray(); + } + break; + case "excludedperson": + if (value == null) + { + break; + } + + if (value is IEnumerable objectListExcludedPerson && objectListExcludedPerson.Any()) + { + writer.WriteStartArray("excludedPerson"u8); + + foreach(var excludedPersonItem in objectListExcludedPerson.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(excludedPersonItem); + } + writer.WriteEndArray(); + } + break; + case "hyperlink": + if (value == null) + { + break; + } - return this.Serialize(valueGroup); + if (value is IEnumerable objectListHyperLink && objectListHyperLink.Any()) + { + writer.WriteStartArray("hyperLink"u8); + + foreach(var hyperLinkItem in objectListHyperLink.OfType().OrderBy(x => x, this.GuidComparer)) + { + writer.WriteStringValue(hyperLinkItem); + } + writer.WriteEndArray(); + } + break; + case "iid": + writer.WritePropertyName("iid"u8); + + if(value != null) + { + writer.WriteStringValue((Guid)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "modifiedon": + writer.WritePropertyName("modifiedOn"u8); + + if(value != null) + { + writer.WriteStringValue(((DateTime)value).ToString(SerializerHelper.DateTimeFormat)); + } + else + { + writer.WriteNullValue(); + } + + break; + case "name": + writer.WritePropertyName("name"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "revisionnumber": + writer.WritePropertyName("revisionNumber"u8); + + if(value != null) + { + writer.WriteNumberValue((int)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "shortname": + writer.WritePropertyName("shortName"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + case "thingpreference": + writer.WritePropertyName("thingPreference"u8); + + if(value != null) + { + writer.WriteStringValue((string)value); + } + else + { + writer.WriteNullValue(); + } + + break; + default: + throw new ArgumentException($"The requested property {propertyName} does not exist on the ValueGroup"); + } } + + /// + /// Gets the association between a name of a property and all versions where that property is defined + /// + private static readonly IReadOnlyDictionary> AllowedVersionsPerProperty = new Dictionary>() + { + { "actor", new []{ "1.3.0" }}, + { "alias", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "category", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "classKind", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "definition", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedDomain", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "excludedPerson", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "hyperLink", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "iid", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "modifiedOn", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "name", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "revisionNumber", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "shortName", new []{ "1.1.0", "1.2.0", "1.3.0" }}, + { "thingPreference", new []{ "1.2.0", "1.3.0" }}, + }; } } diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/ActualFiniteStateKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/ActualFiniteStateKindDeserializer.cs new file mode 100644 index 000000000..970712ee8 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/ActualFiniteStateKindDeserializer.cs @@ -0,0 +1,64 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.EngineeringModelData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class ActualFiniteStateKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static ActualFiniteStateKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "MANDATORY" => ActualFiniteStateKind.MANDATORY, + "FORBIDDEN" => ActualFiniteStateKind.FORBIDDEN, + _ => throw new InvalidDataException($"{value} is not a valid for ActualFiniteStateKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationApprovalKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationApprovalKindDeserializer.cs new file mode 100644 index 000000000..2c1aff9ae --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationApprovalKindDeserializer.cs @@ -0,0 +1,65 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.ReportingData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class AnnotationApprovalKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static AnnotationApprovalKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "ACCEPTED" => AnnotationApprovalKind.ACCEPTED, + "REJECTED" => AnnotationApprovalKind.REJECTED, + "WITHDRAWN" => AnnotationApprovalKind.WITHDRAWN, + _ => throw new InvalidDataException($"{value} is not a valid for AnnotationApprovalKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationClassificationKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationClassificationKindDeserializer.cs new file mode 100644 index 000000000..836f0fa1d --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationClassificationKindDeserializer.cs @@ -0,0 +1,64 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.ReportingData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class AnnotationClassificationKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static AnnotationClassificationKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "MAJOR" => AnnotationClassificationKind.MAJOR, + "MINOR" => AnnotationClassificationKind.MINOR, + _ => throw new InvalidDataException($"{value} is not a valid for AnnotationClassificationKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationStatusKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationStatusKindDeserializer.cs new file mode 100644 index 000000000..1c4d194ee --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/AnnotationStatusKindDeserializer.cs @@ -0,0 +1,68 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.ReportingData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class AnnotationStatusKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static AnnotationStatusKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "OPEN" => AnnotationStatusKind.OPEN, + "DONE" => AnnotationStatusKind.DONE, + "CLOSED" => AnnotationStatusKind.CLOSED, + "INVALID" => AnnotationStatusKind.INVALID, + "WONTFIX" => AnnotationStatusKind.WONTFIX, + "NOT_APPLICABLE" => AnnotationStatusKind.NOT_APPLICABLE, + _ => throw new InvalidDataException($"{value} is not a valid for AnnotationStatusKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/BooleanOperatorKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/BooleanOperatorKindDeserializer.cs new file mode 100644 index 000000000..97fc42971 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/BooleanOperatorKindDeserializer.cs @@ -0,0 +1,65 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.EngineeringModelData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class BooleanOperatorKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static BooleanOperatorKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "AND" => BooleanOperatorKind.AND, + "OR" => BooleanOperatorKind.OR, + "XOR" => BooleanOperatorKind.XOR, + _ => throw new InvalidDataException($"{value} is not a valid for BooleanOperatorKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/ClassKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/ClassKindDeserializer.cs new file mode 100644 index 000000000..0403a56ac --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/ClassKindDeserializer.cs @@ -0,0 +1,243 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.CommonData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class ClassKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static ClassKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "ActionItem" => ClassKind.ActionItem, + "ActualFiniteState" => ClassKind.ActualFiniteState, + "ActualFiniteStateList" => ClassKind.ActualFiniteStateList, + "Alias" => ClassKind.Alias, + "AndExpression" => ClassKind.AndExpression, + "Approval" => ClassKind.Approval, + "ArrayParameterType" => ClassKind.ArrayParameterType, + "BinaryNote" => ClassKind.BinaryNote, + "BinaryRelationship" => ClassKind.BinaryRelationship, + "BinaryRelationshipRule" => ClassKind.BinaryRelationshipRule, + "Book" => ClassKind.Book, + "BooleanExpression" => ClassKind.BooleanExpression, + "BooleanParameterType" => ClassKind.BooleanParameterType, + "Bounds" => ClassKind.Bounds, + "BuiltInRuleVerification" => ClassKind.BuiltInRuleVerification, + "Category" => ClassKind.Category, + "ChangeProposal" => ClassKind.ChangeProposal, + "ChangeRequest" => ClassKind.ChangeRequest, + "Citation" => ClassKind.Citation, + "Color" => ClassKind.Color, + "CommonFileStore" => ClassKind.CommonFileStore, + "CompoundParameterType" => ClassKind.CompoundParameterType, + "Constant" => ClassKind.Constant, + "ContractChangeNotice" => ClassKind.ContractChangeNotice, + "ContractDeviation" => ClassKind.ContractDeviation, + "ConversionBasedUnit" => ClassKind.ConversionBasedUnit, + "CyclicRatioScale" => ClassKind.CyclicRatioScale, + "DateParameterType" => ClassKind.DateParameterType, + "DateTimeParameterType" => ClassKind.DateTimeParameterType, + "DecompositionRule" => ClassKind.DecompositionRule, + "DefinedThing" => ClassKind.DefinedThing, + "Definition" => ClassKind.Definition, + "DependentParameterTypeAssignment" => ClassKind.DependentParameterTypeAssignment, + "DerivedQuantityKind" => ClassKind.DerivedQuantityKind, + "DerivedUnit" => ClassKind.DerivedUnit, + "DiagramCanvas" => ClassKind.DiagramCanvas, + "DiagramEdge" => ClassKind.DiagramEdge, + "DiagramElementContainer" => ClassKind.DiagramElementContainer, + "DiagramElementThing" => ClassKind.DiagramElementThing, + "DiagrammingStyle" => ClassKind.DiagrammingStyle, + "DiagramObject" => ClassKind.DiagramObject, + "DiagramShape" => ClassKind.DiagramShape, + "DiagramThingBase" => ClassKind.DiagramThingBase, + "DiscussionItem" => ClassKind.DiscussionItem, + "DomainFileStore" => ClassKind.DomainFileStore, + "DomainOfExpertise" => ClassKind.DomainOfExpertise, + "DomainOfExpertiseGroup" => ClassKind.DomainOfExpertiseGroup, + "ElementBase" => ClassKind.ElementBase, + "ElementDefinition" => ClassKind.ElementDefinition, + "ElementUsage" => ClassKind.ElementUsage, + "EmailAddress" => ClassKind.EmailAddress, + "EngineeringModel" => ClassKind.EngineeringModel, + "EngineeringModelDataAnnotation" => ClassKind.EngineeringModelDataAnnotation, + "EngineeringModelDataDiscussionItem" => ClassKind.EngineeringModelDataDiscussionItem, + "EngineeringModelDataNote" => ClassKind.EngineeringModelDataNote, + "EngineeringModelSetup" => ClassKind.EngineeringModelSetup, + "EnumerationParameterType" => ClassKind.EnumerationParameterType, + "EnumerationValueDefinition" => ClassKind.EnumerationValueDefinition, + "ExclusiveOrExpression" => ClassKind.ExclusiveOrExpression, + "ExternalIdentifierMap" => ClassKind.ExternalIdentifierMap, + "File" => ClassKind.File, + "FileRevision" => ClassKind.FileRevision, + "FileStore" => ClassKind.FileStore, + "FileType" => ClassKind.FileType, + "Folder" => ClassKind.Folder, + "GenericAnnotation" => ClassKind.GenericAnnotation, + "Glossary" => ClassKind.Glossary, + "Goal" => ClassKind.Goal, + "HyperLink" => ClassKind.HyperLink, + "IdCorrespondence" => ClassKind.IdCorrespondence, + "IndependentParameterTypeAssignment" => ClassKind.IndependentParameterTypeAssignment, + "IntervalScale" => ClassKind.IntervalScale, + "Iteration" => ClassKind.Iteration, + "IterationSetup" => ClassKind.IterationSetup, + "LinearConversionUnit" => ClassKind.LinearConversionUnit, + "LogarithmicScale" => ClassKind.LogarithmicScale, + "LogEntryChangelogItem" => ClassKind.LogEntryChangelogItem, + "MappingToReferenceScale" => ClassKind.MappingToReferenceScale, + "MeasurementScale" => ClassKind.MeasurementScale, + "MeasurementUnit" => ClassKind.MeasurementUnit, + "ModellingAnnotationItem" => ClassKind.ModellingAnnotationItem, + "ModellingThingReference" => ClassKind.ModellingThingReference, + "ModelLogEntry" => ClassKind.ModelLogEntry, + "ModelReferenceDataLibrary" => ClassKind.ModelReferenceDataLibrary, + "MultiRelationship" => ClassKind.MultiRelationship, + "MultiRelationshipRule" => ClassKind.MultiRelationshipRule, + "NaturalLanguage" => ClassKind.NaturalLanguage, + "NestedElement" => ClassKind.NestedElement, + "NestedParameter" => ClassKind.NestedParameter, + "Note" => ClassKind.Note, + "NotExpression" => ClassKind.NotExpression, + "NotThing" => ClassKind.NotThing, + "Option" => ClassKind.Option, + "OrdinalScale" => ClassKind.OrdinalScale, + "OrExpression" => ClassKind.OrExpression, + "Organization" => ClassKind.Organization, + "OrganizationalParticipant" => ClassKind.OrganizationalParticipant, + "OwnedStyle" => ClassKind.OwnedStyle, + "Page" => ClassKind.Page, + "Parameter" => ClassKind.Parameter, + "ParameterBase" => ClassKind.ParameterBase, + "ParameterGroup" => ClassKind.ParameterGroup, + "ParameterizedCategoryRule" => ClassKind.ParameterizedCategoryRule, + "ParameterOrOverrideBase" => ClassKind.ParameterOrOverrideBase, + "ParameterOverride" => ClassKind.ParameterOverride, + "ParameterOverrideValueSet" => ClassKind.ParameterOverrideValueSet, + "ParameterSubscription" => ClassKind.ParameterSubscription, + "ParameterSubscriptionValueSet" => ClassKind.ParameterSubscriptionValueSet, + "ParameterType" => ClassKind.ParameterType, + "ParameterTypeComponent" => ClassKind.ParameterTypeComponent, + "ParameterValue" => ClassKind.ParameterValue, + "ParameterValueSet" => ClassKind.ParameterValueSet, + "ParameterValueSetBase" => ClassKind.ParameterValueSetBase, + "ParametricConstraint" => ClassKind.ParametricConstraint, + "Participant" => ClassKind.Participant, + "ParticipantPermission" => ClassKind.ParticipantPermission, + "ParticipantRole" => ClassKind.ParticipantRole, + "Person" => ClassKind.Person, + "PersonPermission" => ClassKind.PersonPermission, + "PersonRole" => ClassKind.PersonRole, + "Point" => ClassKind.Point, + "PossibleFiniteState" => ClassKind.PossibleFiniteState, + "PossibleFiniteStateList" => ClassKind.PossibleFiniteStateList, + "PrefixedUnit" => ClassKind.PrefixedUnit, + "Publication" => ClassKind.Publication, + "QuantityKind" => ClassKind.QuantityKind, + "QuantityKindFactor" => ClassKind.QuantityKindFactor, + "RatioScale" => ClassKind.RatioScale, + "ReferenceDataLibrary" => ClassKind.ReferenceDataLibrary, + "ReferencerRule" => ClassKind.ReferencerRule, + "ReferenceSource" => ClassKind.ReferenceSource, + "RelationalExpression" => ClassKind.RelationalExpression, + "Relationship" => ClassKind.Relationship, + "RelationshipParameterValue" => ClassKind.RelationshipParameterValue, + "RequestForDeviation" => ClassKind.RequestForDeviation, + "RequestForWaiver" => ClassKind.RequestForWaiver, + "Requirement" => ClassKind.Requirement, + "RequirementsContainer" => ClassKind.RequirementsContainer, + "RequirementsContainerParameterValue" => ClassKind.RequirementsContainerParameterValue, + "RequirementsGroup" => ClassKind.RequirementsGroup, + "RequirementsSpecification" => ClassKind.RequirementsSpecification, + "ReviewItemDiscrepancy" => ClassKind.ReviewItemDiscrepancy, + "Rule" => ClassKind.Rule, + "RuleVerification" => ClassKind.RuleVerification, + "RuleVerificationList" => ClassKind.RuleVerificationList, + "RuleViolation" => ClassKind.RuleViolation, + "SampledFunctionParameterType" => ClassKind.SampledFunctionParameterType, + "ScalarParameterType" => ClassKind.ScalarParameterType, + "ScaleReferenceQuantityValue" => ClassKind.ScaleReferenceQuantityValue, + "ScaleValueDefinition" => ClassKind.ScaleValueDefinition, + "Section" => ClassKind.Section, + "SharedStyle" => ClassKind.SharedStyle, + "SimpleParameterizableThing" => ClassKind.SimpleParameterizableThing, + "SimpleParameterValue" => ClassKind.SimpleParameterValue, + "SimpleQuantityKind" => ClassKind.SimpleQuantityKind, + "SimpleUnit" => ClassKind.SimpleUnit, + "SiteDirectory" => ClassKind.SiteDirectory, + "SiteDirectoryDataAnnotation" => ClassKind.SiteDirectoryDataAnnotation, + "SiteDirectoryDataDiscussionItem" => ClassKind.SiteDirectoryDataDiscussionItem, + "SiteDirectoryThingReference" => ClassKind.SiteDirectoryThingReference, + "SiteLogEntry" => ClassKind.SiteLogEntry, + "SiteReferenceDataLibrary" => ClassKind.SiteReferenceDataLibrary, + "Solution" => ClassKind.Solution, + "SpecializedQuantityKind" => ClassKind.SpecializedQuantityKind, + "Stakeholder" => ClassKind.Stakeholder, + "StakeholderValue" => ClassKind.StakeholderValue, + "StakeHolderValueMap" => ClassKind.StakeHolderValueMap, + "StakeHolderValueMapSettings" => ClassKind.StakeHolderValueMapSettings, + "TelephoneNumber" => ClassKind.TelephoneNumber, + "Term" => ClassKind.Term, + "TextParameterType" => ClassKind.TextParameterType, + "TextualNote" => ClassKind.TextualNote, + "Thing" => ClassKind.Thing, + "ThingReference" => ClassKind.ThingReference, + "TimeOfDayParameterType" => ClassKind.TimeOfDayParameterType, + "TopContainer" => ClassKind.TopContainer, + "UnitFactor" => ClassKind.UnitFactor, + "UnitPrefix" => ClassKind.UnitPrefix, + "UserPreference" => ClassKind.UserPreference, + "UserRuleVerification" => ClassKind.UserRuleVerification, + "ValueGroup" => ClassKind.ValueGroup, + _ => throw new InvalidDataException($"{value} is not a valid for ClassKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/EngineeringModelKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/EngineeringModelKindDeserializer.cs new file mode 100644 index 000000000..27fb940e2 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/EngineeringModelKindDeserializer.cs @@ -0,0 +1,66 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.SiteDirectoryData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class EngineeringModelKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static EngineeringModelKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "STUDY_MODEL" => EngineeringModelKind.STUDY_MODEL, + "TEMPLATE_MODEL" => EngineeringModelKind.TEMPLATE_MODEL, + "MODEL_CATALOGUE" => EngineeringModelKind.MODEL_CATALOGUE, + "SCRATCH_MODEL" => EngineeringModelKind.SCRATCH_MODEL, + _ => throw new InvalidDataException($"{value} is not a valid for EngineeringModelKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/InterfaceEndKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/InterfaceEndKindDeserializer.cs new file mode 100644 index 000000000..8ada83306 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/InterfaceEndKindDeserializer.cs @@ -0,0 +1,67 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.EngineeringModelData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class InterfaceEndKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static InterfaceEndKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "NONE" => InterfaceEndKind.NONE, + "UNDIRECTED" => InterfaceEndKind.UNDIRECTED, + "INPUT" => InterfaceEndKind.INPUT, + "OUTPUT" => InterfaceEndKind.OUTPUT, + "IN_OUT" => InterfaceEndKind.IN_OUT, + _ => throw new InvalidDataException($"{value} is not a valid for InterfaceEndKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/LogEntryChangelogItemKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogEntryChangelogItemKindDeserializer.cs new file mode 100644 index 000000000..a8d2e067b --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogEntryChangelogItemKindDeserializer.cs @@ -0,0 +1,65 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.CommonData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class LogEntryChangelogItemKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static LogEntryChangelogItemKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "ADD" => LogEntryChangelogItemKind.ADD, + "UPDATE" => LogEntryChangelogItemKind.UPDATE, + "DELETE" => LogEntryChangelogItemKind.DELETE, + _ => throw new InvalidDataException($"{value} is not a valid for LogEntryChangelogItemKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/LogLevelKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogLevelKindDeserializer.cs new file mode 100644 index 000000000..cc8236966 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogLevelKindDeserializer.cs @@ -0,0 +1,66 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.CommonData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class LogLevelKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static LogLevelKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "TRACE" => LogLevelKind.TRACE, + "DEBUG" => LogLevelKind.DEBUG, + "INFO" => LogLevelKind.INFO, + "USER" => LogLevelKind.USER, + _ => throw new InvalidDataException($"{value} is not a valid for LogLevelKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/LogarithmBaseKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogarithmBaseKindDeserializer.cs new file mode 100644 index 000000000..723c97b51 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/LogarithmBaseKindDeserializer.cs @@ -0,0 +1,65 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.SiteDirectoryData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class LogarithmBaseKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static LogarithmBaseKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "NATURAL" => LogarithmBaseKind.NATURAL, + "BASE2" => LogarithmBaseKind.BASE2, + "BASE10" => LogarithmBaseKind.BASE10, + _ => throw new InvalidDataException($"{value} is not a valid for LogarithmBaseKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/NumberSetKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/NumberSetKindDeserializer.cs new file mode 100644 index 000000000..f3b6a7f83 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/NumberSetKindDeserializer.cs @@ -0,0 +1,66 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.SiteDirectoryData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class NumberSetKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static NumberSetKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "NATURAL_NUMBER_SET" => NumberSetKind.NATURAL_NUMBER_SET, + "INTEGER_NUMBER_SET" => NumberSetKind.INTEGER_NUMBER_SET, + "RATIONAL_NUMBER_SET" => NumberSetKind.RATIONAL_NUMBER_SET, + "REAL_NUMBER_SET" => NumberSetKind.REAL_NUMBER_SET, + _ => throw new InvalidDataException($"{value} is not a valid for NumberSetKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/ParameterSwitchKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/ParameterSwitchKindDeserializer.cs new file mode 100644 index 000000000..c1efbc40b --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/ParameterSwitchKindDeserializer.cs @@ -0,0 +1,65 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.EngineeringModelData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class ParameterSwitchKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static ParameterSwitchKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "COMPUTED" => ParameterSwitchKind.COMPUTED, + "MANUAL" => ParameterSwitchKind.MANUAL, + "REFERENCE" => ParameterSwitchKind.REFERENCE, + _ => throw new InvalidDataException($"{value} is not a valid for ParameterSwitchKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/ParticipantAccessRightKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/ParticipantAccessRightKindDeserializer.cs new file mode 100644 index 000000000..9c22c901a --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/ParticipantAccessRightKindDeserializer.cs @@ -0,0 +1,69 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.CommonData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class ParticipantAccessRightKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static ParticipantAccessRightKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "NOT_APPLICABLE" => ParticipantAccessRightKind.NOT_APPLICABLE, + "NONE" => ParticipantAccessRightKind.NONE, + "SAME_AS_CONTAINER" => ParticipantAccessRightKind.SAME_AS_CONTAINER, + "SAME_AS_SUPERCLASS" => ParticipantAccessRightKind.SAME_AS_SUPERCLASS, + "READ" => ParticipantAccessRightKind.READ, + "MODIFY" => ParticipantAccessRightKind.MODIFY, + "MODIFY_IF_OWNER" => ParticipantAccessRightKind.MODIFY_IF_OWNER, + _ => throw new InvalidDataException($"{value} is not a valid for ParticipantAccessRightKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/PersonAccessRightKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/PersonAccessRightKindDeserializer.cs new file mode 100644 index 000000000..adc1bc8dc --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/PersonAccessRightKindDeserializer.cs @@ -0,0 +1,71 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.CommonData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class PersonAccessRightKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static PersonAccessRightKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "NOT_APPLICABLE" => PersonAccessRightKind.NOT_APPLICABLE, + "NONE" => PersonAccessRightKind.NONE, + "SAME_AS_CONTAINER" => PersonAccessRightKind.SAME_AS_CONTAINER, + "SAME_AS_SUPERCLASS" => PersonAccessRightKind.SAME_AS_SUPERCLASS, + "READ" => PersonAccessRightKind.READ, + "MODIFY" => PersonAccessRightKind.MODIFY, + "READ_IF_PARTICIPANT" => PersonAccessRightKind.READ_IF_PARTICIPANT, + "MODIFY_IF_PARTICIPANT" => PersonAccessRightKind.MODIFY_IF_PARTICIPANT, + "MODIFY_OWN_PERSON" => PersonAccessRightKind.MODIFY_OWN_PERSON, + _ => throw new InvalidDataException($"{value} is not a valid for PersonAccessRightKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/RelationalOperatorKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/RelationalOperatorKindDeserializer.cs new file mode 100644 index 000000000..d8b29aece --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/RelationalOperatorKindDeserializer.cs @@ -0,0 +1,68 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.EngineeringModelData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class RelationalOperatorKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static RelationalOperatorKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "EQ" => RelationalOperatorKind.EQ, + "NE" => RelationalOperatorKind.NE, + "LT" => RelationalOperatorKind.LT, + "GT" => RelationalOperatorKind.GT, + "LE" => RelationalOperatorKind.LE, + "GE" => RelationalOperatorKind.GE, + _ => throw new InvalidDataException($"{value} is not a valid for RelationalOperatorKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/RuleVerificationStatusKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/RuleVerificationStatusKindDeserializer.cs new file mode 100644 index 000000000..ca6a2c70d --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/RuleVerificationStatusKindDeserializer.cs @@ -0,0 +1,66 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.EngineeringModelData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class RuleVerificationStatusKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static RuleVerificationStatusKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "NONE" => RuleVerificationStatusKind.NONE, + "PASSED" => RuleVerificationStatusKind.PASSED, + "FAILED" => RuleVerificationStatusKind.FAILED, + "INCONCLUSIVE" => RuleVerificationStatusKind.INCONCLUSIVE, + _ => throw new InvalidDataException($"{value} is not a valid for RuleVerificationStatusKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/StudyPhaseKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/StudyPhaseKindDeserializer.cs new file mode 100644 index 000000000..c96dfcaed --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/StudyPhaseKindDeserializer.cs @@ -0,0 +1,66 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.SiteDirectoryData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class StudyPhaseKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static StudyPhaseKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "PREPARATION_PHASE" => StudyPhaseKind.PREPARATION_PHASE, + "DESIGN_SESSION_PHASE" => StudyPhaseKind.DESIGN_SESSION_PHASE, + "REPORTING_PHASE" => StudyPhaseKind.REPORTING_PHASE, + "COMPLETED_STUDY" => StudyPhaseKind.COMPLETED_STUDY, + _ => throw new InvalidDataException($"{value} is not a valid for StudyPhaseKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardEmailAddressKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardEmailAddressKindDeserializer.cs new file mode 100644 index 000000000..7df59b43e --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardEmailAddressKindDeserializer.cs @@ -0,0 +1,64 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.SiteDirectoryData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class VcardEmailAddressKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static VcardEmailAddressKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "WORK" => VcardEmailAddressKind.WORK, + "HOME" => VcardEmailAddressKind.HOME, + _ => throw new InvalidDataException($"{value} is not a valid for VcardEmailAddressKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardTelephoneNumberKindDeserializer.cs b/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardTelephoneNumberKindDeserializer.cs new file mode 100644 index 000000000..7bf91ce87 --- /dev/null +++ b/CDP4JsonSerializer/AutoGenEnumDeserializers/VcardTelephoneNumberKindDeserializer.cs @@ -0,0 +1,71 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ + +namespace CDP4JsonSerializer +{ + using System; + using System.IO; + using System.Text.Json; + + using CDP4Common.SiteDirectoryData; + + /// + /// The purpose of the is to deserialize a JSON object to a + /// + internal static class VcardTelephoneNumberKindDeserializer + { + /// + /// Deserializes the into a + /// + /// the element to deserialize + /// the + /// if the can't be parsed into the + internal static VcardTelephoneNumberKind Deserialize(JsonElement jsonElement) + { + var value = jsonElement.GetString(); + + return value switch + { + "WORK" => VcardTelephoneNumberKind.WORK, + "HOME" => VcardTelephoneNumberKind.HOME, + "VOICE" => VcardTelephoneNumberKind.VOICE, + "TEXT" => VcardTelephoneNumberKind.TEXT, + "FAX" => VcardTelephoneNumberKind.FAX, + "CELL" => VcardTelephoneNumberKind.CELL, + "PAGER" => VcardTelephoneNumberKind.PAGER, + "TEXTPHONE" => VcardTelephoneNumberKind.TEXTPHONE, + "VIDEO" => VcardTelephoneNumberKind.VIDEO, + _ => throw new InvalidDataException($"{value} is not a valid for VcardTelephoneNumberKind") + }; + } + } +} + +// ------------------------------------------------------------------------------------------------ +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- +// ------------------------------------------------------------------------------------------------ diff --git a/CDP4JsonSerializer/CDP4JsonSerializer.csproj b/CDP4JsonSerializer/CDP4JsonSerializer.csproj index e962e55db..02ac76dde 100644 --- a/CDP4JsonSerializer/CDP4JsonSerializer.csproj +++ b/CDP4JsonSerializer/CDP4JsonSerializer.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4JsonSerializer Community Edition - 27.4.0 + 28.0.0 CDP4 JSON Serialization Library Copyright © Starion Group S.A. Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael @@ -20,13 +20,15 @@ CDP COMET ECSS-E-TM-10-25 JSON LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json - README.md + README.md + 11.0 + @@ -34,23 +36,14 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - - - - + + + + - - - - - - - - - - + \ No newline at end of file diff --git a/CDP4JsonSerializer/Cdp4DalJsonSerializer.cs b/CDP4JsonSerializer/Cdp4DalJsonSerializer.cs new file mode 100644 index 000000000..2a5f15cee --- /dev/null +++ b/CDP4JsonSerializer/Cdp4DalJsonSerializer.cs @@ -0,0 +1,78 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +namespace CDP4JsonSerializer +{ + using System; + + using CDP4Common.MetaInfo; + + using CDP4JsonSerializer.JsonConverter; + + /// + /// The is a that also supports (de)serialization of + /// + /// + public class Cdp4DalJsonSerializer : Cdp4JsonSerializer + { + /// + /// Asserts that the have to be ignored + /// + private readonly bool ignorePostOperationCopyProperty; + + /// + /// Initializes a new instance of the class. + /// + /// + /// The meta Info Provider. + /// + /// + /// The supported version of the data-model + /// + /// Asserts that the have to be ignored + public Cdp4DalJsonSerializer(IMetaDataProvider metaInfoProvider, Version supportedVersion, bool ignorePostOperationCopyProperty) + { + this.ignorePostOperationCopyProperty = ignorePostOperationCopyProperty; + this.Initialize(metaInfoProvider, supportedVersion); + } + + /// + /// Initializes a new instance of the class. + /// + /// Asserts that the have to be ignored + public Cdp4DalJsonSerializer(bool ignorePostOperationCopyProperty) + { + this.ignorePostOperationCopyProperty = ignorePostOperationCopyProperty; + } + + /// + /// Initialize the property + /// + public override void InitializeJsonSerializerOptions() + { + base.InitializeJsonSerializerOptions(); + this.JsonSerializerOptions.Converters.Add(new PostOperationJsonConverter(this.ignorePostOperationCopyProperty)); + } + } +} diff --git a/CDP4JsonSerializer/Cdp4JsonSerializer.cs b/CDP4JsonSerializer/Cdp4JsonSerializer.cs index 0275cd39b..91b2f10d1 100644 --- a/CDP4JsonSerializer/Cdp4JsonSerializer.cs +++ b/CDP4JsonSerializer/Cdp4JsonSerializer.cs @@ -10,17 +10,17 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer { @@ -28,17 +28,16 @@ namespace CDP4JsonSerializer using System.Collections.Generic; using System.Diagnostics; using System.IO; + using System.Text.Json; + using System.Text.Json.Serialization; using CDP4Common.MetaInfo; + using CDP4JsonSerializer.Helper; using CDP4JsonSerializer.JsonConverter; - using Newtonsoft.Json; - using Newtonsoft.Json.Converters; - using Newtonsoft.Json.Serialization; - using NLog; - + using Thing = CDP4Common.DTO.Thing; /// @@ -52,7 +51,7 @@ public class Cdp4JsonSerializer : ICdp4JsonSerializer private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// /// The meta Info Provider. @@ -66,12 +65,17 @@ public Cdp4JsonSerializer(IMetaDataProvider metaInfoProvider, Version supportedV } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public Cdp4JsonSerializer() { } + /// + /// Gets or sets the options for the serializer + /// + public JsonSerializerOptions JsonSerializerOptions { get; private set; } + /// /// Gets or sets the data model version for this request. /// @@ -83,14 +87,15 @@ public Cdp4JsonSerializer() public IMetaDataProvider MetaInfoProvider { get; private set; } /// - /// Initialize this instance with the required and supported + /// Initialize this instance with the required and supported /// - /// The - /// The supported + /// The + /// The supported public void Initialize(IMetaDataProvider metaInfoProvider, Version supportedVersion) { this.MetaInfoProvider = metaInfoProvider; this.RequestDataModelVersion = supportedVersion; + this.InitializeJsonSerializerOptions(); } /// @@ -115,31 +120,25 @@ public void SerializeToStream(object collectionSource, Stream outputStream) } var sw = Stopwatch.StartNew(); - - var serializer = this.CreateJsonSerializer(); - - Logger.Trace("initializing JsonTextWriter"); - var jsonWriter = new JsonTextWriter(new StreamWriter(outputStream)); - Logger.Trace("Serialize to JsonTextWriter"); - serializer.Serialize(jsonWriter, collectionSource); - jsonWriter.Flush(); + Logger.Trace("initializing Serialization"); + JsonSerializer.Serialize(outputStream, collectionSource, this.JsonSerializerOptions); sw.Stop(); Logger.Debug("SerializeToStream finished in {0} [ms]", sw.ElapsedMilliseconds); } /// - /// Serialize the to a JSON stream + /// Serialize the to a JSON stream /// /// - /// The + /// The /// /// /// The output stream to which the serialized JSON objects are written /// /// - /// A value indicating whether the contained shall be included in the JSON stream + /// A value indicating whether the contained shall be included in the JSON stream /// /// A JSON stream public void SerializeToStream(CDP4Common.CommonData.Thing source, Stream outputStream, bool isExtentDeep) @@ -160,9 +159,11 @@ public void SerializeToStream(CDP4Common.CommonData.Thing source, Stream outputS } var dtos = new List(); + if (isExtentDeep) { var pocos = source.QueryContainedThingsDeep(); + foreach (var poco in pocos) { dtos.Add(poco.ToDto()); @@ -179,10 +180,10 @@ public void SerializeToStream(CDP4Common.CommonData.Thing source, Stream outputS } /// - /// Serialize the to a JSON string + /// Serialize the to a JSON string /// - /// The - /// A value indicating whether the contained shall be processed + /// The + /// A value indicating whether the contained shall be processed /// The JSON string public string SerializeToString(CDP4Common.CommonData.Thing source, bool isExtentDeep) { @@ -190,28 +191,62 @@ public string SerializeToString(CDP4Common.CommonData.Thing source, bool isExten { throw new InvalidOperationException("The supported version or the metainfo provider has not been set. Call the Initialize method to set them."); } - - string jsonString; + Logger.Trace("initializing MemoryStream"); - using (var stream = new MemoryStream()) - { - this.SerializeToStream(source, stream, isExtentDeep); + using var stream = new MemoryStream(); - Logger.Trace("rewind MemoryStream"); - stream.Position = 0; + this.SerializeToStream(source, stream, isExtentDeep); - Logger.Trace("initializing StreamReader"); - using (var reader = new StreamReader(stream)) - { - var sw = new Stopwatch(); - sw.Start(); - jsonString = reader.ReadToEnd(); - sw.Stop(); - Logger.Trace("write json stream to json string in {0} [ms]", sw.ElapsedMilliseconds); - } + Logger.Trace("rewind MemoryStream"); + stream.Position = 0; + + Logger.Trace("initializing StreamReader"); + using var reader = new StreamReader(stream); + + var sw = new Stopwatch(); + sw.Start(); + var jsonString = reader.ReadToEnd(); + sw.Stop(); + Logger.Trace("write json stream to json string in {0} [ms]", sw.ElapsedMilliseconds); + + return jsonString; + } + + /// + /// Serialize an object into a string + /// + /// The object to serialize + /// The serialized string + /// + /// If the or + /// has not been initialized + /// + public string SerializeToString(object toSerialize) + { + if (this.RequestDataModelVersion == null || this.MetaInfoProvider == null) + { + throw new InvalidOperationException("The supported version or the metainfo provider has not been set. Call the Initialize method to set them."); } + Logger.Trace("initializing MemoryStream"); + + using var stream = new MemoryStream(); + + this.SerializeToStream(toSerialize, stream); + + Logger.Trace("rewind MemoryStream"); + stream.Position = 0; + + Logger.Trace("initializing StreamReader"); + using var reader = new StreamReader(stream); + + var sw = new Stopwatch(); + sw.Start(); + var jsonString = reader.ReadToEnd(); + sw.Stop(); + Logger.Trace("write json stream to json string in {0} [ms]", sw.ElapsedMilliseconds); + return jsonString; } @@ -222,7 +257,7 @@ public string SerializeToString(CDP4Common.CommonData.Thing source, bool isExten /// The content Stream. /// /// - /// The the deserialized collection of . + /// The the deserialized collection of . /// public IEnumerable Deserialize(Stream contentStream) { @@ -248,43 +283,49 @@ public T Deserialize(Stream contentStream) throw new InvalidOperationException("The supported version or the metainfo provider has not been set. Call the Initialize method to set them."); } - var serializer = this.CreateJsonSerializer(); - - T data; - using (var streamReader = new StreamReader(contentStream)) - using (var jsonTextReader = new JsonTextReader(streamReader)) - { - var sw = new Stopwatch(); - sw.Start(); - data = serializer.Deserialize(jsonTextReader); - Logger.Trace("Deserialize from stream in {0} [ms]", sw.ElapsedMilliseconds); - } - + var sw = new Stopwatch(); + sw.Start(); + var data = JsonSerializer.Deserialize(contentStream, this.JsonSerializerOptions); + Logger.Trace("Deserialize from stream in {0} [ms]", sw.ElapsedMilliseconds); return data; } /// - /// Create a + /// Convenience method that deserializes the passed in JSON content stream /// + /// + /// The type info for which deserialization will be performed + /// + /// + /// The content string. + /// /// - /// an instance of + /// The the deserialized instance of the specified Type /// - protected JsonSerializer CreateJsonSerializer() + public T Deserialize(string contentString) { - Logger.Trace("initializing JsonSerializer"); - var serializer = new JsonSerializer + if (this.RequestDataModelVersion == null || this.MetaInfoProvider == null) { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - NullValueHandling = NullValueHandling.Ignore - }; - - Logger.Trace("register converters"); - serializer.Converters.Add(new ThingSerializer(this.MetaInfoProvider, this.RequestDataModelVersion)); - serializer.Converters.Add(new ClasslessDtoSerializer(this.MetaInfoProvider, this.RequestDataModelVersion)); - serializer.Converters.Add(new ClassKindConverter()); - serializer.Converters.Add(new StringEnumConverter()); - - return serializer; + throw new InvalidOperationException("The supported version or the metainfo provider has not been set. Call the Initialize method to set them."); + } + + var sw = new Stopwatch(); + sw.Start(); + var data = JsonSerializer.Deserialize(contentString, this.JsonSerializerOptions); + Logger.Trace("Deserialize from stream in {0} [ms]", sw.ElapsedMilliseconds); + return data; + } + + /// + /// Initialize the property + /// + public virtual void InitializeJsonSerializerOptions() + { + this.JsonSerializerOptions = JsonSerializerOptionsCreator.CreateNew(); + + this.JsonSerializerOptions.Converters.Add(new ThingSerializer(this.MetaInfoProvider, this.RequestDataModelVersion)); + this.JsonSerializerOptions.Converters.Add(new ClasslessDtoSerializer(this.MetaInfoProvider, this.RequestDataModelVersion)); + this.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(null, false)); } } -} \ No newline at end of file +} diff --git a/CDP4JsonSerializer/DtoSerializer/BaseThingSerializer.cs b/CDP4JsonSerializer/DtoSerializer/BaseThingSerializer.cs index 647c21cfc..31cfca1a0 100644 --- a/CDP4JsonSerializer/DtoSerializer/BaseThingSerializer.cs +++ b/CDP4JsonSerializer/DtoSerializer/BaseThingSerializer.cs @@ -10,37 +10,45 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer { using System; + using CDP4Common.Comparers; using CDP4Common.Types; + using NLog; + /// /// Abstract supertype from which all derive /// public abstract class BaseThingSerializer { + /// + /// The NLog logger + /// + protected static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + /// /// The used to compare 2 s /// - protected readonly GuidComparer guidComparer = new GuidComparer(); + protected readonly GuidComparer GuidComparer = new(); /// /// The used to compare 2 s /// - protected readonly OrderedItemComparer orderedItemComparer = new OrderedItemComparer(); + protected readonly OrderedItemComparer OrderedItemComparer = new(); } -} \ No newline at end of file +} diff --git a/CDP4JsonSerializer/DtoSerializer/IThingSerializer.cs b/CDP4JsonSerializer/DtoSerializer/IThingSerializer.cs index 6209d85d6..c3f80690f 100644 --- a/CDP4JsonSerializer/DtoSerializer/IThingSerializer.cs +++ b/CDP4JsonSerializer/DtoSerializer/IThingSerializer.cs @@ -10,42 +10,62 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer { using System; - using System.Collections.Generic; + using System.Text.Json; + using System.Text.Json.Nodes; using CDP4Common.DTO; - using Newtonsoft.Json.Linq; - /// - /// Definition of the used to serialize instances of to a + /// Definition of the used to serialize instances of to a + /// /// public interface IThingSerializer { /// - /// Gets the map containing the serialization method for each property + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer); + + /// + /// Serialize a value for a property into a + /// + /// The name of the property to serialize + /// The object value to serialize + /// The + /// The that has been requested for the serialization + void SerializeProperty(string propertyName, object value, Utf8JsonWriter writer, Version requestedDataModelVersion); + + /// + /// Serializes a into an /// - IReadOnlyDictionary> PropertySerializerMap { get; } + /// The that have to be serialized + /// The + void Serialize(Thing thing, Utf8JsonWriter writer); /// - /// Serialize the + /// Serializes a into an /// - /// The to serialize - /// The - JObject Serialize(Thing thing); + /// The that have to be serialized + /// The + /// The that has been requested for the serialization + void Serialize(Thing thing, Utf8JsonWriter writer, Version requestedDataModelVersion); } -} \ No newline at end of file +} diff --git a/CDP4JsonSerializer/Extensions/JsonElementExtensions.cs b/CDP4JsonSerializer/Extensions/JsonElementExtensions.cs new file mode 100644 index 000000000..d6bd679b1 --- /dev/null +++ b/CDP4JsonSerializer/Extensions/JsonElementExtensions.cs @@ -0,0 +1,70 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +namespace CDP4JsonSerializer.Extensions +{ + using System.Collections.Generic; + using System.Text.Json; + + using CDP4Common; + using CDP4Common.Dto; + using CDP4Common.DTO; + + using CDP4DalCommon.Protocol.Operations; + + /// + /// Extension class for + /// + public static class JsonElementExtensions + { + /// + /// Deserialize the content of the to the + /// + /// The + /// The that will receive new value properties + /// The + public static void DeserializePostOperation(this JsonElement element, PostOperation postOperation, JsonSerializerOptions serializerOptions) + { + if (element.TryGetProperty("_delete", out var deleteElement)) + { + postOperation.Delete = deleteElement.Deserialize>(serializerOptions); + } + + if (element.TryGetProperty("_create", out var createElement)) + { + postOperation.Create = createElement.Deserialize>(serializerOptions); + } + + if (element.TryGetProperty("_update", out var updateElement)) + { + postOperation.Update = updateElement.Deserialize>(serializerOptions); + } + + if (element.TryGetProperty("_copy", out var copyElement)) + { + postOperation.Copy = copyElement.Deserialize>(serializerOptions); + } + } + } +} diff --git a/CDP4JsonSerializer/Helper/JsonSerializerOptionsCreator.cs b/CDP4JsonSerializer/Helper/JsonSerializerOptionsCreator.cs new file mode 100644 index 000000000..8ed2b7e9b --- /dev/null +++ b/CDP4JsonSerializer/Helper/JsonSerializerOptionsCreator.cs @@ -0,0 +1,49 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +namespace CDP4JsonSerializer.Helper +{ + using System.Text.Json; + + /// + /// Static class that returns correct for serialization purposes + /// + public static class JsonSerializerOptionsCreator + { + /// + /// Creates the and returns the new instance + /// + /// the new instance + public static JsonSerializerOptions CreateNew() + { + return new JsonSerializerOptions + { + WriteIndented = false, + Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping, + PropertyNameCaseInsensitive = true, + NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString, + }; + } + } +} diff --git a/CDP4JsonSerializer/Helper/SerializerHelper.cs b/CDP4JsonSerializer/Helper/SerializerHelper.cs index b1f28d080..50925b2d5 100644 --- a/CDP4JsonSerializer/Helper/SerializerHelper.cs +++ b/CDP4JsonSerializer/Helper/SerializerHelper.cs @@ -1,6 +1,6 @@ // -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2021 Starion Group S.A. +// Copyright (c) 2015-2024 Starion Group S.A. // // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft // @@ -10,44 +10,64 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer { using System; using System.Collections.Generic; using System.Linq; + using System.Text.Json; using System.Text.RegularExpressions; using CDP4Common.Types; - using Newtonsoft.Json; - using Newtonsoft.Json.Linq; - + using CDP4JsonSerializer.Helper; + /// /// Utility method to convert a JSON token to a CDP4 type /// public static class SerializerHelper { + /// + /// Gets the format of the to use + /// + public const string DateTimeFormat = "yyyy-MM-ddTHH:mm:ss.fffZ"; + + /// + /// The default instance for this class + /// + private static readonly JsonSerializerOptions JsonSerializerOptions; + /// /// Regex used for conversion of Json value to string /// - private static readonly Regex JsonToValueArrayRegex = new Regex(@"^\[(.*)\]$", RegexOptions.Singleline); - + private static readonly Regex JsonToValueArrayRegex ; + /// /// Regex used for conversion of HStore value to string /// - private static readonly Regex HstoreToValueArrayRegex = new Regex(@"^\{(.*)\}$", RegexOptions.Singleline); + private static readonly Regex HstoreToValueArrayRegex; + + /// + /// Creates the new instance of the static class + /// + static SerializerHelper() + { + JsonSerializerOptions = JsonSerializerOptionsCreator.CreateNew(); + JsonToValueArrayRegex = new(@"^\[(.*)\]$", RegexOptions.Singleline); + HstoreToValueArrayRegex = new(@"^\{(.*)\}$", RegexOptions.Singleline); + } /// /// Convert a string to a @@ -78,44 +98,92 @@ public static string ToJsonString(this ValueArray valueArray) } /// - /// Serialize a to a + /// Writes an into an /// - /// The - /// The - public static JObject ToJsonObject(this OrderedItem orderedItem) + /// The + /// The to write + public static void WriteOrderedItem(this Utf8JsonWriter writer, OrderedItem orderedItem) { - var jsonObject = new JObject(); - jsonObject.Add("k", new JValue(orderedItem.K)); + writer.WriteStartObject(); + writer.WriteNumber("k"u8, orderedItem.K); if (orderedItem.M != null) { - jsonObject.Add("m", new JValue(orderedItem.M)); + writer.WriteNumber("m"u8, orderedItem.M.Value); } - jsonObject.Add("v", new JValue(orderedItem.V)); - return jsonObject; + writer.WritePropertyName("v"u8); + + switch (orderedItem.V) + { + case string stringValue: + writer.WriteStringValue(stringValue); + break; + case Guid guidValue: + writer.WriteStringValue(guidValue); + break; + case bool boolValue: + writer.WriteBooleanValue(boolValue); + break; + case int intValue: + writer.WriteNumberValue(intValue); + break; + case long longValue: + writer.WriteNumberValue(longValue); + break; + case double doubleValue: + writer.WriteNumberValue(doubleValue); + break; + case float floatValue: + writer.WriteNumberValue(floatValue); + break; + default: + throw new NotSupportedException($"The type {orderedItem.V.GetType().Name} is not supported for the {nameof(OrderedItem)} serialization"); + } + + writer.WriteEndObject(); } /// - /// Instantiate a from a + /// Instantiate a from a /// - /// The + /// The /// The - public static IEnumerable ToOrderedItemCollection(this JToken jsonToken) + public static IEnumerable ToOrderedItemCollection(this JsonElement jsonToken) { var list = new List(); - foreach (var token in jsonToken) + + foreach (var prop in jsonToken.EnumerateArray()) { + var valueProp = prop.GetProperty("v"); + var valueKind = valueProp.ValueKind; + + object valueToAssign = valueKind switch + { + JsonValueKind.String => valueProp.GetString(), + JsonValueKind.Number => valueProp.GetInt32(), + _ => null + }; + + var keyProp = prop.GetProperty("k"); + valueKind = keyProp.ValueKind; + + var keyValue = valueKind switch + { + JsonValueKind.String => long.Parse(keyProp.GetString()!), + JsonValueKind.Number => keyProp.GetInt64(), + _ => long.MinValue + }; + var orderedItem = new OrderedItem { - K = token["k"].ToObject(), - V = token["v"].ToString() + K = keyValue, + V = valueToAssign }; - var move = token["m"]; - if (move != null) + if (prop.TryGetProperty("m", out var value) && value.ValueKind != JsonValueKind.Null) { - orderedItem.M = move.ToObject(); + orderedItem.M = value.GetInt64(); } list.Add(orderedItem); @@ -124,19 +192,6 @@ public static IEnumerable ToOrderedItemCollection(this JToken jsonT return list; } - /// - /// Assert Whether a is null or empty - /// - /// The - /// True if the is null or empty - public static bool IsNullOrEmpty(this JToken token) - { - return (token == null) || - (token.Type == JTokenType.Array && !token.HasValues) || - (token.Type == JTokenType.Object && !token.HasValues) || - (token.Type == JTokenType.Null); - } - /// /// Convert a string to a /// @@ -159,7 +214,7 @@ private static ValueArray ToValueArray(string valueArrayString, Regex rege foreach (Match match in test) { - stringValues.Add(JsonConvert.DeserializeObject($"\"{match.Groups[1].Value}\"")); + stringValues.Add(JsonSerializer.Deserialize($"\"{match.Groups[1].Value}\"")); } var convertedStringList = stringValues.Select(m => (T)Convert.ChangeType(m, typeof(T))).ToList(); @@ -189,7 +244,7 @@ private static IEnumerable ValueArrayToStringList(ValueArray val for (var i = 0; i < items.Count; i++) { - items[i] = $"{JsonConvert.SerializeObject(items[i])}"; + items[i] = $"{JsonSerializer.Serialize(items[i], JsonSerializerOptions)}"; } return items; diff --git a/CDP4JsonSerializer/ICdp4JsonSerializer.cs b/CDP4JsonSerializer/ICdp4JsonSerializer.cs index 271c91341..e5d2c0edc 100644 --- a/CDP4JsonSerializer/ICdp4JsonSerializer.cs +++ b/CDP4JsonSerializer/ICdp4JsonSerializer.cs @@ -10,17 +10,17 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer { @@ -86,6 +86,17 @@ public interface ICdp4JsonSerializer /// A value indicating whether the contained shall be processed /// The JSON string string SerializeToString(CDP4Common.CommonData.Thing source, bool isExtentDeep); + + /// + /// Serialize an object into a string + /// + /// The object to serialize + /// The serialized string + /// + /// If the or + /// has not been initialized + /// + string SerializeToString(object toSerialize); /// /// Convenience method that deserializes the passed in JSON content stream @@ -111,5 +122,19 @@ public interface ICdp4JsonSerializer /// The the deserialized instance of the specified Type /// T Deserialize(Stream contentStream); + + /// + /// Convenience method that deserializes the passed in JSON content stream + /// + /// + /// The type info for which deserialization will be performed + /// + /// + /// The content string. + /// + /// + /// The the deserialized instance of the specified Type + /// + T Deserialize(string contentString); } -} \ No newline at end of file +} diff --git a/CDP4JsonSerializer/JsonConverter/ClassKindConverter.cs b/CDP4JsonSerializer/JsonConverter/ClassKindConverter.cs deleted file mode 100644 index 10b4b9379..000000000 --- a/CDP4JsonSerializer/JsonConverter/ClassKindConverter.cs +++ /dev/null @@ -1,50 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2015-2021 Starion Group S.A. -// -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft -// -// This file is part of CDP4-SDK Community Edition -// -// The CDP4-SDK Community Edition is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program; if not, write to the Free Software Foundation, -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace CDP4JsonSerializer.JsonConverter -{ - using System; - - using CDP4Common.CommonData; - - using Newtonsoft.Json.Converters; - - /// - /// Specific converter for values. - /// - public class ClassKindConverter : StringEnumConverter - { - /// - /// Determines whether this instance can convert the specified object type. - /// - /// Type of the object. - /// - /// true if this instance can convert the specified object type; otherwise, false. - /// - public override bool CanConvert(Type objectType) - { - return objectType == typeof(ClassKind); - } - } -} diff --git a/CDP4JsonSerializer/JsonConverter/ClasslessDtoSerializer.cs b/CDP4JsonSerializer/JsonConverter/ClasslessDtoSerializer.cs index 0f7cb2c14..86f76b2e2 100644 --- a/CDP4JsonSerializer/JsonConverter/ClasslessDtoSerializer.cs +++ b/CDP4JsonSerializer/JsonConverter/ClasslessDtoSerializer.cs @@ -10,12 +10,12 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -27,23 +27,25 @@ namespace CDP4JsonSerializer.JsonConverter using System; using System.Collections.Generic; + using System.IO; + using System.Text.Json; + using System.Text.Json.Nodes; + using System.Text.Json.Serialization; + using CDP4Common; using CDP4Common.MetaInfo; using CDP4Common.Polyfills; using CDP4JsonSerializer.Helper; - using Newtonsoft.Json; - using Newtonsoft.Json.Linq; - using NLog; using Dto = CDP4Common.DTO; /// - /// The for s + /// The for s /// - public class ClasslessDtoSerializer : JsonConverter + public class ClasslessDtoSerializer : JsonConverter { /// /// The NLog logger @@ -51,149 +53,96 @@ public class ClasslessDtoSerializer : JsonConverter private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); /// - /// The + /// The data model version for this request. /// - private readonly IMetaDataProvider metaDataProvider; + private readonly Version dataModelVersion; /// - /// The data model version for this request. + /// The /// - private readonly Version dataModelVersion; + private readonly IMetaDataProvider metaDataProvider; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// - /// The + /// The /// - /// The supported + /// The supported public ClasslessDtoSerializer(IMetaDataProvider metaDataProvider, Version dataModelVersion) { this.metaDataProvider = metaDataProvider; this.dataModelVersion = dataModelVersion; } - /// - /// Gets a value indicating whether this converter supports JSON read. - /// - public override bool CanRead - { - get { return true; } - } - - /// - /// Gets a value indicating whether this converter supports JSON write. - /// - public override bool CanWrite - { - get { return true; } - } - /// /// Override of the can convert type check. /// - /// + /// /// The object type. /// /// /// true if this converter is to be used. /// - public override bool CanConvert(Type objectType) + public override bool CanConvert(Type typeToConvert) { - return typeof(ClasslessDTO).QueryIsAssignableFrom(objectType); + return typeof(ClasslessDTO).QueryIsAssignableFrom(typeToConvert); } /// - /// Write JSON. + /// Tries to deserialize a JSON into a /// - /// - /// The JSON writer. - /// - /// - /// The value object. - /// - /// - /// The JSON serializer. - /// - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + /// the + /// the to convert + /// the options of the serializer + /// the + public override ClasslessDTO Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - var classlessDto = (ClasslessDTO)value; - - var typeName = classlessDto["ClassKind"].ToString(); - var classVersion = new Version(this.metaDataProvider.GetClassVersion(typeName)); - if (classVersion > this.dataModelVersion) - { - // skip type serialization if the data version is larger then the request data model version - return; - } - - var jsonObject = ((ClasslessDTO)value).ToJsonObject(); - - var nonSerializablePropeties = new List(); - foreach (var kvp in jsonObject) + if (!JsonElement.TryParseValue(ref reader, out var jsonElement)) { - var propertyVersion = new Version(this.metaDataProvider.GetPropertyVersion(typeName, Helper.Utils.CapitalizeFirstLetter(kvp.Key))); - if (propertyVersion > this.dataModelVersion) - { - nonSerializablePropeties.Add(kvp.Key); - } + Logger.Error("The data object in the JSON array could not be cast to a JsonElement type."); + throw new InvalidDataException("The data object in the JSON array could not be cast to a JsonElement type."); } - foreach (var nonSerializablePropety in nonSerializablePropeties) - { - jsonObject.Remove(nonSerializablePropety); - } + var dto = jsonElement.Value.ToDto(); + var classlessDto = this.GenerateClasslessDto(jsonElement.Value, dto); - jsonObject.WriteTo(writer); + return classlessDto; } /// - /// Override of the Read JSON method. + /// Write a JSON /// - /// - /// The JSON reader. - /// - /// - /// The type information of the object. - /// - /// - /// The existing object value. - /// - /// - /// The JSON serializer. - /// - /// - /// A deserialized instance. - /// - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + /// the + /// the to serialize + /// the options of the serializer + public override void Write(Utf8JsonWriter writer, ClasslessDTO value, JsonSerializerOptions options) { - // load object from stream - var jsonObject = JObject.Load(reader); + var typeName = value["ClassKind"].ToString(); + var classVersion = new Version(this.metaDataProvider.GetClassVersion(typeName)); - if (jsonObject == null) + if (classVersion > this.dataModelVersion) { - Logger.Error("The data object in the JSON array could not be cast to a JObject type."); - throw new NullReferenceException("The data object in the JSON array could not be cast to a JObject type."); + // skip type serialization if the data version is larger then the request data model version + return; } - var dto = jsonObject.ToDto(); - var classlessDto = this.GenerateClasslessDto(jsonObject, dto); - - return classlessDto; + value.SerializeClasslessDto(writer, this.dataModelVersion); } /// - /// Create a from a and a partial + /// Create a from a and a partial /// - /// The - /// The - /// The generated - private ClasslessDTO GenerateClasslessDto(JObject jsonObject, Dto.Thing dto) + /// The + /// The + /// The generated + private ClasslessDTO GenerateClasslessDto(JsonElement jsonObject, Dto.Thing dto) { var metainfo = this.metaDataProvider.GetMetaInfo(dto.ClassKind.ToString()); var classlessDto = new ClasslessDTO(); - foreach (var property in jsonObject.Properties()) + + foreach (var property in jsonObject.EnumerateObject()) { var propertyName = Utils.CapitalizeFirstLetter(property.Name); classlessDto.Add(propertyName, metainfo.GetValue(propertyName, dto)); @@ -202,4 +151,4 @@ private ClasslessDTO GenerateClasslessDto(JObject jsonObject, Dto.Thing dto) return classlessDto; } } -} \ No newline at end of file +} diff --git a/CDP4JsonSerializer/JsonConverter/PostOperationJsonConverter.cs b/CDP4JsonSerializer/JsonConverter/PostOperationJsonConverter.cs new file mode 100644 index 000000000..5cb462970 --- /dev/null +++ b/CDP4JsonSerializer/JsonConverter/PostOperationJsonConverter.cs @@ -0,0 +1,150 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +namespace CDP4JsonSerializer.JsonConverter +{ + using System; + using System.IO; + using System.Runtime.Serialization; + using System.Text.Json; + using System.Text.Json.Serialization; + + using CDP4Common.Polyfills; + using CDP4DalCommon.Protocol.Operations; + + using CDP4JsonSerializer.Extensions; + + using NLog; + + /// + /// The for s + /// + public class PostOperationJsonConverter: JsonConverter + { + /// + /// The NLog logger + /// + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + /// + /// Asserts that the have to be ignored + /// + private readonly bool ignoreCopyProperty; + + /// + /// Initializes a new instance. + /// + /// Asserts that the have to be ignored + public PostOperationJsonConverter(bool ignoreCopyProperty) + { + this.ignoreCopyProperty = ignoreCopyProperty; + } + + /// + /// Override of the can convert type check. + /// + /// + /// The object type. + /// + /// + /// true if this converter is to be used. + /// + public override bool CanConvert(Type typeToConvert) + { + return typeof(PostOperation).QueryIsAssignableFrom(typeToConvert); + } + + /// Reads and converts the JSON to type . + /// The reader. + /// The type to convert. + /// An object that specifies serialization options to use. + /// The converted value. + public override PostOperation Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (!JsonElement.TryParseValue(ref reader, out var jsonElement)) + { + Logger.Error("The data object in the JSON array could not be cast to a JsonElement type."); + throw new InvalidDataException("The data object in the JSON array could not be cast to a JObject type."); + } + + if (!typeof(PostOperation).IsAssignableFrom(typeToConvert)) + { + Logger.Error($"The request Type {typeToConvert.Name} is not a PostOperation"); + throw new InvalidDataException($"The request Type {typeToConvert.Name} is not a PostOperation"); + } + + var postOperation = (PostOperation)FormatterServices.GetUninitializedObject(typeToConvert); + + jsonElement.Value.DeserializePostOperation(postOperation, options); + return postOperation; + } + + /// Writes a specified value as JSON. + /// The writer to write to. + /// The value to convert to JSON. + /// An object that specifies serialization options to use. + public override void Write(Utf8JsonWriter writer, PostOperation value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + writer.WriteStartArray("_delete"u8); + + foreach (var toDelete in value.Delete) + { + JsonSerializer.Serialize(writer, toDelete, options); + } + + writer.WriteEndArray(); + writer.WriteStartArray("_create"u8); + + foreach (var toCreate in value.Create) + { + JsonSerializer.Serialize(writer, toCreate, options); + } + + writer.WriteEndArray(); + writer.WriteStartArray("_update"u8); + + foreach (var toUpdate in value.Update) + { + JsonSerializer.Serialize(writer, toUpdate, options); + } + + writer.WriteEndArray(); + + if (!this.ignoreCopyProperty) + { + writer.WriteStartArray("_copy"u8); + + foreach (var toCopy in value.Copy) + { + JsonSerializer.Serialize(writer, toCopy, options); + } + + writer.WriteEndArray(); + } + + writer.WriteEndObject(); + } + } +} diff --git a/CDP4JsonSerializer/JsonConverter/ThingConverterExtensions.cs b/CDP4JsonSerializer/JsonConverter/ThingConverterExtensions.cs new file mode 100644 index 000000000..9cee9b2f9 --- /dev/null +++ b/CDP4JsonSerializer/JsonConverter/ThingConverterExtensions.cs @@ -0,0 +1,111 @@ +// ------------------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// +// This file is part of CDP4-COMET SDK Community Edition +// +// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// ------------------------------------------------------------------------------------------------------------------------------- + +namespace CDP4JsonSerializer.JsonConverter +{ + using System; + using System.Linq; + + using CDP4Common.DTO; + using CDP4Common.MetaInfo; + + /// + /// The purpose of the is to implement extra business logic for hand-coded serialization to + /// decide to include or exclude classes from the serialization process + /// + public class ThingConverterExtensions + { + /// + /// Asserts whether an object shall be serialized or not + /// + /// + /// the for which the serialization is to be asserted + /// + /// + /// The used to provide meta data + /// + /// + /// The data model version to be used to determine whether a class shall be serialized or not + /// + /// + /// returns true when the object shall be serialzed, false if not + /// + public bool AssertSerialization(object value, IMetaDataProvider metaDataProvider, Version version) + { + if (value is PersonPermission personPermission) + { + var classVersion = new Version(metaDataProvider.GetClassVersion(personPermission.ObjectClass.ToString())); + + if (classVersion > version) + { + return false; + } + } + + if (value is ParticipantPermission participantPermission) + { + var classVersion = new Version(metaDataProvider.GetClassVersion(participantPermission.ObjectClass.ToString())); + + if (classVersion > version) + { + return false; + } + } + + return true; + } + + /// + /// Checks the 's property for compatibility + /// + /// + /// the for which the serialization is to be asserted + /// + /// + /// The used to provide meta data + /// + /// + /// The data model version to be used to determine whether a class shall be serialized or not + /// + public void CheckCategoryPermissibleClasses(object value, IMetaDataProvider metaDataProvider, Version version) + { + if (value is Category category) + { + var permissibleClasses = category.PermissibleClass.ToList(); + + foreach (var permissibleClass in permissibleClasses) + { + var permissibleClassVersion = new Version(metaDataProvider.GetClassVersion(permissibleClass.ToString())); + + if (permissibleClassVersion <= version) + { + continue; + } + + category.PermissibleClass.Remove(permissibleClass); + } + } + } + } +} diff --git a/CDP4JsonSerializer/JsonConverter/ThingSerializer.cs b/CDP4JsonSerializer/JsonConverter/ThingSerializer.cs index 2a1f71862..76b5e631b 100644 --- a/CDP4JsonSerializer/JsonConverter/ThingSerializer.cs +++ b/CDP4JsonSerializer/JsonConverter/ThingSerializer.cs @@ -10,38 +10,35 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4JsonSerializer.JsonConverter { using System; - using System.Collections.Generic; - using System.Linq; + using System.IO; + using System.Text.Json; + using System.Text.Json.Serialization; using CDP4Common.DTO; - using CDP4Common.Extensions; using CDP4Common.MetaInfo; using CDP4Common.Polyfills; - using Newtonsoft.Json; - using Newtonsoft.Json.Linq; - using NLog; /// - /// The that is responsible for (De)serialization on a + /// The that is responsible for (De)serialization on a /// - public class ThingSerializer : JsonConverter + public class ThingSerializer : JsonConverter { /// /// The NLog logger @@ -54,10 +51,20 @@ public class ThingSerializer : JsonConverter private readonly Version dataModelVersion; /// - /// The used to determine whether a class is to be serialized or not + /// Override default null handling + /// + public override bool HandleNull => true; + + /// + /// The used to determine whether a class is to be serialized or not /// private readonly ThingConverterExtensions thingConverterExtensions; + /// + /// Gets or sets the meta info provider. + /// + private IMetaDataProvider MetaInfoProvider { get; set; } + /// /// Initializes a new instance of the class. /// @@ -75,48 +82,48 @@ public ThingSerializer(IMetaDataProvider metaInfoProvider, Version dataModelVers this.thingConverterExtensions = new ThingConverterExtensions(); } - /// - /// Gets a value indicating whether this converter supports JSON read. - /// - public override bool CanRead => true; - - /// - /// Gets a value indicating whether this converter supports JSON write. - /// - public override bool CanWrite => true; - - /// - /// Gets or sets the meta info provider. - /// - private IMetaDataProvider MetaInfoProvider { get; set; } - /// /// Override of the can convert type check. /// - /// + /// /// The object type. /// /// /// true if this converter is to be used. /// - public override bool CanConvert(Type objectType) + public override bool CanConvert(Type typeToConvert) { - return typeof(Thing).QueryIsAssignableFrom(objectType); + return typeof(Thing).QueryIsAssignableFrom(typeToConvert); } /// - /// Write JSON. + /// Tries to deserialize a JSON into a /// - /// - /// The JSON writer. - /// - /// - /// The value object. - /// - /// - /// The JSON serializer. - /// - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + /// the + /// the to convert + /// the options of the serializer + /// the + public override Thing Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + // load object from stream + if (!JsonElement.TryParseValue(ref reader, out var jsonElement)) + { + Logger.Error("The data object in the JSON array could not be cast to a JsonElement type."); + throw new InvalidDataException("The data object in the JSON array could not be cast to a JsonElement type."); + } + + var newThing = jsonElement.Value.ToDto(); + + return newThing; + } + + /// + /// Write a JSON + /// + /// the + /// the to serialize + /// the options of the serializer + public override void Write(Utf8JsonWriter writer, Thing value, JsonSerializerOptions options) { var typeName = value.GetType().Name; var classVersion = new Version(this.MetaInfoProvider.GetClassVersion(typeName)); @@ -134,62 +141,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s } this.thingConverterExtensions.CheckCategoryPermissibleClasses(value, this.MetaInfoProvider, this.dataModelVersion); - - var jsonObject = ((Thing)value).ToJsonObject(); - - // remove versioned properties - var nonSerializableProperties = new List(); - - foreach (var kvp in jsonObject) - { - var propertyVersion = new Version(this.MetaInfoProvider.GetPropertyVersion(typeName, Helper.Utils.CapitalizeFirstLetter(kvp.Key))); - - if (propertyVersion > this.dataModelVersion) - { - nonSerializableProperties.Add(kvp.Key); - } - } - - foreach (var nonSerializableProperty in nonSerializableProperties) - { - jsonObject.Remove(nonSerializableProperty); - } - - jsonObject.WriteTo(writer); - } - - /// - /// Override of the Read JSON method. - /// - /// - /// The JSON reader. - /// - /// - /// The type information of the object. - /// - /// - /// The existing object value. - /// - /// - /// The JSON serializer. - /// - /// - /// A deserialized instance. - /// - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - // load object from stream - var jsonObject = JObject.Load(reader); - - if (jsonObject == null) - { - Logger.Error("The data object in the JSON array could not be cast to a JObject type."); - throw new NullReferenceException("The data object in the JSON array could not be cast to a JObject type."); - } - - var newThing = jsonObject.ToDto(); - - return newThing; + value.SerializeThing(writer, this.dataModelVersion); } } } diff --git a/CDP4JsonSerializer/Properties/AssemblyInfo.cs b/CDP4JsonSerializer/Properties/AssemblyInfo.cs index b51edd402..0f5b8ac56 100644 --- a/CDP4JsonSerializer/Properties/AssemblyInfo.cs +++ b/CDP4JsonSerializer/Properties/AssemblyInfo.cs @@ -24,5 +24,6 @@ using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("CDP4JsonSerializer.Tests")] -[assembly: InternalsVisibleTo("CDP4JsonSerializer.NetCore.Tests")] \ No newline at end of file +[assembly: InternalsVisibleTo("Cdp4JsonSerializer")] +[assembly: InternalsVisibleTo("Cdp4JsonSerializer.Tests")] +[assembly: InternalsVisibleTo("Cdp4JsonSerializer.NetCore.Tests")] \ No newline at end of file diff --git a/CDP4MessagePackSerializer.Tests/CDP4MessagePackSerializer.Tests.csproj b/CDP4MessagePackSerializer.Tests/CDP4MessagePackSerializer.Tests.csproj index debc6f9ae..eef5800a5 100644 --- a/CDP4MessagePackSerializer.Tests/CDP4MessagePackSerializer.Tests.csproj +++ b/CDP4MessagePackSerializer.Tests/CDP4MessagePackSerializer.Tests.csproj @@ -10,7 +10,7 @@ - + diff --git a/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj b/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj index b1e8cf8a7..65b667f6a 100644 --- a/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj +++ b/CDP4MessagePackSerializer/CDP4MessagePackSerializer.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4MessagePackSerializer Community Edition - 27.4.0 + 28.0.0 CDP4 MessagePack Serialization Library Copyright © Starion Group S.A. Sam, Alex, Alexander, Nathanael, Antoine, Omar @@ -20,8 +20,7 @@ CDP COMET ECSS-E-TM-10-25 MessagePack LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 - [Update] To MessagePack 2.5.187 + [Refactor] Newtonsoft to System.Text.Json README.md @@ -36,8 +35,8 @@ - - + + diff --git a/CDP4Reporting.Tests/CDP4Reporting.Tests.csproj b/CDP4Reporting.Tests/CDP4Reporting.Tests.csproj index 03c7802a5..c4cdfa36e 100644 --- a/CDP4Reporting.Tests/CDP4Reporting.Tests.csproj +++ b/CDP4Reporting.Tests/CDP4Reporting.Tests.csproj @@ -28,7 +28,7 @@ - + diff --git a/CDP4Reporting/CDP4Reporting.csproj b/CDP4Reporting/CDP4Reporting.csproj index 687103b22..75d99793c 100644 --- a/CDP4Reporting/CDP4Reporting.csproj +++ b/CDP4Reporting/CDP4Reporting.csproj @@ -4,7 +4,7 @@ netstandard2.0 Starion Group S.A. CDP4Reporting Community Edition - 27.4.0 + 28.0.0 CDP4 Reporting Copyright © Starion Group S.A. Sam, Alex, Alexander @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json latest README.md diff --git a/CDP4RequirementsVerification.Tests/CDP4RequirementsVerification.Tests.csproj b/CDP4RequirementsVerification.Tests/CDP4RequirementsVerification.Tests.csproj index 3504ebc5a..fd1c7c43d 100644 --- a/CDP4RequirementsVerification.Tests/CDP4RequirementsVerification.Tests.csproj +++ b/CDP4RequirementsVerification.Tests/CDP4RequirementsVerification.Tests.csproj @@ -11,7 +11,7 @@ - + diff --git a/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj b/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj index 8427ceeae..5b02e3a22 100644 --- a/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj +++ b/CDP4RequirementsVerification/CDP4RequirementsVerification.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4RequirementsVerification Community Edition - 27.4.0 + 28.0.0 CDP4 Class Library that provides requirement verification Copyright © Starion Group S.A. Sam, Alex, Alexander, Yevhen, Nathanael @@ -20,13 +20,13 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json README.md - + diff --git a/CDP4Rules.NetCore.Tests/CDP4Rules.NetCore.Tests.csproj b/CDP4Rules.NetCore.Tests/CDP4Rules.NetCore.Tests.csproj index 0d3a282e1..4e013a92a 100644 --- a/CDP4Rules.NetCore.Tests/CDP4Rules.NetCore.Tests.csproj +++ b/CDP4Rules.NetCore.Tests/CDP4Rules.NetCore.Tests.csproj @@ -16,7 +16,7 @@ - + diff --git a/CDP4Rules/CDP4Rules.csproj b/CDP4Rules/CDP4Rules.csproj index ad35b2c5c..a36697597 100644 --- a/CDP4Rules/CDP4Rules.csproj +++ b/CDP4Rules/CDP4Rules.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4Rules Community Edition - 27.4.0 + 28.0.0 CDP4 Class Library that provides Model Analysis and Rule Checking Copyright © Starion Group S.A. Sam, Alex, Alexander, Yevhen, Nathanael @@ -20,13 +20,13 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json README.md - + diff --git a/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj b/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj index 4ec60558c..0f1670ea0 100644 --- a/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj +++ b/CDP4ServicesDal.NetCore.Tests/CDP4ServicesDal.NetCore.Tests.csproj @@ -11,14 +11,13 @@ - - + diff --git a/CDP4ServicesDal.NetCore.Tests/CdpServicesDalTestFixture.cs b/CDP4ServicesDal.NetCore.Tests/CdpServicesDalTestFixture.cs index 0c988696b..515f73e50 100644 --- a/CDP4ServicesDal.NetCore.Tests/CdpServicesDalTestFixture.cs +++ b/CDP4ServicesDal.NetCore.Tests/CdpServicesDalTestFixture.cs @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal.Tests { @@ -49,7 +49,8 @@ namespace CDP4ServicesDal.Tests using CDP4Dal.Exceptions; using CDP4Dal.Operations; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; using NUnit.Framework; @@ -92,7 +93,7 @@ public void Setup() this.siteDirectory = new SiteDirectory(Guid.Parse("f13de6f8-b03a-46e7-a492-53b2f260f294"), this.session.Assembler.Cache, this.uri); var lazySiteDirectory = new Lazy(() => this.siteDirectory); lazySiteDirectory.Value.Cache.TryAdd(new CacheKey(lazySiteDirectory.Value.Iid, null), lazySiteDirectory); - + this.jsonSerializerOptions = new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, @@ -183,7 +184,7 @@ public void Verify_That_When_constructed_with_null_httpclient_throws_exception() HttpClient httpClient = null; Assert.Throws(() => new CdpServicesDal(httpClient)); } - + [Test] [Category("WebServicesDependent")] public async Task VerifThatAClosedDalCannotBeClosedAgain() @@ -326,6 +327,7 @@ public void VerifyThatPostBodyIsCorrectlyResolves() IsSynonym = false, LanguageCode = "en", }; + testDtoOriginal.AddContainer(ClassKind.DomainOfExpertise, domainOfExpertiseIid); testDtoOriginal.AddContainer(ClassKind.SiteDirectory, siteDirecortoryIid); @@ -335,6 +337,7 @@ public void VerifyThatPostBodyIsCorrectlyResolves() IsSynonym = true, LanguageCode = "en", }; + testDtoModified.AddContainer(ClassKind.DomainOfExpertise, domainOfExpertiseIid); testDtoModified.AddContainer(ClassKind.SiteDirectory, siteDirecortoryIid); @@ -343,6 +346,7 @@ public void VerifyThatPostBodyIsCorrectlyResolves() Content = "somecontent", LanguageCode = "en", }; + testDtoOriginal2.AddContainer(ClassKind.DomainOfExpertise, domainOfExpertiseIid); testDtoOriginal2.AddContainer(ClassKind.SiteDirectory, siteDirecortoryIid); @@ -351,6 +355,7 @@ public void VerifyThatPostBodyIsCorrectlyResolves() Content = "somecontent2", LanguageCode = "en", }; + testDtoModified2.AddContainer(ClassKind.DomainOfExpertise, domainOfExpertiseIid); testDtoModified2.AddContainer(ClassKind.SiteDirectory, siteDirecortoryIid); @@ -477,10 +482,11 @@ public async Task AssemblerSynchronizePerformanceTest() await assembler.Clear(); } }, Throws.Nothing); - + var synchronizeMeanElapsedTime = elapsedTimes.Average(); var maxElapsedTime = elapsedTimes.Max(); var minElapsedTime = elapsedTimes.Min(); + // 204.64 | 181 | 458 ms // refactor: 31.61 | 26 | 283 } @@ -497,7 +503,7 @@ public async Task VerifyThatFileCanBeUploaded() var files = new List { filepath }; var contentHash = "F73747371CFD9473C19A0A7F99BCAB008474C4CA"; - var uri = new Uri("https://cdp4services-test.cdp4.org"); + var uri = new Uri("https://cdp4services-test.cdp4.org"); this.credentials = new Credentials("admin", "pass", uri); var returned = await this.dal.Open(this.credentials, this.cancelationTokenSource.Token); @@ -621,7 +627,7 @@ public async Task Verify_that_opens_returns_expected_result() public async Task Verify_that_open_with_proxy_returns_expected_result() { var proxySettings = new ProxySettings(new Uri("http://tinyproxy:8888")); - + var uri = new Uri("https://cdp4services-test.cdp4.org"); this.credentials = new Credentials("admin", "pass", uri, false, proxySettings); @@ -630,16 +636,15 @@ public async Task Verify_that_open_with_proxy_returns_expected_result() Assert.That(result, Is.Not.Null); } - + [Test] [Category("WebServicesDependent")] public async Task Verify_that_multiple_read_requests_can_be_made_in_parallel() { var uri = new Uri("https://cdp4services-test.cdp4.org"); var credentials = new Credentials("admin", "pass", uri); - + var dal = new CdpServicesDal(); - var result = await dal.Open(credentials, new CancellationToken()); @@ -699,7 +704,7 @@ public async Task VerifyReadCometTask() this.dal = new CdpServicesDal(httpClient); this.SetDalToBeOpen(this.dal); - + var cometTaskId = Guid.NewGuid(); var requestHandler = mockHttp.When($"{CdpServicesDal.CometTaskRoute}/{cometTaskId}"); @@ -748,7 +753,7 @@ public async Task VerifyReadCometTasks() this.dal = new CdpServicesDal(httpClient); this.SetDalToBeOpen(this.dal); - + var requestHandler = mockHttp.When($"{CdpServicesDal.CometTaskRoute}"); var notFoundHttpResponse = new HttpResponseMessage() @@ -764,7 +769,7 @@ public async Task VerifyReadCometTasks() var cometTasks = new List() { - new () + new() { Id = Guid.NewGuid(), Actor = Guid.NewGuid(), @@ -830,7 +835,7 @@ public async Task VerifyWriteLongRunningTask() newCometTaskResponse.Content = new StringContent(JsonSerializer.Serialize(cometTask, this.jsonSerializerOptions)); SetHttpHeader(newCometTaskResponse, "application/json"); - var longRunningTaskResult = await this.dal.Write(operationContainer,1); + var longRunningTaskResult = await this.dal.Write(operationContainer, 1); Assert.Multiple(() => { @@ -843,12 +848,12 @@ public async Task VerifyWriteLongRunningTask() requestHandler.Respond(_ => thingsResponse); var stream = new MemoryStream(); - this.dal.Cdp4JsonSerializer.SerializeToStream(this.iteration, stream, true); + this.dal.Cdp4DalJsonSerializer.SerializeToStream(this.iteration, stream, true); stream.Position = 0; thingsResponse.Content = new StreamContent(stream); SetHttpHeader(thingsResponse, "application/json"); - longRunningTaskResult = await this.dal.Write(operationContainer,1); + longRunningTaskResult = await this.dal.Write(operationContainer, 1); Assert.Multiple(() => { diff --git a/CDP4ServicesDal.NetCore.Tests/CopyOperationHandlerTestFixture.cs b/CDP4ServicesDal.NetCore.Tests/CopyOperationHandlerTestFixture.cs index dd10f7cd5..83f16c4d8 100644 --- a/CDP4ServicesDal.NetCore.Tests/CopyOperationHandlerTestFixture.cs +++ b/CDP4ServicesDal.NetCore.Tests/CopyOperationHandlerTestFixture.cs @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal.Tests { @@ -36,6 +36,8 @@ namespace CDP4ServicesDal.Tests using CDP4Dal.Operations; using CDP4Dal.Permission; + using CDP4DalCommon.Protocol.Operations; + using Moq; using NUnit.Framework; diff --git a/CDP4ServicesDal.NetCore.Tests/OperationModifierTestFixture.cs b/CDP4ServicesDal.NetCore.Tests/OperationModifierTestFixture.cs index 0bbed62b7..970190784 100644 --- a/CDP4ServicesDal.NetCore.Tests/OperationModifierTestFixture.cs +++ b/CDP4ServicesDal.NetCore.Tests/OperationModifierTestFixture.cs @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal.Tests { @@ -34,6 +34,8 @@ namespace CDP4ServicesDal.Tests using CDP4Dal; using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using Moq; using NUnit.Framework; diff --git a/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs b/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs index 35f2d839d..ac195a939 100644 --- a/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs +++ b/CDP4ServicesDal.NetCore.Tests/PostOperationTestFixture.cs @@ -10,17 +10,17 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal.Tests { @@ -35,34 +35,35 @@ namespace CDP4ServicesDal.Tests using CDP4Common.MetaInfo; using CDP4Common.Types; - using CDP4JsonSerializer; - using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + + using CDP4JsonSerializer; + using CDP4ServicesDal.Tests.Helper; - - using Newtonsoft.Json; - + using NUnit.Framework; - + using File = System.IO.File; - + [TestFixture] public class PostOperationTestFixture { - private Cdp4JsonSerializer serializer; + private Cdp4DalJsonSerializer serializer; [SetUp] public void Setup() { var metamodel = new MetaDataProvider(); - this.serializer = new Cdp4JsonSerializer(metamodel, new Version(1, 1, 0)); + this.serializer = new Cdp4DalJsonSerializer(metamodel, new Version(1, 1, 0), false); } [Test] public void Verify_that_deserialization_of_Post_Operation_does_not_throw_an_exception() { var response = File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData/PostOperation.json")); + using (var stream = StreamHelper.GenerateStreamFromString(response)) { var test = this.serializer.Deserialize(stream); @@ -139,34 +140,6 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( private class TestPostOperation : PostOperation { - public override void ConstructFromOperation(Operation operation) - { - throw new NotImplementedException(); - } - - /// - /// Gets or sets the collection of DTOs to delete. - /// - [JsonProperty("_delete")] - public override List Delete { get; set; } - - /// - /// Gets or sets the collection of DTOs to create. - /// - [JsonProperty("_create")] - public override List Create { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - [JsonProperty("_update")] - public override List Update { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - [JsonProperty("_copy")] - public override List Copy { get; set; } } } } diff --git a/CDP4ServicesDal.Tests/CDP4ServicesDal.Tests.csproj b/CDP4ServicesDal.Tests/CDP4ServicesDal.Tests.csproj index 15478becf..7b14022b4 100644 --- a/CDP4ServicesDal.Tests/CDP4ServicesDal.Tests.csproj +++ b/CDP4ServicesDal.Tests/CDP4ServicesDal.Tests.csproj @@ -18,7 +18,7 @@ - + diff --git a/CDP4ServicesDal.Tests/CdpServicesDalTestFixture.cs b/CDP4ServicesDal.Tests/CdpServicesDalTestFixture.cs index b85a2af13..6add04da1 100644 --- a/CDP4ServicesDal.Tests/CdpServicesDalTestFixture.cs +++ b/CDP4ServicesDal.Tests/CdpServicesDalTestFixture.cs @@ -1,4 +1,4 @@ -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2024 Starion Group S.A. // @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal.Tests { @@ -38,6 +38,7 @@ namespace CDP4ServicesDal.Tests using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; + using CDP4Common.MetaInfo; using CDP4Common.SiteDirectoryData; using CDP4Common.Types; @@ -47,9 +48,10 @@ namespace CDP4ServicesDal.Tests using CDP4Dal.Exceptions; using CDP4Dal.Operations; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; - using Newtonsoft.Json; + using CDP4JsonSerializer; using NUnit.Framework; @@ -76,6 +78,7 @@ public class CdpServicesDalTestFixture private SiteReferenceDataLibrary siteReferenceDataLibrary; private ModelReferenceDataLibrary modelReferenceDataLibrary; private CDPMessageBus messageBus; + private Cdp4JsonSerializer jsonSerializer; [SetUp] public void Setup() @@ -91,7 +94,8 @@ public void Setup() this.siteDirectory = new SiteDirectory(Guid.Parse("f13de6f8-b03a-46e7-a492-53b2f260f294"), this.session.Assembler.Cache, this.uri); var lazySiteDirectory = new Lazy(() => this.siteDirectory); lazySiteDirectory.Value.Cache.TryAdd(new CacheKey(lazySiteDirectory.Value.Iid, null), lazySiteDirectory); - + var metaDataProvider = new MetaDataProvider(); + this.jsonSerializer = new Cdp4JsonSerializer(metaDataProvider, metaDataProvider.GetMaxSupportedModelVersion()); this.PopulateSiteDirectory(); } @@ -723,7 +727,7 @@ public async Task Verify_that_person_can_be_Posted() Assert.That(resultPerson, Is.Not.Null); } - [Test] + [Test] public async Task VerifyReadCometTask() { var mockHttp = new MockHttpMessageHandler(); @@ -732,7 +736,7 @@ public async Task VerifyReadCometTask() this.dal = new CdpServicesDal(httpClient); this.SetDalToBeOpen(this.dal); - + var cometTaskId = Guid.NewGuid(); var requestHandler = mockHttp.When($"{CdpServicesDal.CometTaskRoute}/{cometTaskId}"); @@ -758,7 +762,7 @@ public async Task VerifyReadCometTask() StatusKind = StatusKind.SUCCEEDED }; - foundHttpResponse.Content = new StringContent(JsonConvert.SerializeObject(cometTask)); + foundHttpResponse.Content = new StringContent(this.jsonSerializer.SerializeToString(cometTask)); SetHttpHeader(foundHttpResponse, "application/json"); var readCometTask = await this.dal.ReadCometTask(cometTaskId, CancellationToken.None); @@ -766,7 +770,7 @@ public async Task VerifyReadCometTask() var messagePackHttpResponse = new HttpResponseMessage(); requestHandler.Respond(_ => messagePackHttpResponse); - messagePackHttpResponse.Content = new StringContent(JsonConvert.SerializeObject(cometTask)); + messagePackHttpResponse.Content = new StringContent(this.jsonSerializer.SerializeToString(cometTask)); SetHttpHeader(messagePackHttpResponse, "application/msgpack"); Assert.That(() => this.dal.ReadCometTask(cometTaskId, CancellationToken.None), Throws.Exception.TypeOf()); @@ -781,7 +785,7 @@ public async Task VerifyReadCometTasks() this.dal = new CdpServicesDal(httpClient); this.SetDalToBeOpen(this.dal); - + var requestHandler = mockHttp.When($"{CdpServicesDal.CometTaskRoute}"); var notFoundHttpResponse = new HttpResponseMessage() @@ -808,7 +812,7 @@ public async Task VerifyReadCometTasks() } }; - foundHttpResponse.Content = new StringContent(JsonConvert.SerializeObject(cometTasks)); + foundHttpResponse.Content = new StringContent(this.jsonSerializer.SerializeToString(cometTasks)); SetHttpHeader(foundHttpResponse, "application/json"); var readCometTasks = await this.dal.ReadCometTasks(CancellationToken.None); @@ -816,7 +820,7 @@ public async Task VerifyReadCometTasks() var messagePackHttpResponse = new HttpResponseMessage(); requestHandler.Respond(_ => messagePackHttpResponse); - messagePackHttpResponse.Content = new StringContent(JsonConvert.SerializeObject(cometTasks)); + messagePackHttpResponse.Content = new StringContent(this.jsonSerializer.SerializeToString(cometTasks)); SetHttpHeader(messagePackHttpResponse, "application/msgpack"); Assert.That(() => this.dal.ReadCometTasks(CancellationToken.None), Throws.Exception.TypeOf()); @@ -862,10 +866,10 @@ public async Task VerifyWriteLongRunningTask() var newCometTaskResponse = new HttpResponseMessage(); requestHandler.Respond(_ => newCometTaskResponse); - newCometTaskResponse.Content = new StringContent(JsonConvert.SerializeObject(cometTask)); + newCometTaskResponse.Content = new StringContent(this.jsonSerializer.SerializeToString(cometTask)); SetHttpHeader(newCometTaskResponse, "application/json"); - var longRunningTaskResult = await this.dal.Write(operationContainer,1); + var longRunningTaskResult = await this.dal.Write(operationContainer, 1); Assert.Multiple(() => { @@ -878,12 +882,12 @@ public async Task VerifyWriteLongRunningTask() requestHandler.Respond(_ => thingsResponse); var stream = new MemoryStream(); - this.dal.Cdp4JsonSerializer.SerializeToStream(this.iteration, stream, true); + this.dal.Cdp4DalJsonSerializer.SerializeToStream(this.iteration, stream, true); stream.Position = 0; thingsResponse.Content = new StreamContent(stream); SetHttpHeader(thingsResponse, "application/json"); - longRunningTaskResult = await this.dal.Write(operationContainer,1); + longRunningTaskResult = await this.dal.Write(operationContainer, 1); Assert.Multiple(() => { @@ -895,7 +899,7 @@ public async Task VerifyWriteLongRunningTask() var messagePackResponse = new HttpResponseMessage(); requestHandler.Respond(_ => messagePackResponse); - messagePackResponse.Content = new StringContent(JsonConvert.SerializeObject(cometTask)); + messagePackResponse.Content = new StringContent(this.jsonSerializer.SerializeToString(cometTask)); SetHttpHeader(messagePackResponse, "application/msgpack"); Assert.That(() => this.dal.Write(operationContainer, 1), Throws.Exception.TypeOf()); } diff --git a/CDP4ServicesDal.Tests/CopyOperationHandlerTestFixture.cs b/CDP4ServicesDal.Tests/CopyOperationHandlerTestFixture.cs index ffd0198ea..50272e3fe 100644 --- a/CDP4ServicesDal.Tests/CopyOperationHandlerTestFixture.cs +++ b/CDP4ServicesDal.Tests/CopyOperationHandlerTestFixture.cs @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal.Tests { @@ -36,6 +36,8 @@ namespace CDP4ServicesDal.Tests using CDP4Dal.Operations; using CDP4Dal.Permission; + using CDP4DalCommon.Protocol.Operations; + using Moq; using NUnit.Framework; diff --git a/CDP4ServicesDal.Tests/OperationModifierTestFixture.cs b/CDP4ServicesDal.Tests/OperationModifierTestFixture.cs index 02586eddb..3fc532c14 100644 --- a/CDP4ServicesDal.Tests/OperationModifierTestFixture.cs +++ b/CDP4ServicesDal.Tests/OperationModifierTestFixture.cs @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal.Tests { @@ -34,6 +34,8 @@ namespace CDP4ServicesDal.Tests using CDP4Dal; using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using Moq; using NUnit.Framework; diff --git a/CDP4ServicesDal.Tests/PostOperationTestFixture.cs b/CDP4ServicesDal.Tests/PostOperationTestFixture.cs index e4c06b070..9c3f5d5e1 100644 --- a/CDP4ServicesDal.Tests/PostOperationTestFixture.cs +++ b/CDP4ServicesDal.Tests/PostOperationTestFixture.cs @@ -10,17 +10,17 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal.Tests { @@ -35,14 +35,14 @@ namespace CDP4ServicesDal.Tests using CDP4Common.MetaInfo; using CDP4Common.Types; - using CDP4JsonSerializer; - using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + + using CDP4JsonSerializer; + using CDP4ServicesDal.Tests.Helper; - - using Newtonsoft.Json; - + using NUnit.Framework; using File = System.IO.File; @@ -50,19 +50,20 @@ namespace CDP4ServicesDal.Tests [TestFixture] public class PostOperationTestFixture { - private Cdp4JsonSerializer serializer; + private Cdp4DalJsonSerializer serializer; [SetUp] public void Setup() { var metamodel = new MetaDataProvider(); - this.serializer = new Cdp4JsonSerializer(metamodel, new Version(1, 1, 0)); + this.serializer = new Cdp4DalJsonSerializer(metamodel, new Version(1, 1, 0), false); } [Test] public void Verify_that_deserialization_of_Post_Operation_does_not_throw_an_exception() { var response = File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData/PostOperation.json")); + using (var stream = StreamHelper.GenerateStreamFromString(response)) { var test = this.serializer.Deserialize(stream); @@ -88,7 +89,7 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( originalDomainFileStore.AddContainer(ClassKind.Iteration, iterationIid); originalDomainFileStore.AddContainer(ClassKind.EngineeringModel, engineeringModelIid); - var modifiedDomainFileStore = originalDomainFileStore.DeepClone(); + var modifiedDomainFileStore = originalDomainFileStore.DeepClone(); modifiedDomainFileStore.File.Add(fileIid); var file = new CDP4Common.DTO.File(fileIid, 0); @@ -101,7 +102,7 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( var fileRevision = new FileRevision(fileRevisionIid, 0); fileRevision.Name = "testfile"; fileRevision.ContentHash = "F73747371CFD9473C19A0A7F99BCAB008474C4CA"; - fileRevision.FileType.Add(new OrderedItem() {K = 1, V = fileTypeIid }); + fileRevision.FileType.Add(new OrderedItem() { K = 1, V = fileTypeIid }); fileRevision.Creator = participantIid; fileRevision.AddContainer(ClassKind.File, fileIid); fileRevision.AddContainer(ClassKind.DomainFileStore, domainFileStoreIid); @@ -122,7 +123,8 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( var postOperation = new CdpPostOperation(new MetaDataProvider(), null); - foreach (var operation in operationContainer.Operations) { + foreach (var operation in operationContainer.Operations) + { postOperation.ConstructFromOperation(operation); } @@ -138,34 +140,6 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( private class TestPostOperation : PostOperation { - public override void ConstructFromOperation(Operation operation) - { - throw new NotImplementedException(); - } - - /// - /// Gets or sets the collection of DTOs to delete. - /// - [JsonProperty("_delete")] - public override List Delete { get; set; } - - /// - /// Gets or sets the collection of DTOs to create. - /// - [JsonProperty("_create")] - public override List Create { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - [JsonProperty("_update")] - public override List Update { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - [JsonProperty("_copy")] - public override List Copy { get; set; } } } } diff --git a/CDP4ServicesDal/CDP4ServicesDal.csproj b/CDP4ServicesDal/CDP4ServicesDal.csproj index d75880e18..f1c76fb64 100644 --- a/CDP4ServicesDal/CDP4ServicesDal.csproj +++ b/CDP4ServicesDal/CDP4ServicesDal.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4ServicesDal Community Edition - 27.4.0 + 28.0.0 CDP4ServicesDal Dal Plugin Copyright © Starion Group S.A. Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael @@ -20,13 +20,14 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json README.md - + + @@ -39,14 +40,10 @@ - - - - - + diff --git a/CDP4ServicesDal/CdpPostOperation.cs b/CDP4ServicesDal/CdpPostOperation.cs index 5c5273caa..7c493e2f6 100644 --- a/CDP4ServicesDal/CdpPostOperation.cs +++ b/CDP4ServicesDal/CdpPostOperation.cs @@ -1,5 +1,4 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2015-2019 Starion Group S.A. // @@ -11,18 +10,17 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal { @@ -30,16 +28,19 @@ namespace CDP4ServicesDal using System.Collections; using System.Collections.Generic; using System.Linq; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.Dto; using CDP4Common.EngineeringModelData; - using CDP4Common.MetaInfo; + using CDP4Common.MetaInfo; using CDP4Common.SiteDirectoryData; using CDP4Common.Types; + using CDP4Dal; using CDP4Dal.Operations; - using Newtonsoft.Json; + + using CDP4DalCommon.Protocol.Operations; /// /// The CDP POST operation @@ -78,30 +79,6 @@ internal CdpPostOperation(IMetaDataProvider metaDataProvider, ISession session) this.session = session; } - /// - /// Gets or sets the collection of DTOs to delete. - /// - [JsonProperty("_delete")] - public override List Delete { get; set; } - - /// - /// Gets or sets the collection of DTOs to create. - /// - [JsonProperty("_create")] - public override List Create { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - [JsonProperty("_update")] - public override List Update { get; set; } - - /// - /// Gets or sets the collection of DTOs to copy. - /// - [JsonProperty("_copy")] - public override List Copy { get; set; } - /// /// Populate the current with the content based on the /// provided @@ -114,7 +91,7 @@ public override void ConstructFromOperation(Operation operation) { if (operation.ModifiedThing == null) { - throw new ArgumentNullException("operation", "The operation may not be null"); + throw new ArgumentNullException(nameof(operation), "The operation may not be null"); } switch (operation.OperationKind) @@ -154,6 +131,7 @@ private void ResolveUpdate(Operation operation) foreach (var key in original.Keys) { var originalIenumerable = original[key] as IEnumerable; + if (originalIenumerable != null && originalIenumerable.GetType().IsGenericType) { var modifiedIenumerable = (IEnumerable)modifiedFull[key]; @@ -177,6 +155,7 @@ private void ResolveUpdate(Operation operation) List modifiedProperty; var genericTypeArgument = original[key].GetType().GenericTypeArguments[0]; + if (genericTypeArgument == typeof(Guid) || genericTypeArgument == typeof(ClassKind) || genericTypeArgument == typeof(VcardTelephoneNumberKind)) { originalProperty = originalIenumerable.Cast().ToList(); @@ -221,6 +200,7 @@ private void ResolveUpdate(Operation operation) } var possibleDeletions = originalProperty.Except(modifiedProperty).ToList(); + if (possibleDeletions.Count > 0) { // this part will be added to the delete @@ -275,6 +255,7 @@ private void ResolveUpdate(Operation operation) if (listsToAdd.Count > 0) { var updateDto = modified; + foreach (var kvp in listsToAdd) { updateDto.Add(kvp.Key, kvp.Value); @@ -311,18 +292,20 @@ private void ResolveCopy(Operation operation) var source = new CopySource { - Thing = new CopyReference {Iid = operation.OriginalThing.Iid, ClassKind = operation.OriginalThing.ClassKind}, - TopContainer = new CopyReference {Iid = sourcepoco.TopContainer.Iid, ClassKind = sourcepoco.TopContainer.ClassKind}, + Thing = new CopyReference { Iid = operation.OriginalThing.Iid, ClassKind = operation.OriginalThing.ClassKind }, + TopContainer = new CopyReference { Iid = sourcepoco.TopContainer.Iid, ClassKind = sourcepoco.TopContainer.ClassKind }, IterationId = sourceIteration?.Iid }; var poco = operation.ModifiedThing.QuerySourceThing(); + if (poco.Container == null) { throw new InvalidOperationException("The container cannot be null."); } var targetIteration = poco.GetContainerOfType(); + var target = new CopyTarget { Container = new CopyReference { Iid = poco.Container.Iid, ClassKind = poco.Container.ClassKind }, diff --git a/CDP4ServicesDal/CdpServicesDal.cs b/CDP4ServicesDal/CdpServicesDal.cs index adc8222fc..1b994f883 100644 --- a/CDP4ServicesDal/CdpServicesDal.cs +++ b/CDP4ServicesDal/CdpServicesDal.cs @@ -2,7 +2,7 @@ // // Copyright (c) 2015-2024 Starion Group S.A. // -// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar // // This file is part of CDP4-COMET SDK Community Edition // @@ -27,7 +27,6 @@ namespace CDP4ServicesDal #if NETFRAMEWORK using System.ComponentModel.Composition; #endif - using System; using System.Collections.Generic; using System.Diagnostics; @@ -45,8 +44,6 @@ namespace CDP4ServicesDal using CDP4Common.DTO; using CDP4Common.Extensions; - using CDP4DalCommon.Tasks; - using CDP4Dal; using CDP4Dal.Composition; using CDP4Dal.DAL; @@ -54,6 +51,9 @@ namespace CDP4ServicesDal using CDP4Dal.Exceptions; using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; + using CDP4JsonSerializer; using CDP4MessagePackSerializer; @@ -94,7 +94,7 @@ public class CdpServicesDal : Dal /// public CdpServicesDal() { - this.Cdp4JsonSerializer = new Cdp4JsonSerializer(this.MetaDataProvider, this.DalVersion); + this.Cdp4DalJsonSerializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion, false); this.MessagePackSerializer = new MessagePackSerializer(); } @@ -106,18 +106,13 @@ public CdpServicesDal() /// public CdpServicesDal(HttpClient httpClient) : this() { - if (httpClient == null) - { - throw new ArgumentNullException(nameof(httpClient)); - } - - this.httpClient = httpClient; + this.httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); } /// - /// Gets the + /// Gets the /// - public Cdp4JsonSerializer Cdp4JsonSerializer { get; private set; } + public Cdp4DalJsonSerializer Cdp4DalJsonSerializer { get; private set; } /// /// Gets the @@ -208,7 +203,7 @@ public override async Task> Write(OperationContainer operatio { case ContentTypeKind.JSON: Logger.Info("Deserializing JSON response"); - result.AddRange(this.Cdp4JsonSerializer.Deserialize(resultStream)); + result.AddRange(this.Cdp4DalJsonSerializer.Deserialize(resultStream)); Logger.Info("JSON Deserializer completed in {0} [ms]", deserializationWatch.ElapsedMilliseconds); break; case ContentTypeKind.MESSAGEPACK: @@ -342,7 +337,7 @@ public override async Task Write(OperationContainer opera case ContentTypeKind.MESSAGEPACK: throw new NotSupportedException("Long running task not supported with MESSAGEPACK"); default: - throw new InvalidOperationException( $"ContentTypeKind {contentTypeKind} not supported"); + throw new InvalidOperationException($"ContentTypeKind {contentTypeKind} not supported"); } deserializationWatch.Stop(); @@ -500,7 +495,7 @@ public override async Task> Read(IEnumerable> Read(T thing, CancellationToke { case ContentTypeKind.JSON: Logger.Info("Deserializing JSON response"); - returned = this.Cdp4JsonSerializer.Deserialize(resultStream); + returned = this.Cdp4DalJsonSerializer.Deserialize(resultStream); Logger.Info("JSON Deserializer completed in {0} [ms]", deserializationWatch.ElapsedMilliseconds); break; case ContentTypeKind.MESSAGEPACK: @@ -729,13 +724,13 @@ public override async Task ReadCometTask(Guid id, CancellationToken c { case ContentTypeKind.JSON: Logger.Info("Deserializing JSON response"); - returned = this.Cdp4JsonSerializer.Deserialize(resultStream); + returned = this.Cdp4DalJsonSerializer.Deserialize(resultStream); Logger.Info("JSON Deserializer completed in {0} [ms]", deserializationWatch.ElapsedMilliseconds); break; case ContentTypeKind.MESSAGEPACK: throw new NotSupportedException("Read CometTask by id not supported with MESSAGEPACK"); default: - throw new InvalidOperationException( $"ContentTypeKind {contentTypeKind} not supported"); + throw new InvalidOperationException($"ContentTypeKind {contentTypeKind} not supported"); } deserializationWatch.Stop(); @@ -790,13 +785,13 @@ public override async Task> ReadCometTasks(CancellationTo { case ContentTypeKind.JSON: Logger.Info("Deserializing JSON response"); - returned = this.Cdp4JsonSerializer.Deserialize>(resultStream); + returned = this.Cdp4DalJsonSerializer.Deserialize>(resultStream); Logger.Info("JSON Deserializer completed in {0} [ms]", deserializationWatch.ElapsedMilliseconds); break; case ContentTypeKind.MESSAGEPACK: throw new NotSupportedException("Read all CometTask not supported with MESSAGEPACK"); default: - throw new InvalidOperationException( $"ContentTypeKind {contentTypeKind} not supported"); + throw new InvalidOperationException($"ContentTypeKind {contentTypeKind} not supported"); } deserializationWatch.Stop(); @@ -934,7 +929,7 @@ public override async Task> Open(Credentials credentials, Can { case ContentTypeKind.JSON: Logger.Info("Deserializing JSON response"); - returned = this.Cdp4JsonSerializer.Deserialize(resultStream); + returned = this.Cdp4DalJsonSerializer.Deserialize(resultStream); Logger.Info("JSON Deserializer completed in {0} [ms]", deserializationWatch.ElapsedMilliseconds); break; case ContentTypeKind.MESSAGEPACK: @@ -1090,6 +1085,7 @@ private HttpClient CreateHttpClient(Credentials credentials, HttpClient injected result.DefaultRequestHeaders.Accept.Clear(); result.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); result.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/msgpack")); + result.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{credentials.UserName}:{credentials.Password}"))); result.DefaultRequestHeaders.Add(Headers.AcceptCdpVersion, Headers.AcceptCdpVersionValue); result.DefaultRequestHeaders.Add("User-Agent", "CDP4 (ECSS-E-TM-10-25 Annex C.2) CDPServicesDal"); @@ -1173,7 +1169,7 @@ internal void ConstructPostRequestBodyStream(string token, OperationContainer op postOperation.ConstructFromOperation(operation); } - this.Cdp4JsonSerializer.SerializeToStream(postOperation, outputStream); + this.Cdp4DalJsonSerializer.SerializeToStream(postOperation, outputStream); outputStream.Position = 0; if (Logger.IsTraceEnabled) @@ -1402,9 +1398,9 @@ private LongRunningTaskResult ExtractResultFromStream(Stream stream) var firstChar = (char)reader.Peek(); stream.Position = 0; - return firstChar == '[' - ? new LongRunningTaskResult(this.Cdp4JsonSerializer.Deserialize(stream)) - : new LongRunningTaskResult(this.Cdp4JsonSerializer.Deserialize(stream)); + return firstChar == '[' + ? new LongRunningTaskResult(this.Cdp4DalJsonSerializer.Deserialize(stream)) + : new LongRunningTaskResult(this.Cdp4DalJsonSerializer.Deserialize(stream)); } } diff --git a/CDP4ServicesDal/CopyOperationHandler.cs b/CDP4ServicesDal/CopyOperationHandler.cs index 7b077bd94..f6c1ce2c0 100644 --- a/CDP4ServicesDal/CopyOperationHandler.cs +++ b/CDP4ServicesDal/CopyOperationHandler.cs @@ -10,17 +10,17 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal { @@ -31,12 +31,13 @@ namespace CDP4ServicesDal using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; - using CDP4Common.Helpers; using CDP4Dal; using CDP4Dal.Operations; using CDP4Dal.Permission; + using CDP4DalCommon.Protocol.Operations; + using Poco = CDP4Common.CommonData.Thing; /// @@ -55,7 +56,7 @@ internal class CopyOperationHandler private readonly ISession session; /// - /// A that map the original to the copied version + /// A that map the original to the copied version /// private Dictionary copyThingMap; @@ -95,6 +96,7 @@ public void ModifiedCopyOperation(OperationContainer operationContainer) var operationsToAdd = new List(); var copyOperationCount = operationContainer.Operations.Count(x => x.OperationKind.IsCopyOperation()); + if (copyOperationCount > 1) { // TODO: support this if needed @@ -102,6 +104,7 @@ public void ModifiedCopyOperation(OperationContainer operationContainer) } var copyOperation = operationContainer.Operations.SingleOrDefault(x => x.OperationKind.IsCopyOperation()); + if (copyOperation == null) { return; @@ -156,6 +159,7 @@ private void ComputeOperations(Operation copyOperation) // Add all contained objects this.copyableIds.AddRange(copyPermissionResult.CopyableThings.Select(c => c.Iid).ToList()); + if (this.copyableIds.Contains(originalPoco.Iid)) { var updatedIteration = copyPoco.GetContainerOfType(); @@ -164,6 +168,7 @@ private void ComputeOperations(Operation copyOperation) // modify the references to point to the copy thing this.ModifyReferences(); + if (copyOperation.OperationKind.IsCopyChangeOwnerOperation()) { this.ChangeOwner(updatedIteration); @@ -209,6 +214,7 @@ private void CreatePocoCopy(Poco poco, Iteration targetIteration) foreach (var containerList in poco.ContainerLists) { var updatedContainerList = new List(); + foreach (Poco containedPoco in containerList) { if (!this.copyableIds.Contains(containedPoco.Iid)) @@ -311,6 +317,7 @@ private void ModifyReferences(ElementUsage usage) private void ModifyReferences(Parameter parameter) { parameter.StateDependence = null; + if (parameter.Group == null) { return; @@ -319,6 +326,7 @@ private void ModifyReferences(Parameter parameter) // if the group cannot be copied, set to null Poco groupCopy; this.copyThingMap.TryGetValue(parameter.Group, out groupCopy); + parameter.Group = this.copyThingMap.TryGetValue(parameter.Group, out groupCopy) ? (ParameterGroup)groupCopy : null; @@ -338,6 +346,7 @@ private void ModifyReferences(ParameterGroup group) // if the group cannot be copied, set to null Poco groupCopy; this.copyThingMap.TryGetValue(group.ContainingGroup, out groupCopy); + group.ContainingGroup = this.copyThingMap.TryGetValue(group.ContainingGroup, out groupCopy) ? (ParameterGroup)groupCopy : null; @@ -361,12 +370,14 @@ private void ModifyReferences(ParameterOverride parameterOverride) private void ChangeOwner(Iteration iteration) { var activeDomain = this.session.OpenIterations.Single(x => x.Key.Iid == iteration.Iid).Value.Item1; + if (activeDomain == null) { throw new InvalidOperationException("The active domain is null. The copy operation cannot be performed."); } var ownedThings = this.copyThingMap.Values.OfType().ToList(); + foreach (var ownedThing in ownedThings) { // the owner of a subscription shall not be set to the active one @@ -379,4 +390,4 @@ private void ChangeOwner(Iteration iteration) } } } -} \ No newline at end of file +} diff --git a/CDP4ServicesDal/OperationModifier.cs b/CDP4ServicesDal/OperationModifier.cs index c3d1637f0..57214ae1e 100644 --- a/CDP4ServicesDal/OperationModifier.cs +++ b/CDP4ServicesDal/OperationModifier.cs @@ -10,35 +10,33 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal { - using System; using System.Collections.Generic; using System.Linq; - using CDP4Common.CommonData; + using CDP4Common.EngineeringModelData; - using CDP4Common.Types; + using CDP4Dal; using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using ActualFiniteState = CDP4Common.DTO.ActualFiniteState; - using ElementUsage = CDP4Common.DTO.ElementUsage; - using ParameterOverride = CDP4Common.DTO.ParameterOverride; - using ParameterSubscription = CDP4Common.DTO.ParameterSubscription; using PossibleFiniteStateList = CDP4Common.DTO.PossibleFiniteStateList; - + /// /// The purpose of the is to perform operations that /// are not performed directly by the server @@ -73,6 +71,7 @@ public void ModifyOperationContainer(OperationContainer operationContainer) if (operation.OperationKind == OperationKind.Update) { var possibleStateList = operation.ModifiedThing as PossibleFiniteStateList; + if (possibleStateList != null) { operationsToAdd.AddRange(this.ModifyActualStateKindOnDefaultPossibleStateUpdate(possibleStateList)); @@ -95,6 +94,7 @@ private IEnumerable ModifyActualStateKindOnDefaultPossibleStateUpdate { var operations = new List(); var defaultStateId = possibleFiniteStateList.DefaultState; + if (!defaultStateId.HasValue) { return operations; @@ -102,14 +102,15 @@ private IEnumerable ModifyActualStateKindOnDefaultPossibleStateUpdate // gets the actualList that uses the updated possible list var actualLists = this.session.Assembler.Cache.Select(x => x.Value) - .Select(x => x.Value) - .OfType() - .Where(x => x.PossibleFiniteStateList.Select(pl => pl.Iid).Contains(possibleFiniteStateList.Iid)) - .ToList(); + .Select(x => x.Value) + .OfType() + .Where(x => x.PossibleFiniteStateList.Select(pl => pl.Iid).Contains(possibleFiniteStateList.Iid)) + .ToList(); foreach (var actualFiniteStateList in actualLists) { var possibleLists = actualFiniteStateList.PossibleFiniteStateList.Where(x => x.Iid != possibleFiniteStateList.Iid).ToList(); + if (possibleLists.Any(x => x.DefaultState == null)) { // one of the possible list has no default state @@ -141,4 +142,4 @@ private IEnumerable ModifyActualStateKindOnDefaultPossibleStateUpdate return operations; } } -} \ No newline at end of file +} diff --git a/CDP4ServicesDal/ValueSetOperationCreator.cs b/CDP4ServicesDal/ValueSetOperationCreator.cs index 9b20d9962..bde85c07c 100644 --- a/CDP4ServicesDal/ValueSetOperationCreator.cs +++ b/CDP4ServicesDal/ValueSetOperationCreator.cs @@ -1,7 +1,6 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 Starion Group S.A. +// Copyright (c) 2015-2024 Starion Group S.A. // // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou // @@ -11,28 +10,32 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4ServicesDal { using System; using System.Collections.Generic; using System.Linq; + using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; + using CDP4Dal; using CDP4Dal.Operations; + + using CDP4DalCommon.Protocol.Operations; + using Dto = CDP4Common.DTO; /// @@ -44,7 +47,7 @@ internal class ValueSetOperationCreator /// The associated /// private readonly ISession session; - + /// /// Initializes a new instance of the class /// @@ -70,6 +73,7 @@ public OperationContainer CreateValueSetsUpdateOperations(string context, IEnume var dtolist = dtos.ToList(); var topContainer = dtolist.SingleOrDefault(x => x is Dto.TopContainer); + if (topContainer == null) { throw new InvalidOperationException("No Top container were found in the returned list of dtos."); @@ -78,9 +82,10 @@ public OperationContainer CreateValueSetsUpdateOperations(string context, IEnume // Gets the parameter base which value set shall be updated var copyParameterBases = dtolist.OfType().ToList(); var copyParameterBasesIds = copyParameterBases.Select(p => p.Iid).ToList(); + var valuesets = dtolist.Where(dto => dto.ClassKind == ClassKind.ParameterValueSet || - dto.ClassKind == ClassKind.ParameterSubscriptionValueSet || - dto.ClassKind == ClassKind.ParameterOverrideValueSet).ToList(); + dto.ClassKind == ClassKind.ParameterSubscriptionValueSet || + dto.ClassKind == ClassKind.ParameterOverrideValueSet).ToList(); this.ComputeRoutes(valuesets, dtolist); var valueSetsClones = valuesets.Select(dto => dto.DeepClone()).ToList(); @@ -98,6 +103,7 @@ public OperationContainer CreateValueSetsUpdateOperations(string context, IEnume // value sets to update var copyValueSets = valueSetsClones.Where(x => copyDto.ValueSets.Contains(x.Iid)).ToList(); var defaultValueSet = this.GetDefaultValueSet(originalParameter); + if (defaultValueSet == null) { continue; @@ -107,6 +113,7 @@ public OperationContainer CreateValueSetsUpdateOperations(string context, IEnume } var operationContainer = new OperationContainer(context, topContainer.RevisionNumber); + foreach (var valueSetsClone in valueSetsClones) { var valuesetToUpdate = valuesets.Single(x => x.Iid == valueSetsClone.Iid); @@ -203,4 +210,4 @@ private void SetValueSetValues(Dto.ParameterSubscriptionValueSet valueSet, Param valueSet.ValueSwitch = originalValueSet.ValueSwitch; } } -} \ No newline at end of file +} diff --git a/CDP4ServicesMessaging.Tests/CDP4ServicesMessaging.Tests.csproj b/CDP4ServicesMessaging.Tests/CDP4ServicesMessaging.Tests.csproj index 2e36d34d6..5c382bcfd 100644 --- a/CDP4ServicesMessaging.Tests/CDP4ServicesMessaging.Tests.csproj +++ b/CDP4ServicesMessaging.Tests/CDP4ServicesMessaging.Tests.csproj @@ -10,7 +10,7 @@ - + diff --git a/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj b/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj index b8bb41d1d..c238e3485 100644 --- a/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj +++ b/CDP4ServicesMessaging/CDP4ServicesMessaging.csproj @@ -1,10 +1,10 @@ - + netstandard2.0 Starion Group S.A. CDP4Common Community Edition - 27.4.0 + 28.0.0 CDP4 Services Messaging is a Class Library that contains clients and messages class that can be used for inter services communication Copyright © Starion Group S.A. Sam, Alex, Alexander, Nathanael, Antoine @@ -20,7 +20,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json README.md latest @@ -37,10 +37,10 @@ - - - - + + + + diff --git a/CDP4ServicesMessaging/Serializers/Json/Cdp4MessageSerializer.cs b/CDP4ServicesMessaging/Serializers/Json/Cdp4MessageSerializer.cs index 0eeae0807..f251f9f8d 100644 --- a/CDP4ServicesMessaging/Serializers/Json/Cdp4MessageSerializer.cs +++ b/CDP4ServicesMessaging/Serializers/Json/Cdp4MessageSerializer.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2023 Starion Group S.A. +// Copyright (c) 2015-2024 Starion Group S.A. // // Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Antoine Théate, Nathanael Smiechowski // @@ -10,12 +10,12 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -27,13 +27,12 @@ namespace CDP4ServicesMessaging.Serializers.Json using System; using System.Diagnostics; using System.IO; - + using System.Text.Json; + using CDP4Common.MetaInfo; using CDP4JsonSerializer; - using Newtonsoft.Json; - using NLog; /// @@ -58,7 +57,7 @@ public Cdp4MessageSerializer() /// /// The public Cdp4MessageSerializer(IMetaDataProvider metaInfoProvider) : base(metaInfoProvider, metaInfoProvider.GetMaxSupportedModelVersion()) - { + { } /// @@ -70,27 +69,22 @@ public Cdp4MessageSerializer(IMetaDataProvider metaInfoProvider) : base(metaInfo public ReadOnlyMemory Serialize(T message) { var sw = Stopwatch.StartNew(); - var serializer = this.CreateJsonSerializer(); // Use a MemoryStream to store the serialized data using var memoryStream = new MemoryStream(); - Logger.Trace("initializing JsonTextWriter"); - using var jsonWriter = new JsonTextWriter(new StreamWriter(memoryStream)); - Logger.Trace("Serialize to JsonTextWriter"); - serializer.Serialize(jsonWriter, message); - jsonWriter.Flush(); + JsonSerializer.Serialize(memoryStream, message, this.JsonSerializerOptions); // Get the ReadOnlyMemory from the MemoryStream var serializedMessage = new ReadOnlyMemory(memoryStream.ToArray()); sw.Stop(); Logger.Debug("SerializeThingsChangedMessage finished in {0} [ms]", sw.ElapsedMilliseconds); - + return serializedMessage; } - + /// /// Deserializes a message of type from the specified . /// diff --git a/CDP4Web.Tests/CDP4Web.Tests.csproj b/CDP4Web.Tests/CDP4Web.Tests.csproj index 703657985..c6e80e872 100644 --- a/CDP4Web.Tests/CDP4Web.Tests.csproj +++ b/CDP4Web.Tests/CDP4Web.Tests.csproj @@ -15,8 +15,8 @@ - - + + diff --git a/CDP4Web/CDP4Web.csproj b/CDP4Web/CDP4Web.csproj index d81e648c9..4f6000a70 100644 --- a/CDP4Web/CDP4Web.csproj +++ b/CDP4Web/CDP4Web.csproj @@ -5,7 +5,7 @@ latest Starion Group S.A. CDP4Web Community Edition - 27.4.0 + 28.0.0 CDP4Web Dedicated Sdk for CDPServicesDal Copyright © Starion Group S.A. Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime @@ -21,8 +21,7 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 - [Update] to Microsoft.Extensions.Logging.Abstractions 8.0.2 + [Refactor] Newtonsoft to System.Text.Json README.md @@ -40,7 +39,7 @@ - + diff --git a/CDP4WspDal.NetCore.Tests/CDP4WspDal.NetCore.Tests.csproj b/CDP4WspDal.NetCore.Tests/CDP4WspDal.NetCore.Tests.csproj index 0edea0745..582140888 100644 --- a/CDP4WspDal.NetCore.Tests/CDP4WspDal.NetCore.Tests.csproj +++ b/CDP4WspDal.NetCore.Tests/CDP4WspDal.NetCore.Tests.csproj @@ -18,7 +18,7 @@ - + diff --git a/CDP4WspDal.NetCore.Tests/CopyOperationHandlerTestFixture.cs b/CDP4WspDal.NetCore.Tests/CopyOperationHandlerTestFixture.cs index af924e2ad..fee5c8609 100644 --- a/CDP4WspDal.NetCore.Tests/CopyOperationHandlerTestFixture.cs +++ b/CDP4WspDal.NetCore.Tests/CopyOperationHandlerTestFixture.cs @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests { @@ -36,6 +36,8 @@ namespace CDP4WspDal.Tests using CDP4Dal.Operations; using CDP4Dal.Permission; + using CDP4DalCommon.Protocol.Operations; + using Moq; using NUnit.Framework; diff --git a/CDP4WspDal.NetCore.Tests/OperationModifierTestFixture.cs b/CDP4WspDal.NetCore.Tests/OperationModifierTestFixture.cs index 763490580..87cb0f197 100644 --- a/CDP4WspDal.NetCore.Tests/OperationModifierTestFixture.cs +++ b/CDP4WspDal.NetCore.Tests/OperationModifierTestFixture.cs @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests { @@ -34,6 +34,8 @@ namespace CDP4WspDal.Tests using CDP4Dal; using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using Moq; using NUnit.Framework; diff --git a/CDP4WspDal.NetCore.Tests/Operations/WSPPostOperationTestFixture.cs b/CDP4WspDal.NetCore.Tests/Operations/WSPPostOperationTestFixture.cs index 02ebbedf0..65eda2928 100644 --- a/CDP4WspDal.NetCore.Tests/Operations/WSPPostOperationTestFixture.cs +++ b/CDP4WspDal.NetCore.Tests/Operations/WSPPostOperationTestFixture.cs @@ -1,7 +1,6 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 Starion Group S.A. +// Copyright (c) 2015-2024 Starion Group S.A. // // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou // @@ -11,30 +10,29 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests.Operations { using System; using System.Collections; - using System.Collections.Generic; using System.Linq; + using CDP4Common.DTO; - using CDP4Common.MetaInfo; + using CDP4Common.MetaInfo; using CDP4Common.Types; - using CDP4Dal.Operations; - using CDP4WspDal; + + using CDP4DalCommon.Protocol.Operations; using NUnit.Framework; @@ -101,7 +99,7 @@ public void VerifyThatExceptionIsThrownWhenModifiedThingIsNotProvided() { var simpleUnit = new SimpleUnit(Guid.NewGuid(), 1); var operation = new Operation(simpleUnit, null, OperationKind.Delete); - Assert.Throws(() => this.wspPostOperation.ConstructFromOperation(operation)) ; + Assert.Throws(() => this.wspPostOperation.ConstructFromOperation(operation)); } [Test] diff --git a/CDP4WspDal.NetCore.Tests/PostOperationTestFixture.cs b/CDP4WspDal.NetCore.Tests/PostOperationTestFixture.cs index b6a7815e2..06a7118f6 100644 --- a/CDP4WspDal.NetCore.Tests/PostOperationTestFixture.cs +++ b/CDP4WspDal.NetCore.Tests/PostOperationTestFixture.cs @@ -1,6 +1,6 @@ // -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 Starion Group S.A. +// Copyright (c) 2015-2024 Starion Group S.A. // // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Yevhen Ikonnykov // @@ -10,52 +10,61 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests { using System; using System.Collections.Generic; using System.IO; + using CDP4Common; + using CDP4Common.CommonData; using CDP4Common.Dto; + using CDP4Common.DTO; using CDP4Common.MetaInfo; - using CDP4JsonSerializer; + using CDP4Common.Types; + using CDP4Dal.Operations; + + using CDP4DalCommon.Protocol.Operations; + + using CDP4JsonSerializer; + using CDP4WspDal.Tests.Helper; - using Newtonsoft.Json; + using NUnit.Framework; - using CDP4Common.DTO; - using CDP4Common.CommonData; - using CDP4Common.Types; + using File = System.IO.File; + using Thing = CDP4Common.DTO.Thing; [TestFixture] public class PostOperationTestFixture { - private Cdp4JsonSerializer serializer; + private Cdp4DalJsonSerializer serializer; [SetUp] public void Setup() { var metamodel = new MetaDataProvider(); - this.serializer = new Cdp4JsonSerializer(metamodel, new Version(1, 1, 0)); + this.serializer = new Cdp4DalJsonSerializer(metamodel, new Version(1, 1, 0), true); } [Test] public void Verify_that_deserialization_of_Post_Operation_does_not_throw_an_exception() { var response = File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData/PostOperation.json")); + using (var stream = StreamHelper.GenerateStreamFromString(response)) { Assert.DoesNotThrow(() => this.serializer.Deserialize(stream)); @@ -93,7 +102,7 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( var fileRevision = new FileRevision(fileRevisionIid, 0); fileRevision.Name = "testfile"; fileRevision.ContentHash = "F73747371CFD9473C19A0A7F99BCAB008474C4CA"; - fileRevision.FileType.Add(new OrderedItem() { K = 1, V = fileTypeIid }); + fileRevision.FileType.Add(new OrderedItem { K = 1, V = fileTypeIid }); fileRevision.Creator = participantIid; fileRevision.AddContainer(ClassKind.File, fileIid); fileRevision.AddContainer(ClassKind.DomainFileStore, domainFileStoreIid); @@ -101,7 +110,7 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( fileRevision.AddContainer(ClassKind.EngineeringModel, engineeringModelIid); var context = $"/EngineeringModel/{engineeringModelIid}/iteration/{iterationIid}"; - var operationContainer = new OperationContainer(context, null); + var operationContainer = new OperationContainer(context); var updateCommonFileStoreOperation = new Operation(originalDomainFileStore, modifiedDomainFileStore, OperationKind.Update); operationContainer.AddOperation(updateCommonFileStoreOperation); @@ -131,34 +140,6 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( private class TestPostOperation : PostOperation { - public override void ConstructFromOperation(Operation operation) - { - throw new NotImplementedException(); - } - - /// - /// Gets or sets the collection of DTOs to delete. - /// - [JsonProperty("_delete")] - public override List Delete { get; set; } - - /// - /// Gets or sets the collection of DTOs to create. - /// - [JsonProperty("_create")] - public override List Create { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - [JsonProperty("_update")] - public override List Update { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - [JsonProperty("_copy")] - public override List Copy { get; set; } } } } diff --git a/CDP4WspDal.NetCore.Tests/WSPDalTestFixture.cs b/CDP4WspDal.NetCore.Tests/WSPDalTestFixture.cs index 07a217f13..b7cac6f05 100644 --- a/CDP4WspDal.NetCore.Tests/WSPDalTestFixture.cs +++ b/CDP4WspDal.NetCore.Tests/WSPDalTestFixture.cs @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests { @@ -45,6 +45,8 @@ namespace CDP4WspDal.Tests using CDP4Dal.DAL.ECSS1025AnnexC; using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; /// diff --git a/CDP4WspDal.Tests/CDP4WspDal.Tests.csproj b/CDP4WspDal.Tests/CDP4WspDal.Tests.csproj index a90610895..e8c4b5fe2 100644 --- a/CDP4WspDal.Tests/CDP4WspDal.Tests.csproj +++ b/CDP4WspDal.Tests/CDP4WspDal.Tests.csproj @@ -23,7 +23,7 @@ - + diff --git a/CDP4WspDal.Tests/CopyOperationHandlerTestFixture.cs b/CDP4WspDal.Tests/CopyOperationHandlerTestFixture.cs index 6f5924b70..a93fbf98e 100644 --- a/CDP4WspDal.Tests/CopyOperationHandlerTestFixture.cs +++ b/CDP4WspDal.Tests/CopyOperationHandlerTestFixture.cs @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests { @@ -36,6 +36,8 @@ namespace CDP4WspDal.Tests using CDP4Dal.Operations; using CDP4Dal.Permission; + using CDP4DalCommon.Protocol.Operations; + using Moq; using NUnit.Framework; diff --git a/CDP4WspDal.Tests/OperationModifierTestFixture.cs b/CDP4WspDal.Tests/OperationModifierTestFixture.cs index 73b00ea97..506cebbc1 100644 --- a/CDP4WspDal.Tests/OperationModifierTestFixture.cs +++ b/CDP4WspDal.Tests/OperationModifierTestFixture.cs @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests { @@ -34,6 +34,8 @@ namespace CDP4WspDal.Tests using CDP4Dal; using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using Moq; using NUnit.Framework; diff --git a/CDP4WspDal.Tests/Operations/WSPPostOperationTestFixture.cs b/CDP4WspDal.Tests/Operations/WSPPostOperationTestFixture.cs index 02ebbedf0..c35b7fa69 100644 --- a/CDP4WspDal.Tests/Operations/WSPPostOperationTestFixture.cs +++ b/CDP4WspDal.Tests/Operations/WSPPostOperationTestFixture.cs @@ -1,7 +1,6 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 Starion Group S.A. +// Copyright (c) 2015-2024 Starion Group S.A. // // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou // @@ -11,30 +10,29 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // -------------------------------------------------------------------------------------------------------------------- -#endregion namespace CDP4WspDal.Tests.Operations { using System; using System.Collections; - using System.Collections.Generic; using System.Linq; + using CDP4Common.DTO; - using CDP4Common.MetaInfo; + using CDP4Common.MetaInfo; using CDP4Common.Types; - using CDP4Dal.Operations; - using CDP4WspDal; + + using CDP4DalCommon.Protocol.Operations; using NUnit.Framework; @@ -101,7 +99,7 @@ public void VerifyThatExceptionIsThrownWhenModifiedThingIsNotProvided() { var simpleUnit = new SimpleUnit(Guid.NewGuid(), 1); var operation = new Operation(simpleUnit, null, OperationKind.Delete); - Assert.Throws(() => this.wspPostOperation.ConstructFromOperation(operation)) ; + Assert.Throws(() => this.wspPostOperation.ConstructFromOperation(operation)); } [Test] diff --git a/CDP4WspDal.Tests/PostOperationTestFixture.cs b/CDP4WspDal.Tests/PostOperationTestFixture.cs index 56047dfe1..06a7118f6 100644 --- a/CDP4WspDal.Tests/PostOperationTestFixture.cs +++ b/CDP4WspDal.Tests/PostOperationTestFixture.cs @@ -1,6 +1,6 @@ // -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 Starion Group S.A. +// Copyright (c) 2015-2024 Starion Group S.A. // // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Yevhen Ikonnykov // @@ -10,52 +10,61 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests { using System; using System.Collections.Generic; using System.IO; + using CDP4Common; + using CDP4Common.CommonData; using CDP4Common.Dto; using CDP4Common.DTO; using CDP4Common.MetaInfo; - using CDP4JsonSerializer; + using CDP4Common.Types; + using CDP4Dal.Operations; + + using CDP4DalCommon.Protocol.Operations; + + using CDP4JsonSerializer; + using CDP4WspDal.Tests.Helper; - using Newtonsoft.Json; + using NUnit.Framework; - using CDP4Common.Types; + using File = System.IO.File; - using CDP4Common.CommonData; + using Thing = CDP4Common.DTO.Thing; [TestFixture] public class PostOperationTestFixture { - private Cdp4JsonSerializer serializer; + private Cdp4DalJsonSerializer serializer; [SetUp] public void Setup() { var metamodel = new MetaDataProvider(); - this.serializer = new Cdp4JsonSerializer(metamodel, new Version(1, 1, 0)); + this.serializer = new Cdp4DalJsonSerializer(metamodel, new Version(1, 1, 0), true); } [Test] public void Verify_that_deserialization_of_Post_Operation_does_not_throw_an_exception() { var response = File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData/PostOperation.json")); + using (var stream = StreamHelper.GenerateStreamFromString(response)) { Assert.DoesNotThrow(() => this.serializer.Deserialize(stream)); @@ -93,7 +102,7 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( var fileRevision = new FileRevision(fileRevisionIid, 0); fileRevision.Name = "testfile"; fileRevision.ContentHash = "F73747371CFD9473C19A0A7F99BCAB008474C4CA"; - fileRevision.FileType.Add(new OrderedItem() { K = 1, V = fileTypeIid }); + fileRevision.FileType.Add(new OrderedItem { K = 1, V = fileTypeIid }); fileRevision.Creator = participantIid; fileRevision.AddContainer(ClassKind.File, fileIid); fileRevision.AddContainer(ClassKind.DomainFileStore, domainFileStoreIid); @@ -101,7 +110,7 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( fileRevision.AddContainer(ClassKind.EngineeringModel, engineeringModelIid); var context = $"/EngineeringModel/{engineeringModelIid}/iteration/{iterationIid}"; - var operationContainer = new OperationContainer(context, null); + var operationContainer = new OperationContainer(context); var updateCommonFileStoreOperation = new Operation(originalDomainFileStore, modifiedDomainFileStore, OperationKind.Update); operationContainer.AddOperation(updateCommonFileStoreOperation); @@ -128,36 +137,9 @@ public void Verify_that_serialization_of_Post_Operation_returns_expected_result( Assert.That(streamReader.ReadToEnd(), Is.EqualTo(expected)); } } + private class TestPostOperation : PostOperation { - public override void ConstructFromOperation(Operation operation) - { - throw new NotImplementedException(); - } - - /// - /// Gets or sets the collection of DTOs to delete. - /// - [JsonProperty("_delete")] - public override List Delete { get; set; } - - /// - /// Gets or sets the collection of DTOs to create. - /// - [JsonProperty("_create")] - public override List Create { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - [JsonProperty("_update")] - public override List Update { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - [JsonProperty("_copy")] - public override List Copy { get; set; } } } } diff --git a/CDP4WspDal.Tests/WSPDalTestFixture.cs b/CDP4WspDal.Tests/WSPDalTestFixture.cs index 43857f18a..8aef3f061 100644 --- a/CDP4WspDal.Tests/WSPDalTestFixture.cs +++ b/CDP4WspDal.Tests/WSPDalTestFixture.cs @@ -20,7 +20,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal.Tests { @@ -45,6 +45,8 @@ namespace CDP4WspDal.Tests using CDP4Dal.DAL.ECSS1025AnnexC; using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using NUnit.Framework; /// diff --git a/CDP4WspDal/CDP4WspDal.csproj b/CDP4WspDal/CDP4WspDal.csproj index 19325e3d0..6de44c4e3 100644 --- a/CDP4WspDal/CDP4WspDal.csproj +++ b/CDP4WspDal/CDP4WspDal.csproj @@ -4,7 +4,7 @@ net48;netstandard2.0 Starion Group S.A. CDP4WspDal Community Edition - 27.4.0 + 28.0.0 CDP4 WSP Dal Plugin Copyright © Starion Group S.A. Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael @@ -20,13 +20,13 @@ CDP COMET ECSS-E-TM-10-25 LGPL-3.0-only - [BUMP] To CDP4Common 27.4.0 + [Refactor] Newtonsoft to System.Text.Json README.md - + @@ -41,8 +41,8 @@ - + diff --git a/CDP4WspDal/CopyOperationHandler.cs b/CDP4WspDal/CopyOperationHandler.cs index 49a6190d8..95647049e 100644 --- a/CDP4WspDal/CopyOperationHandler.cs +++ b/CDP4WspDal/CopyOperationHandler.cs @@ -1,7 +1,6 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 Starion Group S.A. +// Copyright (c) 2015-2024 Starion Group S.A. // // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou // @@ -11,18 +10,17 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal { @@ -30,11 +28,16 @@ namespace CDP4WspDal using System.Collections.Generic; using System.Linq; using System.Reflection; + using CDP4Common.CommonData; using CDP4Common.EngineeringModelData; + using CDP4Dal; using CDP4Dal.Operations; using CDP4Dal.Permission; + + using CDP4DalCommon.Protocol.Operations; + using Poco = CDP4Common.CommonData.Thing; /// @@ -53,7 +56,7 @@ internal class CopyOperationHandler private readonly ISession session; /// - /// A that map the original to the copied version + /// A that map the original to the copied version /// private Dictionary copyThingMap; @@ -82,7 +85,7 @@ public CopyOperationHandler(ISession session) public IReadOnlyDictionary CopyThingMap { get { return this.copyThingMap; } - } + } /// /// Modify the if it contains copy @@ -93,6 +96,7 @@ public void ModifiedCopyOperation(OperationContainer operationContainer) var operationsToAdd = new List(); var copyOperationCount = operationContainer.Operations.Count(x => x.OperationKind.IsCopyOperation()); + if (copyOperationCount > 1) { // TODO: support this if needed @@ -100,6 +104,7 @@ public void ModifiedCopyOperation(OperationContainer operationContainer) } var copyOperation = operationContainer.Operations.SingleOrDefault(x => x.OperationKind.IsCopyOperation()); + if (copyOperation == null) { return; @@ -140,7 +145,7 @@ private void ComputeOperations(Operation copyOperation) var originalDto = copyOperation.OriginalThing; var originalPoco = originalDto.QuerySourceThing(); - + if (copyPoco.TopContainer.ClassKind != ClassKind.EngineeringModel) { throw new InvalidOperationException("The copy operation on WSP is only implemented for things contained by EngineeringModel."); @@ -154,6 +159,7 @@ private void ComputeOperations(Operation copyOperation) // Add all contained objects this.copyableIds.AddRange(copyPermissionResult.CopyableThings.Select(c => c.Iid).ToList()); + if (this.copyableIds.Contains(originalPoco.Iid)) { var updatedIteration = copyPoco.GetContainerOfType(); @@ -162,6 +168,7 @@ private void ComputeOperations(Operation copyOperation) // modify the references to point to the copy thing this.ModifyReferences(); + if (copyOperation.OperationKind.IsCopyChangeOwnerOperation()) { this.ChangeOwner(updatedIteration); @@ -207,6 +214,7 @@ private void CreatePocoCopy(Poco poco, Iteration targetIteration) foreach (var containerList in poco.ContainerLists) { var updatedContainerList = new List(); + foreach (Poco containedPoco in containerList) { if (!this.copyableIds.Contains(containedPoco.Iid)) @@ -265,6 +273,7 @@ private void CreateOperations() } #region Modify References + /// /// Modify the references for a and all its contained elements /// @@ -310,6 +319,7 @@ private void ModifyReferences(ElementUsage usage) private void ModifyReferences(Parameter parameter) { parameter.StateDependence = null; + if (parameter.Group == null) { return; @@ -318,6 +328,7 @@ private void ModifyReferences(Parameter parameter) // if the group cannot be copied, set to null Poco groupCopy; this.copyThingMap.TryGetValue(parameter.Group, out groupCopy); + parameter.Group = this.copyThingMap.TryGetValue(parameter.Group, out groupCopy) ? (ParameterGroup)groupCopy : null; @@ -337,6 +348,7 @@ private void ModifyReferences(ParameterGroup group) // if the group cannot be copied, set to null Poco groupCopy; this.copyThingMap.TryGetValue(group.ContainingGroup, out groupCopy); + group.ContainingGroup = this.copyThingMap.TryGetValue(group.ContainingGroup, out groupCopy) ? (ParameterGroup)groupCopy : null; @@ -352,6 +364,7 @@ private void ModifyReferences(ParameterOverride parameterOverride) var copy = (Parameter)this.copyThingMap[parameterOverride.Parameter]; parameterOverride.Parameter = copy; } + #endregion /// @@ -361,12 +374,14 @@ private void ModifyReferences(ParameterOverride parameterOverride) private void ChangeOwner(Iteration iteration) { var activeDomain = this.session.OpenIterations.Single(x => x.Key.Iid == iteration.Iid).Value.Item1; + if (activeDomain == null) { throw new InvalidOperationException("The active domain is null. The copy operation cannot be performed."); } var ownedThings = this.copyThingMap.Values.OfType().ToList(); + foreach (var ownedThing in ownedThings) { // the owner of a subscription shall not be set to the active one @@ -379,4 +394,4 @@ private void ChangeOwner(Iteration iteration) } } } -} \ No newline at end of file +} diff --git a/CDP4WspDal/OperationModifier.cs b/CDP4WspDal/OperationModifier.cs index 2e763ef75..74aaed9df 100644 --- a/CDP4WspDal/OperationModifier.cs +++ b/CDP4WspDal/OperationModifier.cs @@ -1,6 +1,6 @@ // -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 Starion Group S.A. +// Copyright (c) 2015-2024 Starion Group S.A. // // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou // @@ -10,29 +10,33 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal { using System; using System.Collections.Generic; using System.Linq; + using CDP4Common.CommonData; - using CDP4Common.EngineeringModelData; + using CDP4Common.EngineeringModelData; using CDP4Common.Types; + using CDP4Dal; using CDP4Dal.Operations; + using CDP4DalCommon.Protocol.Operations; + using ActualFiniteState = CDP4Common.DTO.ActualFiniteState; using ElementUsage = CDP4Common.DTO.ElementUsage; using ParameterOverride = CDP4Common.DTO.ParameterOverride; @@ -72,6 +76,7 @@ public void ModifyOperationContainer(OperationContainer operationContainer) if (operation.OperationKind == OperationKind.Create) { var parameterOverride = operation.ModifiedThing as ParameterOverride; + if (parameterOverride != null) { operationsToAdd.AddRange(this.AddParameterSubscriptionCreateOperation(operationContainer, parameterOverride)); @@ -80,6 +85,7 @@ public void ModifyOperationContainer(OperationContainer operationContainer) else if (operation.OperationKind == OperationKind.Update) { var possibleStateList = operation.ModifiedThing as PossibleFiniteStateList; + if (possibleStateList != null) { operationsToAdd.AddRange(this.ModifyActualStateKindOnDefaultPossibleStateUpdate(possibleStateList)); @@ -90,7 +96,7 @@ public void ModifyOperationContainer(OperationContainer operationContainer) foreach (var operation in operationsToAdd) { operationContainer.AddOperation(operation); - } + } } /// @@ -104,12 +110,14 @@ private IEnumerable AddParameterSubscriptionCreateOperation(Operation var parameterId = parameterOverride.Parameter; Lazy lazyParameter; var operations = new List(); + if (!this.session.Assembler.Cache.TryGetValue(new CacheKey(parameterId, parameterOverride.IterationContainerId), out lazyParameter)) { return operations; } - + var parameter = (Parameter)lazyParameter.Value; + foreach (var subscription in parameter.ParameterSubscription.Where(x => x.Owner.Iid != parameterOverride.Owner)) { var parameterSubscription = new ParameterSubscription @@ -123,13 +131,14 @@ private IEnumerable AddParameterSubscriptionCreateOperation(Operation operationContainer.Operations.Select(x => x.ModifiedThing) .OfType() .SingleOrDefault(x => x.ParameterOverride.Contains(parameterOverride.Iid)); - + if (elementUsageContainer == null) { continue; } Lazy lazyElementUsageContainer; + if (!this.session.Assembler.Cache.TryGetValue(new CacheKey(elementUsageContainer.Iid, elementUsageContainer.IterationContainerId), out lazyElementUsageContainer)) { continue; @@ -166,6 +175,7 @@ private IEnumerable ModifyActualStateKindOnDefaultPossibleStateUpdate { var operations = new List(); var defaultStateId = possibleFiniteStateList.DefaultState; + if (!defaultStateId.HasValue) { return operations; @@ -173,14 +183,15 @@ private IEnumerable ModifyActualStateKindOnDefaultPossibleStateUpdate // gets the actualList that uses the updated possible list var actualLists = this.session.Assembler.Cache.Select(x => x.Value) - .Select(x => x.Value) - .OfType() - .Where(x => x.PossibleFiniteStateList.Select(pl => pl.Iid).Contains(possibleFiniteStateList.Iid)) - .ToList(); + .Select(x => x.Value) + .OfType() + .Where(x => x.PossibleFiniteStateList.Select(pl => pl.Iid).Contains(possibleFiniteStateList.Iid)) + .ToList(); foreach (var actualFiniteStateList in actualLists) { var possibleLists = actualFiniteStateList.PossibleFiniteStateList.Where(x => x.Iid != possibleFiniteStateList.Iid).ToList(); + if (possibleLists.Any(x => x.DefaultState == null)) { // one of the possible list has no default state @@ -212,4 +223,4 @@ private IEnumerable ModifyActualStateKindOnDefaultPossibleStateUpdate return operations; } } -} \ No newline at end of file +} diff --git a/CDP4WspDal/ValueSetOperationCreator.cs b/CDP4WspDal/ValueSetOperationCreator.cs index ee1c1545e..6fa466b67 100644 --- a/CDP4WspDal/ValueSetOperationCreator.cs +++ b/CDP4WspDal/ValueSetOperationCreator.cs @@ -1,7 +1,6 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 Starion Group S.A. +// Copyright (c) 2015-2024 Starion Group S.A. // // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou // @@ -11,28 +10,32 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal { using System; using System.Collections.Generic; using System.Linq; + using CDP4Common.CommonData; - using CDP4Common.EngineeringModelData; + using CDP4Common.EngineeringModelData; + using CDP4Dal; using CDP4Dal.Operations; + + using CDP4DalCommon.Protocol.Operations; + using Dto = CDP4Common.DTO; /// @@ -44,7 +47,7 @@ internal class ValueSetOperationCreator /// The associated /// private readonly ISession session; - + /// /// Initializes a new instance of the class /// @@ -70,6 +73,7 @@ public OperationContainer CreateValueSetsUpdateOperations(string context, IEnume var dtolist = dtos.ToList(); var topContainer = dtolist.SingleOrDefault(x => x is Dto.TopContainer); + if (topContainer == null) { throw new InvalidOperationException("No Top container were found in the returned list of dtos."); @@ -78,9 +82,10 @@ public OperationContainer CreateValueSetsUpdateOperations(string context, IEnume // Gets the parameter base which value set shall be updated var copyParameterBases = dtolist.OfType().ToList(); var copyParameterBasesIds = copyParameterBases.Select(p => p.Iid).ToList(); - var valuesets = dtolist.Where(dto => dto.ClassKind == ClassKind.ParameterValueSet || - dto.ClassKind == ClassKind.ParameterSubscriptionValueSet || - dto.ClassKind == ClassKind.ParameterOverrideValueSet).ToList(); + + var valuesets = dtolist.Where(dto => dto.ClassKind == ClassKind.ParameterValueSet || + dto.ClassKind == ClassKind.ParameterSubscriptionValueSet || + dto.ClassKind == ClassKind.ParameterOverrideValueSet).ToList(); this.ComputeRoutes(valuesets, dtolist); var valueSetsClones = valuesets.Select(dto => dto.DeepClone()).ToList(); @@ -98,6 +103,7 @@ public OperationContainer CreateValueSetsUpdateOperations(string context, IEnume // value sets to update var copyValueSets = valueSetsClones.Where(x => copyDto.ValueSets.Contains(x.Iid)).ToList(); var defaultValueSet = this.GetDefaultValueSet(originalParameter); + if (defaultValueSet == null) { continue; @@ -105,8 +111,9 @@ public OperationContainer CreateValueSetsUpdateOperations(string context, IEnume this.SetValueSetValues(copyValueSets, defaultValueSet); } - + var operationContainer = new OperationContainer(context, topContainer.RevisionNumber); + foreach (var valueSetsClone in valueSetsClones) { var valuesetToUpdate = valuesets.Single(x => x.Iid == valueSetsClone.Iid); @@ -203,4 +210,4 @@ private void SetValueSetValues(Dto.ParameterSubscriptionValueSet valueSet, Param valueSet.ValueSwitch = originalValueSet.ValueSwitch; } } -} \ No newline at end of file +} diff --git a/CDP4WspDal/WSPDal.cs b/CDP4WspDal/WSPDal.cs index 2bdf168a9..e704a89b4 100644 --- a/CDP4WspDal/WSPDal.cs +++ b/CDP4WspDal/WSPDal.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2021 Starion Group S.A. +// Copyright (c) 2015-2024 Starion Group S.A. // // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexandervan Delft, Nathanael Smiechowski, Ahmed Abulwafa Ahmed // @@ -10,12 +10,12 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The COMET-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -27,7 +27,6 @@ namespace CDP4WspDal #if NETFRAMEWORK using System.ComponentModel.Composition; #endif - using System; using System.Collections.Generic; using System.Diagnostics; @@ -50,10 +49,11 @@ namespace CDP4WspDal using CDP4Dal.Exceptions; using CDP4Dal.Operations; - using CDP4DalCommon.Tasks; + using CDP4DalCommon.Protocol.Operations; + using CDP4DalCommon.Protocol.Tasks; using CDP4JsonSerializer; - + using NLog; using EngineeringModelSetup = CDP4Common.SiteDirectoryData.EngineeringModelSetup; @@ -83,13 +83,13 @@ public class WspDal : Dal /// public WspDal() { - this.Serializer = new Cdp4JsonSerializer(this.MetaDataProvider, this.DalVersion); + this.Cdp4DalJsonSerializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion, true); } /// - /// Gets or sets the + /// Gets or sets the /// - public Cdp4JsonSerializer Serializer { get; private set; } + public Cdp4DalJsonSerializer Cdp4DalJsonSerializer { get; private set; } /// /// Gets the value indicating whether this is read only @@ -131,7 +131,7 @@ public override async Task> Write(OperationContainer operatio var watch = Stopwatch.StartNew(); - var hasCopyValuesOperations = operationContainer.Operations.Any(op => OperationKindExtensions.IsCopyKeepOriginalValuesOperation(op.OperationKind)); + var hasCopyValuesOperations = operationContainer.Operations.Any(op => op.OperationKind.IsCopyKeepOriginalValuesOperation()); var modifier = new OperationModifier(this.Session); var copyHandler = new CopyOperationHandler(this.Session); @@ -140,18 +140,19 @@ public override async Task> Write(OperationContainer operatio modifier.ModifyOperationContainer(operationContainer); var invalidOperationKind = operationContainer.Operations.Any(operation => operation.OperationKind == OperationKind.Move || OperationKindExtensions.IsCopyOperation(operation.OperationKind)); + if (invalidOperationKind) { throw new InvalidOperationKindException("The WSP DAL does not support Copy or Move operations"); } - + var result = new List(); if (files != null && files.Any()) { this.OperationContainerFileVerification(operationContainer, files); } - + var attribute = new QueryAttributes { RevisionNumber = operationContainer.TopContainerRevisionNumber @@ -180,12 +181,13 @@ public override async Task> Write(OperationContainer operatio Logger.Error(msg); throw new DalWriteException(msg); } - + using (var resultStream = await httpResponseMessage.Content.ReadAsStreamAsync()) { - result.AddRange(this.Serializer.Deserialize(resultStream)); + result.AddRange(this.Cdp4DalJsonSerializer.Deserialize(resultStream)); Guid iterationId; + if (this.TryExtractIterationIdfromUri(httpResponseMessage.RequestMessage.RequestUri, out iterationId)) { this.SetIterationContainer(result, iterationId); @@ -204,6 +206,7 @@ public override async Task> Write(OperationContainer operatio foreach (var valueSetDto in valueSetResult) { var index = result.FindIndex(x => x.Iid == valueSetDto.Iid); + if (index >= 0) { result[index] = valueSetDto; @@ -282,6 +285,7 @@ public override async Task> Read(CDP4Common.DTO.Iteration ite // Get the RequiredRdl to load var siteDirectory = this.Session.Assembler.RetrieveSiteDirectory(); var iterationSetup = siteDirectory.Model.SelectMany(mod => mod.IterationSetup).SingleOrDefault(it => it.IterationIid == iteration.Iid); + if (iterationSetup == null) { throw new InvalidOperationException("The Iteration to open does not have any associated IterationSetup."); @@ -401,12 +405,13 @@ public override async Task> Read(T thing, CancellationToke Logger.Error(msg); throw new DalReadException(msg); } - + using (var resultStream = await httpResponseMessage.Content.ReadAsStreamAsync()) { - var returned = this.Serializer.Deserialize(resultStream); + var returned = this.Cdp4DalJsonSerializer.Deserialize(resultStream); Guid iterationId; + if (this.TryExtractIterationIdfromUri(httpResponseMessage.RequestMessage.RequestUri, out iterationId)) { this.SetIterationContainer(returned, iterationId); @@ -419,7 +424,7 @@ public override async Task> Read(T thing, CancellationToke } } } - + /// /// Reads the identified by the provided /// @@ -529,9 +534,9 @@ public override async Task> Open(Credentials credentials, Can var openToken = CDP4Common.Helpers.TokenGenerator.GenerateRandomToken(); this.httpClient = this.CreateHttpClient(credentials); - + var watch = Stopwatch.StartNew(); - + var uriBuilder = this.GetUriBuilder(credentials.Uri, ref resourcePath); Logger.Debug("Resource Path {0}: {1}", openToken, resourcePath); @@ -543,7 +548,7 @@ public override async Task> Open(Credentials credentials, Can { Logger.Info("The ECSS-E-TM-10-25A Annex C Services responded in {0} [ms] to Open {1}", requestsw.ElapsedMilliseconds, openToken); requestsw.Stop(); - + if (httpResponseMessage.StatusCode != HttpStatusCode.OK) { var msg = $"The data-source replied with code {httpResponseMessage.StatusCode}: {httpResponseMessage.ReasonPhrase}"; @@ -553,17 +558,18 @@ public override async Task> Open(Credentials credentials, Can watch.Stop(); Logger.Info("WSP DAL Open {0} completed in {1} [ms]", openToken, watch.ElapsedMilliseconds); - + watch = Stopwatch.StartNew(); using (var resultStream = await httpResponseMessage.Content.ReadAsStreamAsync()) { - var returned = this.Serializer.Deserialize(resultStream); + var returned = this.Cdp4DalJsonSerializer.Deserialize(resultStream); watch.Stop(); Logger.Info("JSON Deserializer completed in {0} [ms]", watch.ElapsedMilliseconds); var returnedPerson = returned.OfType().SingleOrDefault(x => x.ShortName == credentials.UserName); + if (returnedPerson == null) { throw new InvalidOperationException("User not found."); @@ -700,7 +706,7 @@ internal void ConstructPostRequestBodyStream(string token, OperationContainer op postOperation.ConstructFromOperation(operation); } - this.Serializer.SerializeToStream(postOperation, outputStream); + this.Cdp4DalJsonSerializer.SerializeToStream(postOperation, outputStream); outputStream.Position = 0; if (Logger.IsTraceEnabled) @@ -709,6 +715,7 @@ internal void ConstructPostRequestBodyStream(string token, OperationContainer op { outputStream.CopyTo(memoryStream); memoryStream.Position = 0; + using (var streamReader = new StreamReader(memoryStream)) { var postBody = streamReader.ReadToEnd(); @@ -763,6 +770,7 @@ public override bool IsValidUri(string uri) try { var validUriAssertion = new Uri(uri); + if (!(validUriAssertion.Scheme == Uri.UriSchemeHttp || validUriAssertion.Scheme == Uri.UriSchemeHttps)) { return false; @@ -814,6 +822,6 @@ private IQueryAttributes GetIUriQueryAttribute(bool includeReferenceData = false Extent = ExtentQueryAttribute.deep, IncludeAllContainers = true }; - } + } } } diff --git a/CDP4WspDal/WSPPostOperation.cs b/CDP4WspDal/WSPPostOperation.cs index 91de411ed..c5c170d97 100644 --- a/CDP4WspDal/WSPPostOperation.cs +++ b/CDP4WspDal/WSPPostOperation.cs @@ -1,7 +1,6 @@ -#region Copyright -// -------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2015-2019 Starion Group S.A. +// Copyright (c) 2015-2024 Starion Group S.A. // // Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou // @@ -11,18 +10,17 @@ // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. -// -// The CDP4-SDK Community Edition is distributed in the hope that it will be useful, +// +// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // -// -------------------------------------------------------------------------------------------------------------------- -#endregion +// ------------------------------------------------------------------------------------------------------------------------------- namespace CDP4WspDal { @@ -30,15 +28,16 @@ namespace CDP4WspDal using System.Collections; using System.Collections.Generic; using System.Linq; + using CDP4Common; using CDP4Common.CommonData; using CDP4Common.Dto; using CDP4Common.MetaInfo; using CDP4Common.SiteDirectoryData; using CDP4Common.Types; - using CDP4Dal.Operations; - using Newtonsoft.Json; - using DomainOfExpertise = CDP4Common.DTO.DomainOfExpertise; + + using CDP4DalCommon.Protocol.Operations; + using Thing = CDP4Common.DTO.Thing; /// @@ -60,30 +59,6 @@ public WspPostOperation(IMetaDataProvider metaDataProvider) this.metaDataProvider = metaDataProvider; } - /// - /// Gets or sets the collection of DTOs to delete. - /// - [JsonProperty("_delete")] - public override List Delete { get; set; } - - /// - /// Gets or sets the collection of DTOs to create. - /// - [JsonProperty("_create")] - public override List Create { get; set; } - - /// - /// Gets or sets the collection of DTOs to update. - /// - [JsonProperty("_update")] - public override List Update { get; set; } - - /// - /// Gets or sets the collection of DTOs to copy. - /// - [JsonIgnore] - public override List Copy { get; set; } - /// /// Populate this with the correct setup for the OCDT protocol /// @@ -94,7 +69,7 @@ public override void ConstructFromOperation(Operation operation) { if (operation.ModifiedThing == null) { - throw new ArgumentNullException("operation"); + throw new ArgumentNullException(nameof(operation)); } if (operation.OperationKind == OperationKind.Update && operation.OriginalThing == null) @@ -139,6 +114,7 @@ private void ResolveUpdate(Operation operation) foreach (var key in original.Keys) { var originalIenumerable = original[key] as IEnumerable; + if (originalIenumerable != null && originalIenumerable.GetType().IsGenericType) { var modifiedIenumerable = (IEnumerable)modifiedFull[key]; @@ -162,6 +138,7 @@ private void ResolveUpdate(Operation operation) List modifiedProperty; var genericTypeArgument = original[key].GetType().GenericTypeArguments[0]; + if (genericTypeArgument == typeof(Guid) || genericTypeArgument == typeof(ClassKind) || genericTypeArgument == typeof(VcardTelephoneNumberKind)) { originalProperty = originalIenumerable.Cast().ToList(); @@ -206,6 +183,7 @@ private void ResolveUpdate(Operation operation) } var possibleDeletions = originalProperty.Except(modifiedProperty).ToList(); + if (possibleDeletions.Count > 0) { // this part will be added to the delete @@ -236,7 +214,7 @@ private void ResolveUpdate(Operation operation) { if (original[key].Equals(modifiedFull[key])) { - modified.Remove(key); + modified.Remove(key); } } } @@ -260,6 +238,7 @@ private void ResolveUpdate(Operation operation) if (listsToAdd.Count > 0) { var updateDto = modified; + foreach (var kvp in listsToAdd) { updateDto.Add(kvp.Key, kvp.Value); @@ -271,6 +250,6 @@ private void ResolveUpdate(Operation operation) { this.Update.Add(modified); } - } + } } } diff --git a/README.md b/README.md index 7b63fb52b..7772459e5 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,10 @@ The CDP4Dal library is a library that provides the basis to implement ECSS-E-TM- The CDP4DalCommon library provides common classes to support the ECSS-E-TM-10-25 and CDP4-COMET protocol. +## CDP4DalJsonSerializer + +The CDP4DalJsonSerializer library provides JsonSerializer converter for common classes contained in CDP4DalCommon library. + ## CDP4JsonFileDal The CDP4JsonFileDal library is a C# library that provides an implementation of ECSS-E-TM-10-25A Annex C.3, the JSON Exchange File Format. This file format is a ZIP archive in which a number of files are stored that each contain one or more ECSS-E-TM-10-25 objects that are serialized in the form of a JSON array of JSON objects. The CDP4JsonFileDal library can be used to read from such a ZIP archive, and to create such a ZIP archive. The ZIP archive is typically used to exchange complete models between organizations. diff --git a/pre-release.bat b/pre-release.bat index 512ad2715..fa4c872bc 100644 --- a/pre-release.bat +++ b/pre-release.bat @@ -44,7 +44,7 @@ ECHO. for %%f in (%~dp0PreReleaseBuilds\*.nupkg) do ( (Echo "%%f" | FIND /I "symbols" 1>NUL) || ( echo Pushing %%f - dotnet nuget push "%%f" --source https://nuget.pkg.github.com/RHEAGROUP/index.json -k %apikey% + dotnet nuget push "%%f" --source https://nuget.pkg.github.com/STARIONGROUP/index.json -k %apikey% ) ) diff --git a/versionBump.sh b/versionBump.sh new file mode 100644 index 000000000..853534081 --- /dev/null +++ b/versionBump.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +rootFolder=$(pwd) + +newVersionPrefix=$1 + +# Get all .csproj files recursively within the root folder and discard tests project +projectFiles=$(find "$rootFolder" -type f -name '*.csproj' | grep -v 'Tests.csproj') + +for file in $projectFiles; do + sed "s|\(\)[^<]*\(<\/VersionPrefix>\)|\1$newVersionPrefix\2|g" "$file" > "$file.tmp" + mv "$file.tmp" "$file" +done + +echo "VersionPrefix updated to $newVersionPrefix in all .csproj files."