Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: or-2334 handle grar as command instead of messages #1035

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace AssociationRegistry.Admin.AddressSync;

using Grar.AddressSync;
using Grar.Models;
using Infrastructure.Notifications;
using Marten;
using MessageHandling.Sqs.AddressSync;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Notifications;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,9 @@
<ProjectReference Include="..\AssociationRegistry\AssociationRegistry.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="MessageHandling\Sqs\" />
</ItemGroup>

<Import Project="..\..\.paket\Paket.Restore.targets"/>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace AssociationRegistry.Admin.AddressSync;

using Grar.AddressSync;
using Marten;
using Messages;

public interface ITeSynchroniserenLocatiesFetcher
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace AssociationRegistry.Admin.AddressSync.MessageHandling.Sqs.AddressSync;

using Messages;
using Wolverine;

public class TeSynchroniserenLocatieAdresMessageHandler(IMessageBus messageBus)
{
public async Task Handle(TeSynchroniserenLocatieAdresMessage message, CancellationToken cancellationToken)
{
var command = message.ToCommand();

await messageBus.InvokeAsync(command, cancellationToken);
}
}
2 changes: 1 addition & 1 deletion src/AssociationRegistry.Admin.AddressSync/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using Destructurama;
using EventStore;
using Grar;
using Grar.AddressSync;
using Infrastructure.Extensions;
using MessageHandling.Sqs.AddressSync;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace AssociationRegistry.Admin.AddressSync;

using Grar;
using Grar.AddressSync;
using Grar.Exceptions;
using Grar.Models;
using Marten;
using Messages;
using Microsoft.Extensions.Logging;
using Schema.Detail;
using System.Diagnostics.Contracts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

using Asp.Versioning;
using Be.Vlaanderen.Basisregisters.Api;
using Grar.AddressMatch;
using Marten;
using MessageHandling.Sqs.AddressMatch;
using Messages;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Schema.Detail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<Folder Include="GrarConsumer\Handlers\Fusies\" />
<Folder Include="Infrastructure\ConfigurationBindings\" />
<Folder Include="MessageHandling\Postgres\" />
<Folder Include="MessageHandling\Sqs\" />
<Folder Include="Verenigingen\Contactgegevens\FeitelijkeVereniging\" />
<Folder Include="Verenigingen\Vertegenwoordigers\FeitelijkeVereniging\" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
using Acties.GrarConsumer;
using Amazon.Runtime;
using EventStore;
using Grar.AddressMatch;
using Hosts.Configuration;
using JasperFx.CodeGeneration;
using MessageHandling.Postgres.Dubbels;
using MessageHandling.Sqs.AddressMatch;
using Messages;
using Serilog;
using Vereniging;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace AssociationRegistry.Admin.Api.MessageHandling.Sqs.AddressMatch;

using Messages;
using Wolverine;

public class TeAdresMatchenLocatieMessageHandler(IMessageBus messageBus)
{
public async Task Handle(TeAdresMatchenLocatieMessage message, CancellationToken cancellationToken)
{
var command = message.ToCommand();

await messageBus.InvokeAsync(command, cancellationToken);
}
}
2 changes: 1 addition & 1 deletion src/AssociationRegistry.Admin.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace AssociationRegistry.Admin.Api;
using Formats;
using Framework;
using Grar;
using Grar.AddressMatch;
using Grar.GrarUpdates;
using Grar.GrarUpdates.Fusies;
using Grar.GrarUpdates.Fusies.TeHeradresserenLocaties;
Expand Down Expand Up @@ -51,6 +50,7 @@ namespace AssociationRegistry.Admin.Api;
using Lamar.Microsoft.DependencyInjection;
using Magda;
using Marten;
using MessageHandling.Sqs.AddressMatch;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Diagnostics;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace AssociationRegistry.Acties.ProbeerAdresTeMatchen;

public record ProbeerAdresTeMatchenCommand(string VCode, int LocatieId);
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
namespace AssociationRegistry.Grar.AddressMatch;
namespace AssociationRegistry.Acties.ProbeerAdresTeMatchen;

