Skip to content

Commit

Permalink
feat: update projections with municipalitywasmerged
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneD committed Jul 5, 2024
1 parent 439c1e3 commit 2d999fa
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 21 deletions.
14 changes: 7 additions & 7 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ nuget Be.Vlaanderen.Basisregisters.Projector 15.0.0

nuget Be.Vlaanderen.Basisregisters.Crab 4.0.0

nuget Be.Vlaanderen.Basisregisters.GrAr.Common 21.0.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Contracts 21.0.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Import 21.0.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Legacy 21.0.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Oslo 21.0.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Provenance 21.0.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Extracts 21.0.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Common 21.8.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Contracts 21.8.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Import 21.8.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Legacy 21.8.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Oslo 21.8.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Provenance 21.8.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Extracts 21.8.0

nuget Be.Vlaanderen.Basisregisters.Shaperon 10.0.2

Expand Down
22 changes: 10 additions & 12 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,16 @@ NUGET
Autofac.Extensions.DependencyInjection (>= 9.0)
Be.Vlaanderen.Basisregisters.EventHandling (5.0)
Be.Vlaanderen.Basisregisters.Generators.Guid.Deterministic (4.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.8)
Be.Vlaanderen.Basisregisters.AggregateSource (>= 9.0.1)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 9.0.1)
NetTopologySuite (>= 2.5)
NodaTime (>= 3.1.11)
Be.Vlaanderen.Basisregisters.GrAr.Contracts (21.0)
Be.Vlaanderen.Basisregisters.AggregateSource (>= 9.0.1)
NodaTime (>= 3.1.11)
Be.Vlaanderen.Basisregisters.GrAr.Extracts (21.0)
Be.Vlaanderen.Basisregisters.GrAr.Contracts (21.8)
Be.Vlaanderen.Basisregisters.GrAr.Extracts (21.8)
Be.Vlaanderen.Basisregisters.Api (>= 21.0)
Be.Vlaanderen.Basisregisters.Shaperon (>= 10.0.2)
Be.Vlaanderen.Basisregisters.GrAr.Import (21.0)
Be.Vlaanderen.Basisregisters.GrAr.Import (21.8)
Autofac (>= 8.0)
Be.Vlaanderen.Basisregisters.AggregateSource.SqlStreamStore (>= 9.0.1)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 9.0.1)
Expand All @@ -246,21 +244,21 @@ NUGET
Serilog (>= 3.1.1)
Serilog.Extensions.Logging (>= 8.0)
System.Threading.Tasks.Dataflow (>= 8.0)
Be.Vlaanderen.Basisregisters.GrAr.Legacy (21.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.0)
Be.Vlaanderen.Basisregisters.GrAr.Legacy (21.8)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.8)
Be.Vlaanderen.Basisregisters.Utilities.Rfc3339DateTimeOffset (>= 4.0)
Newtonsoft.Json (>= 13.0.3)
Be.Vlaanderen.Basisregisters.GrAr.Oslo (21.0)
Be.Vlaanderen.Basisregisters.GrAr.Oslo (21.8)
Be.Vlaanderen.Basisregisters.AspNetCore.Mvc.Formatters.Json (>= 5.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.8)
Be.Vlaanderen.Basisregisters.Utilities.Rfc3339DateTimeOffset (>= 4.0)
Microsoft.Extensions.Configuration (>= 8.0)
Microsoft.Extensions.Http.Polly (>= 8.0.3)
Newtonsoft.Json (>= 13.0.3)
Be.Vlaanderen.Basisregisters.GrAr.Provenance (21.0)
Be.Vlaanderen.Basisregisters.GrAr.Provenance (21.8)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 9.0.1)
Be.Vlaanderen.Basisregisters.Crab (>= 4.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (21.8)
Microsoft.CSharp (>= 4.7)
Be.Vlaanderen.Basisregisters.MessageHandling.Kafka.Producer (5.0.1)
Confluent.Kafka (>= 2.3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,22 @@ await snapshotManager.FindMatchingSnapshot(
message.Position,
ct);
});

When<Envelope<MunicipalityWasMerged>>(async (_, message, ct) =>
{
var municipalityDetail = GetMunicipalityDetail(legacyContext, message.Message.MunicipalityId);

await FindAndProduce(async () =>
await snapshotManager.FindMatchingSnapshot(
GetNisCode(municipalityDetail),
message.Message.Provenance.Timestamp,
null,
message.Position,
throwStaleWhenGone: false,
ct),
message.Position,
ct);
});
}

