Skip to content

Commit

Permalink
Revert "feat: settlement report - include previous grid owners (#73)" (
Browse files Browse the repository at this point in the history
…#74)

This reverts commit f7d0fc3.
  • Loading branch information
michaelmajgaard authored Dec 9, 2024
1 parent f7d0fc3 commit cf1d2fd
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,79 +13,29 @@
// limitations under the License.

using Energinet.DataHub.SettlementReport.Application.Commands;
using Energinet.DataHub.SettlementReport.Application.Model;
using Energinet.DataHub.SettlementReport.Application.Services;
using Energinet.DataHub.SettlementReport.Interfaces.Helpers;
using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2;
using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models;
using NodaTime.Extensions;

namespace Energinet.DataHub.SettlementReport.Application.Handlers;

public sealed class RequestSettlementReportHandler : IRequestSettlementReportJobHandler
{
private readonly IDatabricksJobsHelper _jobHelper;
private readonly ISettlementReportInitializeHandler _settlementReportInitializeHandler;
private readonly IGridAreaOwnerRepository _gridAreaOwnerRepository;

public RequestSettlementReportHandler(
IDatabricksJobsHelper jobHelper,
ISettlementReportInitializeHandler settlementReportInitializeHandler,
IGridAreaOwnerRepository gridAreaOwnerRepository)
ISettlementReportInitializeHandler settlementReportInitializeHandler)
{
_jobHelper = jobHelper;
_settlementReportInitializeHandler = settlementReportInitializeHandler;
_gridAreaOwnerRepository = gridAreaOwnerRepository;
}

public async Task<JobRunId> HandleAsync(RequestSettlementReportCommand request)
{
if (request.MarketRole == MarketRole.GridAccessProvider)
{
JobRunId? firstRunId = null;

var gridAreas = request.RequestDto.Filter.GridAreas.Select(x => x.Key);

var distinctOwners = await GetGridAreaOwnersAsync(gridAreas, request.RequestDto.Filter).ConfigureAwait(false);

foreach (var owner in distinctOwners)
{
var id = await StartReportAsync(request, owner.Value).ConfigureAwait(false);
firstRunId ??= id;
}

return firstRunId!;
}

return await StartReportAsync(request, request.ActorGln).ConfigureAwait(false);
}

private async Task<IEnumerable<ActorNumber>> GetGridAreaOwnersAsync(IEnumerable<string> gridAreaCodes, SettlementReportRequestFilterDto filter)
{
var gridAreaOwners = new HashSet<ActorNumber>();

foreach (var grid in gridAreaCodes)
{
var owners = await _gridAreaOwnerRepository.GetGridAreaOwnersAsync(
new GridAreaCode(grid),
filter.PeriodStart.ToInstant(),
filter.PeriodEnd.ToInstant()).ConfigureAwait(false);

foreach (var owner in owners)
{
gridAreaOwners.Add(owner.ActorNumber);
}
}

return gridAreaOwners;
}

private async Task<JobRunId> StartReportAsync(RequestSettlementReportCommand request, string requestActorGln)
{
var reportId = new SettlementReportRequestId(Guid.NewGuid().ToString());

var runId = await _jobHelper.RunSettlementReportsJobAsync(request.RequestDto, request.MarketRole, reportId, requestActorGln).ConfigureAwait(false);

var runId = await _jobHelper.RunSettlementReportsJobAsync(request.RequestDto, request.MarketRole, reportId, request.ActorGln).ConfigureAwait(false);
await _settlementReportInitializeHandler
.InitializeFromJobAsync(
request.UserId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Energinet.DataHub.SettlementReport.Application.Model;
namespace Energinet.DataHub.SettlementReport.Infrastructure.Model;

public sealed record ActorNumber(string Value);
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Energinet.DataHub.SettlementReport.Application.Model;
namespace Energinet.DataHub.SettlementReport.Infrastructure.Model;

public sealed record GridAreaCode(string Value);
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@

using NodaTime;

namespace Energinet.DataHub.SettlementReport.Application.Model;
namespace Energinet.DataHub.SettlementReport.Infrastructure.Model;

public sealed record GridAreaOwner(GridAreaCode Code, ActorNumber ActorNumber, Instant ValidFrom);
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Energinet.DataHub.SettlementReport.Application.Model;
using Energinet.DataHub.SettlementReport.Application.Services;
using Energinet.DataHub.SettlementReport.Infrastructure.Contracts;
using Energinet.DataHub.SettlementReport.Infrastructure.Model;
using Energinet.DataHub.SettlementReport.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
using NodaTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Energinet.DataHub.SettlementReport.Application.Model;
using Energinet.DataHub.SettlementReport.Infrastructure.Model;
using NodaTime;

namespace Energinet.DataHub.SettlementReport.Application.Services;
namespace Energinet.DataHub.SettlementReport.Infrastructure.Services;

public interface IGridAreaOwnerRepository
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Energinet.DataHub.SettlementReport.Application.Model;
using Energinet.DataHub.SettlementReport.Infrastructure.Contracts;
using Energinet.DataHub.SettlementReport.Infrastructure.Model;
using Energinet.DataHub.SettlementReport.Infrastructure.Persistence;
using Energinet.DataHub.SettlementReport.Infrastructure.Services;
using Energinet.DataHub.SettlementReport.Test.Core.Fixture.Database;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using System.Collections.ObjectModel;
using Energinet.DataHub.SettlementReport.Application.Commands;
using Energinet.DataHub.SettlementReport.Application.Handlers;
using Energinet.DataHub.SettlementReport.Application.Services;
using Energinet.DataHub.SettlementReport.Interfaces.Helpers;
using Energinet.DataHub.SettlementReport.Interfaces.Models;
using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2;
Expand Down Expand Up @@ -56,7 +55,7 @@ public async Task Handle_ValidRequest_ReturnsJobId()
.ReturnsAsync(jobRunId);

var command = new RequestSettlementReportCommand(request, Guid.NewGuid(), Guid.NewGuid(), true, "1233", MarketRole.EnergySupplier);
var handler = new RequestSettlementReportHandler(jobHelperMock.Object, initializerMock.Object, new Mock<IGridAreaOwnerRepository>().Object);
var handler = new RequestSettlementReportHandler(jobHelperMock.Object, initializerMock.Object);

// Act
var result = await handler.HandleAsync(command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

using Energinet.DataHub.Core.App.Common.Extensions.DependencyInjection;
using Energinet.DataHub.SettlementReport.Application.Handlers;
using Energinet.DataHub.SettlementReport.Application.Services;
using Energinet.DataHub.SettlementReport.Application.SettlementReports_v2;
using Energinet.DataHub.SettlementReport.Common.Infrastructure.Extensions.Options;
using Energinet.DataHub.SettlementReport.Common.Infrastructure.HealthChecks;
Expand Down

0 comments on commit cf1d2fd

Please sign in to comment.