Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsDue committed Dec 4, 2024
1 parent 51a0be5 commit 528fc12
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 9 deletions.
34 changes: 34 additions & 0 deletions source/BuildingBlocks.Domain/Models/MessageType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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.Text.Json.Serialization;
using Energinet.DataHub.EDI.BuildingBlocks.Domain.DataHub;

namespace Energinet.DataHub.EDI.BuildingBlocks.Domain.Models;

/// <summary>
/// Represent the Message Type
/// Mapping of the Message Type code to the Message Type name is comming from this section "Datadefinitioner for DocumentNameCodeType" document:
/// https://energinet.dk/media/4v0nfpec/edi-transaktioner-for-det-danske-elmarked.pdf
/// </summary>
public sealed class MessageType : DataHubType<MessageType>
{
public static readonly MessageType ValidatedMeteredData = new(nameof(ValidatedMeteredData), "E66");
public static readonly MessageType RequestAggregatedMeteredData = new(nameof(RequestAggregatedMeteredData), "E74");
public static readonly MessageType RequestForAggregatedBillingInformation = new(nameof(RequestForAggregatedBillingInformation), "D21");

[JsonConstructor]
private MessageType(string name, string code)
: base(name, code) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public interface IIncomingMessage
/// </summary>
IReadOnlyCollection<IIncomingMessageSeries> Series { get; }

public IReadOnlyCollection<string> AllowedMessageTypes { get; }
public IReadOnlyCollection<MessageType> AllowedMessageTypes { get; }

public IReadOnlyCollection<BusinessReason> AllowedBusinessReasons { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ public class MeteredDataForMeasurementPointMessageBase(

public IReadOnlyCollection<IIncomingMessageSeries> Series { get; } = series;

public IReadOnlyCollection<string> AllowedMessageTypes => ["E66"];
public IReadOnlyCollection<MessageType> AllowedMessageTypes => [
Energinet.DataHub.EDI.BuildingBlocks.Domain.Models.MessageType.ValidatedMeteredData,
];

public IReadOnlyCollection<BusinessReason> AllowedBusinessReasons => [Energinet.DataHub.EDI.BuildingBlocks.Domain.Models.BusinessReason.PeriodicMetering];
public IReadOnlyCollection<BusinessReason> AllowedBusinessReasons => [
Energinet.DataHub.EDI.BuildingBlocks.Domain.Models.BusinessReason.PeriodicMetering,
];

public IReadOnlyCollection<ActorRole> AllowedSenderRoles => [ActorRole.MeteredDataResponsible];
public IReadOnlyCollection<ActorRole> AllowedSenderRoles => [
ActorRole.MeteredDataResponsible,
];
}

public record MeteredDataForMeasurementPointSeries(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public record RequestAggregatedMeasureDataMessage(
string? BusinessType,
IReadOnlyCollection<IIncomingMessageSeries> Series) : IIncomingMessage
{
public IReadOnlyCollection<string> AllowedMessageTypes => ["E74"];
public IReadOnlyCollection<MessageType> AllowedMessageTypes => [
Energinet.DataHub.EDI.BuildingBlocks.Domain.Models.MessageType.RequestAggregatedMeteredData,
];

public IReadOnlyCollection<BusinessReason> AllowedBusinessReasons =>
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public record RequestWholesaleServicesMessage(
string? BusinessType,
IReadOnlyCollection<IIncomingMessageSeries> Series) : IIncomingMessage
{
public IReadOnlyCollection<string> AllowedMessageTypes => ["D21"];
public IReadOnlyCollection<MessageType> AllowedMessageTypes => [
Energinet.DataHub.EDI.BuildingBlocks.Domain.Models.MessageType.RequestForAggregatedBillingInformation,
];

public IReadOnlyCollection<BusinessReason> AllowedBusinessReasons =>
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Task<Result> ValidateAsync(IIncomingMessage message, CancellationToken ca
{
ArgumentNullException.ThrowIfNull(message);

return Task.FromResult(message.AllowedMessageTypes.Contains(message.MessageType)
return Task.FromResult(message.AllowedMessageTypes.Select(x => x.Code).Contains(message.MessageType)
? Result.Succeeded()
: Result.Failure(new NotSupportedMessageType(message.MessageType)));
}
Expand Down
6 changes: 4 additions & 2 deletions source/IncomingMessages.Domain/Validation/SenderAuthorizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ private void EnsureSenderRoleCode(IIncomingMessage message, bool allSeriesAreDel
return;
}

if (message.AllowedSenderRoles.Contains(ActorRole.FromCode(message.SenderRoleCode)) == false)
if (message.AllowedSenderRoles.Contains(ActorRole.FromCode(message.SenderRoleCode)))
{
_validationErrors.Add(new SenderRoleTypeIsNotAuthorized());
return;
}

_validationErrors.Add(new SenderRoleTypeIsNotAuthorized());
}

private bool AllSeriesAreDelegatedToSender(bool allSeriesAreDelegated)
Expand Down

0 comments on commit 528fc12

Please sign in to comment.