private static string GetNisCode(MunicipalityDetail municipalityDetail)
Expand Down
12 changes: 12 additions & 0 deletions src/MunicipalityRegistry.Producer/Extensions/MessageExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace MunicipalityRegistry.Producer.Extensions
{
using System.Linq;
using Be.Vlaanderen.Basisregisters.GrAr.Provenance;
using Be.Vlaanderen.Basisregisters.Utilities;
using Contracts = Be.Vlaanderen.Basisregisters.GrAr.Contracts.MunicipalityRegistry;
using ContractsCommon = Be.Vlaanderen.Basisregisters.GrAr.Contracts.Common;
using Domain = Municipality.Events;
Expand Down Expand Up @@ -67,5 +69,15 @@ public static Contracts.MunicipalityGeometryWasCorrectedToCleared ToContract(thi

public static Contracts.MunicipalityWasDrawn ToContract(this Domain.MunicipalityWasDrawn message) =>
new Contracts.MunicipalityWasDrawn(message.MunicipalityId.ToString("D"), message.ExtendedWkbGeometry, message.Provenance.ToContract());

public static Contracts.MunicipalityWasMerged ToContract(this Domain.MunicipalityWasMerged message) =>
new Contracts.MunicipalityWasMerged(
message.MunicipalityId.ToString("D"),
message.NisCode,
message.MunicipalityIdsToMergeWith.Select(x => x.ToString("D")),
message.NisCodesToMergeWith,
message.NewMunicipalityId.ToString("D"),
message.NewNisCode,
message.Provenance.ToContract());
}
}
5 changes: 5 additions & 0 deletions src/MunicipalityRegistry.Producer/ProducerProjections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public ProducerProjections(IProducer producer)
{
await Produce(message.Message.MunicipalityId, message.Message.ToContract(), message.Position, ct);
});

When<Be.Vlaanderen.Basisregisters.ProjectionHandling.SqlStreamStore.Envelope<Domain.MunicipalityWasMerged>>(async (_, message, ct) =>
{
await Produce(message.Message.MunicipalityId, message.Message.ToContract(), message.Position, ct);
});
}

private async Task Produce<T>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ await context.FindAndUpdateMunicipalityExtract(
ct);
});

When<Envelope<MunicipalityWasMerged>>(async (context, message, ct) =>
{
await context.FindAndUpdateMunicipalityExtract(
message.Message.MunicipalityId,
municipality =>
{
UpdateStatus(municipality, Retired);
UpdateVersie(municipality, message.Message.Provenance.Timestamp);
},
ct);
});

When<Envelope<MunicipalityFacilityLanguageWasAdded>>(async (context, message, ct) => await DoNothing());
When<Envelope<MunicipalityFacilityLanguageWasRemoved>>(async (context, message, ct) => await DoNothing());
When<Envelope<MunicipalityGeometryWasCleared>>(async (context, message, ct) => await DoNothing());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,19 @@ await context.FindAndUpdateMunicipality(
},
ct);
});

When<Envelope<MunicipalityWasMerged>>(async (context, message, ct) =>
{
await context.FindAndUpdateMunicipality(
message.Message.MunicipalityId,
municipality =>
{
municipality.Status = MunicipalityStatus.Retired;
municipality.OsloStatus = MunicipalityStatus.Retired.ConvertFromMunicipalityStatus();
UpdateVersionTimestamp(municipality, message.Message.Provenance.Timestamp);
},
ct);
});
}

private static void UpdateNameByLanguage(MunicipalityLatestItem municipality, Language? language, string? name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,19 @@ await context.CreateNewMunicipalityVersion(
},
ct);
});

When<Envelope<MunicipalityWasMerged>>(async (context, message, ct) =>
{
await context.CreateNewMunicipalityVersion(
message.Message.MunicipalityId,
message,
x =>
{
x.Status = MunicipalityStatus.Retired;
x.OsloStatus = MunicipalityStatus.Retired.ConvertFromMunicipalityStatus();
},
ct);
});
}

private static void UpdateNameByLanguage(MunicipalityVersion municipalityVersion, Language language, string? name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public LastChangedListProjections()
await GetLastChangedRecordsAndUpdatePosition(message.Message.MunicipalityId.ToString(), message.Position, context, ct);
});

When<Envelope<MunicipalityWasMerged>>(async (context, message, ct) =>
{
await GetLastChangedRecordsAndUpdatePosition(message.Message.MunicipalityId.ToString(), message.Position, context, ct);
});

