Skip to content

Commit

Permalink
Merge pull request #855 from Klantinteractie-Servicesysteem/oud-naast…
Browse files Browse the repository at this point in the history
…-nieuw-nnpid

PC-357 NnpIdentifier instelbaar per zaaksysteem
  • Loading branch information
felixcicatt authored Aug 15, 2024
2 parents bd59a1d + f1468e3 commit 63a4b48
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void GetConfigReturnsCorrectVariables()
var deeplinkUrl = Guid.NewGuid().ToString();
var idProperty = Guid.NewGuid().ToString();

var config = new ZaaksysteemConfig(baseUrl, "", "", deeplinkUrl, idProperty);
var config = new ZaaksysteemConfig(baseUrl, "", "", deeplinkUrl, idProperty, null);

var sut = new GetZaaksysteemDeeplinkConfig(new[] { config }, Mock.Of<ILogger<GetZaaksysteemDeeplinkConfig>>());
var result = sut.Get(baseUrl);
Expand Down
64 changes: 57 additions & 7 deletions Kiss.Bff.Test/Zaaksysteem/GetZakenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ public async Task GetZaken_correctly_proxies_400_status_code()
.Respond(HttpStatusCode.BadRequest);
var httpClient = new HttpClient(handler);
var clientFactory = Mock.Of<IHttpClientFactory>(x => x.CreateClient(It.IsAny<string>()) == httpClient);
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters", null, null);
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters", null, null, null);


var sut = new GetZaken(new[] { config }, clientFactory, logger);

var result = await sut.Get(version, Enumerable.Empty<string>(), default);
var result = await sut.Get(version, Enumerable.Empty<string>(), null, null, default);
Assert.IsInstanceOfType<IStatusCodeActionResult>(result, out var statusCodeResult);
Assert.AreEqual(400, statusCodeResult.StatusCode);
}
Expand All @@ -94,12 +94,12 @@ public async Task GetZaken_correctly_proxies_unreachable_host()

var httpClient = new HttpClient(handler);
var clientFactory = Mock.Of<IHttpClientFactory>(x => x.CreateClient(It.IsAny<string>()) == httpClient);
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters", null, null);
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters", null, null, null);


var sut = new GetZaken(new[] { config }, clientFactory, logger);

var result = await sut.Get(version, Enumerable.Empty<string>(), default);
var result = await sut.Get(version, Enumerable.Empty<string>(), null, null, default);
Assert.IsInstanceOfType<IStatusCodeActionResult>(result, out var statusCodeResult);
Assert.AreEqual(502, statusCodeResult.StatusCode);
}
Expand All @@ -117,11 +117,61 @@ public async Task GetZaken_correctly_handles_missing_config()

var sut = new GetZaken(Enumerable.Empty<ZaaksysteemConfig>(), clientFactory, logger);

var result = await sut.Get(version, Enumerable.Empty<string>(), default);
var result = await sut.Get(version, Enumerable.Empty<string>(), null, null, default);
Assert.IsInstanceOfType<IStatusCodeActionResult>(result, out var statusCodeResult);
Assert.AreEqual(500, statusCodeResult.StatusCode);
}

[TestMethod]
public async Task GetZaken_with_kvknummer_and_rsin_queries_by_rsin_by_default()
{
var logger = Mock.Of<ILogger<GetZaken>>();
var handler = new MockHttpMessageHandler();
var baseUrl = "http://example.com";
var version = "my-version";
var rsin = "12345";
var kvkNummer = "54321";

handler.Expect($"{baseUrl}/zaken/api/{version}/zaken?rol__betrokkeneIdentificatie__nietNatuurlijkPersoon__innNnpId={rsin}")
.Respond("application/json", "{\"results\": []}");
var httpClient = new HttpClient(handler);
var clientFactory = Mock.Of<IHttpClientFactory>(x => x.CreateClient(It.IsAny<string>()) == httpClient);
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters", null, null, null);


var sut = new GetZaken(new[] { config }, clientFactory, logger);

var result = await sut.Get(version, Enumerable.Empty<string>(), kvkNummer, rsin, default);
Assert.IsInstanceOfType<IStatusCodeActionResult>(result, out var statusCodeResult);
Assert.AreEqual(200, statusCodeResult.StatusCode);
handler.VerifyNoOutstandingExpectation();
}

