diff --git a/.localstack/init/ready.d/01_sqs-init.redrive.json b/.localstack/init/ready.d/01_sqs-init.redrive.json index 6d6cfa79b..067ee0eab 100755 --- a/.localstack/init/ready.d/01_sqs-init.redrive.json +++ b/.localstack/init/ready.d/01_sqs-init.redrive.json @@ -1,5 +1,3 @@ { - "ContentBasedDeduplication": "true", - "DeduplicationScope": "messageGroup", "RedrivePolicy": "{\"maxReceiveCount\": \"3\", \"deadLetterTargetArn\": \"arn:aws:sqs:eu-west-1:000000000000:verenigingsregister-addresssmatch-dlq\"}" } diff --git a/.localstack/init/ready.d/02_sqs-init.redrive.json b/.localstack/init/ready.d/02_sqs-init.redrive.json index c1e8a9d7f..4944931fb 100755 --- a/.localstack/init/ready.d/02_sqs-init.redrive.json +++ b/.localstack/init/ready.d/02_sqs-init.redrive.json @@ -1,5 +1,3 @@ { - "ContentBasedDeduplication": "true", - "DeduplicationScope": "messageGroup", "RedrivePolicy": "{\"maxReceiveCount\": \"3\", \"deadLetterTargetArn\": \"arn:aws:sqs:eu-west-1:000000000000:verenigingsregister-grarsync-dlq\"}" } diff --git a/paket.lock b/paket.lock index d435edec7..8d261b206 100644 --- a/paket.lock +++ b/paket.lock @@ -171,7 +171,7 @@ NUGET Autofac.Extensions.DependencyInjection (>= 9.0) Be.Vlaanderen.Basisregisters.EventHandling (5.0) Be.Vlaanderen.Basisregisters.Generators.Guid.Deterministic (4.0) - Be.Vlaanderen.Basisregisters.GrAr.Contracts (21.7) + Be.Vlaanderen.Basisregisters.GrAr.Contracts (21.15) Be.Vlaanderen.Basisregisters.Middleware.AddProblemJsonHeader (3.0) Be.Vlaanderen.Basisregisters.ProblemDetails (9.0) System.Reflection.Metadata (>= 8.0) diff --git a/src/AssociationRegistry.Admin.Api/AssociationRegistry.Admin.Api.csproj b/src/AssociationRegistry.Admin.Api/AssociationRegistry.Admin.Api.csproj index 191818737..c891a455c 100755 --- a/src/AssociationRegistry.Admin.Api/AssociationRegistry.Admin.Api.csproj +++ b/src/AssociationRegistry.Admin.Api/AssociationRegistry.Admin.Api.csproj @@ -65,6 +65,7 @@ + diff --git a/src/AssociationRegistry.Admin.Api/GrarConsumer/Finders/LocatieFinder.cs b/src/AssociationRegistry.Admin.Api/GrarConsumer/Finders/LocatieFinder.cs new file mode 100644 index 000000000..38c6672fc --- /dev/null +++ b/src/AssociationRegistry.Admin.Api/GrarConsumer/Finders/LocatieFinder.cs @@ -0,0 +1,52 @@ +namespace AssociationRegistry.Admin.Api.GrarConsumer.Finders; + +using Grar.GrarUpdates.LocatieFinder; +using Schema.Detail; +using Marten; + +public class LocatieFinder : ILocatieFinder +{ + private readonly IDocumentStore _documentStore; + + public LocatieFinder(IDocumentStore documentStore) + { + _documentStore = documentStore; + } + + public async Task FindLocaties(params int[] adresIds) + { + return await FindLocaties( + adresIds + .Select(x => x.ToString()) + .ToArray()); + } + + public async Task FindLocaties(params string[] adresIds) + { + var locatieIdsGroupedByVCode = + GroupByVCode( + await FindLocatieLookupDocuments(adresIds) + ); + + return LocatiesPerVCodeCollection.FromLocatiesPerVCode(locatieIdsGroupedByVCode); + } + + public async Task> FindLocatieLookupDocuments(string[] adresIds) + { + await using var session = _documentStore.LightweightSession(); + + return session.Query() + .Where(x => adresIds.Contains(x.AdresId)) + .Select(x => new LocatieLookupData(x.LocatieId, x.AdresId, x.VCode)); + } + + private static Dictionary GroupByVCode(IEnumerable locaties) + { + return locaties + .GroupBy(x => x.VCode) + .ToDictionary(grouping => grouping.Key, + documents => documents.Select(x => x) + .ToArray()); + } +} + diff --git a/src/AssociationRegistry.Admin.Api/GrarConsumer/Finders/LocatieMetVCode.cs b/src/AssociationRegistry.Admin.Api/GrarConsumer/Finders/LocatieMetVCode.cs new file mode 100644 index 000000000..9de75bde0 --- /dev/null +++ b/src/AssociationRegistry.Admin.Api/GrarConsumer/Finders/LocatieMetVCode.cs @@ -0,0 +1,3 @@ +namespace AssociationRegistry.Admin.Api.GrarConsumer.Finders; + +public record LocatieMetVCode(string VCode, int LocatieId); diff --git a/src/AssociationRegistry.Admin.Api/GrarSync/AddressKafkaConfiguration.cs b/src/AssociationRegistry.Admin.Api/GrarConsumer/Kafka/AddressKafkaConfiguration.cs similarity index 94% rename from src/AssociationRegistry.Admin.Api/GrarSync/AddressKafkaConfiguration.cs rename to src/AssociationRegistry.Admin.Api/GrarConsumer/Kafka/AddressKafkaConfiguration.cs index f2143eb15..12a012c05 100644 --- a/src/AssociationRegistry.Admin.Api/GrarSync/AddressKafkaConfiguration.cs +++ b/src/AssociationRegistry.Admin.Api/GrarConsumer/Kafka/AddressKafkaConfiguration.cs @@ -1,7 +1,7 @@ -namespace AssociationRegistry.Admin.Api.GrarSync; +namespace AssociationRegistry.Admin.Api.GrarConsumer.Kafka; -using Confluent.Kafka; using Hosts.Configuration; +using Confluent.Kafka; public class AddressKafkaConfiguration : ConsumerConfig { diff --git a/src/AssociationRegistry.Admin.Api/GrarSync/AddressKafkaConsumer.cs b/src/AssociationRegistry.Admin.Api/GrarConsumer/Kafka/AddressKafkaConsumer.cs similarity index 75% rename from src/AssociationRegistry.Admin.Api/GrarSync/AddressKafkaConsumer.cs rename to src/AssociationRegistry.Admin.Api/GrarConsumer/Kafka/AddressKafkaConsumer.cs index 96ca97fbe..e0844c7eb 100644 --- a/src/AssociationRegistry.Admin.Api/GrarSync/AddressKafkaConsumer.cs +++ b/src/AssociationRegistry.Admin.Api/GrarConsumer/Kafka/AddressKafkaConsumer.cs @@ -1,36 +1,39 @@ -namespace AssociationRegistry.Admin.Api.GrarSync; +namespace AssociationRegistry.Admin.Api.GrarConsumer.Kafka; +using Infrastructure.AWS; +using Infrastructure.Extensions; +using Notifications.Messages; using AssociationRegistry.Notifications; using Be.Vlaanderen.Basisregisters.GrAr.Contracts.AddressRegistry; using Confluent.Kafka; +using Grar.GrarUpdates.Fusies; +using Grar.GrarUpdates.Hernummering; using IdentityModel; -using Infrastructure.AWS; -using Infrastructure.Extensions; using Marten; -using Notifications.Messages; using Polly; +using StraatHernummering; using System.Text; public class AddressKafkaConsumer : BackgroundService { private readonly AddressKafkaConfiguration _configuration; - private readonly TeHeradresserenLocatiesMapper _teHeradresserenLocatiesMapper; - private readonly SqsClientWrapper _sqsClientWrapper; + private readonly IFusieEventProcessor _fusieEventProcessor; + private readonly ITeHernummerenStraatEventProcessor _teHernummerenStraatEventProcessor; private readonly IDocumentStore _store; private readonly INotifier _notifier; private readonly ILogger _logger; public AddressKafkaConsumer( AddressKafkaConfiguration configuration, - TeHeradresserenLocatiesMapper teHeradresserenLocatiesMapper, - SqsClientWrapper sqsClientWrapper, + IFusieEventProcessor fusieEventProcessor, + ITeHernummerenStraatEventProcessor teHernummerenStraatEventProcessor, IDocumentStore store, INotifier notifier, ILogger logger) { _configuration = configuration; - _teHeradresserenLocatiesMapper = teHeradresserenLocatiesMapper; - _sqsClientWrapper = sqsClientWrapper; + _fusieEventProcessor = fusieEventProcessor; + _teHernummerenStraatEventProcessor = teHernummerenStraatEventProcessor; _store = store; _notifier = notifier; _logger = logger; @@ -80,17 +83,25 @@ private async Task Consume(CancellationToken stoppingToken) switch (message) { + case AddressWasRetiredBecauseOfMunicipalityMerger addressWasRetiredBecauseOfMunicipalityMerger: + await _fusieEventProcessor.Process( + addressWasRetiredBecauseOfMunicipalityMerger.AddressPersistentLocalId, + addressWasRetiredBecauseOfMunicipalityMerger.NewAddressPersistentLocalId, + idempotenceKey); + break; + + case AddressWasRejectedBecauseOfMunicipalityMerger addressWasRejectedBecauseOfMunicipalityMerger: + await _fusieEventProcessor.Process( + addressWasRejectedBecauseOfMunicipalityMerger.AddressPersistentLocalId, + addressWasRejectedBecauseOfMunicipalityMerger.NewAddressPersistentLocalId, + idempotenceKey); + break; + case StreetNameWasReaddressed streetNameWasReaddressed: _logger.LogInformation($"{nameof(StreetNameWasReaddressed)} found! Offset: {result.Offset}"); - var teHeradresserenLocatiesMessages = - await _teHeradresserenLocatiesMapper.ForAddress(streetNameWasReaddressed.ReaddressedHouseNumbers, - idempotenceKey); - - foreach (var teHeradresserenLocatiesMessage in teHeradresserenLocatiesMessages) - { - await _sqsClientWrapper.QueueReaddressMessage(teHeradresserenLocatiesMessage); - } + await _teHernummerenStraatEventProcessor.Process( + TeHernummerenStraatFactory.From(streetNameWasReaddressed), idempotenceKey); break; diff --git a/src/AssociationRegistry.Admin.Api/GrarSync/AddressKafkaConsumerOffset.cs b/src/AssociationRegistry.Admin.Api/GrarConsumer/Kafka/AddressKafkaConsumerOffset.cs similarity index 81% rename from src/AssociationRegistry.Admin.Api/GrarSync/AddressKafkaConsumerOffset.cs rename to src/AssociationRegistry.Admin.Api/GrarConsumer/Kafka/AddressKafkaConsumerOffset.cs index 7ab9fe4b6..894275b15 100644 --- a/src/AssociationRegistry.Admin.Api/GrarSync/AddressKafkaConsumerOffset.cs +++ b/src/AssociationRegistry.Admin.Api/GrarConsumer/Kafka/AddressKafkaConsumerOffset.cs @@ -1,4 +1,4 @@ -namespace AssociationRegistry.Admin.Api.GrarSync; +namespace AssociationRegistry.Admin.Api.GrarConsumer.Kafka; using Marten.Schema; diff --git a/src/AssociationRegistry.Admin.Api/GrarConsumer/Kafka/StraatHernummering/TeHernummerenAdres.cs b/src/AssociationRegistry.Admin.Api/GrarConsumer/Kafka/StraatHernummering/TeHernummerenAdres.cs new file mode 100644 index 000000000..486c19506 --- /dev/null +++ b/src/AssociationRegistry.Admin.Api/GrarConsumer/Kafka/StraatHernummering/TeHernummerenAdres.cs @@ -0,0 +1,26 @@ +namespace AssociationRegistry.Admin.Api.GrarConsumer.Kafka.StraatHernummering; + +using Be.Vlaanderen.Basisregisters.GrAr.Contracts.AddressRegistry; +using Grar.GrarUpdates.Hernummering; + +public static class TeHernummerenStraatFactory +{ + public static TeHernummerenStraat From(StreetNameWasReaddressed streetNameWasReaddressed) + { + var result = new List(); + + foreach (var readdressed in streetNameWasReaddressed.ReaddressedHouseNumbers) + { + result.AddRange(readdressed.ReaddressedBoxNumbers.Select(From)); + result.Add(From(readdressed.ReaddressedHouseNumber)); + } + + return new(result); + } + + private static TeHernummerenAdres From(ReaddressedAddressData readdressedAddressData) + => new( + readdressedAddressData.SourceAddressPersistentLocalId, + readdressedAddressData.DestinationAddressPersistentLocalId); +} + diff --git a/src/AssociationRegistry.Admin.Api/GrarSync/AdresMigratieData.cs b/src/AssociationRegistry.Admin.Api/GrarSync/AdresMigratieData.cs deleted file mode 100644 index 7660edd49..000000000 --- a/src/AssociationRegistry.Admin.Api/GrarSync/AdresMigratieData.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace AssociationRegistry.Admin.Api.GrarSync; - -public class AdresMigratieData -{ - public string VanAdresId { get; set; } - public string NaarAdresId { get; set; } -} diff --git a/src/AssociationRegistry.Admin.Api/GrarSync/ILocatieFinder.cs b/src/AssociationRegistry.Admin.Api/GrarSync/ILocatieFinder.cs deleted file mode 100644 index 4bfe29440..000000000 --- a/src/AssociationRegistry.Admin.Api/GrarSync/ILocatieFinder.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace AssociationRegistry.Admin.Api.GrarSync; - -using Schema.Detail; - -public interface ILocatieFinder -{ - Task> FindLocaties(string[] adresIds); -} diff --git a/src/AssociationRegistry.Admin.Api/GrarSync/LocatieFinder.cs b/src/AssociationRegistry.Admin.Api/GrarSync/LocatieFinder.cs deleted file mode 100644 index 79c8ad335..000000000 --- a/src/AssociationRegistry.Admin.Api/GrarSync/LocatieFinder.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace AssociationRegistry.Admin.Api.GrarSync; - -using Marten; -using Schema.Detail; - -public class LocatieFinder : ILocatieFinder -{ - private readonly IDocumentStore _documentStore; - - public LocatieFinder(IDocumentStore documentStore) - { - _documentStore = documentStore; - } - - public async Task> FindLocaties(string[] adresIds) - { - await using var session = _documentStore.LightweightSession(); - - return session.Query().Where(x => adresIds.Contains(x.AdresId)); - } -} diff --git a/src/AssociationRegistry.Admin.Api/GrarSync/TeHeradresserenLocatiesMapper.cs b/src/AssociationRegistry.Admin.Api/GrarSync/TeHeradresserenLocatiesMapper.cs deleted file mode 100644 index 39f3821ea..000000000 --- a/src/AssociationRegistry.Admin.Api/GrarSync/TeHeradresserenLocatiesMapper.cs +++ /dev/null @@ -1,52 +0,0 @@ -namespace AssociationRegistry.Admin.Api.GrarSync; - -using Be.Vlaanderen.Basisregisters.GrAr.Contracts.AddressRegistry; -using Grar.HeradresseerLocaties; -using Grar.Models; - -public class TeHeradresserenLocatiesMapper -{ - private readonly ILocatieFinder _locatieFinder; - - public TeHeradresserenLocatiesMapper(ILocatieFinder locatieFinder) - { - _locatieFinder = locatieFinder; - } - - public async Task> ForAddress( - IReadOnlyList readdressedHouseNumbers, - string idempotenceKey) - { - var readdressedAddressData = GetReaddressedAddressData(readdressedHouseNumbers); - var sourceAddressIds = readdressedAddressData.Select(s => s.SourceAddressPersistentLocalId.ToString()).ToArray(); - var locations = await _locatieFinder.FindLocaties(sourceAddressIds); - - var grouping = locations.GroupBy(l => l.VCode); - - var result = grouping.Select(g => new TeHeradresserenLocatiesMessage( - g.Key, - g.Select(s => - new LocatieIdWithAdresId(s.LocatieId, - GetDestinationAddressIdFromSourceAddressId( - s.AdresId, readdressedAddressData))).ToList(), - idempotenceKey)); - - return result; - } - - private string GetDestinationAddressIdFromSourceAddressId(string sourceAddressId, IReadOnlyList data) - => data.Single(s => s.SourceAddressPersistentLocalId.ToString() == sourceAddressId).DestinationAddressPersistentLocalId.ToString(); - - private IReadOnlyList GetReaddressedAddressData(IReadOnlyList data) - { - var result = new List(); - - foreach (var readdressed in data) - { - result.AddRange(readdressed.ReaddressedBoxNumbers); - result.Add(readdressed.ReaddressedHouseNumber); - } - - return result; - } -} diff --git a/src/AssociationRegistry.Admin.Api/Infrastructure/AWS/SqsClientWrapper.cs b/src/AssociationRegistry.Admin.Api/Infrastructure/AWS/SqsClientWrapper.cs index 55b246e9b..19f8c2152 100644 --- a/src/AssociationRegistry.Admin.Api/Infrastructure/AWS/SqsClientWrapper.cs +++ b/src/AssociationRegistry.Admin.Api/Infrastructure/AWS/SqsClientWrapper.cs @@ -1,13 +1,17 @@ namespace AssociationRegistry.Admin.Api.Infrastructure.AWS; +using Acties.GrarConsumer.HeradresseerLocaties; using Amazon.SQS; -using Grar.HeradresseerLocaties; +using Framework; +using Grar.GrarUpdates.Fusies.TeHeradresserenLocaties; using Hosts.Configuration; using Hosts.Configuration.ConfigurationBindings; using Kbo; using System.Text.Json; -public class SqsClientWrapper + + +public class SqsClientWrapper : ISqsClientWrapper { private readonly IAmazonSQS _sqsClient; private readonly string _kboSyncQueueUrl; @@ -20,7 +24,12 @@ public SqsClientWrapper(IAmazonSQS sqsClient, AppSettings appSettings, GrarOptio _readdressQueueUrl = grarOptions.Sqs.GrarSyncQueueUrl; } - public async Task QueueReaddressMessage(TeHeradresserenLocatiesMessage message) + public async Task QueueReaddressMessage(HeradresseerLocatiesMessage message) + { + await QueueMessage(message); + } + + public async Task QueueMessage(TMessage message) { await _sqsClient.SendMessageAsync( _readdressQueueUrl, @@ -29,9 +38,6 @@ await _sqsClient.SendMessageAsync( public async Task QueueKboNummerToSynchronise(string kboNummer) { - await _sqsClient.SendMessageAsync( - _kboSyncQueueUrl, - JsonSerializer.Serialize( - new TeSynchroniserenKboNummerMessage(kboNummer))); + await QueueMessage(new TeSynchroniserenKboNummerMessage(kboNummer)); } } diff --git a/src/AssociationRegistry.Admin.Api/Infrastructure/Extensions/MartenExtensions.cs b/src/AssociationRegistry.Admin.Api/Infrastructure/Extensions/MartenExtensions.cs index 14139f9ce..e33c9aa7e 100644 --- a/src/AssociationRegistry.Admin.Api/Infrastructure/Extensions/MartenExtensions.cs +++ b/src/AssociationRegistry.Admin.Api/Infrastructure/Extensions/MartenExtensions.cs @@ -1,7 +1,8 @@ namespace AssociationRegistry.Admin.Api.Infrastructure.Extensions; using Formats; -using GrarSync; +using GrarConsumer; +using GrarConsumer.Kafka; using Hosts.Configuration.ConfigurationBindings; using JasperFx.CodeGeneration; using Json; diff --git a/src/AssociationRegistry.Admin.Api/Infrastructure/Extensions/WolverineExtensions.cs b/src/AssociationRegistry.Admin.Api/Infrastructure/Extensions/WolverineExtensions.cs index df7d0bb49..9cad3b73f 100644 --- a/src/AssociationRegistry.Admin.Api/Infrastructure/Extensions/WolverineExtensions.cs +++ b/src/AssociationRegistry.Admin.Api/Infrastructure/Extensions/WolverineExtensions.cs @@ -1,9 +1,13 @@ namespace AssociationRegistry.Admin.Api.Infrastructure.Extensions; +using Acties.GrarConsumer; +using Acties.GrarConsumer.HeradresseerLocaties; +using Acties.GrarConsumer.OntkoppelAdres; using Amazon.Runtime; +using Amazon.SQS.Model; using EventStore; using Grar.AddressMatch; -using Grar.HeradresseerLocaties; +using Grar.GrarUpdates.Fusies.TeHeradresserenLocaties; using Hosts.Configuration; using JasperFx.CodeGeneration; using Serilog; @@ -11,6 +15,8 @@ using Wolverine; using Wolverine.AmazonSqs; using Wolverine.ErrorHandling; +using Wolverine.Runtime.Routing; +using Wolverine.Runtime.Serialization; public static class WolverineExtensions { @@ -25,6 +31,13 @@ public static void AddWolverine(this WebApplicationBuilder builder) options.Discovery.IncludeAssembly(typeof(Vereniging).Assembly); options.Discovery.IncludeType(); options.Discovery.IncludeType(); + options.Discovery.IncludeType(); + options.Discovery.IncludeType(); + options.Discovery.IncludeType(); + options.Discovery.IncludeType(); + options.Discovery.IncludeType(); + options.Discovery.IncludeType(); + options.OnException().RetryWithCooldown( TimeSpan.FromSeconds(1), @@ -101,13 +114,41 @@ private static void ConfigureGrarSyncListener( sqsDeadLetterQueueName ); - options.ListenToSqsQueue(sqsQueueName, configure: configure => + options.ListenToSqsQueue(sqsQueueName, configure: configure => { configure.MaxNumberOfMessages = 1; configure.DeadLetterQueueName = sqsDeadLetterQueueName; + configure.RegisterSerializer(new MySerializer()); }) .ConfigureDeadLetterQueue(sqsDeadLetterQueueName) - .ReceiveRawJsonMessage(typeof(TeHeradresserenLocatiesMessage)) + .ReceiveRawJsonMessage(typeof(OverkoepelendeGrarConsumerMessage)) .MaximumParallelMessages(1); } } + +internal class MySerializer : IntrinsicSerializer +{ + public byte[] Write(Envelope envelope) + { + return base.Write(envelope); + } + + public object ReadFromData(Type messageType, Envelope envelope) + { + return base.ReadFromData(messageType, envelope); + } + + public object ReadFromData(byte[] data) + { + return base.ReadFromData(data); + + } + + public byte[] WriteMessage(object message) + { + return base.WriteMessage(message); + } + + public string ContentType { get; } +} + diff --git a/src/AssociationRegistry.Admin.Api/Program.cs b/src/AssociationRegistry.Admin.Api/Program.cs index 1b6c2af06..97980fea8 100755 --- a/src/AssociationRegistry.Admin.Api/Program.cs +++ b/src/AssociationRegistry.Admin.Api/Program.cs @@ -23,7 +23,15 @@ namespace AssociationRegistry.Admin.Api; using Framework; using Grar; using Grar.AddressMatch; -using GrarSync; +using Grar.GrarUpdates; +using Grar.GrarUpdates.Fusies; +using Grar.GrarUpdates.Fusies.TeHeradresserenLocaties; +using Grar.GrarUpdates.Fusies.TeOntkoppelenLocaties; +using Grar.GrarUpdates.Hernummering; +using Grar.GrarUpdates.LocatieFinder; +using GrarConsumer; +using GrarConsumer.Finders; +using GrarConsumer.Kafka; using Hosts; using Hosts.Configuration; using Hosts.Configuration.ConfigurationBindings; @@ -385,6 +393,7 @@ private static void ConfigureServices(WebApplicationBuilder builder) .AddScoped() .AddScoped() .AddScoped() + .AddTransient() .AddTransient() .AddTransient() .AddTransient() @@ -394,6 +403,10 @@ private static void ConfigureServices(WebApplicationBuilder builder) .AddTransient() .AddTransient() .AddTransient() + .AddTransient() + .AddTransient() + .AddTransient() + .AddTransient() .AddMarten(builder.Configuration, postgreSqlOptionsSection, builder.Environment.IsDevelopment()) .AddElasticSearch(elasticSearchOptionsSection) .AddHttpContextAccessor() diff --git a/src/AssociationRegistry/Acties/GrarConsumer/HeradresseerLocaties/HeradresseerLocatiesMessage.cs b/src/AssociationRegistry/Acties/GrarConsumer/HeradresseerLocaties/HeradresseerLocatiesMessage.cs new file mode 100644 index 000000000..9fb5011b4 --- /dev/null +++ b/src/AssociationRegistry/Acties/GrarConsumer/HeradresseerLocaties/HeradresseerLocatiesMessage.cs @@ -0,0 +1,5 @@ +namespace AssociationRegistry.Acties.GrarConsumer.HeradresseerLocaties; + +using Grar.GrarUpdates.Hernummering; + +public record HeradresseerLocatiesMessage(string VCode, List TeHeradresserenLocaties, string idempotencyKey); diff --git a/src/AssociationRegistry/Acties/GrarConsumer/HeradresseerLocaties/HeradresseerLocatiesMessageHandler.cs b/src/AssociationRegistry/Acties/GrarConsumer/HeradresseerLocaties/HeradresseerLocatiesMessageHandler.cs new file mode 100644 index 000000000..8ff37bcb0 --- /dev/null +++ b/src/AssociationRegistry/Acties/GrarConsumer/HeradresseerLocaties/HeradresseerLocatiesMessageHandler.cs @@ -0,0 +1,67 @@ +namespace AssociationRegistry.Acties.GrarConsumer.HeradresseerLocaties; + +using AssociationRegistry.EventStore; +using AssociationRegistry.Framework; +using AssociationRegistry.Grar; +using AssociationRegistry.Grar.GrarUpdates.Hernummering; +using AssociationRegistry.Grar.Models; +using AssociationRegistry.Vereniging; +using Newtonsoft.Json; +using NodaTime; +using Wolverine; + +public class StringHandler +{ + private readonly IVerenigingsRepository _repository; + private readonly IGrarClient _client; + + public StringHandler(IVerenigingsRepository repository, IGrarClient client) + { + _repository = repository; + _client = client; + } + + public async Task Handle(HeradresseerLocatiesMessage message, Envelope envelope, CancellationToken cancellationToken) + { + var asJson = JsonConvert.SerializeObject(message); + var back1 = JsonConvert.DeserializeObject(asJson); + } +} + +public class HeradresseerLocatiesMessageHandler +{ + private readonly IVerenigingsRepository _repository; + private readonly IGrarClient _client; + + public HeradresseerLocatiesMessageHandler(IVerenigingsRepository repository, IGrarClient client) + { + _repository = repository; + _client = client; + } + + public async Task Handle(HeradresseerLocatiesMessage doorFusieMessage, CancellationToken cancellationToken) + { + var vereniging = await _repository.Load(VCode.Hydrate(doorFusieMessage.VCode)); + + var locatiesWithAddresses = await FetchAddressesForLocaties(doorFusieMessage.TeHeradresserenLocaties, cancellationToken); + + await vereniging.HeradresseerLocaties(locatiesWithAddresses, doorFusieMessage.idempotencyKey, _client); + + await _repository.Save(vereniging, new CommandMetadata(EventStore.DigitaalVlaanderenOvoNumber, + SystemClock.Instance.GetCurrentInstant(), Guid.NewGuid(), + vereniging.Version), cancellationToken); + } + + private async Task> FetchAddressesForLocaties(List locatiesMetAdres, CancellationToken cancellationToken) + { + var locatiesWithAddresses = new List(); + + foreach (var (locatieId, adresId) in locatiesMetAdres) + { + var adres = await _client.GetAddressById(adresId, cancellationToken); + locatiesWithAddresses.Add(new LocatieWithAdres(locatieId, adres)); + } + + return locatiesWithAddresses; + } +} diff --git a/src/AssociationRegistry/Acties/GrarConsumer/OntkoppelAdres/OntkoppelLocatiesMessage.cs b/src/AssociationRegistry/Acties/GrarConsumer/OntkoppelAdres/OntkoppelLocatiesMessage.cs new file mode 100644 index 000000000..9c3674502 --- /dev/null +++ b/src/AssociationRegistry/Acties/GrarConsumer/OntkoppelAdres/OntkoppelLocatiesMessage.cs @@ -0,0 +1,3 @@ +namespace AssociationRegistry.Acties.GrarConsumer.OntkoppelAdres; + +public record OntkoppelLocatiesMessage (string VCode, int[] TeOntkoppelenLocatieIds); diff --git a/src/AssociationRegistry/Acties/GrarConsumer/OntkoppelAdres/OntkoppelLocatiesMessageHandler.cs b/src/AssociationRegistry/Acties/GrarConsumer/OntkoppelAdres/OntkoppelLocatiesMessageHandler.cs new file mode 100644 index 000000000..ad73f33e3 --- /dev/null +++ b/src/AssociationRegistry/Acties/GrarConsumer/OntkoppelAdres/OntkoppelLocatiesMessageHandler.cs @@ -0,0 +1,30 @@ +namespace AssociationRegistry.Acties.GrarConsumer.OntkoppelAdres; + +using AssociationRegistry.EventStore; +using AssociationRegistry.Framework; +using AssociationRegistry.Vereniging; +using NodaTime; + +public class OntkoppelLocatiesMessageHandler +{ + private readonly IVerenigingsRepository _repository; + + public OntkoppelLocatiesMessageHandler(IVerenigingsRepository repository) + { + _repository = repository; + } + + public async Task Handle(OntkoppelLocatiesMessage message, CancellationToken cancellationToken) + { + var vereniging = await _repository.Load(VCode.Hydrate(message.VCode)); + + foreach (var teOntkoppelenLocatieId in message.TeOntkoppelenLocatieIds) + { + vereniging.OntkoppelLocatie(teOntkoppelenLocatieId); + } + + await _repository.Save(vereniging, new CommandMetadata(EventStore.DigitaalVlaanderenOvoNumber, + SystemClock.Instance.GetCurrentInstant(), Guid.NewGuid(), + vereniging.Version), cancellationToken); + } +} diff --git a/src/AssociationRegistry/Acties/GrarConsumer/OverkoepelendeGrarConsumerMessage.cs b/src/AssociationRegistry/Acties/GrarConsumer/OverkoepelendeGrarConsumerMessage.cs new file mode 100644 index 000000000..9ea0240cf --- /dev/null +++ b/src/AssociationRegistry/Acties/GrarConsumer/OverkoepelendeGrarConsumerMessage.cs @@ -0,0 +1,10 @@ +namespace AssociationRegistry.Acties.GrarConsumer; + +using HeradresseerLocaties; +using OntkoppelAdres; + +public record OverkoepelendeGrarConsumerMessage +{ + public HeradresseerLocatiesMessage? HeradresseerLocatiesMessage { get; init; } + public OntkoppelLocatiesMessage? OntkoppelLocatiesMessage { get; init; } +} diff --git a/src/AssociationRegistry/Acties/GrarConsumer/OverkoepelendeGrarConsumerMessageHandler.cs b/src/AssociationRegistry/Acties/GrarConsumer/OverkoepelendeGrarConsumerMessageHandler.cs new file mode 100644 index 000000000..ff665110f --- /dev/null +++ b/src/AssociationRegistry/Acties/GrarConsumer/OverkoepelendeGrarConsumerMessageHandler.cs @@ -0,0 +1,22 @@ +namespace AssociationRegistry.Acties.GrarConsumer; + +using Wolverine; + +public class OverkoepelendeGrarConsumerMessageHandler +{ + private readonly IMessageBus _bus; + + public OverkoepelendeGrarConsumerMessageHandler(IMessageBus bus) + { + _bus = bus; + } + + public async Task Handle(OverkoepelendeGrarConsumerMessage message) + { + if (message.HeradresseerLocatiesMessage is not null) + await _bus.InvokeAsync(message.HeradresseerLocatiesMessage, CancellationToken.None); + + if (message.OntkoppelLocatiesMessage is not null) + await _bus.InvokeAsync(message.OntkoppelLocatiesMessage, CancellationToken.None); + } +} diff --git a/src/AssociationRegistry/Acties/RegistreerFeitelijkeVereniging/RegistreerFeitelijkeVerenigingCommandHandler.cs b/src/AssociationRegistry/Acties/RegistreerFeitelijkeVereniging/RegistreerFeitelijkeVerenigingCommandHandler.cs index 9e467c27e..a02462f3c 100644 --- a/src/AssociationRegistry/Acties/RegistreerFeitelijkeVereniging/RegistreerFeitelijkeVerenigingCommandHandler.cs +++ b/src/AssociationRegistry/Acties/RegistreerFeitelijkeVereniging/RegistreerFeitelijkeVerenigingCommandHandler.cs @@ -1,10 +1,10 @@ namespace AssociationRegistry.Acties.RegistreerFeitelijkeVereniging; +using Grar; +using Grar.AddressMatch; using DuplicateVerenigingDetection; using Events; using Framework; -using Grar; -using Grar.AddressMatch; using Marten; using Microsoft.Extensions.Logging; using ResultNet; diff --git a/src/AssociationRegistry/Acties/RegistreerVerenigingUitKbo/RegistreerVerenigingUitKboCommandHandler.cs b/src/AssociationRegistry/Acties/RegistreerVerenigingUitKbo/RegistreerVerenigingUitKboCommandHandler.cs index 58632f1e8..ece4e24d6 100644 --- a/src/AssociationRegistry/Acties/RegistreerVerenigingUitKbo/RegistreerVerenigingUitKboCommandHandler.cs +++ b/src/AssociationRegistry/Acties/RegistreerVerenigingUitKbo/RegistreerVerenigingUitKboCommandHandler.cs @@ -2,17 +2,13 @@ using Be.Vlaanderen.Basisregisters.AggregateSource; using DuplicateVerenigingDetection; -using Events; using Framework; -using Grar.AddressMatch; using Kbo; -using Marten; using Microsoft.Extensions.Logging; using Resources; using ResultNet; using Vereniging; using Vereniging.Exceptions; -using Wolverine.Marten; public class RegistreerVerenigingUitKboCommandHandler { diff --git a/src/AssociationRegistry/Acties/SyncKbo/SyncKboCommand.cs b/src/AssociationRegistry/Acties/SyncKbo/SyncKboCommand.cs index 250b4bd2d..68e55fc46 100644 --- a/src/AssociationRegistry/Acties/SyncKbo/SyncKboCommand.cs +++ b/src/AssociationRegistry/Acties/SyncKbo/SyncKboCommand.cs @@ -1,6 +1,5 @@ namespace AssociationRegistry.Acties.SyncKbo; using Vereniging; -using Kbo; public record SyncKboCommand(KboNummer KboNummer); diff --git a/src/AssociationRegistry/Acties/SyncKbo/SyncKboCommandHandler.cs b/src/AssociationRegistry/Acties/SyncKbo/SyncKboCommandHandler.cs index 2b3ded15e..12a049a9d 100644 --- a/src/AssociationRegistry/Acties/SyncKbo/SyncKboCommandHandler.cs +++ b/src/AssociationRegistry/Acties/SyncKbo/SyncKboCommandHandler.cs @@ -1,10 +1,7 @@ namespace AssociationRegistry.Acties.SyncKbo; -using Events; using Framework; -using Grar.AddressMatch; using Kbo; -using Marten; using Microsoft.Extensions.Logging; using Notifications; using Notifications.Messages; @@ -12,7 +9,6 @@ using ResultNet; using Vereniging; using Vereniging.Exceptions; -using Wolverine.Marten; public class SyncKboCommandHandler { diff --git a/src/AssociationRegistry/Acties/VerenigingMetRechtspersoonlijkheid/WijzigBasisgegevens/WijzigBasisgegevensCommandHandler.cs b/src/AssociationRegistry/Acties/VerenigingMetRechtspersoonlijkheid/WijzigBasisgegevens/WijzigBasisgegevensCommandHandler.cs index 133146d3a..6a50ca555 100644 --- a/src/AssociationRegistry/Acties/VerenigingMetRechtspersoonlijkheid/WijzigBasisgegevens/WijzigBasisgegevensCommandHandler.cs +++ b/src/AssociationRegistry/Acties/VerenigingMetRechtspersoonlijkheid/WijzigBasisgegevens/WijzigBasisgegevensCommandHandler.cs @@ -1,7 +1,6 @@ namespace AssociationRegistry.Acties.VerenigingMetRechtspersoonlijkheid.WijzigBasisgegevens; using Framework; -using Marten; using Vereniging; public class WijzigBasisgegevensCommandHandler diff --git a/src/AssociationRegistry/Acties/VoegLocatieToe/VoegLocatieToeCommandHandler.cs b/src/AssociationRegistry/Acties/VoegLocatieToe/VoegLocatieToeCommandHandler.cs index ae07c82c3..b179d3803 100644 --- a/src/AssociationRegistry/Acties/VoegLocatieToe/VoegLocatieToeCommandHandler.cs +++ b/src/AssociationRegistry/Acties/VoegLocatieToe/VoegLocatieToeCommandHandler.cs @@ -1,10 +1,9 @@ namespace AssociationRegistry.Acties.VoegLocatieToe; +using AssociationRegistry.Grar; +using AssociationRegistry.Grar.AddressMatch; using Events; using Framework; -using Grar; -using Grar.AddressMatch; -using Grar.Exceptions; using Marten; using Vereniging; using Wolverine.Marten; diff --git a/src/AssociationRegistry/Acties/WijzigLidmaatschap/WijzigLidmaatschapCommand.cs b/src/AssociationRegistry/Acties/WijzigLidmaatschap/WijzigLidmaatschapCommand.cs index 7adfa06c4..efdfa46bf 100644 --- a/src/AssociationRegistry/Acties/WijzigLidmaatschap/WijzigLidmaatschapCommand.cs +++ b/src/AssociationRegistry/Acties/WijzigLidmaatschap/WijzigLidmaatschapCommand.cs @@ -1,6 +1,5 @@ namespace AssociationRegistry.Acties.WijzigLidmaatschap; -using Primitives; using Vereniging; public record WijzigLidmaatschapCommand( diff --git a/src/AssociationRegistry/Acties/WijzigLidmaatschap/WijzigLidmaatschapCommandHandler.cs b/src/AssociationRegistry/Acties/WijzigLidmaatschap/WijzigLidmaatschapCommandHandler.cs index 4acfb658e..b877515df 100644 --- a/src/AssociationRegistry/Acties/WijzigLidmaatschap/WijzigLidmaatschapCommandHandler.cs +++ b/src/AssociationRegistry/Acties/WijzigLidmaatschap/WijzigLidmaatschapCommandHandler.cs @@ -2,7 +2,6 @@ namespace AssociationRegistry.Acties.WijzigLidmaatschap; using Framework; using Vereniging; -using Vereniging.Exceptions; public class WijzigLidmaatschapCommandHandler { diff --git a/src/AssociationRegistry/Acties/WijzigLocatie/WijzigLocatieCommandHandler.cs b/src/AssociationRegistry/Acties/WijzigLocatie/WijzigLocatieCommandHandler.cs index d19c08252..96d9459ad 100644 --- a/src/AssociationRegistry/Acties/WijzigLocatie/WijzigLocatieCommandHandler.cs +++ b/src/AssociationRegistry/Acties/WijzigLocatie/WijzigLocatieCommandHandler.cs @@ -1,8 +1,8 @@ namespace AssociationRegistry.Acties.WijzigLocatie; +using AssociationRegistry.Grar; +using AssociationRegistry.Grar.AddressMatch; using Framework; -using Grar; -using Grar.AddressMatch; using Marten; using Vereniging; using Wolverine.Marten; diff --git a/src/AssociationRegistry/Events/AdresDetailUitAdressenregister.cs b/src/AssociationRegistry/Events/AdresDetailUitAdressenregister.cs index ad32f7790..1e2c9e795 100644 --- a/src/AssociationRegistry/Events/AdresDetailUitAdressenregister.cs +++ b/src/AssociationRegistry/Events/AdresDetailUitAdressenregister.cs @@ -1,7 +1,6 @@ namespace AssociationRegistry.Events; using Grar.Models; -using System.Text.RegularExpressions; public record AdresDetailUitAdressenregister { diff --git a/src/AssociationRegistry/Events/AdresMatchUitAdressenregister.cs b/src/AssociationRegistry/Events/AdresMatchUitAdressenregister.cs index f6331b984..500becb7c 100644 --- a/src/AssociationRegistry/Events/AdresMatchUitAdressenregister.cs +++ b/src/AssociationRegistry/Events/AdresMatchUitAdressenregister.cs @@ -2,7 +2,6 @@ using Grar.Models; using Grar.Models.PostalInfo; -using Vereniging; using Gemeentenaam = Vereniging.Gemeentenaam; using Postnaam = Grar.Models.PostalInfo.Postnaam; diff --git a/src/AssociationRegistry/Framework/ISqsClientWrapper.cs b/src/AssociationRegistry/Framework/ISqsClientWrapper.cs new file mode 100644 index 000000000..982593322 --- /dev/null +++ b/src/AssociationRegistry/Framework/ISqsClientWrapper.cs @@ -0,0 +1,10 @@ +namespace AssociationRegistry.Framework; + +using Acties.GrarConsumer.HeradresseerLocaties; + +public interface ISqsClientWrapper +{ + Task QueueReaddressMessage(HeradresseerLocatiesMessage message); + Task QueueMessage(TMessage message); + Task QueueKboNummerToSynchronise(string kboNummer); +} diff --git a/src/AssociationRegistry/Grar/Exceptions/AdressenregisterReturnedClientErrorStatusCode.cs b/src/AssociationRegistry/Grar/Exceptions/AdressenregisterReturnedClientErrorStatusCode.cs index 91ed5f760..edbca77fa 100644 --- a/src/AssociationRegistry/Grar/Exceptions/AdressenregisterReturnedClientErrorStatusCode.cs +++ b/src/AssociationRegistry/Grar/Exceptions/AdressenregisterReturnedClientErrorStatusCode.cs @@ -1,7 +1,6 @@ namespace AssociationRegistry.Grar.Exceptions; using Be.Vlaanderen.Basisregisters.AggregateSource; -using Resources; using System.Net; public class AdressenregisterReturnedClientErrorStatusCode : DomainException diff --git a/src/AssociationRegistry/Grar/GrarUpdates/Fusies/FusieEventProcessor.cs b/src/AssociationRegistry/Grar/GrarUpdates/Fusies/FusieEventProcessor.cs new file mode 100644 index 000000000..80e5ea200 --- /dev/null +++ b/src/AssociationRegistry/Grar/GrarUpdates/Fusies/FusieEventProcessor.cs @@ -0,0 +1,30 @@ +namespace AssociationRegistry.Grar.GrarUpdates.Fusies; + +using TeHeradresserenLocaties; +using TeOntkoppelenLocaties; + +public class FusieEventProcessor : IFusieEventProcessor +{ + private readonly ITeHeradresserenLocatiesProcessor _teHeradresserenLocatiesHandler; + private readonly ITeOntkoppelenLocatiesProcessor _teOntkoppelenLocatiesHandler; + + public FusieEventProcessor( + ITeHeradresserenLocatiesProcessor teHeradresserenLocatiesHandler, + ITeOntkoppelenLocatiesProcessor teOntkoppelenLocatiesHandler) + { + _teHeradresserenLocatiesHandler = teHeradresserenLocatiesHandler; + _teOntkoppelenLocatiesHandler = teOntkoppelenLocatiesHandler; + } + + public async Task Process(int sourceAdresId, int? destinationAdresId, string idempotencyKey) + { + if (!destinationAdresId.HasValue) + await _teOntkoppelenLocatiesHandler.Process(sourceAdresId); + else + await _teHeradresserenLocatiesHandler.Process(sourceAdresId, destinationAdresId.Value, idempotencyKey); + } +} +public interface IFusieEventProcessor +{ + Task Process(int sourceAdresId, int? destinationAdresId, string idempotencyKey); +} diff --git a/src/AssociationRegistry/Grar/GrarUpdates/Fusies/TeHeradresserenLocaties/TeHeradresserenLocatiesProcessor.cs b/src/AssociationRegistry/Grar/GrarUpdates/Fusies/TeHeradresserenLocaties/TeHeradresserenLocatiesProcessor.cs new file mode 100644 index 000000000..0c5f8feb1 --- /dev/null +++ b/src/AssociationRegistry/Grar/GrarUpdates/Fusies/TeHeradresserenLocaties/TeHeradresserenLocatiesProcessor.cs @@ -0,0 +1,38 @@ +namespace AssociationRegistry.Grar.GrarUpdates.Fusies.TeHeradresserenLocaties; + +using Acties.GrarConsumer; +using Framework; +using LocatieFinder; + +public class TeHeradresserenLocatiesProcessor : ITeHeradresserenLocatiesProcessor +{ + private readonly ISqsClientWrapper _sqsClientWrapper; + private readonly ILocatieFinder _locatieFinder; + + public TeHeradresserenLocatiesProcessor(ISqsClientWrapper sqsClientWrapper, ILocatieFinder locatieFinder) + { + _sqsClientWrapper = sqsClientWrapper; + _locatieFinder = locatieFinder; + } + + public async Task Process(int sourceAdresId, int destinationAdresId, string idempotencyKey) + { + var locatiesMetVCodes = await _locatieFinder.FindLocaties(sourceAdresId); + + var messages = locatiesMetVCodes.Map(destinationAdresId, idempotencyKey); + + foreach (var message in messages) + { + await _sqsClientWrapper.QueueMessage( + new OverkoepelendeGrarConsumerMessage + { + HeradresseerLocatiesMessage = message, + }); + } + } +} + +public interface ITeHeradresserenLocatiesProcessor +{ + Task Process(int sourceAdresId, int destinationAdresId, string idempotencyKey); +} diff --git a/src/AssociationRegistry/Grar/GrarUpdates/Fusies/TeOntkoppelenLocaties/TeOntkoppelenLocatiesProcessor.cs b/src/AssociationRegistry/Grar/GrarUpdates/Fusies/TeOntkoppelenLocaties/TeOntkoppelenLocatiesProcessor.cs new file mode 100644 index 000000000..eb64ef24d --- /dev/null +++ b/src/AssociationRegistry/Grar/GrarUpdates/Fusies/TeOntkoppelenLocaties/TeOntkoppelenLocatiesProcessor.cs @@ -0,0 +1,38 @@ +namespace AssociationRegistry.Grar.GrarUpdates.Fusies.TeOntkoppelenLocaties; + +using Acties.GrarConsumer; +using Framework; +using LocatieFinder; + +public class TeOntkoppelenLocatiesProcessor : ITeOntkoppelenLocatiesProcessor +{ + private readonly ISqsClientWrapper _sqsClientWrapper; + private readonly ILocatieFinder _locatieFinder; + + public TeOntkoppelenLocatiesProcessor(ISqsClientWrapper sqsClientWrapper, ILocatieFinder locatieFinder) + { + _sqsClientWrapper = sqsClientWrapper; + _locatieFinder = locatieFinder; + } + + public async Task Process(int sourceAdresId) + { + var locatiesMetVCodes = await _locatieFinder.FindLocaties(sourceAdresId); + + var messages = locatiesMetVCodes.Map(); + + foreach (var message in messages) + { + await _sqsClientWrapper.QueueMessage( + new OverkoepelendeGrarConsumerMessage + { + OntkoppelLocatiesMessage = message, + }); + } + } +} + +public interface ITeOntkoppelenLocatiesProcessor +{ + Task Process(int sourceAdresId); +} diff --git a/src/AssociationRegistry/Grar/GrarUpdates/Hernummering/TeHeradresserenLocatie.cs b/src/AssociationRegistry/Grar/GrarUpdates/Hernummering/TeHeradresserenLocatie.cs new file mode 100644 index 000000000..8b6135d06 --- /dev/null +++ b/src/AssociationRegistry/Grar/GrarUpdates/Hernummering/TeHeradresserenLocatie.cs @@ -0,0 +1,3 @@ +namespace AssociationRegistry.Grar.GrarUpdates.Hernummering; + +public record TeHeradresserenLocatie(int LocatieId, string NaarAdresId); diff --git a/src/AssociationRegistry/Grar/GrarUpdates/Hernummering/TeHeradresserenLocatiesMapper.cs b/src/AssociationRegistry/Grar/GrarUpdates/Hernummering/TeHeradresserenLocatiesMapper.cs new file mode 100644 index 000000000..5d66c6226 --- /dev/null +++ b/src/AssociationRegistry/Grar/GrarUpdates/Hernummering/TeHeradresserenLocatiesMapper.cs @@ -0,0 +1,26 @@ +namespace AssociationRegistry.Grar.GrarUpdates.Hernummering; + +using Acties.GrarConsumer.HeradresseerLocaties; +using AssociationRegistry.Grar.GrarUpdates.LocatieFinder; + +public class TeHeradresserenLocatiesMapper +{ + private readonly ILocatieFinder _locatieFinder; + + public TeHeradresserenLocatiesMapper(ILocatieFinder locatieFinder) + { + _locatieFinder = locatieFinder; + } + + public async Task> ForAddress( + TeHernummerenStraat teHernummerenStraat, + string idempotenceKey) + { + var sourceAddressIds = teHernummerenStraat.Select(s => s.VanAdresId.ToString()).ToArray(); + var locatiesPerVCode = await _locatieFinder.FindLocaties(sourceAddressIds); + + return locatiesPerVCode.Select(x => new HeradresseerLocatiesMessage(x.VCode, x.Locaties.Select(locatie => + new TeHeradresserenLocatie(locatie.LocatieId, + teHernummerenStraat.NaarAdresIdVoor(locatie.AdresId))).ToList(), idempotenceKey)); + } +} diff --git a/src/AssociationRegistry/Grar/GrarUpdates/Hernummering/TeHernummerenAdres.cs b/src/AssociationRegistry/Grar/GrarUpdates/Hernummering/TeHernummerenAdres.cs new file mode 100644 index 000000000..8d72421b4 --- /dev/null +++ b/src/AssociationRegistry/Grar/GrarUpdates/Hernummering/TeHernummerenAdres.cs @@ -0,0 +1,3 @@ +namespace AssociationRegistry.Grar.GrarUpdates.Hernummering; + +public record TeHernummerenAdres(int VanAdresId, int NaarAdresId); diff --git a/src/AssociationRegistry/Grar/GrarUpdates/Hernummering/TeHernummerenStraat.cs b/src/AssociationRegistry/Grar/GrarUpdates/Hernummering/TeHernummerenStraat.cs new file mode 100644 index 000000000..462ef2759 --- /dev/null +++ b/src/AssociationRegistry/Grar/GrarUpdates/Hernummering/TeHernummerenStraat.cs @@ -0,0 +1,13 @@ +namespace AssociationRegistry.Grar.GrarUpdates.Hernummering; + +using System.Collections.ObjectModel; + +public class TeHernummerenStraat : ReadOnlyCollection +{ + public TeHernummerenStraat(IList list) : base(list) + { + } + + public string NaarAdresIdVoor(string vanAdresId) + => this.Single(s => s.VanAdresId.ToString() == vanAdresId).NaarAdresId.ToString(); +} diff --git a/src/AssociationRegistry/Grar/GrarUpdates/Hernummering/TeHernummerenStraatEventProcessor.cs b/src/AssociationRegistry/Grar/GrarUpdates/Hernummering/TeHernummerenStraatEventProcessor.cs new file mode 100644 index 000000000..9682d703a --- /dev/null +++ b/src/AssociationRegistry/Grar/GrarUpdates/Hernummering/TeHernummerenStraatEventProcessor.cs @@ -0,0 +1,39 @@ +namespace AssociationRegistry.Grar.GrarUpdates.Hernummering; + +using Acties.GrarConsumer; +using Framework; + +public class TeHernummerenStraatEventProcessor: ITeHernummerenStraatEventProcessor +{ + private readonly TeHeradresserenLocatiesMapper _teHeradresserenLocatiesMapper; + private readonly ISqsClientWrapper _sqsClientWrapper; + + public TeHernummerenStraatEventProcessor( + TeHeradresserenLocatiesMapper teHeradresserenLocatiesMapper, + ISqsClientWrapper sqsClientWrapper) + { + _teHeradresserenLocatiesMapper = teHeradresserenLocatiesMapper; + _sqsClientWrapper = sqsClientWrapper; + } + + public async Task Process(TeHernummerenStraat teHernummerenStraat, string idempotenceKey) + { + var heradresseerLocatiesMessages = + await _teHeradresserenLocatiesMapper.ForAddress(teHernummerenStraat, + idempotenceKey); + + foreach (var heradresseerLocatiesMessage in heradresseerLocatiesMessages) + { + await _sqsClientWrapper.QueueMessage( + new OverkoepelendeGrarConsumerMessage + { + HeradresseerLocatiesMessage = heradresseerLocatiesMessage, + }); + } + } +} + +public interface ITeHernummerenStraatEventProcessor +{ + Task Process(TeHernummerenStraat teHernummerenStraat, string idempotenceKey); +} diff --git a/src/AssociationRegistry/Grar/GrarUpdates/LocatieFinder/ILocatieFinder.cs b/src/AssociationRegistry/Grar/GrarUpdates/LocatieFinder/ILocatieFinder.cs new file mode 100644 index 000000000..c50b6d10a --- /dev/null +++ b/src/AssociationRegistry/Grar/GrarUpdates/LocatieFinder/ILocatieFinder.cs @@ -0,0 +1,9 @@ +namespace AssociationRegistry.Grar.GrarUpdates.LocatieFinder; + +public interface ILocatieFinder +{ + Task FindLocaties(params int[] adresIds); + Task FindLocaties(params string[] adresIds); + Task> FindLocatieLookupDocuments(string[] adresIds); +} + diff --git a/src/AssociationRegistry/Grar/GrarUpdates/LocatieFinder/LocatieLookupData.cs b/src/AssociationRegistry/Grar/GrarUpdates/LocatieFinder/LocatieLookupData.cs new file mode 100644 index 000000000..cdeb09c7f --- /dev/null +++ b/src/AssociationRegistry/Grar/GrarUpdates/LocatieFinder/LocatieLookupData.cs @@ -0,0 +1,3 @@ +namespace AssociationRegistry.Grar.GrarUpdates.LocatieFinder; + +public record LocatieLookupData(int LocatieId, string AdresId, string VCode); diff --git a/src/AssociationRegistry/Grar/GrarUpdates/LocatieFinder/LocatiesPerVCode.cs b/src/AssociationRegistry/Grar/GrarUpdates/LocatieFinder/LocatiesPerVCode.cs new file mode 100644 index 000000000..8bb24547a --- /dev/null +++ b/src/AssociationRegistry/Grar/GrarUpdates/LocatieFinder/LocatiesPerVCode.cs @@ -0,0 +1,3 @@ +namespace AssociationRegistry.Grar.GrarUpdates.LocatieFinder; + +public record LocatiesPerVCode(string VCode, LocatieLookupData[] Locaties); diff --git a/src/AssociationRegistry/Grar/GrarUpdates/LocatieFinder/LocatiesPerVCodeCollection.cs b/src/AssociationRegistry/Grar/GrarUpdates/LocatieFinder/LocatiesPerVCodeCollection.cs new file mode 100644 index 000000000..f0528f4d2 --- /dev/null +++ b/src/AssociationRegistry/Grar/GrarUpdates/LocatieFinder/LocatiesPerVCodeCollection.cs @@ -0,0 +1,34 @@ +namespace AssociationRegistry.Grar.GrarUpdates.LocatieFinder; + +using Acties.GrarConsumer.HeradresseerLocaties; +using Acties.GrarConsumer.OntkoppelAdres; +using Hernummering; +using System.Collections.ObjectModel; + +public class LocatiesPerVCodeCollection : ReadOnlyCollection +{ + private LocatiesPerVCodeCollection(IEnumerable locatieIdsPerVCodes): base(locatieIdsPerVCodes.ToList()) + { + } + + public static readonly new LocatiesPerVCodeCollection Empty = new([]); + + public static LocatiesPerVCodeCollection FromLocatiesPerVCode(Dictionary locatieLookupDataGroupedByVCode) + => new(locatieLookupDataGroupedByVCode.Select(s => new LocatiesPerVCode(s.Key, locatieLookupDataGroupedByVCode[s.Key]))); + + public IEnumerable Map(int destinationAdresId, string idempotencyKey) + { + return this.Select(x => new HeradresseerLocatiesMessage( + x.VCode, + x.Locaties.Select(locatie => new TeHeradresserenLocatie(locatie.LocatieId, destinationAdresId.ToString())) + .ToList(), + idempotencyKey)); + } + + public IEnumerable Map() + { + return this.Select(x => new OntkoppelLocatiesMessage( + x.VCode, + x.Locaties.Select(x => x.LocatieId).ToArray())); + } +} diff --git a/src/AssociationRegistry/Grar/HeradresseerLocaties/TeHeradresserenLocatiesMessage.cs b/src/AssociationRegistry/Grar/HeradresseerLocaties/TeHeradresserenLocatiesMessage.cs deleted file mode 100644 index ad7147d3b..000000000 --- a/src/AssociationRegistry/Grar/HeradresseerLocaties/TeHeradresserenLocatiesMessage.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace AssociationRegistry.Grar.HeradresseerLocaties; - -using Models; - -public record TeHeradresserenLocatiesMessage(string VCode, List LocatiesMetAdres, string idempotencyKey); diff --git a/src/AssociationRegistry/Grar/HeradresseerLocaties/TeHeradresserenLocatiesMessageHandler.cs b/src/AssociationRegistry/Grar/HeradresseerLocaties/TeHeradresserenLocatiesMessageHandler.cs deleted file mode 100644 index d3bb202df..000000000 --- a/src/AssociationRegistry/Grar/HeradresseerLocaties/TeHeradresserenLocatiesMessageHandler.cs +++ /dev/null @@ -1,45 +0,0 @@ -namespace AssociationRegistry.Grar.HeradresseerLocaties; - -using EventStore; -using Framework; -using Models; -using NodaTime; -using Vereniging; - -public class TeHeradresserenLocatiesMessageHandler -{ - private readonly IVerenigingsRepository _repository; - private readonly IGrarClient _client; - - public TeHeradresserenLocatiesMessageHandler(IVerenigingsRepository repository, IGrarClient client) - { - _repository = repository; - _client = client; - } - - public async Task Handle(TeHeradresserenLocatiesMessage message, CancellationToken cancellationToken) - { - var vereniging = await _repository.Load(VCode.Hydrate(message.VCode)); - - var locatiesWithAddresses = await FetchAddressesForLocaties(message.LocatiesMetAdres, cancellationToken); - - await vereniging.HeradresseerLocaties(locatiesWithAddresses, message.idempotencyKey, _client); - - await _repository.Save(vereniging, new CommandMetadata(EventStore.DigitaalVlaanderenOvoNumber, - SystemClock.Instance.GetCurrentInstant(), Guid.NewGuid(), - vereniging.Version), cancellationToken); - } - - private async Task> FetchAddressesForLocaties(List locatiesMetAdres, CancellationToken cancellationToken) - { - var locatiesWithAddresses = new List(); - - foreach (var (locatieId, adresId) in locatiesMetAdres) - { - var adres = await _client.GetAddressById(adresId, cancellationToken); - locatiesWithAddresses.Add(new LocatieWithAdres(locatieId, adres)); - } - - return locatiesWithAddresses; - } -} diff --git a/src/AssociationRegistry/Grar/IGrarClient.cs b/src/AssociationRegistry/Grar/IGrarClient.cs index 814bab167..55fbeaa76 100644 --- a/src/AssociationRegistry/Grar/IGrarClient.cs +++ b/src/AssociationRegistry/Grar/IGrarClient.cs @@ -2,7 +2,6 @@ using Models; using Models.PostalInfo; -using Vereniging; public interface IGrarClient { diff --git a/src/AssociationRegistry/Grar/Models/LocatieWithAdres.cs b/src/AssociationRegistry/Grar/Models/LocatieWithAdres.cs index ff7e1b7fd..24657d0b0 100644 --- a/src/AssociationRegistry/Grar/Models/LocatieWithAdres.cs +++ b/src/AssociationRegistry/Grar/Models/LocatieWithAdres.cs @@ -1,4 +1,3 @@ namespace AssociationRegistry.Grar.Models; public record LocatieWithAdres(int LocatieId, AddressDetailResponse? Adres); -public record LocatieIdWithAdresId(int LocatieId, string AddressId); diff --git a/src/AssociationRegistry/Vereniging/ContactGegevens/Contactgegeven.cs b/src/AssociationRegistry/Vereniging/ContactGegevens/Contactgegeven.cs index 2a74c518a..7066ec7fb 100644 --- a/src/AssociationRegistry/Vereniging/ContactGegevens/Contactgegeven.cs +++ b/src/AssociationRegistry/Vereniging/ContactGegevens/Contactgegeven.cs @@ -6,7 +6,6 @@ using Exceptions; using Framework; using SocialMedias; -using System.Text.RegularExpressions; using TelefoonNummers; using Websites; diff --git a/src/AssociationRegistry/Vereniging/Locaties/Locatie.cs b/src/AssociationRegistry/Vereniging/Locaties/Locatie.cs index e46d1fd7d..4f832e0e4 100644 --- a/src/AssociationRegistry/Vereniging/Locaties/Locatie.cs +++ b/src/AssociationRegistry/Vereniging/Locaties/Locatie.cs @@ -4,7 +4,6 @@ using Exceptions; using Framework; using Grar.Models; -using Normalizers; public record Locatie { diff --git a/src/AssociationRegistry/Vereniging/VerenigingOfAnyKind.cs b/src/AssociationRegistry/Vereniging/VerenigingOfAnyKind.cs index 255d60e00..027ead6ef 100644 --- a/src/AssociationRegistry/Vereniging/VerenigingOfAnyKind.cs +++ b/src/AssociationRegistry/Vereniging/VerenigingOfAnyKind.cs @@ -12,7 +12,6 @@ namespace AssociationRegistry.Vereniging; using SocialMedias; using System.Diagnostics.Contracts; using System.Net; -using System.Numerics; using TelefoonNummers; public class VerenigingOfAnyKind : VerenigingsBase, IHydrate @@ -365,6 +364,23 @@ private IEvent GetAdresMatchExceptionEvent( return @event; } + public void OntkoppelLocatie(int locatieId) + { + if (!State.Locaties.HasKey(locatieId)) + return; + + var locatie = State.Locaties[locatieId]; + + if (locatie.AdresId is null) + return; + + AddEvent(new AdresWerdOntkoppeldVanAdressenregister( + VCode, + locatieId, + Registratiedata.AdresId.With(locatie.AdresId), + Registratiedata.Adres.With(locatie.Adres))); + } + private string GetExceptionMessage(HttpStatusCode statusCode) => statusCode == HttpStatusCode.BadRequest ? GrarClient.BadRequestSuccessStatusCodeMessage diff --git a/test/AssociationRegistry.Test.Admin.Api/Commands/FeitelijkeVereniging/When_WijzigBasisGegevens/RequestValidating/Doelgroep/A_Doelgroep.cs b/test/AssociationRegistry.Test.Admin.Api/Commands/FeitelijkeVereniging/When_WijzigBasisGegevens/RequestValidating/Doelgroep/A_Doelgroep.cs index 29fea1b93..bbf474a6f 100644 --- a/test/AssociationRegistry.Test.Admin.Api/Commands/FeitelijkeVereniging/When_WijzigBasisGegevens/RequestValidating/Doelgroep/A_Doelgroep.cs +++ b/test/AssociationRegistry.Test.Admin.Api/Commands/FeitelijkeVereniging/When_WijzigBasisGegevens/RequestValidating/Doelgroep/A_Doelgroep.cs @@ -1,4 +1,4 @@ -namespace AssociationRegistry.Test.Admin.Api.Commands.FeitelijkeVereniging.When_WijzigBasisGegevens.RequestValidating; +namespace AssociationRegistry.Test.Admin.Api.Commands.FeitelijkeVereniging.When_WijzigBasisGegevens.RequestValidating.Doelgroep; using AssociationRegistry.Admin.Api.Verenigingen.Common; using AssociationRegistry.Admin.Api.Verenigingen.WijzigBasisgegevens.FeitelijkeVereniging.RequestModels; diff --git a/test/AssociationRegistry.Test.Admin.Api/Commands/VerenigingMetRechtspersoonlijkheid/When_WijzigBasisGegevens/RequestValidating/Doelgroep/A_Doelgroep.cs b/test/AssociationRegistry.Test.Admin.Api/Commands/VerenigingMetRechtspersoonlijkheid/When_WijzigBasisGegevens/RequestValidating/Doelgroep/A_Doelgroep.cs index 9522641e4..c9bc2a029 100644 --- a/test/AssociationRegistry.Test.Admin.Api/Commands/VerenigingMetRechtspersoonlijkheid/When_WijzigBasisGegevens/RequestValidating/Doelgroep/A_Doelgroep.cs +++ b/test/AssociationRegistry.Test.Admin.Api/Commands/VerenigingMetRechtspersoonlijkheid/When_WijzigBasisGegevens/RequestValidating/Doelgroep/A_Doelgroep.cs @@ -1,4 +1,4 @@ -namespace AssociationRegistry.Test.Admin.Api.Commands.VerenigingMetRechtspersoonlijkheid.When_WijzigBasisGegevens.RequestValidating; +namespace AssociationRegistry.Test.Admin.Api.Commands.VerenigingMetRechtspersoonlijkheid.When_WijzigBasisGegevens.RequestValidating.Doelgroep; using AssociationRegistry.Admin.Api.Verenigingen.Common; using AssociationRegistry.Admin.Api.Verenigingen.WijzigBasisgegevens.MetRechtspersoonlijkheid.RequestModels; diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/Finders/When_Finding_Locaties/Given_No_Matching_LocatieLookupDocuments.cs b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/Finders/When_Finding_Locaties/Given_No_Matching_LocatieLookupDocuments.cs new file mode 100644 index 000000000..8de3dc4c3 --- /dev/null +++ b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/Finders/When_Finding_Locaties/Given_No_Matching_LocatieLookupDocuments.cs @@ -0,0 +1,129 @@ +namespace AssociationRegistry.Test.Admin.Api.GrarConsumer.Finders.When_Finding_Locaties; + +using AssociationRegistry.Admin.Api.GrarConsumer.Finders; +using AssociationRegistry.Admin.Schema.Detail; +using AutoFixture; +using Common.AutoFixture; +using Common.Framework; +using FluentAssertions; +using Grar.GrarUpdates.LocatieFinder; +using Marten; +using Vereniging; +using Xunit; +using Xunit.Categories; + +public class LocatieLookupFixture : IAsyncLifetime +{ + public Fixture AutoFixture { get; private set; } + public DocumentStore Store { get; private set; } + public IDocumentSession Session { get; private set; } + + public async Task InitializeAsync() + { + AutoFixture = new Fixture().CustomizeAdminApi(); + + Store = await TestDocumentStoreFactory.Create(nameof(LocatieLookupFixture)); + Session = Store.LightweightSession(); + } + + public async Task DisposeAsync() + { + } +} + +[IntegrationTest] +public class Given_LocatieLookupDocuments : IClassFixture +{ + private readonly LocatieLookupFixture _fixture; + + public Given_LocatieLookupDocuments(LocatieLookupFixture fixture) + { + _fixture = fixture; + } + + [Fact] + public async Task With_No_Matching_Documents_Then_Returns_Empty_Collection() + { + var locatieLookupDocument = _fixture.AutoFixture.Create(); + + _fixture.Session.Store(locatieLookupDocument); + await _fixture.Session.SaveChangesAsync(); + + var sut = new LocatieFinder(_fixture.Store); + + var actual = await sut.FindLocaties(_fixture.AutoFixture.Create()); + + actual.Should().BeEmpty(); + } + + [Fact] + public async Task With_One_Matching_Documents_Then_Returns_A_Collection_With_One_Match() + { + var locatieLookupDocument = _fixture.AutoFixture.Create(); + + _fixture.Session.Store(locatieLookupDocument); + await _fixture.Session.SaveChangesAsync(); + + var sut = new LocatieFinder(_fixture.Store); + + var actual = await sut.FindLocaties(locatieLookupDocument.AdresId); + + actual.Should().BeEquivalentTo(LocatiesPerVCodeCollection.FromLocatiesPerVCode(new Dictionary() + { + { locatieLookupDocument.VCode, + [new LocatieLookupData(locatieLookupDocument.LocatieId, locatieLookupDocument.AdresId, locatieLookupDocument.VCode)] + }, + })); + } + + [Fact] + public async Task With_Multiple_Matching_Documents_Then_Returns_A_Collection_With_Multiple_Matches() + { + var vCode1 = _fixture.AutoFixture.Create(); + var vCode2 = _fixture.AutoFixture.Create(); + var adresId1 = _fixture.AutoFixture.Create(); + + LocatieLookupDocument[] locatieLookupData = + [ + _fixture.AutoFixture.Create() with + { + VCode = vCode1, + AdresId = adresId1 + }, + _fixture.AutoFixture.Create() with + { + VCode = vCode2, + AdresId = adresId1 + }, + _fixture.AutoFixture.Create() with + { + VCode = vCode1, + AdresId = adresId1 + }, + ]; + + _fixture.Session.Store(locatieLookupData); + await _fixture.Session.SaveChangesAsync(); + + var sut = new LocatieFinder(_fixture.Store); + + var actual = await sut.FindLocaties(adresId1); + + actual.Should().BeEquivalentTo(LocatiesPerVCodeCollection.FromLocatiesPerVCode(new() + { + { + vCode1, + [ + new LocatieLookupData(locatieLookupData[0].LocatieId, locatieLookupData[0].AdresId, locatieLookupData[0].VCode), + new LocatieLookupData(locatieLookupData[2].LocatieId, locatieLookupData[2].AdresId, locatieLookupData[2].VCode), + ] + }, + { + vCode2, + [ + new LocatieLookupData(locatieLookupData[1].LocatieId, locatieLookupData[1].AdresId, locatieLookupData[1].VCode), + ] + }, + })); + } +} diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/AdresMergerHandler/Given_A_Destination_Adres.cs b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/AdresMergerHandler/Given_A_Destination_Adres.cs new file mode 100644 index 000000000..61fc20239 --- /dev/null +++ b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/AdresMergerHandler/Given_A_Destination_Adres.cs @@ -0,0 +1,30 @@ +namespace AssociationRegistry.Test.Admin.Api.GrarConsumer.FusieEvents.When_Consuming_Merger_Events.AdresMergerHandler; + +using AssociationRegistry.Test.Common.AutoFixture; +using AutoFixture; +using Grar.GrarUpdates.Fusies; +using Grar.GrarUpdates.Fusies.TeHeradresserenLocaties; +using Grar.GrarUpdates.Fusies.TeOntkoppelenLocaties; +using Moq; +using Xunit; + +public class Given_A_Destination_Adres +{ + [Fact] + public async Task Then_It_Calls_TeHeradresserenLocatiesHandler() + { + var teHeradresserenLocatiesHandler = new Mock(); + var teOntkoppelenLocatiesHandler = new Mock(); + + var sut = new FusieEventProcessor(teHeradresserenLocatiesHandler.Object, teOntkoppelenLocatiesHandler.Object); + + var fixture = new Fixture().CustomizeAdminApi(); + var sourceAdresId = fixture.Create(); + var destinationAdresId = fixture.Create(); + var idempotencyKey = fixture.Create(); + await sut.Process(sourceAdresId, destinationAdresId, idempotencyKey); + + teHeradresserenLocatiesHandler.Verify(v => v.Process(sourceAdresId, destinationAdresId, idempotencyKey), Times.Once()); + teOntkoppelenLocatiesHandler.Verify(v => v.Process(It.IsAny()), Times.Never()); + } +} diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/AdresMergerHandler/Given_No_Destination_Adres.cs b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/AdresMergerHandler/Given_No_Destination_Adres.cs new file mode 100644 index 000000000..2a630c9d3 --- /dev/null +++ b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/AdresMergerHandler/Given_No_Destination_Adres.cs @@ -0,0 +1,29 @@ +namespace AssociationRegistry.Test.Admin.Api.GrarConsumer.FusieEvents.When_Consuming_Merger_Events.AdresMergerHandler; + +using AssociationRegistry.Test.Common.AutoFixture; +using AutoFixture; +using Grar.GrarUpdates.Fusies; +using Grar.GrarUpdates.Fusies.TeHeradresserenLocaties; +using Grar.GrarUpdates.Fusies.TeOntkoppelenLocaties; +using Moq; +using Xunit; + +public class Given_No_Destination_Adres +{ + [Fact] + public async Task Then_It_Calls_TeOntkoppelenHandler() + { + var teHeradresserenLocatiesHandler = new Mock(); + var teOntkoppelenLocatiesHandler = new Mock(); + + var sut = new FusieEventProcessor(teHeradresserenLocatiesHandler.Object, teOntkoppelenLocatiesHandler.Object); + + var fixture = new Fixture().CustomizeAdminApi(); + var sourceAdresId = fixture.Create(); + var idempotencyKey = fixture.Create(); + await sut.Process(sourceAdresId, null, idempotencyKey); + + teHeradresserenLocatiesHandler.Verify(v => v.Process(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never()); + teOntkoppelenLocatiesHandler.Verify(v => v.Process(sourceAdresId), Times.Once()); + } +} diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/SetupMockExtension.cs b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/SetupMockExtension.cs new file mode 100644 index 000000000..79e70026b --- /dev/null +++ b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/SetupMockExtension.cs @@ -0,0 +1,21 @@ +namespace AssociationRegistry.Test.Admin.Api.GrarConsumer.FusieEvents.When_Consuming_Merger_Events; + +using Acties.GrarConsumer; +using Acties.GrarConsumer.HeradresseerLocaties; +using Acties.GrarConsumer.OntkoppelAdres; +using AssociationRegistry.Admin.Api.Infrastructure.AWS; +using AssociationRegistry.Framework; +using Grar.GrarUpdates.Fusies.TeHeradresserenLocaties; +using Grar.GrarUpdates.Fusies.TeOntkoppelenLocaties; +using Moq; + +public static class SetupMockExtension +{ + public static void CaptureQueueOverkoepelendeGrarMessage( + this Mock sqsClientWrapper, + Action action) + { + sqsClientWrapper.Setup(v => v.QueueMessage(It.IsAny())) + .Callback(action); + } +} diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/TeHeradresserenLocatiesHandlerTests/Given_No_Locations_Found.cs b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/TeHeradresserenLocatiesHandlerTests/Given_No_Locations_Found.cs new file mode 100644 index 000000000..3762aafd1 --- /dev/null +++ b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/TeHeradresserenLocatiesHandlerTests/Given_No_Locations_Found.cs @@ -0,0 +1,33 @@ +namespace AssociationRegistry.Test.Admin.Api.GrarConsumer.FusieEvents.When_Consuming_Merger_Events.TeHeradresserenLocatiesHandlerTests; + +using Acties.GrarConsumer.HeradresseerLocaties; +using AssociationRegistry.Framework; +using AutoFixture; +using Common.AutoFixture; +using Grar.GrarUpdates.Fusies.TeHeradresserenLocaties; +using Grar.GrarUpdates.LocatieFinder; +using Moq; +using Xunit; + +public class Given_No_Locations_Found +{ + [Fact] + public async Task Then_No_Messages_Are_Sent() + { + var fixture = new Fixture().CustomizeAdminApi(); + var sourceAdresId = fixture.Create(); + var destinationAdresId = fixture.Create(); + var idempotencyKey = fixture.Create(); + + var sqsClientWrapperMock = new Mock(); + var locatiesFinder = new Mock(); + + locatiesFinder.Setup(s => s.FindLocaties(sourceAdresId)) + .ReturnsAsync(LocatiesPerVCodeCollection.Empty); + + var sut = new TeHeradresserenLocatiesProcessor(sqsClientWrapperMock.Object, locatiesFinder.Object); + await sut.Process(sourceAdresId, destinationAdresId, idempotencyKey); + + sqsClientWrapperMock.Verify(v => v.QueueReaddressMessage(It.IsAny()), Times.Never()); + } +} diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/TeHeradresserenLocatiesHandlerTests/Given_One_Location_Found.cs b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/TeHeradresserenLocatiesHandlerTests/Given_One_Location_Found.cs new file mode 100644 index 000000000..7693416eb --- /dev/null +++ b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/TeHeradresserenLocatiesHandlerTests/Given_One_Location_Found.cs @@ -0,0 +1,38 @@ +namespace AssociationRegistry.Test.Admin.Api.GrarConsumer.FusieEvents.When_Consuming_Merger_Events.TeHeradresserenLocatiesHandlerTests; + +using Acties.GrarConsumer.HeradresseerLocaties; +using AssociationRegistry.Framework; +using AssociationRegistry.Test.Common.AutoFixture; +using AutoFixture; +using FluentAssertions; +using Grar.GrarUpdates.Fusies.TeHeradresserenLocaties; +using Grar.GrarUpdates.LocatieFinder; +using Moq; +using Xunit; + +public class Given_One_Location_Found +{ + [Fact] + public async Task Then_One_Message_Is_Sent() + { + var fixture = new Fixture().CustomizeAdminApi(); + var sourceAdresId = fixture.Create(); + var destinationAdresId = fixture.Create(); + + HeradresseerLocatiesMessage actual = null; + var sqsClientWrapper = new Mock(); + sqsClientWrapper.CaptureQueueOverkoepelendeGrarMessage(message => actual = message.HeradresseerLocatiesMessage); + + var locatieId = fixture.Create(); + var idempotencyKey = fixture.Create(); + var locatiesFinder = new StubLocatieFinder(sourceAdresId, [locatieId]); + var locatieIdsPerVCode = await locatiesFinder.FindLocaties(sourceAdresId); + + var sut = new TeHeradresserenLocatiesProcessor(sqsClientWrapper.Object, locatiesFinder); + await sut.Process(sourceAdresId, destinationAdresId, idempotencyKey); + + var messages = locatieIdsPerVCode.Map(destinationAdresId, idempotencyKey); + + actual.Should().BeEquivalentTo(messages.First()); + } +} diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/TeOntkoppelenHandlerTests/Given_No_Locations_Found.cs b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/TeOntkoppelenHandlerTests/Given_No_Locations_Found.cs new file mode 100644 index 000000000..d30483961 --- /dev/null +++ b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/TeOntkoppelenHandlerTests/Given_No_Locations_Found.cs @@ -0,0 +1,32 @@ +namespace AssociationRegistry.Test.Admin.Api.GrarConsumer.FusieEvents.When_Consuming_Merger_Events.TeOntkoppelenHandlerTests; + +using Acties.GrarConsumer.OntkoppelAdres; +using AssociationRegistry.Admin.Api.Infrastructure.AWS; +using AssociationRegistry.Framework; +using AutoFixture; +using Common.AutoFixture; +using Grar.GrarUpdates.Fusies.TeOntkoppelenLocaties; +using Grar.GrarUpdates.LocatieFinder; +using Moq; +using Xunit; + +public class Given_No_Locations_Found +{ + [Fact] + public async Task Then_No_Messages_Are_Sent() + { + var fixture = new Fixture().CustomizeAdminApi(); + var sourceAdresId = fixture.Create(); + + var sqsClientWrapperMock = new Mock(); + var locatiesFinder = new Mock(); + + locatiesFinder.Setup(s => s.FindLocaties(sourceAdresId)) + .ReturnsAsync(LocatiesPerVCodeCollection.Empty); + + var sut = new TeOntkoppelenLocatiesProcessor(sqsClientWrapperMock.Object, locatiesFinder.Object); + await sut.Process(sourceAdresId); + + sqsClientWrapperMock.Verify(v => v.QueueMessage(It.IsAny()), Times.Never()); + } +} diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/TeOntkoppelenHandlerTests/Given_One_Location_Found.cs b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/TeOntkoppelenHandlerTests/Given_One_Location_Found.cs new file mode 100644 index 000000000..a9771435f --- /dev/null +++ b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Consuming_Merger_Events/TeOntkoppelenHandlerTests/Given_One_Location_Found.cs @@ -0,0 +1,40 @@ +namespace AssociationRegistry.Test.Admin.Api.GrarConsumer.FusieEvents.When_Consuming_Merger_Events.TeOntkoppelenHandlerTests; + +using Acties.GrarConsumer.OntkoppelAdres; +using AssociationRegistry.Admin.Api.Infrastructure.AWS; +using AssociationRegistry.Framework; +using AutoFixture; +using Common.AutoFixture; +using FluentAssertions; +using Grar.GrarUpdates.Fusies.TeOntkoppelenLocaties; +using Grar.GrarUpdates.LocatieFinder; +using Moq; +using Xunit; + +public class Given_One_Location_Found +{ + [Fact] + public async Task Then_One_Message_Is_Sent() + { + var fixture = new Fixture().CustomizeAdminApi(); + var sourceAdresId = fixture.Create(); + + OntkoppelLocatiesMessage actual = null; + var sqsClientWrapper = new Mock(); + sqsClientWrapper.CaptureQueueOverkoepelendeGrarMessage(message => actual = message.OntkoppelLocatiesMessage); + + var locatieId = fixture.Create(); + var locatiesFinder = new StubLocatieFinder(sourceAdresId, [locatieId]); + var locatieIdsPerVCode = await locatiesFinder.FindLocaties(sourceAdresId); + + var sut = new TeOntkoppelenLocatiesProcessor(sqsClientWrapper.Object, locatiesFinder); + await sut.Process(sourceAdresId); + + actual.Should().BeEquivalentTo( + new OntkoppelLocatiesMessage + ( + locatieIdsPerVCode.First().VCode, + locatieIdsPerVCode.First().Locaties.Select(x => x.LocatieId).ToArray() + )); + } +} diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Mapping_LocatieIdsPerVCode/Given_Locaties_For_Different_VCodes.cs b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Mapping_LocatieIdsPerVCode/Given_Locaties_For_Different_VCodes.cs new file mode 100644 index 000000000..b613dfadd --- /dev/null +++ b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Mapping_LocatieIdsPerVCode/Given_Locaties_For_Different_VCodes.cs @@ -0,0 +1,47 @@ +namespace AssociationRegistry.Test.Admin.Api.GrarConsumer.FusieEvents.When_Mapping_LocatieIdsPerVCode; + +using Acties.GrarConsumer.HeradresseerLocaties; +using AssociationRegistry.Grar.Models; +using AssociationRegistry.Test.Common.AutoFixture; +using AutoFixture; +using FluentAssertions; +using Grar.GrarUpdates.Fusies.TeHeradresserenLocaties; +using Grar.GrarUpdates.Hernummering; +using Grar.GrarUpdates.LocatieFinder; +using Xunit; + +public class Given_Locaties_For_Different_VCodes +{ + [Fact] + public void Then_Returns_HeradresseerLocatiesMessage_For_VCode() + { + var fixture = new Fixture().CustomizeAdminApi(); + var destinationAdresId = fixture.Create(); + var idempotencyKey = fixture.Create(); + + var vCode1 = fixture.Create(); + var locatieIdsForVCode1 = fixture.Create(); + + var vCode2 = fixture.Create(); + var locatieIdsForVCode2 = fixture.Create(); + + var locatieIdsPerVCode = LocatiesPerVCodeCollection.FromLocatiesPerVCode(new Dictionary() + { + { vCode1, locatieIdsForVCode1 }, + { vCode2, locatieIdsForVCode2 }, + }); + + var actual = locatieIdsPerVCode.Map(destinationAdresId, idempotencyKey); + + actual.Should().BeEquivalentTo([ + new HeradresseerLocatiesMessage( + vCode1, + locatieIdsForVCode1.Select(l => new TeHeradresserenLocatie(l.LocatieId, destinationAdresId.ToString())).ToList(), + idempotencyKey), + new HeradresseerLocatiesMessage( + vCode2, + locatieIdsForVCode2.Select(l => new TeHeradresserenLocatie(l.LocatieId, destinationAdresId.ToString())).ToList(), + idempotencyKey), + ]); + } +} diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Mapping_LocatieIdsPerVCode/Given_Locaties_For_One_VCode.cs b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Mapping_LocatieIdsPerVCode/Given_Locaties_For_One_VCode.cs new file mode 100644 index 000000000..88356b628 --- /dev/null +++ b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Mapping_LocatieIdsPerVCode/Given_Locaties_For_One_VCode.cs @@ -0,0 +1,40 @@ +namespace AssociationRegistry.Test.Admin.Api.GrarConsumer.FusieEvents.When_Mapping_LocatieIdsPerVCode; + +using Acties.GrarConsumer.HeradresseerLocaties; +using AssociationRegistry.Grar.Models; +using AssociationRegistry.Test.Common.AutoFixture; +using AutoFixture; +using FluentAssertions; +using Grar.GrarUpdates.Fusies.TeHeradresserenLocaties; +using Grar.GrarUpdates.Hernummering; +using Grar.GrarUpdates.LocatieFinder; +using Xunit; + +public class Given_Locaties_For_One_VCode +{ + [Fact] + public void Then_Returns_One_HeradresseerLocatiesMessage_For_VCode() + { + var fixture = new Fixture().CustomizeAdminApi(); + var destinationAdresId = fixture.Create(); + var idempotencyKey = fixture.Create(); + + var vCode = fixture.Create(); + + var locatieIds = fixture.Create(); + + var locatieIdsPerVCode = LocatiesPerVCodeCollection.FromLocatiesPerVCode(new Dictionary() + { + {vCode, locatieIds}, + }); + + var actual = locatieIdsPerVCode.Map(destinationAdresId, idempotencyKey); + + actual.Should().BeEquivalentTo([ + new HeradresseerLocatiesMessage( + vCode, + locatieIds.Select(l => new TeHeradresserenLocatie(l.LocatieId, destinationAdresId.ToString())).ToList(), + idempotencyKey), + ]); + } +} diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Mapping_LocatieIdsPerVCode/Given_No_Data.cs b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Mapping_LocatieIdsPerVCode/Given_No_Data.cs new file mode 100644 index 000000000..01ac21b79 --- /dev/null +++ b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/FusieEvents/When_Mapping_LocatieIdsPerVCode/Given_No_Data.cs @@ -0,0 +1,20 @@ +namespace AssociationRegistry.Test.Admin.Api.GrarConsumer.FusieEvents.When_Mapping_LocatieIdsPerVCode; + +using AssociationRegistry.Test.Common.AutoFixture; +using AutoFixture; +using FluentAssertions; +using Grar.GrarUpdates.LocatieFinder; +using Xunit; + +public class Given_No_Data +{ + [Fact] + public void Then_Returns_Empty_Array() + { + var fixture = new Fixture().CustomizeAdminApi(); + var locatieIdsPerVCode = LocatiesPerVCodeCollection.Empty; + + var actual = locatieIdsPerVCode.Map(fixture.Create(), fixture.Create()); + actual.Should().BeEmpty(); + } +} diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/ReAddressEvents/When_Mapping_ReaddressData_To_TeHernummerenStraat/Given_ReaddressedData.cs b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/ReAddressEvents/When_Mapping_ReaddressData_To_TeHernummerenStraat/Given_ReaddressedData.cs new file mode 100644 index 000000000..d797eca43 --- /dev/null +++ b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/ReAddressEvents/When_Mapping_ReaddressData_To_TeHernummerenStraat/Given_ReaddressedData.cs @@ -0,0 +1,68 @@ +namespace AssociationRegistry.Test.Admin.Api.GrarConsumer.ReAddressEvents.When_Mapping_ReaddressData_To_TeHernummerenStraat; + +using AssociationRegistry.Admin.Api.GrarConsumer.Kafka.StraatHernummering; +using AssociationRegistry.Test.Common.AutoFixture; +using AutoFixture; +using Be.Vlaanderen.Basisregisters.GrAr.Contracts.AddressRegistry; +using Be.Vlaanderen.Basisregisters.GrAr.Contracts.Common; +using FluentAssertions; +using Grar.GrarUpdates.Hernummering; +using Xunit; + +public class Given_ReaddressedData +{ + private readonly Fixture _fixture; + + public Given_ReaddressedData() + { + _fixture = new Fixture().CustomizeAdminApi(); + } + + [Fact] + public void Then_It_Maps() + { + var firstHouseNumberToReaddress = new AddressHouseNumberReaddressedData(addressPersistentLocalId: 1000, // can be ignored + CreateReaddressedAddressData( + vanAdresId: 1000, naarAdresId: 2000), + new List + { + CreateReaddressedAddressData( + vanAdresId: 1001, naarAdresId: 2001), + CreateReaddressedAddressData( + vanAdresId: 1002, naarAdresId: 2002), + }); + + var secondHouseNumberToReaddress = new AddressHouseNumberReaddressedData(addressPersistentLocalId: 2000, // can be ignored + CreateReaddressedAddressData( + vanAdresId: 2000, naarAdresId: 3000), + new List + { + CreateReaddressedAddressData( + vanAdresId: 2001, naarAdresId: 3002), + CreateReaddressedAddressData( + vanAdresId: 2002, naarAdresId: 3003), + }); + + var actual = TeHernummerenStraatFactory.From( + new StreetNameWasReaddressed( + _fixture.Create(), + [firstHouseNumberToReaddress, secondHouseNumberToReaddress], + _fixture.Create())); + + var expected = new TeHernummerenStraat(new List + { + new(VanAdresId: 1000, NaarAdresId: 2000), + new(VanAdresId: 1001, NaarAdresId: 2001), + new(VanAdresId: 1002, NaarAdresId: 2002), + new(VanAdresId: 2000, NaarAdresId: 3000), + new(VanAdresId: 2001, NaarAdresId: 3002), + new(VanAdresId: 2002, NaarAdresId: 3003), + }); + + actual.Should().BeEquivalentTo(expected); + } + + public ReaddressedAddressData CreateReaddressedAddressData(int vanAdresId, int naarAdresId) + => new(vanAdresId, naarAdresId, isDestinationNewlyProposed: false, string.Empty, string.Empty, string.Empty, + string.Empty, string.Empty, string.Empty, string.Empty, sourceIsOfficiallyAssigned: false); +} diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/ReAddressEvents/When_Mapping_ReaddressedData/FakeLocatieFinder.cs b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/ReAddressEvents/When_Mapping_ReaddressedData/FakeLocatieFinder.cs new file mode 100644 index 000000000..d599eceab --- /dev/null +++ b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/ReAddressEvents/When_Mapping_ReaddressedData/FakeLocatieFinder.cs @@ -0,0 +1,29 @@ +namespace AssociationRegistry.Test.Admin.Api.GrarConsumer.ReAddressEvents.When_Mapping_ReaddressedData; + +using AssociationRegistry.Admin.Api.GrarConsumer.Finders; +using AssociationRegistry.Admin.Schema.Detail; +using Grar.GrarUpdates; +using Grar.GrarUpdates.LocatieFinder; + +public class FakeLocatieFinder : ILocatieFinder +{ + private readonly List _locatieLookupDocuments; + + public FakeLocatieFinder(List locatieLookupDocuments) + { + _locatieLookupDocuments = locatieLookupDocuments; + } + + public async Task> FindLocatieLookupDocuments(string[] adresIds) + => _locatieLookupDocuments.Where(x => adresIds.Contains(x.AdresId)) + .Select(x => new LocatieLookupData(x.LocatieId, x.AdresId, x.VCode)) + .ToList(); + + public async Task FindLocaties(params int[] adresIds) + => throw new NotImplementedException(); + + async Task ILocatieFinder.FindLocaties(params string[] adresIds) + => throw new NotImplementedException(); +} + +public record LocatieLookupMetExpectedAdres(LocatieLookupDocument Document, string ExpectedAdresId); diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/ReAddressEvents/When_Mapping_ReaddressedData/Given_Multiple_LocatieLookup_Records_For_The_Same_VCode.cs b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/ReAddressEvents/When_Mapping_ReaddressedData/Given_Multiple_LocatieLookup_Records_For_The_Same_VCode.cs new file mode 100644 index 000000000..0e6139fe1 --- /dev/null +++ b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/ReAddressEvents/When_Mapping_ReaddressedData/Given_Multiple_LocatieLookup_Records_For_The_Same_VCode.cs @@ -0,0 +1,66 @@ +namespace AssociationRegistry.Test.Admin.Api.GrarConsumer.ReAddressEvents.When_Mapping_ReaddressedData; + +using Acties.GrarConsumer.HeradresseerLocaties; +using AutoFixture; +using Be.Vlaanderen.Basisregisters.GrAr.Contracts.AddressRegistry; +using Common.AutoFixture; +using FluentAssertions; +using Grar.GrarUpdates.Hernummering; +using Grar.GrarUpdates.LocatieFinder; +using Moq; +using Xunit; + +public class Given_Multiple_LocatieLookup_Records_For_The_Same_VCode +{ + private readonly Fixture _fixture; + + public Given_Multiple_LocatieLookup_Records_For_The_Same_VCode() + { + _fixture = new Fixture().CustomizeAdminApi(); + } + + [Fact] + public async Task Then_Messages_Are_GroupedBy_VCode() + { + + var locatieFinderMock = new Mock(); + + locatieFinderMock.Setup(x => x.FindLocaties(It.IsAny())) + .ReturnsAsync(LocatiesPerVCodeCollection.FromLocatiesPerVCode(new Dictionary() + { + { "VCode1", [new LocatieLookupData(1, "123", "VCode1"), new LocatieLookupData(2, "456", "VCode1")] }, + { "VCode2", [new LocatieLookupData(1, "123", "VCode2"), new LocatieLookupData(2, "789", "VCode2")] }, + })); + + var sut = new TeHeradresserenLocatiesMapper(locatieFinderMock.Object); + + var addressHouseNumberReaddressedData = new TeHernummerenStraat(new List + { + new(VanAdresId: 123, NaarAdresId: 777), + new(VanAdresId: 456, NaarAdresId: 888), + new(VanAdresId: 789, NaarAdresId: 999), + }); + + var result = await sut.ForAddress(addressHouseNumberReaddressedData, idempotenceKey: "idempotencyKey"); + + result.Should().BeEquivalentTo(new List + { + new(VCode: "VCode1", new List + { + new(LocatieId: 1, NaarAdresId: "777"), + new(LocatieId: 2, NaarAdresId: "888"), + }, + idempotencyKey: "idempotencyKey"), + new(VCode: "VCode2", new List + { + new(LocatieId: 1, NaarAdresId: "777"), + new(LocatieId: 2, NaarAdresId: "999"), + }, + idempotencyKey: "idempotencyKey"), + }); + } + + public ReaddressedAddressData CreateReaddressedAddressData(int vanAdresId, int naarAdresId) + => new(vanAdresId, naarAdresId, isDestinationNewlyProposed: false, string.Empty, string.Empty, string.Empty, + string.Empty, string.Empty, string.Empty, string.Empty, sourceIsOfficiallyAssigned: false); +} diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/StubLocatieFinder.cs b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/StubLocatieFinder.cs new file mode 100644 index 000000000..bacb74e8a --- /dev/null +++ b/test/AssociationRegistry.Test.Admin.Api/GrarConsumer/StubLocatieFinder.cs @@ -0,0 +1,28 @@ +namespace AssociationRegistry.Test.Admin.Api.GrarConsumer; + +using AssociationRegistry.Admin.Api.GrarConsumer.Finders; +using AssociationRegistry.Admin.Schema.Detail; +using Grar.GrarUpdates; +using Grar.GrarUpdates.LocatieFinder; + +public class StubLocatieFinder : ILocatieFinder +{ + private readonly Dictionary _locatieLookupData; + + public StubLocatieFinder(int sourceAdresId, LocatieLookupData[]? stubData) + { + _locatieLookupData = new Dictionary() + { + { sourceAdresId.ToString(), stubData }, + }; + } + + public async Task FindLocaties(params string[] adresIds) + => throw new NotImplementedException(); + + public async Task> FindLocatieLookupDocuments(string[] adresIds) + => throw new NotImplementedException(); + + public async Task FindLocaties(params int[] adresIds) + => await Task.FromResult(LocatiesPerVCodeCollection.FromLocatiesPerVCode(_locatieLookupData)); +} diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarSync/When_Mapping_ReaddressedData/FakeLocatieFinder.cs b/test/AssociationRegistry.Test.Admin.Api/GrarSync/When_Mapping_ReaddressedData/FakeLocatieFinder.cs deleted file mode 100644 index cebb26c28..000000000 --- a/test/AssociationRegistry.Test.Admin.Api/GrarSync/When_Mapping_ReaddressedData/FakeLocatieFinder.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace AssociationRegistry.Test.Admin.Api.GrarSync.When_Mapping_ReaddressedData; - -using AssociationRegistry.Admin.Api.GrarSync; -using AssociationRegistry.Admin.Schema.Detail; - -public class FakeLocatieFinder : ILocatieFinder -{ - private readonly List _locatieLookupDocuments; - - public FakeLocatieFinder(List locatieLookupDocuments) - { - _locatieLookupDocuments = locatieLookupDocuments; - } - - public async Task> FindLocaties(string[] adresIds) - => _locatieLookupDocuments.Where(x => adresIds.Contains(x.AdresId)); -} - -public record LocatieLookupMetExpectedAdres(LocatieLookupDocument Document, string ExpectedAdresId); diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarSync/When_Mapping_ReaddressedData/Given_Multiple_LocatieLookup_Records_For_The_Same_VCode.cs b/test/AssociationRegistry.Test.Admin.Api/GrarSync/When_Mapping_ReaddressedData/Given_Multiple_LocatieLookup_Records_For_The_Same_VCode.cs deleted file mode 100644 index 901c7eaf6..000000000 --- a/test/AssociationRegistry.Test.Admin.Api/GrarSync/When_Mapping_ReaddressedData/Given_Multiple_LocatieLookup_Records_For_The_Same_VCode.cs +++ /dev/null @@ -1,80 +0,0 @@ -namespace AssociationRegistry.Test.Admin.Api.GrarSync.When_Mapping_ReaddressedData; - -using AssociationRegistry.Admin.Api.GrarSync; -using AssociationRegistry.Admin.Schema.Detail; -using AutoFixture; -using Be.Vlaanderen.Basisregisters.GrAr.Contracts.AddressRegistry; -using Common.AutoFixture; -using FluentAssertions; -using Framework; -using Grar.HeradresseerLocaties; -using Grar.Models; -using Xunit; - -public class Given_Multiple_LocatieLookup_Records_For_The_Same_VCode -{ - private readonly Fixture _fixture; - - public Given_Multiple_LocatieLookup_Records_For_The_Same_VCode() - { - _fixture = new Fixture().CustomizeAdminApi(); - } - - [Fact] - public async Task Then_Messages_Are_GroupedBy_VCode() - { - var locatieFinder = new FakeLocatieFinder(new List - { - new() - { - VCode = "VCode1", - AdresId = "123", - LocatieId = 1, - }, - new() - { - VCode = "VCode1", - AdresId = "456", - LocatieId = 2, - }, - new() - { - VCode = "VCode2", - AdresId = "123", - LocatieId = 1, - }, - new() - { - VCode = "VCode2", - AdresId = "789", - LocatieId = 2, - }, - }); - - var sut = new TeHeradresserenLocatiesMapper(locatieFinder); - - var addressHouseNumberReaddressedData = new List - { - new(addressPersistentLocalId: 777, // can be ignored - CreateReaddressedAddressData(vanAdresId: 123, naarAdresId: 777), // vanAdresId, naarAdresId (HouseNumber) - new List() // BoxNumbers - ), - }; - - var result = await sut.ForAddress(addressHouseNumberReaddressedData, idempotenceKey: "idempotencyKey"); - - result.Should().BeEquivalentTo(new List - { - new(VCode: "VCode1", new List - { new(LocatieId: 1, AddressId: "777") }, - idempotencyKey: "idempotencyKey"), - new(VCode: "VCode2", new List - { new(LocatieId: 1, AddressId: "777") }, - idempotencyKey: "idempotencyKey"), - }); - } - - public ReaddressedAddressData CreateReaddressedAddressData(int vanAdresId, int naarAdresId) - => new(vanAdresId, naarAdresId, isDestinationNewlyProposed: false, string.Empty, string.Empty, string.Empty, - string.Empty, string.Empty, string.Empty, string.Empty, sourceIsOfficiallyAssigned: false); -} diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarSync/When_Mapping_ReaddressedData/Given_Multiple_LocatieLookup_Records_For_The_Same_VCode_Grouping.cs b/test/AssociationRegistry.Test.Admin.Api/GrarSync/When_Mapping_ReaddressedData/Given_Multiple_LocatieLookup_Records_For_The_Same_VCode_Grouping.cs deleted file mode 100644 index 73c899884..000000000 --- a/test/AssociationRegistry.Test.Admin.Api/GrarSync/When_Mapping_ReaddressedData/Given_Multiple_LocatieLookup_Records_For_The_Same_VCode_Grouping.cs +++ /dev/null @@ -1,85 +0,0 @@ -namespace AssociationRegistry.Test.Admin.Api.GrarSync.When_Mapping_ReaddressedData; - -using AssociationRegistry.Admin.Api.GrarSync; -using AssociationRegistry.Admin.Schema.Detail; -using AutoFixture; -using Be.Vlaanderen.Basisregisters.GrAr.Contracts.AddressRegistry; -using Common.AutoFixture; -using FluentAssertions; -using Framework; -using Grar.HeradresseerLocaties; -using Grar.Models; -using Xunit; - -public class Given_Multiple_LocatieLookup_Records_For_The_Same_VCode_Grouping -{ - private readonly Fixture _fixture; - - public Given_Multiple_LocatieLookup_Records_For_The_Same_VCode_Grouping() - { - _fixture = new Fixture().CustomizeAdminApi(); - } - - [Fact] - public async Task Then_Messages_Are_Queued() - { - var locatieFinder = new FakeLocatieFinder(new List - { - new() - { - VCode = "VCode1", - AdresId = "123", - LocatieId = 1, - }, - new() - { - VCode = "VCode1", - AdresId = "456", - LocatieId = 2, - }, - new() - { - VCode = "VCode2", - AdresId = "123", - LocatieId = 1, - }, - new() - { - VCode = "VCode2", - AdresId = "789", - LocatieId = 2, - }, - }); - - var sut = new TeHeradresserenLocatiesMapper(locatieFinder); - - var addressHouseNumberReaddressedData = new List - { - new(addressPersistentLocalId: 777, // can be ignored - CreateReaddressedAddressData(vanAdresId: 123, naarAdresId: 777), // vanAdresId, naarAdresId (HouseNumber) - new List() // BoxNumbers - ), - new(addressPersistentLocalId: 777, // can be ignored - CreateReaddressedAddressData(vanAdresId: 456, naarAdresId: 888), // vanAdresId, naarAdresId (HouseNumber) - new List() // BoxNumbers - ), - }; - - var result = await sut.ForAddress(addressHouseNumberReaddressedData, idempotenceKey: "idempotencyKey"); - - result.Should().BeEquivalentTo(new List - { - new( - VCode: "VCode1", new List - { new(LocatieId: 1, AddressId: "777"), new(LocatieId: 2, AddressId: "888") }, - idempotencyKey: "idempotencyKey"), - new(VCode: "VCode2", new List - { new(LocatieId: 1, AddressId: "777") }, - idempotencyKey: "idempotencyKey"), - }); - } - - public ReaddressedAddressData CreateReaddressedAddressData(int vanAdresId, int naarAdresId) - => new(vanAdresId, naarAdresId, isDestinationNewlyProposed: false, string.Empty, string.Empty, string.Empty, - string.Empty, string.Empty, string.Empty, string.Empty, sourceIsOfficiallyAssigned: false); -} diff --git a/test/AssociationRegistry.Test.Admin.Api/GrarSync/When_Mapping_ReaddressedData/Given_Multiple_LocatieLookup_Records_For_The_Same_VCode_With_BoxNumbers.cs b/test/AssociationRegistry.Test.Admin.Api/GrarSync/When_Mapping_ReaddressedData/Given_Multiple_LocatieLookup_Records_For_The_Same_VCode_With_BoxNumbers.cs deleted file mode 100644 index d506e717f..000000000 --- a/test/AssociationRegistry.Test.Admin.Api/GrarSync/When_Mapping_ReaddressedData/Given_Multiple_LocatieLookup_Records_For_The_Same_VCode_With_BoxNumbers.cs +++ /dev/null @@ -1,151 +0,0 @@ -namespace AssociationRegistry.Test.Admin.Api.GrarSync.When_Mapping_ReaddressedData; - -using AssociationRegistry.Admin.Api.GrarSync; -using AssociationRegistry.Admin.Schema.Detail; -using AutoFixture; -using Be.Vlaanderen.Basisregisters.GrAr.Contracts.AddressRegistry; -using Common.AutoFixture; -using FluentAssertions; -using Framework; -using Grar.HeradresseerLocaties; -using Grar.Models; -using Xunit; - -public class Given_Multiple_LocatieLookup_Records_For_The_Same_VCode_With_BoxNumbers -{ - private readonly Fixture _fixture; - - public Given_Multiple_LocatieLookup_Records_For_The_Same_VCode_With_BoxNumbers() - { - _fixture = new Fixture().CustomizeAdminApi(); - } - - [Fact] - public async Task Then_Messages_Are_Queued() - { - var firstHouseNumberToReaddress = new AddressHouseNumberReaddressedData(addressPersistentLocalId: 1000, // can be ignored - CreateReaddressedAddressData( - vanAdresId: 1000, naarAdresId: 2000), - new List - { - CreateReaddressedAddressData( - vanAdresId: 1001, naarAdresId: 2001), - CreateReaddressedAddressData( - vanAdresId: 1002, naarAdresId: 2002), - }); - - var secondHouseNumberToReaddress = new AddressHouseNumberReaddressedData(addressPersistentLocalId: 2000, // can be ignored - CreateReaddressedAddressData( - vanAdresId: 2000, naarAdresId: 3000), - new List - { - CreateReaddressedAddressData( - vanAdresId: 2001, naarAdresId: 3002), - CreateReaddressedAddressData( - vanAdresId: 2002, naarAdresId: 3003), - }); - - var addressHouseNumberReaddressedData = new List - { - firstHouseNumberToReaddress, - secondHouseNumberToReaddress, - }; - - var vCode1 = "VCode1"; - var vCode2 = "VCode2"; - - var locatieLookupHuisnummer1 = CreateLocatieLookupMetExpectedAdres( - vCode1, - locatieId: 1, - firstHouseNumberToReaddress.ReaddressedHouseNumber.SourceAddressPersistentLocalId.ToString(), - firstHouseNumberToReaddress.ReaddressedHouseNumber.DestinationAddressPersistentLocalId.ToString()); - - var locatieLookupHuisnummer1Busnummer1 = CreateLocatieLookupMetExpectedAdres( - vCode2, - locatieId: 1, - firstHouseNumberToReaddress.ReaddressedBoxNumbers[0].SourceAddressPersistentLocalId.ToString(), - firstHouseNumberToReaddress.ReaddressedBoxNumbers[0].DestinationAddressPersistentLocalId.ToString()); - - var locatieLookupHuisnummer1Busnummer2 = CreateLocatieLookupMetExpectedAdres( - vCode1, - locatieId: 2, - firstHouseNumberToReaddress.ReaddressedBoxNumbers[1].SourceAddressPersistentLocalId.ToString(), - firstHouseNumberToReaddress.ReaddressedBoxNumbers[1].DestinationAddressPersistentLocalId.ToString()); - - var locatieLookupHuisnummer2 = CreateLocatieLookupMetExpectedAdres( - vCode2, - locatieId: 2, - firstHouseNumberToReaddress.ReaddressedHouseNumber.SourceAddressPersistentLocalId.ToString(), - firstHouseNumberToReaddress.ReaddressedHouseNumber.DestinationAddressPersistentLocalId.ToString()); - - var locatieLookupHuisnummer2Busnummer1 = CreateLocatieLookupMetExpectedAdres( - vCode1, - locatieId: 3, - firstHouseNumberToReaddress.ReaddressedBoxNumbers[0].SourceAddressPersistentLocalId.ToString(), - firstHouseNumberToReaddress.ReaddressedBoxNumbers[0].DestinationAddressPersistentLocalId.ToString()); - - var locatieLookupHuisnummer2Busnummer2 = CreateLocatieLookupMetExpectedAdres( - vCode2, - locatieId: 3, - firstHouseNumberToReaddress.ReaddressedBoxNumbers[1].SourceAddressPersistentLocalId.ToString(), - firstHouseNumberToReaddress.ReaddressedBoxNumbers[1].DestinationAddressPersistentLocalId.ToString()); - - var sut = new TeHeradresserenLocatiesMapper(new FakeLocatieFinder(new List - { - locatieLookupHuisnummer1.Document, //vcode1 - locatieLookupHuisnummer1Busnummer1.Document, //vcode2 - locatieLookupHuisnummer1Busnummer2.Document, //vcode1 - locatieLookupHuisnummer2.Document, //vcode2 - locatieLookupHuisnummer2Busnummer1.Document, //vcode1 - locatieLookupHuisnummer2Busnummer2.Document, //vcode2 - })); - - var result = await sut.ForAddress(addressHouseNumberReaddressedData, idempotenceKey: "idempotencyKey"); - - result.Should().BeEquivalentTo(expectation: new List - { - new( - vCode1, - new List - { - new(locatieLookupHuisnummer1.Document.LocatieId, - locatieLookupHuisnummer1.ExpectedAdresId), - new(locatieLookupHuisnummer1Busnummer2.Document.LocatieId, - locatieLookupHuisnummer1Busnummer2.ExpectedAdresId), - new(locatieLookupHuisnummer2Busnummer1.Document.LocatieId, - locatieLookupHuisnummer2Busnummer1.ExpectedAdresId), - }, - idempotencyKey: "idempotencyKey"), - new( - vCode2, - new List - { - new(locatieLookupHuisnummer1Busnummer1.Document.LocatieId, - locatieLookupHuisnummer1Busnummer1.ExpectedAdresId), - new(locatieLookupHuisnummer2.Document.LocatieId, - locatieLookupHuisnummer2.ExpectedAdresId), - new(locatieLookupHuisnummer2Busnummer2.Document.LocatieId, - locatieLookupHuisnummer2Busnummer2.ExpectedAdresId), - }, - idempotencyKey: "idempotencyKey"), - }); - } - - private LocatieLookupMetExpectedAdres CreateLocatieLookupMetExpectedAdres( - string vCode, - int locatieId, - string vanAdresId, - string naarAdresId) - => new( - new LocatieLookupDocument - { - VCode = vCode, - AdresId = vanAdresId, - LocatieId = locatieId, - }, - naarAdresId); - - public ReaddressedAddressData CreateReaddressedAddressData(int vanAdresId, int naarAdresId) - => new(vanAdresId, naarAdresId, isDestinationNewlyProposed: false, string.Empty, string.Empty, string.Empty, - string.Empty, string.Empty, string.Empty, string.Empty, sourceIsOfficiallyAssigned: false); -} diff --git a/test/AssociationRegistry.Test.Common/Framework/TestDocumentStoreFactory.cs b/test/AssociationRegistry.Test.Common/Framework/TestDocumentStoreFactory.cs index b0e104d0b..fd8749399 100644 --- a/test/AssociationRegistry.Test.Common/Framework/TestDocumentStoreFactory.cs +++ b/test/AssociationRegistry.Test.Common/Framework/TestDocumentStoreFactory.cs @@ -8,7 +8,7 @@ namespace AssociationRegistry.Test.Common.Framework; using Newtonsoft.Json; using Weasel.Core; -public class TestDocumentStoreFactory +public static class TestDocumentStoreFactory { public static async Task Create(string schema) { diff --git a/test/AssociationRegistry.Test.Common/Scenarios/CommandHandling/AdresMultipleWerdOvergenomenUitAdressenregisterScenario.cs b/test/AssociationRegistry.Test.Common/Scenarios/CommandHandling/AdresMultipleWerdOvergenomenUitAdressenregisterScenario.cs new file mode 100644 index 000000000..8d784f5f9 --- /dev/null +++ b/test/AssociationRegistry.Test.Common/Scenarios/CommandHandling/AdresMultipleWerdOvergenomenUitAdressenregisterScenario.cs @@ -0,0 +1,54 @@ +namespace AssociationRegistry.Test.Common.Scenarios.CommandHandling; + +using AssociationRegistry.Framework; +using AutoFixture; +using Events; +using global::AutoFixture; +using Vereniging; + +public class MultipleAdresWerdOvergenomenUitAdressenregisterScenario : CommandhandlerScenarioBase +{ + public MultipleAdresWerdOvergenomenUitAdressenregisterScenario() + { + var fixture = new Fixture().CustomizeAdminApi(); + VCode = fixture.Create(); + + FeitelijkeVerenigingWerdGeregistreerd = fixture.Create() with + { + VCode = VCode, Locaties = Array.Empty(), + }; + + LocatieWerdToegevoegd = fixture.Create(); + AdresWerdOvergenomenUitAdressenregister = fixture.Create() + with + { + LocatieId = LocatieWerdToegevoegd.Locatie.LocatieId, + }; + + LocatieWerdToegevoegd2 = fixture.Create(); + AdresWerdOvergenomenUitAdressenregister2 = fixture.Create() + with + { + LocatieId = LocatieWerdToegevoegd2.Locatie.LocatieId, + }; + } + + public override VCode VCode { get; } + public FeitelijkeVerenigingWerdGeregistreerd FeitelijkeVerenigingWerdGeregistreerd { get; } + public LocatieWerdToegevoegd LocatieWerdToegevoegd { get; } + public AdresWerdOvergenomenUitAdressenregister AdresWerdOvergenomenUitAdressenregister { get; } + public LocatieWerdToegevoegd LocatieWerdToegevoegd2 { get; } + public AdresWerdOvergenomenUitAdressenregister AdresWerdOvergenomenUitAdressenregister2 { get; } + + public override IEnumerable Events() + { + return new IEvent[] + { + FeitelijkeVerenigingWerdGeregistreerd, + LocatieWerdToegevoegd, + AdresWerdOvergenomenUitAdressenregister, + LocatieWerdToegevoegd2, + AdresWerdOvergenomenUitAdressenregister2, + }; + } +} diff --git a/test/AssociationRegistry.Test.Common/Scenarios/CommandHandling/AdresWerdOntkoppeldScenario.cs b/test/AssociationRegistry.Test.Common/Scenarios/CommandHandling/AdresWerdOntkoppeldScenario.cs new file mode 100644 index 000000000..042c965e6 --- /dev/null +++ b/test/AssociationRegistry.Test.Common/Scenarios/CommandHandling/AdresWerdOntkoppeldScenario.cs @@ -0,0 +1,51 @@ +namespace AssociationRegistry.Test.Common.Scenarios.CommandHandling; + +using AssociationRegistry.Framework; +using AutoFixture; +using Events; +using global::AutoFixture; +using Vereniging; + +public class AdresWerdOntkoppeldScenario : CommandhandlerScenarioBase +{ + public AdresWerdOntkoppeldScenario() + { + var fixture = new Fixture().CustomizeAdminApi(); + VCode = fixture.Create(); + + FeitelijkeVerenigingWerdGeregistreerd = fixture.Create() with + { + VCode = VCode, Locaties = Array.Empty(), + }; + + LocatieWerdToegevoegd = fixture.Create(); + AdresWerdOvergenomenUitAdressenregister = fixture.Create() + with + { + LocatieId = LocatieWerdToegevoegd.Locatie.LocatieId, + }; + + AdresWerdOntkoppeldVanAdressenregister = fixture.Create() + with + { + LocatieId = LocatieWerdToegevoegd.Locatie.LocatieId, + }; + } + + public override VCode VCode { get; } + public FeitelijkeVerenigingWerdGeregistreerd FeitelijkeVerenigingWerdGeregistreerd { get; } + public LocatieWerdToegevoegd LocatieWerdToegevoegd { get; } + public AdresWerdOvergenomenUitAdressenregister AdresWerdOvergenomenUitAdressenregister { get; } + public AdresWerdOntkoppeldVanAdressenregister AdresWerdOntkoppeldVanAdressenregister { get; } + + public override IEnumerable Events() + { + return new IEvent[] + { + FeitelijkeVerenigingWerdGeregistreerd, + LocatieWerdToegevoegd, + AdresWerdOvergenomenUitAdressenregister, + AdresWerdOntkoppeldVanAdressenregister + }; + } +} diff --git a/test/AssociationRegistry.Test.Common/Scenarios/CommandHandling/AdresWerdOvergenomenUitAdressenregisterScenario.cs b/test/AssociationRegistry.Test.Common/Scenarios/CommandHandling/AdresWerdOvergenomenUitAdressenregisterScenario.cs new file mode 100644 index 000000000..9cc3efd89 --- /dev/null +++ b/test/AssociationRegistry.Test.Common/Scenarios/CommandHandling/AdresWerdOvergenomenUitAdressenregisterScenario.cs @@ -0,0 +1,43 @@ +namespace AssociationRegistry.Test.Common.Scenarios.CommandHandling; + +using AssociationRegistry.Framework; +using AutoFixture; +using Events; +using global::AutoFixture; +using Vereniging; + +public class AdresWerdOvergenomenUitAdressenregisterScenario : CommandhandlerScenarioBase +{ + public AdresWerdOvergenomenUitAdressenregisterScenario() + { + var fixture = new Fixture().CustomizeAdminApi(); + VCode = fixture.Create(); + + FeitelijkeVerenigingWerdGeregistreerd = fixture.Create() with + { + VCode = VCode, Locaties = Array.Empty(), + }; + + LocatieWerdToegevoegd = fixture.Create(); + AdresWerdOvergenomenUitAdressenregister = fixture.Create() + with + { + LocatieId = LocatieWerdToegevoegd.Locatie.LocatieId, + }; + } + + public override VCode VCode { get; } + public FeitelijkeVerenigingWerdGeregistreerd FeitelijkeVerenigingWerdGeregistreerd { get; } + public LocatieWerdToegevoegd LocatieWerdToegevoegd { get; } + public AdresWerdOvergenomenUitAdressenregister AdresWerdOvergenomenUitAdressenregister { get; } + + public override IEnumerable Events() + { + return new IEvent[] + { + FeitelijkeVerenigingWerdGeregistreerd, + LocatieWerdToegevoegd, + AdresWerdOvergenomenUitAdressenregister, + }; + } +} diff --git a/test/AssociationRegistry.Test/GrarUpdates/TeOntkoppelenLocatiesHandlerTests/Given_A_Single_Existing_Locatie.cs b/test/AssociationRegistry.Test/GrarUpdates/TeOntkoppelenLocatiesHandlerTests/Given_A_Single_Existing_Locatie.cs new file mode 100644 index 000000000..d3284d75c --- /dev/null +++ b/test/AssociationRegistry.Test/GrarUpdates/TeOntkoppelenLocatiesHandlerTests/Given_A_Single_Existing_Locatie.cs @@ -0,0 +1,39 @@ +namespace AssociationRegistry.Test.GrarUpdates.TeOntkoppelenLocatiesHandlerTests; + +using Acties.GrarConsumer.OntkoppelAdres; +using Common.Framework; +using Common.Scenarios.CommandHandling; +using Events; +using Grar.GrarUpdates.Fusies.TeOntkoppelenLocaties; +using Vereniging; +using Xunit; + +public class Given_A_Single_Existing_Locatie +{ + [Fact] + public async Task Then_The_Locatie_Is_Ontkoppeld() + { + var scenario = new AdresWerdOvergenomenUitAdressenregisterScenario(); + + var verenigingRepositoryMock = new VerenigingRepositoryMock(scenario.GetVerenigingState()); + + var message = new OntkoppelLocatiesMessage(scenario.VCode, + [ + scenario.LocatieWerdToegevoegd.Locatie.LocatieId, + ]); + + var sut = new OntkoppelLocatiesMessageHandler(verenigingRepositoryMock); + + await sut.Handle(message, CancellationToken.None); + + var adres = scenario.AdresWerdOvergenomenUitAdressenregister.Adres; + + verenigingRepositoryMock.ShouldHaveSaved( + new AdresWerdOntkoppeldVanAdressenregister( + scenario.VCode, + scenario.LocatieWerdToegevoegd.Locatie.LocatieId, + scenario.AdresWerdOvergenomenUitAdressenregister.AdresId, + new Registratiedata.Adres(adres.Straatnaam, adres.Huisnummer, adres.Busnummer, adres.Postcode, adres.Gemeente, + Adres.België))); + } +} diff --git a/test/AssociationRegistry.Test/GrarUpdates/TeOntkoppelenLocatiesHandlerTests/Given_Already_Ontkoppelde_Locatie.cs b/test/AssociationRegistry.Test/GrarUpdates/TeOntkoppelenLocatiesHandlerTests/Given_Already_Ontkoppelde_Locatie.cs new file mode 100644 index 000000000..084ca237f --- /dev/null +++ b/test/AssociationRegistry.Test/GrarUpdates/TeOntkoppelenLocatiesHandlerTests/Given_Already_Ontkoppelde_Locatie.cs @@ -0,0 +1,31 @@ +namespace AssociationRegistry.Test.GrarUpdates.TeOntkoppelenLocatiesHandlerTests; + +using Acties.GrarConsumer.OntkoppelAdres; +using Common.Framework; +using Common.Scenarios.CommandHandling; +using Events; +using Grar.GrarUpdates.Fusies.TeOntkoppelenLocaties; +using Vereniging; +using Xunit; + +public class Given_Already_Ontkoppelde_Locatie +{ + [Fact] + public async Task Then_The_Locatie_Is_Ontkoppeld() + { + var scenario = new AdresWerdOntkoppeldScenario(); + + var verenigingRepositoryMock = new VerenigingRepositoryMock(scenario.GetVerenigingState()); + + var message = new OntkoppelLocatiesMessage(scenario.VCode, + [ + scenario.LocatieWerdToegevoegd.Locatie.LocatieId, + ]); + + var sut = new OntkoppelLocatiesMessageHandler(verenigingRepositoryMock); + + await sut.Handle(message, CancellationToken.None); + + verenigingRepositoryMock.ShouldNotHaveAnySaves(); + } +} diff --git a/test/AssociationRegistry.Test/GrarUpdates/TeOntkoppelenLocatiesHandlerTests/Given_Multiple_Existing_Locaties.cs b/test/AssociationRegistry.Test/GrarUpdates/TeOntkoppelenLocatiesHandlerTests/Given_Multiple_Existing_Locaties.cs new file mode 100644 index 000000000..370c2b1bf --- /dev/null +++ b/test/AssociationRegistry.Test/GrarUpdates/TeOntkoppelenLocatiesHandlerTests/Given_Multiple_Existing_Locaties.cs @@ -0,0 +1,47 @@ +namespace AssociationRegistry.Test.GrarUpdates.TeOntkoppelenLocatiesHandlerTests; + +using Acties.GrarConsumer.OntkoppelAdres; +using Common.Framework; +using Common.Scenarios.CommandHandling; +using Events; +using Grar.GrarUpdates.Fusies.TeOntkoppelenLocaties; +using Vereniging; +using Xunit; + +public class Given_Multiple_Existing_Locatie +{ + [Fact] + public async Task Then_The_Locaties_Are_Ontkoppeld() + { + var scenario = new MultipleAdresWerdOvergenomenUitAdressenregisterScenario(); + + var verenigingRepositoryMock = new VerenigingRepositoryMock(scenario.GetVerenigingState()); + + var message = new OntkoppelLocatiesMessage(scenario.VCode, + [ + scenario.LocatieWerdToegevoegd.Locatie.LocatieId, + scenario.LocatieWerdToegevoegd2.Locatie.LocatieId, + ]); + + var sut = new OntkoppelLocatiesMessageHandler(verenigingRepositoryMock); + + await sut.Handle(message, CancellationToken.None); + + var adres = scenario.AdresWerdOvergenomenUitAdressenregister.Adres; + var adres2 = scenario.AdresWerdOvergenomenUitAdressenregister2.Adres; + + verenigingRepositoryMock.ShouldHaveSaved( + new AdresWerdOntkoppeldVanAdressenregister( + scenario.VCode, + scenario.LocatieWerdToegevoegd.Locatie.LocatieId, + scenario.AdresWerdOvergenomenUitAdressenregister.AdresId, + new Registratiedata.Adres(adres.Straatnaam, adres.Huisnummer, adres.Busnummer, adres.Postcode, adres.Gemeente, + Adres.België)), + new AdresWerdOntkoppeldVanAdressenregister( + scenario.VCode, + scenario.LocatieWerdToegevoegd2.Locatie.LocatieId, + scenario.AdresWerdOvergenomenUitAdressenregister2.AdresId, + new Registratiedata.Adres(adres2.Straatnaam, adres2.Huisnummer, adres2.Busnummer, adres2.Postcode, adres2.Gemeente, + Adres.België))); + } +} diff --git a/test/AssociationRegistry.Test/GrarUpdates/TeOntkoppelenLocatiesHandlerTests/Given_No_Existing_Locatie.cs b/test/AssociationRegistry.Test/GrarUpdates/TeOntkoppelenLocatiesHandlerTests/Given_No_Existing_Locatie.cs new file mode 100644 index 000000000..e54a97398 --- /dev/null +++ b/test/AssociationRegistry.Test/GrarUpdates/TeOntkoppelenLocatiesHandlerTests/Given_No_Existing_Locatie.cs @@ -0,0 +1,32 @@ +namespace AssociationRegistry.Test.GrarUpdates.TeOntkoppelenLocatiesHandlerTests; + +using Acties.GrarConsumer.OntkoppelAdres; +using AutoFixture; +using Common.AutoFixture; +using Common.Framework; +using Common.Scenarios.CommandHandling; +using Grar.GrarUpdates.Fusies.TeOntkoppelenLocaties; +using Xunit; + +public class Given_No_Existing_Locatie +{ + [Fact] + public async Task Then_The_Locaties_Are_Ontkoppeld() + { + var fixture = new Fixture().CustomizeDomain(); + var scenario = new FeitelijkeVerenigingWerdGeregistreerdWithMinimalFields(); + + var verenigingRepositoryMock = new VerenigingRepositoryMock(scenario.GetVerenigingState()); + + var message = fixture.Create() with + { + VCode = scenario.VCode, + }; + + var sut = new OntkoppelLocatiesMessageHandler(verenigingRepositoryMock); + + await sut.Handle(message, CancellationToken.None); + + verenigingRepositoryMock.ShouldNotHaveAnySaves(); + } +} diff --git a/test/AssociationRegistry.Test/When_Heradresseren_Locaties/Given_Multiple_Message_With_Same_IdempotenceKey.cs b/test/AssociationRegistry.Test/When_Heradresseren_Locaties/Given_Multiple_Message_With_Same_IdempotenceKey.cs index 41fea9a60..6224140fc 100644 --- a/test/AssociationRegistry.Test/When_Heradresseren_Locaties/Given_Multiple_Message_With_Same_IdempotenceKey.cs +++ b/test/AssociationRegistry.Test/When_Heradresseren_Locaties/Given_Multiple_Message_With_Same_IdempotenceKey.cs @@ -1,5 +1,6 @@ namespace AssociationRegistry.Test.When_Heradresseren_Locaties; +using Acties.GrarConsumer.HeradresseerLocaties; using AssociationRegistry.Framework; using AutoFixture; using Common.AutoFixture; @@ -8,7 +9,8 @@ using Events; using FluentAssertions; using Grar; -using Grar.HeradresseerLocaties; +using Grar.GrarUpdates.Fusies.TeHeradresserenLocaties; +using Grar.GrarUpdates.Hernummering; using Grar.Models; using Moq; using Xunit; @@ -39,23 +41,23 @@ public async Task Then_A_LocatieWerdToegevoegd_Event_Is_Saved() var locatieId1 = scenario.Locaties.First().LocatieId; var locatieId2 = scenario.Locaties.ToArray()[1].LocatieId; - var message1 = fixture.Create() with + var message1 = fixture.Create() with { - LocatiesMetAdres = new List - { new(locatieId1, AddressId: "123"), new(locatieId2, AddressId: "456") }, + TeHeradresserenLocaties = new List + { new(locatieId1, NaarAdresId: "123"), new(locatieId2, NaarAdresId: "456") }, VCode = scenario.VCode, idempotencyKey = idempotenceKey, }; - var message2 = fixture.Create() with + var message2 = fixture.Create() with { - LocatiesMetAdres = new List - { new(locatieId1, AddressId: "456"), new(locatieId2, AddressId: "123") }, + TeHeradresserenLocaties = new List + { new(locatieId1, NaarAdresId: "456"), new(locatieId2, NaarAdresId: "123") }, VCode = scenario.VCode, idempotencyKey = idempotenceKey + 1, }; - var messageHandler = new TeHeradresserenLocatiesMessageHandler(verenigingRepositoryMock, grarClientMock.Object); + var messageHandler = new HeradresseerLocatiesMessageHandler(verenigingRepositoryMock, grarClientMock.Object); await messageHandler.Handle(message1, CancellationToken.None); await messageHandler.Handle(message2, CancellationToken.None); diff --git a/test/AssociationRegistry.Test/When_Heradresseren_Locaties/With_DecoratingWithPostalInformation.cs b/test/AssociationRegistry.Test/When_Heradresseren_Locaties/With_DecoratingWithPostalInformation.cs index 131c5718d..c7df077f9 100644 --- a/test/AssociationRegistry.Test/When_Heradresseren_Locaties/With_DecoratingWithPostalInformation.cs +++ b/test/AssociationRegistry.Test/When_Heradresseren_Locaties/With_DecoratingWithPostalInformation.cs @@ -1,12 +1,14 @@ namespace AssociationRegistry.Test.When_Heradresseren_Locaties; +using Acties.GrarConsumer.HeradresseerLocaties; using AutoFixture; using Common.AutoFixture; using Common.Framework; using Common.Scenarios.CommandHandling; using Events; using Grar; -using Grar.HeradresseerLocaties; +using Grar.GrarUpdates.Fusies.TeHeradresserenLocaties; +using Grar.GrarUpdates.Hernummering; using Grar.Models; using Grar.Models.PostalInfo; using Moq; @@ -50,15 +52,15 @@ public async Task Then_A_LocatieWerdToegevoegd_Event_Is_Saved() var locatieId = scenario.Locaties.First().LocatieId; - var message = fixture.Create() with + var message = fixture.Create() with { - LocatiesMetAdres = new List - { new(locatieId, AddressId: "123") }, + TeHeradresserenLocaties = new List + { new(locatieId, NaarAdresId: "123") }, VCode = "V001", idempotencyKey = "123456789", }; - var messageHandler = new TeHeradresserenLocatiesMessageHandler(verenigingRepositoryMock, grarClientMock.Object); + var messageHandler = new HeradresseerLocatiesMessageHandler(verenigingRepositoryMock, grarClientMock.Object); var expectedAdres = new AdresDetailUitAdressenregister { diff --git a/test/AssociationRegistry.Test/When_Heradresseren_Locaties/With_Multiple_TeHeradressren_Locaties.cs b/test/AssociationRegistry.Test/When_Heradresseren_Locaties/With_Multiple_TeHeradressren_Locaties.cs index 8736df45f..7281a1134 100644 --- a/test/AssociationRegistry.Test/When_Heradresseren_Locaties/With_Multiple_TeHeradressren_Locaties.cs +++ b/test/AssociationRegistry.Test/When_Heradresseren_Locaties/With_Multiple_TeHeradressren_Locaties.cs @@ -1,12 +1,14 @@ namespace AssociationRegistry.Test.When_Heradresseren_Locaties; +using Acties.GrarConsumer.HeradresseerLocaties; using AutoFixture; using Common.AutoFixture; using Common.Framework; using Common.Scenarios.CommandHandling; using Events; using Grar; -using Grar.HeradresseerLocaties; +using Grar.GrarUpdates.Fusies.TeHeradresserenLocaties; +using Grar.GrarUpdates.Hernummering; using Grar.Models; using Moq; using Xunit; @@ -36,15 +38,15 @@ public async Task Then_A_LocatieWerdToegevoegd_Event_Is_Saved() var locatieId1 = scenario.Locaties.First().LocatieId; var locatieId2 = scenario.Locaties.ToArray()[1].LocatieId; - var message = fixture.Create() with + var message = fixture.Create() with { - LocatiesMetAdres = new List - { new(locatieId1, AddressId: "123"), new(locatieId2, AddressId: "456") }, + TeHeradresserenLocaties = new List + { new(locatieId1, NaarAdresId: "123"), new(locatieId2, NaarAdresId: "456") }, VCode = "V001", idempotencyKey = "123456789", }; - var messageHandler = new TeHeradresserenLocatiesMessageHandler(verenigingRepositoryMock, grarClientMock.Object); + var messageHandler = new HeradresseerLocatiesMessageHandler(verenigingRepositoryMock, grarClientMock.Object); await messageHandler.Handle(message, CancellationToken.None); diff --git a/test/AssociationRegistry.Test/When_Heradresseren_Locaties/With_NonExistingLocatie.cs b/test/AssociationRegistry.Test/When_Heradresseren_Locaties/With_NonExistingLocatie.cs index ca6599f4d..e35bb1423 100644 --- a/test/AssociationRegistry.Test/When_Heradresseren_Locaties/With_NonExistingLocatie.cs +++ b/test/AssociationRegistry.Test/When_Heradresseren_Locaties/With_NonExistingLocatie.cs @@ -1,11 +1,13 @@ namespace AssociationRegistry.Test.When_Heradresseren_Locaties; +using Acties.GrarConsumer.HeradresseerLocaties; using AutoFixture; using Common.AutoFixture; using Common.Framework; using Common.Scenarios.CommandHandling; using Grar; -using Grar.HeradresseerLocaties; +using Grar.GrarUpdates.Fusies.TeHeradresserenLocaties; +using Grar.GrarUpdates.Hernummering; using Grar.Models; using Moq; using Xunit; @@ -33,15 +35,15 @@ public async Task Then_A_LocatieWerdToegevoegd_Event_Is_Saved() var locatieId = scenario.Locaties.First().LocatieId; var nonExistingLocatieId = locatieId * -1; - var message = fixture.Create() with + var message = fixture.Create() with { - LocatiesMetAdres = new List - { new(nonExistingLocatieId, AddressId: "123") }, + TeHeradresserenLocaties = new List + { new(nonExistingLocatieId, NaarAdresId: "123") }, VCode = "V001", idempotencyKey = "123456789", }; - var messageHandler = new TeHeradresserenLocatiesMessageHandler(verenigingRepositoryMock, grarClientMock.Object); + var messageHandler = new HeradresseerLocatiesMessageHandler(verenigingRepositoryMock, grarClientMock.Object); await messageHandler.Handle(message, CancellationToken.None); diff --git a/test/AssociationRegistry.Test/When_Heradresseren_Locaties/With_TeHeradressren_Locaties.cs b/test/AssociationRegistry.Test/When_Heradresseren_Locaties/With_TeHeradressren_Locaties.cs index c39948ad0..be9682d78 100644 --- a/test/AssociationRegistry.Test/When_Heradresseren_Locaties/With_TeHeradressren_Locaties.cs +++ b/test/AssociationRegistry.Test/When_Heradresseren_Locaties/With_TeHeradressren_Locaties.cs @@ -1,12 +1,14 @@ namespace AssociationRegistry.Test.When_Heradresseren_Locaties; +using Acties.GrarConsumer.HeradresseerLocaties; using AutoFixture; using Common.AutoFixture; using Common.Framework; using Common.Scenarios.CommandHandling; using Events; using Grar; -using Grar.HeradresseerLocaties; +using Grar.GrarUpdates.Fusies.TeHeradresserenLocaties; +using Grar.GrarUpdates.Hernummering; using Grar.Models; using Moq; using Xunit; @@ -33,15 +35,15 @@ public async Task Then_A_LocatieWerdToegevoegd_Event_Is_Saved() var locatieId = scenario.Locaties.First().LocatieId; - var message = fixture.Create() with + var message = fixture.Create() with { - LocatiesMetAdres = new List - { new(locatieId, AddressId: "123") }, + TeHeradresserenLocaties = new List + { new(locatieId, NaarAdresId: "123") }, VCode = "V001", idempotencyKey = "123456789", }; - var messageHandler = new TeHeradresserenLocatiesMessageHandler(verenigingRepositoryMock, grarClientMock.Object); + var messageHandler = new HeradresseerLocatiesMessageHandler(verenigingRepositoryMock, grarClientMock.Object); await messageHandler.Handle(message, CancellationToken.None);