Skip to content

Commit

Permalink
feat: or-2031 registreer inschrijving when adding kbo verenigingen
Browse files Browse the repository at this point in the history
  • Loading branch information
koenmetsu committed Feb 9, 2024
1 parent 3e6185d commit e2f18b4
Show file tree
Hide file tree
Showing 117 changed files with 5,728 additions and 239 deletions.
10 changes: 10 additions & 0 deletions AssociationRegistry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "mappings", "mappings", "{9E
wiremock\mappings\GeefOnderneming.notfound.json = wiremock\mappings\GeefOnderneming.notfound.json
wiremock\mappings\GeefOnderneming.vestiging.json = wiremock\mappings\GeefOnderneming.vestiging.json
wiremock\mappings\projectionactions.json = wiremock\mappings\projectionactions.json
wiremock\mappings\RegistreerInschrijving.json = wiremock\mappings\RegistreerInschrijving.json
wiremock\mappings\RegistreerInschrijving.connection-failure.json = wiremock\mappings\RegistreerInschrijving.connection-failure.json
wiremock\mappings\RegistreerInschrijving.uitzondering.fout.json = wiremock\mappings\RegistreerInschrijving.uitzondering.fout.json
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssociationRegistry.Magda", "src\AssociationRegistry.Magda\AssociationRegistry.Magda.csproj", "{85139412-485D-4B23-8423-A0C2021B60DE}"
Expand All @@ -113,6 +116,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GeefOndernemingResponses",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssociationRegistry.Hosts", "src\AssociationRegistry.Hosts\AssociationRegistry.Hosts.csproj", "{F0853B2C-FEAB-4ACF-92D5-D9FBC3DA1427}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "RegistreerInschrijvingResponses", "RegistreerInschrijvingResponses", "{598628E9-81AA-41EE-8F2A-C9607A2D294A}"
ProjectSection(SolutionItems) = preProject
wiremock\__files\RegistreerInschrijvingResponses\RegistreerInschrijvingResponse.xml = wiremock\__files\RegistreerInschrijvingResponses\RegistreerInschrijvingResponse.xml
wiremock\__files\RegistreerInschrijvingResponses\0725459040.uitzondering.fout.xml = wiremock\__files\RegistreerInschrijvingResponses\0725459040.uitzondering.fout.xml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -211,5 +220,6 @@ Global
{85139412-485D-4B23-8423-A0C2021B60DE} = {1157AB42-EACF-454D-92D5-DBA9FF3D0E24}
{9C2CDA4C-FFF3-4AA1-B31A-8804D98F0469} = {A30C8928-5F0D-459A-BB1B-0AE24A160CBB}
{F0853B2C-FEAB-4ACF-92D5-D9FBC3DA1427} = {20B970CD-1737-4427-A924-D299A42346FE}
{598628E9-81AA-41EE-8F2A-C9607A2D294A} = {A30C8928-5F0D-459A-BB1B-0AE24A160CBB}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions AssociationRegistry.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Feitelijke/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=foezie/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Geregistreerd/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=historiek/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=hoofdactivititeit/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=hoofdactivititeiten/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=identificator/@EntryIndexedValue">True</s:Boolean>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace AssociationRegistry.Admin.Api.Infrastructure.Extensions;
using Schema;
using Schema.Detail;
using Schema.Historiek;
using Schema.KboSync;
using System;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -38,6 +39,9 @@ private static ShardName GetShardName<T>() where T : IMetadata
if (typeof(T) == typeof(BeheerVerenigingHistoriekDocument))
return new ShardName("AssociationRegistry.Admin.ProjectionHost.Projections.Historiek.BeheerVerenigingHistoriekProjection");

if (typeof(T) == typeof(BeheerKboSyncHistoriekGebeurtenisDocument))
return new ShardName("AssociationRegistry.Admin.ProjectionHost.Projections.KboSync.BeheerKboSyncHistoriekProjection");

throw new NotImplementedException("ExpectedSequence is voor deze projectie niet ondersteund.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ public class MagdaGeefVerenigingService : IMagdaGeefVerenigingService
};

private readonly IMagdaCallReferenceRepository _magdaCallReferenceRepository;
private readonly IMagdaFacade _magdaFacade;
private readonly IMagdaClient _magdaClient;
private readonly TemporaryMagdaVertegenwoordigersSection _temporaryMagdaVertegenwoordigersSection;
private readonly ILogger<MagdaGeefVerenigingService> _logger;

