Skip to content

Commit

Permalink
fix(FSADT1-1144): adding dba to 100% match
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj committed Jan 17, 2024
1 parent c078853 commit bb5f816
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClientDoingBusinessAsEntity> matchBy(String companyName);

Flux<ClientDoingBusinessAsEntity> findByDoingBusinessAsName(String doingBusinessAsName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ForestClientEntity, String>,
Expand Down Expand Up @@ -44,4 +45,6 @@ AND UPPER(CLIENT_NAME) = UPPER(:lastName)
ORDER BY CLIENT_NUMBER""")
Flux<ForestClientEntity> matchBy(String companyName);

Mono<ForestClientEntity> findByClientNumber(String clientNumber);

}
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
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
@Slf4j
public class ClientSearchService {

private final ForestClientRepository forestClientRepository;
private final ClientDoingBusinessAsRepository doingBusinessAsRepository;
private final AbstractForestClientMapper<ForestClientDto, ForestClientEntity> mapper;

public Flux<ForestClientDto> findByIncorporationOrName(
Expand All @@ -32,8 +37,22 @@ public Flux<ForestClientDto> 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<ForestClientDto> findByIndividual(
Expand Down

0 comments on commit bb5f816

Please sign in to comment.