Skip to content

Commit

Permalink
now sends out the correct issue doing a rollback for when connectivity (
Browse files Browse the repository at this point in the history
#113)

changes on route segment with related equipment
  • Loading branch information
runeanielsen authored Sep 8, 2023
1 parent c7bc5f1 commit c494f2c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/OpenFTTH.GDBIntegrator.Config/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public static class ErrorCode
public const string CANNOT_DELETE_ROUTE_NODE_WITH_RELATED_EQUIPMENT = "CANNOT_DELETE_ROUTE_NODE_WITH_RELATED_EQUIPMENT";
public const string CANNOT_DELETE_ROUTE_SEGMENT_WITH_RELATED_EQUIPMENT = "CANNOT_DELETE_ROUTE_SEGMENT_WITH_RELATED_EQUIPMENT";
public const string ROUTE_NODE_MODIFIED_LESS_THAN_TOLERANCE = "ROUTE_NODE_MODIFIED_LESS_THAN_TOLERANCE";
public const string CANNOT_CHANGE_CONNECTIVITY_ROUTE_SEGMENT_WITH_RELATED_EQUIPMENT = "CANNOT_CHANGE_CONNECTIVITY_ROUTE_SEGMENT_WITH_RELATED_EQUIPMENT";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;

namespace OpenFTTH.GDBIntegrator.Integrator.Commands;

public class CannotChangeConnectivityRouteSegmentRelatedEquipmentException : Exception
{
public CannotChangeConnectivityRouteSegmentRelatedEquipmentException()
{
}

public CannotChangeConnectivityRouteSegmentRelatedEquipmentException(string message)
: base(message)
{
}

public CannotChangeConnectivityRouteSegmentRelatedEquipmentException(string message, Exception inner)
: base(message, inner)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,36 @@ await RollbackOrDelete(
}
// This is not a pretty wasy to handle it, but it was the simplest way
// without having to restructure the whole thing.
catch (CannotDeleteRouteSegmentRelatedEquipmentException)
catch (CannotDeleteRouteSegmentRelatedEquipmentException ex)
{
await _geoDatabase.RollbackTransaction();
await _geoDatabase.BeginTransaction();

await RollbackOrDelete(
request.UpdateMessage,
$"Cannot delete route segment when it has related equipment.",
ex.Message,
ErrorCode.CANNOT_DELETE_ROUTE_SEGMENT_WITH_RELATED_EQUIPMENT
);

await _geoDatabase.Commit();
}
// This is not a pretty wasy to handle it, but it was the simplest way
// without having to restructure the whole thing.
catch (CannotChangeConnectivityRouteSegmentRelatedEquipmentException ex)
{
await _geoDatabase.RollbackTransaction();
await _geoDatabase.BeginTransaction();

await RollbackOrDelete(
request.UpdateMessage,
ex.Message,
ErrorCode.CANNOT_CHANGE_CONNECTIVITY_ROUTE_SEGMENT_WITH_RELATED_EQUIPMENT
);

await _geoDatabase.Commit();
}
// This is not a pretty wasy to handle it, but it was the simplest way
// without having to restructure the whole thing.
catch (CannotDeleteRouteNodeRelatedEquipmentException)
{
await _geoDatabase.RollbackTransaction();
Expand Down Expand Up @@ -537,8 +552,13 @@ private async Task HandleRouteSegment(RouteSegmentMessage routeSegmentMessage)
var routeSegmentUpdatedEvents = await _routeSegmentEventFactory
.CreateUpdatedEvent(routeSegmentMessage.Before, routeSegmentMessage.After);

var possibleIllegalOperation = routeSegmentUpdatedEvents.Any(x => x.GetType() == typeof(RouteSegmentDeleted) || x.GetType() == typeof(RouteSegmentConnectivityChanged));
if (possibleIllegalOperation)
var possibleIllegalOperationSegmentDeletion = routeSegmentUpdatedEvents
.Any(x => x.GetType() == typeof(RouteSegmentDeleted));

var possibleIllegalOperationSegmentConnectivityChanged = routeSegmentUpdatedEvents
.Any(x => x.GetType() == typeof(RouteSegmentConnectivityChanged));

if (possibleIllegalOperationSegmentDeletion)
{
var hasRelatedEquipment = await _validationService.HasRelatedEquipment(
routeSegmentMessage.After.Mrid);
Expand All @@ -549,6 +569,17 @@ private async Task HandleRouteSegment(RouteSegmentMessage routeSegmentMessage)
"Cannot delete route segment when it has releated equipment.");
}
}
else if (possibleIllegalOperationSegmentConnectivityChanged)
{
var hasRelatedEquipment = await _validationService.HasRelatedEquipment(
routeSegmentMessage.After.Mrid);

if (hasRelatedEquipment)
{
throw new CannotChangeConnectivityRouteSegmentRelatedEquipmentException(
"Cannot change the route segment connectivity when it has related equipment.");
}
}

foreach (var modifiedEvent in infoModifiedEvents)
{
Expand Down

0 comments on commit c494f2c

Please sign in to comment.