Skip to content

Commit

Permalink
Passthrough values
Browse files Browse the repository at this point in the history
  • Loading branch information
elsand committed Apr 20, 2022
1 parent 5b0ec7a commit 7d124a1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 51 deletions.
26 changes: 4 additions & 22 deletions src/Altinn.Dan.Plugin.Pensjon/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,19 @@ public async Task<HttpResponseData> GetNorskPensjon(

private async Task<List<EvidenceValue>> GetEvidenceValuesPensjon(EvidenceHarvesterRequest evidenceHarvesterRequest)
{
var content = await MakeRequest<NorskPensjonResponse>(_settings.NorskPensjonUrl, evidenceHarvesterRequest.SubjectParty);
var content = await MakeRequest(_settings.NorskPensjonUrl, evidenceHarvesterRequest.SubjectParty);

var ecb = new EvidenceBuilder(new Metadata(), "NorskPensjon");
ecb.AddEvidenceValue($"default", JsonConvert.SerializeObject(content), Metadata.SOURCE, false);
ecb.AddEvidenceValue($"default", content, Metadata.SOURCE, false);

return ecb.GetEvidenceValues();
}

private async Task<T> MakeRequest<T>(string target, Party subject) where T : new()
private async Task<string> MakeRequest(string target, Party subject)
{
HttpResponseMessage result = null;
var requestBody = new NorskPensjonRequest();
requestBody.Fodselsnummer = subject.NorwegianSocialSecurityNumber;
T response = default(T);

try
{
var request = new HttpRequestMessage(HttpMethod.Post, target);
Expand All @@ -78,23 +76,7 @@ private async Task<List<EvidenceValue>> GetEvidenceValuesPensjon(EvidenceHarvest
{
case HttpStatusCode.OK:
{
try
{
response = JsonConvert.DeserializeObject<T>(await result.Content.ReadAsStringAsync());
}
catch (Exception ex)
{
_logger.LogError($"Could not deserialize response: {ex.Message}");

throw new EvidenceSourcePermanentServerException(Metadata.ERROR_CCR_UPSTREAM_ERROR, "Could not deserialize response: " + ex.Message);
}

if (response == null)
{
throw new EvidenceSourcePermanentServerException(Metadata.ERROR_CCR_UPSTREAM_ERROR, "Did not understand the data model returned from upstream source");
}

return response;
return await result.Content.ReadAsStringAsync();
}
case HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden:
{
Expand Down
2 changes: 1 addition & 1 deletion src/Altinn.Dan.Plugin.Pensjon/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public List<EvidenceCode> GetEvidenceCodes()
{
EvidenceValueName = "default",
ValueType = EvidenceValueType.JsonSchema,
JsonSchemaDefintion = JsonSchema.FromType<NorskPensjonResponse>().ToJson(Newtonsoft.Json.Formatting.Indented)
JsonSchemaDefintion = null
},
}
}
Expand Down
28 changes: 0 additions & 28 deletions src/Altinn.Dan.Plugin.Pensjon/Models/NorskPensjonResponse.cs

This file was deleted.

0 comments on commit 7d124a1

Please sign in to comment.