Skip to content

Commit

Permalink
Merge pull request #12 from DEFRA/feature/cdms-182
Browse files Browse the repository at this point in the history
rearranged domain services, added decisions skeleton
  • Loading branch information
tstesyn authored Dec 10, 2024
2 parents 315714c + 64c8d7c commit 6ea885a
Show file tree
Hide file tree
Showing 30 changed files with 260 additions and 18 deletions.
19 changes: 19 additions & 0 deletions Btms.Business.Tests/Services/Decisions/DecisionServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Btms.Business.Services.Decisions;
using Xunit;

namespace Btms.Business.Tests.Services.Decisions;

public class DecisionServiceTests
{
[Fact]
public async Task DeriveDecision()
{
// Arrange
var sut = new DecisionService();

// Act

// Assert
await Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Btms.Business.Services.Decisions.Finders;
using Xunit;

namespace Btms.Business.Tests.Services.Decisions.Finders;

public class ChedADecisionFinderTests
{
[Fact]
public async Task Find_Should_DoThings()
{
// Arrange
var sut = new ChedADecisionFinder();

// Act

// Assert
await Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Btms.Business.Services.Decisions.Finders;
using Xunit;

namespace Btms.Business.Tests.Services.Decisions.Finders;

public class ChedDDecisionFinderTests
{
[Fact]
public async Task Find_Should_DoThings()
{
// Arrange
var sut = new ChedDDecisionFinder();

// Act

// Assert
await Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Btms.Business.Services.Decisions.Finders;
using Xunit;

namespace Btms.Business.Tests.Services.Decisions.Finders;

public class ChedPDecisionFinderTests
{
[Fact]
public async Task Find_Should_DoThings()
{
// Arrange
var sut = new ChedPDecisionFinder();

// Act

// Assert
await Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Btms.Business.Services.Decisions.Finders;
using Xunit;

namespace Btms.Business.Tests.Services.Decisions.Finders;

public class ChedPPDecisionFinderTests
{
[Fact]
public async Task Find_Should_DoThings()
{
// Arrange
var sut = new ChedPPDecisionFinder();

// Act

// Assert
await Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Btms.Backend.Data;
using Btms.Backend.Data.InMemory;
using Btms.Business.Services;
using Btms.Business.Services.Linking;
using Btms.Metrics;
using Btms.Model.Alvs;
using Btms.Model.ChangeLog;
Expand All @@ -12,7 +12,7 @@
using Items = Btms.Model.Alvs.Items;
using Movement = Btms.Model.Movement;

namespace Btms.Business.Tests.Services;
namespace Btms.Business.Tests.Services.Linking;

public class LinkingServiceTests
{
Expand Down
4 changes: 4 additions & 0 deletions Btms.Business/Btms.Business.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@
<ProjectReference Include="..\Btms.Types.Ipaffs.V1\Btms.Types.Ipaffs.V1.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Services\Matching\" />
</ItemGroup>

</Project>
4 changes: 3 additions & 1 deletion Btms.Business/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Btms.Business.Pipelines;
using Btms.Business.Pipelines.Matching;
using Btms.Business.Pipelines.Matching.Rules;
using Btms.Business.Services;
using Btms.Backend.Data.Extensions;
using Btms.BlobService;
using Btms.BlobService.Extensions;
Expand All @@ -14,6 +13,8 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Btms.Business.Pipelines.PreProcessing;
using Btms.Business.Services.Decisions;
using Btms.Business.Services.Linking;
using Btms.Types.Alvs;

namespace Btms.Business.Extensions
Expand Down Expand Up @@ -61,6 +62,7 @@ public static IServiceCollection AddBusinessServices(this IServiceCollection ser
});

services.AddScoped<ILinkingService, LinkingService>();
services.AddScoped<IDecisionService, DecisionService>();

services.AddScoped<IPreProcessor<ImportNotification, Model.Ipaffs.ImportNotification>, ImportNotificationPreProcessor>();
services.AddScoped<IPreProcessor<AlvsClearanceRequest, Model.Movement>, MovementPreProcessor>();
Expand Down
15 changes: 15 additions & 0 deletions Btms.Business/Services/Decisions/DecisionCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Btms.Business.Services.Decisions;

public enum DecisionCode
{
E03,
C03,
C05,
C06,
C07,
C08,
N02,
N03,
N04,
N07
}
10 changes: 10 additions & 0 deletions Btms.Business/Services/Decisions/DecisionContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Btms.Model;
using Btms.Model.Ipaffs;

namespace Btms.Business.Services.Decisions;

public class DecisionContext
{
public List<ImportNotification> Notifications { get; set; } = new();
public List<Movement> Movements { get; set; } = new();
}
3 changes: 3 additions & 0 deletions Btms.Business/Services/Decisions/DecisionResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Btms.Business.Services.Decisions;

public record DecisionResult(DecisionCode DecisionCode);
58 changes: 58 additions & 0 deletions Btms.Business/Services/Decisions/DecisionService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Btms.Business.Services.Decisions.Finders;
using Btms.Model.Ipaffs;

namespace Btms.Business.Services.Decisions;

public class DecisionService : IDecisionService
{
public async Task<DecisionResult> DeriveDecision(DecisionContext decisionContext)
{
// Validate and prerequisite checks

var decisions = decisionContext.Notifications.Select(x => (x.Id, GetDecision(x))).ToList();

foreach (var movement in decisionContext.Movements)
{
// Generate list matched items -> decisions

foreach (var item in movement.Items)
{
// check decisions list for match reference, if no match then drop out with "no-match"

}

// Return decision based on prioritisation from confluence
}

await Task.CompletedTask;
return new DecisionResult(DecisionCode.N02);
}

private DecisionResult GetDecision(ImportNotification notification)
{
// get decision finder - fold IUU stuff into the decision finder for fish?
IDecisionFinder finder;
switch (notification.ImportNotificationType)
{
case ImportNotificationTypeEnum.Ced:
finder = new ChedDDecisionFinder();
break;

case ImportNotificationTypeEnum.Cveda:
finder = new ChedADecisionFinder();
break;

case ImportNotificationTypeEnum.Cvedp:
finder = new ChedPDecisionFinder();
break;

case ImportNotificationTypeEnum.Chedpp:
finder = new ChedPPDecisionFinder();
break;

default: throw new InvalidOperationException("Invalid ImportNotificationType");
}

return finder.FindDecision(notification);
}
}
11 changes: 11 additions & 0 deletions Btms.Business/Services/Decisions/Finders/ChedADecisionFinder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Btms.Model.Ipaffs;

namespace Btms.Business.Services.Decisions.Finders;

public class ChedADecisionFinder : IDecisionFinder
{
public DecisionResult FindDecision(ImportNotification notification)
{
throw new NotImplementedException();
}
}
11 changes: 11 additions & 0 deletions Btms.Business/Services/Decisions/Finders/ChedDDecisionFinder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Btms.Model.Ipaffs;

namespace Btms.Business.Services.Decisions.Finders;

public class ChedDDecisionFinder : IDecisionFinder
{
public DecisionResult FindDecision(ImportNotification notification)
{
throw new NotImplementedException();
}
}
11 changes: 11 additions & 0 deletions Btms.Business/Services/Decisions/Finders/ChedPDecisionFinder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Btms.Model.Ipaffs;

namespace Btms.Business.Services.Decisions.Finders;

public class ChedPDecisionFinder : IDecisionFinder
{
public DecisionResult FindDecision(ImportNotification notification)
{
throw new NotImplementedException();
}
}
11 changes: 11 additions & 0 deletions Btms.Business/Services/Decisions/Finders/ChedPPDecisionFinder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Btms.Model.Ipaffs;

namespace Btms.Business.Services.Decisions.Finders;

public class ChedPPDecisionFinder : IDecisionFinder
{
public DecisionResult FindDecision(ImportNotification notification)
{
throw new NotImplementedException();
}
}
8 changes: 8 additions & 0 deletions Btms.Business/Services/Decisions/Finders/IDecisionFinder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Btms.Model.Ipaffs;

namespace Btms.Business.Services.Decisions.Finders;

public interface IDecisionFinder
{
DecisionResult FindDecision(ImportNotification notification);
}
6 changes: 6 additions & 0 deletions Btms.Business/Services/Decisions/IDecisionService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Btms.Business.Services.Decisions;

public interface IDecisionService
{
public Task<DecisionResult> DeriveDecision(DecisionContext decisionContext);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

namespace Btms.Business.Services;
namespace Btms.Business.Services.Linking;

public interface ILinkingService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Btms.Model.ChangeLog;
using Btms.Model.Ipaffs;

namespace Btms.Business.Services;
namespace Btms.Business.Services.Linking;

public record ImportNotificationLinkContext(ImportNotification PersistedImportNotification, ChangeSet? ChangeSet) : LinkContext
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Btms.Model.ChangeLog;
using Btms.Model.Ipaffs;

namespace Btms.Business.Services;
namespace Btms.Business.Services.Linking;

public abstract record LinkContext
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace Btms.Business.Services;
namespace Btms.Business.Services.Linking;

public class LinkException(Exception inner) : Exception("Failed to link", inner);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Btms.Business.Services;
namespace Btms.Business.Services.Linking;

public enum LinkOutcome
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Btms.Model;
using Btms.Model.Ipaffs;

namespace Btms.Business.Services;
namespace Btms.Business.Services.Linking;

public class LinkResult(LinkOutcome state)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using System.Text.RegularExpressions;
using Btms.Backend.Data;
using Btms.Backend.Data.Extensions;
using Btms.Common.Extensions;
using Btms.Metrics;
using Btms.Model;
using Btms.Model.ChangeLog;
using Btms.Model.Ipaffs;
using Btms.Model.Relationships;
using Json.Patch;
using Microsoft.Extensions.Logging;

namespace Btms.Business.Services;
namespace Btms.Business.Services.Linking;

public static partial class LinkingServiceLogging
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Btms.Model;
using Btms.Model.ChangeLog;

namespace Btms.Business.Services;
namespace Btms.Business.Services.Linking;

public record MovementLinkContext(Movement PersistedMovement, ChangeSet? ChangeSet) : LinkContext
{
Expand Down
2 changes: 1 addition & 1 deletion Btms.Consumers.Tests/ClearanceRequestConsumerTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Btms.Business.Pipelines.PreProcessing;
using Btms.Business.Services;
using Btms.Business.Services.Linking;
using Btms.Consumers.Extensions;
using Btms.Model;
using Btms.Model.Auditing;
Expand Down
Loading

0 comments on commit 6ea885a

Please sign in to comment.