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

feat: add sync from municipality registry #1570

Merged
merged 6 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions RoadRegistry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RoadRegistry.Integration.Pr
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RoadRegistry.Snapshot.Handlers.Sqs.Lambda.Console", "test\RoadRegistry.Snapshot.Handlers.Sqs.Lambda.Console\RoadRegistry.Snapshot.Handlers.Sqs.Lambda.Console.csproj", "{18024416-CD26-433B-B34B-2B248A57539C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RoadRegistry.Sync.MunicipalityRegistry", "src\RoadRegistry.Sync.MunicipalityRegistry\RoadRegistry.Sync.MunicipalityRegistry.csproj", "{EF98CA87-B1AD-448D-A708-0E329FB532B2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -916,6 +918,18 @@ Global
{18024416-CD26-433B-B34B-2B248A57539C}.Release|x64.Build.0 = Release|Any CPU
{18024416-CD26-433B-B34B-2B248A57539C}.Release|x86.ActiveCfg = Release|Any CPU
{18024416-CD26-433B-B34B-2B248A57539C}.Release|x86.Build.0 = Release|Any CPU
{EF98CA87-B1AD-448D-A708-0E329FB532B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EF98CA87-B1AD-448D-A708-0E329FB532B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF98CA87-B1AD-448D-A708-0E329FB532B2}.Debug|x64.ActiveCfg = Debug|Any CPU
{EF98CA87-B1AD-448D-A708-0E329FB532B2}.Debug|x64.Build.0 = Debug|Any CPU
{EF98CA87-B1AD-448D-A708-0E329FB532B2}.Debug|x86.ActiveCfg = Debug|Any CPU
{EF98CA87-B1AD-448D-A708-0E329FB532B2}.Debug|x86.Build.0 = Debug|Any CPU
{EF98CA87-B1AD-448D-A708-0E329FB532B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF98CA87-B1AD-448D-A708-0E329FB532B2}.Release|Any CPU.Build.0 = Release|Any CPU
{EF98CA87-B1AD-448D-A708-0E329FB532B2}.Release|x64.ActiveCfg = Release|Any CPU
{EF98CA87-B1AD-448D-A708-0E329FB532B2}.Release|x64.Build.0 = Release|Any CPU
{EF98CA87-B1AD-448D-A708-0E329FB532B2}.Release|x86.ActiveCfg = Release|Any CPU
{EF98CA87-B1AD-448D-A708-0E329FB532B2}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -984,6 +998,7 @@ Global
{2345054A-9FEC-4930-A278-49526BB73CF6} = {C2F8FF63-7A48-4179-A720-86206C42F496}
{8BBCF59D-7A4F-48A3-B8B2-5BD0C5CE46A8} = {8EA18457-86E2-4D2D-AC9E-2552FDC9676F}
{18024416-CD26-433B-B34B-2B248A57539C} = {8EA18457-86E2-4D2D-AC9E-2552FDC9676F}
{EF98CA87-B1AD-448D-A708-0E329FB532B2} = {C2F8FF63-7A48-4179-A720-86206C42F496}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2EB87445-E263-4E1E-89CC-3839170028E5}
Expand Down
13 changes: 4 additions & 9 deletions src/RoadRegistry.BackOffice/OrganizationEventWriter.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
namespace RoadRegistry.BackOffice;

using Be.Vlaanderen.Basisregisters.EventHandling;
using System.Threading;
using System.Threading.Tasks;
using Framework;
using Messages;
using SqlStreamStore;
using SqlStreamStore.Streams;
using System.Threading;
using System.Threading.Tasks;

public interface IOrganizationEventWriter
{
Expand All @@ -15,16 +13,13 @@ public interface IOrganizationEventWriter

public class OrganizationEventWriter : RoadRegistryEventWriter, IOrganizationEventWriter
{
private static readonly EventMapping EventMapping =
new(EventMapping.DiscoverEventNamesInAssembly(typeof(RoadNetworkEvents).Assembly));

public OrganizationEventWriter(IStreamStore store, EventEnricher enricher)
: base(store, enricher, EventMapping)
: base(store, enricher)
{
}

public Task WriteAsync(OrganizationId id, Event @event, CancellationToken cancellationToken)
{
return AppendToStoreStream(OrganizationId.ToStreamName(id), @event, ExpectedVersion.Any, new[] { @event.Body }, cancellationToken);
return AppendToStoreStream(OrganizationId.ToStreamName(id), @event, ExpectedVersion.Any, [@event.Body], cancellationToken);
}
}
9 changes: 9 additions & 0 deletions src/RoadRegistry.BackOffice/RoadRegistryEventWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace RoadRegistry.BackOffice;
using Be.Vlaanderen.Basisregisters.Generators.Guid;
using Be.Vlaanderen.Basisregisters.GrAr.Provenance;
using Framework;
using Messages;
using Newtonsoft.Json;
using SqlStreamStore.Streams;
using SqlStreamStore;
Expand All @@ -19,10 +20,18 @@ public abstract class RoadRegistryEventWriter
protected static readonly JsonSerializerSettings SerializerSettings =
EventsJsonSerializerSettingsProvider.CreateSerializerSettings();

private static readonly EventMapping EventMapping =
new(EventMapping.DiscoverEventNamesInAssembly(typeof(RoadNetworkEvents).Assembly));

private readonly EventEnricher _enricher;
private readonly IStreamStore _store;
private readonly EventMapping _eventMapping;

protected RoadRegistryEventWriter(IStreamStore store, EventEnricher enricher)
: this(store, enricher, EventMapping)
{
}

protected RoadRegistryEventWriter(IStreamStore store, EventEnricher enricher, EventMapping eventMapping)
{
_store = store.ThrowIfNull();
Expand Down
2 changes: 2 additions & 0 deletions src/RoadRegistry.BackOffice/WellKnownConnectionNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public static class WellKnownConnectionNames
public const string StreetNameSnapshotConsumerAdmin = "StreetNameSnapshotConsumerAdmin";
public const string OrganizationConsumerProjections = "OrganizationConsumerProjections";
public const string OrganizationConsumerProjectionsAdmin = "OrganizationConsumerProjectionsAdmin";
public const string MunicipalityEventConsumer = "MunicipalityEventConsumer";
public const string MunicipalityEventConsumerAdmin = "MunicipalityEventConsumerAdmin";
}
2 changes: 2 additions & 0 deletions src/RoadRegistry.BackOffice/WellKnownSchemas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static class WellKnownSchemas
public const string StreetNameEventConsumerSchema = "RoadRegistryStreetNameEventConsumer";
public const string StreetNameSnapshotConsumerSchema = "RoadRegistryStreetNameSnapshotConsumer";
public const string OrganizationConsumerSchema = "RoadRegistryOrganizationConsumer";
public const string MunicipalityEventConsumerSchema = "RoadRegistryMunicipalityEventConsumer";

public const string RoadNodeProducerSnapshotMetaSchema = "RoadRegistryRoadNodeProducerSnapshotMeta";
public const string RoadNodeProducerSnapshotSchema = "RoadRegistryRoadNodeProducerSnapshot";
Expand Down Expand Up @@ -50,6 +51,7 @@ public static class MigrationTables
public const string StreetNameEventConsumer = "__EFMigrationsHistoryStreetNameEventConsumer";
public const string StreetNameSnapshotConsumer = "__EFMigrationsHistoryStreetNameSnapshotConsumer";
public const string OrganizationConsumer = "__EFMigrationsHistoryOrganizationConsumer";
public const string MunicipalityEventConsumer = "__EFMigrationsHistoryMunicipalityEventConsumer";

public const string RoadNodeProducerSnapshot = "__EFMigrationsHistoryRoadNodeProducerSnapshot";
public const string RoadSegmentProducerSnapshot = "__EFMigrationsHistoryRoadSegmentProducerSnapshot";
Expand Down

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using NetTopologySuite.Geometries;

#nullable disable

namespace RoadRegistry.Sync.MunicipalityRegistry.Migrations
{
/// <inheritdoc />
public partial class Initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "RoadRegistryMunicipalityEventConsumer");

migrationBuilder.CreateTable(
name: "Municipalities",
schema: "RoadRegistryMunicipalityEventConsumer",
columns: table => new
{
MunicipalityId = table.Column<string>(type: "nvarchar(450)", nullable: false),
NisCode = table.Column<string>(type: "nvarchar(450)", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
Geometry = table.Column<Geometry>(type: "Geometry", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Municipalities", x => x.MunicipalityId)
.Annotation("SqlServer:Clustered", false);
});

migrationBuilder.CreateTable(
name: "ProcessedMessages",
schema: "RoadRegistryMunicipalityEventConsumer",
columns: table => new
{
IdempotenceKey = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
DateProcessed = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ProcessedMessages", x => x.IdempotenceKey)
.Annotation("SqlServer:Clustered", true);
});

migrationBuilder.CreateIndex(
name: "IX_Municipalities_NisCode",
schema: "RoadRegistryMunicipalityEventConsumer",
table: "Municipalities",
column: "NisCode")
.Annotation("SqlServer:Clustered", true);

migrationBuilder.CreateIndex(
name: "IX_ProcessedMessages_DateProcessed",
schema: "RoadRegistryMunicipalityEventConsumer",
table: "ProcessedMessages",
column: "DateProcessed");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Municipalities",
schema: "RoadRegistryMunicipalityEventConsumer");

migrationBuilder.DropTable(
name: "ProcessedMessages",
schema: "RoadRegistryMunicipalityEventConsumer");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NetTopologySuite.Geometries;
using RoadRegistry.Sync.MunicipalityRegistry;

#nullable disable

namespace RoadRegistry.Sync.MunicipalityRegistry.Migrations
{
[DbContext(typeof(MunicipalityEventConsumerContext))]
partial class MunicipalityEventConsumerContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

modelBuilder.Entity("Be.Vlaanderen.Basisregisters.MessageHandling.Kafka.Consumer.ProcessedMessage", b =>
{
b.Property<string>("IdempotenceKey")
.HasMaxLength(128)
.HasColumnType("nvarchar(128)");

b.Property<DateTimeOffset>("DateProcessed")
.HasColumnType("datetimeoffset");

b.HasKey("IdempotenceKey");

SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("IdempotenceKey"));

b.HasIndex("DateProcessed");

b.ToTable("ProcessedMessages", "RoadRegistryMunicipalityEventConsumer");
});

modelBuilder.Entity("RoadRegistry.Sync.MunicipalityRegistry.Models.Municipality", b =>
{
b.Property<string>("MunicipalityId")
.HasColumnType("nvarchar(450)");

b.Property<Geometry>("Geometry")
.HasColumnType("Geometry");

b.Property<string>("NisCode")
.IsRequired()
.HasColumnType("nvarchar(450)");

b.Property<int>("Status")
.HasColumnType("int");

b.HasKey("MunicipalityId");

SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("MunicipalityId"), false);

b.HasIndex("NisCode");

SqlServerIndexBuilderExtensions.IsClustered(b.HasIndex("NisCode"));

b.ToTable("Municipalities", "RoadRegistryMunicipalityEventConsumer");
});
#pragma warning restore 612, 618
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace RoadRegistry.Sync.MunicipalityRegistry.Models;

using BackOffice;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using NetTopologySuite.Geometries;

public class Municipality
{
public string MunicipalityId { get; set; }
public string NisCode { get; set; }
public MunicipalityStatus Status { get; set; }
public Geometry? Geometry { get; set; }
}

public enum MunicipalityStatus
{
Proposed = 0,
Current = 1,
Retired = 2
}

public class MunicipalityConfiguration : IEntityTypeConfiguration<Municipality>
{
public const string TableName = "Municipalities";

public void Configure(EntityTypeBuilder<Municipality> b)
{
b.ToTable(TableName, WellKnownSchemas.MunicipalityEventConsumerSchema)
.HasKey(p => p.MunicipalityId)
.IsClustered(false);

b.Property(p => p.MunicipalityId)
.ValueGeneratedNever()
.IsRequired();

b.Property(p => p.NisCode);
b.Property(p => p.Status);
b.Property(p => p.Geometry)
.HasColumnType("Geometry")
.IsRequired(false);

b.HasIndex(p => p.NisCode)
.IsClustered();
}
}
Loading
Loading