From 5a8dacc0230865e41d578e10c96176a6f93adcba Mon Sep 17 00:00:00 2001 From: Rik De Peuter Date: Fri, 27 Sep 2024 08:44:01 +0200 Subject: [PATCH] fix: wfs/wms road segment projection deal with unknown roadsegments instead of error (#1547) --- .../RoadSegmentRecordProjection.cs | 10 +++++++--- .../RoadSegmentRecordProjection.cs | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/RoadRegistry.Wfs.Projections/RoadSegmentRecordProjection.cs b/src/RoadRegistry.Wfs.Projections/RoadSegmentRecordProjection.cs index 3ac18e1de..7efc33ee3 100644 --- a/src/RoadRegistry.Wfs.Projections/RoadSegmentRecordProjection.cs +++ b/src/RoadRegistry.Wfs.Projections/RoadSegmentRecordProjection.cs @@ -129,7 +129,7 @@ private static async Task AddRoadSegment(IStreetNameCache streetNameCache, var leftSideStreetNameRecord = await TryGetFromCache(streetNameCache, roadSegmentAdded.LeftSide.StreetNameId, token); var rightSideStreetNameRecord = await TryGetFromCache(streetNameCache, roadSegmentAdded.RightSide.StreetNameId, token); - + dbRecord.MaintainerId = roadSegmentAdded.MaintenanceAuthority.Code; dbRecord.MaintainerName = OrganizationName.FromValueWithFallback(roadSegmentAdded.MaintenanceAuthority.Name); dbRecord.MethodDutchName = method.Translation.Name; @@ -159,7 +159,11 @@ private static async Task ModifyRoadSegment(IStreetNameCache streetNameCache, .ConfigureAwait(false); if (dbRecord is null) { - throw new InvalidOperationException($"RoadSegmentRecord with id {roadSegmentModified.Id} is not found"); + dbRecord = new RoadSegmentRecord + { + Id = roadSegmentModified.Id + }; + await context.RoadSegments.AddAsync(dbRecord, token); } var method = RoadSegmentGeometryDrawMethod.Parse(roadSegmentModified.GeometryDrawMethod); @@ -170,7 +174,7 @@ private static async Task ModifyRoadSegment(IStreetNameCache streetNameCache, var leftSideStreetNameRecord = await TryGetFromCache(streetNameCache, roadSegmentModified.LeftSide.StreetNameId, token); var rightSideStreetNameRecord = await TryGetFromCache(streetNameCache, roadSegmentModified.RightSide.StreetNameId, token); - + dbRecord.Id = roadSegmentModified.Id; dbRecord.MaintainerId = roadSegmentModified.MaintenanceAuthority.Code; dbRecord.MaintainerName = OrganizationName.FromValueWithFallback(roadSegmentModified.MaintenanceAuthority.Name); diff --git a/src/RoadRegistry.Wms.Projections/RoadSegmentRecordProjection.cs b/src/RoadRegistry.Wms.Projections/RoadSegmentRecordProjection.cs index 678b02ee7..3971efcfb 100644 --- a/src/RoadRegistry.Wms.Projections/RoadSegmentRecordProjection.cs +++ b/src/RoadRegistry.Wms.Projections/RoadSegmentRecordProjection.cs @@ -237,7 +237,11 @@ private static async Task ModifyRoadSegment(IStreetNameCache streetNameCache, .ConfigureAwait(false); if (dbRecord is null) { - throw new InvalidOperationException($"RoadSegmentRecord with id {roadSegmentModified.Id} is not found"); + dbRecord = new RoadSegmentRecord + { + Id = roadSegmentModified.Id + }; + await context.RoadSegments.AddAsync(dbRecord, token); } var transactionId = new TransactionId(envelope.Message.TransactionId);