diff --git a/source/ArchivedMessages.Application/ArchivedMessages.Application.csproj b/source/ArchivedMessages.Application/ArchivedMessages.Application.csproj index 6dce3e198f..235c70fde8 100644 --- a/source/ArchivedMessages.Application/ArchivedMessages.Application.csproj +++ b/source/ArchivedMessages.Application/ArchivedMessages.Application.csproj @@ -1,21 +1,17 @@ - + Energinet.DataHub.EDI.ArchivedMessages.Application Energinet.DataHub.EDI.ArchivedMessages.Application - - all runtime; build; native; contentfiles; analyzers; buildtransitive - + - - diff --git a/source/ArchivedMessages.Application/ArchivedMessagesClient.cs b/source/ArchivedMessages.Application/ArchivedMessagesClient.cs index 10299a95b1..bb228b0ca6 100644 --- a/source/ArchivedMessages.Application/ArchivedMessagesClient.cs +++ b/source/ArchivedMessages.Application/ArchivedMessagesClient.cs @@ -12,38 +12,46 @@ // See the License for the specific language governing permissions and // limitations under the License. -using Energinet.DataHub.EDI.ArchivedMessages.Infrastructure; +using Energinet.DataHub.EDI.ArchivedMessages.Application.Mapping; +using Energinet.DataHub.EDI.ArchivedMessages.Domain.Models; using Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +using Energinet.DataHub.EDI.ArchivedMessages.Interfaces.Models; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models; namespace Energinet.DataHub.EDI.ArchivedMessages.Application; -public class ArchivedMessagesClient : IArchivedMessagesClient +public class ArchivedMessagesClient(IArchivedMessageRepository archivedMessageRepository) : IArchivedMessagesClient { - private readonly IArchivedMessageRepository _archivedMessageRepository; + private readonly IArchivedMessageRepository _archivedMessageRepository = archivedMessageRepository; - public ArchivedMessagesClient(IArchivedMessageRepository archivedMessageRepository) - { - _archivedMessageRepository = archivedMessageRepository; - } - - public async Task CreateAsync(ArchivedMessage message, CancellationToken cancellationToken) + public async Task CreateAsync(ArchivedMessageDto message, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(message); - await _archivedMessageRepository.AddAsync(message, cancellationToken).ConfigureAwait(false); - return new ArchivedFile(message.FileStorageReference, message.ArchivedMessageStream); + var mappedArchivedMessage = ArchivedMessageMapper.Map(message); + + await _archivedMessageRepository.AddAsync(mappedArchivedMessage, cancellationToken).ConfigureAwait(false); + + return new ArchivedFile(mappedArchivedMessage.FileStorageReference, mappedArchivedMessage.ArchivedMessageStream); } - public async Task GetAsync(ArchivedMessageId id, CancellationToken cancellationToken) + public async Task GetAsync(ArchivedMessageIdDto id, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(id); - return await _archivedMessageRepository.GetAsync(id, cancellationToken).ConfigureAwait(false); + + var archivedMessageId = new ArchivedMessageId(id.Value); + + var result = await _archivedMessageRepository.GetAsync(archivedMessageId, cancellationToken).ConfigureAwait(false); + + return result != null ? new ArchivedMessageStreamDto(result.Stream) : null; } - public Task SearchAsync(GetMessagesQuery queryInput, CancellationToken cancellationToken) + public async Task SearchAsync(GetMessagesQueryDto queryInputDto, CancellationToken cancellationToken) { - ArgumentNullException.ThrowIfNull(queryInput); - return _archivedMessageRepository.SearchAsync(queryInput, cancellationToken); + ArgumentNullException.ThrowIfNull(queryInputDto); + + var result = await _archivedMessageRepository.SearchAsync(GetMessagesQueryMapper.Map(queryInputDto), cancellationToken).ConfigureAwait(false); + + return MessagesSearchResultMapper.Map(result); } } diff --git a/source/ArchivedMessages.Application/Mapping/ArchivedMessageMapper.cs b/source/ArchivedMessages.Application/Mapping/ArchivedMessageMapper.cs new file mode 100644 index 0000000000..cbbbc3d010 --- /dev/null +++ b/source/ArchivedMessages.Application/Mapping/ArchivedMessageMapper.cs @@ -0,0 +1,43 @@ +// 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.ArchivedMessages.Domain.Exceptions; +using Energinet.DataHub.EDI.ArchivedMessages.Domain.Models; +using Energinet.DataHub.EDI.ArchivedMessages.Interfaces.Models; +using Energinet.DataHub.EDI.BuildingBlocks.Domain.Validation; + +namespace Energinet.DataHub.EDI.ArchivedMessages.Application.Mapping; + +public static class ArchivedMessageMapper +{ + public static ArchivedMessage Map(ArchivedMessageDto dto) + { + return !EnumCompatibilityChecker.AreEnumsCompatible() + ? throw new InvalidEnumMappingException($"Enum of type {nameof(ArchivedMessageType)} cannot be mapped to type {nameof(ArchivedMessageTypeDto)}.") + : new ArchivedMessage( + id: new ArchivedMessageId(dto.Id.Value), + messageId: dto.MessageId, + eventIds: dto.EventIds, + documentType: dto.DocumentType, + senderNumber: dto.SenderNumber, + senderRole: dto.SenderRole, + receiverNumber: dto.ReceiverNumber, + receiverRole: dto.ReceiverRole, + createdAt: dto.CreatedAt, + businessReason: dto.BusinessReason, + archivedMessageType: (ArchivedMessageType)dto.ArchivedMessageType, + archivedMessageStream: new ArchivedMessageStream(dto.ArchivedMessageStream.Stream), + relatedToMessageId: dto.RelatedToMessageId); + } +} diff --git a/source/ArchivedMessages.Application/Mapping/GetMessagesQueryMapper.cs b/source/ArchivedMessages.Application/Mapping/GetMessagesQueryMapper.cs new file mode 100644 index 0000000000..c260fbd04c --- /dev/null +++ b/source/ArchivedMessages.Application/Mapping/GetMessagesQueryMapper.cs @@ -0,0 +1,74 @@ +// 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.ArchivedMessages.Domain.Models; +using Energinet.DataHub.EDI.ArchivedMessages.Interfaces.Models; + +namespace Energinet.DataHub.EDI.ArchivedMessages.Application.Mapping; + +internal static class GetMessagesQueryMapper +{ + internal static GetMessagesQuery Map(GetMessagesQueryDto dto) + { + return new GetMessagesQuery( + Pagination: SetSortedCursorBasedPagination(dto.Pagination), + CreationPeriod: SetMessageCreationPeriod(dto.CreationPeriod), + MessageId: dto.MessageId, + SenderNumber: dto.SenderNumber, + SenderRoleCode: dto.SenderRoleCode, + ReceiverNumber: dto.ReceiverNumber, + ReceiverRoleCode: dto.ReceiverRoleCode, + DocumentTypes: dto.DocumentTypes, + BusinessReasons: dto.BusinessReasons, + IncludeRelatedMessages: dto.IncludeRelatedMessages); + } + + private static SortedCursorBasedPagination SetSortedCursorBasedPagination(SortedCursorBasedPaginationDto dto) + { + return new SortedCursorBasedPagination( + cursor: SetSortingCursor(dto.Cursor), + pageSize: dto.PageSize, + navigationForward: dto.NavigationForward, + fieldToSortBy: SetFieldToSortBy(dto.FieldToSortBy), + directionToSortBy: SetDirectionToSortBy(dto.DirectionToSortBy)); + } + + private static MessageCreationPeriod? SetMessageCreationPeriod(MessageCreationPeriodDto? messageCreationPeriod) + { + return messageCreationPeriod is not null + ? new MessageCreationPeriod(messageCreationPeriod.DateToSearchFrom, messageCreationPeriod.DateToSearchTo) + : null; + } + + private static SortingCursor? SetSortingCursor(SortingCursorDto? sortingCursor) + { + return sortingCursor is not null + ? new SortingCursor(sortingCursor.SortedFieldValue, sortingCursor.RecordId) + : null; + } + + private static FieldToSortBy? SetFieldToSortBy(FieldToSortByDto? fieldToSortBy) + { + return fieldToSortBy is not null + ? new FieldToSortBy(fieldToSortBy.Value.Identifier) + : null; + } + + private static DirectionToSortBy? SetDirectionToSortBy(DirectionToSortByDto? directionToSortBy) + { + return directionToSortBy is not null + ? new DirectionToSortBy(directionToSortBy.Value.Identifier) + : null; + } +} diff --git a/source/ArchivedMessages.Application/Mapping/MessagesSearchResultMapper.cs b/source/ArchivedMessages.Application/Mapping/MessagesSearchResultMapper.cs new file mode 100644 index 0000000000..01202ed6f6 --- /dev/null +++ b/source/ArchivedMessages.Application/Mapping/MessagesSearchResultMapper.cs @@ -0,0 +1,44 @@ +// 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; +using Energinet.DataHub.EDI.ArchivedMessages.Domain.Models; +using Energinet.DataHub.EDI.ArchivedMessages.Interfaces.Models; + +namespace Energinet.DataHub.EDI.ArchivedMessages.Application.Mapping; + +internal static class MessagesSearchResultMapper +{ + internal static MessageSearchResultDto Map(MessageSearchResult messageSearchResult) + { + return new MessageSearchResultDto(SetMessageInfoCollection(messageSearchResult.Messages), messageSearchResult.TotalAmountOfMessages); + } + + private static ReadOnlyCollection SetMessageInfoCollection(IReadOnlyCollection collection) + { + return collection.Select(mi => new MessageInfoDto( + RecordId: mi.RecordId, + Id: mi.Id, + MessageId: mi.MessageId, + DocumentType: mi.DocumentType, + SenderNumber: mi.SenderNumber, + SenderRoleCode: mi.SenderRoleCode, + ReceiverNumber: mi.ReceiverNumber, + ReceiverRoleCode: mi.ReceiverRoleCode, + CreatedAt: mi.CreatedAt, + BusinessReason: mi.BusinessReason)) + .ToList() + .AsReadOnly(); + } +} diff --git a/source/ArchivedMessages.Domain/ArchivedMessages.Domain.csproj b/source/ArchivedMessages.Domain/ArchivedMessages.Domain.csproj new file mode 100644 index 0000000000..e056c42ed9 --- /dev/null +++ b/source/ArchivedMessages.Domain/ArchivedMessages.Domain.csproj @@ -0,0 +1,15 @@ + + + Energinet.DataHub.EDI.ArchivedMessages.Domain + Energinet.DataHub.EDI.ArchivedMessages.Domain + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + diff --git a/source/ArchivedMessages.Domain/Exceptions/InvalidEnumMappingException.cs b/source/ArchivedMessages.Domain/Exceptions/InvalidEnumMappingException.cs new file mode 100644 index 0000000000..840e5ca608 --- /dev/null +++ b/source/ArchivedMessages.Domain/Exceptions/InvalidEnumMappingException.cs @@ -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. + +namespace Energinet.DataHub.EDI.ArchivedMessages.Domain.Exceptions; + +public class InvalidEnumMappingException : Exception +{ + public InvalidEnumMappingException() + { + } + + public InvalidEnumMappingException(string message) + : base(message) + { + } + + public InvalidEnumMappingException(string message, Exception innerException) + : base(message, innerException) + { + } +} diff --git a/source/ArchivedMessages.Infrastructure/IArchivedMessageRepository.cs b/source/ArchivedMessages.Domain/IArchivedMessageRepository.cs similarity index 93% rename from source/ArchivedMessages.Infrastructure/IArchivedMessageRepository.cs rename to source/ArchivedMessages.Domain/IArchivedMessageRepository.cs index b6dc562c9a..a112be5bfd 100644 --- a/source/ArchivedMessages.Infrastructure/IArchivedMessageRepository.cs +++ b/source/ArchivedMessages.Domain/IArchivedMessageRepository.cs @@ -12,9 +12,9 @@ // 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.Domain.Models; -namespace Energinet.DataHub.EDI.ArchivedMessages.Infrastructure; +namespace Energinet.DataHub.EDI.ArchivedMessages.Interfaces; /// /// Responsible for archiving messages. diff --git a/source/ArchivedMessages.Interfaces/ArchivedMessage.cs b/source/ArchivedMessages.Domain/Models/ArchivedMessage.cs similarity index 66% rename from source/ArchivedMessages.Interfaces/ArchivedMessage.cs rename to source/ArchivedMessages.Domain/Models/ArchivedMessage.cs index 8cb2c8d558..e5030f3c5a 100644 --- a/source/ArchivedMessages.Interfaces/ArchivedMessage.cs +++ b/source/ArchivedMessages.Domain/Models/ArchivedMessage.cs @@ -15,47 +15,14 @@ using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models; using NodaTime; -namespace Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +namespace Energinet.DataHub.EDI.ArchivedMessages.Domain.Models; public class ArchivedMessage { public static readonly FileStorageCategory FileStorageCategory = ArchivedFile.FileStorageCategory; - /// - /// Created an ArchivedMessage from a market document (typically from a outgoing message) - /// public ArchivedMessage( - string? messageId, - IReadOnlyList eventIds, - string documentType, - ActorNumber senderNumber, - ActorRole senderRole, - ActorNumber receiverNumber, - ActorRole receiverRole, - Instant createdAt, - string? businessReason, - ArchivedMessageType archivedMessageType, - IMarketDocumentStream marketDocumentStream, - MessageId? relatedToMessageId = null) - : this(messageId, eventIds, documentType, senderNumber, senderRole, receiverNumber, receiverRole, createdAt, businessReason, archivedMessageType, new ArchivedMessageStream(marketDocumentStream), relatedToMessageId) { } - - /// - /// Creates an ArchivedMessage for an incoming message - /// - public ArchivedMessage( - string? messageId, - string documentType, - ActorNumber senderNumber, - ActorRole senderRole, - ActorNumber receiverNumber, - ActorRole receiverRole, - Instant createdAt, - string? businessReason, - ArchivedMessageType archivedMessageType, - IIncomingMarketMessageStream incomingMarketMessageStream) - : this(messageId, Array.Empty(), documentType, senderNumber, senderRole, receiverNumber, receiverRole, createdAt, businessReason, archivedMessageType, new ArchivedMessageStream(incomingMarketMessageStream)) { } - - internal ArchivedMessage( + ArchivedMessageId id, string? messageId, IReadOnlyList eventIds, string documentType, @@ -69,7 +36,7 @@ internal ArchivedMessage( ArchivedMessageStream archivedMessageStream, MessageId? relatedToMessageId = null) { - Id = ArchivedMessageId.Create(); + Id = id; MessageId = messageId; EventIds = eventIds; DocumentType = documentType; diff --git a/source/ArchivedMessages.Interfaces/ArchivedMessageId.cs b/source/ArchivedMessages.Domain/Models/ArchivedMessageId.cs similarity index 91% rename from source/ArchivedMessages.Interfaces/ArchivedMessageId.cs rename to source/ArchivedMessages.Domain/Models/ArchivedMessageId.cs index 46cbdb69c3..db1b298920 100644 --- a/source/ArchivedMessages.Interfaces/ArchivedMessageId.cs +++ b/source/ArchivedMessages.Domain/Models/ArchivedMessageId.cs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +namespace Energinet.DataHub.EDI.ArchivedMessages.Domain.Models; public record ArchivedMessageId(Guid Value) { diff --git a/source/ArchivedMessages.Interfaces/ArchivedMessageStream.cs b/source/ArchivedMessages.Domain/Models/ArchivedMessageStream.cs similarity index 69% rename from source/ArchivedMessages.Interfaces/ArchivedMessageStream.cs rename to source/ArchivedMessages.Domain/Models/ArchivedMessageStream.cs index 64500b491e..3a77b79639 100644 --- a/source/ArchivedMessages.Interfaces/ArchivedMessageStream.cs +++ b/source/ArchivedMessages.Domain/Models/ArchivedMessageStream.cs @@ -14,7 +14,7 @@ using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models; -namespace Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +namespace Energinet.DataHub.EDI.ArchivedMessages.Domain.Models; #pragma warning disable CA1711 // Is a "Stream" value type public sealed record ArchivedMessageStream : StreamValueObject, IArchivedMessageStream @@ -22,15 +22,9 @@ public sealed record ArchivedMessageStream : StreamValueObject, IArchivedMessage public ArchivedMessageStream(FileStorageFile fileStorageFile) : base(fileStorageFile?.Stream) { } - public ArchivedMessageStream(IMarketDocumentStream marketDocumentStream) - : base(marketDocumentStream?.Stream) { } - - public ArchivedMessageStream(IIncomingMarketMessageStream incomingMarketMessageStream) - : base(incomingMarketMessageStream?.Stream) { } - /// - /// This is only intended for testing purposes + /// This is only intended for testing and mapping purposes /// - internal ArchivedMessageStream(Stream stream) + public ArchivedMessageStream(Stream stream) : base(stream) { } } diff --git a/source/ArchivedMessages.Interfaces/ArchivedMessageType.cs b/source/ArchivedMessages.Domain/Models/ArchivedMessageType.cs similarity index 91% rename from source/ArchivedMessages.Interfaces/ArchivedMessageType.cs rename to source/ArchivedMessages.Domain/Models/ArchivedMessageType.cs index d912bde7b5..51b4266af2 100644 --- a/source/ArchivedMessages.Interfaces/ArchivedMessageType.cs +++ b/source/ArchivedMessages.Domain/Models/ArchivedMessageType.cs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +namespace Energinet.DataHub.EDI.ArchivedMessages.Domain.Models; public enum ArchivedMessageType { diff --git a/source/ArchivedMessages.Interfaces/SortByDirection.cs b/source/ArchivedMessages.Domain/Models/DirectionToSortBy.cs similarity index 88% rename from source/ArchivedMessages.Interfaces/SortByDirection.cs rename to source/ArchivedMessages.Domain/Models/DirectionToSortBy.cs index 743ce135e0..28d319ea36 100644 --- a/source/ArchivedMessages.Interfaces/SortByDirection.cs +++ b/source/ArchivedMessages.Domain/Models/DirectionToSortBy.cs @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +namespace Energinet.DataHub.EDI.ArchivedMessages.Domain.Models; public readonly struct DirectionToSortBy { public static readonly DirectionToSortBy Ascending = new("ASC"); public static readonly DirectionToSortBy Descending = new("DESC"); - private DirectionToSortBy(string identifier) + public DirectionToSortBy(string identifier) { Identifier = identifier; } diff --git a/source/ArchivedMessages.Interfaces/FieldToSortBy.cs b/source/ArchivedMessages.Domain/Models/FieldToSortBy.cs similarity index 91% rename from source/ArchivedMessages.Interfaces/FieldToSortBy.cs rename to source/ArchivedMessages.Domain/Models/FieldToSortBy.cs index dd11a531b3..ed7eddfd4a 100644 --- a/source/ArchivedMessages.Interfaces/FieldToSortBy.cs +++ b/source/ArchivedMessages.Domain/Models/FieldToSortBy.cs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +namespace Energinet.DataHub.EDI.ArchivedMessages.Domain.Models; public readonly struct FieldToSortBy { @@ -22,7 +22,7 @@ public readonly struct FieldToSortBy public static readonly FieldToSortBy ReceiverNumber = new("ReceiverNumber"); public static readonly FieldToSortBy CreatedAt = new("CreatedAt"); - private FieldToSortBy(string identifier) + public FieldToSortBy(string identifier) { Identifier = identifier; } diff --git a/source/ArchivedMessages.Interfaces/GetMessagesQuery.cs b/source/ArchivedMessages.Domain/Models/GetMessagesQuery.cs similarity index 94% rename from source/ArchivedMessages.Interfaces/GetMessagesQuery.cs rename to source/ArchivedMessages.Domain/Models/GetMessagesQuery.cs index 9f2b7243ac..4bc9224a67 100644 --- a/source/ArchivedMessages.Interfaces/GetMessagesQuery.cs +++ b/source/ArchivedMessages.Domain/Models/GetMessagesQuery.cs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +namespace Energinet.DataHub.EDI.ArchivedMessages.Domain.Models; /// /// Represents a query options for retrieving messages. diff --git a/source/ArchivedMessages.Interfaces/MessageCreationPeriod.cs b/source/ArchivedMessages.Domain/Models/MessageCreationPeriod.cs similarity index 91% rename from source/ArchivedMessages.Interfaces/MessageCreationPeriod.cs rename to source/ArchivedMessages.Domain/Models/MessageCreationPeriod.cs index 40c5a8e02f..c0ac56d716 100644 --- a/source/ArchivedMessages.Interfaces/MessageCreationPeriod.cs +++ b/source/ArchivedMessages.Domain/Models/MessageCreationPeriod.cs @@ -14,6 +14,6 @@ using NodaTime; -namespace Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +namespace Energinet.DataHub.EDI.ArchivedMessages.Domain.Models; public record MessageCreationPeriod(Instant DateToSearchFrom, Instant DateToSearchTo); diff --git a/source/ArchivedMessages.Interfaces/MessageInfo.cs b/source/ArchivedMessages.Domain/Models/MessageInfo.cs similarity index 93% rename from source/ArchivedMessages.Interfaces/MessageInfo.cs rename to source/ArchivedMessages.Domain/Models/MessageInfo.cs index 9975c64648..46ca718506 100644 --- a/source/ArchivedMessages.Interfaces/MessageInfo.cs +++ b/source/ArchivedMessages.Domain/Models/MessageInfo.cs @@ -14,7 +14,7 @@ using NodaTime; -namespace Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +namespace Energinet.DataHub.EDI.ArchivedMessages.Domain.Models; public record MessageInfo( long RecordId, diff --git a/source/ArchivedMessages.Interfaces/MessageSearchResult.cs b/source/ArchivedMessages.Domain/Models/MessageSearchResult.cs similarity index 92% rename from source/ArchivedMessages.Interfaces/MessageSearchResult.cs rename to source/ArchivedMessages.Domain/Models/MessageSearchResult.cs index 203edfc43f..1663f6140f 100644 --- a/source/ArchivedMessages.Interfaces/MessageSearchResult.cs +++ b/source/ArchivedMessages.Domain/Models/MessageSearchResult.cs @@ -14,6 +14,6 @@ using System.Collections.ObjectModel; -namespace Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +namespace Energinet.DataHub.EDI.ArchivedMessages.Domain.Models; public record MessageSearchResult(ReadOnlyCollection Messages, int TotalAmountOfMessages); diff --git a/source/ArchivedMessages.Interfaces/SortedCursorBasedPagination.cs b/source/ArchivedMessages.Domain/Models/SortedCursorBasedPagination.cs similarity index 90% rename from source/ArchivedMessages.Interfaces/SortedCursorBasedPagination.cs rename to source/ArchivedMessages.Domain/Models/SortedCursorBasedPagination.cs index 006953b6e8..71a84d5211 100644 --- a/source/ArchivedMessages.Interfaces/SortedCursorBasedPagination.cs +++ b/source/ArchivedMessages.Domain/Models/SortedCursorBasedPagination.cs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -namespace Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +namespace Energinet.DataHub.EDI.ArchivedMessages.Domain.Models; /// /// The SortedCursorBasedPagination is navigating forward or backwards through a dataset @@ -23,7 +23,7 @@ public class SortedCursorBasedPagination( int pageSize = 100, bool navigationForward = true, FieldToSortBy? fieldToSortBy = null, - DirectionToSortBy? directionSortBy = null) + DirectionToSortBy? directionToSortBy = null) { /// /// The current position in the dataset. @@ -43,12 +43,12 @@ public class SortedCursorBasedPagination( /// /// The field to sort by. /// - public FieldToSortBy SortBy { get; } = fieldToSortBy ?? FieldToSortBy.CreatedAt; + public FieldToSortBy FieldToSortBy { get; } = fieldToSortBy ?? FieldToSortBy.CreatedAt; /// /// The direction to sort by. /// - public DirectionToSortBy DirectionToSortBy { get; } = directionSortBy ?? DirectionToSortBy.Descending; + public DirectionToSortBy DirectionToSortBy { get; } = directionToSortBy ?? DirectionToSortBy.Descending; } /// diff --git a/source/ArchivedMessages.Infrastructure/ArchivedMessageRepository.cs b/source/ArchivedMessages.Infrastructure/ArchivedMessageRepository.cs index 94559cc85a..6915d38672 100644 --- a/source/ArchivedMessages.Infrastructure/ArchivedMessageRepository.cs +++ b/source/ArchivedMessages.Infrastructure/ArchivedMessageRepository.cs @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -using System.Text.RegularExpressions; using Dapper; +using Energinet.DataHub.EDI.ArchivedMessages.Domain.Models; using Energinet.DataHub.EDI.ArchivedMessages.Interfaces; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Authentication; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models; diff --git a/source/ArchivedMessages.Infrastructure/ArchivedMessages.Infrastructure.csproj b/source/ArchivedMessages.Infrastructure/ArchivedMessages.Infrastructure.csproj index 288a52ad11..d483cb6030 100644 --- a/source/ArchivedMessages.Infrastructure/ArchivedMessages.Infrastructure.csproj +++ b/source/ArchivedMessages.Infrastructure/ArchivedMessages.Infrastructure.csproj @@ -1,4 +1,4 @@ - + Energinet.DataHub.EDI.ArchivedMessages.Infrastructure @@ -15,9 +15,13 @@ + + + + diff --git a/source/ArchivedMessages.Application/Extensions/DependencyInjection/ArchivedMessageExtensions.cs b/source/ArchivedMessages.Infrastructure/Extensions/DependencyInjection/ArchivedMessageExtensions.cs similarity index 90% rename from source/ArchivedMessages.Application/Extensions/DependencyInjection/ArchivedMessageExtensions.cs rename to source/ArchivedMessages.Infrastructure/Extensions/DependencyInjection/ArchivedMessageExtensions.cs index 400c5b662e..abd96742f2 100644 --- a/source/ArchivedMessages.Application/Extensions/DependencyInjection/ArchivedMessageExtensions.cs +++ b/source/ArchivedMessages.Infrastructure/Extensions/DependencyInjection/ArchivedMessageExtensions.cs @@ -13,13 +13,13 @@ // limitations under the License. using BuildingBlocks.Application.Extensions.DependencyInjection; -using Energinet.DataHub.EDI.ArchivedMessages.Infrastructure; +using Energinet.DataHub.EDI.ArchivedMessages.Application; using Energinet.DataHub.EDI.ArchivedMessages.Interfaces; using Energinet.DataHub.EDI.DataAccess.Extensions.DependencyInjection; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -namespace Energinet.DataHub.EDI.ArchivedMessages.Application.Extensions.DependencyInjection; +namespace Energinet.DataHub.EDI.ArchivedMessages.Infrastructure.Extensions.DependencyInjection; public static class ArchivedMessageExtensions { diff --git a/source/ArchivedMessages.Infrastructure/QueryBuilder.cs b/source/ArchivedMessages.Infrastructure/QueryBuilder.cs index 699b519dae..594e612ba5 100644 --- a/source/ArchivedMessages.Infrastructure/QueryBuilder.cs +++ b/source/ArchivedMessages.Infrastructure/QueryBuilder.cs @@ -13,7 +13,7 @@ // limitations under the License. using Dapper; -using Energinet.DataHub.EDI.ArchivedMessages.Interfaces; +using Energinet.DataHub.EDI.ArchivedMessages.Domain.Models; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Authentication; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Exceptions; @@ -144,11 +144,11 @@ private static string WherePaginationPosition(FieldToSortBy fieldToSortBy, Direc """; } - private string OrderBy(FieldToSortBy fieldToSortBy, DirectionToSortBy directionToSortBy, bool navigatingForward) + private string OrderBy(FieldToSortBy fieldToSortBy, DirectionToSortBy sortByDirection, bool navigatingForward) { var pagingDirection = navigatingForward ? "DESC" : "ASC"; // Toggle the sort direction if navigating backwards, because sql use top to limit the result - var sortDirection = navigatingForward ? directionToSortBy : directionToSortBy.Identifier == DirectionToSortBy.Ascending.Identifier ? DirectionToSortBy.Descending : DirectionToSortBy.Ascending; + var sortDirection = navigatingForward ? sortByDirection : sortByDirection.Identifier == DirectionToSortBy.Ascending.Identifier ? DirectionToSortBy.Descending : DirectionToSortBy.Ascending; return $" ORDER BY {fieldToSortBy.Identifier} {sortDirection.Identifier}, RecordId {pagingDirection}"; } @@ -156,7 +156,7 @@ private string BuildStatement(GetMessagesQuery query) { var whereClause = " WHERE "; whereClause += _statement.Count > 0 ? $"{string.Join(" AND ", _statement)} AND " : string.Empty; - whereClause += WherePaginationPosition(query.Pagination.SortBy, query.Pagination.DirectionToSortBy, query.Pagination.Cursor, query.Pagination.NavigationForward); + whereClause += WherePaginationPosition(query.Pagination.FieldToSortBy, query.Pagination.DirectionToSortBy, query.Pagination.Cursor, query.Pagination.NavigationForward); string sqlStatement; if (query.IncludeRelatedMessages == true && query.MessageId is not null) @@ -183,7 +183,7 @@ private string BuildStatement(GetMessagesQuery query) sqlStatement = selectStatement + whereClause; } - sqlStatement += OrderBy(query.Pagination.SortBy, query.Pagination.DirectionToSortBy, query.Pagination.NavigationForward); + sqlStatement += OrderBy(query.Pagination.FieldToSortBy, query.Pagination.DirectionToSortBy, query.Pagination.NavigationForward); return sqlStatement; } diff --git a/source/ArchivedMessages.IntegrationTests/ArchivedMessages.IntegrationTests.csproj b/source/ArchivedMessages.IntegrationTests/ArchivedMessages.IntegrationTests.csproj index 37f297af9a..fc37da3b3e 100644 --- a/source/ArchivedMessages.IntegrationTests/ArchivedMessages.IntegrationTests.csproj +++ b/source/ArchivedMessages.IntegrationTests/ArchivedMessages.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;