-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* functionality for sbl bridge * fix db migration * add empty value to appsettings * dont initialize httpClient in dev service * test with client instead of singleton * log more info * cleanup * fix missing comma * send to sblbridge when published * cleanup * big cleanup --------- Co-authored-by: Hammerbeck <andreas.hammerbeck@digdir.no>
- Loading branch information
Showing
30 changed files
with
809 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ | |
} | ||
}, | ||
"AllowedHosts": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/Altinn.Correspondence.Application/ProcessLegacyParty/ProcessLegacyPartyHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Altinn.Correspondence.Core.Repositories; | ||
using Altinn.Correspondence.Core.Services; | ||
using Microsoft.Extensions.Logging; | ||
using OneOf; | ||
using System.Security.Claims; | ||
|
||
namespace Altinn.Correspondence.Application.ProcessLegacyParty; | ||
|
||
public class ProcessLegacyPartyHandler( | ||
ILogger<ProcessLegacyPartyHandler> logger, | ||
IAltinnRegisterService altinnRegisterService, | ||
IAltinnSblBridgeService sblBridgeService, | ||
ILegacyPartyRepository legacyPartyRepository) | ||
{ | ||
public async Task Process(string recipient, ClaimsPrincipal? user, CancellationToken cancellationToken) | ||
{ | ||
logger.LogInformation("Process legacy party {recipient}", recipient); | ||
var partyId = await altinnRegisterService.LookUpPartyId(recipient, cancellationToken); | ||
if (partyId is null) | ||
{ | ||
throw new Exception("Failed to look up party in Altinn Register"); | ||
} | ||
var exists = await legacyPartyRepository.PartyAlreadyExists((int)partyId, cancellationToken); | ||
if (!exists) | ||
{ | ||
var success = await sblBridgeService.AddPartyToSblBridge((int)partyId, cancellationToken); | ||
if (!success) | ||
{ | ||
throw new Exception("Failed to send party to SBL"); | ||
} | ||
logger.Log(LogLevel.Information, "Party {partyId} added to SBL", partyId); | ||
await legacyPartyRepository.AddLegacyPartyId((int)partyId, cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/Altinn.Correspondence.Core/Models/Entities/LegacyPartyEntity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using Altinn.Correspondence.Core.Models.Enums; | ||
|
||
namespace Altinn.Correspondence.Core.Models.Entities | ||
{ | ||
public class LegacyPartyEntity | ||
{ | ||
[Key] | ||
public Guid Id { get; set; } | ||
public int PartyId { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/Altinn.Correspondence.Core/Repositories/ILegacyPartyRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Altinn.Correspondence.Core.Models.Entities; | ||
|
||
namespace Altinn.Correspondence.Core.Repositories | ||
{ | ||
public interface ILegacyPartyRepository | ||
{ | ||
Task AddLegacyPartyId(int id, CancellationToken cancellationToken); | ||
Task<bool> PartyAlreadyExists(int id, CancellationToken cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/Altinn.Correspondence.Core/Services/IAltinnSblBridgeService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Altinn.Correspondence.Core.Models.Entities; | ||
|
||
namespace Altinn.Correspondence.Core.Services; | ||
public interface IAltinnSblBridgeService | ||
{ | ||
Task<bool> AddPartyToSblBridge(int partyId, CancellationToken cancellationToken); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/Altinn.Correspondence.Integrations/Altinn/SblBridge/AltinnSblBridgeDevService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Altinn.Correspondence.Core.Services; | ||
|
||
namespace Altinn.Correspondence.Integrations.Altinn.SblBridge; | ||
public class AltinnSblBridgeDevService : IAltinnSblBridgeService | ||
{ | ||
private readonly string _baseUrl; | ||
public AltinnSblBridgeDevService(string baseUrl) | ||
{ | ||
_baseUrl = baseUrl; | ||
} | ||
|
||
public async Task<bool> AddPartyToSblBridge(int partyId, CancellationToken cancellationToken = default) | ||
{ | ||
if (partyId <= 0) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Altinn.Correspondence.Integrations/Altinn/SblBridge/AltinnSblBridgeService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Net.Http.Headers; | ||
using System.Text; | ||
using Altinn.Correspondence.Core.Services; | ||
|
||
|
||
namespace Altinn.Correspondence.Integrations.Altinn.SblBridge; | ||
public class AltinnSblBridgeService : IAltinnSblBridgeService | ||
{ | ||
private readonly HttpClient _httpClient; | ||
|
||
public AltinnSblBridgeService(HttpClient httpClient) | ||
{ | ||
_httpClient = httpClient; | ||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||
} | ||
|
||
public async Task<bool> AddPartyToSblBridge(int partyId, CancellationToken cancellationToken = default) | ||
{ | ||
if (partyId <= 0) | ||
{ | ||
return false; | ||
} | ||
StringContent content = new StringContent(partyId.ToString(), Encoding.UTF8, "application/json"); | ||
using var response = await _httpClient.PostAsync($"authorization/api/partieswithmessages", content, cancellationToken); | ||
if (!response.IsSuccessStatusCode) | ||
{ | ||
var statusCode = response.StatusCode; | ||
var errorContent = await response.Content.ReadAsStringAsync(cancellationToken); | ||
throw new Exception($"Error when adding party to SBL Bridge. Statuscode was: ${statusCode}, error was: ${errorContent}"); | ||
} | ||
return true; | ||
} | ||
} |
Oops, something went wrong.