From 4a9d8c10fd246e3f188b255206690b75f125cefd Mon Sep 17 00:00:00 2001 From: Mathias Ormstrup Bjerregaard Date: Wed, 4 Dec 2024 08:09:46 +0100 Subject: [PATCH] review comments 1 --- .../OutgoingMessageFactory.cs | 2 +- ...orMeasurementPointCimJsonDocumentWriter.cs | 46 ++++++++-------- .../IOutgoingMessagesClient.cs | 2 +- ...ataForMeasurementPointMessageProcessDto.cs | 35 ++++++------ ...zeMeteredDataForMeasurementPointHandler.cs | 54 ++++++++++--------- 5 files changed, 66 insertions(+), 73 deletions(-) diff --git a/source/OutgoingMessages.Application/OutgoingMessageFactory.cs b/source/OutgoingMessages.Application/OutgoingMessageFactory.cs index 2bae46ca3..a4388b351 100644 --- a/source/OutgoingMessages.Application/OutgoingMessageFactory.cs +++ b/source/OutgoingMessages.Application/OutgoingMessageFactory.cs @@ -401,7 +401,7 @@ public static OutgoingMessage CreateMessage( gridAreaCode: null, externalId: message.ExternalId, calculationId: null, - message.Series.OrderBy(s => s.StartedDateTime).First().StartedDateTime); + message.Series.StartedDateTime); } private static ActorRole GetChargeOwnerRole(ActorNumber chargeOwnerId) diff --git a/source/OutgoingMessages.Domain/DocumentWriters/RSM012/MeteredDateForMeasurementPointCimJsonDocumentWriter.cs b/source/OutgoingMessages.Domain/DocumentWriters/RSM012/MeteredDateForMeasurementPointCimJsonDocumentWriter.cs index 7e99bf87d..0a7498e30 100644 --- a/source/OutgoingMessages.Domain/DocumentWriters/RSM012/MeteredDateForMeasurementPointCimJsonDocumentWriter.cs +++ b/source/OutgoingMessages.Domain/DocumentWriters/RSM012/MeteredDateForMeasurementPointCimJsonDocumentWriter.cs @@ -64,32 +64,28 @@ private Document ParseFrom(OutgoingMessageHeader header, IReadOnlyCollection(); - foreach (var transaction in transactions) + foreach (var activityRecord in transactions.Select(t => _parser.From(t))) { - var activityRecords = _parser.From>(transaction); - foreach (var activityRecord in activityRecords) - { - meteredDataForMeasurementPoints.Add( - new MeteredDataForMeasurementPoint( - activityRecord.TransactionId, - activityRecord.MarketEvaluationPointNumber, - activityRecord.MarketEvaluationPointType, - activityRecord.OriginalTransactionIdReferenceId, - activityRecord.Product, - activityRecord.QuantityMeasureUnit, - activityRecord.RegistrationDateTime, - new Period( - activityRecord.Resolution.Code, - new TimeInterval( - activityRecord.StartedDateTime, - activityRecord.EndedDateTime), - activityRecord.EnergyObservations.Select( - p => new Point( - p.Position, - p.Quality, - p.Quantity)) - .ToList()))); - } + meteredDataForMeasurementPoints.Add( + new MeteredDataForMeasurementPoint( + activityRecord.TransactionId, + activityRecord.MarketEvaluationPointNumber, + activityRecord.MarketEvaluationPointType, + activityRecord.OriginalTransactionIdReferenceId, + activityRecord.Product, + activityRecord.QuantityMeasureUnit, + activityRecord.RegistrationDateTime, + new Period( + activityRecord.Resolution.Code, + new TimeInterval( + activityRecord.StartedDateTime, + activityRecord.EndedDateTime), + activityRecord.EnergyObservations.Select( + p => new Point( + p.Position, + p.Quality, + p.Quantity)) + .ToList()))); } return new Document( diff --git a/source/OutgoingMessages.Interfaces/IOutgoingMessagesClient.cs b/source/OutgoingMessages.Interfaces/IOutgoingMessagesClient.cs index 73e825798..88a7767fc 100644 --- a/source/OutgoingMessages.Interfaces/IOutgoingMessagesClient.cs +++ b/source/OutgoingMessages.Interfaces/IOutgoingMessagesClient.cs @@ -105,7 +105,7 @@ Task EnqueueAsync( Task EnqueueAsync(AcceptedWholesaleServicesMessageDto acceptedWholesaleServicesMessage, CancellationToken cancellationToken); /// - /// Enqueue metered data for measurement point messages, handles enqueuing messages to all appropriate parties (Receiver, ChargeOwner) in a single transaction. + /// Enqueue metered data for measurement point messages, handles enqueuing messages to all appropriate parties in a single transaction. /// Task EnqueueAndCommitAsync( MeteredDataForMeasurementPointMessageProcessDto meteredDataForMeasurementPointMessageProcessDto, diff --git a/source/OutgoingMessages.Interfaces/Models/MeteredDataForMeasurementPoint/MeteredDataForMeasurementPointMessageProcessDto.cs b/source/OutgoingMessages.Interfaces/Models/MeteredDataForMeasurementPoint/MeteredDataForMeasurementPointMessageProcessDto.cs index 2b4f7e995..700c927c5 100644 --- a/source/OutgoingMessages.Interfaces/Models/MeteredDataForMeasurementPoint/MeteredDataForMeasurementPointMessageProcessDto.cs +++ b/source/OutgoingMessages.Interfaces/Models/MeteredDataForMeasurementPoint/MeteredDataForMeasurementPointMessageProcessDto.cs @@ -16,25 +16,20 @@ namespace Energinet.DataHub.EDI.OutgoingMessages.Interfaces.Models.MeteredDataForMeasurementPoint; -public sealed class MeteredDataForMeasurementPointMessageProcessDto : OutgoingMessageDto +public sealed class MeteredDataForMeasurementPointMessageProcessDto( + EventId eventId, + Actor receiver, + BusinessReason businessReason, + MeteredDataForMeasurementPointMessageSeriesDto series) + : OutgoingMessageDto( + DocumentType.MeteredDataForMeasurementPoint, + receiver.ActorNumber, + null, + eventId, + businessReason.Name, + receiver.ActorRole, + new ExternalId(Guid.NewGuid()), + null) { - public MeteredDataForMeasurementPointMessageProcessDto( - EventId eventId, - Actor receiver, - BusinessReason businessReason, - IReadOnlyCollection series) - : base( - DocumentType.MeteredDataForMeasurementPoint, - receiver.ActorNumber, - null, - eventId, - businessReason.Name, - receiver.ActorRole, - new ExternalId(Guid.NewGuid()), - null) - { - Series = series; - } - - public IReadOnlyCollection Series { get; } + public MeteredDataForMeasurementPointMessageSeriesDto Series { get; } = series; } diff --git a/source/Process.Application/ProcessInitializationHandlers/InitializeMeteredDataForMeasurementPointHandler.cs b/source/Process.Application/ProcessInitializationHandlers/InitializeMeteredDataForMeasurementPointHandler.cs index 1fde0f88b..68133253b 100644 --- a/source/Process.Application/ProcessInitializationHandlers/InitializeMeteredDataForMeasurementPointHandler.cs +++ b/source/Process.Application/ProcessInitializationHandlers/InitializeMeteredDataForMeasurementPointHandler.cs @@ -58,34 +58,36 @@ public async Task ProcessAsync(byte[] processInitializationData) { await _outgoingMessagesClient.EnqueueAndCommitAsync( new MeteredDataForMeasurementPointMessageProcessDto( - EventId.From(marketMessage.MessageId), + EventId.From(Guid.NewGuid()), new Actor(series.RequestedByActor.ActorNumber, series.RequestedByActor.ActorRole), BusinessReason.FromCode(marketMessage.BusinessReason), - marketMessage.Series.Select( - s => new MeteredDataForMeasurementPointMessageSeriesDto( - TransactionId.From(s.TransactionId), - s.MeteringPointType!, - s.MeteringPointLocationId!, - null, - s.ProductNumber!, - s.ProductUnitType!, - marketMessage.CreatedAt, - Resolution.FromCode(s.Resolution!), - InstantPattern.Create("yyyy-MM-ddTHH:mm'Z'", CultureInfo.InvariantCulture) - .Parse(s.StartDateTime) - .Value, - s.EndDateTime != null - ? InstantPattern.Create("yyyy-MM-ddTHH:mm'Z'", CultureInfo.InvariantCulture) - .Parse(s.EndDateTime) - .Value - : throw new ArgumentNullException(), - s.EnergyObservations.Select( - o => new EnergyObservationDto( - o.Position != null ? int.Parse(o.Position) : throw new ArgumentNullException(nameof(o.Position)), - o.EnergyQuantity != null ? decimal.Parse(o.EnergyQuantity) : throw new ArgumentNullException(nameof(o.EnergyQuantity)), - o.QuantityQuality)) - .ToList())) - .ToList()), + new MeteredDataForMeasurementPointMessageSeriesDto( + TransactionId.From(series.TransactionId), + series.MeteringPointType!, + series.MeteringPointLocationId!, + null, + series.ProductNumber!, + series.ProductUnitType!, + marketMessage.CreatedAt, + Resolution.FromCode(series.Resolution!), + InstantPattern.Create("yyyy-MM-ddTHH:mm'Z'", CultureInfo.InvariantCulture) + .Parse(series.StartDateTime) + .Value, + series.EndDateTime != null + ? InstantPattern.Create("yyyy-MM-ddTHH:mm'Z'", CultureInfo.InvariantCulture) + .Parse(series.EndDateTime) + .Value + : throw new ArgumentNullException(), + series.EnergyObservations.Select( + o => new EnergyObservationDto( + o.Position != null + ? int.Parse(o.Position) + : throw new ArgumentNullException(nameof(o.Position)), + o.EnergyQuantity != null + ? decimal.Parse(o.EnergyQuantity) + : throw new ArgumentNullException(nameof(o.EnergyQuantity)), + o.QuantityQuality)) + .ToList())), CancellationToken.None) .ConfigureAwait(false); }