Skip to content

Commit

Permalink
feat: add suspicious case CurrentAddressLinkedToProposedStreetName
Browse files Browse the repository at this point in the history
  • Loading branch information
rikdepeuter authored and ArneD committed Dec 10, 2024
1 parent 676c37f commit e97fe85
Show file tree
Hide file tree
Showing 8 changed files with 625 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public class SuspiciousCase
// SuspiciousCasesType.ActiveBuildingUnitLinkedToMultipleAddresses,
// new SuspiciousCase(Category.BuildingUnit, "Gebouweenheden met status 'gepland' of 'gerealiseerd' die gekoppeld zijn aan meerdere adressen", Severity.Improvable)
// },
{
SuspiciousCasesType.CurrentAddressLinkedToProposedStreetName,
new SuspiciousCase(Category.Address, "Adres \"in gebruik\" met koppeling naar een straatnaam met de status \"voorgesteld\"", Severity.Suspicious)
},
};

public Category Category { get; }
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Basisregisters.IntegrationDb.SuspiciousCases.Migrations
{
using System;
using Infrastructure;
using Views;

/// <inheritdoc />
public partial class AddViewCurrentAddressLinkedToProposedStreetName : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql($"DROP VIEW IF EXISTS {Schema.SuspiciousCases}.{CurrentAddressLinkedToProposedStreetNameConfiguration.ViewName};");

migrationBuilder.Sql(CurrentAddressLinkedToProposedStreetNameConfiguration.Create);

migrationBuilder.Sql(SuspiciousCaseCountConfiguration.Create);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
throw new NotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,34 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToSqlQuery("\r\n SELECT\r\n persistent_local_id,\r\n building_unit_persistent_local_id,\r\n nis_code,\r\n CONCAT('Gebouweenheden-', building_unit_persistent_local_id) as description\r\n FROM integration_suspicious_cases.view_building_unit_longer_than_two_years_planned");
});

modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.CurrentAddressLinkedToProposedStreetName", b =>
{
b.Property<int>("AddressPersistentLocalId")
.HasColumnType("integer")
.HasColumnName("address_persistent_local_id");

b.Property<string>("Description")
.IsRequired()
.HasColumnType("text")
.HasColumnName("description");

b.Property<string>("NisCode")
.IsRequired()
.HasColumnType("text")
.HasColumnName("nis_code");

b.Property<string>("PersistentLocalId")
.IsRequired()
.HasColumnType("text")
.HasColumnName("persistent_local_id");

b.ToTable((string)null);

b.ToView("view_current_address_linked_to_proposed_streetname", "integration_suspicious_cases");

b.ToSqlQuery("\r\n SELECT\r\n persistent_local_id,\r\n address_persistent_local_id,\r\n nis_code,\r\n description\r\n FROM integration_suspicious_cases.view_current_address_linked_to_proposed_streetname");
});

modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.CurrentAddressLinkedWithBuildingUnitButNotWithParcel", b =>
{
b.Property<int>("AddressPersistentLocalId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class SuspiciousCasesContext : DbContext
public DbSet<ProposedAddressWithoutLinkedParcelOrBuildingUnit> ProposedAddressesWithoutLinkedParcelOrBuilding => Set<ProposedAddressWithoutLinkedParcelOrBuildingUnit>();
public DbSet<StreetNameLongerThanTwoYearsProposed> StreetNamesLongerThanTwoYearsProposed => Set<StreetNameLongerThanTwoYearsProposed>();
public DbSet<AddressLongerThanTwoYearsProposed> AddressesLongerThanTwoYearsProposed => Set<AddressLongerThanTwoYearsProposed>();
public DbSet<CurrentAddressLinkedToProposedStreetName> CurrentAddressesLinkedToProposedStreetName => Set<CurrentAddressLinkedToProposedStreetName>();
public DbSet<BuildingLongerThanTwoYearsPlanned> BuildingsLongerThanTwoYearsPlanned => Set<BuildingLongerThanTwoYearsPlanned>();
public DbSet<BuildingUnitsLongerThanTwoYearsPlanned> BuildingUnitsLongerThanTwoYearsPlanned => Set<BuildingUnitsLongerThanTwoYearsPlanned>();
public DbSet<ActiveAddressOutsideMunicipalityBounds> ActiveAddressesOutsideMunicipalityBounds => Set<ActiveAddressOutsideMunicipalityBounds>();
Expand Down Expand Up @@ -92,6 +93,13 @@ public async Task<IEnumerable<SuspiciousCase>> GetSuspiciousCase(
.Skip(offset)
.Take(limit)
.ToListAsync(ct);
case SuspiciousCasesType.CurrentAddressLinkedToProposedStreetName:
return await CurrentAddressesLinkedToProposedStreetName
.Where(x => x.NisCode == nisCode)
.OrderBy(x => x.Description)
.Skip(offset)
.Take(limit)
.ToListAsync(ct);

// StreetName
case SuspiciousCasesType.CurrentStreetNameWithoutLinkedRoadSegment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public enum SuspiciousCasesType
BuildingUnitLongerThanTwoYearsPlanned = 12,
RoadSegmentLongerThanTwoYearsWithPermit = 13,
RoadSegmentWithSingleLinkedStreetName = 14,

// ActiveBuildingUnitLinkedToMultipleAddresses = 15,
CurrentAddressLinkedToProposedStreetName = 16,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace Basisregisters.IntegrationDb.SuspiciousCases.Views
{
using Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

public sealed class CurrentAddressLinkedToProposedStreetName : SuspiciousCase
{
public int AddressPersistentLocalId { get; set; }

public override Category Category => Category.Address;
}

public sealed class CurrentAddressLinkedToProposedStreetNameConfiguration : IEntityTypeConfiguration<CurrentAddressLinkedToProposedStreetName>
{
public void Configure(EntityTypeBuilder<CurrentAddressLinkedToProposedStreetName> builder)
{
builder
.ToView(ViewName, Schema.SuspiciousCases)
.HasNoKey()
.ToSqlQuery(@$"
SELECT
persistent_local_id,
address_persistent_local_id,
nis_code,
description
FROM {Schema.SuspiciousCases}.{ViewName}");

builder.Property(x => x.PersistentLocalId).HasColumnName("persistent_local_id");
builder.Property(x => x.AddressPersistentLocalId).HasColumnName("address_persistent_local_id");
builder.Property(x => x.NisCode).HasColumnName("nis_code");
builder.Property(x => x.Description).HasColumnName("description");
}

public const string ViewName = "view_current_address_linked_to_proposed_streetname";

public const string Create = $@"
CREATE OR REPLACE VIEW {Schema.SuspiciousCases}.{ViewName} AS
SELECT
CAST(a.persistent_local_id as varchar) AS persistent_local_id,
a.persistent_local_id AS address_persistent_local_id,
s.nis_code AS nis_code,
{Schema.FullAddress}(s.name_dutch, a.house_number, a.box_number, a.postal_code, m.name_dutch) as description
FROM {SchemaLatestItems.Address} AS a
JOIN {SchemaLatestItems.StreetName} s ON s.persistent_local_id = a.street_name_persistent_local_id AND s.status = 0
JOIN {SchemaLatestItems.Municipality} m ON s.municipality_id = m.municipality_id
WHERE
a.status = 2
AND a.removed = false
;";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ CREATE MATERIALIZED VIEW {{Schema.SuspiciousCases}}.{{ViewName}}
UNION
{{CreateScript(SuspiciousCasesType.CurrentAddressesWithSpecificationDerivedFromBuildingUnitWithoutLinkedBuildingUnit, CurrentAddressWithSpecificationDerivedFromBuildingUnitWithoutLinkedBuildingUnitConfiguration.ViewName)}}
UNION
{{CreateScript(SuspiciousCasesType.CurrentAddressLinkedToProposedStreetName, CurrentAddressLinkedToProposedStreetNameConfiguration.ViewName)}}
UNION
{{CreateScript(SuspiciousCasesType.CurrentStreetNameWithoutLinkedRoadSegment, CurrentStreetNameWithoutLinkedRoadSegmentsConfiguration.ViewName)}}
UNION
{{CreateScript(SuspiciousCasesType.ProposedAddressWithoutLinkedParcelOrBuildingUnit, ProposedAddressWithoutLinkedParcelOrBuildingUnitConfiguration.ViewName)}}
Expand Down

0 comments on commit e97fe85

Please sign in to comment.