Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into mwo/enq-met-dat
Browse files Browse the repository at this point in the history
  • Loading branch information
MWO1024 committed Dec 4, 2024
2 parents 4a9d8c1 + 7ea441e commit 12278a9
Show file tree
Hide file tree
Showing 25 changed files with 327 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task<HttpResponseData> RunAsync(
.ReceiveIncomingMarketMessageAsync(
incomingMarketMessageStream,
incomingDocumentFormat: DocumentFormat.Ebix,
IncomingDocumentType.MeteredDataForMeasurementPoint,
IncomingDocumentType.NotifyValidatedMeasureData,
responseDocumentFormat: DocumentFormat.Ebix,
cancellationToken)
.ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion source/B2BApi/IncomingMessages/IncomingMessageReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private static async Task<HttpResponseData> CreateResponseAsync(
{
{ IncomingDocumentType.RequestAggregatedMeasureData, AuditLogEntityType.RequestAggregatedMeasureData },
{ IncomingDocumentType.RequestWholesaleSettlement, AuditLogEntityType.RequestWholesaleServices },
{ IncomingDocumentType.MeteredDataForMeasurementPoint, AuditLogEntityType.MeteredDataForMeasurementPointReceived },
{ IncomingDocumentType.NotifyValidatedMeasureData, AuditLogEntityType.MeteredDataForMeasurementPointReceived },
};

entityTypeMapping.TryGetValue(incomingDocumentType, out var affectedEntityType);
Expand Down
2 changes: 1 addition & 1 deletion source/BuildingBlocks.Domain/Models/DocumentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DocumentType : EnumerationType
public static readonly DocumentType RejectRequestAggregatedMeasureData = new(nameof(RejectRequestAggregatedMeasureData), MessageCategory.Aggregations);
public static readonly DocumentType NotifyWholesaleServices = new(nameof(NotifyWholesaleServices), MessageCategory.Aggregations);
public static readonly DocumentType RejectRequestWholesaleSettlement = new(nameof(RejectRequestWholesaleSettlement), MessageCategory.Aggregations);
public static readonly DocumentType MeteredDataForMeasurementPoint = new(nameof(MeteredDataForMeasurementPoint), MessageCategory.TimeSeries);
public static readonly DocumentType NotifyValidatedMeasureData = new(nameof(NotifyValidatedMeasureData), MessageCategory.TimeSeries);

private DocumentType(string name, MessageCategory category)
: base(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class IncomingDocumentType : EnumerationType
public static readonly IncomingDocumentType B2CRequestAggregatedMeasureData = new(nameof(B2CRequestAggregatedMeasureData));
public static readonly IncomingDocumentType RequestWholesaleSettlement = new(nameof(RequestWholesaleSettlement));
public static readonly IncomingDocumentType B2CRequestWholesaleSettlement = new(nameof(B2CRequestWholesaleSettlement));
public static readonly IncomingDocumentType MeteredDataForMeasurementPoint = new(nameof(MeteredDataForMeasurementPoint));
public static readonly IncomingDocumentType NotifyValidatedMeasureData = new(nameof(NotifyValidatedMeasureData));

private IncomingDocumentType(string name)
: base(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ public async Task Validate_WhenPeriodStartAndPeriodEndAreInvalidFormat_ReturnsUn
// Arrange
var now = SystemClock.Instance.GetCurrentInstant().ToDateTimeOffset();

var startToYearsAgo = now.AddYears(-2);
var endToYearsAgo = now.AddYears(-2).AddMonths(1);
var request = new WholesaleServicesRequestBuilder()
.WithPeriodStart(
new LocalDateTime(now.Year - 2, now.Month, 1, 17, 45, 12)
new LocalDateTime(startToYearsAgo.Year, startToYearsAgo.Month, 1, 17, 45, 12)
.InZoneStrictly(DateTimeZoneProviders.Tzdb.GetZoneOrNull("Europe/Copenhagen")!)
.ToInstant()
.ToString())
.WithPeriodEnd(
new LocalDateTime(now.Year - 2, now.Month + 1, 1, 8, 13, 56)
new LocalDateTime(endToYearsAgo.Year, endToYearsAgo.Month, 1, 8, 13, 56)
.InZoneStrictly(DateTimeZoneProviders.Tzdb.GetZoneOrNull("Europe/Copenhagen")!)
.ToInstant()
.ToString())
Expand All @@ -100,8 +102,7 @@ public async Task Validate_WhenPeriodStartAndPeriodEndAreInvalidFormat_ReturnsUn
var validationErrors = await _sut.ValidateAsync(request);

// Assert
validationErrors.Should().HaveCount(2);
validationErrors.Select(e => e.ErrorCode).Should().BeEquivalentTo(["D66", "D66"]);
validationErrors.Where(x => x.ErrorCode == "D66").Should().HaveCount(2);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private ProcessType MapToProcessType(IncomingDocumentType incomingDocumentType)
{ IncomingDocumentType.B2CRequestAggregatedMeasureData, ProcessType.RequestEnergyResults },
{ IncomingDocumentType.RequestWholesaleSettlement, ProcessType.RequestWholesaleResults },
{ IncomingDocumentType.B2CRequestWholesaleSettlement, ProcessType.RequestWholesaleResults },
{ IncomingDocumentType.MeteredDataForMeasurementPoint, ProcessType.IncomingMeteredDataForMeasurementPoint },
{ IncomingDocumentType.NotifyValidatedMeasureData, ProcessType.IncomingMeteredDataForMeasurementPoint },
};

if (documentTypeToProcessTypeMap.TryGetValue(incomingDocumentType, out var processType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ await _delegateIncomingMessage

private static bool ShouldArchive(IncomingDocumentType documentType)
{
return documentType != IncomingDocumentType.MeteredDataForMeasurementPoint;
return documentType != IncomingDocumentType.NotifyValidatedMeasureData;
}

private async Task<IncomingMarketMessageParserResult> ParseIncomingMessageAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class MeteredDateForMeasurementPointEbixMessageParser(EbixSchemaProvider
private const string QuantityQuality = "QuantityQuality";
private const string IntervalEnergyObservation = "IntervalEnergyObservation";

public override IncomingDocumentType DocumentType => IncomingDocumentType.MeteredDataForMeasurementPoint;
public override IncomingDocumentType DocumentType => IncomingDocumentType.NotifyValidatedMeasureData;

public override DocumentFormat DocumentFormat => DocumentFormat.Ebix;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class MeteredDateForMeasurementPointJsonMessageParser(JsonSchemaProvider
private const string QuantityElementName = "quantity";
private const string RegistrationDateAndOrTimeElementName = "registration_DateAndOrTime.dateTime";

public override IncomingDocumentType DocumentType => IncomingDocumentType.MeteredDataForMeasurementPoint;
public override IncomingDocumentType DocumentType => IncomingDocumentType.NotifyValidatedMeasureData;

public override DocumentFormat DocumentFormat => DocumentFormat.Json;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class MeteredDateForMeasurementPointXmlMessageParser(CimXmlSchemaProvider
private const string QualityElementName = "quality";
private const string RegistrationDateAndOrTimeElementName = "registration_DateAndOrTime.dateTime";

public override IncomingDocumentType DocumentType => IncomingDocumentType.MeteredDataForMeasurementPoint;
public override IncomingDocumentType DocumentType => IncomingDocumentType.NotifyValidatedMeasureData;

protected override string RootPayloadElementName => "NotifyValidatedMeasureData_MarketDocument";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public static TheoryData<DocumentFormat, IncomingDocumentType, ActorRole, Incomi
{
{ DocumentFormat.Json, IncomingDocumentType.RequestAggregatedMeasureData, ActorRole.BalanceResponsibleParty, ReadFile(@"IncomingMessages\RequestAggregatedMeasureDataAsDdk.json") },
{ DocumentFormat.Json, IncomingDocumentType.RequestWholesaleSettlement, ActorRole.EnergySupplier, ReadFile(@"IncomingMessages\RequestWholesaleSettlement.json") },
{ DocumentFormat.Ebix, IncomingDocumentType.MeteredDataForMeasurementPoint, ActorRole.GridAccessProvider, ReadFile(@"IncomingMessages\EbixMeteredDataForMeasurementPoint.xml") },
{ DocumentFormat.Xml, IncomingDocumentType.MeteredDataForMeasurementPoint, ActorRole.GridAccessProvider, ReadFile(@"IncomingMessages\MeteredDataForMeasurementPoint.xml") },
{ DocumentFormat.Json, IncomingDocumentType.MeteredDataForMeasurementPoint, ActorRole.GridAccessProvider, ReadFile(@"IncomingMessages\MeteredDataForMeasurementPoint.json") },
{ DocumentFormat.Ebix, IncomingDocumentType.NotifyValidatedMeasureData, ActorRole.GridAccessProvider, ReadFile(@"IncomingMessages\EbixMeteredDataForMeasurementPoint.xml") },
{ DocumentFormat.Xml, IncomingDocumentType.NotifyValidatedMeasureData, ActorRole.GridAccessProvider, ReadFile(@"IncomingMessages\MeteredDataForMeasurementPoint.xml") },
{ DocumentFormat.Json, IncomingDocumentType.NotifyValidatedMeasureData, ActorRole.GridAccessProvider, ReadFile(@"IncomingMessages\MeteredDataForMeasurementPoint.json") },
};

return data;
Expand Down Expand Up @@ -409,7 +409,7 @@ public async Task When_MeteredDataForMeasurementPointMessageIsReceived_Then_Inco
await _incomingMessagesRequest.ReceiveIncomingMarketMessageAsync(
messageStream,
DocumentFormat.Ebix,
IncomingDocumentType.MeteredDataForMeasurementPoint,
IncomingDocumentType.NotifyValidatedMeasureData,
DocumentFormat.Ebix,
CancellationToken.None);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ await AddDelegationAsync(
var response = await _incomingMessagesRequest.ReceiveIncomingMarketMessageAsync(
messageStream,
documentFormat,
IncomingDocumentType.MeteredDataForMeasurementPoint,
IncomingDocumentType.NotifyValidatedMeasureData,
documentFormat,
CancellationToken.None);

Expand Down Expand Up @@ -431,7 +431,7 @@ public async Task AndGiven_MessageIsMeteredDataForMeasurementPoint_When_SenderIs
var response = await _incomingMessagesRequest.ReceiveIncomingMarketMessageAsync(
messageStream,
documentFormat,
IncomingDocumentType.MeteredDataForMeasurementPoint,
IncomingDocumentType.NotifyValidatedMeasureData,
documentFormat,
CancellationToken.None);

Expand Down Expand Up @@ -480,7 +480,7 @@ await AddDelegationAsync(
var response = await _incomingMessagesRequest.ReceiveIncomingMarketMessageAsync(
messageStream,
documentFormat,
IncomingDocumentType.MeteredDataForMeasurementPoint,
IncomingDocumentType.NotifyValidatedMeasureData,
documentFormat,
CancellationToken.None);

Expand Down Expand Up @@ -529,7 +529,7 @@ public async Task AndGiven_MessageIsMeteredDataForMeasurementPoint_When_SenderIs
var response = await _incomingMessagesRequest.ReceiveIncomingMarketMessageAsync(
messageStream,
documentFormat,
IncomingDocumentType.MeteredDataForMeasurementPoint,
IncomingDocumentType.NotifyValidatedMeasureData,
documentFormat,
CancellationToken.None);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,13 +609,13 @@ public async Task When_BusinessTypeIsNotAllowed_Then_ExpectedValidationError()
DocumentFormat documentFormat)
{
var incomingMarketMessageStream = new IncomingMarketMessageStream(message);
if (_messageParsers.TryGetValue((IncomingDocumentType.MeteredDataForMeasurementPoint, documentFormat), out var messageParser))
if (_messageParsers.TryGetValue((IncomingDocumentType.NotifyValidatedMeasureData, documentFormat), out var messageParser))
{
var result = await messageParser.ParseAsync(incomingMarketMessageStream, CancellationToken.None).ConfigureAwait(false);
return (IncomingMessage: (MeteredDataForMeasurementPointMessage?)result.IncomingMessage, ParserResult: result);
}

throw new NotSupportedException($"No message parser found for message format '{documentFormat}' and document type '{IncomingDocumentType.MeteredDataForMeasurementPoint}'");
throw new NotSupportedException($"No message parser found for message format '{documentFormat}' and document type '{IncomingDocumentType.NotifyValidatedMeasureData}'");
}

private async Task StoreMessageIdForActorAsync(string messageId, string senderActorNumber)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected async Task<ResponseMessage> GivenReceivedMeteredDataForMeasurementPoin
incomingMessageClient.ReceiveIncomingMarketMessageAsync(
incomingMessageStream,
documentFormat,
IncomingDocumentType.MeteredDataForMeasurementPoint,
IncomingDocumentType.NotifyValidatedMeasureData,
documentFormat,
CancellationToken.None);

Expand All @@ -67,7 +67,7 @@ protected async Task<ResponseMessage> GivenReceivedMeteredDataForMeasurementPoin
using var scope = new AssertionScope();
response.IsErrorResponse
.Should()
.BeFalse("because the response should not have an error. Actual response: {0}", response.MessageBody);
.BeFalse("the response should not have an error. Actual response: {0}", response.MessageBody);

response.MessageBody.Should().BeEmpty();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public bool HandlesFormat(DocumentFormat format)

public bool HandlesType(DocumentType documentType)
{
return documentType == DocumentType.MeteredDataForMeasurementPoint;
return documentType == DocumentType.NotifyValidatedMeasureData;
}

public async Task<MarketDocumentStream> WriteAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,77 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models;
using Energinet.DataHub.EDI.OutgoingMessages.Domain.Models.MarketDocuments;
using Energinet.DataHub.EDI.OutgoingMessages.Domain.Models.OutgoingMessages;
using System.Globalization;
using System.Xml;
using System.Xml.Linq;
using Energinet.DataHub.EDI.OutgoingMessages.Domain.DocumentWriters.Formats;
using Energinet.DataHub.EDI.OutgoingMessages.Domain.DocumentWriters.Formats.CIM.Xml;

namespace Energinet.DataHub.EDI.OutgoingMessages.Domain.DocumentWriters.RSM012;

public class MeteredDateForMeasurementPointCimXmlDocumentWriter : IDocumentWriter
public class MeteredDateForMeasurementPointCimXmlDocumentWriter(
IMessageRecordParser parser)
: CimXmlDocumentWriter(
new DocumentDetails(
"NotifyValidatedMeasureData_MarketDocument",
"urn:ediel.org:measure:notifyvalidatedmeasuredata:0:1 urn-ediel-org-measure-notifyvalidatedmeasuredata-0-1.xsd",
"urn:ediel.org:measure:notifyvalidatedmeasuredata:0:1",
"cim",
"E66"),
parser)
{
public bool HandlesFormat(DocumentFormat format)
protected override async Task WriteMarketActivityRecordsAsync(
IReadOnlyCollection<string> marketActivityPayloads,
XmlWriter writer)
{
return format == DocumentFormat.Xml;
}
ArgumentNullException.ThrowIfNull(marketActivityPayloads);
ArgumentNullException.ThrowIfNull(writer);
XNamespace @namespace = "urn:ediel.org:measure:notifyvalidatedmeasuredata:0:1";
foreach (var activityRecord in ParseFrom<MeteredDateForMeasurementPointMarketActivityRecord>(marketActivityPayloads))
{
var seriesElement = new XElement(
@namespace + "Series",
new XElement(@namespace + "mRID", activityRecord.TransactionId),
new XElement(
@namespace + "originalTransactionIDReference_Series.mRID",
activityRecord.OriginalTransactionIdReferenceId),
new XElement(
@namespace + "marketEvaluationPoint.mRID",
new XAttribute("codingScheme", "A10"),
activityRecord.MarketEvaluationPointNumber),
new XElement(@namespace + "marketEvaluationPoint.type", activityRecord.MarketEvaluationPointType),
new XElement(@namespace + "registration_DateAndOrTime.dateTime", activityRecord.RegistrationDateTime),
new XElement(@namespace + "product", activityRecord.Product),
new XElement(@namespace + "quantity_Measure_Unit.name", activityRecord.QuantityMeasureUnit),
new XElement(
@namespace + "Period",
new XElement(@namespace + "resolution", activityRecord.Resolution),
new XElement(
@namespace + "timeInterval",
new XElement(@namespace + "start", activityRecord.StartedDateTime),
new XElement(@namespace + "end", activityRecord.EndedDateTime)),
activityRecord.EnergyObservations.Select(x => CreatePointElement(x, @namespace))));

public bool HandlesType(DocumentType documentType)
{
return documentType == DocumentType.MeteredDataForMeasurementPoint;
await seriesElement.WriteToAsync(writer, CancellationToken.None).ConfigureAwait(false);
}
}

public Task<MarketDocumentStream> WriteAsync(
OutgoingMessageHeader header,
IReadOnlyCollection<string> marketActivityRecords,
CancellationToken cancellationToken)
private XElement CreatePointElement(PointActivityRecord point, XNamespace @namespace)
{
throw new NotImplementedException();
var pointElement = new XElement(
@namespace + "Point",
new XElement(@namespace + "position", point.Position.ToString(NumberFormatInfo.InvariantInfo)));

if (point.Quantity != null)
{
pointElement.Add(new XElement(@namespace + "quantity", point.Quantity?.ToString(NumberFormatInfo.InvariantInfo)));
}

if (point.Quality != null)
{
pointElement.Add(new XElement(@namespace + "quality", point.Quality?.ToString(NumberFormatInfo.InvariantInfo)));
}

return pointElement;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Energinet.DataHub.EDI.OutgoingMessages.Domain.DocumentWriters.RSM012;

public record MeteredDateForMeasurementPointMarketActivityRecord(
public sealed record MeteredDateForMeasurementPointMarketActivityRecord(
string TransactionId,
string MarketEvaluationPointNumber,
string MarketEvaluationPointType,
Expand All @@ -29,4 +29,4 @@ public record MeteredDateForMeasurementPointMarketActivityRecord(
string EndedDateTime,
IReadOnlyList<PointActivityRecord> EnergyObservations);

public record PointActivityRecord(int Position, string? Quality, decimal? Quantity);
public sealed record PointActivityRecord(int Position, string? Quality, decimal? Quantity);
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void Ensure_that_all_document_support_ebix(DocumentType documentType)
var writer = _documentWriters.FirstOrDefault(writer =>
writer.HandlesType(documentType) && writer.HandlesFormat(DocumentFormat.Ebix));

if (documentType == DocumentType.MeteredDataForMeasurementPoint)
if (documentType == DocumentType.NotifyValidatedMeasureData)
{
writer.Should().BeNull($"{documentType} does not support ebix");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed class MeteredDataForMeasurementPointMessageProcessDto(
BusinessReason businessReason,
MeteredDataForMeasurementPointMessageSeriesDto series)
: OutgoingMessageDto(
DocumentType.MeteredDataForMeasurementPoint,
DocumentType.NotifyValidatedMeasureData,
receiver.ActorNumber,
null,
eventId,
Expand Down
Loading

0 comments on commit 12278a9

Please sign in to comment.