Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Or 2334 #1022

Merged
merged 22 commits into from
Dec 11, 2024
Merged

Or 2334 #1022

Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2657e23
test: or-2334 write e2e test for markeer als dubbel van
emalfroy Dec 10, 2024
ad26326
feat: or-2334 add controller & command for markeer als dubbel van
emalfroy Dec 10, 2024
855b5c1
ftest or-2334 add validator checks for validity and empty values
Dec 10, 2024
c0b130e
test: or-2334 check conversion from request to command
Dec 10, 2024
dfe19c9
fix: or-2334 correct endpoint route and documentation
Dec 10, 2024
0583c33
chore: or-2334 add initial setup for projections for markeer als dubbel
Dec 10, 2024
439db6e
feat: or-2334 complete beheer detail flow for markeer als dubbel van
emalfroy Dec 10, 2024
5929882
test: or-2334 write tests for MarkeerAlsDubbelVanHandler
emalfroy Dec 10, 2024
f5763f4
test: or-2334 set isDubbelVan to string.empty for v1 projection tests
emalfroy Dec 10, 2024
540d7a3
wip: or-2334 voeg dubbele vereniging toe message handler
Dec 10, 2024
b16b2d0
test: or-2334 verify outbox message is sent when marking as double
koenmetsu Dec 10, 2024
182284e
test: or-2334 add tests for VoegDubbelToeMessageHandler
emalfroy Dec 11, 2024
168869f
refactor: or-2334 rename properties dubbel events and command
emalfroy Dec 11, 2024
bf6b656
refactor: or-2334 make distinction between messages and commands
emalfroy Dec 11, 2024
333c26b
refactor: or-2334 rename to aanvaard dubbele vereniging
koenmetsu Dec 11, 2024
71dd88a
feat: or-2334 add aanvaarde vereniging to corresponderende vcodes of …
koenmetsu Dec 11, 2024
71e1b50
fix: or-2334 use primitive string io vCode in wolverine messages
koenmetsu Dec 11, 2024
8685fcc
fix: or-2334 combine empty and null validation
koenmetsu Dec 11, 2024
3aafde8
fix: or-2334 fix exception message VerenigingKanGeenDubbelWordenVanVe…
emalfroy Dec 11, 2024
e93901c
feat: or-2334 implement public detail for dubbels
emalfroy Dec 11, 2024
32d532b
fix: or-2334 also return verenigingen with status dubbel for publiek …
emalfroy Dec 11, 2024
2bdd6d7
test: or-2334 add e2e test for authentieke vereniging publiek detail
emalfroy Dec 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<ItemGroup>
<Folder Include="GrarConsumer\Handlers\Fusies\" />
<Folder Include="Infrastructure\ConfigurationBindings\" />
<Folder Include="MessageHandling\Postgres\" />
<Folder Include="Verenigingen\Contactgegevens\FeitelijkeVereniging\" />
<Folder Include="Verenigingen\Vertegenwoordigers\FeitelijkeVereniging\" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
using Grar.AddressMatch;
using Hosts.Configuration;
using JasperFx.CodeGeneration;
using MessageHandling.Postgres.Dubbels;
using Messages;
using Serilog;
using Vereniging;
using Wolverine;
using Wolverine.AmazonSqs;
using Wolverine.ErrorHandling;
using Wolverine.Postgresql;