[TestMethod]
public async Task GetZaken_with_kvknummer_and_rsin_queries_by_kvknummer_if_specified_in_config()
{
var logger = Mock.Of<ILogger<GetZaken>>();
var handler = new MockHttpMessageHandler();
var baseUrl = "http://example.com";
var version = "my-version";
var rsin = "12345";
var kvkNummer = "54321";

handler.Expect($"{baseUrl}/zaken/api/{version}/zaken?rol__betrokkeneIdentificatie__nietNatuurlijkPersoon__innNnpId={kvkNummer}")
.Respond("application/json", "{\"results\": []}");
var httpClient = new HttpClient(handler);
var clientFactory = Mock.Of<IHttpClientFactory>(x => x.CreateClient(It.IsAny<string>()) == httpClient);
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters", null, null, "kvkNummer");


var sut = new GetZaken(new[] { config }, clientFactory, logger);

var result = await sut.Get(version, Enumerable.Empty<string>(), kvkNummer, rsin, default);
Assert.IsInstanceOfType<IStatusCodeActionResult>(result, out var statusCodeResult);
Assert.AreEqual(200, statusCodeResult.StatusCode);
handler.VerifyNoOutstandingExpectation();
}

private static async Task<IActionResult> RunHappyFlowTest(string baseUrl, StringValues ordering, string responseBody)
{
const string Version = "my-version";
Expand All @@ -131,12 +181,12 @@ private static async Task<IActionResult> RunHappyFlowTest(string baseUrl, String
.Respond("application/json", responseBody);
var httpClient = new HttpClient(handler);
var clientFactory = Mock.Of<IHttpClientFactory>(x => x.CreateClient(It.IsAny<string>()) == httpClient);
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters", null, null);
var config = new ZaaksysteemConfig(baseUrl, "ClientId", "Secret of at least X characters", null, null, null);


var sut = new GetZaken(new[] { config }, clientFactory, logger);

var result = await sut.Get(Version, ordering, default);
var result = await sut.Get(Version, ordering, null, null, default);

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion Kiss.Bff.Test/Zaaksysteem/ZaaksysteemProxyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Proxy_returns_correct_result()
{
var baseUrl = "http://example.com";
var key = "een sleutel van minimaal 16 karakters";
var config = new ZaaksysteemConfig(baseUrl, "", key, null, null);
var config = new ZaaksysteemConfig(baseUrl, "", key, null, null, null);
var sut = new ZaaksysteemProxy(new[] { config }, Mock.Of<ILogger<ZaaksysteemProxy>>());

var id = Guid.NewGuid();
Expand Down
39 changes: 33 additions & 6 deletions Kiss.Bff/Extern/ZaakGerichtWerken/Zaaksysteem/GetZaken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
using Kiss.Bff.Extern.ZaakGerichtWerken.Zaaksysteem.Shared;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Primitives;

namespace Kiss.Bff.Extern.ZaakGerichtWerken.Zaaksysteem
{
[ApiController]
public class GetZaken : ControllerBase
{
const string KvkNummer = "kvkNummer";
const string Rsin = "rsin";

private readonly IEnumerable<ZaaksysteemConfig> _configs;
private readonly IHttpClientFactory _httpClientFactory;
private readonly ILogger<GetZaken> _logger;
Expand Down Expand Up @@ -36,9 +40,14 @@ public GetZaken(
/// <param name="token"></param>
/// <returns></returns>
[HttpGet("api/zaken/zaken/api/{version}/zaken")]
public async Task<IActionResult> Get([FromRoute] string version, [FromQuery(Name = "ordering")] IEnumerable<string> ordering, CancellationToken token)
public async Task<IActionResult> Get(
[FromRoute] string version,
[FromQuery(Name = "ordering")] IEnumerable<string> ordering,
[FromQuery(Name = KvkNummer)] string? kvkNummer,
[FromQuery(Name = Rsin)] string? rsin,
CancellationToken token)
{
var messages = await SendRequestToZaaksystemen($"zaken/api/{version}/zaken", token);
var messages = await SendRequestToZaaksystemen($"zaken/api/{version}/zaken", kvkNummer, rsin, token);

if (messages.Length == 0)
{
Expand Down Expand Up @@ -120,15 +129,33 @@ public async Task<IActionResult> Get([FromRoute] string version, [FromQuery(Name
return Ok(result);
}

private Task<(Uri? BaseAddress, HttpResponseMessage? Message)[]> SendRequestToZaaksystemen(string path, CancellationToken token)
private Task<(Uri? BaseAddress, HttpResponseMessage? Message)[]> SendRequestToZaaksystemen(string path, string? kvkNummer, string? rsin, CancellationToken token)
{
var tasks = _configs
.Select(CreateClient)
.Select(async (client) =>
.Select(async (config) =>
{
var client = CreateClient(config);
try
{
var message = await client.GetAsync($"{path}{Request?.QueryString}", HttpCompletionOption.ResponseHeadersRead, token);
var queryString = Request?.QueryString.ToString();

if (!string.IsNullOrWhiteSpace(kvkNummer) && !string.IsNullOrWhiteSpace(rsin))
{
var identifier = config.NietNatuurlijkPersoonIdentifier == "kvkNummer"
? kvkNummer
: rsin;

var queryParametersExcludingRsinAndKvk = Request?.Query?
.Where(x => x.Key != KvkNummer && x.Key != Rsin)
?? Enumerable.Empty<KeyValuePair<string, StringValues>>();

var dict = queryParametersExcludingRsinAndKvk
.Append(new("rol__betrokkeneIdentificatie__nietNatuurlijkPersoon__innNnpId", identifier))
.SelectMany(x=> x.Value.Select(v => $"{x.Key}={x.Value}"));

queryString = $"?{string.Join('&', dict)}";
}
var message = await client.GetAsync($"{path}{queryString}", HttpCompletionOption.ResponseHeadersRead, token);
Response?.RegisterForDispose(message);
return (client.BaseAddress, Message: (HttpResponseMessage?)message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static IEnumerable<ZaaksysteemConfig> GetZaakSysteemConfigs(IConfigurati
&& configuration["ZAKEN_API_CLIENT_ID"] is string clientId
&& configuration["ZAKEN_API_KEY"] is string apiKey)
{
yield return new(baseUrl, clientId, apiKey, configuration["ZAAKSYSTEEM_DEEPLINK_URL"], configuration["ZAAKSYSTEEM_DEEPLINK_PROPERTY"]);
yield return new(baseUrl, clientId, apiKey, configuration["ZAAKSYSTEEM_DEEPLINK_URL"], configuration["ZAAKSYSTEEM_DEEPLINK_PROPERTY"], configuration["NIETNATUURLIJKPERSOONIDENTIFIER"]);
}

// multiple zaaksystemen
Expand All @@ -58,7 +58,8 @@ private static IEnumerable<ZaaksysteemConfig> GetZaakSysteemConfigs(IConfigurati
{
var deeplinkUrl = item.GetValueOrDefault("DEEPLINK_URL");
var deeplinkProperty = item.GetValueOrDefault("DEEPLINK_PROPERTY");
yield return new(itemBaseUrl, itemClientId, itemApiKey, deeplinkUrl, deeplinkProperty);
var nnpId = item.GetValueOrDefault("NIETNATUURLIJKPERSOONIDENTIFIER");
yield return new(itemBaseUrl, itemClientId, itemApiKey, deeplinkUrl, deeplinkProperty, nnpId);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Kiss.Bff.Extern.ZaakGerichtWerken.Zaaksysteem.Shared
{
public record ZaaksysteemConfig(string BaseUrl, string ClientId, string Secret, string? DeeplinkBaseUrl, string? DeeplinkProperty);
public record ZaaksysteemConfig(string BaseUrl, string ClientId, string Secret, string? DeeplinkBaseUrl, string? DeeplinkProperty, string? NietNatuurlijkPersoonIdentifier);
}
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ const zakenToevoegenAanContactmoment = async (
try {
await koppelZaakContactmoment({
contactmoment: contactmomentId,
zaak: zaak.self,
...zaak,
});
} catch (e) {
try {
Expand All @@ -499,7 +499,7 @@ const zakenToevoegenAanContactmoment = async (
);
await koppelZaakContactmoment({
contactmoment: contactmomentId,
zaak: zaak.self,
...zaak,
});
} catch (e) {
try {
Expand All @@ -509,7 +509,7 @@ const zakenToevoegenAanContactmoment = async (
);
await koppelZaakContactmoment({
contactmoment: contactmomentId,
zaak: zaak.self,
...zaak,
});
} catch (e) {
console.log(
Expand Down
8 changes: 6 additions & 2 deletions src/features/contact/contactmoment/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,18 @@ export const koppelObject = (data: ContactmomentObject) =>
body: JSON.stringify(data),
}).then(throwIfNotOk);

export const koppelZaakContactmoment = (data: ZaakContactmoment) =>
export const koppelZaakContactmoment = ({
zaaksysteemId,
url,
contactmoment,
}: ZaakContactmoment) =>
fetchLoggedIn(zaakcontactmomentUrl, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify(data),
body: JSON.stringify({ zaaksysteemId, url, contactmoment }),
}).then(throwIfNotOk);

export function koppelKlant({
Expand Down
3 changes: 2 additions & 1 deletion src/features/contact/contactmoment/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export interface ContactmomentObject {

export interface ZaakContactmoment {
contactmoment: string;
zaak: string;
url: string;
zaaksysteemId: string;
}

export interface ContactverzoekDetail {
Expand Down
23 changes: 7 additions & 16 deletions src/features/klant/bedrijf/service/use-bedrijf-by-identifier.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { ServiceResult, enforceOneOrZero } from "@/services";
import {
searchBedrijvenInHandelsRegister,
preferredNietNatuurlijkPersoonIdentifierPromise,
type NietNatuurlijkPersoonIdentifierValue,
} from "./shared/shared";
import { searchBedrijvenInHandelsRegister } from "./shared/shared";
import type { BedrijfIdentifier } from "../types";

let identifier: NietNatuurlijkPersoonIdentifierValue | undefined;

preferredNietNatuurlijkPersoonIdentifierPromise.then((r) => {
identifier = r.nietNatuurlijkPersoonIdentifier;
});

const zoekenUrl = "/api/kvk/v2/zoeken";

export const useBedrijfByIdentifier = (
Expand All @@ -38,11 +28,7 @@ export const useBedrijfByIdentifier = (
const getUrlVoorGetBedrijfById = (
bedrijfsZoekParamter: BedrijfIdentifier | undefined,
) => {
if (
!identifier ||
!bedrijfsZoekParamter ||
typeof bedrijfsZoekParamter != "object"
) {
if (!bedrijfsZoekParamter || typeof bedrijfsZoekParamter != "object") {
return "";
}

Expand All @@ -60,6 +46,11 @@ const getUrlVoorGetBedrijfById = (
"nietNatuurlijkPersoonIdentifier" in bedrijfsZoekParamter &&
bedrijfsZoekParamter.nietNatuurlijkPersoonIdentifier
) {
// TIJDELIJK. netter maken bij OK2 bedrijf stories
const identifier =
bedrijfsZoekParamter.nietNatuurlijkPersoonIdentifier.length === 9
? "rsin"
: "kvkNummer";
searchParams.set(
identifier,
bedrijfsZoekParamter.nietNatuurlijkPersoonIdentifier,
Expand Down
1 change: 1 addition & 0 deletions src/features/klant/bedrijf/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface Bedrijf {
kvkNummer: string;
type: string;
vestigingsnummer?: string;
rsin?: string;
bedrijfsnaam: string;
postcode?: string;
huisnummer?: string;
Expand Down
15 changes: 8 additions & 7 deletions src/features/zaaksysteem/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ type ZaakBedrijfIdentifier =
vestigingsnummer: string;
}
| {
nietNatuurlijkPersoonIdentifier: string;
rsin: string;
kvkNummer: string;
};

export const useZakenByKlantBedrijfIdentifier = (
Expand All @@ -130,12 +131,12 @@ export const useZakenByKlantBedrijfIdentifier = (
"rol__betrokkeneIdentificatie__vestiging__vestigingsNummer",
searchParam.vestigingsnummer,
);
} else if ("nietNatuurlijkPersoonIdentifier" in searchParam) {
url.searchParams.set(
"rol__betrokkeneIdentificatie__nietNatuurlijkPersoon__innNnpId",
searchParam.nietNatuurlijkPersoonIdentifier,
);
}
} else if ("rsin" in searchParam) {
// LET OP: deze query parameters zijn custom voor KISS. op de backend wordt per zaaksysteem gekozen uit rsin of kvkNummer.
// Deze wordt vervolgens in rol__betrokkeneIdentificatie__vestiging__vestigingsNummer gezet.
url.searchParams.set("rsin", searchParam.rsin);
url.searchParams.set("kvkNummer", searchParam.kvkNummer);
} else return "";
return url.toString();
};

Expand Down
9 changes: 7 additions & 2 deletions src/views/BedrijfDetailView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ const getBedrijfIdentifier = (): BedrijfIdentifier | undefined => {
};
};
const zaken = useZakenByKlantBedrijfIdentifier(getBedrijfIdentifier);
const bedrijf = useBedrijfByIdentifier(getBedrijfIdentifier);
const zaken = useZakenByKlantBedrijfIdentifier(() => {
if (!bedrijf.success || !bedrijf.data?.kvkNummer) return undefined;
if (bedrijf.data.vestigingsnummer)
return { vestigingsnummer: bedrijf.data.vestigingsnummer };
if (bedrijf.data.rsin)
return { rsin: bedrijf.data.rsin, kvkNummer: bedrijf.data.kvkNummer };
});
</script>

0 comments on commit 63a4b48

Please sign in to comment.