Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

now sends out the correct issue doing a rollback for when connectivity #113

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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