From 99658719fa495c7dbd66d752e92c4cf824d2fe10 Mon Sep 17 00:00:00 2001 From: Vitalie Belinschi Date: Mon, 23 Sep 2024 13:56:51 +0200 Subject: [PATCH] remove two columns for energy suppliers in MDMP --- .../MeteringPointMasterDataFileGenerator.cs | 36 ++++++----- ...ReportMeteringPointMasterDataRepository.cs | 2 +- ...eportFileRequestHandlerIntegrationTests.cs | 59 +++++++++++++++++++ 3 files changed, 80 insertions(+), 17 deletions(-) diff --git a/source/settlement-report/SettlementReports.Infrastructure/SettlementReports_v2/Generators/MeteringPointMasterDataFileGenerator.cs b/source/settlement-report/SettlementReports.Infrastructure/SettlementReports_v2/Generators/MeteringPointMasterDataFileGenerator.cs index 56a8c82..b8d3af6 100644 --- a/source/settlement-report/SettlementReports.Infrastructure/SettlementReports_v2/Generators/MeteringPointMasterDataFileGenerator.cs +++ b/source/settlement-report/SettlementReports.Infrastructure/SettlementReports_v2/Generators/MeteringPointMasterDataFileGenerator.cs @@ -51,36 +51,40 @@ public sealed class SettlementReportMeteringPointMasterDataRowMap : ClassMap r.MeteringPointId) .Name("METERINGPOINTID") - .Index(0); + .Index(columnIndex++); Map(r => r.PeriodStart) .Name("VALIDFROM") - .Index(1); + .Index(columnIndex++); Map(r => r.PeriodEnd) .Name("VALIDTO") - .Index(2); + .Index(columnIndex++); Map(r => r.GridAreaId) .Name("GRIDAREAID") - .Index(3) + .Index(columnIndex++) .Convert(row => row.Value.GridAreaId.PadLeft(3, '0')); - Map(r => r.GridAreaToId) - .Name("TOGRIDAREAID") - .Index(4) - .Convert(row => row.Value.GridAreaToId?.PadLeft(3, '0')); - - Map(r => r.GridAreaFromId) - .Name("FROMGRIDAREAID") - .Index(5) - .Convert(row => row.Value.GridAreaFromId?.PadLeft(3, '0')); + if (actorInfo.MarketRole is not MarketRole.EnergySupplier) + { + Map(r => r.GridAreaToId) + .Name("TOGRIDAREAID") + .Index(columnIndex++) + .Convert(row => row.Value.GridAreaToId?.PadLeft(3, '0')); + + Map(r => r.GridAreaFromId) + .Name("FROMGRIDAREAID") + .Index(columnIndex++) + .Convert(row => row.Value.GridAreaFromId?.PadLeft(3, '0')); + } Map(r => r.MeteringPointType) .Name("TYPEOFMP") - .Index(6) + .Index(columnIndex++) .Convert(row => row.Value.MeteringPointType switch { null => string.Empty, @@ -104,7 +108,7 @@ public SettlementReportMeteringPointMasterDataRowMap(SettlementReportRequestedBy Map(r => r.SettlementMethod) .Name("SETTLEMENTMETHOD") - .Index(7) + .Index(columnIndex++) .Convert(row => row.Value.SettlementMethod switch { null => string.Empty, @@ -117,7 +121,7 @@ public SettlementReportMeteringPointMasterDataRowMap(SettlementReportRequestedBy { Map(r => r.EnergySupplierId) .Name("ENERGYSUPPLIERID") - .Index(8); + .Index(columnIndex++); } } } diff --git a/source/settlement-report/SettlementReports.Infrastructure/SettlementReports_v2/SettlementReportMeteringPointMasterDataRepository.cs b/source/settlement-report/SettlementReports.Infrastructure/SettlementReports_v2/SettlementReportMeteringPointMasterDataRepository.cs index 47fa743..070cc15 100644 --- a/source/settlement-report/SettlementReports.Infrastructure/SettlementReports_v2/SettlementReportMeteringPointMasterDataRepository.cs +++ b/source/settlement-report/SettlementReports.Infrastructure/SettlementReports_v2/SettlementReportMeteringPointMasterDataRepository.cs @@ -34,7 +34,7 @@ public SettlementReportMeteringPointMasterDataRepository(ISettlementReportDatabr public Task CountAsync(SettlementReportRequestFilterDto filter, long maximumCalculationVersion) { - return Task.FromResult(1); + return Task.FromResult(1); } public async IAsyncEnumerable GetAsync(SettlementReportRequestFilterDto filter, int skip, int take, long maximumCalculationVersion) diff --git a/source/settlement-report/SettlementReports.IntegrationTests/Application/SettlementReports/SettlementReportFileRequestHandlerIntegrationTests.cs b/source/settlement-report/SettlementReports.IntegrationTests/Application/SettlementReports/SettlementReportFileRequestHandlerIntegrationTests.cs index 5a6163e..45711b9 100644 --- a/source/settlement-report/SettlementReports.IntegrationTests/Application/SettlementReports/SettlementReportFileRequestHandlerIntegrationTests.cs +++ b/source/settlement-report/SettlementReports.IntegrationTests/Application/SettlementReports/SettlementReportFileRequestHandlerIntegrationTests.cs @@ -278,6 +278,9 @@ await _databricksSqlStatementApiFixture.DatabricksSchemaManager.InsertAsync x, _ => (CalculationId?)new CalculationId(calculationId)), @@ -327,6 +330,62 @@ await _databricksSqlStatementApiFixture.DatabricksSchemaManager.InsertAsync x, _ => (CalculationId?)new CalculationId(calculationId)), + _january1St.ToDateTimeOffset(), + _january5Th.ToDateTimeOffset(), + CalculationType.WholesaleFixing, + null, + null); + + var requestId = new SettlementReportRequestId(Guid.NewGuid().ToString()); + var fileRequest = new SettlementReportFileRequestDto( + requestId, + SettlementReportFileContent.MeteringPointMasterData, + new SettlementReportPartialFileInfo(Guid.NewGuid().ToString(), true), + filter, + 1); + var actorInfo = new SettlementReportRequestedByActor(MarketRole.EnergySupplier, null); + + await _databricksSqlStatementApiFixture.DatabricksSchemaManager.InsertAsync( + _databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions.Value.METERING_POINT_MASTER_DATA_V1_VIEW_NAME, + [ + ["'f8af5e30-3c65-439e-8fd0-1da0c40a26de'", "'wholesale_fixing'", "'15cba911-b91e-4782-bed4-f0d2841829e1'", "'2022-01-02T02:00:00.000+00:00'", "'2022-01-03T02:00:00.000+00:00'", "'018'", "'406'", "'407'", "'consumption'", "'flex'", "8397670583196"], + ["'f8af5e30-3c65-439e-8fd0-1da0c40a26de'", "'wholesale_fixing'", "'15cba911-b91e-4782-bed4-f0d2841829e2'", "'2022-01-02T02:00:00.000+00:00'", "'2022-01-03T02:00:00.000+00:00'", "'018'", "'406'", "'407'", "'consumption'", "'flex'", "8397670583196"], + ]); + + // Act + var actual = await Sut.RequestFileAsync(fileRequest, actorInfo); + + // Assert + Assert.Equal(requestId, actual.RequestId); + + var container = _settlementReportFileBlobStorageFixture.CreateBlobContainerClient(); + var generatedFileBlob = container.GetBlobClient($"settlement-reports/{requestId.Id}/{actual.StorageFileName}"); + var generatedFile = await generatedFileBlob.DownloadContentAsync(); + var fileContents = generatedFile.Value.Content.ToString(); + var fileLines = fileContents.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); + + Assert.Equal(3, fileLines.Length); + Assert.Equal( + "METERINGPOINTID,VALIDFROM,VALIDTO,GRIDAREAID,TYPEOFMP,SETTLEMENTMETHOD", + fileLines[0]); + Assert.Equal( + "\"15cba911-b91e-4782-bed4-f0d2841829e1\",2022-01-02T02:00:00Z,2022-01-03T02:00:00Z,\"018\",\"E17\",\"D01\"", + fileLines[1]); + Assert.Equal( + "\"15cba911-b91e-4782-bed4-f0d2841829e2\",2022-01-02T02:00:00Z,2022-01-03T02:00:00Z,\"018\",\"E17\",\"D01\"", + fileLines[2]); + } + [Fact] public async Task RequestFileAsync_ForMonthlyAmount_ReturnsExpectedCsv() {