-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: grid area ownership event handling
- Loading branch information
1 parent
ed4bc04
commit edd308c
Showing
21 changed files
with
610 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
source/settlement-report/DatabaseMigration/Scripts/202412021100_Add_GridAreaOwner.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE [settlementreports].[GridAreaOwner] | ||
( | ||
Id INT IDENTITY(1,1) NOT NULL PRIMARY KEY, | ||
Code VARCHAR(4) NOT NULL, | ||
ActorNumber VARCHAR(50) NOT NULL, | ||
ValidFrom datetimeoffset(7) NOT NULL, | ||
SequenceNumber INT NOT NULL DEFAULT 0, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
source/settlement-report/SettlementReports.Function/Functions/ExchangeEventTrigger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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 Azure.Messaging.ServiceBus; | ||
using Energinet.DataHub.Core.Messaging.Communication; | ||
using Energinet.DataHub.Core.Messaging.Communication.Extensions.Options; | ||
using Energinet.DataHub.Core.Messaging.Communication.Subscriber; | ||
using Energinet.DataHub.RevisionLog.Integration; | ||
using Energinet.DataHub.SettlementReport.Common.Infrastructure.Telemetry; | ||
using Microsoft.Azure.Functions.Worker; | ||
using NodaTime; | ||
|
||
namespace SettlementReports.Function.Functions; | ||
|
||
public sealed class ExchangeEventTrigger | ||
{ | ||
private readonly ISubscriber _subscriber; | ||
private readonly IRevisionLogClient _revisionLogClient; | ||
|
||
public ExchangeEventTrigger(ISubscriber subscriber, IRevisionLogClient revisionLogClient) | ||
{ | ||
_subscriber = subscriber; | ||
_revisionLogClient = revisionLogClient; | ||
} | ||
|
||
[Function(nameof(ExchangeEventTrigger))] | ||
public async Task RunAsync( | ||
[ServiceBusTrigger( | ||
$"%{IntegrationEventsOptions.SectionName}:{nameof(IntegrationEventsOptions.TopicName)}%", | ||
$"%{IntegrationEventsOptions.SectionName}:{nameof(IntegrationEventsOptions.SubscriptionName)}%", | ||
Connection = ServiceBusNamespaceOptions.SectionName)] | ||
ServiceBusReceivedMessage message, | ||
FunctionContext context) | ||
{ | ||
ArgumentNullException.ThrowIfNull(message); | ||
ArgumentNullException.ThrowIfNull(context); | ||
|
||
var msg = IntegrationEventServiceBusMessage.Create(message); | ||
|
||
await _revisionLogClient.LogAsync( | ||
new RevisionLogEntry( | ||
logId: msg.MessageId, | ||
systemId: SubsystemInformation.Id, | ||
occurredOn: SystemClock.Instance.GetCurrentInstant(), | ||
activity: "ConsumedIntegrationEvent", | ||
origin: nameof(ExchangeEventTrigger), | ||
payload: Convert.ToBase64String(message.Body))) | ||
.ConfigureAwait(false); | ||
|
||
await _subscriber.HandleAsync(msg).ConfigureAwait(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...settlement-report/SettlementReports.Infrastructure/Contracts/GridAreaOwnershipAssigned.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// 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.SettlementReport.Infrastructure.Contracts; | ||
|
||
public partial class GridAreaOwnershipAssigned | ||
{ | ||
public const string EventName = "GridAreaOwnershipAssigned"; | ||
public const int CurrentMinorVersion = 1; | ||
} |
39 changes: 39 additions & 0 deletions
39
source/settlement-report/SettlementReports.Infrastructure/Contracts/eic_function.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* 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. | ||
*/ | ||
|
||
syntax = "proto3"; | ||
|
||
option csharp_namespace = "Energinet.DataHub.SettlementReport.Infrastructure.Contracts"; | ||
|
||
enum EicFunction { | ||
/* | ||
* Unspecified is unused but according to best practice. | ||
* Read more at https://protobuf.dev/programming-guides/style/#enums. | ||
*/ | ||
EIC_FUNCTION_UNSPECIFIED = 0; | ||
EIC_FUNCTION_GRID_ACCESS_PROVIDER = 1; | ||
EIC_FUNCTION_BALANCE_RESPONSIBLE_PARTY = 2; | ||
EIC_FUNCTION_BILLING_AGENT = 3; | ||
EIC_FUNCTION_ENERGY_SUPPLIER = 4; | ||
EIC_FUNCTION_IMBALANCE_SETTLEMENT_RESPONSIBLE = 5; | ||
EIC_FUNCTION_METERED_DATA_ADMINISTRATOR = 6; | ||
EIC_FUNCTION_METERED_DATA_RESPONSIBLE = 7; | ||
EIC_FUNCTION_METERING_POINT_ADMINISTRATOR = 8; | ||
EIC_FUNCTION_SYSTEM_OPERATOR = 9; | ||
EIC_FUNCTION_DANISH_ENERGY_AGENCY = 10; | ||
EIC_FUNCTION_DATAHUB_ADMINISTRATOR = 11; | ||
EIC_FUNCTION_INDEPENDENT_AGGREGATOR = 12; | ||
EIC_FUNCTION_SERIAL_ENERGY_TRADER = 13; | ||
} |
53 changes: 53 additions & 0 deletions
53
...ment-report/SettlementReports.Infrastructure/Contracts/grid_area_ownership_assigned.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* 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. | ||
*/ | ||
|
||
syntax = "proto3"; | ||
import "google/protobuf/timestamp.proto"; | ||
import "Contracts/eic_function.proto"; | ||
|
||
option csharp_namespace = "Energinet.DataHub.SettlementReport.Infrastructure.Contracts"; | ||
|
||
/* | ||
* GridAreaOwnershipAssigned Integration Event. | ||
* | ||
* Occurs when an actor is assigned ownership of a grid area through the specified market role. | ||
*/ | ||
message GridAreaOwnershipAssigned { | ||
|
||
/* | ||
* The EIC or GLN identifier of the actor that got assigned ownership. | ||
*/ | ||
string actor_number = 1; | ||
|
||
/* | ||
* The code of the grid area that the actor got ownership of. | ||
*/ | ||
string grid_area_code = 2; | ||
|
||
/* | ||
* The market role for which the ownership is assigned. | ||
*/ | ||
EicFunction actor_role = 3; | ||
|
||
/* | ||
* A timestamp from when the ownership is valid. | ||
*/ | ||
google.protobuf.Timestamp valid_from = 4; | ||
|
||
/* | ||
* The sequence number of the event. Used to distinguish between events with identical valid_from timestamps. | ||
*/ | ||
int32 sequence_number = 5; | ||
} |
17 changes: 17 additions & 0 deletions
17
source/settlement-report/SettlementReports.Infrastructure/Model/ActorNumber.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.SettlementReport.Infrastructure.Model; | ||
|
||
public sealed record ActorNumber(string Value); |
17 changes: 17 additions & 0 deletions
17
source/settlement-report/SettlementReports.Infrastructure/Model/GridAreaCode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.SettlementReport.Infrastructure.Model; | ||
|
||
public sealed record GridAreaCode(string Value); |
19 changes: 19 additions & 0 deletions
19
source/settlement-report/SettlementReports.Infrastructure/Model/GridAreaOwner.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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 NodaTime; | ||
|
||
namespace Energinet.DataHub.SettlementReport.Infrastructure.Model; | ||
|
||
public sealed record GridAreaOwner(GridAreaCode Code, ActorNumber ActorNumber, Instant ValidFrom); |
28 changes: 28 additions & 0 deletions
28
source/settlement-report/SettlementReports.Infrastructure/Persistence/GridAreaOwnerEntity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// 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.SettlementReport.Infrastructure.Persistence; | ||
|
||
public class GridAreaOwnerEntity | ||
{ | ||
public int Id { get; set; } | ||
|
||
public string Code { get; set; } = null!; | ||
|
||
public string ActorNumber { get; set; } = null!; | ||
|
||
public DateTimeOffset ValidFrom { get; set; } | ||
|
||
public int SequenceNumber { get; set; } | ||
} |
32 changes: 32 additions & 0 deletions
32
...t-report/SettlementReports.Infrastructure/Persistence/GridAreaOwnerEntityConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// 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 Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Energinet.DataHub.SettlementReport.Infrastructure.Persistence; | ||
|
||
public class GridAreaOwnerEntityConfiguration : IEntityTypeConfiguration<GridAreaOwnerEntity> | ||
{ | ||
public void Configure(EntityTypeBuilder<GridAreaOwnerEntity> builder) | ||
{ | ||
ArgumentNullException.ThrowIfNull(builder); | ||
|
||
builder.ToTable("GridAreaOwner"); | ||
builder.HasKey(e => e.Id); | ||
builder.Property(e => e.Id).ValueGeneratedOnAdd(); | ||
builder.Property(e => e.Code).HasMaxLength(4); | ||
builder.Property(e => e.ActorNumber).HasMaxLength(50); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.