Skip to content

Commit

Permalink
Add Settlement Reports WebAPI (#3531)
Browse files Browse the repository at this point in the history
* Revert "Update dh-edit-user-role-modal.component.ts (#3442)"

This reverts commit aba4d29.

* Add settlement report client

* Implement webAPI

temporarily set useApi to true when requesting a report

* Update mocks

* Delete bun.lockb

* Create bun.lockb

* Update SettlementReport.cs

* Possible typescript to high version fix

* chore: Update PRODUCTION_DEPENDENCIES.md

* To ensure ci-orchestrator works

* Small fixes

* Update SchemaTests.ChangeTest.verified.graphql

* Update SettlementReportsClient.cs

* Added nullable jobId property

* Update Program.cs

* Revert "Update Program.cs"

This reverts commit 88c79c7.

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
FirestarJes and github-actions[bot] authored Sep 13, 2024
1 parent c237c53 commit 15440f1
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 15 deletions.
2 changes: 1 addition & 1 deletion PRODUCTION_DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
| [express](https://github.com/expressjs/express) | 4.19.2 | MIT |
| [graphql-sse](https://github.com/enisdenjo/graphql-sse) | 2.5.3 | MIT |
| [graphql](https://github.com/graphql/graphql-js) | 16.8.1 | MIT |
| [highlight.js](https://github.com/highlightjs/highlight.js) | 11.9.0 | BSD-3-Clause |
| [highlight.js](https://github.com/highlightjs/highlight.js) | 11.10.0 | BSD-3-Clause |
| [include-media](https://github.com/eduardoboucas/include-media) | 2.0.0 | MIT |
| [jwt-decode](https://github.com/auth0/jwt-decode) | 4.0.0 | MIT |
| [libphonenumber-js](git+https://gitlab.com/catamphetamine/libphonenumber-js) | 1.10.60 | MIT |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public sealed class HealthCheckFixture : IDisposable
"/wholesaleorchestrations/api/monitor/live",
"/esett/monitor/live",
"/edib2capi/monitor/live",
"/settlement-reports/monitor/live"
];

public HealthCheckFixture()
Expand All @@ -40,6 +41,7 @@ public HealthCheckFixture()
Environment.SetEnvironmentVariable("ApiClientSettings__WholesaleOrchestrationsBaseUrl", "http://localhost:8080/wholesaleorchestrations");
Environment.SetEnvironmentVariable("ApiClientSettings__ESettExchangeBaseUrl", "http://localhost:8080/esett");
Environment.SetEnvironmentVariable("ApiClientSettings__EdiB2CWebApiBaseUrl", "http://localhost:8080/edib2capi");
Environment.SetEnvironmentVariable("ApiClientSettings__SettlementReportsAPIBaseUrl", "http://localhost:8080/settlement-reports");

SetServicesAsHealthy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ type SettlementReport {
progress: Float!
statusType: SettlementReportStatusType!
executionTime: DateRange!
fromApi: Boolean!
splitReportPerGridArea: Boolean!
includeMonthlyAmount: Boolean!
gridAreas: [String!]!
Expand Down Expand Up @@ -827,6 +828,7 @@ input RequestSettlementReportInput {
preventLargeTextFiles: Boolean!
includeMonthlySums: Boolean!
includeBasisData: Boolean!
useApi: Boolean!
energySupplier: String
csvLanguage: String
}
Expand Down
2 changes: 2 additions & 0 deletions apps/dh/api-dh/source/DataHub.WebApi/ApiClientSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public class ApiClientSettings
public string EdiB2CWebApiBaseUrl { get; set; } = string.Empty;

public string ImbalancePricesBaseUrl { get; set; } = string.Empty;

public string SettlementReportsAPIBaseUrl { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ public sealed record RequestedSettlementReportDto(
bool IncludeMonthlyAmount,
IReadOnlyDictionary<string, CalculationId?> GridAreas,
DateTimeOffset CreatedDateTime,
DateTimeOffset? EndedDateTime);
DateTimeOffset? EndedDateTime,
SettlementReportJobId? JobId);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2020 Energinet DataHub A/S
//
// Licensed under the Apache License, Version 2.0 (the "License2");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Energinet.DataHub.WebApi.Clients.Wholesale.SettlementReports.Dto;

public sealed record SettlementReportJobId(long Id);
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public sealed record SettlementReportRequestDto(
bool PreventLargeTextFiles,
bool IncludeBasisData,
bool IncludeMonthlyAmount,
bool UseAPI,
SettlementReportRequestFilterDto Filter);
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,50 @@ namespace Energinet.DataHub.WebApi.Clients.Wholesale.SettlementReports;
public sealed class SettlementReportsClient : ISettlementReportsClient
{
private readonly HttpClient _httpClient;
private readonly HttpClient _apiHttpClient;

public SettlementReportsClient(string baseUrl, HttpClient httpClient)
public SettlementReportsClient(string baseUrl, HttpClient httpClient, HttpClient apiHttpClient)
{
ArgumentException.ThrowIfNullOrWhiteSpace(baseUrl);
ArgumentNullException.ThrowIfNull(httpClient);
ArgumentNullException.ThrowIfNull(apiHttpClient);

_httpClient = httpClient;
_apiHttpClient = apiHttpClient;
}

public async Task RequestAsync(SettlementReportRequestDto requestDto, CancellationToken cancellationToken)
{
using var request = new HttpRequestMessage(HttpMethod.Post, "api/RequestSettlementReport");
request.Content = new StringContent(
JsonConvert.SerializeObject(requestDto),
Encoding.UTF8,
"application/json");
using var request = requestDto.UseAPI
? new HttpRequestMessage(HttpMethod.Post, "settlement-reports/RequestSettlementReport")
: new HttpRequestMessage(HttpMethod.Post, "api/RequestSettlementReport");

using var response = await _httpClient.SendAsync(request, cancellationToken);
response.EnsureSuccessStatusCode();
request.Content = new StringContent(
JsonConvert.SerializeObject(requestDto),
Encoding.UTF8,
"application/json");

using var response = await (requestDto.UseAPI
? _apiHttpClient.SendAsync(request, cancellationToken)
: _httpClient.SendAsync(request, cancellationToken));

response.EnsureSuccessStatusCode();
}

public async Task<IEnumerable<RequestedSettlementReportDto>> GetAsync(CancellationToken cancellationToken)
{
using var requestApi = new HttpRequestMessage(HttpMethod.Get, "settlement-reports/list");
using var request = new HttpRequestMessage(HttpMethod.Get, "api/ListSettlementReports");

using var actualResponseApi = await _apiHttpClient.SendAsync(requestApi, cancellationToken);
using var actualResponse = await _httpClient.SendAsync(request, cancellationToken);

actualResponseApi.EnsureSuccessStatusCode();
actualResponse.EnsureSuccessStatusCode();

return await actualResponse.Content.ReadFromJsonAsync<IEnumerable<RequestedSettlementReportDto>>(cancellationToken) ?? [];
var actualResponseContent = await actualResponse.Content.ReadFromJsonAsync<IEnumerable<RequestedSettlementReportDto>>(cancellationToken) ?? [];
var actualResponseApiContent = await actualResponseApi.Content.ReadFromJsonAsync<IEnumerable<RequestedSettlementReportDto>>(cancellationToken) ?? [];
return actualResponseContent.Concat(actualResponseApiContent).OrderByDescending(x => x.CreatedDateTime);
}

public async Task<Stream> DownloadAsync(SettlementReportRequestId requestId, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ await client.RequestAsync(
requestSettlementReportInput.PreventLargeTextFiles,
requestSettlementReportInput.IncludeBasisData,
requestSettlementReportInput.IncludeMonthlySums,
requestSettlementReportInput.UseApi,
requestFilter),
default);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public async Task<IEnumerable<SettlementReport>> GetSettlementReportsAsync(
report.Progress,
settlementReportStatusType,
new Interval(Instant.FromDateTimeOffset(report.CreatedDateTime), report.EndedDateTime != null ? Instant.FromDateTimeOffset(report.EndedDateTime.Value) : null),
report.JobId is not null,
report.SplitReportPerGridArea,
report.IncludeMonthlyAmount,
report.GridAreas.Select(ga => ga.Key).ToArray()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ public record RequestSettlementReportInput(
bool PreventLargeTextFiles,
bool IncludeMonthlySums,
bool IncludeBasisData,
bool UseApi,
string? EnergySupplier,
string? CsvLanguage);
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public sealed record SettlementReport(
double Progress,
SettlementReportStatusType StatusType,
Interval ExecutionTime,
bool FromApi,
bool SplitReportPerGridArea,
bool IncludeMonthlyAmount,
string[] GridAreas);
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public static IServiceCollection AddDomainClients(this IServiceCollection servic
.AddWholesaleOrchestrationsClient(
GetBaseUri(apiClientSettings.WholesaleOrchestrationsBaseUrl))
.AddSettlementReportsClient(
GetBaseUri(apiClientSettings.WholesaleOrchestrationSettlementReportsBaseUrl))
GetBaseUri(apiClientSettings.WholesaleOrchestrationSettlementReportsBaseUrl),
GetBaseUri(apiClientSettings.SettlementReportsAPIBaseUrl))
.AddESettClient(
GetBaseUri(apiClientSettings.ESettExchangeBaseUrl))
.AddEdiWebAppClient(
Expand Down Expand Up @@ -81,12 +82,13 @@ private static IServiceCollection AddWholesaleOrchestrationsClient(this IService
provider.GetRequiredService<AuthorizedHttpClientFactory>().CreateClient(baseUri)));
}

private static IServiceCollection AddSettlementReportsClient(this IServiceCollection serviceCollection, Uri baseUri)
private static IServiceCollection AddSettlementReportsClient(this IServiceCollection serviceCollection, Uri baseUri, Uri apiBaseUri)
{
return serviceCollection.AddScoped<ISettlementReportsClient, SettlementReportsClient>(
provider => new SettlementReportsClient(
baseUri.ToString(),
provider.GetRequiredService<AuthorizedHttpClientFactory>().CreateClient(baseUri)));
provider.GetRequiredService<AuthorizedHttpClientFactory>().CreateClient(baseUri),
provider.GetRequiredService<AuthorizedHttpClientFactory>().CreateClient(apiBaseUri)));
}

private static IServiceCollection AddESettClient(this IServiceCollection serviceCollection, Uri baseUri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static void SetupHealthEndpoints(this IServiceCollection services, ApiCli
.AddServiceHealthCheck("wholesale", CreateHealthEndpointUri(settings.WholesaleBaseUrl))
.AddServiceHealthCheck("wholesaleOrchestrations", CreateHealthEndpointUri(settings.WholesaleOrchestrationsBaseUrl, isAzureFunction: true))
.AddServiceHealthCheck("eSettExchange", CreateHealthEndpointUri(settings.ESettExchangeBaseUrl))
.AddServiceHealthCheck("settlementReportsAPI", CreateHealthEndpointUri(settings.SettlementReportsAPIBaseUrl))
.AddServiceHealthCheck("ediB2CWebApi", CreateHealthEndpointUri(settings.EdiB2CWebApiBaseUrl));

private static Uri CreateHealthEndpointUri(string baseUri, bool isAzureFunction = false)
Expand Down
Binary file modified bun.lockb
100755 → 100644
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const wholesaleSettlementReportsQueryMock = (
end: executionTimeEnd_Days,
},
settlementReportDownloadUrl: `${apiBase}/v1/WholesaleSettlementReport/DownloadReport`,
fromApi: true,
},
{
__typename: 'SettlementReport',
Expand All @@ -73,6 +74,7 @@ export const wholesaleSettlementReportsQueryMock = (
end: executionTimeStart_Hours,
},
settlementReportDownloadUrl: `${apiBase}/v1/WholesaleSettlementReport/DownloadReport`,
fromApi: true,
},
{
__typename: 'SettlementReport',
Expand All @@ -93,6 +95,7 @@ export const wholesaleSettlementReportsQueryMock = (
end: executionTimeStart_Minutes,
},
settlementReportDownloadUrl: `${apiBase}/v1/WholesaleSettlementReport/DownloadReport`,
fromApi: true,
},
{
__typename: 'SettlementReport',
Expand All @@ -113,6 +116,7 @@ export const wholesaleSettlementReportsQueryMock = (
end: null,
},
settlementReportDownloadUrl: `${apiBase}/v1/WholesaleSettlementReport/DownloadReport`,
fromApi: true,
},
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ query getSettlementReports {
statusType
settlementReportDownloadUrl
executionTime
fromApi
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export class DhRequestSettlementReportModalComponent extends WattTypedModal {
preventLargeTextFiles: !allowLargeTextFiles,
energySupplier: energySupplier == ALL_ENERGY_SUPPLIERS ? null : energySupplier,
csvLanguage: translate('selectedLanguageIso'),
useApi: true,
},
},
refetchQueries: (result) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
"source-map-explorer": "2.5.3",
"storybook-addon-pseudo-states": "2.1.0",
"ts-jest": "29.1.2",
"typescript": "^5.5.3",
"typescript": "~5.5.3",
"typescript-eslint": "^7.16.0"
},
"volta": {
Expand Down

0 comments on commit 15440f1

Please sign in to comment.