public static class WolverineExtensions
{
public static void AddWolverine(this WebApplicationBuilder builder)
{
const string AanvaardDubbeleVerenigingQueueName = "aanvaard-dubbele-vereniging-queue";

builder.Host.UseWolverine(
(context, options) =>
{
Expand All @@ -26,6 +31,8 @@ public static void AddWolverine(this WebApplicationBuilder builder)
options.Discovery.IncludeType<TeAdresMatchenLocatieMessageHandler>();
options.Discovery.IncludeType<OverkoepelendeGrarConsumerMessage>();
options.Discovery.IncludeType<OverkoepelendeGrarConsumerMessageHandler>();
options.Discovery.IncludeType<AanvaardDubbeleVerenigingMessage>();
options.Discovery.IncludeType<AanvaardDubbeleVerenigingMessageHandler>();

options.OnException<UnexpectedAggregateVersionDuringSyncException>().RetryWithCooldown(
TimeSpan.FromSeconds(1),
Expand All @@ -50,12 +57,19 @@ public static void AddWolverine(this WebApplicationBuilder builder)

ConfigureAddressMatchPublisher(options, grarOptions.Sqs.AddressMatchQueueName);

ConfiguredAddressMatchListener(options, grarOptions.Sqs.AddressMatchQueueName,
ConfigureAddressMatchListener(options, grarOptions.Sqs.AddressMatchQueueName,
grarOptions.Sqs.AddressMatchDeadLetterQueueName);

ConfigureGrarSyncListener(options, grarOptions.Sqs.GrarSyncQueueName, grarOptions.Sqs.GrarSyncDeadLetterQueueName,
grarOptions.Sqs.GrarSyncQueueListenerEnabled);

options.PersistMessagesWithPostgresql(context.Configuration.GetPostgreSqlOptionsSection().GetConnectionString());

options.PublishMessage<AanvaardDubbeleVerenigingMessage>()
.ToPostgresqlQueue(AanvaardDubbeleVerenigingQueueName);

options.ListenToPostgresqlQueue(AanvaardDubbeleVerenigingQueueName);

if (grarOptions.Wolverine.AutoProvision)
transportConfiguration.AutoProvision();

Expand All @@ -73,7 +87,7 @@ private static void ConfigureAddressMatchPublisher(WolverineOptions options, str
.MessageBatchSize(1);
}

private static void ConfiguredAddressMatchListener(WolverineOptions options, string sqsQueueName, string sqsDeadLetterQueueName)
private static void ConfigureAddressMatchListener(WolverineOptions options, string sqsQueueName, string sqsDeadLetterQueueName)
{
options.ListenToSqsQueue(sqsQueueName, configure: configure =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace AssociationRegistry.Admin.Api.Infrastructure.ResponseWriter;

using AssociationRegistry.Admin.Api.Infrastructure.Extensions;
using Extensions;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Microsoft.AspNetCore.Mvc;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace AssociationRegistry.Admin.Api.Infrastructure.Sequence;

using AssociationRegistry.Admin.Api.Infrastructure.Extensions;
using AssociationRegistry.Admin.Schema.Detail;
using AssociationRegistry.EventStore;
using Extensions;
using Schema.Detail;
using EventStore;
using Marten;

public class SequenceGuarder : ISequenceGuarder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace AssociationRegistry.Admin.Api.Infrastructure.Validation;

using AssociationRegistry.Admin.Api.Infrastructure.ExceptionHandlers;
using ExceptionHandlers;
using FluentValidation;
using System.Diagnostics.CodeAnalysis;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace AssociationRegistry.Admin.Api.MessageHandling.Postgres.Dubbels;

using Messages;
using Wolverine;

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

await messageBus.InvokeAsync(command, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private static VerenigingDetail Map(
Relaties = vereniging.Relaties.Select(relatie => Map(relatie, baseUrl)).ToArray(),
Lidmaatschappen = vereniging.Lidmaatschappen.Select(lidmaatschap => Map(lidmaatschap, namenVoorLidmaatschapMapper)).ToArray(),
Bron = vereniging.Bron,
IsDubbelVan = vereniging.IsDubbelVan,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,8 @@ public class VerenigingDetail
/// </summary>
[DataMember(Name = "Bron")]
public string Bron { get; set; } = null!;

/// <summary>De VCode van de vereniging waarvan deze vereniging een dubbel is</summary>
[DataMember(Name = "IsDubbelVan")]
public string IsDubbelVan { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace AssociationRegistry.Admin.Api.Verenigingen.Dubbels.FeitelijkeVereniging.MarkeerAlsDubbelVan.Examples;

using RequestModels;
using Swashbuckle.AspNetCore.Filters;

public class MarkeerAlsDubbelVanRequestExamples : IExamplesProvider<MarkeerAlsDubbelVanRequest>
{
public MarkeerAlsDubbelVanRequest GetExamples()
=> new()
{
IsDubbelVan = "V0001002",
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
namespace AssociationRegistry.Admin.Api.Verenigingen.Dubbels.FeitelijkeVereniging.MarkeerAlsDubbelVan;

using Acties.MarkeerAlsDubbelVan;
using Asp.Versioning;
using Be.Vlaanderen.Basisregisters.Api;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Examples;
using FluentValidation;
using Framework;
using Hosts.Configuration.ConfigurationBindings;
using Infrastructure;
using Infrastructure.Extensions;
using Infrastructure.Middleware;
using Infrastructure.Swagger.Annotations;
using Infrastructure.Swagger.Examples;
using Infrastructure.Validation;
using Microsoft.AspNetCore.Mvc;
using RequestModels;
using Swashbuckle.AspNetCore.Filters;
using Vereniging;
using Wolverine;
using ProblemDetails = Be.Vlaanderen.Basisregisters.BasicApiProblem.ProblemDetails;
using ValidationProblemDetails = Be.Vlaanderen.Basisregisters.BasicApiProblem.ValidationProblemDetails;

[ApiVersion("1.0")]
[AdvertiseApiVersions("1.0")]
[ApiRoute("verenigingen")]
[SwaggerGroup.DecentraalBeheer]
public class MarkeerAlsDubbelVanController : ApiController
{
private readonly IMessageBus _messageBus;
private readonly IValidator<MarkeerAlsDubbelVanRequest> _validator;
private readonly AppSettings _appSettings;

public MarkeerAlsDubbelVanController(IMessageBus messageBus, IValidator<MarkeerAlsDubbelVanRequest> validator, AppSettings appSettings)
{
_messageBus = messageBus;
_validator = validator;
_appSettings = appSettings;
}

/// <summary>
/// Markeer een vereniging als dubbel van een andere vereniging.
/// </summary>
/// <remarks>
/// Na het uitvoeren van deze actie wordt een sequentie teruggegeven via de `VR-Sequence` header.
/// Deze waarde kan gebruikt worden in andere endpoints om op te volgen of de aanpassing
/// al is doorgestroomd naar deze endpoints.
/// </remarks>
/// <param name="vCode">De vCode van de vereniging.</param>
/// <param name="request">De gegevens van de andere vereniging waarvan deze een dubbel is.</param>
/// <param name="metadataProvider"></param>
/// <param name="ifMatch">If-Match header met ETag van de laatst gekende versie van de vereniging.</param>
/// <response code="202">De vereniging werd als dubbel gemarkeerd.</response>
/// <response code="400">Er was een probleem met de doorgestuurde waarden.</response>
/// <response code="412">De gevraagde vereniging heeft niet de verwachte sequentiewaarde.</response>
/// <response code="500">Er is een interne fout opgetreden.</response>
[HttpPost("{vCode}/dubbelVan")]
[ConsumesJson]
[ProducesJson]
[SwaggerRequestExample(typeof(MarkeerAlsDubbelVanRequest), typeof(MarkeerAlsDubbelVanRequestExamples))]
[SwaggerResponseHeader(StatusCodes.Status202Accepted, WellknownHeaderNames.Sequence, type: "string",
description: "Het sequence nummer van deze request.")]
[SwaggerResponseHeader(StatusCodes.Status202Accepted, name: "ETag", type: "string",
description: "De versie van de vereniging die als dubbel werd gemarkeerd.")]
[SwaggerResponseExample(StatusCodes.Status400BadRequest, typeof(ProblemAndValidationProblemDetailsExamples))]
[SwaggerResponseExample(StatusCodes.Status412PreconditionFailed, typeof(PreconditionFailedProblemDetailsExamples))]
[SwaggerResponseExample(StatusCodes.Status500InternalServerError, typeof(InternalServerErrorResponseExamples))]
[ProducesResponseType(StatusCodes.Status202Accepted)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status412PreconditionFailed)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> Post(
[FromRoute] string vCode,
[FromBody] MarkeerAlsDubbelVanRequest request,
[FromServices] ICommandMetadataProvider metadataProvider,
[FromHeader(Name = "If-Match")] string? ifMatch = null)
{
await _validator.NullValidateAndThrowAsync(request);

var metaData = metadataProvider.GetMetadata(IfMatchParser.ParseIfMatch(ifMatch));
var envelope = new CommandEnvelope<MarkeerAlsDubbelVanCommand>(request.ToCommand(vCode), metaData);
var commandResult = await _messageBus.InvokeAsync<CommandResult>(envelope);

return this.AcceptedCommand(_appSettings, commandResult);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace AssociationRegistry.Admin.Api.Verenigingen.Dubbels.FeitelijkeVereniging.MarkeerAlsDubbelVan;

using FluentValidation;
using Infrastructure.Validation;
using RequestModels;

// ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
public class MarkeerAlsDubbelVanValidator : AbstractValidator<MarkeerAlsDubbelVanRequest>
{
public MarkeerAlsDubbelVanValidator()
{
RuleFor(r => r.IsDubbelVan)
.NotNull()
.NotEmpty()
.WithVeldIsVerplichtMessage(nameof(MarkeerAlsDubbelVanRequest.IsDubbelVan));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace AssociationRegistry.Admin.Api.Verenigingen.Dubbels.FeitelijkeVereniging.MarkeerAlsDubbelVan.RequestModels;

using Acties.MarkeerAlsDubbelVan;
using System.Runtime.Serialization;
using Vereniging;

[DataContract]
public class MarkeerAlsDubbelVanRequest
{
/// <summary>De VCode van de vereniging waarvan deze vereniging een dubbel is.</summary>
[DataMember(Name = "isDubbelVan")]
public string IsDubbelVan { get; set; } = null!;

public MarkeerAlsDubbelVanCommand ToCommand(string vCode)
=> new(VCode.Create(vCode), VCode.Create(IsDubbelVan));
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
namespace AssociationRegistry.Admin.Api.Verenigingen.Registreer.MetRechtspersoonlijkheid.RequestModels;

using AssociationRegistry.Admin.Api.Infrastructure.Validation;
using Infrastructure.Validation;
using FluentValidation;

public class RegistreerVerenigingUitKboRequestValidator : AbstractValidator<RegistreerVerenigingUitKboRequest>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ public async Task Project(IEvent<LidmaatschapWerdGewijzigd> @event, IDocumentOpe
public async Task Project(IEvent<LidmaatschapWerdVerwijderd> @event, IDocumentOperations ops)
=> await Update(@event, ops, BeheerVerenigingDetailProjector.Apply);

public async Task Project(IEvent<VerenigingWerdGermarkeerdAlsDubbelVan> @event, IDocumentOperations ops)
=> await Update(@event, ops, BeheerVerenigingDetailProjector.Apply);

public async Task Project(IEvent<VerenigingAanvaardeDubbeleVereniging> @event, IDocumentOperations ops)
=> await Update(@event, ops, BeheerVerenigingDetailProjector.Apply);

private async Task SoftDelete(string? streamKey, IDocumentOperations ops)
=> ops.Delete<BeheerVerenigingDetailDocument>(streamKey);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static BeheerVerenigingDetailDocument Create(IEvent<FeitelijkeVerenigingW
.FormatAsBelgianDate(),
Status = VerenigingStatus.Actief,
IsUitgeschrevenUitPubliekeDatastroom = feitelijkeVerenigingWerdGeregistreerd.Data.IsUitgeschrevenUitPubliekeDatastroom,
IsDubbelVan = "",
Contactgegevens = feitelijkeVerenigingWerdGeregistreerd.Data.Contactgegevens
.Select(c => BeheerVerenigingDetailMapper.MapContactgegeven(
c, feitelijkeVerenigingWerdGeregistreerd.Data.Bron,
Expand Down Expand Up @@ -90,6 +91,7 @@ public static BeheerVerenigingDetailDocument Create(
DatumLaatsteAanpassing = verenigingMetRechtspersoonlijkheidWerdGeregistreerd.GetHeaderInstant(MetadataHeaderNames.Tijdstip).FormatAsBelgianDate(),
Status = VerenigingStatus.Actief,
IsUitgeschrevenUitPubliekeDatastroom = false,
IsDubbelVan = "",
Contactgegevens = [],
Locaties = [],
Vertegenwoordigers = [],
Expand Down Expand Up @@ -746,4 +748,19 @@ public static void Apply(IEvent<LidmaatschapWerdVerwijderd> lidmaatschapWerdToeg
.OrderBy(l => l.LidmaatschapId)
.ToArray();
}


public static void Apply(IEvent<VerenigingWerdGermarkeerdAlsDubbelVan> verenigingWerdGemarkeerdAlsDubbel, BeheerVerenigingDetailDocument document)
{
document.Status = VerenigingStatus.Dubbel;
document.IsDubbelVan = verenigingWerdGemarkeerdAlsDubbel.Data.VCodeAuthentiekeVereniging;
}

public static void Apply(IEvent<VerenigingAanvaardeDubbeleVereniging> verenigingAanvaardeDubbeleVereniging, BeheerVerenigingDetailDocument document)
{
document.CorresponderendeVCodes =
document.CorresponderendeVCodes
.Append(verenigingAanvaardeDubbeleVereniging.Data.VCodeDubbeleVereniging)
.ToArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public static class VerenigingStatus
{
public const string Actief = "Actief";
public const string Gestopt = "Gestopt";
public const string Dubbel = "Dubbel";
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ public record BeheerVerenigingDetailDocument : IVCode, ISoftDeleted, IMetadata
[Identity] public string VCode { get; init; } = null!;
public bool Deleted { get; set; }
public DateTimeOffset? DeletedAt { get; set; }
public string IsDubbelVan { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace AssociationRegistry.Acties.AanvaardDubbel;

using AssociationRegistry.Vereniging;

public record AanvaardDubbeleVerenigingCommand(VCode VCode, VCode VCodeDubbeleVereniging);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace AssociationRegistry.Acties.AanvaardDubbel;

using AssociationRegistry.EventStore;
using AssociationRegistry.Framework;
using AssociationRegistry.Vereniging;
using NodaTime;

public class AanvaardDubbeleVerenigingCommandHandler(IVerenigingsRepository repository)
{
public async Task Handle(AanvaardDubbeleVerenigingCommand command, CancellationToken cancellationToken)
{
var vereniging = await repository.Load<Vereniging>(command.VCode);

vereniging.AanvaardDubbeleVereniging(command.VCodeDubbeleVereniging);

await repository.Save(
vereniging,
new CommandMetadata(EventStore.DigitaalVlaanderenOvoNumber,
SystemClock.Instance.GetCurrentInstant(),
Guid.NewGuid()),
cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace AssociationRegistry.Acties.MarkeerAlsDubbelVan;

using Vereniging;

public record MarkeerAlsDubbelVanCommand(VCode VCode, VCode VCodeAuthentiekeVereniging);
Loading
Loading