When<Envelope<MunicipalityGeometryWasCleared>>(async (context, message, ct) => await DoNothing());
When<Envelope<MunicipalityGeometryWasCorrected>>(async (context, message, ct) => await DoNothing());
When<Envelope<MunicipalityGeometryWasCorrectedToCleared>>(async (context, message, ct) => await DoNothing());
Expand All @@ -121,7 +126,7 @@ protected override string BuildCacheKey(AcceptType acceptType, string identifier
{
var shortenedAcceptType = acceptType.ToString().ToLowerInvariant();
return acceptType switch
{
{
AcceptType.JsonLd => $"oslo/municipality:{{0}}.{shortenedAcceptType}",
_ => throw new NotImplementedException($"Cannot build CacheKey for type {typeof(AcceptType)}")
};
Expand All @@ -130,7 +135,7 @@ protected override string BuildCacheKey(AcceptType acceptType, string identifier
protected override string BuildUri(AcceptType acceptType, string identifier)
{
return acceptType switch
{
{
AcceptType.JsonLd => $"/v2/gemeenten/{{0}}",
_ => throw new NotImplementedException($"Cannot build Uri for type {typeof(AcceptType)}")
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ await context.FindAndUpdateMunicipalityDetail(
ct);
});

When<Envelope<MunicipalityWasMerged>>(async (context, message, ct) =>
{
await context.FindAndUpdateMunicipalityDetail(
message.Message.MunicipalityId,
municipality =>
{
municipality.Status = MunicipalityStatus.Retired;
UpdateVersionTimestamp(municipality, message.Message.Provenance.Timestamp);
},
ct);
});

When<Envelope<MunicipalityGeometryWasCleared>>(async (context, message, ct) => await DoNothing());
When<Envelope<MunicipalityGeometryWasCorrected>>(async (context, message, ct) => await DoNothing());
When<Envelope<MunicipalityGeometryWasCorrectedToCleared>>(async (context, message, ct) => await DoNothing());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ namespace MunicipalityRegistry.Projections.Legacy.MunicipalityList
{
using System.Linq;
using System.Threading.Tasks;
using Azure.Messaging;
using Be.Vlaanderen.Basisregisters.GrAr.Common;
using Be.Vlaanderen.Basisregisters.ProjectionHandling.Connector;
using Be.Vlaanderen.Basisregisters.ProjectionHandling.SqlStreamStore;
using Municipality.Events;
using NodaTime;
using Polly;

[ConnectedProjectionName("API endpoint lijst gemeenten")]
[ConnectedProjectionDescription("Projectie die de gemeenten data voor de gemeenten lijst voorziet.")]
Expand Down Expand Up @@ -199,6 +201,18 @@ await context.FindAndUpdateMunicipalityListItem(
ct);
});

When<Envelope<MunicipalityWasMerged>>(async (context, message, ct) =>
{
await context.FindAndUpdateMunicipalityListItem(
message.Message.MunicipalityId,
municipalityListItem =>
{
municipalityListItem.Status = MunicipalityStatus.Retired;
UpdateVersionTimestamp(municipalityListItem, message.Message.Provenance.Timestamp);
},
ct);
});

When<Envelope<MunicipalityGeometryWasCleared>>(async (context, message, ct) => await DoNothing());
When<Envelope<MunicipalityGeometryWasCorrected>>(async (context, message, ct) => await DoNothing());
When<Envelope<MunicipalityGeometryWasCorrectedToCleared>>(async (context, message, ct) => await DoNothing());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ await context.CreateNewMunicipalitySyndicationItem(
ct);
});

When<Envelope<MunicipalityWasMerged>>(async (context, message, ct) =>
{
await context.CreateNewMunicipalitySyndicationItem(
message.Message.MunicipalityId,
message,
x => x.Status = MunicipalityStatus.Retired,
ct);
});

When<Envelope<MunicipalityGeometryWasCleared>>(async (context, message, ct) => await DoNothing());
When<Envelope<MunicipalityGeometryWasCorrected>>(async (context, message, ct) => await DoNothing());
When<Envelope<MunicipalityGeometryWasCorrectedToCleared>>(async (context, message, ct) => await DoNothing());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ await context.FindAndUpdateMunicipalityHelper(
},
ct);
});

When<Envelope<MunicipalityWasMerged>>(async (context, message, ct) =>
{
await context.FindAndUpdateMunicipalityHelper(
message.Message.MunicipalityId,
municipality =>
{
municipality.Status = MunicipalityStatus.Retired;
UpdateVersionTimestamp(municipality, message.Message.Provenance.Timestamp);
},
ct);
});
}

private static void UpdateNameByLanguage(MunicipalityHelper municipality, Language? language, string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ await context.FindAndUpdateMunicipalityHelper(
},
ct);
});

When<Envelope<MunicipalityWasMerged>>(async (context, message, ct) =>
{
await context.FindAndUpdateMunicipalityHelper(
message.Message.MunicipalityId,
municipality =>
{
municipality.Status = MunicipalityStatus.Retired;
UpdateVersionTimestamp(municipality, message.Message.Provenance.Timestamp);
},
ct);
});
}

private static void UpdateNameByLanguage(MunicipalityHelper municipality, Language? language, string name)
Expand Down

0 comments on commit 2d999fa

Please sign in to comment.