Skip to content

Commit

Permalink
Merge branch 'main' into juj/TempFixForDeployToDev003
Browse files Browse the repository at this point in the history
  • Loading branch information
FirestarJes authored Nov 14, 2024
2 parents e864fd3 + 5376455 commit 9270866
Show file tree
Hide file tree
Showing 44 changed files with 248 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ public async Task GetActorGridAreasAsync()
.Setup(x => x.ActorGetAsync(_actorId, It.IsAny<string?>()))
.ReturnsAsync(new ActorDto
{
MarketRoles = [
MarketRole =
new ActorMarketRoleDto
{
GridAreas = _gridAreas
.Select(g => new ActorGridAreaDto { Id = g.Id })
.ToList(),
},
],
});

server.MarketParticipantClientV1Mock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Energinet.DataHub.WebApi.Tests.Integration.GraphQL.Actor;
public class FilteredActorsQueryTests
{
private static readonly string _filteredActors =
$$"""
"""
{
filteredActors {
displayName
Expand All @@ -54,23 +54,17 @@ public async Task GetFilteredActorsAsync(bool isFas)
new()
{
ActorId = actorId,
ActorNumber = new ActorNumberDto() { Value = "1234567890" },
MarketRoles =
[
new ActorMarketRoleDto() { EicFunction = EicFunction.DataHubAdministrator },
],
Name = new ActorNameDto() { Value = "Test" },
ActorNumber = new ActorNumberDto { Value = "1234567890" },
MarketRole = new ActorMarketRoleDto { EicFunction = EicFunction.DataHubAdministrator },
Name = new ActorNameDto { Value = "Test" },
OrganizationId = organizationId,
},
new()
{
ActorId = new Guid("ceaa4172-cce6-4276-bd88-23589ef500bb"),
ActorNumber = new ActorNumberDto() { Value = "1234567890" },
MarketRoles =
[
new ActorMarketRoleDto() { EicFunction = EicFunction.BillingAgent },
],
Name = new ActorNameDto() { Value = "Test1" },
ActorNumber = new ActorNumberDto { Value = "1234567890" },
MarketRole = new ActorMarketRoleDto { EicFunction = EicFunction.BillingAgent },
Name = new ActorNameDto { Value = "Test1" },
OrganizationId = organizationId,
},
};
Expand All @@ -81,7 +75,7 @@ public async Task GetFilteredActorsAsync(bool isFas)

server.MarketParticipantClientV1Mock
.Setup(x => x.OrganizationGetAsync(organizationId, default))
.ReturnsAsync(new OrganizationDto() { OrganizationId = organizationId, Domains = new List<string> { "test.com", "test2.dk" } });
.ReturnsAsync(new OrganizationDto { OrganizationId = organizationId, Domains = new List<string> { "test.com", "test2.dk" } });

var context = new DefaultHttpContext
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Energinet.DataHub.WebApi.Clients.MarketParticipant.v1;
Expand Down Expand Up @@ -43,11 +42,11 @@ public class BalanceResponsibilityAgreementStatusTests

public static IEnumerable<object[]> GetTestCases()
{
yield return new object[] { "Awaiting", DateTimeOffset.Now.AddDays(5), null };
yield return new object[] { "Active without enddate", DateTimeOffset.Now.AddDays(-5), null };
yield return new object[] { "Active with enddate", DateTimeOffset.Now.AddDays(-5), DateTimeOffset.Now.AddDays(10) };
yield return new object[] { "Expired", DateTimeOffset.Now.AddDays(-5), DateTimeOffset.Now.AddDays(-1) };
yield return new object[] { "SoonToExpire", DateTimeOffset.Now.AddDays(-5), DateTimeOffset.Now.AddDays(3) };
yield return ["Awaiting", DateTimeOffset.Now.AddDays(5), null];
yield return ["Active without enddate", DateTimeOffset.Now.AddDays(-5), null];
yield return ["Active with enddate", DateTimeOffset.Now.AddDays(-5), DateTimeOffset.Now.AddDays(10)];
yield return ["Expired", DateTimeOffset.Now.AddDays(-5), DateTimeOffset.Now.AddDays(-1)];
yield return ["SoonToExpire", DateTimeOffset.Now.AddDays(-5), DateTimeOffset.Now.AddDays(3)];
}

#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
Expand All @@ -68,22 +67,19 @@ private static async Task ExecuteTestAsync(string testname, DateTimeOffset valid
ActorId = _actorId,
Name = new ActorNameDto { Value = "Test" },
ActorNumber = new ActorNumberDto { Value = "1234567890123" },
MarketRoles = new[]
{
MarketRole =
new ActorMarketRoleDto
{
EicFunction = EicFunction.BalanceResponsibleParty,
},
},
OrganizationId = Guid.NewGuid(),
Status = "Active",
});

server.MarketParticipantClientV1Mock
.Setup(x => x.BalanceResponsibilityRelationsAsync(_actorId, default))
.ReturnsAsync(new[]
{
new BalanceResponsibilityRelationDto()
.ReturnsAsync([
new BalanceResponsibilityRelationDto()
{
BalanceResponsibleId = Guid.NewGuid(),
ValidFrom = validFrom,
Expand All @@ -92,7 +88,7 @@ private static async Task ExecuteTestAsync(string testname, DateTimeOffset valid
GridAreaId = Guid.NewGuid(),
MeteringPointType = MeteringPointType.D03NotUsed,
},
});
]);

var result = await server.ExecuteRequestAsync(b => b.SetDocument(_actorByIdWithbalanceResponsibleAgreementsQuery));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@
using System.Threading;
using System.Threading.Tasks;
using Energinet.DataHub.WebApi.Clients.MarketParticipant.v1;
using Energinet.DataHub.WebApi.GraphQL.Extensions;
using Energinet.DataHub.WebApi.Tests.Extensions;
using Energinet.DataHub.WebApi.Tests.TestServices;
using Moq;
using Xunit;

namespace Energinet.DataHub.WebApi.Tests.Integration.GraphQL.Actor;
namespace Energinet.DataHub.WebApi.Tests.Integration.GraphQL.GridArea;

public class CalculateGridAreaStatusTest
{
private static readonly string _getGridAreasWithStatus =
$$"""
"""
{
gridAreas {
id
Expand All @@ -47,22 +46,16 @@ public async Task GetGridAreaWithStatusAsync()
new()
{
ActorId = new Guid("ceaa4172-cce6-4276-bd88-23589ef500aa"),
ActorNumber = new ActorNumberDto() { Value = "1234567890" },
MarketRoles =
[
new ActorMarketRoleDto() { EicFunction = EicFunction.DataHubAdministrator },
],
Name = new ActorNameDto() { Value = "Test" },
ActorNumber = new ActorNumberDto { Value = "1234567890" },
MarketRole = new ActorMarketRoleDto { EicFunction = EicFunction.DataHubAdministrator },
Name = new ActorNameDto { Value = "Test" },
},
new()
{
ActorId = new Guid("ceaa4172-cce6-4276-bd88-23589ef500bb"),
ActorNumber = new ActorNumberDto() { Value = "1234567890" },
MarketRoles =
[
new ActorMarketRoleDto() { EicFunction = EicFunction.BillingAgent },
],
Name = new ActorNameDto() { Value = "Test1" },
ActorNumber = new ActorNumberDto { Value = "1234567890" },
MarketRole = new ActorMarketRoleDto { EicFunction = EicFunction.BillingAgent },
Name = new ActorNameDto { Value = "Test1" },
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Actor {
name: String!
glnOrEicNumber: String!
displayName: String!
marketRole: EicFunction
marketRole: EicFunction!
userRoles: [ActorUserRole!]!
status: ActorStatus!
gridAreas: [GridAreaDto!]!
Expand Down Expand Up @@ -865,7 +865,7 @@ input CreateActorInput {
organizationId: UUID!
name: ActorNameDtoInput!
actorNumber: ActorNumberDtoInput!
marketRoles: [CreateActorMarketRoleInput!]!
marketRole: CreateActorMarketRoleInput!
}

input CreateActorMarketRoleInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7039,8 +7039,8 @@ public partial class ActorDto
[Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public ActorNameDto Name { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("marketRoles", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.ICollection<ActorMarketRoleDto> MarketRoles { get; set; } = default!;
[Newtonsoft.Json.JsonProperty("marketRole", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public ActorMarketRoleDto MarketRole { get; set; } = default!;

}

Expand Down Expand Up @@ -7148,8 +7148,8 @@ public partial class ChangeActorDto
[Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public ActorNameDto Name { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("marketRoles", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.ICollection<ActorMarketRoleDto> MarketRoles { get; set; } = default!;
[Newtonsoft.Json.JsonProperty("marketRole", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public ActorMarketRoleDto MarketRole { get; set; } = default!;

}

Expand Down Expand Up @@ -7232,8 +7232,8 @@ public partial class CreateActorDto
[Newtonsoft.Json.JsonProperty("actorNumber", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public ActorNumberDto ActorNumber { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("marketRoles", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.ICollection<ActorMarketRoleDto> MarketRoles { get; set; } = default!;
[Newtonsoft.Json.JsonProperty("marketRole", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public ActorMarketRoleDto MarketRole { get; set; } = default!;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3824,11 +3824,12 @@
}
]
},
"marketRoles": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ActorMarketRoleDto"
}
"marketRole": {
"allOf": [
{
"$ref": "#/components/schemas/ActorMarketRoleDto"
}
]
}
}
},
Expand Down Expand Up @@ -4018,11 +4019,12 @@
}
]
},
"marketRoles": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ActorMarketRoleDto"
}
"marketRole": {
"allOf": [
{
"$ref": "#/components/schemas/ActorMarketRoleDto"
}
]
}
}
},
Expand Down Expand Up @@ -4144,11 +4146,12 @@
}
]
},
"marketRoles": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ActorMarketRoleDto"
}
"marketRole": {
"allOf": [
{
"$ref": "#/components/schemas/ActorMarketRoleDto"
}
]
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public async Task DownloadBalanceResponsiblesAsync([FromQuery] string locale, [F
}

var actors = await _marketParticipantClientV1.ActorGetAsync().ConfigureAwait(false);
var energySuppliers = actors.Where(x => x.MarketRoles.Any(y => y.EicFunction == EicFunction.EnergySupplier)).ToDictionary(x => x.ActorNumber.Value, x => x.Name.Value);
var balanceResponsibles = actors.Where(x => x.MarketRoles.Any(y => y.EicFunction == EicFunction.BalanceResponsibleParty)).ToDictionary(x => x.ActorNumber.Value, x => x.Name.Value);
var energySuppliers = actors.Where(x => x.MarketRole.EicFunction == EicFunction.EnergySupplier).ToDictionary(x => x.ActorNumber.Value, x => x.Name.Value);
var balanceResponsibles = actors.Where(x => x.MarketRole.EicFunction == EicFunction.BalanceResponsibleParty).ToDictionary(x => x.ActorNumber.Value, x => x.Name.Value);
var separator = new CultureInfo(locale).TextInfo.ListSeparator;

headerLine += $"{separator}\"SUPPLIER_NAME\"{separator}\"BALANCE_RESPONSIBLE_NAME\"\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ActorByNumberAndRoleBatchDataLoader(
{
return (await _client
.ActorGetAsync(cancellationToken))
.Where(x => x.MarketRoles.Any(role => keys.Contains((x.ActorNumber.Value, role.EicFunction))))
.ToDictionary(x => (x.ActorNumber.Value, x.MarketRoles.First(role => keys.Contains((x.ActorNumber.Value, role.EicFunction))).EicFunction));
.Where(x => keys.Contains((x.ActorNumber.Value, x.MarketRole.EicFunction)))
.ToDictionary(x => (x.ActorNumber.Value, x.MarketRole.EicFunction));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public ActorNameByMarketRoleDataLoader(

foreach (var actor in actors.Where(x => actorNumbers.Contains(x.ActorNumber.Value)))
{
foreach (var marketRole in actor.MarketRoles)
{
dictionary.TryAdd((actor.ActorNumber.Value, marketRole.EicFunction), actor.Name);
}
dictionary.TryAdd((actor.ActorNumber.Value, actor.MarketRole.EicFunction), actor.Name);
}

return dictionary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ internal static async Task<IEnumerable<GridAreaDto>> GetGridAreasAsync(
{
var owner = actors.FirstOrDefault(actor =>
actor.Status == "Active" &&
actor.MarketRoles.Any(mr =>
mr.EicFunction == EicFunction.GridAccessProvider &&
mr.GridAreas.Any(ga => ga.Id == gridArea.Id)));
actor.MarketRole.EicFunction == EicFunction.GridAccessProvider &&
actor.MarketRole.GridAreas.Any(ga => ga.Id == gridArea.Id));

return owner == null
? gridArea
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ public async Task<bool> CreateMarketParticipantAsync(
Name = input.Actor.Name,
ActorNumber = input.Actor.ActorNumber,
OrganizationId = organizationId,
MarketRoles = input.Actor.MarketRoles.Select(mr => new ActorMarketRoleDto
MarketRole = new ActorMarketRoleDto
{
EicFunction = mr.EicFunction,
GridAreas = mr.GridAreas.Select(ga => new ActorGridAreaDto()
EicFunction = input.Actor.MarketRole.EicFunction,
Comment = input.Actor.MarketRole.Comment,
GridAreas = input.Actor.MarketRole.GridAreas.Select(ga => new ActorGridAreaDto()
{
MeteringPointTypes = ga.MeteringPointTypes,
Id = gridAreas.Single(g => g.Code == ga.Code).Id,
}).ToList(),
Comment = mr.Comment,
}).ToList(),
},
};

var actorId = await client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public async Task<IEnumerable<ActorDto>> GetActorsForEicFunctionAsync(
EicFunction[]? eicFunctions,
[Service] IMarketParticipantClient_V1 client) =>
(await client.ActorGetAsync())
.Where(x =>
x.MarketRoles.Any(y =>
eicFunctions != null && eicFunctions.Contains(y.EicFunction)));
.Where(x => eicFunctions != null && eicFunctions.Contains(x.MarketRole.EicFunction));

public async Task<IEnumerable<ProcessDelegation>> GetDelegationsForActorAsync(
Guid actorId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public async Task<Connection<ArchivedMessageResultV3>> GetArchivedMessagesAsync(
End = created.End.ToDateTimeOffset(),
},
SenderNumber = (await sender)?.ActorNumber.Value,
SenderRole = (await sender)?.MarketRoles.FirstOrDefault()?.EicFunction.ToActorRole(),
SenderRole = (await sender)?.MarketRole.EicFunction.ToActorRole(),
ReceiverNumber = (await receiver)?.ActorNumber.Value,
ReceiverRole = (await receiver)?.MarketRoles.FirstOrDefault()?.EicFunction.ToActorRole(),
ReceiverRole = (await receiver)?.MarketRole.EicFunction.ToActorRole(),
DocumentTypes = documentTypes,
BusinessReasons = businessReasons.IsNullOrEmpty()
? null
Expand Down Expand Up @@ -157,8 +157,8 @@ private static Edge<ArchivedMessageResultV3> MakeEdge(
{
FieldToSortBy.MessageId => message.MessageId ?? string.Empty,
FieldToSortBy.DocumentType => message.DocumentType.ToString(),
FieldToSortBy.SenderNumber => message.SenderNumber ?? string.Empty,
FieldToSortBy.ReceiverNumber => message.ReceiverNumber ?? string.Empty,
FieldToSortBy.SenderNumber => message.SenderNumber,
FieldToSortBy.ReceiverNumber => message.ReceiverNumber,
FieldToSortBy.CreatedAt => message.CreatedAt.ToString("yyyy-MM-dd HH:mm:ss.fff"),
_ => throw new ArgumentOutOfRangeException(nameof(field), field, "Unexpected FieldToSortBy value"),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public async Task<IEnumerable<GridAreaDto>> GetGridAreasAsync(
GridAreaByIdBatchDataLoader dataLoader)
{
var gridAreas = await Task.WhenAll(
actor.MarketRoles
.SelectMany(marketRole => marketRole.GridAreas.Select(gridArea => gridArea.Id))
.Distinct()
actor.MarketRole.GridAreas.Select(gridArea => gridArea.Id)
.Select(gridAreaId => dataLoader.LoadRequiredAsync(gridAreaId)));

return gridAreas.OrderBy(g => g.Code);
Expand Down
Loading

0 comments on commit 9270866

Please sign in to comment.