From 2cb122e13367609e887f2cd0607879905276df70 Mon Sep 17 00:00:00 2001 From: erlend oksvoll Date: Tue, 14 Nov 2023 15:36:23 +0100 Subject: [PATCH] clean up program.cs, fixed null in createresponse --- .../Altinn.Dan.Plugin.Pensjon.csproj | 6 +++--- src/Altinn.Dan.Plugin.Pensjon/Main.cs | 14 ++++++++------ src/Altinn.Dan.Plugin.Pensjon/Program.cs | 15 ++------------- .../Altinn.Dan.Plugin.Pensjon.Test.csproj | 2 ++ 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/Altinn.Dan.Plugin.Pensjon/Altinn.Dan.Plugin.Pensjon.csproj b/src/Altinn.Dan.Plugin.Pensjon/Altinn.Dan.Plugin.Pensjon.csproj index 3764707..9a8b17a 100644 --- a/src/Altinn.Dan.Plugin.Pensjon/Altinn.Dan.Plugin.Pensjon.csproj +++ b/src/Altinn.Dan.Plugin.Pensjon/Altinn.Dan.Plugin.Pensjon.csproj @@ -1,4 +1,4 @@ - + net6.0 v4 @@ -7,8 +7,8 @@ false - - + + diff --git a/src/Altinn.Dan.Plugin.Pensjon/Main.cs b/src/Altinn.Dan.Plugin.Pensjon/Main.cs index 6c7c5c8..bccddc1 100644 --- a/src/Altinn.Dan.Plugin.Pensjon/Main.cs +++ b/src/Altinn.Dan.Plugin.Pensjon/Main.cs @@ -41,7 +41,7 @@ public async Task GetNorskPensjon( var requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var evidenceHarvesterRequest = JsonConvert.DeserializeObject(requestBody); - return await EvidenceSourceResponse.CreateResponse(null, () => GetEvidenceValuesPensjon(evidenceHarvesterRequest)); + return await EvidenceSourceResponse.CreateResponse(req, () => GetEvidenceValuesPensjon(evidenceHarvesterRequest)); } private async Task> GetEvidenceValuesPensjon(EvidenceHarvesterRequest evidenceHarvesterRequest) @@ -49,7 +49,7 @@ private async Task> GetEvidenceValuesPensjon(EvidenceHarvest var content = await MakeRequest(_settings.NorskPensjonUrl, evidenceHarvesterRequest.SubjectParty); var ecb = new EvidenceBuilder(new Metadata(), "NorskPensjon"); - ecb.AddEvidenceValue($"default", content, Metadata.SOURCE, false); + ecb.AddEvidenceValue("default", content, Metadata.SOURCE, false); return ecb.GetEvidenceValues(); } @@ -57,13 +57,15 @@ private async Task> GetEvidenceValuesPensjon(EvidenceHarvest private async Task MakeRequest(string target, Party subject) { HttpResponseMessage result = null; - var requestBody = new NorskPensjonRequest(); - requestBody.Fodselsnummer = subject.NorwegianSocialSecurityNumber; + var requestBody = new NorskPensjonRequest + { + Fodselsnummer = subject.NorwegianSocialSecurityNumber + }; + try { var request = new HttpRequestMessage(HttpMethod.Post, target); - request.Content = new StringContent(JsonConvert.SerializeObject(requestBody), Encoding.UTF8, - "application/json"); + request.Content = new StringContent(JsonConvert.SerializeObject(requestBody), Encoding.UTF8, "application/json"); result = await _client.SendAsync(request); switch (result.StatusCode) { diff --git a/src/Altinn.Dan.Plugin.Pensjon/Program.cs b/src/Altinn.Dan.Plugin.Pensjon/Program.cs index f1bda30..838141d 100644 --- a/src/Altinn.Dan.Plugin.Pensjon/Program.cs +++ b/src/Altinn.Dan.Plugin.Pensjon/Program.cs @@ -2,6 +2,7 @@ using System.Net.Http; using System.Threading.Tasks; using Altinn.Dan.Plugin.Pensjon.Config; +using Dan.Common.Extensions; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -19,14 +20,9 @@ class Program private static Task Main(string[] args) { var host = new HostBuilder() - .ConfigureFunctionsWorkerDefaults() + .ConfigureDanPluginDefaults() .ConfigureServices(services => { - services.AddLogging(); - // See https://docs.microsoft.com/en-us/azure/azure-monitor/app/worker-service#using-application-insights-sdk-for-worker-services - services.AddApplicationInsightsTelemetryWorkerService(); - services.AddHttpClient(); - services.AddOptions() .Configure((settings, configuration) => configuration.Bind(settings)); ApplicationSettings = services.BuildServiceProvider().GetRequiredService>().Value; @@ -42,13 +38,6 @@ private static Task Main(string[] args) return handler; }); - - JsonConvert.DefaultSettings = () => new JsonSerializerSettings - { - DefaultValueHandling = DefaultValueHandling.Ignore, - ContractResolver = new CamelCasePropertyNamesContractResolver(), - Converters = new List() { new StringEnumConverter() } - }; }) .Build(); diff --git a/test/Altinn.Dan.Plugin.Pensjon.Test/Altinn.Dan.Plugin.Pensjon.Test.csproj b/test/Altinn.Dan.Plugin.Pensjon.Test/Altinn.Dan.Plugin.Pensjon.Test.csproj index 4d1e26a..f7a04d7 100644 --- a/test/Altinn.Dan.Plugin.Pensjon.Test/Altinn.Dan.Plugin.Pensjon.Test.csproj +++ b/test/Altinn.Dan.Plugin.Pensjon.Test/Altinn.Dan.Plugin.Pensjon.Test.csproj @@ -8,6 +8,8 @@ + +