Skip to content

Commit

Permalink
chore: restructor incoming message module (#1398)
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsDue authored Nov 28, 2024
1 parent 6a12bc2 commit c1c3c8c
Show file tree
Hide file tree
Showing 310 changed files with 1,181 additions and 1,855 deletions.
8 changes: 4 additions & 4 deletions source/ArchitectureTests/RegistrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
using Energinet.DataHub.EDI.BuildingBlocks.Infrastructure.Configuration.Options;
using Energinet.DataHub.EDI.BuildingBlocks.Infrastructure.DataAccess;
using Energinet.DataHub.EDI.DataAccess.UnitOfWork;
using Energinet.DataHub.EDI.IncomingMessages.Domain.MessageParsers;
using Energinet.DataHub.EDI.IncomingMessages.Domain.MessageParsers.RSM017;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.Configuration.DataAccess;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.Configuration.Options;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers.WholesaleSettlementMessageParsers;
using Energinet.DataHub.EDI.MasterData.Infrastructure.DataAccess;
using Energinet.DataHub.EDI.Outbox.Infrastructure;
using Energinet.DataHub.EDI.OutgoingMessages.Application.UseCases;
Expand Down Expand Up @@ -126,10 +126,10 @@ public static IEnumerable<object[]> GetDocumentWritersRequirements()
public static IEnumerable<object[]> GetMessageParserRequirements()
{
return ResolveTypesThatImplementType(
typeof(IMarketMessageParser),
typeof(IMessageParser),
new[]
{
typeof(OldWholesaleSettlementJsonMessageParser).Assembly,
typeof(WholesaleSettlementJsonMessageParser).Assembly,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,4 @@ public enum FeatureFlagName
/// Whether to use orchestration for handling RequestWholesaleServices processes.
/// </summary>
UseRequestWholesaleServicesProcessOrchestration,

/// <summary>
/// Whether to use the new incoming message parser.
/// </summary>
UseNewIncomingMessageParser,
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,4 @@ public interface IFeatureFlagManager
/// Whether to use the RequestWholesaleServices process orchestration.
/// </summary>
Task<bool> UseRequestWholesaleServicesProcessOrchestrationAsync();

/// <summary>
/// Whether to use the new incoming message parser.
/// </summary>
Task<bool> UseNewIncomingMessageParserAsync();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,5 @@ public MicrosoftFeatureFlagManager(IFeatureManager featureManager)
public Task<bool> UseRequestWholesaleServicesProcessOrchestrationAsync() =>
IsEnabledAsync(FeatureFlagName.UseRequestWholesaleServicesProcessOrchestration);

public Task<bool> UseNewIncomingMessageParserAsync() => IsEnabledAsync(FeatureFlagName.UseNewIncomingMessageParser);

private Task<bool> IsEnabledAsync(FeatureFlagName featureFlagName) => _featureManager.IsEnabledAsync(featureFlagName.ToString());
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,4 @@ public class FeatureFlagManagerStub : IFeatureFlagManager
public Task<bool> ReceiveMeteredDataForMeasurementPointsAsync() => Task.FromResult(true);

public Task<bool> UseRequestWholesaleServicesProcessOrchestrationAsync() => Task.FromResult(false);

public Task<bool> UseNewIncomingMessageParserAsync() => Task.FromResult(true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,23 @@
using Energinet.DataHub.Core.Messaging.Communication.Extensions.Builder;
using Energinet.DataHub.Core.Messaging.Communication.Extensions.DependencyInjection;
using Energinet.DataHub.Core.Messaging.Communication.Extensions.Options;
using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models;
using Energinet.DataHub.EDI.BuildingBlocks.Infrastructure.Extensions.DependencyInjection;
using Energinet.DataHub.EDI.DataAccess.Extensions.DependencyInjection;
using Energinet.DataHub.EDI.IncomingMessages.Application.UseCases;
using Energinet.DataHub.EDI.IncomingMessages.Domain.MessageParsers;
using Energinet.DataHub.EDI.IncomingMessages.Domain.MessageParsers.RSM012;
using Energinet.DataHub.EDI.IncomingMessages.Domain.MessageParsers.RSM016;
using Energinet.DataHub.EDI.IncomingMessages.Domain.MessageParsers.RSM017;
using Energinet.DataHub.EDI.IncomingMessages.Domain.Schemas.Cim.Json;
using Energinet.DataHub.EDI.IncomingMessages.Domain.Schemas.Cim.Xml;
using Energinet.DataHub.EDI.IncomingMessages.Domain.Schemas.Ebix;
using Energinet.DataHub.EDI.IncomingMessages.Domain.Validation;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.Configuration.DataAccess;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.Configuration.Options;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers.AggregatedMeasureDataRequestMessageParsers;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers.MeteredDateForMeasurementPointParsers;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers.MeteredDateForMeasurementPointParsers.Ebix;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers.WholesaleSettlementMessageParsers;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.Repositories.MessageId;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.Repositories.TransactionId;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.Response;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.Schemas.Cim.Json;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.Schemas.Cim.Xml;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.Schemas.Ebix;
using Energinet.DataHub.EDI.IncomingMessages.Interfaces;
using Microsoft.Extensions.Azure;
using Microsoft.Extensions.Configuration;
Expand All @@ -61,14 +59,6 @@ public static IServiceCollection AddIncomingMessagesModule(this IServiceCollecti
.AddScoped<DelegateIncomingMessage>()
.AddScoped<ITransactionIdRepository, TransactionIdRepository>()
.AddScoped<IMessageIdRepository, MessageIdRepository>()
.AddScoped<IMarketMessageParser, OldAggregatedMeasureDataXmlMessageParser>()
.AddScoped<IMarketMessageParser, OldAggregatedMeasureDataJsonMessageParser>()
.AddScoped<IMarketMessageParser, OldAggregatedMeasureDataB2CJsonMessageParser>()
.AddScoped<IMarketMessageParser, OldWholesaleSettlementJsonMessageParser>()
.AddScoped<IMarketMessageParser, OldWholesaleSettlementXmlMessageParser>()
.AddScoped<IMarketMessageParser, OldWholesaleSettlementB2CJsonMessageParser>()
.AddScoped<IMarketMessageParser, MeteredDataForMeasurementPointEbixMessageParser>()
.AddScoped<MarketMessageParser>()
.AddScoped<ISenderAuthorizer, SenderAuthorizer>()
.AddScoped<ValidateIncomingMessage>()
.AddSingleton<IProcessTypeValidator, ProcessTypeValidator>()
Expand Down Expand Up @@ -142,11 +132,11 @@ public static IServiceCollection AddIncomingMessagesModule(this IServiceCollecti

services.AddTransient<IMessageParser, WholesaleSettlementXmlMessageParser>();
services.AddTransient<IMessageParser, WholesaleSettlementJsonMessageParser>();
services.AddTransient<IMessageParser, WholesaleSettlementB2CJsonMessageParserBase>();
services.AddTransient<IMessageParser, WholesaleSettlementB2CJsonMessageParser>();

services.AddTransient<IMessageParser, AggregatedMeasureDataXmlMessageParser>();
services.AddTransient<IMessageParser, AggregatedMeasureDataJsonMessageParser>();
services.AddTransient<IMessageParser, AggregatedMeasureDataB2CJsonMessageParserBase>();
services.AddTransient<IMessageParser, AggregatedMeasureDataB2CJsonMessageParser>();

return services;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models;
using Energinet.DataHub.EDI.BuildingBlocks.Infrastructure.FeatureFlag;
using Energinet.DataHub.EDI.IncomingMessages.Domain.Abstractions;
using Energinet.DataHub.EDI.IncomingMessages.Domain.MessageParsers;
using Energinet.DataHub.EDI.IncomingMessages.Domain.Validation;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.Response;
using Energinet.DataHub.EDI.IncomingMessages.Interfaces.Models;
using Microsoft.Extensions.Logging;
Expand All @@ -31,7 +31,6 @@ namespace Energinet.DataHub.EDI.IncomingMessages.Application.UseCases;

public class ReceiveIncomingMarketMessage
{
private readonly MarketMessageParser _marketMessageParser;
private readonly IDictionary<(IncomingDocumentType, DocumentFormat), IMessageParser> _messageParsers;
private readonly IFeatureFlagManager _featureFlagManager;
private readonly ValidateIncomingMessage _validateIncomingMessage;
Expand All @@ -44,7 +43,6 @@ public class ReceiveIncomingMarketMessage
private readonly AuthenticatedActor _actorAuthenticator;

public ReceiveIncomingMarketMessage(
MarketMessageParser marketMessageParser,
IEnumerable<IMessageParser> messageParsers,
IFeatureFlagManager featureFlagManager,
ValidateIncomingMessage validateIncomingMessage,
Expand All @@ -56,7 +54,6 @@ public ReceiveIncomingMarketMessage(
IClock clock,
AuthenticatedActor actorAuthenticator)
{
_marketMessageParser = marketMessageParser;
_messageParsers = messageParsers
.ToDictionary(
parser => (parser.DocumentType, parser.DocumentFormat),
Expand Down Expand Up @@ -111,8 +108,8 @@ await ArchiveIncomingMessageAsync(
}

await _delegateIncomingMessage
.DelegateAsync(incomingMarketMessageParserResult.IncomingMessage, documentType, cancellationToken)
.ConfigureAwait(false);
.DelegateAsync(incomingMarketMessageParserResult.IncomingMessage, documentType, cancellationToken)
.ConfigureAwait(false);

var validationResult = await _validateIncomingMessage
.ValidateAsync(incomingMarketMessageParserResult.IncomingMessage, incomingDocumentFormat, cancellationToken)
Expand All @@ -129,8 +126,8 @@ await _delegateIncomingMessage

var result = await _incomingMessageReceiver
.ReceiveAsync(
incomingMarketMessageParserResult.IncomingMessage,
cancellationToken)
incomingMarketMessageParserResult.IncomingMessage,
cancellationToken)
.ConfigureAwait(false);

if (result.Success)
Expand All @@ -156,16 +153,12 @@ private async Task<IncomingMarketMessageParserResult> ParseIncomingMessageAsync(
IncomingDocumentType documentType,
CancellationToken cancellationToken)
{
if (await _featureFlagManager.UseNewIncomingMessageParserAsync().ConfigureAwait(false))
if (_messageParsers.TryGetValue((documentType, documentFormat), out var messageParser))
{
if (_messageParsers.TryGetValue((documentType, documentFormat), out var messageParser))
{
return await messageParser.ParseAsync(incomingMarketMessageStream, cancellationToken).ConfigureAwait(false);
}
return await messageParser.ParseAsync(incomingMarketMessageStream, cancellationToken).ConfigureAwait(false);
}

return await _marketMessageParser.ParseAsync(incomingMarketMessageStream, documentFormat, documentType, cancellationToken)
.ConfigureAwait(false);
throw new NotSupportedException($"No message parser found for message format '{documentFormat}' and document type '{documentType}'");
}

private async Task ArchiveIncomingMessageAsync(
Expand All @@ -176,19 +169,20 @@ private async Task ArchiveIncomingMessageAsync(
{
var authenticatedActor = _actorAuthenticator.CurrentActorIdentity;
await _archivedMessagesClient.CreateAsync(
new ArchivedMessageDto(
incomingMessage.MessageId,
incomingDocumentType.Name,
authenticatedActor.ActorNumber,
authenticatedActor.ActorRole,
// For RequestAggregatedMeteringData and RequestWholesaleServices,
// the receiver is Metered Data Administrator
DataHubDetails.DataHubActorNumber,
ActorRole.MeteredDataAdministrator,
_clock.GetCurrentInstant(),
incomingMessage.BusinessReason,
ArchivedMessageTypeDto.IncomingMessage,
incomingMarketMessageStream),
cancellationToken).ConfigureAwait(false);
new ArchivedMessageDto(
incomingMessage.MessageId,
incomingDocumentType.Name,
authenticatedActor.ActorNumber,
authenticatedActor.ActorRole,
// For RequestAggregatedMeteringData and RequestWholesaleServices,
// the receiver is Metered Data Administrator
DataHubDetails.DataHubActorNumber,
ActorRole.MeteredDataAdministrator,
_clock.GetCurrentInstant(),
incomingMessage.BusinessReason,
ArchivedMessageTypeDto.IncomingMessage,
incomingMarketMessageStream),
cancellationToken)
.ConfigureAwait(false);
}
}
Loading

0 comments on commit c1c3c8c

Please sign in to comment.