From c6c19d2ad75c5755e5e7e1e42c7817db9c0e52f4 Mon Sep 17 00:00:00 2001 From: Anders Balling Petersen Date: Fri, 15 Nov 2024 10:15:04 +0100 Subject: [PATCH 1/3] refac: 0. Refactor MasterData module to clean architecture (#1344) * Refactored MasterData module to clean architecture * Create wrapper interface for MasterDataContext --------- Co-authored-by: Ebbe Knudsen --- source/B2BApi/B2BApi.csproj | 2 +- source/B2BApi/HostFactory.cs | 2 +- source/B2CWebApi/B2CWebApi.csproj | 34 +++++++-------- source/B2CWebApi/Program.cs | 2 +- source/Edi.Repository.sln | 42 +++++++++---------- source/Edi.UnitTests/Edi.UnitTests.csproj | 2 +- source/Edi.UnitTests/EdiTestBase.cs | 6 +-- .../IncomingMessages.IntegrationTests.csproj | 4 +- .../IncomingMessagesTestBase.cs | 4 +- .../Fixture/IntegrationEventsTestBase.cs | 5 +-- .../IntegrationEvents.IntegrationTests.csproj | 2 +- .../Behaviours/BehavioursTestBase.cs | 2 +- .../IntegrationTests/IntegrationTests.csproj | 2 +- source/IntegrationTests/TestBase.cs | 2 +- .../IMasterDataContext.cs | 27 ++++++++++++ .../MasterData.Application.csproj | 8 ++-- .../MasterDataClient.cs | 7 ++-- .../ActorCertificates/ActorCertificate.cs | 1 - .../IActorCertificateRepository.cs | 2 - .../Actors/IActorRepository.cs | 2 - .../IProcessDelegationRepository.cs | 3 -- .../ProcessDelegations/ProcessDelegation.cs | 1 - .../ActorCertificateEntityConfiguration.cs | 3 +- .../Actors/ActorEntityConfiguration.cs | 1 - .../Actors/ActorRepository.cs | 2 - .../DataAccess/MasterDataContext.cs | 7 ++-- .../MasterDataExtensions.cs | 9 +++- .../GridAreaOwnerEntityConfiguration.cs | 1 - .../MasterData.Infrastructure.csproj | 5 ++- .../ProcessDelegationEntityConfiguration.cs | 3 +- .../Fixture/MasterDataTestBase.cs | 4 +- .../MasterData.IntegrationTests.csproj | 2 +- .../OutgoingMessages.IntegrationTests.csproj | 26 ++++++------ .../OutgoingMessagesTestBase.cs | 5 +-- 34 files changed, 120 insertions(+), 110 deletions(-) create mode 100644 source/MasterData.Application/IMasterDataContext.cs rename source/{MasterData.Application => MasterData.Infrastructure}/Extensions/DependencyInjection/MasterDataExtensions.cs (87%) diff --git a/source/B2BApi/B2BApi.csproj b/source/B2BApi/B2BApi.csproj index 5acd4c74f1..e90d5f697c 100644 --- a/source/B2BApi/B2BApi.csproj +++ b/source/B2BApi/B2BApi.csproj @@ -60,7 +60,7 @@ limitations under the License. - + diff --git a/source/B2BApi/HostFactory.cs b/source/B2BApi/HostFactory.cs index a4389816aa..8c37e96a32 100644 --- a/source/B2BApi/HostFactory.cs +++ b/source/B2BApi/HostFactory.cs @@ -25,7 +25,7 @@ using Energinet.DataHub.EDI.DataAccess.UnitOfWork.Extensions.DependencyInjection; using Energinet.DataHub.EDI.IncomingMessages.Application.Extensions.DependencyInjection; using Energinet.DataHub.EDI.IntegrationEvents.Application.Extensions.DependencyInjection; -using Energinet.DataHub.EDI.MasterData.Application.Extensions.DependencyInjection; +using Energinet.DataHub.EDI.MasterData.Infrastructure.Extensions.DependencyInjection; using Energinet.DataHub.EDI.Outbox.Infrastructure; using Energinet.DataHub.EDI.OutgoingMessages.Application.Extensions.DependencyInjection; using Energinet.DataHub.EDI.Process.Application.Extensions.DependencyInjection; diff --git a/source/B2CWebApi/B2CWebApi.csproj b/source/B2CWebApi/B2CWebApi.csproj index a7cc846ee4..4db79b396b 100644 --- a/source/B2CWebApi/B2CWebApi.csproj +++ b/source/B2CWebApi/B2CWebApi.csproj @@ -8,33 +8,33 @@ - + - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - - - - - - - - + + + + + + + + - + - - + + diff --git a/source/B2CWebApi/Program.cs b/source/B2CWebApi/Program.cs index da00b0d93a..5fb79ee946 100644 --- a/source/B2CWebApi/Program.cs +++ b/source/B2CWebApi/Program.cs @@ -24,7 +24,7 @@ using Energinet.DataHub.EDI.B2CWebApi.Security; using Energinet.DataHub.EDI.DataAccess.UnitOfWork.Extensions.DependencyInjection; using Energinet.DataHub.EDI.IncomingMessages.Application.Extensions.DependencyInjection; -using Energinet.DataHub.EDI.MasterData.Application.Extensions.DependencyInjection; +using Energinet.DataHub.EDI.MasterData.Infrastructure.Extensions.DependencyInjection; using Energinet.DataHub.EDI.Outbox.Infrastructure; var builder = WebApplication.CreateBuilder(args); diff --git a/source/Edi.Repository.sln b/source/Edi.Repository.sln index 81b88ac8d5..dedcaae76b 100644 --- a/source/Edi.Repository.sln +++ b/source/Edi.Repository.sln @@ -122,12 +122,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{1DEA9C4F EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MasterData.IntegrationTests", "MasterData.IntegrationTests\MasterData.IntegrationTests.csproj", "{0EA98CF7-1E71-4FFE-9825-A9EA22701E6D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MasterData.Application", "MasterData.Application\MasterData.Application.csproj", "{104BEB59-8E92-4517-8141-620073B89887}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MasterData.Domain", "MasterData.Domain\MasterData.Domain.csproj", "{CDB51D9E-3D69-4E37-A9D4-B12E04722078}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MasterData.Infrastructure", "MasterData.Infrastructure\MasterData.Infrastructure.csproj", "{17E5D9E6-C482-47C5-BABA-56ACFA13BD43}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MasterData.Interfaces", "MasterData.Interfaces\MasterData.Interfaces.csproj", "{03330B59-67CF-426E-AB61-1F87137E10F4}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Outbox", "Outbox", "{C31C36C8-7661-4782-9915-E8278CD4DFEA}" @@ -206,6 +200,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProcessManager.Core.Tests", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProcessManager.Orchestrations.Tests", "ProcessManager.Orchestrations.Tests\ProcessManager.Orchestrations.Tests.csproj", "{6E524405-2B66-4563-B043-492DB8734060}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MasterData.Infrastructure", "MasterData.Infrastructure\MasterData.Infrastructure.csproj", "{61571A46-1145-4FF9-9C91-47C33520B53A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MasterData.Application", "MasterData.Application\MasterData.Application.csproj", "{0E787394-5AD2-4920-900F-E802EDB726B6}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MasterData.Domain", "MasterData.Domain\MasterData.Domain.csproj", "{4A238A51-ED28-4039-8046-ED7B1336C614}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -328,18 +328,6 @@ Global {0EA98CF7-1E71-4FFE-9825-A9EA22701E6D}.Debug|Any CPU.Build.0 = Debug|Any CPU {0EA98CF7-1E71-4FFE-9825-A9EA22701E6D}.Release|Any CPU.ActiveCfg = Release|Any CPU {0EA98CF7-1E71-4FFE-9825-A9EA22701E6D}.Release|Any CPU.Build.0 = Release|Any CPU - {104BEB59-8E92-4517-8141-620073B89887}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {104BEB59-8E92-4517-8141-620073B89887}.Debug|Any CPU.Build.0 = Debug|Any CPU - {104BEB59-8E92-4517-8141-620073B89887}.Release|Any CPU.ActiveCfg = Release|Any CPU - {104BEB59-8E92-4517-8141-620073B89887}.Release|Any CPU.Build.0 = Release|Any CPU - {CDB51D9E-3D69-4E37-A9D4-B12E04722078}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CDB51D9E-3D69-4E37-A9D4-B12E04722078}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CDB51D9E-3D69-4E37-A9D4-B12E04722078}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CDB51D9E-3D69-4E37-A9D4-B12E04722078}.Release|Any CPU.Build.0 = Release|Any CPU - {17E5D9E6-C482-47C5-BABA-56ACFA13BD43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {17E5D9E6-C482-47C5-BABA-56ACFA13BD43}.Debug|Any CPU.Build.0 = Debug|Any CPU - {17E5D9E6-C482-47C5-BABA-56ACFA13BD43}.Release|Any CPU.ActiveCfg = Release|Any CPU - {17E5D9E6-C482-47C5-BABA-56ACFA13BD43}.Release|Any CPU.Build.0 = Release|Any CPU {03330B59-67CF-426E-AB61-1F87137E10F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {03330B59-67CF-426E-AB61-1F87137E10F4}.Debug|Any CPU.Build.0 = Debug|Any CPU {03330B59-67CF-426E-AB61-1F87137E10F4}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -452,6 +440,18 @@ Global {6E524405-2B66-4563-B043-492DB8734060}.Debug|Any CPU.Build.0 = Debug|Any CPU {6E524405-2B66-4563-B043-492DB8734060}.Release|Any CPU.ActiveCfg = Release|Any CPU {6E524405-2B66-4563-B043-492DB8734060}.Release|Any CPU.Build.0 = Release|Any CPU + {61571A46-1145-4FF9-9C91-47C33520B53A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {61571A46-1145-4FF9-9C91-47C33520B53A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {61571A46-1145-4FF9-9C91-47C33520B53A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {61571A46-1145-4FF9-9C91-47C33520B53A}.Release|Any CPU.Build.0 = Release|Any CPU + {0E787394-5AD2-4920-900F-E802EDB726B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0E787394-5AD2-4920-900F-E802EDB726B6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0E787394-5AD2-4920-900F-E802EDB726B6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0E787394-5AD2-4920-900F-E802EDB726B6}.Release|Any CPU.Build.0 = Release|Any CPU + {4A238A51-ED28-4039-8046-ED7B1336C614}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A238A51-ED28-4039-8046-ED7B1336C614}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A238A51-ED28-4039-8046-ED7B1336C614}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A238A51-ED28-4039-8046-ED7B1336C614}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -509,9 +509,6 @@ Global {ED4BC8EC-5C20-4250-B2DD-9FEAEF726D8E} = {5E56C03C-09BD-4F47-917E-4D5B03E4EE0E} {1DEA9C4F-02C5-4D91-A6B4-F87421FDE638} = {ED4BC8EC-5C20-4250-B2DD-9FEAEF726D8E} {0EA98CF7-1E71-4FFE-9825-A9EA22701E6D} = {1DEA9C4F-02C5-4D91-A6B4-F87421FDE638} - {104BEB59-8E92-4517-8141-620073B89887} = {ED4BC8EC-5C20-4250-B2DD-9FEAEF726D8E} - {CDB51D9E-3D69-4E37-A9D4-B12E04722078} = {ED4BC8EC-5C20-4250-B2DD-9FEAEF726D8E} - {17E5D9E6-C482-47C5-BABA-56ACFA13BD43} = {ED4BC8EC-5C20-4250-B2DD-9FEAEF726D8E} {03330B59-67CF-426E-AB61-1F87137E10F4} = {ED4BC8EC-5C20-4250-B2DD-9FEAEF726D8E} {C31C36C8-7661-4782-9915-E8278CD4DFEA} = {5E56C03C-09BD-4F47-917E-4D5B03E4EE0E} {7F858416-5101-4CAE-A7CE-7C7DE65C7465} = {C31C36C8-7661-4782-9915-E8278CD4DFEA} @@ -548,6 +545,9 @@ Global {866DFC4D-9E52-4DC9-B745-E47A2B12822F} = {A1D87C36-B279-40DB-8C75-B74453458A02} {8E6CCEC1-0CD6-464B-A101-24E166715BD7} = {9CB2AEDE-FAB7-405B-913F-3E7E673F962D} {6E524405-2B66-4563-B043-492DB8734060} = {BF4FFF69-2FAA-4C40-A781-ABC5EABEA258} + {61571A46-1145-4FF9-9C91-47C33520B53A} = {ED4BC8EC-5C20-4250-B2DD-9FEAEF726D8E} + {0E787394-5AD2-4920-900F-E802EDB726B6} = {ED4BC8EC-5C20-4250-B2DD-9FEAEF726D8E} + {4A238A51-ED28-4039-8046-ED7B1336C614} = {ED4BC8EC-5C20-4250-B2DD-9FEAEF726D8E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {8C390B97-896A-4AAD-8609-3C20E80966D2} diff --git a/source/Edi.UnitTests/Edi.UnitTests.csproj b/source/Edi.UnitTests/Edi.UnitTests.csproj index 78bd5db121..5d84e9e907 100644 --- a/source/Edi.UnitTests/Edi.UnitTests.csproj +++ b/source/Edi.UnitTests/Edi.UnitTests.csproj @@ -37,6 +37,6 @@ - + diff --git a/source/Edi.UnitTests/EdiTestBase.cs b/source/Edi.UnitTests/EdiTestBase.cs index 60f231ca9c..27d1e55353 100644 --- a/source/Edi.UnitTests/EdiTestBase.cs +++ b/source/Edi.UnitTests/EdiTestBase.cs @@ -13,20 +13,16 @@ // limitations under the License. using BuildingBlocks.Application.Extensions.DependencyInjection; -using Energinet.DataHub.BuildingBlocks.Tests; using Energinet.DataHub.BuildingBlocks.Tests.Logging; using Energinet.DataHub.Core.App.Common.Extensions.DependencyInjection; using Energinet.DataHub.Core.Messaging.Communication.Extensions.Options; using Energinet.DataHub.EDI.DataAccess.Extensions.DependencyInjection; using Energinet.DataHub.EDI.DataAccess.UnitOfWork.Extensions.DependencyInjection; -using Energinet.DataHub.EDI.MasterData.Application.Extensions.DependencyInjection; +using Energinet.DataHub.EDI.MasterData.Infrastructure.Extensions.DependencyInjection; using Energinet.DataHub.Wholesale.Edi.Extensions.DependencyInjection; -using Energinet.DataHub.Wholesale.Edi.Validation; using Energinet.DataHub.Wholesale.Edi.Validation.Helpers; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; -using Microsoft.Extensions.Logging; using Xunit.Abstractions; namespace Energinet.DataHub.Wholesale.Edi.UnitTests; diff --git a/source/IncomingMessages.IntegrationTests/IncomingMessages.IntegrationTests.csproj b/source/IncomingMessages.IntegrationTests/IncomingMessages.IntegrationTests.csproj index dbbede664b..3ebf62fb72 100644 --- a/source/IncomingMessages.IntegrationTests/IncomingMessages.IntegrationTests.csproj +++ b/source/IncomingMessages.IntegrationTests/IncomingMessages.IntegrationTests.csproj @@ -1,4 +1,4 @@ - - + diff --git a/source/ArchivedMessages.Interfaces/IArchivedMessagesClient.cs b/source/ArchivedMessages.Interfaces/IArchivedMessagesClient.cs index 25edc193d7..95d433d8fc 100644 --- a/source/ArchivedMessages.Interfaces/IArchivedMessagesClient.cs +++ b/source/ArchivedMessages.Interfaces/IArchivedMessagesClient.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using Energinet.DataHub.EDI.ArchivedMessages.Interfaces.Models; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models; namespace Energinet.DataHub.EDI.ArchivedMessages.Interfaces; @@ -26,7 +27,7 @@ public interface IArchivedMessagesClient /// /// /// - Task CreateAsync(ArchivedMessage message, CancellationToken cancellationToken); + Task CreateAsync(ArchivedMessageDto message, CancellationToken cancellationToken); /// /// Get a document from the database @@ -34,7 +35,7 @@ public interface IArchivedMessagesClient /// /// /// A representing the result of the asynchronous operation. - Task GetAsync(ArchivedMessageId id, CancellationToken cancellationToken); + Task GetAsync(ArchivedMessageIdDto id, CancellationToken cancellationToken); /// /// Search for messages in the database @@ -42,5 +43,5 @@ public interface IArchivedMessagesClient /// /// /// A representing the result of the asynchronous operation. - Task SearchAsync(GetMessagesQuery queryInput, CancellationToken cancellationToken); + Task SearchAsync(GetMessagesQueryDto queryInput, CancellationToken cancellationToken); } diff --git a/source/ArchivedMessages.Interfaces/Models/ArchivedMessageDto.cs b/source/ArchivedMessages.Interfaces/Models/ArchivedMessageDto.cs new file mode 100644 index 0000000000..05ecfeea68 --- /dev/null +++ b/source/ArchivedMessages.Interfaces/Models/ArchivedMessageDto.cs @@ -0,0 +1,107 @@ +// 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.EDI.BuildingBlocks.Domain.Models; +using NodaTime; + +namespace Energinet.DataHub.EDI.ArchivedMessages.Interfaces.Models; + +public class ArchivedMessageDto +{ + public static readonly FileStorageCategory FileStorageCategory = ArchivedFile.FileStorageCategory; + + public ArchivedMessageDto( + string? messageId, + IReadOnlyList eventIds, + string documentType, + ActorNumber senderNumber, + ActorRole senderRole, + ActorNumber receiverNumber, + ActorRole receiverRole, + Instant createdAt, + string? businessReason, + ArchivedMessageTypeDto archivedMessageType, + IMarketDocumentStream marketDocumentStream, + MessageId? relatedToMessageId = null) + : this(messageId, eventIds, documentType, senderNumber, senderRole, receiverNumber, receiverRole, createdAt, businessReason, archivedMessageType, new ArchivedMessageStreamDto(marketDocumentStream), relatedToMessageId) { } + + public ArchivedMessageDto( + string? messageId, + string documentType, + ActorNumber senderNumber, + ActorRole senderRole, + ActorNumber receiverNumber, + ActorRole receiverRole, + Instant createdAt, + string? businessReason, + ArchivedMessageTypeDto archivedMessageType, + IIncomingMarketMessageStream incomingMarketMessageStream, + MessageId? relatedToMessageId = null) + : this(messageId, Array.Empty(), documentType, senderNumber, senderRole, receiverNumber, receiverRole, createdAt, businessReason, archivedMessageType, new ArchivedMessageStreamDto(incomingMarketMessageStream)) { } + + public ArchivedMessageDto( + string? messageId, + IReadOnlyList eventIds, + string documentType, + ActorNumber senderNumber, + ActorRole senderRole, + ActorNumber receiverNumber, + ActorRole receiverRole, + Instant createdAt, + string? businessReason, + ArchivedMessageTypeDto archivedMessageType, + ArchivedMessageStreamDto archivedMessageStream, + MessageId? relatedToMessageId = null) + { + Id = ArchivedMessageIdDto.Create(); + MessageId = messageId; + EventIds = eventIds; + DocumentType = documentType; + SenderNumber = senderNumber; + SenderRole = senderRole; + ReceiverNumber = receiverNumber; + ReceiverRole = receiverRole; + CreatedAt = createdAt; + BusinessReason = businessReason; + RelatedToMessageId = relatedToMessageId; + ArchivedMessageType = archivedMessageType; + ArchivedMessageStream = archivedMessageStream; + } + + public ArchivedMessageIdDto Id { get; } + + public string? MessageId { get; } + + public IReadOnlyList EventIds { get; } + + public string DocumentType { get; } + + public ActorNumber SenderNumber { get; } + + public ActorRole SenderRole { get; } + + public ActorNumber ReceiverNumber { get; } + + public ActorRole ReceiverRole { get; } + + public Instant CreatedAt { get; } + + public string? BusinessReason { get; } + + public MessageId? RelatedToMessageId { get; private set; } + + public ArchivedMessageTypeDto ArchivedMessageType { get; } + + public ArchivedMessageStreamDto ArchivedMessageStream { get; } +} diff --git a/source/ArchivedMessages.Interfaces/Models/ArchivedMessageIdDto.cs b/source/ArchivedMessages.Interfaces/Models/ArchivedMessageIdDto.cs new file mode 100644 index 0000000000..4fd9d4194d --- /dev/null +++ b/source/ArchivedMessages.Interfaces/Models/ArchivedMessageIdDto.cs @@ -0,0 +1,20 @@ +// 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.EDI.ArchivedMessages.Interfaces.Models; + +public sealed record ArchivedMessageIdDto(Guid Value) +{ + public static ArchivedMessageIdDto Create() => new(Guid.NewGuid()); +} diff --git a/source/ArchivedMessages.Interfaces/Models/ArchivedMessageStreamDto.cs b/source/ArchivedMessages.Interfaces/Models/ArchivedMessageStreamDto.cs new file mode 100644 index 0000000000..0d05c24e2a --- /dev/null +++ b/source/ArchivedMessages.Interfaces/Models/ArchivedMessageStreamDto.cs @@ -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.EDI.BuildingBlocks.Domain.Models; + +namespace Energinet.DataHub.EDI.ArchivedMessages.Interfaces.Models; + +public sealed record ArchivedMessageStreamDto : StreamValueObject, IArchivedMessageStream +{ + public ArchivedMessageStreamDto(FileStorageFile fileStorageFile) + : base(fileStorageFile?.Stream) { } + + public ArchivedMessageStreamDto(IMarketDocumentStream marketDocumentStream) + : base(marketDocumentStream?.Stream) { } + + public ArchivedMessageStreamDto(IIncomingMarketMessageStream incomingMarketMessageStream) + : base(incomingMarketMessageStream?.Stream) { } + + /// + /// This is only intended for testing and mapping purposes + /// + public ArchivedMessageStreamDto(Stream stream) + : base(stream) { } +} diff --git a/source/ArchivedMessages.Interfaces/Models/ArchivedMessageTypeDto.cs b/source/ArchivedMessages.Interfaces/Models/ArchivedMessageTypeDto.cs new file mode 100644 index 0000000000..82542810fb --- /dev/null +++ b/source/ArchivedMessages.Interfaces/Models/ArchivedMessageTypeDto.cs @@ -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.EDI.ArchivedMessages.Interfaces.Models; + +public enum ArchivedMessageTypeDto +{ + IncomingMessage, + OutgoingMessage, +} diff --git a/source/ArchivedMessages.Interfaces/Models/FieldToSortByDto.cs b/source/ArchivedMessages.Interfaces/Models/FieldToSortByDto.cs new file mode 100644 index 0000000000..66a7c967d2 --- /dev/null +++ b/source/ArchivedMessages.Interfaces/Models/FieldToSortByDto.cs @@ -0,0 +1,31 @@ +// 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.EDI.ArchivedMessages.Interfaces.Models; + +public readonly struct FieldToSortByDto +{ + public static readonly FieldToSortByDto MessageId = new("MessageId"); + public static readonly FieldToSortByDto DocumentType = new("DocumentType"); + public static readonly FieldToSortByDto SenderNumber = new("SenderNumber"); + public static readonly FieldToSortByDto ReceiverNumber = new("ReceiverNumber"); + public static readonly FieldToSortByDto CreatedAt = new("CreatedAt"); + + private FieldToSortByDto(string identifier) + { + Identifier = identifier; + } + + public string Identifier { get; } +} diff --git a/source/ArchivedMessages.Interfaces/Models/GetMessagesQueryDto.cs b/source/ArchivedMessages.Interfaces/Models/GetMessagesQueryDto.cs new file mode 100644 index 0000000000..113ae94603 --- /dev/null +++ b/source/ArchivedMessages.Interfaces/Models/GetMessagesQueryDto.cs @@ -0,0 +1,31 @@ +// 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.EDI.ArchivedMessages.Interfaces.Models; + +/// +/// Represents a query options for retrieving messages. +/// Including the pagination for the specific query. +/// +public sealed record GetMessagesQueryDto( + SortedCursorBasedPaginationDto Pagination, + MessageCreationPeriodDto? CreationPeriod = null, + string? MessageId = null, + string? SenderNumber = null, + string? SenderRoleCode = null, + string? ReceiverNumber = null, + string? ReceiverRoleCode = null, + IReadOnlyCollection? DocumentTypes = null, + IReadOnlyCollection? BusinessReasons = null, + bool IncludeRelatedMessages = false); diff --git a/source/ArchivedMessages.Interfaces/Models/MessageCreationPeriodDto.cs b/source/ArchivedMessages.Interfaces/Models/MessageCreationPeriodDto.cs new file mode 100644 index 0000000000..50f336c5c2 --- /dev/null +++ b/source/ArchivedMessages.Interfaces/Models/MessageCreationPeriodDto.cs @@ -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.EDI.ArchivedMessages.Interfaces.Models; + +public sealed record MessageCreationPeriodDto(Instant DateToSearchFrom, Instant DateToSearchTo); diff --git a/source/ArchivedMessages.Interfaces/Models/MessageInfoDto.cs b/source/ArchivedMessages.Interfaces/Models/MessageInfoDto.cs new file mode 100644 index 0000000000..d73bfa50fc --- /dev/null +++ b/source/ArchivedMessages.Interfaces/Models/MessageInfoDto.cs @@ -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. + +using NodaTime; + +namespace Energinet.DataHub.EDI.ArchivedMessages.Interfaces.Models; + +public record MessageInfoDto( + long RecordId, + Guid Id, + string? MessageId, + string DocumentType, + string SenderNumber, + string SenderRoleCode, + string ReceiverNumber, + string ReceiverRoleCode, + Instant CreatedAt, + string? BusinessReason); diff --git a/source/ArchivedMessages.Interfaces/Models/MessageSearchResultDto.cs b/source/ArchivedMessages.Interfaces/Models/MessageSearchResultDto.cs new file mode 100644 index 0000000000..9361bd2031 --- /dev/null +++ b/source/ArchivedMessages.Interfaces/Models/MessageSearchResultDto.cs @@ -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 System.Collections.ObjectModel; + +namespace Energinet.DataHub.EDI.ArchivedMessages.Interfaces.Models; + +public sealed record MessageSearchResultDto(ReadOnlyCollection Messages, int TotalAmountOfMessages); diff --git a/source/ArchivedMessages.Interfaces/Models/SortByDirectionDto.cs b/source/ArchivedMessages.Interfaces/Models/SortByDirectionDto.cs new file mode 100644 index 0000000000..b80fe39830 --- /dev/null +++ b/source/ArchivedMessages.Interfaces/Models/SortByDirectionDto.cs @@ -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.EDI.ArchivedMessages.Interfaces.Models; + +public readonly struct DirectionToSortByDto +{ + public static readonly DirectionToSortByDto Ascending = new("ASC"); + public static readonly DirectionToSortByDto Descending = new("DESC"); + + private DirectionToSortByDto(string identifier) + { + Identifier = identifier; + } + + public string Identifier { get; } +} diff --git a/source/ArchivedMessages.Interfaces/Models/SortedCursorBasedPaginationDto.cs b/source/ArchivedMessages.Interfaces/Models/SortedCursorBasedPaginationDto.cs new file mode 100644 index 0000000000..0f556630b9 --- /dev/null +++ b/source/ArchivedMessages.Interfaces/Models/SortedCursorBasedPaginationDto.cs @@ -0,0 +1,50 @@ +// 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.EDI.ArchivedMessages.Interfaces.Models; + +public sealed record SortedCursorBasedPaginationDto( + SortingCursorDto? Cursor = null, + int PageSize = 100, + bool NavigationForward = true, + FieldToSortByDto? FieldToSortBy = null, + DirectionToSortByDto? DirectionToSortBy = null) +{ + /// + /// The current position in the dataset. + /// + public SortingCursorDto Cursor { get; } = Cursor ?? new SortingCursorDto(); + + /// + /// The number of items per page. + /// + public int PageSize { get; } = PageSize > 0 ? PageSize : throw new ArgumentOutOfRangeException(nameof(PageSize), "Page size must be a positive number."); + + /// + /// A boolean indicating the direction of pagination. + /// + public bool NavigationForward { get; } = NavigationForward; + + /// + /// The field to sort by. + /// + public FieldToSortByDto SortField { get; } = FieldToSortBy ?? FieldToSortByDto.CreatedAt; + + /// + /// The direction to sort by. + /// + public DirectionToSortByDto SortDirection { get; } = DirectionToSortBy ?? DirectionToSortByDto.Descending; +} + +public sealed record SortingCursorDto(string? SortedFieldValue = null, long RecordId = 0); diff --git a/source/B2BApi/B2BApi.csproj b/source/B2BApi/B2BApi.csproj index e90d5f697c..2d6f0eb24c 100644 --- a/source/B2BApi/B2BApi.csproj +++ b/source/B2BApi/B2BApi.csproj @@ -50,7 +50,7 @@ limitations under the License. - + diff --git a/source/B2BApi/HostFactory.cs b/source/B2BApi/HostFactory.cs index 8c37e96a32..4ea6c6125c 100644 --- a/source/B2BApi/HostFactory.cs +++ b/source/B2BApi/HostFactory.cs @@ -17,7 +17,7 @@ using Energinet.DataHub.Core.App.FunctionApp.Extensions.Builder; using Energinet.DataHub.Core.App.FunctionApp.Extensions.DependencyInjection; using Energinet.DataHub.Core.Outbox.Extensions.DependencyInjection; -using Energinet.DataHub.EDI.ArchivedMessages.Application.Extensions.DependencyInjection; +using Energinet.DataHub.EDI.ArchivedMessages.Infrastructure.Extensions.DependencyInjection; using Energinet.DataHub.EDI.AuditLog; using Energinet.DataHub.EDI.B2BApi.Configuration.Middleware; using Energinet.DataHub.EDI.B2BApi.Configuration.Middleware.Authentication; diff --git a/source/B2CWebApi/B2CWebApi.csproj b/source/B2CWebApi/B2CWebApi.csproj index 4db79b396b..0cc450c567 100644 --- a/source/B2CWebApi/B2CWebApi.csproj +++ b/source/B2CWebApi/B2CWebApi.csproj @@ -22,7 +22,7 @@ - + diff --git a/source/B2CWebApi/Controllers/ArchivedMessageGetDocumentController.cs b/source/B2CWebApi/Controllers/ArchivedMessageGetDocumentController.cs index b597db5e36..868f7d9478 100644 --- a/source/B2CWebApi/Controllers/ArchivedMessageGetDocumentController.cs +++ b/source/B2CWebApi/Controllers/ArchivedMessageGetDocumentController.cs @@ -13,7 +13,7 @@ // limitations under the License. using Energinet.DataHub.EDI.ArchivedMessages.Interfaces; -using Energinet.DataHub.EDI.AuditLog; +using Energinet.DataHub.EDI.ArchivedMessages.Interfaces.Models; using Energinet.DataHub.EDI.AuditLog.AuditLogger; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Mvc; @@ -49,7 +49,7 @@ await _auditLogger.LogWithCommitAsync( id.ToString()) .ConfigureAwait(false); - var archivedMessageId = new ArchivedMessageId(id); + var archivedMessageId = new ArchivedMessageIdDto(id); var archivedMessageStream = await _archivedMessagesClient.GetAsync(archivedMessageId, cancellationToken).ConfigureAwait(false); return archivedMessageStream is null ? NoContent() : Ok(archivedMessageStream.Stream); diff --git a/source/B2CWebApi/Controllers/ArchivedMessageSearchController.cs b/source/B2CWebApi/Controllers/ArchivedMessageSearchController.cs index 443b20752b..8b9bfd85c7 100644 --- a/source/B2CWebApi/Controllers/ArchivedMessageSearchController.cs +++ b/source/B2CWebApi/Controllers/ArchivedMessageSearchController.cs @@ -14,10 +14,10 @@ using Asp.Versioning; using Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +using Energinet.DataHub.EDI.ArchivedMessages.Interfaces.Models; using Energinet.DataHub.EDI.AuditLog.AuditLogger; using Energinet.DataHub.EDI.B2CWebApi.Mappers; using Energinet.DataHub.EDI.B2CWebApi.Models; -using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Mvc; using NodaTime.Extensions; @@ -57,21 +57,21 @@ await _auditLogger.LogWithCommitAsync( affectedEntityKey: null) .ConfigureAwait(false); var messageCreationPeriod = request.SearchCriteria.CreatedDuringPeriod is not null - ? new ArchivedMessages.Interfaces.MessageCreationPeriod( + ? new ArchivedMessages.Interfaces.Models.MessageCreationPeriodDto( request.SearchCriteria.CreatedDuringPeriod.Start.ToInstant(), request.SearchCriteria.CreatedDuringPeriod.End.ToInstant()) : null; var cursor = request.Pagination.Cursor != null - ? new SortingCursor(request.Pagination.Cursor.FieldToSortByValue, request.Pagination.Cursor.RecordId) + ? new SortingCursorDto(request.Pagination.Cursor.FieldToSortByValue, request.Pagination.Cursor.RecordId) : null; var pageSize = request.Pagination.PageSize; var navigationForward = request.Pagination.NavigationForward; var fieldToSortBy = FieldToSortByMapper.MapToFieldToSortBy(request.Pagination.SortBy); var directionToSortBy = DirectionToSortByMapper.MapToDirectionToSortBy(request.Pagination.DirectionToSortBy); - var query = new GetMessagesQuery( - new SortedCursorBasedPagination( + var query = new GetMessagesQueryDto( + new SortedCursorBasedPaginationDto( cursor, pageSize, navigationForward, @@ -121,21 +121,21 @@ await _auditLogger.LogWithCommitAsync( .ConfigureAwait(false); var messageCreationPeriod = request.SearchCriteria.CreatedDuringPeriod is not null - ? new ArchivedMessages.Interfaces.MessageCreationPeriod( + ? new ArchivedMessages.Interfaces.Models.MessageCreationPeriodDto( request.SearchCriteria.CreatedDuringPeriod.Start.ToInstant(), request.SearchCriteria.CreatedDuringPeriod.End.ToInstant()) : null; var cursor = request.Pagination.Cursor != null - ? new SortingCursor(request.Pagination.Cursor.FieldToSortByValue, request.Pagination.Cursor.RecordId) + ? new SortingCursorDto(request.Pagination.Cursor.FieldToSortByValue, request.Pagination.Cursor.RecordId) : null; var pageSize = request.Pagination.PageSize; var navigationForward = request.Pagination.NavigationForward; var fieldToSortBy = FieldToSortByMapper.MapToFieldToSortBy(request.Pagination.SortBy); var directionToSortBy = DirectionToSortByMapper.MapToDirectionToSortBy(request.Pagination.DirectionToSortBy); - var query = new GetMessagesQuery( - new SortedCursorBasedPagination( + var query = new GetMessagesQueryDto( + new SortedCursorBasedPaginationDto( cursor, pageSize, navigationForward, diff --git a/source/B2CWebApi/Mappers/DirectionToSortByMapper.cs b/source/B2CWebApi/Mappers/DirectionToSortByMapper.cs index 054faaa36b..db88293420 100644 --- a/source/B2CWebApi/Mappers/DirectionToSortByMapper.cs +++ b/source/B2CWebApi/Mappers/DirectionToSortByMapper.cs @@ -12,19 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -using Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +using Energinet.DataHub.EDI.ArchivedMessages.Interfaces.Models; namespace Energinet.DataHub.EDI.B2CWebApi.Mappers; public static class DirectionToSortByMapper { - public static DirectionToSortBy? MapToDirectionToSortBy( + public static DirectionToSortByDto? MapToDirectionToSortBy( Energinet.DataHub.EDI.B2CWebApi.Models.DirectionToSortBy? directionToSortBy) { return directionToSortBy switch { - Models.DirectionToSortBy.Ascending => DirectionToSortBy.Ascending, - Models.DirectionToSortBy.Descending => DirectionToSortBy.Descending, + Models.DirectionToSortBy.Ascending => DirectionToSortByDto.Ascending, + Models.DirectionToSortBy.Descending => DirectionToSortByDto.Descending, _ => null, }; } diff --git a/source/B2CWebApi/Mappers/FieldToSortByMapper.cs b/source/B2CWebApi/Mappers/FieldToSortByMapper.cs index 7b676c05e4..4c9934af58 100644 --- a/source/B2CWebApi/Mappers/FieldToSortByMapper.cs +++ b/source/B2CWebApi/Mappers/FieldToSortByMapper.cs @@ -12,21 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -using Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +using Energinet.DataHub.EDI.ArchivedMessages.Interfaces.Models; namespace Energinet.DataHub.EDI.B2CWebApi.Mappers; public static class FieldToSortByMapper { - public static FieldToSortBy? MapToFieldToSortBy(Energinet.DataHub.EDI.B2CWebApi.Models.FieldToSortBy? fieldToSortBy) + public static FieldToSortByDto? MapToFieldToSortBy(Energinet.DataHub.EDI.B2CWebApi.Models.FieldToSortBy? fieldToSortBy) { return fieldToSortBy switch { - Models.FieldToSortBy.CreatedAt => FieldToSortBy.CreatedAt, - Models.FieldToSortBy.MessageId => FieldToSortBy.MessageId, - Models.FieldToSortBy.SenderNumber => FieldToSortBy.SenderNumber, - Models.FieldToSortBy.ReceiverNumber => FieldToSortBy.ReceiverNumber, - Models.FieldToSortBy.DocumentType => FieldToSortBy.DocumentType, + Models.FieldToSortBy.CreatedAt => FieldToSortByDto.CreatedAt, + Models.FieldToSortBy.MessageId => FieldToSortByDto.MessageId, + Models.FieldToSortBy.SenderNumber => FieldToSortByDto.SenderNumber, + Models.FieldToSortBy.ReceiverNumber => FieldToSortByDto.ReceiverNumber, + Models.FieldToSortBy.DocumentType => FieldToSortByDto.DocumentType, _ => null, }; } diff --git a/source/B2CWebApi/Program.cs b/source/B2CWebApi/Program.cs index 5fb79ee946..cd22675500 100644 --- a/source/B2CWebApi/Program.cs +++ b/source/B2CWebApi/Program.cs @@ -19,7 +19,7 @@ using Energinet.DataHub.Core.App.WebApp.Extensions.Builder; using Energinet.DataHub.Core.App.WebApp.Extensions.DependencyInjection; using Energinet.DataHub.Core.Outbox.Extensions.DependencyInjection; -using Energinet.DataHub.EDI.ArchivedMessages.Application.Extensions.DependencyInjection; +using Energinet.DataHub.EDI.ArchivedMessages.Infrastructure.Extensions.DependencyInjection; using Energinet.DataHub.EDI.B2CWebApi.Extensions.DependencyInjection; using Energinet.DataHub.EDI.B2CWebApi.Security; using Energinet.DataHub.EDI.DataAccess.UnitOfWork.Extensions.DependencyInjection; diff --git a/source/BuildingBlocks.Domain/BuildingBlocks.Domain.csproj b/source/BuildingBlocks.Domain/BuildingBlocks.Domain.csproj index f230cad237..12ff23a8d6 100644 --- a/source/BuildingBlocks.Domain/BuildingBlocks.Domain.csproj +++ b/source/BuildingBlocks.Domain/BuildingBlocks.Domain.csproj @@ -1,4 +1,4 @@ - + Energinet.DataHub.EDI.BuildingBlocks.Domain Energinet.DataHub.EDI.BuildingBlocks.Domain diff --git a/source/BuildingBlocks.Domain/Validation/EnumCompatibilityChecker.cs b/source/BuildingBlocks.Domain/Validation/EnumCompatibilityChecker.cs new file mode 100644 index 0000000000..8adab24b87 --- /dev/null +++ b/source/BuildingBlocks.Domain/Validation/EnumCompatibilityChecker.cs @@ -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.EDI.BuildingBlocks.Domain.Validation; + +public static class EnumCompatibilityChecker +{ + public static bool AreEnumsCompatible() + where T1 : Enum + where T2 : Enum + { + var firstEnum = Enum.GetValues(typeof(T1)).Cast().ToDictionary(e => e.ToString(), Convert.ToInt32); + var secondEnum = Enum.GetValues(typeof(T2)).Cast().ToDictionary(e => e.ToString(), Convert.ToInt32); + + return firstEnum.All(e => secondEnum.ContainsKey(e.Key) && secondEnum[e.Key] == e.Value); + } +} diff --git a/source/Edi.Repository.sln b/source/Edi.Repository.sln index dedcaae76b..eb4961b20d 100644 --- a/source/Edi.Repository.sln +++ b/source/Edi.Repository.sln @@ -206,6 +206,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MasterData.Application", "M EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MasterData.Domain", "MasterData.Domain\MasterData.Domain.csproj", "{4A238A51-ED28-4039-8046-ED7B1336C614}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchivedMessages.Domain", "ArchivedMessages.Domain\ArchivedMessages.Domain.csproj", "{5DBB75FB-38DC-47ED-987B-255A2D48186C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -452,6 +454,10 @@ Global {4A238A51-ED28-4039-8046-ED7B1336C614}.Debug|Any CPU.Build.0 = Debug|Any CPU {4A238A51-ED28-4039-8046-ED7B1336C614}.Release|Any CPU.ActiveCfg = Release|Any CPU {4A238A51-ED28-4039-8046-ED7B1336C614}.Release|Any CPU.Build.0 = Release|Any CPU + {5DBB75FB-38DC-47ED-987B-255A2D48186C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5DBB75FB-38DC-47ED-987B-255A2D48186C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5DBB75FB-38DC-47ED-987B-255A2D48186C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5DBB75FB-38DC-47ED-987B-255A2D48186C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -548,6 +554,7 @@ Global {61571A46-1145-4FF9-9C91-47C33520B53A} = {ED4BC8EC-5C20-4250-B2DD-9FEAEF726D8E} {0E787394-5AD2-4920-900F-E802EDB726B6} = {ED4BC8EC-5C20-4250-B2DD-9FEAEF726D8E} {4A238A51-ED28-4039-8046-ED7B1336C614} = {ED4BC8EC-5C20-4250-B2DD-9FEAEF726D8E} + {5DBB75FB-38DC-47ED-987B-255A2D48186C} = {0B7C34CA-1AC7-4D94-B44B-5357EFE13F88} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {8C390B97-896A-4AAD-8609-3C20E80966D2} diff --git a/source/IncomingMessages.Application/UseCases/ReceiveIncomingMarketMessage.cs b/source/IncomingMessages.Application/UseCases/ReceiveIncomingMarketMessage.cs index 2417ad8122..b6b3853f93 100644 --- a/source/IncomingMessages.Application/UseCases/ReceiveIncomingMarketMessage.cs +++ b/source/IncomingMessages.Application/UseCases/ReceiveIncomingMarketMessage.cs @@ -13,6 +13,7 @@ // limitations under the License. using Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +using Energinet.DataHub.EDI.ArchivedMessages.Interfaces.Models; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Authentication; using Energinet.DataHub.EDI.BuildingBlocks.Domain.DataHub; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models; @@ -146,7 +147,7 @@ private async Task ArchiveIncomingMessageAsync( { var authenticatedActor = _actorAuthenticator.CurrentActorIdentity; await _archivedMessagesClient.CreateAsync( - new ArchivedMessage( + new ArchivedMessageDto( incomingMessage.MessageId, incomingDocumentType.Name, authenticatedActor.ActorNumber, @@ -157,7 +158,7 @@ await _archivedMessagesClient.CreateAsync( ActorRole.MeteredDataAdministrator, _clock.GetCurrentInstant(), incomingMessage.BusinessReason, - ArchivedMessageType.IncomingMessage, + ArchivedMessageTypeDto.IncomingMessage, incomingMarketMessageStream), cancellationToken).ConfigureAwait(false); } diff --git a/source/IncomingMessages.IntegrationTests/IncomingMessages.IntegrationTests.csproj b/source/IncomingMessages.IntegrationTests/IncomingMessages.IntegrationTests.csproj index 3ebf62fb72..649564f1bf 100644 --- a/source/IncomingMessages.IntegrationTests/IncomingMessages.IntegrationTests.csproj +++ b/source/IncomingMessages.IntegrationTests/IncomingMessages.IntegrationTests.csproj @@ -66,7 +66,7 @@ limitations under the License. - + diff --git a/source/IncomingMessages.IntegrationTests/IncomingMessagesTestBase.cs b/source/IncomingMessages.IntegrationTests/IncomingMessagesTestBase.cs index c77295537f..6f833a3364 100644 --- a/source/IncomingMessages.IntegrationTests/IncomingMessagesTestBase.cs +++ b/source/IncomingMessages.IntegrationTests/IncomingMessagesTestBase.cs @@ -21,7 +21,7 @@ using Energinet.DataHub.BuildingBlocks.Tests.Logging; using Energinet.DataHub.BuildingBlocks.Tests.TestDoubles; using Energinet.DataHub.Core.Messaging.Communication.Extensions.Options; -using Energinet.DataHub.EDI.ArchivedMessages.Application.Extensions.DependencyInjection; +using Energinet.DataHub.EDI.ArchivedMessages.Infrastructure.Extensions.DependencyInjection; using Energinet.DataHub.EDI.B2BApi.Extensions.DependencyInjection; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Authentication; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models; diff --git a/source/IntegrationTests/Application/ArchivedMessages/WhenArchivedMessageIsCreatedTests.cs b/source/IntegrationTests/Application/ArchivedMessages/WhenArchivedMessageIsCreatedTests.cs index f576772fbb..0e60d73f2c 100644 --- a/source/IntegrationTests/Application/ArchivedMessages/WhenArchivedMessageIsCreatedTests.cs +++ b/source/IntegrationTests/Application/ArchivedMessages/WhenArchivedMessageIsCreatedTests.cs @@ -13,7 +13,9 @@ // limitations under the License. using Energinet.DataHub.BuildingBlocks.Tests.TestDoubles; +using Energinet.DataHub.EDI.ArchivedMessages.Application.Mapping; using Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +using Energinet.DataHub.EDI.ArchivedMessages.Interfaces.Models; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models; using Energinet.DataHub.EDI.BuildingBlocks.Infrastructure.FileStorage; using Energinet.DataHub.EDI.IntegrationTests.Fixtures; @@ -74,9 +76,9 @@ public async Task Archived_document_can_be_retrieved_with_correct_content() } [Theory] - [InlineData(ArchivedMessageType.IncomingMessage)] - [InlineData(ArchivedMessageType.OutgoingMessage)] - public async Task Archived_document_is_saved_at_correct_path(ArchivedMessageType archivedMessageType) + [InlineData(ArchivedMessageTypeDto.IncomingMessage)] + [InlineData(ArchivedMessageTypeDto.OutgoingMessage)] + public async Task Archived_document_is_saved_at_correct_path(ArchivedMessageTypeDto archivedMessageType) { var messageId = MessageId.New(); var senderNumber = "1122334455667788"; @@ -92,7 +94,9 @@ public async Task Archived_document_is_saved_at_correct_path(ArchivedMessageType receiverNumber: receiverNumber, timestamp: Instant.FromUtc(year, month, date, 0, 0)); - var expectedActorNumber = archivedMessageType == ArchivedMessageType.IncomingMessage ? senderNumber : receiverNumber; + var mappedArchiveMessage = ArchivedMessageMapper.Map(archivedMessage); + + var expectedActorNumber = archivedMessageType == ArchivedMessageTypeDto.IncomingMessage ? senderNumber : receiverNumber; var expectedFileStorageReference = $"{expectedActorNumber}/{year:000}/{month:00}/{date:00}/{archivedMessage.Id.Value:N}"; await ArchiveMessage(archivedMessage); @@ -100,7 +104,7 @@ public async Task Archived_document_is_saved_at_correct_path(ArchivedMessageType var actualFileStorageReference = await GetArchivedMessageFileStorageReferenceFromDatabaseAsync(messageId.Value); using var assertionScope = new AssertionScope(); - archivedMessage.FileStorageReference.Category.Value.Should().Be("archived"); + mappedArchiveMessage.FileStorageReference.Category.Value.Should().Be("archived"); actualFileStorageReference.Should().Be(expectedFileStorageReference); } @@ -148,15 +152,15 @@ public async Task Adding_archived_message_with_existing_message_id_creates_new_a Assert.Fail("We should be able to save multiple messages with the same message id"); } - var result = await _archivedMessagesClient.SearchAsync(new GetMessagesQuery(new SortedCursorBasedPagination()), CancellationToken.None); + var result = await _archivedMessagesClient.SearchAsync(new GetMessagesQueryDto(new SortedCursorBasedPaginationDto()), CancellationToken.None); Assert.Equal(2, result.Messages.Count); Assert.Equal(messageId, result.Messages[0].MessageId); Assert.Equal(messageId, result.Messages[1].MessageId); } - private static ArchivedMessage CreateArchivedMessage( - ArchivedMessageType? archivedMessageType = null, + private static ArchivedMessageDto CreateArchivedMessage( + ArchivedMessageTypeDto? archivedMessageType = null, string? messageId = null, string? documentContent = null, string? senderNumber = null, @@ -177,7 +181,7 @@ private static ArchivedMessage CreateArchivedMessage( streamWriter.Flush(); } - return new ArchivedMessage( + return new ArchivedMessageDto( string.IsNullOrWhiteSpace(messageId) ? Guid.NewGuid().ToString() : messageId, new[] { EventId.From(Guid.NewGuid()) }, DocumentType.NotifyAggregatedMeasureData.Name, @@ -187,11 +191,11 @@ private static ArchivedMessage CreateArchivedMessage( ActorRole.EnergySupplier, timestamp ?? Instant.FromUtc(2023, 01, 01, 0, 0), BusinessReason.BalanceFixing.Name, - archivedMessageType ?? ArchivedMessageType.OutgoingMessage, + archivedMessageType ?? ArchivedMessageTypeDto.OutgoingMessage, new MarketDocumentStream(documentStream)); } - private async Task ArchiveMessage(ArchivedMessage archivedMessage) + private async Task ArchiveMessage(ArchivedMessageDto archivedMessage) { await _archivedMessagesClient.CreateAsync(archivedMessage, CancellationToken.None); } diff --git a/source/IntegrationTests/Behaviours/BehavioursTestBase.cs b/source/IntegrationTests/Behaviours/BehavioursTestBase.cs index 1866fb2e99..b0f7601460 100644 --- a/source/IntegrationTests/Behaviours/BehavioursTestBase.cs +++ b/source/IntegrationTests/Behaviours/BehavioursTestBase.cs @@ -22,7 +22,7 @@ using Energinet.DataHub.Core.Messaging.Communication; using Energinet.DataHub.Core.Messaging.Communication.Extensions.Options; using Energinet.DataHub.Core.Messaging.Communication.Subscriber; -using Energinet.DataHub.EDI.ArchivedMessages.Application.Extensions.DependencyInjection; +using Energinet.DataHub.EDI.ArchivedMessages.Infrastructure.Extensions.DependencyInjection; using Energinet.DataHub.EDI.B2BApi.DataRetention; using Energinet.DataHub.EDI.B2BApi.Extensions.DependencyInjection; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Authentication; diff --git a/source/IntegrationTests/Infrastructure/InboxEvents/TestAggregatedTimeSeriesRequestAcceptedHandlerSpy.cs b/source/IntegrationTests/Infrastructure/InboxEvents/TestAggregatedTimeSeriesRequestAcceptedHandlerSpy.cs index b973f16411..64d8483ac4 100644 --- a/source/IntegrationTests/Infrastructure/InboxEvents/TestAggregatedTimeSeriesRequestAcceptedHandlerSpy.cs +++ b/source/IntegrationTests/Infrastructure/InboxEvents/TestAggregatedTimeSeriesRequestAcceptedHandlerSpy.cs @@ -12,11 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models; using Energinet.DataHub.EDI.Process.Application.Transactions.AggregatedMeasureData.Notifications; using Energinet.DataHub.EDI.Process.Domain.Transactions.AggregatedMeasureData; diff --git a/source/IntegrationTests/TestBase.cs b/source/IntegrationTests/TestBase.cs index 734801d334..79b6d7ec5a 100644 --- a/source/IntegrationTests/TestBase.cs +++ b/source/IntegrationTests/TestBase.cs @@ -23,7 +23,7 @@ using Energinet.DataHub.Core.Databricks.SqlStatementExecution; using Energinet.DataHub.Core.Messaging.Communication.Extensions.Options; using Energinet.DataHub.Core.Outbox.Extensions.DependencyInjection; -using Energinet.DataHub.EDI.ArchivedMessages.Application.Extensions.DependencyInjection; +using Energinet.DataHub.EDI.ArchivedMessages.Infrastructure.Extensions.DependencyInjection; using Energinet.DataHub.EDI.B2BApi.DataRetention; using Energinet.DataHub.EDI.B2BApi.Extensions.DependencyInjection; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Authentication; diff --git a/source/OutgoingMessages.Application/UseCases/PeekMessage.cs b/source/OutgoingMessages.Application/UseCases/PeekMessage.cs index 994236716d..9266c315a9 100644 --- a/source/OutgoingMessages.Application/UseCases/PeekMessage.cs +++ b/source/OutgoingMessages.Application/UseCases/PeekMessage.cs @@ -13,6 +13,7 @@ // limitations under the License. using Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +using Energinet.DataHub.EDI.ArchivedMessages.Interfaces.Models; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Authentication; using Energinet.DataHub.EDI.BuildingBlocks.Domain.DataHub; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models; @@ -118,7 +119,7 @@ private async Task GenerateMarketDocumentAsync( var marketDocumentStream = await _documentFactory.CreateFromAsync(outgoingMessageBundle, request.DocumentFormat, timestamp, cancellationToken).ConfigureAwait(false); var authenticatedActor = _actorAuthenticator.CurrentActorIdentity; - var archivedMessageToCreate = new ArchivedMessage( + var archivedMessageToCreate = new ArchivedMessageDto( outgoingMessageBundle.MessageId.Value, outgoingMessageBundle.OutgoingMessages.Select(om => om.EventId).ToArray(), outgoingMessageBundle.DocumentType.ToString(), @@ -129,7 +130,7 @@ private async Task GenerateMarketDocumentAsync( authenticatedActor.ActorRole, timestamp, outgoingMessageBundle.BusinessReason, - ArchivedMessageType.OutgoingMessage, + ArchivedMessageTypeDto.OutgoingMessage, marketDocumentStream, outgoingMessageBundle.RelatedToMessageId); diff --git a/source/OutgoingMessages.IntegrationTests/OutgoingMessages.IntegrationTests.csproj b/source/OutgoingMessages.IntegrationTests/OutgoingMessages.IntegrationTests.csproj index 083cb4af12..be6dd187ea 100644 --- a/source/OutgoingMessages.IntegrationTests/OutgoingMessages.IntegrationTests.csproj +++ b/source/OutgoingMessages.IntegrationTests/OutgoingMessages.IntegrationTests.csproj @@ -33,7 +33,7 @@ - + diff --git a/source/OutgoingMessages.IntegrationTests/OutgoingMessagesTestBase.cs b/source/OutgoingMessages.IntegrationTests/OutgoingMessagesTestBase.cs index 73eedbbde6..100f41211f 100644 --- a/source/OutgoingMessages.IntegrationTests/OutgoingMessagesTestBase.cs +++ b/source/OutgoingMessages.IntegrationTests/OutgoingMessagesTestBase.cs @@ -20,7 +20,7 @@ using Energinet.DataHub.BuildingBlocks.Tests.Logging; using Energinet.DataHub.BuildingBlocks.Tests.TestDoubles; using Energinet.DataHub.Core.Messaging.Communication.Extensions.Options; -using Energinet.DataHub.EDI.ArchivedMessages.Application.Extensions.DependencyInjection; +using Energinet.DataHub.EDI.ArchivedMessages.Infrastructure.Extensions.DependencyInjection; using Energinet.DataHub.EDI.B2BApi.Extensions.DependencyInjection; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Authentication; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models;