From bb5f8164e5c0ec0a7e631456bb89c765a2ea32f2 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Tue, 16 Jan 2024 16:00:14 -0800 Subject: [PATCH] fix(FSADT1-1144): adding dba to 100% match --- .../ClientDoingBusinessAsRepository.java | 2 ++ .../repository/ForestClientRepository.java | 3 +++ .../gov/app/service/ClientSearchService.java | 23 +++++++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/legacy/src/main/java/ca/bc/gov/app/repository/ClientDoingBusinessAsRepository.java b/legacy/src/main/java/ca/bc/gov/app/repository/ClientDoingBusinessAsRepository.java index d609a3164d..8b6de5cb5e 100644 --- a/legacy/src/main/java/ca/bc/gov/app/repository/ClientDoingBusinessAsRepository.java +++ b/legacy/src/main/java/ca/bc/gov/app/repository/ClientDoingBusinessAsRepository.java @@ -23,4 +23,6 @@ public interface ClientDoingBusinessAsRepository extends UTL_MATCH.JARO_WINKLER_SIMILARITY(UPPER(DOING_BUSINESS_AS_NAME),UPPER(:companyName)) >= 95 ORDER BY CLIENT_NUMBER""") Flux matchBy(String companyName); + + Flux findByDoingBusinessAsName(String doingBusinessAsName); } diff --git a/legacy/src/main/java/ca/bc/gov/app/repository/ForestClientRepository.java b/legacy/src/main/java/ca/bc/gov/app/repository/ForestClientRepository.java index fa3501c746..e542dbed77 100644 --- a/legacy/src/main/java/ca/bc/gov/app/repository/ForestClientRepository.java +++ b/legacy/src/main/java/ca/bc/gov/app/repository/ForestClientRepository.java @@ -9,6 +9,7 @@ import org.springframework.data.repository.reactive.ReactiveSortingRepository; import org.springframework.stereotype.Repository; import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; @Repository public interface ForestClientRepository extends ReactiveCrudRepository, @@ -44,4 +45,6 @@ AND UPPER(CLIENT_NAME) = UPPER(:lastName) ORDER BY CLIENT_NUMBER""") Flux matchBy(String companyName); + Mono findByClientNumber(String clientNumber); + } diff --git a/legacy/src/main/java/ca/bc/gov/app/service/ClientSearchService.java b/legacy/src/main/java/ca/bc/gov/app/service/ClientSearchService.java index 8b02612aa1..0c57665457 100644 --- a/legacy/src/main/java/ca/bc/gov/app/service/ClientSearchService.java +++ b/legacy/src/main/java/ca/bc/gov/app/service/ClientSearchService.java @@ -1,16 +1,20 @@ package ca.bc.gov.app.service; import ca.bc.gov.app.dto.ForestClientDto; +import ca.bc.gov.app.entity.ClientDoingBusinessAsEntity; import ca.bc.gov.app.entity.ForestClientEntity; import ca.bc.gov.app.exception.MissingRequiredParameterException; import ca.bc.gov.app.mappers.AbstractForestClientMapper; +import ca.bc.gov.app.repository.ClientDoingBusinessAsRepository; import ca.bc.gov.app.repository.ForestClientRepository; import java.time.LocalDate; +import java.util.Optional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; @Service @RequiredArgsConstructor @@ -18,6 +22,7 @@ public class ClientSearchService { private final ForestClientRepository forestClientRepository; + private final ClientDoingBusinessAsRepository doingBusinessAsRepository; private final AbstractForestClientMapper mapper; public Flux findByIncorporationOrName( @@ -32,8 +37,22 @@ public Flux findByIncorporationOrName( return forestClientRepository .findClientByIncorporationOrName(incorporationNumber, companyName) - .map(mapper::toDto) - .doOnNext(dto -> log.info("Found client: {} {}", dto.clientNumber(), dto.clientName())); + .doOnNext( + dto -> log.info("Found client: {} {}", dto.getClientNumber(), dto.getClientName())) + .switchIfEmpty( + Flux + .from(Mono.justOrEmpty(Optional.ofNullable(companyName))) + .filter(StringUtils::isNotBlank) + .flatMap(name -> + doingBusinessAsRepository + .findByDoingBusinessAsName(name.toUpperCase()) + .doOnNext(dto -> log.info("Found client doing business as: {} {}", + dto.getClientNumber(), dto.getDoingBusinessAsName())) + .map(ClientDoingBusinessAsEntity::getClientNumber) + .flatMap(forestClientRepository::findByClientNumber) + ) + ) + .map(mapper::toDto); } public Flux findByIndividual(