From e773f185347643f145beb7e7d9d938d9ede9263d Mon Sep 17 00:00:00 2001 From: Rune Nielsen Date: Fri, 7 Aug 2020 15:39:21 +0200 Subject: [PATCH] Last cmd is now being set for routesegments --- .../EventMessages/RouteNodeAdded.cs | 5 +- .../RouteNodeGeometryModified.cs | 4 +- .../RouteNodeMarkedForDeletion.cs | 4 +- .../EventMessages/RouteSegmentAdded.cs | 5 +- .../RouteSegmentGeometryModified.cs | 4 +- .../RouteSegmentMarkedForDeletion.cs | 4 +- .../EventMessages/RouteSegmentRemoved.cs | 11 ++- .../Factories/RouteNodeEventFactory.cs | 2 +- .../Factories/RouteSegmentEventFactory.cs | 15 +++- .../ExistingRouteSegmentSplitted.cs | 3 +- ...tRouteNode.cs => NewRouteNodeDigitized.cs} | 5 +- .../Notifications/NewRouteSegmentDigitized.cs | 3 +- .../Notifications/RouteNodeAdded.cs | 7 +- .../Notifications/RouteNodeDeleted.cs | 5 +- .../Notifications/RouteNodeLocationChanged.cs | 3 +- .../Notifications/RouteSegmentAdded.cs | 4 +- .../RouteSegmentConnectivityChanged.cs | 85 ++++++++++++------- .../Notifications/RouteSegmentDeleted.cs | 4 +- .../RouteSegmentLocationChanged.cs | 8 +- .../Notifications/RouteSegmentRemoved.cs | 4 +- 20 files changed, 129 insertions(+), 56 deletions(-) rename src/OpenFTTH.GDBIntegrator.Integrator/Notifications/{InsertRouteNode.cs => NewRouteNodeDigitized.cs} (87%) diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteNodeAdded.cs b/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteNodeAdded.cs index 5d4c209..54b757a 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteNodeAdded.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteNodeAdded.cs @@ -16,6 +16,7 @@ public class RouteNodeAdded public string NodeName { get; } public string NodeKind { get; } public string NodeFunction { get; } + public bool IsLastEventInCmd { get; } public RouteNodeAdded ( @@ -27,7 +28,8 @@ public RouteNodeAdded string applicationInfo, string nodeName, string nodeKind, - string nodeFunction + string nodeFunction, + bool isLastEventInCmd = false ) { CmdId = cmdId; @@ -39,6 +41,7 @@ string nodeFunction NodeName = nodeName; NodeKind = nodeKind; NodeFunction = nodeFunction; + IsLastEventInCmd = isLastEventInCmd; } } } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteNodeGeometryModified.cs b/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteNodeGeometryModified.cs index da2eafb..c8ac8f9 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteNodeGeometryModified.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteNodeGeometryModified.cs @@ -11,13 +11,15 @@ public class RouteNodeGeometryModified public string CmdType { get; } public Guid NodeId { get; } public string Geometry { get; } + public bool IsLastEventInCmd { get; } - public RouteNodeGeometryModified(Guid cmdId, Guid nodeId, string cmdType, string geometry) + public RouteNodeGeometryModified(Guid cmdId, Guid nodeId, string cmdType, string geometry, bool isLastEventInCmd = false) { CmdId = cmdId; NodeId = nodeId; CmdType = cmdType; Geometry = geometry; + IsLastEventInCmd = IsLastEventInCmd; } } } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteNodeMarkedForDeletion.cs b/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteNodeMarkedForDeletion.cs index cd7ca89..4d41b69 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteNodeMarkedForDeletion.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteNodeMarkedForDeletion.cs @@ -10,12 +10,14 @@ public class RouteNodeMarkedForDeletion public Guid CmdId { get; } public string CmdType { get; } public Guid NodeId { get; } + public bool IsLastEventInCmd { get; } - public RouteNodeMarkedForDeletion(Guid cmdId, Guid segmentId, string cmdType) + public RouteNodeMarkedForDeletion(Guid cmdId, Guid segmentId, string cmdType, bool isLastEventInCmd = false) { CmdId = cmdId; NodeId = segmentId; CmdType = cmdType; + IsLastEventInCmd = isLastEventInCmd; } } } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteSegmentAdded.cs b/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteSegmentAdded.cs index 4252483..d00acc1 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteSegmentAdded.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteSegmentAdded.cs @@ -18,6 +18,7 @@ public class RouteSegmentAdded public string Username { get; } public string ApplicationName { get; } public string ApplicationInfo { get; } + public bool IsLastEventInCmd { get; } public RouteSegmentAdded( Guid cmdId, @@ -30,7 +31,8 @@ public RouteSegmentAdded( Guid workTaskMrid, string username, string applicationName, - string applicationInfo) + string applicationInfo, + bool isLastEventInCmd = false) { CmdId = cmdId; SegmentId = segmentId; @@ -43,6 +45,7 @@ public RouteSegmentAdded( Username = username; ApplicationName = applicationName; ApplicationInfo = applicationInfo; + IsLastEventInCmd = isLastEventInCmd; } } } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteSegmentGeometryModified.cs b/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteSegmentGeometryModified.cs index 779772f..b813d9d 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteSegmentGeometryModified.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteSegmentGeometryModified.cs @@ -11,13 +11,15 @@ public class RouteSegmentGeometryModified public string CmdType { get; } public Guid SegmentId { get; } public string Geometry { get; } + public bool IsLastEventInCmd { get; } - public RouteSegmentGeometryModified(Guid cmdId, Guid segmentId, string cmdType, string geometry) + public RouteSegmentGeometryModified(Guid cmdId, Guid segmentId, string cmdType, string geometry, bool isLastEventInCmd = false) { CmdId = cmdId; SegmentId = segmentId; CmdType = cmdType; Geometry = geometry; + IsLastEventInCmd = isLastEventInCmd; } } } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteSegmentMarkedForDeletion.cs b/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteSegmentMarkedForDeletion.cs index e0ed761..13fef13 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteSegmentMarkedForDeletion.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteSegmentMarkedForDeletion.cs @@ -10,12 +10,14 @@ public class RouteSegmentMarkedForDeletion public Guid CmdId { get; } public string CmdType { get; } public Guid SegmentId { get; } + public bool IsLastEventInCmd { get; } - public RouteSegmentMarkedForDeletion(Guid cmdId, Guid segmentId, string cmdType) + public RouteSegmentMarkedForDeletion(Guid cmdId, Guid segmentId, string cmdType, bool isLastEventInCmd = false) { CmdId = cmdId; SegmentId = segmentId; CmdType = cmdType; + IsLastEventInCmd = isLastEventInCmd; } } } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteSegmentRemoved.cs b/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteSegmentRemoved.cs index 4bb4703..a0dc5f3 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteSegmentRemoved.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/EventMessages/RouteSegmentRemoved.cs @@ -13,8 +13,16 @@ public class RouteSegmentRemoved public Guid CmdId { get; } public Guid SegmentId { get; } public IEnumerable ReplacedBySegments { get; } + public bool IsLastEventInCmd { get; } - public RouteSegmentRemoved(Guid cmdId, Guid segmentId, IEnumerable replacedBySegments, string cmdType) + public RouteSegmentRemoved + ( + Guid cmdId, + Guid segmentId, + IEnumerable replacedBySegments, + string cmdType, + bool isLastEventInCmd = false + ) { if (replacedBySegments.Count() > 2) throw new ArgumentOutOfRangeException($"{nameof(ReplacedBySegments)} count cannot be more than 2"); @@ -23,6 +31,7 @@ public RouteSegmentRemoved(Guid cmdId, Guid segmentId, IEnumerable replace SegmentId = segmentId; ReplacedBySegments = replacedBySegments; CmdType = cmdType; + IsLastEventInCmd = isLastEventInCmd; } } } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/Factories/RouteNodeEventFactory.cs b/src/OpenFTTH.GDBIntegrator.Integrator/Factories/RouteNodeEventFactory.cs index 8593eeb..2614f6a 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/Factories/RouteNodeEventFactory.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/Factories/RouteNodeEventFactory.cs @@ -43,7 +43,7 @@ public async Task CreateUpdatedEvent(RouteNode before, RouteNode var cmdId = Guid.NewGuid(); if (after.MarkAsDeleted) - return new RouteNodeDeleted { CmdId = cmdId, RouteNode = after }; + return new RouteNodeDeleted { CmdId = cmdId, RouteNode = after, IsLastEventInCmd = true }; return new RouteNodeLocationChanged { CmdId = cmdId, RouteNodeAfter = after, RouteNodeBefore = before }; } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/Factories/RouteSegmentEventFactory.cs b/src/OpenFTTH.GDBIntegrator.Integrator/Factories/RouteSegmentEventFactory.cs index b381be2..9e84fc7 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/Factories/RouteSegmentEventFactory.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/Factories/RouteSegmentEventFactory.cs @@ -51,7 +51,7 @@ public async Task> CreateUpdatedEvent(RouteSegment be var cmdId = Guid.NewGuid(); if (after.MarkAsDeleted) - return new List { CreateRouteSegmentDeleted(after, cmdId) }; + return new List { CreateRouteSegmentDeleted(after, cmdId, true) }; var intersectingStartSegments = await _geoDatabase.GetIntersectingStartRouteSegments(after); var intersectingEndSegments = await _geoDatabase.GetIntersectingEndRouteSegments(after); @@ -140,7 +140,13 @@ private List HandleExistingRouteSegmentSplitted(int intersectingS if (intersectingSegmentsCount == 1 && intersectingNodesCount == 0) { var startNode = _routeNodeFactory.Create(point); - notifications.Add(new NewRouteNodeDigitized { CmdId = cmdId, RouteNode = startNode }); + notifications.Add(new NewRouteNodeDigitized + { + CmdId = cmdId, + RouteNode = startNode, + IsLastEventInCmd = false, + CmdType = nameof(ExistingRouteSegmentSplitted) + }); var routeSegmentSplitted = CreateExistingRouteSegmentSplitted(routeSegment, cmdId, startNode); notifications.Add(routeSegmentSplitted); @@ -159,12 +165,13 @@ private bool IsCreatedByApplication(RouteSegment routeSegment) return routeSegment.ApplicationName == _applicationSettings.ApplicationName; } - private RouteSegmentDeleted CreateRouteSegmentDeleted(RouteSegment routeSegment, Guid cmdId) + private RouteSegmentDeleted CreateRouteSegmentDeleted(RouteSegment routeSegment, Guid cmdId, bool isLastEventInCommand) { return new RouteSegmentDeleted { RouteSegment = routeSegment, - CmdId = cmdId + CmdId = cmdId, + IsLastEventInCmd = isLastEventInCommand }; } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/ExistingRouteSegmentSplitted.cs b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/ExistingRouteSegmentSplitted.cs index 9d168cb..d6757ee 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/ExistingRouteSegmentSplitted.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/ExistingRouteSegmentSplitted.cs @@ -110,7 +110,8 @@ await _mediator.Publish( CmdId = cmdId, RouteSegment = intersectingRouteSegment, ReplacedBySegments = routeSegments.Select(x => x.Mrid), - CmdType = nameof(ExistingRouteSegmentSplitted) + CmdType = nameof(ExistingRouteSegmentSplitted), + IsLastEventInCmd = true }); } } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/InsertRouteNode.cs b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/NewRouteNodeDigitized.cs similarity index 87% rename from src/OpenFTTH.GDBIntegrator.Integrator/Notifications/InsertRouteNode.cs rename to src/OpenFTTH.GDBIntegrator.Integrator/Notifications/NewRouteNodeDigitized.cs index 592ae5e..eaef88c 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/InsertRouteNode.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/NewRouteNodeDigitized.cs @@ -14,6 +14,8 @@ public class NewRouteNodeDigitized : INotification { public RouteNode RouteNode { get; set; } public Guid CmdId { get; set; } + public string CmdType { get; set; } + public bool? IsLastEventInCmd { get; set; } } public class NewRouteNodeDigitizedHandler : INotificationHandler @@ -44,7 +46,8 @@ await _mediator.Publish(new RouteNodeAdded { RouteNode = request.RouteNode, CmdId = request.CmdId, - CmdType = nameof(NewRouteNodeDigitized) + CmdType = request.CmdType ?? nameof(NewRouteNodeDigitized), + IsLastEventInCmd = request.IsLastEventInCmd ?? true }); } } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/NewRouteSegmentDigitized.cs b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/NewRouteSegmentDigitized.cs index b0483d5..dfb3e8e 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/NewRouteSegmentDigitized.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/NewRouteSegmentDigitized.cs @@ -79,7 +79,8 @@ await _mediator.Publish(new RouteSegmentAdded RouteSegment = routeSegment, StartRouteNode = startNode, EndRouteNode = endNode, - CmdType = nameof(NewRouteSegmentDigitized) + CmdType = nameof(NewRouteSegmentDigitized), + IsLastEventInCmd = true }); } } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteNodeAdded.cs b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteNodeAdded.cs index 015e7ff..3201b3f 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteNodeAdded.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteNodeAdded.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Newtonsoft.Json; namespace OpenFTTH.GDBIntegrator.Integrator.Notifications { @@ -16,6 +15,7 @@ public class RouteNodeAdded : INotification public RouteNode RouteNode { get; set; } public Guid CmdId { get; set; } public string CmdType { get; set; } + public bool IsLastEventInCmd { get; set; } } public class RouteNodeAddedHandler : INotificationHandler @@ -49,8 +49,11 @@ await _producer.Produce(_kafkaSettings.EventRouteNetworkTopicName, request.RouteNode.ApplicationInfo, request.RouteNode.NodeName, request.RouteNode.NodeKind, - request.RouteNode.NodeFunction + request.RouteNode.NodeFunction, + request.IsLastEventInCmd )); + + _logger.LogInformation($"Sending {nameof(RouteNodeAdded)} with mrid '{request.RouteNode.Mrid}' to producer"); } } } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteNodeDeleted.cs b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteNodeDeleted.cs index c80eb6a..4d2ae30 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteNodeDeleted.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteNodeDeleted.cs @@ -5,7 +5,6 @@ using System; using System.Threading; using System.Threading.Tasks; -using System.Collections.Generic; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -15,6 +14,7 @@ public class RouteNodeDeleted : INotification { public RouteNode RouteNode { get; set; } public Guid CmdId { get; set; } + public bool IsLastEventInCmd { get; set; } } public class RouteNodeDeletedHandler : INotificationHandler @@ -43,7 +43,8 @@ await _producer.Produce( ( request.CmdId, request.RouteNode.Mrid, - nameof(RouteSegmentDeleted) + nameof(RouteSegmentDeleted), + request.IsLastEventInCmd )); } } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteNodeLocationChanged.cs b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteNodeLocationChanged.cs index 34cfcbd..bac42be 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteNodeLocationChanged.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteNodeLocationChanged.cs @@ -102,7 +102,8 @@ await _producer.Produce(_kafkaSettings.EventRouteNetworkTopicName, request.CmdId, routeSegmentToBeUpdated.Mrid, nameof(RouteNodeLocationChanged), - routeSegmentToBeUpdated.GetGeoJsonCoordinate() + routeSegmentToBeUpdated.GetGeoJsonCoordinate(), + true )); } } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentAdded.cs b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentAdded.cs index 046a2aa..4a9946a 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentAdded.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentAdded.cs @@ -17,6 +17,7 @@ public class RouteSegmentAdded : INotification public RouteNode EndRouteNode { get; set; } public Guid CmdId { get; set; } public string CmdType { get; set; } + public bool IsLastEventInCmd { get; set; } } public class RouteSegmentAddedHandler : INotificationHandler @@ -51,7 +52,8 @@ await _producer.Produce(_kafkaSettings.EventRouteNetworkTopicName, request.RouteSegment.WorkTaskMrid, request.RouteSegment.Username, request.RouteSegment.ApplicationName, - request.RouteSegment.ApplicationInfo + request.RouteSegment.ApplicationInfo, + request.IsLastEventInCmd )); } } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentConnectivityChanged.cs b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentConnectivityChanged.cs index a46965e..4cdedea 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentConnectivityChanged.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentConnectivityChanged.cs @@ -1,7 +1,6 @@ using OpenFTTH.GDBIntegrator.RouteNetwork; using OpenFTTH.GDBIntegrator.RouteNetwork.Factories; using OpenFTTH.GDBIntegrator.Config; -using OpenFTTH.GDBIntegrator.Producer; using OpenFTTH.GDBIntegrator.GeoDatabase; using MediatR; using System; @@ -70,69 +69,95 @@ public async Task Handle(RouteSegmentConnectivityChanged request, CancellationTo } var routeSegmentClone = await InsertRouteSegmentClone(request.After, request.CmdId); - await RevertAndMarkExistingRouteSegmentForDeletion(request.Before, request.CmdId, routeSegmentClone); + await MarkRouteSegmentForDeletion(request.Before); - await MarkDeadRouteNodesForDeletion(request.Before, request.CmdId); - } + var beforeStartNode = (await _geoDatabase.GetIntersectingStartRouteNodes(request.Before)).FirstOrDefault(); + var beforeEndNode = (await _geoDatabase.GetIntersectingEndRouteNodes(request.Before)).FirstOrDefault(); + var isBeforeStartNodeDeleteable = await IsDeleteable(beforeStartNode); + var isBeforeEndNodeDeletable = await IsDeleteable(beforeEndNode); - private async Task MarkDeadRouteNodesForDeletion(RouteSegment routeSegment, Guid cmdId) - { - var startNode = (await _geoDatabase.GetIntersectingStartRouteNodes(routeSegment)).FirstOrDefault(); - var endNode = (await _geoDatabase.GetIntersectingEndRouteNodes(routeSegment)).FirstOrDefault(); + var isRevertAndDeleteLastEventInCmd = !isBeforeStartNodeDeleteable && !isBeforeEndNodeDeletable; + await PublishMarkedAsDeletedSegment( + request.Before, + request.CmdId, + routeSegmentClone, + isRevertAndDeleteLastEventInCmd); + + if (isBeforeStartNodeDeleteable) + await MarkDeleteRouteNode(beforeStartNode, request.CmdId, !isBeforeEndNodeDeletable); - await MarkDeleteRouteNode(startNode, cmdId); - await MarkDeleteRouteNode(endNode, cmdId); + if (isBeforeEndNodeDeletable) + await MarkDeleteRouteNode(beforeEndNode, request.CmdId, true); } - private async Task MarkDeleteRouteNode(RouteNode routeNode, Guid cmdId) + private async Task IsDeleteable(RouteNode routeNode) { var intersectingRouteSegments = await _geoDatabase.GetIntersectingRouteSegments(routeNode); - var isDeleteable = String.IsNullOrEmpty(routeNode.NodeKind) && String.IsNullOrEmpty(routeNode.NodeName) && intersectingRouteSegments.Count == 0; + return String.IsNullOrEmpty(routeNode.NodeKind) + && String.IsNullOrEmpty(routeNode.NodeName) + && intersectingRouteSegments.Count == 0; + } - if (isDeleteable) + private async Task MarkDeleteRouteNode(RouteNode routeNode, Guid cmdId, bool isLastEventInCmd) + { + await _geoDatabase.MarkDeleteRouteNode(routeNode.Mrid); + await _mediator.Publish(new RouteNodeDeleted { - await _geoDatabase.MarkDeleteRouteNode(routeNode.Mrid); - await _mediator.Publish(new RouteNodeDeleted { CmdId = cmdId, RouteNode = routeNode }); - } + CmdId = cmdId, + RouteNode = routeNode, + IsLastEventInCmd = isLastEventInCmd + }); } private async Task InsertRouteNode(RouteNode routeNode, Guid cmdId) { await _geoDatabase.InsertRouteNode(routeNode); await _mediator.Publish(new RouteNodeAdded - { - CmdId = cmdId, - CmdType = nameof(RouteSegmentConnectivityChanged), - RouteNode = routeNode - }); + { + CmdId = cmdId, + CmdType = nameof(RouteSegmentConnectivityChanged), + RouteNode = routeNode + }); } - private async Task RevertAndMarkExistingRouteSegmentForDeletion(RouteSegment beforeRouteSegment, Guid cmdId, RouteSegment replacedBySegment) + private async Task MarkRouteSegmentForDeletion(RouteSegment beforeRouteSegment) { beforeRouteSegment.MarkAsDeleted = true; await _geoDatabase.UpdateRouteSegment(beforeRouteSegment); + } + + private async Task PublishMarkedAsDeletedSegment + ( + RouteSegment beforeRouteSegment, + Guid cmdId, + RouteSegment replacedBySegment, + bool isLastEventInCmd + ) + { await _mediator.Publish( new RouteSegmentRemoved { CmdId = cmdId, RouteSegment = beforeRouteSegment, ReplacedBySegments = new List { replacedBySegment.Mrid }, - CmdType = nameof(RouteSegmentConnectivityChanged) + CmdType = nameof(RouteSegmentConnectivityChanged), + IsLastEventInCmd = isLastEventInCmd }); } + private async Task InsertRouteSegmentClone(RouteSegment routeSegment, Guid cmdId) { var routeSegmentClone = _routeSegmentFactory.Create(routeSegment.GetLineString()); await _geoDatabase.InsertRouteSegment(routeSegmentClone); await _mediator.Publish(new RouteSegmentAdded - { - CmdId = cmdId, - RouteSegment = routeSegmentClone, - StartRouteNode = (await _geoDatabase.GetIntersectingStartRouteNodes(routeSegmentClone)).FirstOrDefault(), - EndRouteNode = (await _geoDatabase.GetIntersectingEndRouteNodes(routeSegmentClone)).FirstOrDefault(), - CmdType = nameof(RouteSegmentConnectivityChanged) - }); + { + CmdId = cmdId, + RouteSegment = routeSegmentClone, + StartRouteNode = (await _geoDatabase.GetIntersectingStartRouteNodes(routeSegmentClone)).FirstOrDefault(), + EndRouteNode = (await _geoDatabase.GetIntersectingEndRouteNodes(routeSegmentClone)).FirstOrDefault(), + CmdType = nameof(RouteSegmentConnectivityChanged), + }); return routeSegmentClone; } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentDeleted.cs b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentDeleted.cs index b70c974..9c79028 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentDeleted.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentDeleted.cs @@ -14,6 +14,7 @@ public class RouteSegmentDeleted : INotification { public RouteSegment RouteSegment { get; set; } public Guid CmdId { get; set; } + public bool IsLastEventInCmd { get; set; } } public class RouteSegmentDeletedHandler : INotificationHandler @@ -42,7 +43,8 @@ await _producer.Produce( ( request.CmdId, request.RouteSegment.Mrid, - nameof(RouteSegmentDeleted) + nameof(RouteSegmentDeleted), + request.IsLastEventInCmd )); } } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentLocationChanged.cs b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentLocationChanged.cs index 0025410..c220b98 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentLocationChanged.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentLocationChanged.cs @@ -14,16 +14,17 @@ public class RouteSegmentLocationChanged : INotification { public RouteSegment RouteSegment { get; set; } public Guid CmdId { get; set; } + public bool IsLastEventInCmd { get; set; } } public class RouteSegmentLocationChangedHandler : INotificationHandler { - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly KafkaSetting _kafkaSettings; private readonly IProducer _producer; public RouteSegmentLocationChangedHandler( - ILogger logger, + ILogger logger, IOptions kafkaSettings, IProducer producer) { @@ -42,7 +43,8 @@ await _producer.Produce(_kafkaSettings.EventRouteNetworkTopicName, request.CmdId, request.RouteSegment.Mrid, nameof(RouteSegmentLocationChanged), - request.RouteSegment.GetGeoJsonCoordinate() + request.RouteSegment.GetGeoJsonCoordinate(), + request.IsLastEventInCmd )); } } diff --git a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentRemoved.cs b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentRemoved.cs index 79f1a93..4a41a49 100644 --- a/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentRemoved.cs +++ b/src/OpenFTTH.GDBIntegrator.Integrator/Notifications/RouteSegmentRemoved.cs @@ -17,6 +17,7 @@ public class RouteSegmentRemoved : INotification public Guid CmdId { get; set; } public IEnumerable ReplacedBySegments { get; set; } public string CmdType { get; set; } + public bool IsLastEventInCmd { get; set; } } public class RouteSegmentRemovedHandler : INotificationHandler @@ -44,7 +45,8 @@ await _producer.Produce(_kafkaSettings.EventRouteNetworkTopicName, request.CmdId, request.RouteSegment.Mrid, request.ReplacedBySegments, - request.CmdType + request.CmdType, + request.IsLastEventInCmd )); } }