Skip to content

Commit

Permalink
Merge branch 'main' into or-1349-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Lesage committed Dec 20, 2023
2 parents 7c11645 + fb8cb97 commit 26c071c
Show file tree
Hide file tree
Showing 24 changed files with 215 additions and 83 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# [8.39.0](https://github.com/informatievlaanderen/association-registry/compare/v8.38.0...v8.39.0) (2023-12-20)


### Features

* or-2013 add correlationId to session ([6f388fe](https://github.com/informatievlaanderen/association-registry/commit/6f388fea0dafa21aa905278fea1483e76dd298a7))
* or-2013 add initiator to otel tracing ([1e30b81](https://github.com/informatievlaanderen/association-registry/commit/1e30b81033cd90feaf7765ce83e51cb9fe0084b8))
* or-2013 use lightweight session io obsolete method ([29ee136](https://github.com/informatievlaanderen/association-registry/commit/29ee136e752f14d296cfd1331c1e56a386293b46))

# [8.38.0](https://github.com/informatievlaanderen/association-registry/compare/v8.37.0...v8.38.0) (2023-12-20)


### Features

* or-2006 make kbo numbers unique in tests; fix vlk; ([cb8f541](https://github.com/informatievlaanderen/association-registry/commit/cb8f541872f476839af644dd9cdb21521405c910))
* or-2006 simple solution for or-2006 ([4f49efe](https://github.com/informatievlaanderen/association-registry/commit/4f49efe6909e922e979f8f4d18c973d7a8429da4))

# [8.37.0](https://github.com/informatievlaanderen/association-registry/compare/v8.36.1...v8.37.0) (2023-12-18)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "association-registry",
"version": "8.37.0",
"version": "8.39.0",
"description": "Association registry.",
"author": "Basisregisters Vlaanderen",
"license": "EUPL-1.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ public static IServiceCollection AddMarten(
if (serviceProvider.GetRequiredService<IHostEnvironment>().IsDevelopment())
{
opts.GeneratedCodeMode = TypeLoadMode.Dynamic;

// serviceProvider.GetRequiredService<IDatabaseInitializer>()
// .InitializeDatabase(opts);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace AssociationRegistry.Admin.Api.VCodeGeneration;

using Marten;
using System;
using System.Linq;
using System.Threading.Tasks;
using Marten;
using Vereniging;
using Weasel.Postgresql;

Expand All @@ -23,7 +23,7 @@ public SequenceVCodeService(IDocumentStore maybeDocumentStore)

public async Task<VCode> GetNext()
{
await using var session = _documentStore.OpenSession();
await using var session = _documentStore.LightweightSession();

return VCode.Create(session.NextInSequence(_vCodeSequence));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

public static class ServiceCollectionExtensions
{
private const string VrInitiatorHeaderName = "VR-Initiator";

public static IServiceCollection AddOpenTelemetry(this IServiceCollection services)
{
var (serviceName, collectorUrl, configureResource) = GetResources();
Expand All @@ -34,7 +36,7 @@ public static IServiceCollection AddOpenTelemetry<T>(this IServiceCollection ser

return services.AddTracking(configureResource, collectorUrl, serviceName)
.AddLogging(configureResource, collectorUrl)
.AddMetrics(configureResource, collectorUrl, builder =>
.AddMetrics(configureResource, collectorUrl, extraConfig: builder =>
{
foreach (var instrumentation in instrumentations)
{
Expand Down Expand Up @@ -108,14 +110,19 @@ private static IServiceCollection AddTracking(
{
return services.AddOpenTelemetryTracing(
builder =>
{
builder
.AddSource(serviceName)
.ConfigureResource(configureResource).AddHttpClientInstrumentation()
.AddAspNetCoreInstrumentation(
options =>
{
options.EnrichWithHttpRequest =
(activity, request) => activity.SetParentId(request.Headers["traceparent"]);
(activity, request) =>
{
activity.SetCustomProperty(VrInitiatorHeaderName, request.Headers[VrInitiatorHeaderName]);
activity.SetParentId(request.Headers["traceparent"]);

Check warning on line 124 in src/AssociationRegistry.OpenTelemetry/Extensions/ServiceCollectionExtensions.cs

View workflow job for this annotation

GitHub Actions / analyze-code

Possible null reference argument for parameter 'parentId' in 'Activity Activity.SetParentId(string parentId)'.

Check warning on line 124 in src/AssociationRegistry.OpenTelemetry/Extensions/ServiceCollectionExtensions.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'parentId' in 'Activity Activity.SetParentId(string parentId)'.

Check warning on line 124 in src/AssociationRegistry.OpenTelemetry/Extensions/ServiceCollectionExtensions.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'parentId' in 'Activity Activity.SetParentId(string parentId)'.

Check warning on line 124 in src/AssociationRegistry.OpenTelemetry/Extensions/ServiceCollectionExtensions.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'parentId' in 'Activity Activity.SetParentId(string parentId)'.

Check warning on line 124 in src/AssociationRegistry.OpenTelemetry/Extensions/ServiceCollectionExtensions.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'parentId' in 'Activity Activity.SetParentId(string parentId)'.
};

options.Filter = context => context.Request.Method != HttpMethods.Options;
})
Expand All @@ -126,7 +133,8 @@ private static IServiceCollection AddTracking(
options.Protocol = OtlpExportProtocol.Grpc;
options.Endpoint = new Uri(collectorUrl);
})
.AddSource("Wolverine"));
.AddSource("Wolverine");
});
}

private static (string serviceName, string collectorUrl, Action<ResourceBuilder> configureResource) GetResources()
Expand Down
29 changes: 23 additions & 6 deletions src/AssociationRegistry/EventStore/EventStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ public EventStore(IDocumentStore documentStore)
_documentStore = documentStore;
}

public async Task<StreamActionResult> Save(string aggregateId, CommandMetadata metadata, CancellationToken cancellationToken = default, params IEvent[] events)
public async Task<StreamActionResult> Save(
string aggregateId,
CommandMetadata metadata,
CancellationToken cancellationToken = default,
params IEvent[] events)
{
await using var session = _documentStore.OpenSession();
await using var session = _documentStore.LightweightSession();

try
{
SetHeaders(metadata, session);

TryLockForKboNumber(aggregateId, session, events.FirstOrDefault());

var streamAction = AppendEvents(session, aggregateId, events, metadata.ExpectedVersion);

await session.SaveChangesAsync(cancellationToken);
Expand All @@ -40,10 +46,20 @@ public async Task<StreamActionResult> Save(string aggregateId, CommandMetadata m
}
}

private static StreamAction AppendEvents(IDocumentSession session, string aggregateId, IReadOnlyCollection<IEvent> events, long? expectedVersion)
private static void TryLockForKboNumber(string vCode, IDocumentSession session, IEvent? registreerEvent)
{
if (registreerEvent is VerenigingMetRechtspersoonlijkheidWerdGeregistreerd evnt)
session.Events.StartStream<KboNummer>(evnt.KboNummer, new { VCode = vCode });
}

private static StreamAction AppendEvents(
IDocumentSession session,
string aggregateId,
IReadOnlyCollection<IEvent> events,
long? expectedVersion)
{
if (expectedVersion is not null)
return session.Events.Append(stream: aggregateId, expectedVersion: expectedVersion.Value + events.Count, events: events);
return session.Events.Append(aggregateId, expectedVersion.Value + events.Count, events);

return session.Events.Append(aggregateId, events);
}
Expand All @@ -52,6 +68,7 @@ private static void SetHeaders(CommandMetadata metadata, IDocumentSession sessio
{
session.SetHeader(MetadataHeaderNames.Initiator, metadata.Initiator);
session.SetHeader(MetadataHeaderNames.Tijdstip, InstantPattern.General.Format(metadata.Tijdstip));
session.CorrelationId = metadata.CorrelationId.ToString();
}

private static bool IsEventFromDigitaalVlaanderen(Type eventType)
Expand All @@ -65,15 +82,15 @@ private static bool IsEventFromDigitaalVlaanderen(Type eventType)

public async Task<T> Load<T>(string id) where T : class, IHasVersion, new()
{
await using var session = _documentStore.OpenSession();
await using var session = _documentStore.LightweightSession();

return await session.Events.AggregateStreamAsync<T>(id) ??
throw new AggregateNotFoundException(id, typeof(T));
}

public async Task<T?> Load<T>(KboNummer kboNummer) where T : class, IHasVersion, new()
{
await using var session = _documentStore.OpenSession();
await using var session = _documentStore.LightweightSession();

var id = (await session.Events.QueryRawEventDataOnly<VerenigingMetRechtspersoonlijkheidWerdGeregistreerd>()
.Where(geregistreerd => geregistreerd.KboNummer == kboNummer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public V029_VerenigingMetRechtspersoonlijkheidWerdGeregistreerd_With_All_Data()
VCode = VCode,
Naam = Naam,
KorteNaam = "RDZ",
KboNummer = "7981199887",
KboNummer = "7981199829",
Rechtsvorm = Verenigingstype.VZW.Code,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public V030_VerenigingeMetRechtspersoonlijkheidWerdGeregistreerd_With_Invalid_Da
VCode = VCode,
Naam = Naam,
KorteNaam = "RDZ",
KboNummer = "7981199887",
KboNummer = "7981199830",
};

MaatschappelijkeZetelKonNietOvergenomenWordenUitKbo = new MaatschappelijkeZetelKonNietOvergenomenWordenUitKbo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public V045_VerenigingMetRechtspersoonlijkheidWerdGeregistreerd_With_Contactgege
VCode = VCode,
Naam = Naam,
KorteNaam = "RDZ",
KboNummer = "7981199887",
KboNummer = "7981199845",
Rechtsvorm = Verenigingstype.VZW.Code,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public async Task Then_It_Returns_GeefOndernemingResponseBody(MagdaOptionsSectio
onderneming?.Namen.MaatschappelijkeNamen.Should().ContainEquivalentOf(
new NaamOndernemingType
{
Naam = "Vlaamse Liga tegen Kanker",
Naam = "Kom op tegen Kanker",
Taalcode = "nl",
DatumBegin = "1998-01-01",
DatumBegin = "2015-10-13",
DatumEinde = null,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
namespace AssociationRegistry.Test.Admin.Api.VerenigingMetRechtspersoonlijkheid.When_RegistreerVerenigingMetRechtspersoonlijkheid;

using AssociationRegistry.Admin.Api.Verenigingen.Registreer.MetRechtspersoonlijkheid.RequestModels;
using AutoFixture;
using Events;
using Fixtures;
using FluentAssertions;
using Framework;
using System.Net;
using Vereniging;
using Xunit;
using Xunit.Categories;

public sealed class When_RegistreerVerenigingMetRechtspersoonlijkheid_With_Duplicate_Requests
{
private static When_RegistreerVerenigingMetRechtspersoonlijkheid_With_Duplicate_Requests? called;
public readonly RegistreerVerenigingUitKboRequest UitKboRequest;
public readonly List<Tuple<Task<HttpResponseMessage>, Task<HttpResponseMessage>>> Responses;

private When_RegistreerVerenigingMetRechtspersoonlijkheid_With_Duplicate_Requests(EventsInDbScenariosFixture fixture)
{
var autofixture = new Fixture().CustomizeAdminApi();

UitKboRequest = new RegistreerVerenigingUitKboRequest
{
KboNummer = fixture.V020VerenigingMetRechtspersoonlijkheidWerdGeregistreerdForDuplicateDetection
.VerenigingMetRechtspersoonlijkheidWerdGeregistreerd.KboNummer,
};

Responses = new List<Tuple<Task<HttpResponseMessage>, Task<HttpResponseMessage>>>();

foreach (var kboNummer in autofixture.CreateMany<KboNummer>(5))
{
var request = new RegistreerVerenigingUitKboRequest { KboNummer = kboNummer };

Responses.Add(new Tuple<Task<HttpResponseMessage>, Task<HttpResponseMessage>>(
fixture.DefaultClient.RegistreerKboVereniging(GetJsonBody(request)),
fixture.DefaultClient.RegistreerKboVereniging(GetJsonBody(request))));
}
}

public static When_RegistreerVerenigingMetRechtspersoonlijkheid_With_Duplicate_Requests Called(EventsInDbScenariosFixture fixture)
=> called ??= new When_RegistreerVerenigingMetRechtspersoonlijkheid_With_Duplicate_Requests(fixture);

private string GetJsonBody(RegistreerVerenigingUitKboRequest uitKboRequest)
=> GetType()
.GetAssociatedResourceJson("files.request.with_kboNummer")
.Replace(oldValue: "{{kboNummer}}", uitKboRequest.KboNummer);
}

[Collection(nameof(AdminApiCollection))]
[Category("AdminApi")]
[IntegrationTest]
public class With_Duplicate_Requests
{
private readonly EventsInDbScenariosFixture _fixture;

public With_Duplicate_Requests(EventsInDbScenariosFixture fixture)
{
_fixture = fixture;
}

private RegistreerVerenigingUitKboRequest Request
=> When_RegistreerVerenigingMetRechtspersoonlijkheid_With_Duplicate_Requests.Called(_fixture).UitKboRequest;


[Fact]
public async Task Then_it_returns_an_ok_response_with_correct_headers()
{
var responses = When_RegistreerVerenigingMetRechtspersoonlijkheid_With_Duplicate_Requests.Called(_fixture).Responses;

foreach (var responseTuple in responses)
{
var httpResponseMessages = await Task.WhenAll(responseTuple.Item1, responseTuple.Item2);
httpResponseMessages.Count(x => x.StatusCode == HttpStatusCode.Accepted).Should().Be(1);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace AssociationRegistry.Test.Admin.Api.VerenigingMetRechtspersoonlijkheid.When_RegistreerVerenigingMetRechtspersoonlijkheid.With_Kbo_Nummer_For_Supported_Rechtsvorm;
namespace AssociationRegistry.Test.Admin.Api.VerenigingMetRechtspersoonlijkheid.When_RegistreerVerenigingMetRechtspersoonlijkheid.
With_Kbo_Nummer_For_Supported_Rechtsvorm;

using Events;
using Fixtures;
Expand All @@ -7,33 +8,39 @@ namespace AssociationRegistry.Test.Admin.Api.VerenigingMetRechtspersoonlijkheid.
using Vereniging;
using Xunit;

public class RegistreerPrivateStichtingSetup: RegistreerVereniginMetRechtspersoonlijkheidSetup
public class RegistreerPrivateStichtingSetup : RegistreerVereniginMetRechtspersoonlijkheidSetup
{
public RegistreerPrivateStichtingSetup(EventsInDbScenariosFixture fixture): base(fixture, "0546572531")
public RegistreerPrivateStichtingSetup(EventsInDbScenariosFixture fixture) : base(fixture, kboNummer: "0546572531")
{

}
}

public class With_KboNummer_For_PrivateStichting: With_KboNummer_For_Supported_Vereniging, IClassFixture<RegistreerPrivateStichtingSetup>
public class With_KboNummer_For_PrivateStichting : With_KboNummer_For_Supported_Vereniging, IClassFixture<RegistreerPrivateStichtingSetup>
{
public With_KboNummer_For_PrivateStichting(EventsInDbScenariosFixture fixture, RegistreerPrivateStichtingSetup registreerSetup) : base(fixture, registreerSetup)
public With_KboNummer_For_PrivateStichting(EventsInDbScenariosFixture fixture, RegistreerPrivateStichtingSetup registreerSetup) : base(
fixture, registreerSetup)
{
}

[Fact]
public void Then_it_saves_the_events()
{
using var session = _fixture.DocumentStore
.LightweightSession();
.LightweightSession();

var verenigingMetRechtspersoonlijkheidWerdGeregistreerd = session
.Events
.QueryRawEventDataOnly<
VerenigingMetRechtspersoonlijkheidWerdGeregistreerd>()
.Should().ContainSingle(
e => e.KboNummer == RegistreerVerenigingMetRechtspersoonlijkheidSetup
.UitKboRequest.KboNummer).Subject;

var verenigingMetRechtspersoonlijkheidWerdGeregistreerd = session.Events.QueryRawEventDataOnly<VerenigingMetRechtspersoonlijkheidWerdGeregistreerd>()
.Should().ContainSingle(e => e.KboNummer == RegistreerVerenigingMetRechtspersoonlijkheidSetup.UitKboRequest.KboNummer).Subject;
using (new AssertionScope())
{
verenigingMetRechtspersoonlijkheidWerdGeregistreerd.Naam.Should().Be("Vlaamse Liga tegen Kanker");
verenigingMetRechtspersoonlijkheidWerdGeregistreerd.Naam.Should().Be("Kom op tegen Kanker");
verenigingMetRechtspersoonlijkheidWerdGeregistreerd.KorteNaam.Should().Be("V.L.K.");
verenigingMetRechtspersoonlijkheidWerdGeregistreerd.Startdatum.Should().Be(new DateOnly(1989, 10, 03));
verenigingMetRechtspersoonlijkheidWerdGeregistreerd.Startdatum.Should().Be(new DateOnly(year: 1989, month: 10, day: 03));

verenigingMetRechtspersoonlijkheidWerdGeregistreerd.Rechtsvorm.Should().Be(Verenigingstype.PrivateStichting.Code);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void Then_it_saves_the_events()

using (new AssertionScope())
{
verenigingMetRechtspersoonlijkheidWerdGeregistreerd.Naam.Should().Be("Vlaamse Liga tegen Kanker");
verenigingMetRechtspersoonlijkheidWerdGeregistreerd.Naam.Should().Be("Kom op tegen Kanker");
verenigingMetRechtspersoonlijkheidWerdGeregistreerd.KorteNaam.Should().Be("V.L.K.");
verenigingMetRechtspersoonlijkheidWerdGeregistreerd.Startdatum.Should().Be(new DateOnly(year: 1989, month: 10, day: 03));
verenigingMetRechtspersoonlijkheidWerdGeregistreerd.Rechtsvorm.Should().Be(Verenigingstype.StichtingVanOpenbaarNut.Code);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void Then_it_saves_the_events()

using (new AssertionScope())
{
verenigingMetRechtspersoonlijkheidWerdGeregistreerd.Naam.Should().Be("Vlaamse Liga tegen Kanker");
verenigingMetRechtspersoonlijkheidWerdGeregistreerd.Naam.Should().Be("Kom op tegen Kanker");
verenigingMetRechtspersoonlijkheidWerdGeregistreerd.KorteNaam.Should().Be("V.L.K.");
verenigingMetRechtspersoonlijkheidWerdGeregistreerd.Startdatum.Should().Be(new DateOnly(year: 1989, month: 10, day: 03));
verenigingMetRechtspersoonlijkheidWerdGeregistreerd.Rechtsvorm.Should().Be(Verenigingstype.VZW.Code);
Expand Down
Loading

0 comments on commit 26c071c

Please sign in to comment.