Skip to content

Commit

Permalink
Last cmd is now being set for routesegments
Browse files Browse the repository at this point in the history
  • Loading branch information
runeanielsen committed Aug 7, 2020
1 parent a73d5d0 commit e773f18
Show file tree
Hide file tree
Showing 20 changed files with 129 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand All @@ -27,7 +28,8 @@ public RouteNodeAdded
string applicationInfo,
string nodeName,
string nodeKind,
string nodeFunction
string nodeFunction,
bool isLastEventInCmd = false
)
{
CmdId = cmdId;
Expand All @@ -39,6 +41,7 @@ string nodeFunction
NodeName = nodeName;
NodeKind = nodeKind;
NodeFunction = nodeFunction;
IsLastEventInCmd = isLastEventInCmd;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -30,7 +31,8 @@ public RouteSegmentAdded(
Guid workTaskMrid,
string username,
string applicationName,
string applicationInfo)
string applicationInfo,
bool isLastEventInCmd = false)
{
CmdId = cmdId;
SegmentId = segmentId;
Expand All @@ -43,6 +45,7 @@ public RouteSegmentAdded(
Username = username;
ApplicationName = applicationName;
ApplicationInfo = applicationInfo;
IsLastEventInCmd = isLastEventInCmd;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ public class RouteSegmentRemoved
public Guid CmdId { get; }
public Guid SegmentId { get; }
public IEnumerable<Guid> ReplacedBySegments { get; }
public bool IsLastEventInCmd { get; }

public RouteSegmentRemoved(Guid cmdId, Guid segmentId, IEnumerable<Guid> replacedBySegments, string cmdType)
public RouteSegmentRemoved
(
Guid cmdId,
Guid segmentId,
IEnumerable<Guid> replacedBySegments,
string cmdType,
bool isLastEventInCmd = false
)
{
if (replacedBySegments.Count() > 2)
throw new ArgumentOutOfRangeException($"{nameof(ReplacedBySegments)} count cannot be more than 2");
Expand All @@ -23,6 +31,7 @@ public RouteSegmentRemoved(Guid cmdId, Guid segmentId, IEnumerable<Guid> replace
SegmentId = segmentId;
ReplacedBySegments = replacedBySegments;
CmdType = cmdType;
IsLastEventInCmd = isLastEventInCmd;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task<INotification> 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 };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task<IEnumerable<INotification>> CreateUpdatedEvent(RouteSegment be
var cmdId = Guid.NewGuid();

if (after.MarkAsDeleted)
return new List<INotification> { CreateRouteSegmentDeleted(after, cmdId) };
return new List<INotification> { CreateRouteSegmentDeleted(after, cmdId, true) };

var intersectingStartSegments = await _geoDatabase.GetIntersectingStartRouteSegments(after);
var intersectingEndSegments = await _geoDatabase.GetIntersectingEndRouteSegments(after);
Expand Down Expand Up @@ -140,7 +140,13 @@ private List<INotification> 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);
Expand All @@ -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
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NewRouteNodeDigitized>
Expand Down Expand Up @@ -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
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ await _mediator.Publish(new RouteSegmentAdded
RouteSegment = routeSegment,
StartRouteNode = startNode,
EndRouteNode = endNode,
CmdType = nameof(NewRouteSegmentDigitized)
CmdType = nameof(NewRouteSegmentDigitized),
IsLastEventInCmd = true
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;

namespace OpenFTTH.GDBIntegrator.Integrator.Notifications
{
Expand All @@ -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<RouteNodeAdded>
Expand Down Expand Up @@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<RouteNodeDeleted>
Expand Down Expand Up @@ -43,7 +43,8 @@ await _producer.Produce(
(
request.CmdId,
request.RouteNode.Mrid,
nameof(RouteSegmentDeleted)
nameof(RouteSegmentDeleted),
request.IsLastEventInCmd
));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ await _producer.Produce(_kafkaSettings.EventRouteNetworkTopicName,
request.CmdId,
routeSegmentToBeUpdated.Mrid,
nameof(RouteNodeLocationChanged),
routeSegmentToBeUpdated.GetGeoJsonCoordinate()
routeSegmentToBeUpdated.GetGeoJsonCoordinate(),
true
));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RouteSegmentAdded>
Expand Down Expand Up @@ -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
));
}
}
Expand Down
Loading

0 comments on commit e773f18

Please sign in to comment.