diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92b5c41f4..5394a1589 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 6.0.x + dotnet-version: 8.0.x - name: Build solution run: dotnet build BDMS.sln -c Release /warnaserror @@ -52,7 +52,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 6.0.x + dotnet-version: 8.0.x - name: Build solution run: dotnet build BDMS.sln -c Release /warnaserror diff --git a/src/api/Authentication/BasicAuthenticationHandler.cs b/src/api/Authentication/BasicAuthenticationHandler.cs index bf53bb8f5..8ead2d82f 100644 --- a/src/api/Authentication/BasicAuthenticationHandler.cs +++ b/src/api/Authentication/BasicAuthenticationHandler.cs @@ -19,10 +19,9 @@ public class BasicAuthenticationHandler : AuthenticationHandlerThe monitor for the options instance. /// The . /// The . - /// The . /// If is null. - public BasicAuthenticationHandler(BdmsContext dbContext, IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) - : base(options, logger, encoder, clock) + public BasicAuthenticationHandler(BdmsContext dbContext, IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder) + : base(options, logger, encoder) { this.dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); } diff --git a/src/api/BDMS.csproj b/src/api/BDMS.csproj index e102f3e1e..c0f934a81 100644 --- a/src/api/BDMS.csproj +++ b/src/api/BDMS.csproj @@ -1,11 +1,10 @@ - - net6.0 + net8.0 enable enable true - 6.0-latest + 8.0-all CS1591,CS8618,CS8620 BDMS GeoWerkstatt GmbH @@ -18,32 +17,26 @@ Linux ..\.. - - + - + - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - all - runtime; build; native; contentfiles; analyzers + + + + + + + + + all + runtime; build; native; contentfiles; analyzers <_Parameter1>$(AssemblyName).Test - - + \ No newline at end of file diff --git a/src/api/BdmsContext.cs b/src/api/BdmsContext.cs index da3e6127f..70bf8d010 100644 --- a/src/api/BdmsContext.cs +++ b/src/api/BdmsContext.cs @@ -39,7 +39,10 @@ public class BdmsContext : DbContext public BdmsContext(DbContextOptions options) : base(options) { +#pragma warning disable CS0618 // Type or member is obsolete, however they do not plan on removing it any time soon. + // TODO: https://github.com/geoadmin/suite-bdms/issues/851 NpgsqlConnection.GlobalTypeMapper.MapEnum(); +#pragma warning restore CS0618 // Type or member is obsolete, however they do not plan on removing it any time soon. } /// diff --git a/src/api/BdmsContextExtensions.cs b/src/api/BdmsContextExtensions.cs index bae126ae8..91f30ea2c 100644 --- a/src/api/BdmsContextExtensions.cs +++ b/src/api/BdmsContextExtensions.cs @@ -698,16 +698,16 @@ FieldMeasurement SeededFieldMeasurements(Observation observation) context.SaveChanges(); // Sync all database sequences - context.Database.ExecuteSqlRaw($"SELECT setval(pg_get_serial_sequence('bdms.workgroups', 'id_wgp'), {workgroup_ids - 1})"); - context.Database.ExecuteSqlRaw($"SELECT setval(pg_get_serial_sequence('bdms.borehole', 'id_bho'), {borehole_ids - 1})"); - context.Database.ExecuteSqlRaw($"SELECT setval(pg_get_serial_sequence('bdms.events', 'id_evs'), {event_ids - 1})"); - context.Database.ExecuteSqlRaw($"SELECT setval(pg_get_serial_sequence('bdms.feedbacks', 'id_feb'), {feedback_ids - 1})"); - context.Database.ExecuteSqlRaw($"SELECT setval(pg_get_serial_sequence('bdms.files', 'id_fil'), {file_ids - 1})"); - context.Database.ExecuteSqlRaw($"SELECT setval(pg_get_serial_sequence('bdms.stratigraphy', 'id_sty'), {stratigraphy_ids - 1})"); - context.Database.ExecuteSqlRaw($"SELECT setval(pg_get_serial_sequence('bdms.layer', 'id_lay'), {layer_ids - 1})"); - context.Database.ExecuteSqlRaw($"SELECT setval(pg_get_serial_sequence('bdms.workflow', 'id_wkf'), {workflow_ids - 1})"); - context.Database.ExecuteSqlRaw($"SELECT setval(pg_get_serial_sequence('bdms.observation', 'id'), {observation_ids - 1})"); - context.Database.ExecuteSqlRaw($"SELECT setval(pg_get_serial_sequence('bdms.hydrotest_result', 'id'), {hydrotestResult_ids - 1})"); + context.Database.ExecuteSqlInterpolated($"SELECT setval(pg_get_serial_sequence('bdms.workgroups', 'id_wgp'), {workgroup_ids - 1})"); + context.Database.ExecuteSqlInterpolated($"SELECT setval(pg_get_serial_sequence('bdms.borehole', 'id_bho'), {borehole_ids - 1})"); + context.Database.ExecuteSqlInterpolated($"SELECT setval(pg_get_serial_sequence('bdms.events', 'id_evs'), {event_ids - 1})"); + context.Database.ExecuteSqlInterpolated($"SELECT setval(pg_get_serial_sequence('bdms.feedbacks', 'id_feb'), {feedback_ids - 1})"); + context.Database.ExecuteSqlInterpolated($"SELECT setval(pg_get_serial_sequence('bdms.files', 'id_fil'), {file_ids - 1})"); + context.Database.ExecuteSqlInterpolated($"SELECT setval(pg_get_serial_sequence('bdms.stratigraphy', 'id_sty'), {stratigraphy_ids - 1})"); + context.Database.ExecuteSqlInterpolated($"SELECT setval(pg_get_serial_sequence('bdms.layer', 'id_lay'), {layer_ids - 1})"); + context.Database.ExecuteSqlInterpolated($"SELECT setval(pg_get_serial_sequence('bdms.workflow', 'id_wkf'), {workflow_ids - 1})"); + context.Database.ExecuteSqlInterpolated($"SELECT setval(pg_get_serial_sequence('bdms.observation', 'id'), {observation_ids - 1})"); + context.Database.ExecuteSqlInterpolated($"SELECT setval(pg_get_serial_sequence('bdms.hydrotest_result', 'id'), {hydrotestResult_ids - 1})"); } } #pragma warning restore CA1505 diff --git a/src/api/BoreholeFileUploadService.cs b/src/api/BoreholeFileUploadService.cs index 941fb0fa5..9d3f11742 100644 --- a/src/api/BoreholeFileUploadService.cs +++ b/src/api/BoreholeFileUploadService.cs @@ -41,7 +41,7 @@ public async Task UploadFileAndLinkToBorehole(IFormFile file, int boreholeId) using (SHA256 sha256Hash = SHA256.Create()) { using Stream stream = file.OpenReadStream(); - byte[] hashBytes = sha256Hash.ComputeHash(stream); + byte[] hashBytes = await sha256Hash.ComputeHashAsync(stream).ConfigureAwait(false); base64Hash = Convert.ToBase64String(hashBytes); } diff --git a/src/api/Controllers/CodeListController.cs b/src/api/Controllers/CodeListController.cs index 130d3df1f..b09885b74 100644 --- a/src/api/Controllers/CodeListController.cs +++ b/src/api/Controllers/CodeListController.cs @@ -40,32 +40,29 @@ public async Task> GetAsync(string? schema = null, [FromQu codeLists = codeLists.Where(c => c.Schema == schema); } - if (testKindIds != null) + if (testKindIds?.Length > 0) { - if (testKindIds.Any()) + List hydrotestResultGeolcodes = new(); + List flowDirectionGeolCodes = new(); + List evaluationMethodIds = new(); + + Array.ForEach(testKindIds, testKindId => { - List hydrotestResultGeolcodes = new(); - List flowDirectionGeolCodes = new(); - List evaluationMethodIds = new(); - - Array.ForEach(testKindIds, testKindId => - { - // Get the Geolcode associated with the TestKindId. - int testKindGeolCode = context.Codelists.SingleOrDefault(c => c.Id == testKindId)?.Geolcode ?? 0; - - // Get the lists of Geolcodes from the HydroCodeLookup based on the testKindGeolCode. - hydrotestResultGeolcodes.AddRange(HydroCodeLookup.HydrotestResultParameterOptions.TryGetValue(testKindGeolCode, out List? tempHRIds) ? tempHRIds : new List()); - flowDirectionGeolCodes.AddRange(HydroCodeLookup.HydrotestFlowDirectionOptions.TryGetValue(testKindGeolCode, out List? tempFDIds) ? tempFDIds : new List()); - evaluationMethodIds.AddRange(HydroCodeLookup.HydrotestEvaluationMethodOptions.TryGetValue(testKindGeolCode, out List? tempEMIds) ? tempEMIds : new List()); - }); - - // Return the Codelists where the Codelist's Geolcode matches any of the compatible geolcodes form the HydroCodeLookup. - codeLists = codeLists.Where(c => - c.Geolcode != null && - ((c.Schema == HydrogeologySchemas.HydrotestResultParameterSchema && hydrotestResultGeolcodes.Contains(c.Geolcode.Value)) || - (c.Schema == HydrogeologySchemas.FlowdirectionSchema && flowDirectionGeolCodes.Contains(c.Geolcode.Value)) || - (c.Schema == HydrogeologySchemas.EvaluationMethodSchema && evaluationMethodIds.Contains(c.Geolcode.Value)))); - } + // Get the Geolcode associated with the TestKindId. + int testKindGeolCode = context.Codelists.SingleOrDefault(c => c.Id == testKindId)?.Geolcode ?? 0; + + // Get the lists of Geolcodes from the HydroCodeLookup based on the testKindGeolCode. + hydrotestResultGeolcodes.AddRange(HydroCodeLookup.HydrotestResultParameterOptions.TryGetValue(testKindGeolCode, out List? tempHRIds) ? tempHRIds : new List()); + flowDirectionGeolCodes.AddRange(HydroCodeLookup.HydrotestFlowDirectionOptions.TryGetValue(testKindGeolCode, out List? tempFDIds) ? tempFDIds : new List()); + evaluationMethodIds.AddRange(HydroCodeLookup.HydrotestEvaluationMethodOptions.TryGetValue(testKindGeolCode, out List? tempEMIds) ? tempEMIds : new List()); + }); + + // Return the Codelists where the Codelist's Geolcode matches any of the compatible geolcodes form the HydroCodeLookup. + codeLists = codeLists.Where(c => + c.Geolcode != null && + ((c.Schema == HydrogeologySchemas.HydrotestResultParameterSchema && hydrotestResultGeolcodes.Contains(c.Geolcode.Value)) || + (c.Schema == HydrogeologySchemas.FlowdirectionSchema && flowDirectionGeolCodes.Contains(c.Geolcode.Value)) || + (c.Schema == HydrogeologySchemas.EvaluationMethodSchema && evaluationMethodIds.Contains(c.Geolcode.Value)))); } return await codeLists.AsNoTracking().ToListAsync().ConfigureAwait(false); @@ -120,6 +117,6 @@ public async Task DownloadCsvAsync(CancellationToken cancellation cancellationToken).ConfigureAwait(false); Response.Headers.ContentDisposition = "attachment; filename=codelist_export.csv"; - return Content(await reader.ReadToEndAsync().ConfigureAwait(false), "text/csv", Encoding.UTF8); + return Content(await reader.ReadToEndAsync(cancellationToken).ConfigureAwait(false), "text/csv", Encoding.UTF8); } } diff --git a/src/api/Controllers/HydrotestController.cs b/src/api/Controllers/HydrotestController.cs index 8a9dc71dd..1a15fbc50 100644 --- a/src/api/Controllers/HydrotestController.cs +++ b/src/api/Controllers/HydrotestController.cs @@ -136,7 +136,7 @@ private async Task> GetCodelists(List codelistIds) private bool AreCodelistIdsPresent(Hydrotest hydrotest) { - return hydrotest.CodelistIds != null && hydrotest.CodelistIds.Any(); + return hydrotest.CodelistIds?.Count > 0; } private bool AreHydrotestCodelistsCompatible(Hydrotest hydrotest) @@ -153,7 +153,7 @@ private bool AreHydrotestCodelistsCompatible(Hydrotest hydrotest) .ToList(); // If there are HydrotestResults, check if the ParameterIds in the results are compatible. - if (hydrotest.HydrotestResults?.Any() == true && testKindGeolCodes.Any()) + if (hydrotest.HydrotestResults?.Count > 0 && testKindGeolCodes.Count > 0) { var compatibleParameterIds = GetCompatibleCodelistIds(testKindGeolCodes, HydrogeologySchemas.HydrotestResultParameterSchema, HydroCodeLookup.HydrotestResultParameterOptions); if (!hydrotest.HydrotestResults.All(r => compatibleParameterIds.Contains(r.ParameterId))) @@ -165,7 +165,7 @@ private bool AreHydrotestCodelistsCompatible(Hydrotest hydrotest) var compatibleCodelistIds = new List(); // If there are CodelistIds, find the compatible CodelistIds for the flow direction and evaluation method options. - if (hydrotest.CodelistIds?.Any() == true && testKindGeolCodes.Any()) + if (hydrotest.CodelistIds?.Count > 0 && testKindGeolCodes.Count > 0) { compatibleCodelistIds.AddRange(hydrotestKindCodelistIds); compatibleCodelistIds.AddRange(GetCompatibleCodelistIds(testKindGeolCodes, HydrogeologySchemas.FlowdirectionSchema, HydroCodeLookup.HydrotestFlowDirectionOptions)); @@ -191,7 +191,7 @@ private List GetCompatibleCodelistIds(List testKindGeolCodes, string s } }); - if (compatibleGeolCodes.Any()) + if (compatibleGeolCodes.Count > 0) { return compatibleGeolCodes.Distinct().ToList(); } diff --git a/src/api/Controllers/UploadController.cs b/src/api/Controllers/UploadController.cs index 38756e2b6..16c0c7c57 100644 --- a/src/api/Controllers/UploadController.cs +++ b/src/api/Controllers/UploadController.cs @@ -161,7 +161,7 @@ public async Task> UploadFileAsync(int workgroupId, IFormFile // Add attachments to borehole. if (attachments != null) { - var boreholeImportsWithAttachments = boreholeImports.Where(x => x.Attachments?.Any() == true).ToList(); + var boreholeImportsWithAttachments = boreholeImports.Where(x => x.Attachments?.Length > 0).ToList(); foreach (var boreholeImport in boreholeImportsWithAttachments) { var attachmentFileNames = boreholeImport.Attachments?.Split(",").Select(s => s.Replace(" ", "", StringComparison.InvariantCulture)).ToList(); @@ -174,7 +174,7 @@ public async Task> UploadFileAsync(int workgroupId, IFormFile } // Add lithology imports if provided - if (lithologyImports.Any()) + if (lithologyImports.Count > 0) { // Get the kind id of a lithostratigraphy. var lithoStratiKindId = context.Codelists.Single(cl => cl.Schema == "layer_kind" && cl.IsDefault == true).Id; diff --git a/src/api/Dockerfile b/src/api/Dockerfile index 8954fec7e..a75fc8716 100644 --- a/src/api/Dockerfile +++ b/src/api/Dockerfile @@ -1,11 +1,11 @@ -FROM mcr.microsoft.com/dotnet/sdk:6.0 AS development +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS development ENV ASPNETCORE_ENVIRONMENT=Development WORKDIR /src # Install missing packages RUN apt-get -y update RUN apt-get -y install git vim curl htop -RUN dotnet tool install --global dotnet-ef --version 6.0.7 +RUN dotnet tool install --global dotnet-ef --version 8.0.0 ENV PATH $PATH:/root/.dotnet/tools # Restore dependencies and tools @@ -14,7 +14,7 @@ RUN dotnet restore ENTRYPOINT dotnet watch run --no-launch-profile -FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build ARG VERSION ARG REVISION WORKDIR /src @@ -32,7 +32,7 @@ RUN dotnet publish \ -p:SourceRevisionId=${REVISION} \ -o /app/publish -FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS deploy +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS deploy ENV ASPNETCORE_ENVIRONMENT=Production WORKDIR /app diff --git a/src/api/Models/Workflow.cs b/src/api/Models/Workflow.cs index 013d14c69..b15ea0e70 100644 --- a/src/api/Models/Workflow.cs +++ b/src/api/Models/Workflow.cs @@ -55,6 +55,6 @@ public class Workflow : IIdentifyable /// /// Gets or sets the . /// - [Column("id_rol_fk", TypeName = "int")] + [Column("id_rol_fk", TypeName = "integer")] public Role? Role { get; set; } } diff --git a/tests/BDMS.Test.csproj b/tests/BDMS.Test.csproj index 3b3853422..3fd28e511 100644 --- a/tests/BDMS.Test.csproj +++ b/tests/BDMS.Test.csproj @@ -1,8 +1,7 @@ - true - net6.0 + net8.0 enable enable false @@ -10,28 +9,22 @@ true CS1591,CS8618,CS8620,CA1001,CA1014,CS8625,CA2000,CA2007 - - - + + + + + + + + all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - all - runtime; build; native; contentfiles; analyzers + runtime; build; native; contentfiles; analyzers - - Always @@ -163,5 +156,4 @@ Always - - + \ No newline at end of file diff --git a/tests/CoordinateControllerTest.cs b/tests/CoordinateControllerTest.cs index 588eee415..8f4e2aeb8 100644 --- a/tests/CoordinateControllerTest.cs +++ b/tests/CoordinateControllerTest.cs @@ -271,7 +271,7 @@ private void AssertLV95BoreholeWithMissingDestCoordinates(Borehole initialBohrun Assert.AreEqual(ReferenceSystem.LV95, editierteBohrung.OriginalReferenceSystem); Assert.AreEqual(2582431.203588229, editierteBohrung.LocationX); Assert.AreEqual(1189604.098138797, editierteBohrung.LocationY); - Assert.AreEqual("POINT (2582431.2035882291 1189604.0981387971)", editierteBohrung.Geometry.ToString()); + Assert.AreEqual("POINT (2582431.203588229 1189604.098138797)", editierteBohrung.Geometry.ToString()); Assert.AreEqual(9876.543543544, editierteBohrung.LocationXLV03); Assert.AreEqual(1234.562356236, editierteBohrung.LocationYLV03); } diff --git a/tests/UploadControllerTest.cs b/tests/UploadControllerTest.cs index 7ffcd9404..fc557d3db 100644 --- a/tests/UploadControllerTest.cs +++ b/tests/UploadControllerTest.cs @@ -431,7 +431,7 @@ public async Task UploadBoreholeWithLV03CoordinatesAsync() Assert.AreEqual(1131551.4611465326, borehole.LocationY); Assert.AreEqual(649258.36125645251, borehole.LocationXLV03); Assert.AreEqual(131551.85893587855, borehole.LocationYLV03); - Assert.AreEqual("POINT (2649258.1270818082 1131551.4611465326)", borehole.Geometry.ToString()); + Assert.AreEqual("POINT (2649258.127081808 1131551.4611465326)", borehole.Geometry.ToString()); Assert.AreEqual("Valais", borehole.Canton); Assert.AreEqual("Schweiz", borehole.Country); Assert.AreEqual("Mörel-Filet", borehole.Municipality);