Skip to content

Commit

Permalink
Merge branch 'main' into mbes/497-Add_grid_area_to_org_role
Browse files Browse the repository at this point in the history
# Conflicts:
#	source/Energinet.DataHub.MarketParticipant.ApplyDBMigrationsApp/Energinet.DataHub.MarketParticipant.ApplyDBMigrationsApp.csproj
#	source/Energinet.DataHub.MarketParticipant.Domain/Model/IOrganizationRole.cs
#	source/Energinet.DataHub.MarketParticipant.Domain/Model/Roles/BalancePowerSupplierRole.cs
#	source/Energinet.DataHub.MarketParticipant.Domain/Model/Roles/BalanceResponsiblePartyRole.cs
#	source/Energinet.DataHub.MarketParticipant.Domain/Model/Roles/DanishEnergyAgencyRole.cs
#	source/Energinet.DataHub.MarketParticipant.Domain/Model/Roles/GridAccessProviderRole.cs
#	source/Energinet.DataHub.MarketParticipant.Domain/Model/Roles/ImbalanceSettlementResponsibleRole.cs
#	source/Energinet.DataHub.MarketParticipant.Domain/Model/Roles/MeteredDataAggregatorRole.cs
#	source/Energinet.DataHub.MarketParticipant.Domain/Model/Roles/MeteredDataResponsibleRole.cs
#	source/Energinet.DataHub.MarketParticipant.Domain/Model/Roles/MeteringPointAdministratorRole.cs
#	source/Energinet.DataHub.MarketParticipant.Domain/Model/Roles/OrganizationRoleBase.cs
#	source/Energinet.DataHub.MarketParticipant.Domain/Model/Roles/SystemOperatorRole.cs
#	source/Energinet.DataHub.MarketParticipant.Infrastructure/Persistence/EntityConfiguration/OrganizationRoleEntityConfiguration.cs
#	source/Energinet.DataHub.MarketParticipant.Infrastructure/Persistence/Mappers/OrganizationMapper.cs
#	source/Energinet.DataHub.MarketParticipant.Infrastructure/Persistence/Model/OrganizationRoleEntity.cs
#	source/Energinet.DataHub.MarketParticipant.IntegrationTests/Repositories/OrganizationRepositoryTests.cs
#	source/Energinet.DataHub.MarketParticipant.Tests/Model/OrganizationRoleBaseTests.cs
  • Loading branch information