using EventStore;
using Framework;
using Grar;
using Microsoft.Extensions.Logging;
using NodaTime;
using Vereniging;
using Vereniging.Exceptions;

public class TeAdresMatchenLocatieMessageHandler
public class ProbeerAdresTeMatchenCommandHandler
{
private readonly ILogger<TeAdresMatchenLocatieMessageHandler> _logger;
private readonly ILogger<ProbeerAdresTeMatchenCommandHandler> _logger;
private readonly IGrarClient _grarClient;
private readonly IVerenigingsRepository _verenigingsRepository;

public TeAdresMatchenLocatieMessageHandler(
public ProbeerAdresTeMatchenCommandHandler(
IVerenigingsRepository verenigingsRepository,
IGrarClient grarClient,
ILogger<TeAdresMatchenLocatieMessageHandler> logger)
ILogger<ProbeerAdresTeMatchenCommandHandler> logger)
{
_verenigingsRepository = verenigingsRepository;
_grarClient = grarClient;
_logger = logger;
}

public async Task Handle(
TeAdresMatchenLocatieMessage teAdresMatchenLocatieMessage,
ProbeerAdresTeMatchenCommand command,
CancellationToken cancellationToken = default)
{
_logger.LogInformation($"Handle {nameof(TeAdresMatchenLocatieMessageHandler)}");
_logger.LogInformation($"Handle {nameof(ProbeerAdresTeMatchenCommandHandler)}");

try
{
var vereniging = await _verenigingsRepository.Load<VerenigingOfAnyKind>(VCode.Hydrate(teAdresMatchenLocatieMessage.VCode), allowDubbeleVereniging: true);
var vereniging = await _verenigingsRepository.Load<VerenigingOfAnyKind>(VCode.Hydrate(command.VCode), allowDubbeleVereniging: true);

await vereniging.ProbeerAdresTeMatchen(_grarClient, teAdresMatchenLocatieMessage.LocatieId, cancellationToken);
await vereniging.ProbeerAdresTeMatchen(_grarClient, command.LocatieId, cancellationToken);

await _verenigingsRepository.Save(
vereniging,
Expand All @@ -44,9 +46,9 @@ await _verenigingsRepository.Save(
{
throw new UnexpectedAggregateVersionDuringSyncException();
}
catch (AssociationRegistry.Vereniging.Exceptions.VerenigingIsVerwijderd)
catch (VerenigingIsVerwijderd)
{
_logger.LogWarning("Kon de locatie niet adresmatchen wegens verwijderde vereniging met VCode: {VCode}.", teAdresMatchenLocatieMessage.VCode);
_logger.LogWarning("Kon de locatie niet adresmatchen wegens verwijderde vereniging met VCode: {VCode}.", command.VCode);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace AssociationRegistry.Acties.RegistreerFeitelijkeVereniging;

using Grar;
using Grar.AddressMatch;
using DuplicateVerenigingDetection;
using Events;
using Framework;
using Grar;
using Marten;
using Messages;
using Microsoft.Extensions.Logging;
using ResultNet;
using Vereniging;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace AssociationRegistry.Acties.SyncAdresLocaties;

using Grar.Models;

public record SyncAdresLocatiesCommand(string VCode, List<LocatieWithAdres> LocatiesWithAdres, string IdempotenceKey);
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace AssociationRegistry.Acties.SyncAdresLocaties;

using EventStore;
using Framework;
using Grar;
using Microsoft.Extensions.Logging;
using NodaTime;
using Vereniging;

public class SyncAdresLocatiesCommandHandler(
IVerenigingsRepository repository,
IGrarClient grarClient,
ILogger<SyncAdresLocatiesCommandHandler> logger)
{
public async Task Handle(SyncAdresLocatiesCommand locatiesCommand, CancellationToken cancellationToken)
{
logger.LogInformation($"Handle {nameof(SyncAdresLocatiesCommandHandler)}");

try
{
var vereniging = await repository.Load<VerenigingOfAnyKind>(VCode.Hydrate(locatiesCommand.VCode), allowDubbeleVereniging: true);

await vereniging.SyncAdresLocaties(locatiesCommand.LocatiesWithAdres, locatiesCommand.IdempotenceKey, grarClient);

await repository.Save(
vereniging,
new CommandMetadata(EventStore.DigitaalVlaanderenOvoNumber,
SystemClock.Instance.GetCurrentInstant(),
Guid.NewGuid()),
cancellationToken);
}
catch (Exception ex)
{
logger.LogError(ex, message: "Fout bij het synchroniseren van vereniging {VCode}", locatiesCommand.VCode);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace AssociationRegistry.Acties.VoegLocatieToe;

using AssociationRegistry.Grar;
using AssociationRegistry.Grar.AddressMatch;
using Events;
using Framework;
using Grar;
using Marten;
using Messages;
using Vereniging;
using Wolverine.Marten;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace AssociationRegistry.Acties.WijzigLocatie;

using AssociationRegistry.Grar;
using AssociationRegistry.Grar.AddressMatch;
using Framework;
using Grar;
using Marten;
using Messages;
using Vereniging;
using Wolverine.Marten;

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace AssociationRegistry.Messages;

using Acties.AanvaardDubbel;
using AssociationRegistry.Vereniging;

public record AanvaardDubbeleVerenigingMessage(string VCode, string VCodeDubbeleVereniging)
{
public AanvaardDubbeleVerenigingCommand ToCommand()
=> new(AssociationRegistry.Vereniging.VCode.Create(VCode), AssociationRegistry.Vereniging.VCode.Create(VCodeDubbeleVereniging));
=> new(Vereniging.VCode.Create(VCode), Vereniging.VCode.Create(VCodeDubbeleVereniging));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace AssociationRegistry.Messages;

using Acties.ProbeerAdresTeMatchen;

public record TeAdresMatchenLocatieMessage(string VCode, int LocatieId)
{
public ProbeerAdresTeMatchenCommand ToCommand()
=> new(VCode, LocatieId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace AssociationRegistry.Messages;

using Acties.SyncAdresLocaties;
using Grar.Models;

public record TeSynchroniserenLocatieAdresMessage(string VCode, List<LocatieWithAdres> LocatiesWithAdres, string IdempotenceKey)
{
public SyncAdresLocatiesCommand ToCommand()
=> new(VCode, LocatiesWithAdres, IdempotenceKey);
}
2 changes: 1 addition & 1 deletion src/AssociationRegistry/Vereniging/Vereniging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public void MarkeerAlsDubbelVan(VCode isDubbelVan)
{
Throw<VerenigingKanGeenDubbelWordenVanZichzelf>.If(isDubbelVan.Equals(VCode));

Throw<AuthentiekeVerenigingKanNietAlsDubbelGemarkeerdWorden>.If(State.CorresponderendeVCodes.Any());
Throw<AuthentiekeVerenigingKanNietAlsDubbelGemarkeerdWorden>.If(State.IsAuthentiekeVereniging);

AddEvent(VerenigingWerdGemarkeerdAlsDubbelVan.With(VCode, isDubbelVan));
}
Expand Down
1 change: 1 addition & 0 deletions src/AssociationRegistry/Vereniging/VerenigingState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
public List<string> HandledIdempotenceKeys { get; set; } = new();
public bool IsVerwijderd { get; set; }
public bool IsDubbel => VerenigingStatus == VerenigingStatus.Dubbel;
public bool IsAuthentiekeVereniging => CorresponderendeVCodes.Length != 0;
public string[] CorresponderendeVCodes { get; set; } = [];
public VerenigingStatus VerenigingStatus { get; set; }

Check warning on line 48 in src/AssociationRegistry/Vereniging/VerenigingState.cs

View workflow job for this annotation

GitHub Actions / Run Tests (test/AssociationRegistry.Test)

Non-nullable property 'VerenigingStatus' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 48 in src/AssociationRegistry/Vereniging/VerenigingState.cs

View workflow job for this annotation

GitHub Actions / Run Tests (test/AssociationRegistry.Test.Public.Api)

Non-nullable property 'VerenigingStatus' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public VerenigingStatus VorigeVerenigingStatus { get; set; }

public long Version { get; set; }
Expand Down
Loading
Loading