-
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.
- Loading branch information
1 parent
25b8000
commit 1ada669
Showing
11 changed files
with
236 additions
and
5 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
3 changes: 3 additions & 0 deletions
3
...ort/DatabaseMigration/Scripts/202410261405_Add_IsNotificationSent_to_SettlementReport.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,3 @@ | ||
ALTER TABLE [settlementreports].[SettlementReport] | ||
ADD [IsNotficationSent] [bit] NOT NULL DEFAULT(1); --For all existing records, we will assume that notification has been sent. | ||
GO |
35 changes: 35 additions & 0 deletions
35
...tration.SettlementReports/Functions/SettlementReports/DispatchIntegrationEventsTrigger.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,35 @@ | ||
// 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.Core.Messaging.Communication.Publisher; | ||
using Microsoft.Azure.Functions.Worker; | ||
|
||
namespace Energinet.DataHub.SettlementReport.Orchestration.SettlementReports.Functions.SettlementReports; | ||
|
||
public sealed class DispatchIntegrationEventsTrigger | ||
{ | ||
private readonly IPublisher _publisher; | ||
|
||
public DispatchIntegrationEventsTrigger(IPublisher publisher) | ||
{ | ||
_publisher = publisher; | ||
} | ||
|
||
[Function(nameof(DispatchIntegrationEventsTrigger))] | ||
public Task RunAsync([TimerTrigger("* */1 * * *")] FunctionContext context) | ||
{ | ||
ArgumentNullException.ThrowIfNull(context); | ||
return _publisher.PublishAsync(context.CancellationToken); | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
...nt-report/SettlementReports.Infrastructure/Contracts/UserNotificationTriggeredMetadata.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 UserNotificationTriggered | ||
{ | ||
public const string EventName = "UserNotificationTriggered"; | ||
public const int CurrentMinorVersion = 1; | ||
} |
65 changes: 65 additions & 0 deletions
65
...ement-report/SettlementReports.Infrastructure/Contracts/user_notification_triggered.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,65 @@ | ||
/* 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"; | ||
|
||
option csharp_namespace = "Energinet.DataHub.SettlementReport.Infrastructure.Contracts"; | ||
|
||
/* | ||
* UserNotificationTriggered Integration Event. | ||
* | ||
* Occurs when some action triggers the notification of a set of users. | ||
*/ | ||
message UserNotificationTriggered { | ||
|
||
/* | ||
* An identifier specifying the reason for the notification. | ||
*/ | ||
string reason_identifier = 1; | ||
|
||
/* | ||
* The unique identifier of the actor whose users will receive the notification. | ||
*/ | ||
string target_actor_id = 2; | ||
|
||
oneof target { | ||
|
||
/* | ||
* The unique identifier of the user that should receive the notification. | ||
*/ | ||
string target_user_id = 3; | ||
|
||
/* | ||
* The unique identifier of the group of users having the specified permission that should receive the notification. | ||
*/ | ||
string target_permissions = 4; | ||
} | ||
|
||
/* | ||
* A reason-specific id of an entity that the notification targets. | ||
*/ | ||
string related_id = 5; | ||
|
||
/* | ||
* A timestamp for when the notification was generated. | ||
*/ | ||
google.protobuf.Timestamp occurred_at = 6; | ||
|
||
/* | ||
* A timestamp for when the notification expires by itself. | ||
*/ | ||
google.protobuf.Timestamp expires_at = 7; | ||
} |
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
69 changes: 69 additions & 0 deletions
69
...tlement-report/SettlementReports.Infrastructure/Notifications/IntegrationEventProvider.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,69 @@ | ||
// 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.Core.Messaging.Communication; | ||
using Energinet.DataHub.Core.Messaging.Communication.Publisher; | ||
using Energinet.DataHub.SettlementReport.Application.SettlementReports_v2; | ||
using Google.Protobuf.WellKnownTypes; | ||
|
||
namespace Energinet.DataHub.SettlementReport.Infrastructure.Notifications; | ||
|
||
public sealed class IntegrationEventProvider : IIntegrationEventProvider | ||
{ | ||
private readonly ISettlementReportRepository _settlementReportRepository; | ||
|
||
public IntegrationEventProvider(ISettlementReportRepository settlementReportRepository) | ||
{ | ||
_settlementReportRepository = settlementReportRepository; | ||
} | ||
|
||
public async IAsyncEnumerable<IntegrationEvent> GetAsync() | ||
{ | ||
var reportsForNotifications = await _settlementReportRepository | ||
.GetNeedsNotificationSent() | ||
.ConfigureAwait(false); | ||
|
||
foreach (var reportForNotification in reportsForNotifications) | ||
{ | ||
yield return await CreateAsync(reportForNotification).ConfigureAwait(false); | ||
|
||
reportForNotification.MarkAsNotificationSent(); | ||
|
||
await _settlementReportRepository.AddOrUpdateAsync(reportForNotification) | ||
.ConfigureAwait(false); | ||
} | ||
} | ||
|
||
private Task<IntegrationEvent> CreateAsync(Application.SettlementReports_v2.SettlementReport reportForNotification) | ||
{ | ||
ArgumentNullException.ThrowIfNull(reportForNotification); | ||
|
||
var now = DateTime.UtcNow; | ||
|
||
var integrationEvent = new IntegrationEvent( | ||
Guid.Parse(reportForNotification.RequestId), | ||
Contracts.UserNotificationTriggered.EventName, | ||
Contracts.UserNotificationTriggered.CurrentMinorVersion, | ||
new Contracts.UserNotificationTriggered | ||
{ | ||
ReasonIdentifier = "SettlementReportFinished", | ||
TargetActorId = reportForNotification.ActorId.ToString(), | ||
RelatedId = reportForNotification.Id.ToString(), | ||
OccurredAt = now.ToTimestamp(), | ||
ExpiresAt = now.AddHours(23).ToTimestamp(), | ||
}); | ||
|
||
return Task.FromResult(integrationEvent); | ||
} | ||
} |
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