mbusk88 committed Feb 24, 2022
2 parents 87e483d + ddb5d4b commit 9281dcd
Show file tree
Hide file tree
Showing 46 changed files with 636 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.MarketParticipant.Application.Commands
{
public sealed record MarketRoleDto(string Function);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

namespace Energinet.DataHub.MarketParticipant.Application.Commands
{
public sealed record OrganizationDto(string? ActorId, string Name, string Gln);
public sealed record OrganizationDto(string Name, string Gln);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Collections.Generic;

namespace Energinet.DataHub.MarketParticipant.Application.Commands
{
public sealed record OrganizationRoleDto(string BusinessRole);
public sealed record OrganizationRoleDto(string BusinessRole, IEnumerable<MarketRoleDto> MarketRoles);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ await _organizationRepository
return Unit.Value;
}

private static IOrganizationRole CreateRole(OrganizationRoleDto role)
private static IOrganizationRole CreateRole(OrganizationRoleDto organizationRoleDto)
{
var businessRole = Enum.Parse<BusinessRoleCode>(role.BusinessRole, true);
return businessRole switch
var businessRole = Enum.Parse<BusinessRoleCode>(organizationRoleDto.BusinessRole, true);

IOrganizationRole organizationRole = businessRole switch
{
BusinessRoleCode.Ddk => new BalanceResponsiblePartyRole(),
BusinessRoleCode.Ddm => new GridAccessProviderRole(),
Expand All @@ -72,8 +73,16 @@ private static IOrganizationRole CreateRole(OrganizationRoleDto role)
BusinessRoleCode.Ez => new SystemOperatorRole(),
BusinessRoleCode.Mdr => new MeteredDataResponsibleRole(),
BusinessRoleCode.Sts => new DanishEnergyAgencyRole(),
_ => throw new ArgumentOutOfRangeException(nameof(role))
_ => throw new ArgumentOutOfRangeException(nameof(organizationRoleDto))
};

foreach (var marketRoleDto in organizationRoleDto.MarketRoles)
{
var function = Enum.Parse<EicFunction>(marketRoleDto.Function, true);
organizationRole.MarketRoles.Add(new MarketRole(function));
}

return organizationRole;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Threading;
using System.Threading.Tasks;
using Energinet.DataHub.MarketParticipant.Application.Commands;
using Energinet.DataHub.MarketParticipant.Domain.Model;
using Energinet.DataHub.MarketParticipant.Domain.Repositories;
using Energinet.DataHub.MarketParticipant.Domain.Services;
using Energinet.DataHub.MarketParticipant.Infrastructure.Services;
using Energinet.DataHub.MarketParticipant.Utilities;
using MediatR;

Expand All @@ -28,28 +28,28 @@ public sealed class CreateOrganizationHandler : IRequestHandler<CreateOrganizati
{
private readonly IOrganizationRepository _organizationRepository;
private readonly IOrganizationEventDispatcher _organizationEventDispatcher;
private readonly IActiveDirectoryService _activeDirectoryService;

public CreateOrganizationHandler(IOrganizationRepository organizationRepository, IOrganizationEventDispatcher organizationEventDispatcher)
public CreateOrganizationHandler(
IOrganizationRepository organizationRepository,
IOrganizationEventDispatcher organizationEventDispatcher,
IActiveDirectoryService activeDirectoryService)
{
_organizationRepository = organizationRepository;
_organizationEventDispatcher = organizationEventDispatcher;
_activeDirectoryService = activeDirectoryService;
}

public async Task<CreateOrganizationResponse> Handle(CreateOrganizationCommand request, CancellationToken cancellationToken)
{
Guard.ThrowIfNull(request, nameof(request));

var (actor, name, gln) = request.Organization;
var (name, gln) = request.Organization;

Guid? actorId = null;

if (Guid.TryParse(actor, out var parsedActorId))
{
actorId = parsedActorId;
}
var appRegistrationId = await _activeDirectoryService.EnsureAppRegistrationIdAsync(gln).ConfigureAwait(false);

var organizationToSave = new Organization(
actorId, // TODO: Where do we get ActorId from?
appRegistrationId,
new GlobalLocationNumber(gln),
name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ public AddOrganizationRoleCommandRuleSet()
.RuleFor(role => role.BusinessRole)
.NotEmpty()
.IsEnumName(typeof(BusinessRoleCode), false);

validator
.RuleFor(x => x.MarketRoles)
.NotNull()
.ChildRules(rolesValidator =>
{
rolesValidator
.RuleForEach(x => x)
.NotNull()
.ChildRules(roleValidator =>
{
roleValidator
.RuleFor(x => x.Function)
.NotEmpty()
.IsEnumName(typeof(EicFunction), false);
});
});
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ limitations under the License.
<EmbeddedResource Include="Scripts\B-002\Model\202202230930 Add GridAreaId to OrganizationRole Table.sql" />
<EmbeddedResource Include="Scripts\B-002\Seed\202201311105 RemoveAssignedActorToGridArea.sql" />
<EmbeddedResource Include="Scripts\B-002\Seed\202201311106 RemoveGridAreaWithNoActor.sql" />
<EmbeddedResource Include="Scripts\LocalDB\202202240930 Create MarketRole Table.sql" />
<EmbeddedResource Include="Scripts\LocalDB\202202181115 Add ActorId to Organization Table.sql" />
<EmbeddedResource Include="Scripts\LocalDB\202202171430 Create OrganizationRole Table.sql" />
<EmbeddedResource Include="Scripts\LocalDB\202202091216 Create Organization Table.sql" />
Expand All @@ -74,6 +75,7 @@ limitations under the License.
<EmbeddedResource Include="Scripts\U-001\Model\202202091216 Create Organization Table.sql" />
<EmbeddedResource Include="Scripts\U-001\Model\202202161302 Create GridAreaNew Table.sql" />
<EmbeddedResource Include="Scripts\U-001\Model\202202230930 Add GridAreaId to OrganizationRole Table.sql" />
<EmbeddedResource Include="Scripts\U-001\Model\202202240930 Create MarketRole Table.sql" />
<EmbeddedResource Include="Scripts\U-001\Seed\202201311105 RemoveAssignedActorToGridArea.sql" />
<EmbeddedResource Include="Scripts\U-001\Seed\202201311104 RemoveAssignGridAreaToEnerginetActor.sql" />
<EmbeddedResource Include="Scripts\U-001\Seed\202201311106 RemoveGridAreaWithNoActor.sql" />
Expand All @@ -84,6 +86,8 @@ limitations under the License.
<None Remove="Scripts\B-002\Model\202201311000 Create GridAreaInfo Table.sql" />
<None Remove="Scripts\LocalDB\202202171430 Create OrganizationRole Table.sql" />
<None Remove="Scripts\LocalDB\202202181115 Add ActorId to Organization Table.sql" />
<None Remove="Scripts\LocalDB\202202240930 Create MarketRole Table.sql" />
<None Remove="Scripts\U-001\Model\202202240930 Create MarketRole Table.sql" />
<EmbeddedResource Include="Scripts\B-002\Model\202201311000 Create GridAreaInfo Table.sql" />
<None Remove="Scripts\B-002\Model\202201311001 Create GridArea View.sql" />
<EmbeddedResource Include="Scripts\B-002\Model\202201311001 Create GridArea View.sql" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE [dbo].[MarketRole]
(
[Id] [uniqueidentifier] NOT NULL,
[OrganizationRoleId] [uniqueidentifier] NOT NULL,
[Function] [int] NOT NULL,

CONSTRAINT PK_MarketRole PRIMARY KEY ([Id]),
CONSTRAINT FK_OrganizationRoleId_OrganizationRole FOREIGN KEY ([OrganizationRoleId]) REFERENCES [dbo].[OrganizationRole]([Id])
)
GO
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE [dbo].[MarketRole]
(
[Id] [uniqueidentifier] NOT NULL,
[OrganizationRoleId] [uniqueidentifier] NOT NULL,
[Function] [int] NOT NULL,

CONSTRAINT PK_MarketRole PRIMARY KEY ([Id]),
CONSTRAINT FK_OrganizationRoleId_OrganizationRole FOREIGN KEY ([OrganizationRoleId]) REFERENCES [dbo].[OrganizationRole]([Id])
)
GO
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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.MarketParticipant.Domain.Model
{
public enum EicFunction
{
BalanceResponsibleParty = 1,
BalancingServiceProvider = 2,
BillingAgent = 3,
CapacityTrader = 4,
Consumer = 5,
ConsumptionResponsibleParty = 6,
ConsentAdministrator = 7,
CoordinatedCapacityCalculator = 8,
CoordinationCentreOperator = 9,
DataProvider = 10,
EnergyServiceCompany = 11,
EnergySupplier = 12,
EnergyTrader = 13,
GridAccessProvider = 14,
ImbalanceSettlementResponsible = 15,
InterconnectionTradeResponsible = 16,
LfcOperator = 17,
MarketInformationAggregator = 18,
MarketOperator = 19,
MeritOrderListResponsible = 20,
MeterAdministrator = 21,
MeterOperator = 22,
MeteredDataAdministrator = 23,
MeteredDataAggregator = 24,
MeteredDataCollector = 25,
MeteredDataResponsible = 26,
MeteringPointAdministrator = 27,
ModelMergingAgent = 28,
ModellingAuthority = 29,
NominatedElectricityMarketOperator = 30,
NominationValidator = 31,
PartyAdministrator = 32,
PartyConnectedtotheGrid = 33,
Producer = 34,
ProductionResponsibleParty = 35,
ReconciliationAccountable = 36,
ReconciliationResponsible = 37,
ReserveAllocator = 38,
ResourceAggregator = 39,
ResourceCapacityMechanismOperator = 40,
ResourceProvider = 41,
Scheduling = 42,
Agent = 43,
SchedulingAreaResponsible = 44,
SystemOperator = 45,
TradeResponsibleParty = 46,
TransmissionCapacityAllocator = 47
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
// limitations under the License.

using System;
using System.Collections.Generic;

namespace Energinet.DataHub.MarketParticipant.Domain.Model
{
/// <summary>
/// Represents one of the role of an organization.
/// Represents one of the roles of an organization.
/// </summary>
public interface IOrganizationRole
{
Expand All @@ -41,18 +42,29 @@ public interface IOrganizationRole
/// </summary>
GridArea? Area { get; }

/// <summary>
/// The list of market roles (functions and permissions) supported by the current organization role.
/// </summary>
public ICollection<MarketRole> MarketRoles { get; }

/// <summary>
/// Activates the current role, the status changes to Active.
/// Only New and Inactive roles can be activated.
/// Only New, Inactive and Passive roles can be activated.
/// </summary>
void Activate();

/// <summary>
/// Deactives the current role, the status changes to Inactive.
/// Only Active roles can be deactivated.
/// Only Active and Passive roles can be deactivated.
/// </summary>
void Deactivate();

/// <summary>
/// Passive roles have certain domain-specific actions that can be performed.
/// Only Active and Inactive roles can be set to passive.
/// </summary>
void SetAsPassive();

/// <summary>
/// Soft-deletes the current role, the status changes to Deleted.
/// The role becomes read-only after deletion.
Expand Down
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;

namespace Energinet.DataHub.MarketParticipant.Domain.Model
{
/// <summary>
/// Describes a marked role, defined by its function and permissions.
/// </summary>
public sealed class MarketRole
{
public MarketRole(EicFunction function)
{
Function = function;
}

/// <summary>
/// Specifies the EIC function of the current role.
/// </summary>
public EicFunction Function { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public sealed class Organization
private readonly ICollection<IOrganizationRole> _roles;

public Organization(
Guid? actorId,
Guid actorId,
GlobalLocationNumber gln,
string name)
{
Expand All @@ -38,7 +38,7 @@ public Organization(

public Organization(
OrganizationId id,
Guid? actorId,
Guid actorId,
GlobalLocationNumber gln,
string name,
IEnumerable<IOrganizationRole> roles)
Expand All @@ -51,7 +51,7 @@ public Organization(
}

public OrganizationId Id { get; }
public Guid? ActorId { get; }
public Guid ActorId { get; }

public GlobalLocationNumber Gln { get; }
public string Name { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum RoleStatus
New = 1,
Active = 2,
Inactive = 3,
Deleted = 4
Passive = 4,
Deleted = 5
}
}
Loading

0 comments on commit 9281dcd

Please sign in to comment.