Skip to content

Commit

Permalink
Fixes a load of sonarqube issues (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigedmunds authored Jan 24, 2025
1 parent 623db86 commit 2bd01e0
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 83 deletions.
10 changes: 6 additions & 4 deletions Btms.Consumers/Extensions/MessageRoutingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace Btms.Consumers.Extensions;
/// </summary>
public static class MessageRoutingExtensions
{
private const string MESSAGE_ID_HEADER_KEY = "messageId";

public static async Task PushToConsumers(this IServiceProvider sp,
ILogger logger, IEnumerable<object> messages,
int sleepMs = 1000, bool synchronous = false)
Expand Down Expand Up @@ -47,25 +49,25 @@ public static async Task PushMessagesToConsumers(this IServiceProvider sp,
throw new ArgumentNullException();

case ImportNotification n:
headers.Add("messageId", n.ReferenceNumber!);
headers.Add(MESSAGE_ID_HEADER_KEY, n.ReferenceNumber!);
await bus.Publish(n, "NOTIFICATIONS", headers);
logger.LogInformation("Sent notification {0} to consumer", n.ReferenceNumber!);
break;

case AlvsClearanceRequest cr:
headers.Add("messageId", cr.Header!.EntryReference!);
headers.Add(MESSAGE_ID_HEADER_KEY, cr.Header!.EntryReference!);
await bus.Publish(cr, "CLEARANCEREQUESTS", headers);
logger.LogInformation("Sent cr {0} to consumer", cr.Header!.EntryReference!);
break;

case Decision d:
headers.Add("messageId", d.Header!.EntryReference!);
headers.Add(MESSAGE_ID_HEADER_KEY, d.Header!.EntryReference!);
await bus.Publish(d, "DECISIONS", headers);
logger.LogInformation("Sent decision {0} to consumer", d.Header!.EntryReference!);
break;

case Finalisation d:
headers.Add("messageId", d.Header!.EntryReference!);
headers.Add(MESSAGE_ID_HEADER_KEY, d.Header!.EntryReference!);
await bus.Publish(d, "FINALISATIONS", headers);
logger.LogInformation("Sent finalisation {0} to consumer", d.Header!.EntryReference!);
break;
Expand Down
11 changes: 3 additions & 8 deletions Btms.Types.Alvs.V1/Finalisation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

namespace Btms.Types.Alvs;

public class Finalisation //
public class Finalisation
{


/// <summary>
///
/// </summary>
Expand All @@ -25,9 +23,8 @@ public class Finalisation //
public required FinalisationHeader Header { get; set; }
}

public partial class FinalisationHeader //
public partial class FinalisationHeader
{

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -57,6 +54,4 @@ public partial class FinalisationHeader //
/// </summary
[JsonPropertyName("manualAction")]
public required string ManualAction { get; set; }

}

}
7 changes: 4 additions & 3 deletions TestDataGenerator/Extensions/ScenarioGeneratorExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Btms.Types.Alvs;
using Btms.Types.Ipaffs;
using TestDataGenerator.Helpers;
using TestDataGenerator.Scenarios;

namespace TestDataGenerator.Extensions;
Expand All @@ -8,7 +9,7 @@ public static class IScenarioGeneratorExtensions
{
public static ImportNotificationBuilder<ImportNotification> GetSimpleNotification(this ScenarioGenerator generator, int scenario, int item, DateTime entryDate, ScenarioConfig config)
{
return generator.GetNotificationBuilder("chedp-one-commodity")
return BuilderHelpers.GetNotificationBuilder("chedp-one-commodity")
.WithCreationDate(entryDate)
.WithRandomArrivalDateTime(config.ArrivalDateRange)
.WithReferenceNumber(ImportNotificationTypeEnum.Cvedp, scenario, entryDate, item)
Expand All @@ -20,7 +21,7 @@ public static ImportNotificationBuilder<ImportNotification> GetSimpleNotificatio

public static ClearanceRequestBuilder<AlvsClearanceRequest> GetSimpleClearanceRequest(this ScenarioGenerator generator, int scenario, int item, DateTime entryDate, ScenarioConfig config, ImportNotification notification)
{
return generator.GetClearanceRequestBuilder("cr-one-item")
return BuilderHelpers.GetClearanceRequestBuilder("cr-one-item")
.WithCreationDate(entryDate.AddHours(2), false)
.WithArrivalDateTimeOffset(notification.PartOne!.ArrivalDate, notification.PartOne!.ArrivalTime)
.WithReferenceNumberOneToOne(notification.ReferenceNumber!)
Expand All @@ -30,7 +31,7 @@ public static ClearanceRequestBuilder<AlvsClearanceRequest> GetSimpleClearanceRe

public static DecisionBuilder<Btms.Types.Alvs.Decision> GetSimpleDecision(this ScenarioGenerator generator, int scenario, int item, DateTime entryDate, ScenarioConfig config, ImportNotification notification, AlvsClearanceRequest clearanceRequest)
{
return generator.GetDecisionBuilder("decision-one-item")
return BuilderHelpers.GetDecisionBuilder("decision-one-item")
.WithCreationDate(clearanceRequest.ServiceHeader!.ServiceCallTimestamp!.Value.AddHours(1), false)
.WithReferenceNumber(notification.ReferenceNumber!)
.WithEntryVersionNumber(1)
Expand Down
11 changes: 6 additions & 5 deletions TestDataGenerator/Helpers/BuilderHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ public static class BuilderHelpers
{
private static readonly string fullFolder =
$"{Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)}/Scenarios/Samples";

internal static ClearanceRequestBuilder GetClearanceRequestBuilder(string file, string fileExtension = ".json")
private const string JSON_FILE_EXTENSION = ".json";

internal static ClearanceRequestBuilder GetClearanceRequestBuilder(string file, string fileExtension = JSON_FILE_EXTENSION)
{
// return BuilderHelpers.GetClearanceRequestBuilder(file, fileExtension);
var fullPath = $"{fullFolder}/{file}{fileExtension}";
Expand All @@ -16,23 +17,23 @@ internal static ClearanceRequestBuilder GetClearanceRequestBuilder(string file,
return builder;
}

internal static FinalisationBuilder GetFinalisationBuilder(string file, string fileExtension = ".json")
internal static FinalisationBuilder GetFinalisationBuilder(string file, string fileExtension = JSON_FILE_EXTENSION)
{
var fullPath = $"{fullFolder}/{file}{fileExtension}";
var builder = new FinalisationBuilder(fullPath);

return builder;
}

internal static DecisionBuilder GetDecisionBuilder(string file, string fileExtension = ".json")
internal static DecisionBuilder GetDecisionBuilder(string file, string fileExtension = JSON_FILE_EXTENSION)
{
var fullPath = $"{fullFolder}/{file}{fileExtension}";
var builder = new DecisionBuilder(fullPath);

return builder;
}

internal static ImportNotificationBuilder<ImportNotification> GetNotificationBuilder(string file, string fileExtension = ".json")
internal static ImportNotificationBuilder<ImportNotification> GetNotificationBuilder(string file, string fileExtension = JSON_FILE_EXTENSION)
{
var fullPath = $"{fullFolder}/{file}{fileExtension}";
var builder = ImportNotificationBuilder.FromFile(fullPath);
Expand Down
18 changes: 10 additions & 8 deletions TestDataGenerator/Helpers/DataHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace TestDataGenerator.Helpers;

public static class DataHelpers
{
private const string PATH_DATE_FORMAT = "yyyy/MM/dd";

internal static string BlobPath(this object resource, string rootPath)
{
switch (resource)
Expand All @@ -36,14 +38,9 @@ private static string BlobPath(this ImportNotification notification, string root
return $"{rootPath}/IPAFFS/{notification.ImportNotificationType!.Value.AsString()}/{dateString}/{notification.ReferenceNumber!.Replace(".", "_")}-{Guid.NewGuid()}.json";
}

private static string DateRef(this DateTime created)
{
return created.ToString("MMdd");
}

private static string BlobPath(this AlvsClearanceRequest clearanceRequest, string rootPath)
{
var dateString = clearanceRequest.ServiceHeader!.ServiceCallTimestamp!.Value.ToString("yyyy/MM/dd");
var dateString = clearanceRequest.ServiceHeader!.ServiceCallTimestamp!.Value.ToString(PATH_DATE_FORMAT);
var subPath = "ALVS";

return
Expand All @@ -52,7 +49,7 @@ private static string BlobPath(this AlvsClearanceRequest clearanceRequest, strin

private static string BlobPath(this Decision decision, string rootPath)
{
var dateString = decision.ServiceHeader!.ServiceCallTimestamp!.Value.ToString("yyyy/MM/dd");
var dateString = decision.ServiceHeader!.ServiceCallTimestamp!.Value.ToString(PATH_DATE_FORMAT);
var subPath = "DECISIONS";

return
Expand All @@ -61,13 +58,18 @@ private static string BlobPath(this Decision decision, string rootPath)

private static string BlobPath(this Finalisation finalisation, string rootPath)
{
var dateString = finalisation.ServiceHeader!.ServiceCallTimestamp!.Value.ToString("yyyy/MM/dd");
var dateString = finalisation.ServiceHeader!.ServiceCallTimestamp!.Value.ToString(PATH_DATE_FORMAT);
var subPath = "FINALISATION";

return
$"{rootPath}/{subPath}/{dateString}/{finalisation.Header!.EntryReference!.Replace(".", "")}-{Guid.NewGuid()}.json";
}

private static string DateRef(this DateTime created)
{
return created.ToString("MMdd");
}

internal static string AsCdsEntryReference(this MatchIdentifier identifier)
{
return $"23GB9999{identifier.Identifier}";
Expand Down
27 changes: 0 additions & 27 deletions TestDataGenerator/ScenarioGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,6 @@ public abstract class ScenarioGenerator

public abstract GeneratorResult Generate(int scenario, int item, DateTime entryDate, ScenarioConfig config);

//TODO : remove these Get methods...
internal ImportNotificationBuilder<ImportNotification> GetNotificationBuilder(string file, string fileExtension = ".json")
{
var fullPath = $"{_fullFolder}/{file}{fileExtension}";
var builder = ImportNotificationBuilder.FromFile(fullPath);

return builder;
}

internal ClearanceRequestBuilder GetClearanceRequestBuilder(string file, string fileExtension = ".json")
{
return BuilderHelpers.GetClearanceRequestBuilder(file, fileExtension);
}

internal FinalisationBuilder GetFinalisationBuilder(string file, string fileExtension = ".json")
{
return BuilderHelpers.GetFinalisationBuilder(file, fileExtension);
}

internal DecisionBuilder GetDecisionBuilder(string file, string fileExtension = ".json")
{
var fullPath = $"{_fullFolder}/{file}{fileExtension}";
var builder = new DecisionBuilder(fullPath);

return builder;
}

/// <summary>
/// A class to hold a list of message types we support. Would be nice to use something
/// other than object :|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Btms.Types.Ipaffs;
using Microsoft.Extensions.Logging;
using TestDataGenerator.Helpers;

namespace TestDataGenerator.Scenarios;

Expand All @@ -8,7 +9,7 @@ public class ChedAManyCommoditiesScenarioGenerator(ILogger<ChedAManyCommoditiesS
{
public override GeneratorResult Generate(int scenario, int item, DateTime entryDate, ScenarioConfig config)
{
var notification = GetNotificationBuilder("cheda-one-commodity")
var notification = BuilderHelpers.GetNotificationBuilder("cheda-one-commodity")
.WithCreationDate(entryDate)
.WithRandomArrivalDateTime(config.ArrivalDateRange)
.WithReferenceNumber(ImportNotificationTypeEnum.Cveda, scenario, entryDate, item)
Expand All @@ -20,7 +21,7 @@ public override GeneratorResult Generate(int scenario, int item, DateTime entryD
logger.LogInformation("Created {NotificationReferenceNumber}",
notification.ReferenceNumber);

var clearanceRequest = GetClearanceRequestBuilder("cr-one-item")
var clearanceRequest = BuilderHelpers.GetClearanceRequestBuilder("cr-one-item")
.WithCreationDate(entryDate)
.WithArrivalDateTimeOffset(notification.PartOne!.ArrivalDate, notification.PartOne!.ArrivalTime)
.WithReferenceNumberOneToOne(notification.ReferenceNumber!)
Expand Down
3 changes: 2 additions & 1 deletion TestDataGenerator/Scenarios/ChedANoMatchScenarioGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using Btms.Types.Ipaffs;
using Microsoft.Extensions.Logging;
using TestDataGenerator.Helpers;

namespace TestDataGenerator.Scenarios;

public class ChedANoMatchScenarioGenerator(ILogger<ChedANoMatchScenarioGenerator> logger) : ScenarioGenerator
{
public override GeneratorResult Generate(int scenario, int item, DateTime entryDate, ScenarioConfig config)
{
var notification = GetNotificationBuilder("cheda-one-commodity")
var notification = BuilderHelpers.GetNotificationBuilder("cheda-one-commodity")
.WithCreationDate(entryDate)
.WithRandomArrivalDateTime(config.ArrivalDateRange)
.WithReferenceNumber(ImportNotificationTypeEnum.Cveda, scenario, entryDate, item)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using Btms.Types.Ipaffs;
using Microsoft.Extensions.Logging;
using TestDataGenerator.Helpers;

namespace TestDataGenerator.Scenarios;

public class ChedASimpleMatchScenarioGenerator(ILogger<ChedASimpleMatchScenarioGenerator> logger) : ScenarioGenerator
{
public override GeneratorResult Generate(int scenario, int item, DateTime entryDate, ScenarioConfig config)
{
var notification = GetNotificationBuilder("cheda-one-commodity")
var notification = BuilderHelpers.GetNotificationBuilder("cheda-one-commodity")
.WithCreationDate(entryDate)
.WithRandomArrivalDateTime(config.ArrivalDateRange)
.WithReferenceNumber(ImportNotificationTypeEnum.Cveda, scenario, entryDate, item)
Expand All @@ -17,15 +18,15 @@ public override GeneratorResult Generate(int scenario, int item, DateTime entryD
logger.LogInformation("Created {NotificationReferenceNumber}",
notification.ReferenceNumber);

var clearanceRequest = GetClearanceRequestBuilder("cr-one-item")
var clearanceRequest = BuilderHelpers.GetClearanceRequestBuilder("cr-one-item")
.WithCreationDate(entryDate)
.WithArrivalDateTimeOffset(notification.PartOne!.ArrivalDate, notification.PartOne!.ArrivalTime)
.WithReferenceNumberOneToOne(notification.ReferenceNumber!)
.WithDispatchCountryCode(notification.PartOne!.Route!.TransitingStates!.FirstOrDefault())
.WithEntryVersionNumber()
.ValidateAndBuild();

var finalisation = GetFinalisationBuilder("finalisation")
var finalisation = BuilderHelpers.GetFinalisationBuilder("finalisation")
.WithCreationDate(clearanceRequest.ServiceHeader!.ServiceCallTimestamp!.Value.AddHours(2), randomTime: false)
.WithReferenceNumber(notification.ReferenceNumber!)
.WithDecisionVersionNumber()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using Btms.Types.Ipaffs;
using Microsoft.Extensions.Logging;
using TestDataGenerator.Extensions;
using TestDataGenerator.Helpers;

namespace TestDataGenerator.Scenarios.ChedP;

public class ClearLinksDueToMrnDocumentRefChange(ILogger<ClearLinksDueToMrnDocumentRefChange> logger) : ScenarioGenerator
{
public override GeneratorResult Generate(int scenario, int item, DateTime entryDate, ScenarioConfig config)
{
var notification = GetNotificationBuilder("chedp-one-commodity")
var notification = BuilderHelpers.GetNotificationBuilder("chedp-one-commodity")
.WithCreationDate(entryDate)
.WithRandomArrivalDateTime(config.ArrivalDateRange)
.WithReferenceNumber(ImportNotificationTypeEnum.Cvedp, scenario, entryDate, item)
Expand All @@ -19,7 +20,7 @@ public override GeneratorResult Generate(int scenario, int item, DateTime entryD
logger.LogInformation("Created {NotificationReferenceNumber}",
notification.ReferenceNumber);

var clearanceRequestBuilder = GetClearanceRequestBuilder("cr-one-item")
var clearanceRequestBuilder = BuilderHelpers.GetClearanceRequestBuilder("cr-one-item")
.WithCreationDate(entryDate.AddHours(2), false)
.WithArrivalDateTimeOffset(notification.PartOne!.ArrivalDate, notification.PartOne!.ArrivalTime)
.WithReferenceNumberOneToOne(notification.ReferenceNumber!)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using Btms.Types.Ipaffs;
using Microsoft.Extensions.Logging;
using TestDataGenerator.Extensions;
using TestDataGenerator.Helpers;

namespace TestDataGenerator.Scenarios.ChedP;

public class DuplicateDecisionScenarioGenerator(ILogger<DuplicateDecisionScenarioGenerator> logger) : ScenarioGenerator
{
public override GeneratorResult Generate(int scenario, int item, DateTime entryDate, ScenarioConfig config)
{
var notification = GetNotificationBuilder("chedp-one-commodity")
var notification = BuilderHelpers.GetNotificationBuilder("chedp-one-commodity")
.WithCreationDate(entryDate)
.WithRandomArrivalDateTime(config.ArrivalDateRange)
.WithReferenceNumber(ImportNotificationTypeEnum.Cvedp, scenario, entryDate, item)
Expand All @@ -21,7 +22,7 @@ public override GeneratorResult Generate(int scenario, int item, DateTime entryD
notification.ReferenceNumber);


var clearanceRequest = GetClearanceRequestBuilder("cr-one-item")
var clearanceRequest = BuilderHelpers.GetClearanceRequestBuilder("cr-one-item")
.WithCreationDate(entryDate.AddHours(2), false)
.WithArrivalDateTimeOffset(notification.PartOne!.ArrivalDate, notification.PartOne!.ArrivalTime)
.WithReferenceNumberOneToOne(notification.ReferenceNumber!)
Expand All @@ -31,7 +32,7 @@ public override GeneratorResult Generate(int scenario, int item, DateTime entryD

logger.LogInformation("Created {EntryReference}", clearanceRequest.Header!.EntryReference);

var alvsDecision = GetDecisionBuilder("decision-one-item")
var alvsDecision = BuilderHelpers.GetDecisionBuilder("decision-one-item")
.WithCreationDate(clearanceRequest.ServiceHeader!.ServiceCallTimestamp!.Value.AddHours(1), false)
.WithReferenceNumber(notification.ReferenceNumber!)
.WithEntryVersionNumber(1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using Btms.Types.Ipaffs;
using Microsoft.Extensions.Logging;
using TestDataGenerator.Extensions;
using TestDataGenerator.Helpers;

namespace TestDataGenerator.Scenarios.ChedP;

public class MultiStepMovementScenarioGenerator(ILogger<MultiStepScenarioGenerator> logger) : ScenarioGenerator
{
public override GeneratorResult Generate(int scenario, int item, DateTime entryDate, ScenarioConfig config)
{
var notification1Builder = GetNotificationBuilder("chedp-one-commodity")
var notification1Builder = BuilderHelpers.GetNotificationBuilder("chedp-one-commodity")
.WithCreationDate(entryDate)
.WithRandomArrivalDateTime(config.ArrivalDateRange)
.WithReferenceNumber(ImportNotificationTypeEnum.Cvedp, scenario, entryDate, 1)
Expand All @@ -29,7 +30,7 @@ public override GeneratorResult Generate(int scenario, int item, DateTime entryD
logger.LogInformation("Created {NotificationReferenceNumber}",
notification2.ReferenceNumber);

var clearanceRequestBuilder = GetClearanceRequestBuilder("cr-one-item")
var clearanceRequestBuilder = BuilderHelpers.GetClearanceRequestBuilder("cr-one-item")
.WithCreationDate(entryDate.AddHours(2), false)
.WithArrivalDateTimeOffset(notification1.PartOne!.ArrivalDate, notification1.PartOne!.ArrivalTime)
.WithReferenceNumberOneToOne(notification1.ReferenceNumber!)
Expand Down
Loading

0 comments on commit 2bd01e0

Please sign in to comment.