Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add import into DH2 Bridge. #3865

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public sealed class HealthCheckFixture : IDisposable
"/esett/monitor/live",
"/edib2capi/monitor/live",
"/settlement-reports/monitor/live",
"/notifications/api/monitor/live",
"/dh2bridge/api/monitor/live",
"/process-manager-general/api/monitor/live",
"/process-manager-orchestrations/api/monitor/live",
];
Expand All @@ -44,6 +46,8 @@ public HealthCheckFixture()
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");
Environment.SetEnvironmentVariable("ApiClientSettings__NotificationsBaseUrl", "http://localhost:8080/notifications");
Environment.SetEnvironmentVariable("ApiClientSettings__Dh2BridgeBaseUrl", "http://localhost:8080/dh2bridge");
Environment.SetEnvironmentVariable("ProcessManagerClient__GeneralApiBaseAddress", "http://localhost:8080/process-manager-general");
Environment.SetEnvironmentVariable("ProcessManagerClient__OrchestrationsApiBaseAddress", "http://localhost:8080/process-manager-orchestrations");

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 @@ -37,4 +37,6 @@ public class ApiClientSettings
public string SettlementReportsAPIBaseUrl { get; set; } = string.Empty;

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

public string Dh2BridgeBaseUrl { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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.Dh2Bridge;

public sealed class Dh2BridgeClient : IDh2BridgeClient
{
private readonly HttpClient _httpClient;

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

_httpClient = httpClient;
}

public async Task ImportCapacitySettlementsAsync(Stream content, CancellationToken cancellationToken)
{
using var request = new HttpRequestMessage(HttpMethod.Post, "api/ImportCapacitySettlements");
request.Content = new StreamContent(content);

using var response = await _httpClient.SendAsync(request, cancellationToken);
response.EnsureSuccessStatusCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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.Dh2Bridge;

/// <summary>
/// Provides an interface for importing capacity settlement data.
/// </summary>
public interface IDh2BridgeClient
{
/// <summary>
/// Asynchronously imports capacity settlement data from the specified stream.
/// </summary>
/// <param name="content">The stream containing capacity settlement data to be imported.</param>
/// <param name="cancellationToken">A token used to cancel the import operation.</param>
/// <returns>A task that represents the asynchronous import operation.</returns>
Task ImportCapacitySettlementsAsync(Stream content, CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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.

using Energinet.DataHub.WebApi.Clients.Dh2Bridge;
using Energinet.DataHub.WebApi.Clients.ImbalancePrices.v1;
using Microsoft.AspNetCore.Mvc;

namespace Energinet.DataHub.WebApi.Controllers;

[ApiController]
[Route("v1/[controller]")]
public sealed class Dh2BridgeController : ControllerBase
{
private readonly IDh2BridgeClient _client;

public Dh2BridgeController(IDh2BridgeClient client)
{
_client = client;
}

[HttpPost]
[Route("ImportCapacitySettlements")]
[RequestSizeLimit(10485760)]
public async Task<ActionResult> ImportCapacitySettlementsAsync(IFormFile jsonFile)
{
try
{
await using var openReadStream = jsonFile.OpenReadStream();
await _client.ImportCapacitySettlementsAsync(openReadStream, default);
return Ok();
}
catch (ApiException ex)
{
return StatusCode(ex.StatusCode, ex.Response);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Energinet.DataHub.Edi.B2CWebApp.Clients.v3;
using Energinet.DataHub.ProcessManager.Client.Extensions.DependencyInjection;
using Energinet.DataHub.ProcessManager.Client.Extensions.Options;
using Energinet.DataHub.WebApi.Clients.Dh2Bridge;
using Energinet.DataHub.WebApi.Clients.ESettExchange.v1;
using Energinet.DataHub.WebApi.Clients.ImbalancePrices.v1;
using Energinet.DataHub.WebApi.Clients.MarketParticipant.v1;
Expand Down Expand Up @@ -93,6 +94,8 @@ public static IServiceCollection AddDomainClients(this IServiceCollection servic
GetBaseUri(apiClientSettings.ImbalancePricesBaseUrl))
.AddNotificationsClient(
GetBaseUri(apiClientSettings.NotificationsBaseUrl))
.AddDh2BridgeClient(
GetBaseUri(apiClientSettings.Dh2BridgeBaseUrl))
.AddSingleton(apiClientSettings);
}

Expand Down Expand Up @@ -184,4 +187,12 @@ private static IServiceCollection AddNotificationsClient(this IServiceCollection
baseUri.ToString(),
provider.GetRequiredService<AuthorizedHttpClientFactory>().CreateClient(baseUri)));
}

private static IServiceCollection AddDh2BridgeClient(this IServiceCollection serviceCollection, Uri baseUri)
{
return serviceCollection.AddScoped<IDh2BridgeClient, Dh2BridgeClient>(
provider => new Dh2BridgeClient(
baseUri.ToString(),
provider.GetRequiredService<AuthorizedHttpClientFactory>().CreateClient(baseUri)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public static void SetupHealthEndpoints(this IServiceCollection services, ApiCli
.AddServiceHealthCheck("wholesaleOrchestrations", CreateHealthEndpointUri(settings.WholesaleOrchestrationsBaseUrl, isAzureFunction: true))
.AddServiceHealthCheck("eSettExchange", CreateHealthEndpointUri(settings.ESettExchangeBaseUrl))
.AddServiceHealthCheck("settlementReportsAPI", CreateHealthEndpointUri(settings.SettlementReportsAPIBaseUrl))
.AddServiceHealthCheck("ediB2CWebApi", CreateHealthEndpointUri(settings.EdiB2CWebApiBaseUrl));
.AddServiceHealthCheck("ediB2CWebApi", CreateHealthEndpointUri(settings.EdiB2CWebApiBaseUrl))
.AddServiceHealthCheck("notificationsWebApi", CreateHealthEndpointUri(settings.NotificationsBaseUrl, isAzureFunction: true))
.AddServiceHealthCheck("dh2BridgeWebApi", CreateHealthEndpointUri(settings.Dh2BridgeBaseUrl, isAzureFunction: true));

internal static Uri CreateHealthEndpointUri(string baseUri, bool isAzureFunction = false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"WholesaleOrchestrationSettlementReportsLightBaseUrl": "https://localhost:5091",
"SettlementReportsAPIBaseUrl": "https://localhost:5091",
"NotificationsBaseUrl": "https://localhost:5091",
"Dh2BridgeBaseUrl": "https://localhost:5091"
},
"APPLICATIONINSIGHTS_CONNECTION_STRING": "APPLICATIONINSIGHTS_CONNECTION_STRING",
"UserAuthentication:MitIdExternalMetadataAddress": "https://<url>",
Expand Down
Loading