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

feat: Start MeteredDataForMeasurementPoint orchestration from EDI #1425

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6e1d063
Send Wholesale/Energi requests to PM
ebbeknudsen Dec 11, 2024
fba009a
Update EDI to start process for each transaction
ebbeknudsen Dec 11, 2024
8ff7e91
Update RequestProcessOrchestrationStarter.cs
ebbeknudsen Dec 11, 2024
165a6b4
Fix architecture tests
ebbeknudsen Dec 11, 2024
77e82f2
Move process manager call to incoming messages
ebbeknudsen Dec 11, 2024
0a62753
Fix test
ebbeknudsen Dec 11, 2024
95a25f8
Fix B2C tests
ebbeknudsen Dec 11, 2024
d03b164
Fix incoming messages test
ebbeknudsen Dec 11, 2024
7bd7171
Default to an "empty" spy if none is registered
ebbeknudsen Dec 11, 2024
afa6be9
Update to use a default spy instead of a new spy
ebbeknudsen Dec 11, 2024
0c45187
Add missing health check
ebbeknudsen Dec 11, 2024
edad36a
Use actual values for starting process
ebbeknudsen Dec 11, 2024
b2a2924
Add test for mapping
ebbeknudsen Dec 11, 2024
9a1d83c
Add app test for starting energy request
ebbeknudsen Dec 11, 2024
f3003b2
Fix test
ebbeknudsen Dec 11, 2024
46884d2
Update RequestAggregatedMeasureDataTests.cs
ebbeknudsen Dec 11, 2024
d498803
Wip
AndersBallingPetersen Dec 16, 2024
6f3520e
Merge branch 'main' into xabpe/Start-from-Command-in-EDI
AndersBallingPetersen Dec 16, 2024
98e6d23
Start MeteredDataForMeasurementPoint orchestration from EDI
AndersBallingPetersen Dec 16, 2024
9a5c787
Merge branch 'main' into xabpe/Start-from-Command-in-EDI
AndersBallingPetersen Dec 16, 2024
bdbe9b1
Align naming
AndersBallingPetersen Dec 18, 2024
43f146f
Fix naming
AndersBallingPetersen Dec 18, 2024
902c81d
Old test asserts removed for incoming messages
AndersBallingPetersen Dec 20, 2024
d86dc44
Fix tests
AndersBallingPetersen Jan 6, 2025
994eabd
Merge remote-tracking branch 'origin/main' into xabpe/Start-from-Comm…
AndersBallingPetersen Jan 6, 2025
cb2aef6
Cleanup
AndersBallingPetersen Jan 6, 2025
0cdce06
Move MeteredData to own OrchestrationStarter
AndersBallingPetersen Jan 6, 2025
673d465
Fix RegistrationDateTime
AndersBallingPetersen Jan 6, 2025
1a4bf7d
Fix orchestration test values
AndersBallingPetersen Jan 6, 2025
eb0aa7d
Deprecate incoming ebix tests
AndersBallingPetersen Jan 6, 2025
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 @@ -128,13 +128,9 @@ private async Task SendInitializeMeteredDataForMeasurementPointMessageProcessAsy
{
ArgumentNullException.ThrowIfNull(initializeMeteredDataForMeasurementPointMessageProcessDto);

var serviceBusMessage =
new ServiceBusMessage(
_serializer.Serialize(initializeMeteredDataForMeasurementPointMessageProcessDto))
{
Subject = nameof(InitializeMeteredDataForMeasurementPointMessageProcessDto),
};

await _sender.SendMessageAsync(serviceBusMessage, cancellationToken).ConfigureAwait(false);
await _requestProcessOrchestrationStarter.StartMeteredDataForMeasurementPointOrchestrationAsync(
initializeMeteredDataForMeasurementPointMessageProcessDto,
cancellationToken)
.ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Energinet.DataHub.EDI.IncomingMessages.Infrastructure</AssemblyName>
<RootNamespace>Energinet.DataHub.EDI.IncomingMessages.Infrastructure</RootNamespace>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ Task StartRequestWholesaleServicesOrchestrationAsync(
Task StartRequestAggregatedMeasureDataOrchestrationAsync(
InitializeAggregatedMeasureDataProcessDto initializeProcessDto,
CancellationToken cancellationToken);

Task StartMeteredDataForMeasurementPointOrchestrationAsync(
InitializeMeteredDataForMeasurementPointMessageProcessDto initializeProcessDto,
AndersBallingPetersen marked this conversation as resolved.
Show resolved Hide resolved
CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Collections.ObjectModel;
using System.Globalization;
using Energinet.DataHub.EDI.BuildingBlocks.Domain.Authentication;
using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models;
using Energinet.DataHub.EDI.Process.Interfaces;
using Energinet.DataHub.ProcessManager.Abstractions.Api.Model.OrchestrationInstance;
using Energinet.DataHub.ProcessManager.Client;
using Energinet.DataHub.ProcessManager.Orchestrations.Abstractions.Processes.BRS_021.ForwardMeteredData.V1.Model;
using Energinet.DataHub.ProcessManager.Orchestrations.Abstractions.Processes.BRS_026.V1.Model;
using Energinet.DataHub.ProcessManager.Orchestrations.Abstractions.Processes.BRS_028.V1.Model;
using NodaTime.Text;

namespace Energinet.DataHub.EDI.IncomingMessages.Infrastructure.ProcessManager;

Expand Down Expand Up @@ -130,6 +134,62 @@ public async Task StartRequestAggregatedMeasureDataOrchestrationAsync(
await Task.WhenAll(startProcessTasks).ConfigureAwait(false);
}

public async Task StartMeteredDataForMeasurementPointOrchestrationAsync(
InitializeMeteredDataForMeasurementPointMessageProcessDto initializeProcessDto,
CancellationToken cancellationToken)
{
var actorId = GetAuthenticatedActorId(initializeProcessDto.MessageId);
var actorIdentity = new ActorIdentityDto(actorId);

var startProcessTasks = new List<Task>();
foreach (var transaction in initializeProcessDto.Series)
{
AndersBallingPetersen marked this conversation as resolved.
Show resolved Hide resolved
var meteringPointType = transaction.MeteringPointType is not null
? MeteringPointType.TryGetNameFromCode(transaction.MeteringPointType, fallbackValue: transaction.MeteringPointType)
: null;

var productUnitType = transaction.ProductUnitType is not null
? MeasurementUnit.TryGetNameFromCode(transaction.ProductUnitType, fallbackValue: transaction.ProductUnitType)
: null;

var resolution = transaction.Resolution is not null
? Resolution.TryGetNameFromCode(transaction.Resolution, fallbackValue: transaction.Resolution)
: null;

var startCommand =
new StartForwardMeteredDataCommandV1(
operatingIdentity: actorIdentity,
new MeteredDataForMeasurementPointMessageInputV1(
AuthenticatedActorId: actorId,
TransactionId: transaction.TransactionId,
MeteringPointId: transaction.MeteringPointLocationId,
MeteringPointType: meteringPointType,
ProductNumber: transaction.ProductNumber,
MeasureUnit: productUnitType,
RegistrationDateTime: InstantPattern.General.Parse(initializeProcessDto.CreatedAt).Value.ToString(),
MadsDue marked this conversation as resolved.
Show resolved Hide resolved
Resolution: resolution,
StartDateTime: transaction.StartDateTime,
EndDateTime: transaction.EndDateTime,
GridAccessProviderNumber: transaction.RequestedByActor.ActorNumber.Value,
DelegatedGridAreaCodes: transaction.DelegatedGridAreaCodes,
EnergyObservations:
new ReadOnlyCollection<EnergyObservation>(
transaction.EnergyObservations
.Select(energyObservation =>
new EnergyObservation(
Position: energyObservation.Position,
EnergyQuantity: energyObservation.EnergyQuantity,
QuantityQuality: energyObservation.QuantityQuality))
.ToList())),
initializeProcessDto.MessageId);

var startProcessTask = _processManagerMessageClient.StartNewOrchestrationInstanceAsync(startCommand, CancellationToken.None);
startProcessTasks.Add(startProcessTask);
}

await Task.WhenAll(startProcessTasks).ConfigureAwait(false);
}

private Guid GetAuthenticatedActorId(string messageId)
{
if (!_authenticatedActor.TryGetCurrentActorIdentity(out var actorIdentity))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Energinet.DataHub.EDI.BuildingBlocks.Infrastructure.FeatureFlag;
using Energinet.DataHub.EDI.BuildingBlocks.Interfaces;
using Energinet.DataHub.EDI.Process.Application.Transactions.AggregatedMeasureData;
using Energinet.DataHub.EDI.Process.Domain.Transactions;
using Energinet.DataHub.EDI.Process.Interfaces;
using MediatR;
AndersBallingPetersen marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -41,6 +43,7 @@ public bool CanHandle(string processTypeToInitialize)
public async Task ProcessAsync(byte[] processInitializationData)
{
var marketMessage = _serializer.Deserialize<InitializeAggregatedMeasureDataProcessDto>(System.Text.Encoding.UTF8.GetString(processInitializationData));

await _mediator.Send(new InitializeAggregatedMeasureDataProcessesCommand(marketMessage)).ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
using Energinet.DataHub.EDI.OutgoingMessages.Interfaces;
using Energinet.DataHub.EDI.OutgoingMessages.Interfaces.Models.MeteredDataForMeasurementPoint;
using Energinet.DataHub.EDI.Process.Interfaces;
using MediatR;
using Microsoft.Extensions.Logging;
using NodaTime;
using NodaTime.Text;
using EventId = Energinet.DataHub.EDI.BuildingBlocks.Domain.Models.EventId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

using Energinet.DataHub.EDI.BuildingBlocks.Domain.Authentication;
using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models;
using Energinet.DataHub.EDI.IncomingMessages.Domain;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.ProcessManager;
using Energinet.DataHub.EDI.Process.Interfaces;
using Energinet.DataHub.ProcessManager.Abstractions.Api.Model;
using Energinet.DataHub.ProcessManager.Abstractions.Api.Model.OrchestrationInstance;
using Energinet.DataHub.ProcessManager.Client;
using Energinet.DataHub.ProcessManager.Orchestrations.Abstractions.Processes.BRS_021.ForwardMeteredData.V1.Model;
using Energinet.DataHub.ProcessManager.Orchestrations.Abstractions.Processes.BRS_026.V1.Model;
using Energinet.DataHub.ProcessManager.Orchestrations.Abstractions.Processes.BRS_028.V1.Model;
using FluentAssertions;
Expand Down Expand Up @@ -247,4 +249,128 @@ await sut.StartRequestAggregatedMeasureDataOrchestrationAsync(
.NotBeNull()
.And.BeEquivalentTo(expectedCommand);
}

[Theory]
[InlineData("571313101700011887", "E17", "2023-05-31T22:00:00Z", "8716867000030", "Kwh", "PT1H")]
[InlineData(null, null, null, null, null, null)]
public async Task Given_MeteredDataForMeasurementPoint_When_StartMeteredDataForMeasurementCalled_Then_ProcessManagerMessageClientIsCalled(
string? expectedMeteringPointId,
string? expectedMeteringPointType,
string? expectedEndDate,
string? expectedProductNumber,
string? expectedMeasureUnit,
string? expectedResolution)
{
// Arrange
// => Setup input
var requestedByActor = RequestedByActor.From(ActorNumber.Create("1111111111111"), ActorRole.GridAccessProvider);

var expectedBusinessReason = BusinessReason.PeriodicMetering;
var expectedTransactionId = MessageId.Create("9b6184bf-2f05-40b9-d783-08dc814df95a").Value;
var expectedStart = "2023-04-30T22:00:00Z";
var expectedRegistrationDateFrom = "2023-04-30T22:00:00Z";
var expectedPosition = "1";
var expectedEnergyQuantity = "A03";
var expectedQuantityQuality = "1001";
AndersBallingPetersen marked this conversation as resolved.
Show resolved Hide resolved

var meteringPointType = expectedMeteringPointType is not null
? MeteringPointType.FromCode(expectedMeteringPointType)
: null;
var productUnitType = expectedMeasureUnit is not null
? MeasurementUnit.FromCode(expectedMeasureUnit)
: null;
var resolution = expectedResolution is not null
? Resolution.FromCode(expectedResolution)
: null;

var initializeProcessDto = new InitializeMeteredDataForMeasurementPointMessageProcessDto(
MessageId: expectedTransactionId,
MessageType: "E66",
CreatedAt: expectedRegistrationDateFrom,
BusinessReason: expectedBusinessReason.Code,
BusinessType: "23",
Series:
[
new InitializeMeteredDataForMeasurementPointMessageSeries(
TransactionId: expectedTransactionId,
Resolution: resolution?.Code,
StartDateTime: expectedStart,
EndDateTime: expectedEndDate,
ProductNumber: expectedProductNumber,
ProductUnitType: productUnitType?.Code,
MeteringPointType: meteringPointType?.Code,
MeteringPointLocationId: expectedMeteringPointId,
DelegatedGridAreaCodes: null,
RequestedByActor: requestedByActor,
EnergyObservations:
[
new InitializeEnergyObservation(
Position: expectedPosition,
EnergyQuantity: expectedEnergyQuantity,
QuantityQuality: expectedQuantityQuality)
])
]);

// => Setup Process Manager client and callback
var processManagerClient = new Mock<IProcessManagerMessageClient>();
MessageCommand<MeteredDataForMeasurementPointMessageInputV1>? actualCommand = null;
processManagerClient.Setup(
client => client.StartNewOrchestrationInstanceAsync(
It.IsAny<StartForwardMeteredDataCommandV1>(),
It.IsAny<CancellationToken>()))
.Callback((MessageCommand<MeteredDataForMeasurementPointMessageInputV1> command, CancellationToken token) => actualCommand = command);

// => Setup authenticated actor
var expectedActorId = Guid.NewGuid();
var authenticatedActor = new AuthenticatedActor();
authenticatedActor.SetAuthenticatedActor(new ActorIdentity(
ActorNumber.Create("1234567890123"),
AndersBallingPetersen marked this conversation as resolved.
Show resolved Hide resolved
Restriction.None,
ActorRole.GridAccessProvider,
expectedActorId));

var sut = new RequestProcessOrchestrationStarter(
processManagerClient.Object,
authenticatedActor);

// Act
await sut.StartMeteredDataForMeasurementPointOrchestrationAsync(
initializeProcessDto,
CancellationToken.None);

// Assert
processManagerClient.Verify(
client => client.StartNewOrchestrationInstanceAsync(
It.IsAny<StartForwardMeteredDataCommandV1>(),
It.IsAny<CancellationToken>()),
Times.Once);

var expectedCommand = new StartForwardMeteredDataCommandV1(
operatingIdentity: new ActorIdentityDto(expectedActorId),
inputParameter: new MeteredDataForMeasurementPointMessageInputV1(
AuthenticatedActorId: expectedActorId,
TransactionId: expectedTransactionId,
MeteringPointId: expectedMeteringPointId,
MeteringPointType: meteringPointType?.Name,
ProductNumber: expectedProductNumber,
MeasureUnit: expectedMeasureUnit,
RegistrationDateTime: expectedRegistrationDateFrom,
Resolution: resolution?.Name,
StartDateTime: expectedStart,
EndDateTime: expectedEndDate,
GridAccessProviderNumber: requestedByActor.ActorNumber.Value,
DelegatedGridAreaCodes: null,
EnergyObservations:
[
new ProcessManager.Orchestrations.Abstractions.Processes.BRS_021.ForwardMeteredData.V1.Model.EnergyObservation(
Position: expectedPosition,
EnergyQuantity: expectedEnergyQuantity,
QuantityQuality: expectedQuantityQuality)
]),
messageId: expectedTransactionId);

actualCommand.Should()
.NotBeNull()
.And.BeEquivalentTo(expectedCommand);
}
}
Loading