public MagdaGeefVerenigingService(
IMagdaCallReferenceRepository magdaCallReferenceRepository,
IMagdaFacade magdaFacade,
IMagdaClient magdaClient,
TemporaryMagdaVertegenwoordigersSection temporaryMagdaVertegenwoordigersSection,
ILogger<MagdaGeefVerenigingService> logger)
{
_magdaCallReferenceRepository = magdaCallReferenceRepository;
_magdaFacade = magdaFacade;
_magdaClient = magdaClient;
_temporaryMagdaVertegenwoordigersSection = temporaryMagdaVertegenwoordigersSection;
_logger = logger;
}
Expand All @@ -56,7 +56,7 @@ public async Task<Result<VerenigingVolgensKbo>> GeefVereniging(
var reference = await CreateReference(_magdaCallReferenceRepository, metadata.Initiator, metadata.CorrelationId, kboNummer,
cancellationToken);

var magdaResponse = await _magdaFacade.GeefOnderneming(kboNummer, reference);
var magdaResponse = await _magdaClient.GeefOnderneming(kboNummer, reference);

if (MagdaResponseValidator.HasBlokkerendeUitzonderingen(magdaResponse))
return HandleUitzonderingen(kboNummer, magdaResponse);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
namespace AssociationRegistry.Admin.Api.Magda;

using AssociationRegistry.Magda;
using AssociationRegistry.Magda.Exceptions;
using AssociationRegistry.Magda.Models;
using AssociationRegistry.Magda.Repertorium.RegistreerInschrijving;
using Framework;
using Kbo;
using Microsoft.Extensions.Logging;
using ResultNet;
using System;
using System.Threading;
using System.Threading.Tasks;
using Vereniging;

public class MagdaRegistreerInschrijvingService : IMagdaRegistreerInschrijvingService
{
private readonly IMagdaCallReferenceRepository _magdaCallReferenceRepository;
private readonly IMagdaClient _magdaClient;
private readonly ILogger<MagdaRegistreerInschrijvingService> _logger;

public MagdaRegistreerInschrijvingService(
IMagdaCallReferenceRepository magdaCallReferenceRepository,
IMagdaClient magdaClient,
ILogger<MagdaRegistreerInschrijvingService> logger)
{
_magdaCallReferenceRepository = magdaCallReferenceRepository;
_magdaClient = magdaClient;
_logger = logger;
}

public async Task<Result> RegistreerInschrijving(
KboNummer kboNummer,
CommandMetadata metadata,
CancellationToken cancellationToken)
{
try
{
var reference = await CreateReference(
_magdaCallReferenceRepository,
metadata.Initiator,
metadata.CorrelationId,
kboNummer,
cancellationToken);

var response = await _magdaClient.RegistreerInschrijving(kboNummer, reference);

var uitzonderingen = response?.Body?.RegistreerInschrijvingResponse?.Repliek.Antwoorden.Antwoord.Uitzonderingen;

_logger.LogInformation(
"Uitzondering bij het aanroepen van de Magda GeefOnderneming service voor KBO-nummer {KboNummer}: " +
"\nFouten:\n'{Uitzonderingen}'" +
"\nWaarschuwingen:\n'{Waarschuwingen}'" +
"\nInformatie:\n'{Informatie}'",
kboNummer,
uitzonderingen?.ConcatenateUitzonderingen(separator: "\n", UitzonderingTypeType.FOUT),
uitzonderingen?.ConcatenateUitzonderingen(separator: "\n", UitzonderingTypeType.WAARSCHUWING),
uitzonderingen?.ConcatenateUitzonderingen(separator: "\n", UitzonderingTypeType.INFORMATIE));


return response?.Body?.RegistreerInschrijvingResponse?.Repliek.Antwoorden.Antwoord.Inhoud.Resultaat.Value == ResultaatEnumType.Item1 ? Result.Success() : Result.Failure();
}
catch (Exception e)
{
throw new MagdaException(
message: "Er heeft zich een fout voorgedaan bij het aanroepen van de Magda RegistreerInschrijvingDienst.", e);
}
}

private static async Task<MagdaCallReference> CreateReference(
IMagdaCallReferenceRepository repository,
string initiator,
Guid correlationId,
string opgevraagdOnderwerp,
CancellationToken cancellationToken)
{
var magdaCallReference = new MagdaCallReference
{
Reference = Guid.NewGuid(),
CalledAt = DateTimeOffset.UtcNow,
Initiator = initiator,
OpgevraagdeDienst = "RegistreerInschrijvingDienst-02.01",
Context = "Registreer inschrijving voor vereniging met rechtspersoonlijkheid",
AanroependeDienst = "Verenigingsregister Beheer Api",
CorrelationId = correlationId,
OpgevraagdOnderwerp = opgevraagdOnderwerp,
};

await repository.Save(magdaCallReference, cancellationToken);

return magdaCallReference;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ namespace AssociationRegistry.Admin.Api.Magda;

using AssociationRegistry.Magda.Models;
using AssociationRegistry.Magda.Models.GeefOnderneming;
using AssociationRegistry.Magda.Onderneming.GeefOnderneming;
using AssociationRegistry.Magda.Repertorium.RegistreerInschrijving;
using System;
using System.Linq;
using UitzonderingType = AssociationRegistry.Magda.Onderneming.GeefOnderneming.UitzonderingType;
using UitzonderingTypeType = AssociationRegistry.Magda.Onderneming.GeefOnderneming.UitzonderingTypeType;

public static class MagdaResponseExtensions
{
Expand All @@ -17,6 +19,15 @@ public static string ConcatenateUitzonderingen(
source.Where(type => type.Type == uitzonderingTypeType)
.Select(type => $"{type.Identificatie} - {type.Diagnose} - {type.Omstandigheid}"));

public static string ConcatenateUitzonderingen(
this AssociationRegistry.Magda.Repertorium.RegistreerInschrijving.UitzonderingType[] source,
string separator,
AssociationRegistry.Magda.Repertorium.RegistreerInschrijving.UitzonderingTypeType uitzonderingTypeType)
=> string.Join(
separator,
source.Where(type => type.Type == uitzonderingTypeType)
.Select(type => $"{type.Identificatie} - {type.Diagnose} - {type.Omstandigheid}"));

public static bool HasUitzonderingenOfType(
this ResponseEnvelope<GeefOndernemingResponseBody>? source,
UitzonderingTypeType uitzonderingTypeType)
Expand Down
6 changes: 3 additions & 3 deletions src/AssociationRegistry.Admin.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ namespace AssociationRegistry.Admin.Api;
using VCodeGeneration;
using Vereniging;
using Wolverine;
using IEventStore = EventStore.IEventStore;

public class Program
{
Expand Down Expand Up @@ -153,7 +152,7 @@ public static async Task Main(string[] args)
.ToList()
.ForEach(key =>
{
app.Services.GetRequiredService<ILogger<Program>>().LogInformation("Archiving {Stream}", key);
app.Services.GetRequiredService<ILogger<Program>>().LogInformation(message: "Archiving {Stream}", key);
session.Events.ArchiveStream(key);
});

Expand Down Expand Up @@ -324,7 +323,8 @@ private static void ConfigureServices(WebApplicationBuilder builder)
.AddTransient<IVerenigingsRepository, VerenigingsRepository>()
.AddTransient<IDuplicateVerenigingDetectionService, SearchDuplicateVerenigingDetectionService>()
.AddTransient<IMagdaGeefVerenigingService, MagdaGeefVerenigingService>()
.AddTransient<IMagdaFacade, MagdaFacade>()
.AddTransient<IMagdaRegistreerInschrijvingService, MagdaRegistreerInschrijvingService>()
.AddTransient<IMagdaClient, MagdaClient>()
.AddTransient<IMagdaCallReferenceRepository, MagdaCallReferenceRepository>()
.AddMarten(postgreSqlOptionsSection, builder.Configuration)
.AddElasticSearch(elasticSearchOptionsSection)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
namespace AssociationRegistry.Admin.Api.Verenigingen.KboSync;

using Be.Vlaanderen.Basisregisters.Api;
using Be.Vlaanderen.Basisregisters.Api.Exceptions;
using Historiek.Examples;
using Infrastructure.Swagger.Annotations;
using Marten;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ResponseModels;
using Schema.KboSync;
using Swashbuckle.AspNetCore.Filters;
using System.Threading.Tasks;
using ProblemDetails = Be.Vlaanderen.Basisregisters.BasicApiProblem.ProblemDetails;

[ApiVersion("1.0")]
[AdvertiseApiVersions("1.0")]
[ApiRoute("verenigingen")]
[ApiExplorerSettings(IgnoreApi = true)]
[Authorize(Policy = Program.SuperAdminPolicyName)]
public class KboSyncHistoriekController : ApiController
{
private readonly KboSyncHistoriekResponseMapper _mapper;

public KboSyncHistoriekController(KboSyncHistoriekResponseMapper mapper)
{
_mapper = mapper;
}

/// <summary>
/// Vraag de historiek van de KBO sync op.
/// </summary>
/// <param name="documentStore"></param>
/// <param name="problemDetailsHelper"></param>
/// <response code="200">De historiek van de KBO sync</response>
/// <response code="500">Er is een interne fout opgetreden.</response>
[HttpGet("kbo/historiek")]
[SwaggerResponseExample(StatusCodes.Status200OK, typeof(HistoriekResponseExamples))]
[SwaggerResponseExample(StatusCodes.Status500InternalServerError, typeof(InternalServerErrorResponseExamples))]
[ProducesResponseType(typeof(KboSyncHistoriekResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
[ProducesJson]
public async Task<IActionResult> GetKboSyncHistoriek(
[FromServices] IDocumentStore documentStore,
[FromServices] ProblemDetailsHelper problemDetailsHelper
)
{
await using var session = documentStore.LightweightSession();

var gebeurtenissen = await session
.Query<BeheerKboSyncHistoriekGebeurtenisDocument>()
.OrderByDescending(nameof(BeheerKboSyncHistoriekGebeurtenisDocument.Sequence))
.ToListAsync();

var response = _mapper.Map(gebeurtenissen);

return Ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace AssociationRegistry.Admin.Api.Verenigingen.KboSync;

using Infrastructure.ConfigurationBindings;
using ResponseModels;
using Schema.KboSync;
using System.Collections.Generic;
using System.Linq;

public class KboSyncHistoriekResponseMapper
{
private readonly AppSettings _appSettings;

public KboSyncHistoriekResponseMapper(AppSettings appSettings)
{
_appSettings = appSettings;
}

public KboSyncHistoriekResponse Map(IEnumerable<BeheerKboSyncHistoriekGebeurtenisDocument> gebeurtenissen)
=> new(gebeurtenissen.Select(Map).ToArray());

private static KboSyncHistoriekGebeurtenisResponse Map(BeheerKboSyncHistoriekGebeurtenisDocument gebeurtenisDocument)
=> new()
{
Kbonummer = gebeurtenisDocument.Kbonummer,
VCode = gebeurtenisDocument.VCode,
Beschrijving = gebeurtenisDocument.Beschrijving,
Tijdstip = gebeurtenisDocument.Tijdstip,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace AssociationRegistry.Admin.Api.Verenigingen.KboSync.ResponseModels;

using System.Runtime.Serialization;

/// <summary>Een gebeurtenis van een vereniging</summary>
[DataContract]
public class KboSyncHistoriekGebeurtenisResponse
{
/// <summary>Het KBO nummer waarop de gebeurtenis plaatsvond</summary>
[DataMember(Name = "kbonummer")]
public string Kbonummer { get; set; } = null!;

/// <summary>De unieke identificatie code van deze vereniging</summary>
[DataMember(Name = "vCode")]
public string VCode { get; init; } = null!;

/// <summary>De beschrijving van de gebeurtenis</summary>
[DataMember(Name = "beschrijving")]
public string Beschrijving { get; set; } = null!;

/// <summary>Het tijdstip waarop de gebeurtenis plaatsvond</summary>
[DataMember(Name = "tijdstip")]
public string Tijdstip { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace AssociationRegistry.Admin.Api.Verenigingen.KboSync.ResponseModels;

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;

/// <summary>Alle gebeurtenissen van deze vereniging</summary>
[DataContract]
public class KboSyncHistoriekResponse : ReadOnlyCollection<KboSyncHistoriekGebeurtenisResponse>
{
public KboSyncHistoriekResponse(IList<KboSyncHistoriekGebeurtenisResponse> gebeurtenissen) : base(gebeurtenissen)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@
"SuperAdminClientIds": [
"superAdminClient"
],

"MagdaOptions": {
"Afzender": "1234",
"Hoedanigheid": "1234",
"Ontvanger": "vip.vlaanderen.be",
"GeefOndernemingVkboEndpoint": "https://123.abc",
"GeefOndernemingVkboEndpoint": "http://localhost:8080/GeefOndernemingVkboDienst-02.00/soap/WebService",
"GeefOndernemingEndpoint": "http://localhost:8080/GeefOndernemingDienst-02.00/soap/WebService",
"RegistreerInschrijvingEndpoint": "http://localhost:8080/RegistreerInschrijvingDienst-02.01/soap/WebService",
"Timeout": 30
},
"TemporaryMagdaVertegenwoordigers": "{\"TemporaryVertegenwoordigers\": [{\"Insz\": \"1234567890\",\"Voornaam\": \"Ikkeltje\",\"Achternaam\": \"Persoon\"},{\"Insz\": \"0987654321\",\"Voornaam\": \"Kramikkeltje\",\"Achternaam\": \"Persoon\"}]}"
Expand Down
Loading

0 comments on commit e2f18b4

Please sign in to comment.