From e0a960859010c7bc0167f1fef84a0ce7b298853d Mon Sep 17 00:00:00 2001 From: pgallik Date: Fri, 15 Dec 2023 10:46:57 +0100 Subject: [PATCH] add integrationdb registration to api --- .../Importer.cs | 2 ++ .../SuspiciousCases/SuspiciousCaseListItem.cs | 2 +- .../Category.cs | 6 +++++ .../Infrastructure/Startup.cs | 24 +++++++++++++++-- .../List/SuspiciousCasesListResponse.cs | 2 +- .../List/SuspiciousCasesListResponseItem.cs | 2 +- .../Severity.cs | 3 +++ .../SuspiciousCase.cs | 26 +++++++++---------- .../SuspiciousCasesController.cs | 2 +- .../appsettings.json | 6 +++-- 10 files changed, 54 insertions(+), 21 deletions(-) diff --git a/src/Basisregisters.IntegrationDb.Municipality.GeometryImporter/Importer.cs b/src/Basisregisters.IntegrationDb.Municipality.GeometryImporter/Importer.cs index 59b334d5..ca68b55f 100644 --- a/src/Basisregisters.IntegrationDb.Municipality.GeometryImporter/Importer.cs +++ b/src/Basisregisters.IntegrationDb.Municipality.GeometryImporter/Importer.cs @@ -32,6 +32,8 @@ public Importer(IntegrationContext integrationContext) public async Task ExecuteAsync() { + var k = _integrationContext.SuspiciousCaseListItems.Take(5).ToList(); + using var httpClient = new HttpClient(); foreach (var nisCode in _integrationContext.Municipalities.Select(x => x.NisCode)) diff --git a/src/Basisregisters.IntegrationDb.Schema/Models/Views/SuspiciousCases/SuspiciousCaseListItem.cs b/src/Basisregisters.IntegrationDb.Schema/Models/Views/SuspiciousCases/SuspiciousCaseListItem.cs index 9abd3e09..78ae1c25 100644 --- a/src/Basisregisters.IntegrationDb.Schema/Models/Views/SuspiciousCases/SuspiciousCaseListItem.cs +++ b/src/Basisregisters.IntegrationDb.Schema/Models/Views/SuspiciousCases/SuspiciousCaseListItem.cs @@ -25,7 +25,7 @@ public void Configure(EntityTypeBuilder builder) ""NisCode"" ,""Count"" ,""Type"" - FROM {ViewName};"); + FROM {ViewName}"); } public const string ViewName = @$"""{IntegrationContext.Schema}"".""VIEW_{nameof(SuspiciousCaseListItemConfiguration)}"""; diff --git a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Category.cs b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Category.cs index 0199088e..224745be 100644 --- a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Category.cs +++ b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Category.cs @@ -11,36 +11,42 @@ public enum Category /// /// Adres. /// + [DataMember(Name = "adres")] [EnumMember] Address = 1, /// /// Perceel. /// + [DataMember(Name = "perceel")] [EnumMember] Parcel = 2, /// /// Wegverbinding. /// + [DataMember(Name = "wegsegment")] [EnumMember] RoadSegment = 3, /// /// Gebouw. /// + [DataMember(Name = "gebouw")] [EnumMember] Building = 4, /// /// Gebouweenheid. /// + [DataMember(Name = "gebouweenheid")] [EnumMember] Buildingunit = 5, /// /// Straatnaam. /// + [DataMember(Name = "straatnaam")] [EnumMember] StreetName = 6 } diff --git a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Infrastructure/Startup.cs b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Infrastructure/Startup.cs index 3091ecb4..9e91dd8c 100644 --- a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Infrastructure/Startup.cs +++ b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Infrastructure/Startup.cs @@ -14,13 +14,16 @@ namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Infrastructure using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.AspNetCore.Mvc.Infrastructure; + using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; + using Microsoft.Extensions.Logging.Abstractions; using Microsoft.OpenApi.Models; using Modules; + using Schema; /// Represents the startup process for the application. public class Startup @@ -105,10 +108,27 @@ public IServiceProvider ConfigureServices(IServiceCollection services) Authorization = options => { options.AddAcmIdmAuthorization(); } } } - .EnableJsonErrorActionFilterOption()) + + .EnableJsonErrorActionFilterOption()) .Configure(_configuration.GetSection("ResponseOptions")) .AddSingleton(); // Used to retrieve the authenticated user claims. + var connectionString = _configuration.GetConnectionString("IntegrationDb") + ?? throw new InvalidOperationException( + $"Could not find a connection string with name 'IntegrationDb'"); + + services + .AddDbContext((_, options) => + { + options.UseLoggerFactory(new NullLoggerFactory()); + options.UseNpgsql(connectionString, sqlServerOptions => + { + sqlServerOptions.EnableRetryOnFailure(); + sqlServerOptions.MigrationsHistoryTable(IntegrationContext.MigrationsTableName, IntegrationContext.Schema); + sqlServerOptions.UseNetTopologySuite(); + }); + }); + var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterModule(new ApiModule(_configuration, services, _loggerFactory)); _applicationContainer = containerBuilder.Build(); @@ -185,7 +205,7 @@ public void Configure( // _configuration.GetConnectionString("SuspiciousCasesAdmin"), // serviceProvider.GetService()); - StartupHelpers.CheckDatabases(healthCheckService, DatabaseTag, loggerFactory).GetAwaiter().GetResult(); + //StartupHelpers.CheckDatabases(healthCheckService, DatabaseTag, loggerFactory).GetAwaiter().GetResult(); } private static string GetApiLeadingText(ApiVersionDescription description) diff --git a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/List/SuspiciousCasesListResponse.cs b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/List/SuspiciousCasesListResponse.cs index 17989d22..66b7026c 100644 --- a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/List/SuspiciousCasesListResponse.cs +++ b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/List/SuspiciousCasesListResponse.cs @@ -10,7 +10,7 @@ public sealed class SuspiciousCasesListResponse /// /// Collectie van verdachte gevallen. /// - [DataMember(Name = "Gebouwen", Order = 1)] + [DataMember(Name = "resultaat", Order = 1)] [JsonProperty(Required = Required.DisallowNull)] public List VerdachteGevallen { get; set; } diff --git a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/List/SuspiciousCasesListResponseItem.cs b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/List/SuspiciousCasesListResponseItem.cs index 9cd0eff9..24de1181 100644 --- a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/List/SuspiciousCasesListResponseItem.cs +++ b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/List/SuspiciousCasesListResponseItem.cs @@ -31,7 +31,7 @@ public sealed class SuspiciousCasesListResponseItem /// /// Naam van het verdacht geval. Dit is uitbreidbaar in de toekomst met nieuwe verdachte gevallen. /// - [DataMember(Name = "Naam", Order = 4)] + [DataMember(Name = "Aantal", Order = 4)] [JsonProperty(Required = Required.DisallowNull)] public int Count { get; set; } diff --git a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Severity.cs b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Severity.cs index 587a8787..7ce6c725 100644 --- a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Severity.cs +++ b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Severity.cs @@ -11,18 +11,21 @@ public enum Severity /// /// Foutief. /// + [DataMember(Name = "foutief")] [EnumMember] Incorrect = 1, /// /// Verdacht. /// + [DataMember(Name = "verdacht")] [EnumMember] Suspicious = 2, /// /// Verbeterbaar. /// + [DataMember(Name = "verbeterbaar")] [EnumMember] Improveable = 3 } diff --git a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/SuspiciousCase.cs b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/SuspiciousCase.cs index 0ca403bc..15cd0ba5 100644 --- a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/SuspiciousCase.cs +++ b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/SuspiciousCase.cs @@ -9,11 +9,11 @@ public class SuspiciousCase { { SuspiciousCasesType.CurrentAddressWithoutLinkedParcelsOrBuildingUnits, - new SuspiciousCase(Category.Address, "Adressen \"in gebruik\" zonder koppeling aan perceel of gebouweenheid", Severity.Incorrect) + new SuspiciousCase(Category.Address, "Adressen 'in gebruik' zonder koppeling aan perceel of gebouweenheid", Severity.Incorrect) }, { SuspiciousCasesType.ProposedAddressWithoutLinkedParcelsOrBuildingUnits, - new SuspiciousCase(Category.Address, "Adressen \"voorgesteld\" zonder koppeling aan perceel of gebouweenheid", Severity.Suspicious) + new SuspiciousCase(Category.Address, "Adressen 'voorgesteld' zonder koppeling aan perceel of gebouweenheid", Severity.Suspicious) }, { SuspiciousCasesType.AddressesOutsideOfMunicipalityBoundaries, @@ -21,27 +21,27 @@ public class SuspiciousCase }, { SuspiciousCasesType.CurrentStreetNamesWithoutRoadSegment, - new SuspiciousCase(Category.StreetName, "Straatnamen \"in gebruik\" zonder koppeling met wegverbinding", Severity.Incorrect) + new SuspiciousCase(Category.StreetName, "Straatnamen 'in gebruik' zonder koppeling met wegverbinding", Severity.Incorrect) }, { SuspiciousCasesType.StreetNamesLongerThanTwoYearsProposed, - new SuspiciousCase(Category.StreetName, "Straatnamen langer dan 2 jaar \"voorgesteld\"", Severity.Improveable) + new SuspiciousCase(Category.StreetName, "Straatnamen langer dan 2 jaar 'voorgesteld'", Severity.Improveable) }, { SuspiciousCasesType.AddressesLongerThanTwoYearsProposed, - new SuspiciousCase(Category.Address, "Adressen bestaat langer dan 2 jaar en heeft nog de status \"voorgesteld\"", Severity.Improveable) + new SuspiciousCase(Category.Address, "Adressen bestaat langer dan 2 jaar en heeft nog de status 'voorgesteld'", Severity.Improveable) }, { SuspiciousCasesType.RoadSegmentsLongerThanTwoYearsProposed, - new SuspiciousCase(Category.RoadSegment, "Wegverbindingen bestaat langer dan 2 jaar en heeft nog de status \"voorgesteld\"", Severity.Improveable) + new SuspiciousCase(Category.RoadSegment, "Wegverbindingen bestaat langer dan 2 jaar en heeft nog de status 'voorgesteld'", Severity.Improveable) }, { SuspiciousCasesType.BuildingLongerThanTwoYearsPlanned, - new SuspiciousCase(Category.Building, "Gebouw bestaat langer dan 2 jaar en heeft nog steeds de status \"gepland\"", Severity.Improveable) + new SuspiciousCase(Category.Building, "Gebouw bestaat langer dan 2 jaar en heeft nog steeds de status 'gepland'", Severity.Improveable) }, { SuspiciousCasesType.BuildingUnitLongerThanTwoYearsPlanned, - new SuspiciousCase(Category.Buildingunit, "Gebouweenheden bestaat langer dan 2 jaar en heeft nog de status \"gepland\"", Severity.Improveable) + new SuspiciousCase(Category.Buildingunit, "Gebouweenheden bestaat langer dan 2 jaar en heeft nog de status 'gepland'", Severity.Improveable) }, { SuspiciousCasesType.StreetNameWithOnlyOneRoadSegmentToOnlyOneSide, @@ -49,23 +49,23 @@ public class SuspiciousCase }, { SuspiciousCasesType.AddressesAppointedByAdministratorOutsideLinkedBuilding, - new SuspiciousCase(Category.Address, "Adressen met herkomst \"AangeduidDoorBeheerder\" buiten het gekoppelde gebouw", Severity.Improveable) + new SuspiciousCase(Category.Address, "Adressen met herkomst 'AangeduidDoorBeheerder' buiten het gekoppelde gebouw", Severity.Improveable) }, { SuspiciousCasesType.AddressesWithBuildingUnitSpecificationOutsideLinkedActiveBuildingUnit, - new SuspiciousCase(Category.Address, "Adressen met specificatie \"gebouweenheid \" en status \"inGebruik\" zonder koppeling met gebouweenheid", Severity.Improveable) + new SuspiciousCase(Category.Address, "Adressen met specificatie 'gebouweenheid ' en status 'inGebruik' zonder koppeling met gebouweenheid", Severity.Improveable) }, { SuspiciousCasesType.BuildingUnitsWithoutAddress, - new SuspiciousCase(Category.Buildingunit, "Gebouweenheden met status \"gepland\" of \"gerealiseerd\" die niet gekoppeld zijn aan een adres", Severity.Improveable) + new SuspiciousCase(Category.Buildingunit, "Gebouweenheden met status 'gepland' of 'gerealiseerd' die niet gekoppeld zijn aan een adres", Severity.Improveable) }, { SuspiciousCasesType.BuildingUnitsLinkedToMultipleAddresses, - new SuspiciousCase(Category.Buildingunit, "Gebouweenheden met status \"gepland\" of \"gerealiseerd\" die gekoppeld zijn aan meerdere adressen", Severity.Improveable) + new SuspiciousCase(Category.Buildingunit, "Gebouweenheden met status 'gepland' of 'gerealiseerd' die gekoppeld zijn aan meerdere adressen", Severity.Improveable) }, { SuspiciousCasesType.AddressesLinkedToMultipleBuildingUnits, - new SuspiciousCase(Category.Address, "Adressen met status \"voorgesteld\" of \"inGebruik\" die gekoppeld zijn aan meerdere gebouweenheden", Severity.Improveable) + new SuspiciousCase(Category.Address, "Adressen met status 'voorgesteld' of 'inGebruik' die gekoppeld zijn aan meerdere gebouweenheden", Severity.Improveable) } }; diff --git a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/SuspiciousCasesController.cs b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/SuspiciousCasesController.cs index f8fb6b5f..cf293782 100644 --- a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/SuspiciousCasesController.cs +++ b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/SuspiciousCasesController.cs @@ -65,7 +65,7 @@ public async Task List(CancellationToken cancellationToken) filtering.Filter.NisCode = nisCode; } - if (string.IsNullOrWhiteSpace(filtering.Filter.NisCode)) + if (string.IsNullOrWhiteSpace(filtering.Filter?.NisCode)) { throw new ValidationException(new[] { diff --git a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/appsettings.json b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/appsettings.json index 7ed4823b..6226b828 100644 --- a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/appsettings.json +++ b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/appsettings.json @@ -1,7 +1,6 @@ { "ConnectionStrings": { - "SuspiciousCases": "Server=(localdb)\\mssqllocaldb;Database=EFProviders.InMemory.BuildingRegistry;Trusted_Connection=True;TrustServerCertificate=True;", - "SuspiciousCasesAdmin": "Server=(localdb)\\mssqllocaldb;Database=EFProviders.InMemory.BuildingRegistry;Trusted_Connection=True;TrustServerCertificate=True;" + "IntegrationDb": "Server=(localdb)\\mssqllocaldb;Database=EFProviders.InMemory.BuildingRegistry;Trusted_Connection=True;TrustServerCertificate=True;" }, "OAuth2IntrospectionOptions": { "ClientId": "clientid", @@ -9,6 +8,9 @@ "Authority": "https://authenticatie-ti.vlaanderen.be/op/v1/auth", "IntrospectionEndpoint": "https://authenticatie-ti.vlaanderen.be/op/v1/introspect" }, + "ClientId": "", + "ClientSecret": "", + "BaseUrl": "https://api.staging-basisregisters.vlaanderen/", "DataDog": { "Enabled": true,