From 3bc3ae2b5a2535f6e7b3ac5fd8e62e1a6f847031 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Tue, 9 Jan 2024 15:31:00 -0800 Subject: [PATCH] fix: fixing client types --- .../java/ca/bc/gov/app/ApplicationConstant.java | 2 ++ .../gov/app/service/client/ClientService.java | 17 +++++++++-------- .../client/ClientSubmitRequestValidator.java | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/ca/bc/gov/app/ApplicationConstant.java b/backend/src/main/java/ca/bc/gov/app/ApplicationConstant.java index c98cdedccd..81c3c410a2 100644 --- a/backend/src/main/java/ca/bc/gov/app/ApplicationConstant.java +++ b/backend/src/main/java/ca/bc/gov/app/ApplicationConstant.java @@ -92,5 +92,7 @@ left join nrfc.province_code pc on (pc.province_code = sl.province_code and pc.c public static final String REFRESH_TOKEN = "refreshToken"; public static final String ID_TOKEN = "idToken"; public static final String ACCESS_TOKEN = "accessToken"; + public static final List AVAILABLE_CLIENT_TYPES = List.of("A", "I", "S", "SP", "RSP", + "USP", "BC", "GP"); } diff --git a/backend/src/main/java/ca/bc/gov/app/service/client/ClientService.java b/backend/src/main/java/ca/bc/gov/app/service/client/ClientService.java index 1ffb1c354b..954eb5bc4b 100644 --- a/backend/src/main/java/ca/bc/gov/app/service/client/ClientService.java +++ b/backend/src/main/java/ca/bc/gov/app/service/client/ClientService.java @@ -1,5 +1,6 @@ package ca.bc.gov.app.service.client; +import ca.bc.gov.app.ApplicationConstant; import ca.bc.gov.app.dto.bcregistry.BcRegistryDocumentDto; import ca.bc.gov.app.dto.bcregistry.BcRegistryFacetSearchResultEntryDto; import ca.bc.gov.app.dto.bcregistry.BcRegistryPartyDto; @@ -206,6 +207,13 @@ public Mono getClientDetails( ) .map(BcRegistryDocumentDto.class::cast) + .flatMap(client ->{ + if(ApplicationConstant.AVAILABLE_CLIENT_TYPES.contains(client.business().legalType())){ + return Mono.just(client); + } + return Mono.error(new UnsuportedClientTypeException(client.business().legalType())); + }) + //if document type is SP and party contains only one entry that is not a person, fail .filter(document -> !("SP".equalsIgnoreCase(document.business().legalType()) @@ -237,14 +245,7 @@ public Flux findByClientNameOrIncorporation(String value) { entry.status(), entry.legalType() ) - ) - .flatMap(client ->{ - if(List.of("A", "I", "S", "SP","RSP","USP").contains(client.legalType())){ - return Mono.just(client); - } - return Mono.error(new UnsuportedClientTypeException(client.legalType())); - }) - .doOnError(System.out::println); + ); } /** diff --git a/backend/src/main/java/ca/bc/gov/app/validator/client/ClientSubmitRequestValidator.java b/backend/src/main/java/ca/bc/gov/app/validator/client/ClientSubmitRequestValidator.java index 6e61e2e522..5b113a0114 100644 --- a/backend/src/main/java/ca/bc/gov/app/validator/client/ClientSubmitRequestValidator.java +++ b/backend/src/main/java/ca/bc/gov/app/validator/client/ClientSubmitRequestValidator.java @@ -78,7 +78,7 @@ private void validateBusinessInformation( validateBirthdate(businessInformation.birthdate(), errors); } - if (!List.of("A", "I", "S", "USP", "RSP","SP").contains(clientType)) { + if (!ApplicationConstant.AVAILABLE_CLIENT_TYPES.contains(clientType)) { errors.rejectValue("businessType", String.format("%s %s is not supported at the moment", "Business type",clientType)); }