|
| 1 | +// ------------------------------------------------------------------------------------------------- |
| 2 | +// <copyright file="TerminateActionUsageExtensions.cs" company="Starion Group S.A."> |
| 3 | +// |
| 4 | +// Copyright 2022-2024 Starion Group S.A. |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// </copyright> |
| 19 | +// ------------------------------------------------------------------------------------------------ |
| 20 | + |
| 21 | +// ------------------------------------------------------------------------------------------------ |
| 22 | +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- |
| 23 | +// ------------------------------------------------------------------------------------------------ |
| 24 | + |
| 25 | +namespace SysML2.NET.Dal |
| 26 | +{ |
| 27 | + using System; |
| 28 | + using System.Collections.Concurrent; |
| 29 | + using System.Collections.Generic; |
| 30 | + using System.Linq; |
| 31 | + |
| 32 | + using Core.POCO; |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// A static class that provides extension methods for the <see cref="TerminateActionUsage"/> class |
| 36 | + /// </summary> |
| 37 | + public static class TerminateActionUsageExtensions |
| 38 | + { |
| 39 | + /// <summary> |
| 40 | + /// Updates the value properties of the <see cref="TerminateActionUsage"/> by setting the value equal to that of the dto |
| 41 | + /// Removes deleted objects from the reference properties and returns the unique identifiers |
| 42 | + /// of the objects that have been removed from contained properties |
| 43 | + /// </summary> |
| 44 | + /// <param name="poco"> |
| 45 | + /// The <see cref="TerminateActionUsage"/> that is to be updated |
| 46 | + /// </param> |
| 47 | + /// <param name="dto"> |
| 48 | + /// The DTO that is used to update the <see cref="TerminateActionUsage"/> with |
| 49 | + /// </param> |
| 50 | + /// <returns> |
| 51 | + /// The unique identifiers of the objects that have been removed from contained properties |
| 52 | + /// </returns> |
| 53 | + /// <exception cref="ArgumentNullException"> |
| 54 | + /// Thrown when the <paramref name="poco"/> or <paramref name="dto"/> is null |
| 55 | + /// </exception> |
| 56 | + public static IEnumerable<Guid> UpdateValueAndRemoveDeletedReferenceProperties(this Core.POCO.TerminateActionUsage poco, Core.DTO.TerminateActionUsage dto) |
| 57 | + { |
| 58 | + if (poco == null) |
| 59 | + { |
| 60 | + throw new ArgumentNullException(nameof(poco), $"the {nameof(poco)} may not be null"); |
| 61 | + } |
| 62 | + |
| 63 | + if (dto == null) |
| 64 | + { |
| 65 | + throw new ArgumentNullException(nameof(dto), $"the {nameof(dto)} may not be null"); |
| 66 | + } |
| 67 | + |
| 68 | + var identifiersOfObjectsToDelete = new List<Guid>(); |
| 69 | + |
| 70 | + poco.AliasIds = dto.AliasIds; |
| 71 | + |
| 72 | + poco.DeclaredName = dto.DeclaredName; |
| 73 | + |
| 74 | + poco.DeclaredShortName = dto.DeclaredShortName; |
| 75 | + |
| 76 | + poco.Direction = dto.Direction; |
| 77 | + |
| 78 | + poco.ElementId = dto.ElementId; |
| 79 | + |
| 80 | + poco.IsAbstract = dto.IsAbstract; |
| 81 | + |
| 82 | + poco.IsComposite = dto.IsComposite; |
| 83 | + |
| 84 | + poco.IsDerived = dto.IsDerived; |
| 85 | + |
| 86 | + poco.IsEnd = dto.IsEnd; |
| 87 | + |
| 88 | + poco.IsImpliedIncluded = dto.IsImpliedIncluded; |
| 89 | + |
| 90 | + poco.IsIndividual = dto.IsIndividual; |
| 91 | + |
| 92 | + poco.IsOrdered = dto.IsOrdered; |
| 93 | + |
| 94 | + poco.IsPortion = dto.IsPortion; |
| 95 | + |
| 96 | + poco.IsReadOnly = dto.IsReadOnly; |
| 97 | + |
| 98 | + poco.IsSufficient = dto.IsSufficient; |
| 99 | + |
| 100 | + poco.IsUnique = dto.IsUnique; |
| 101 | + |
| 102 | + poco.IsVariation = dto.IsVariation; |
| 103 | + |
| 104 | + var ownedRelationshipToDelete = poco.OwnedRelationship.Select(x => x.Id).Except(dto.OwnedRelationship); |
| 105 | + foreach (var identifier in ownedRelationshipToDelete) |
| 106 | + { |
| 107 | + poco.OwnedRelationship.Remove(poco.OwnedRelationship.Single(x => x.Id == identifier)); |
| 108 | + } |
| 109 | + identifiersOfObjectsToDelete.AddRange(ownedRelationshipToDelete); |
| 110 | + |
| 111 | + poco.PortionKind = dto.PortionKind; |
| 112 | + |
| 113 | + |
| 114 | + return identifiersOfObjectsToDelete; |
| 115 | + } |
| 116 | + |
| 117 | + /// <summary> |
| 118 | + /// Updates the Reference properties of the <see cref="TerminateActionUsage"/> using the data (identifiers) encapsulated in the DTO |
| 119 | + /// and the provided cache to find the referenced object. |
| 120 | + /// </summary> |
| 121 | + /// <param name="poco"> |
| 122 | + /// The <see cref="TerminateActionUsage"/> that is to be updated |
| 123 | + /// </param> |
| 124 | + /// <param name="dto"> |
| 125 | + /// The DTO that is used to update the <see cref="TerminateActionUsage"/> with |
| 126 | + /// </param> |
| 127 | + /// <param name="cache"> |
| 128 | + /// The <see cref="ConcurrentDictionary{Guid, Lazy{Core.POCO.IElement}}"/> that contains the |
| 129 | + /// <see cref="Core.POCO.IElement"/>s that are know and cached. |
| 130 | + /// </param> |
| 131 | + /// <exception cref="ArgumentNullException"></exception> |
| 132 | + public static void UpdateReferenceProperties(this Core.POCO.TerminateActionUsage poco, Core.DTO.TerminateActionUsage dto, ConcurrentDictionary<Guid, Lazy<Core.POCO.IElement>> cache) |
| 133 | + { |
| 134 | + if (poco == null) |
| 135 | + { |
| 136 | + throw new ArgumentNullException(nameof(poco), $"the {nameof(poco)} may not be null"); |
| 137 | + } |
| 138 | + |
| 139 | + if (dto == null) |
| 140 | + { |
| 141 | + throw new ArgumentNullException(nameof(dto), $"the {nameof(dto)} may not be null"); |
| 142 | + } |
| 143 | + |
| 144 | + if (cache == null) |
| 145 | + { |
| 146 | + throw new ArgumentNullException(nameof(cache), $"the {nameof(cache)} may not be null"); |
| 147 | + } |
| 148 | + |
| 149 | + Lazy<Core.POCO.IElement> lazyPoco; |
| 150 | + |
| 151 | + var ownedRelationshipToAdd = dto.OwnedRelationship.Except(poco.OwnedRelationship.Select(x => x.Id)); |
| 152 | + foreach (var identifier in ownedRelationshipToAdd) |
| 153 | + { |
| 154 | + if (cache.TryGetValue(identifier, out lazyPoco)) |
| 155 | + { |
| 156 | + poco.OwnedRelationship.Add((IRelationship)lazyPoco.Value); |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + if (dto.OwningRelationship.HasValue && cache.TryGetValue(dto.OwningRelationship.Value, out lazyPoco)) |
| 161 | + { |
| 162 | + poco.OwningRelationship = (IRelationship)lazyPoco.Value; |
| 163 | + } |
| 164 | + else |
| 165 | + { |
| 166 | + poco.OwningRelationship = null; |
| 167 | + } |
| 168 | + |
| 169 | + } |
| 170 | + |
| 171 | + /// <summary> |
| 172 | + /// Creates a <see cref="Core.DTO.TerminateActionUsage"/> based on the provided POCO |
| 173 | + /// </summary> |
| 174 | + /// <param name="poco"> |
| 175 | + /// The subject <see cref="Core.POCO.TerminateActionUsage"/> from which a DTO is to be created |
| 176 | + /// </param> |
| 177 | + /// <returns> |
| 178 | + /// An instance of <see cref="Core.POCO.TerminateActionUsage"/> |
| 179 | + /// </returns> |
| 180 | + public static Core.DTO.TerminateActionUsage ToDto(this Core.POCO.TerminateActionUsage poco) |
| 181 | + { |
| 182 | + var dto = new Core.DTO.TerminateActionUsage(); |
| 183 | + |
| 184 | + dto.Id = poco.Id; |
| 185 | + dto.AliasIds = poco.AliasIds; |
| 186 | + dto.DeclaredName = poco.DeclaredName; |
| 187 | + dto.DeclaredShortName = poco.DeclaredShortName; |
| 188 | + dto.Direction = poco.Direction; |
| 189 | + dto.ElementId = poco.ElementId; |
| 190 | + dto.IsAbstract = poco.IsAbstract; |
| 191 | + dto.IsComposite = poco.IsComposite; |
| 192 | + dto.IsDerived = poco.IsDerived; |
| 193 | + dto.IsEnd = poco.IsEnd; |
| 194 | + dto.IsImpliedIncluded = poco.IsImpliedIncluded; |
| 195 | + dto.IsIndividual = poco.IsIndividual; |
| 196 | + dto.IsOrdered = poco.IsOrdered; |
| 197 | + dto.IsPortion = poco.IsPortion; |
| 198 | + dto.IsReadOnly = poco.IsReadOnly; |
| 199 | + dto.IsSufficient = poco.IsSufficient; |
| 200 | + dto.IsUnique = poco.IsUnique; |
| 201 | + dto.IsVariation = poco.IsVariation; |
| 202 | + dto.OwnedRelationship = poco.OwnedRelationship.Select(x => x.Id).ToList(); |
| 203 | + dto.OwningRelationship = poco.OwningRelationship?.Id; |
| 204 | + dto.PortionKind = poco.PortionKind; |
| 205 | + |
| 206 | + return dto; |
| 207 | + } |
| 208 | + } |
| 209 | +} |
| 210 | + |
| 211 | +// ------------------------------------------------------------------------------------------------ |
| 212 | +// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!-------- |
| 213 | +// ------------------------------------------------------------------------------------------------ |
0 commit comments