Skip to content

Commit

Permalink
chore: fixing sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj committed Dec 18, 2024
1 parent 5da9dbe commit abf26b2
Showing 1 changed file with 65 additions and 16 deletions.
81 changes: 65 additions & 16 deletions legacy/src/main/java/ca/bc/gov/app/service/ClientSearchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -41,7 +40,6 @@
import org.springframework.data.relational.core.query.Criteria;
import org.springframework.data.relational.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

Expand All @@ -57,14 +55,18 @@
@Observed
public class ClientSearchService {

public static final String CLIENT_NAME = "clientName";
public static final String CLIENT_IDENTIFICATION = "clientIdentification";
private final ForestClientRepository forestClientRepository;
private final ClientDoingBusinessAsRepository doingBusinessAsRepository;
private final ForestClientRepository clientRepository;
private final ForestClientContactRepository contactRepository;
private final ForestClientLocationRepository locationRepository;
private final AbstractForestClientMapper<ForestClientDto, ForestClientEntity> forestClientMapper;
private final AbstractForestClientMapper<ForestClientLocationDto, ForestClientLocationEntity> locationMapper;
private final AbstractForestClientMapper<ForestClientContactDto, ForestClientContactEntity> contactMapper;
private final
AbstractForestClientMapper<ForestClientLocationDto, ForestClientLocationEntity> locationMapper;
private final
AbstractForestClientMapper<ForestClientContactDto, ForestClientContactEntity> contactMapper;
private final R2dbcEntityTemplate template;
private final ForestClientConfiguration configuration;

Expand Down Expand Up @@ -164,13 +166,13 @@ public Flux<ForestClientDto> findByIndividual(
}

Criteria queryCriteria = where("legalFirstName").is(firstName).ignoreCase(true)
.and("clientName").is(lastName).ignoreCase(true)
.and(CLIENT_NAME).is(lastName).ignoreCase(true)
.and("birthdate").is(dob.atStartOfDay())
.and("clientTypeCode").is("I").ignoreCase(true);

if (StringUtils.isNotBlank(identification)) {
queryCriteria = queryCriteria
.and("clientIdentification")
.and(CLIENT_IDENTIFICATION)
.is(identification)
.ignoreCase(true);
}
Expand Down Expand Up @@ -227,8 +229,8 @@ public Flux<ForestClientDto> findByIdAndLastName(String clientId, String lastNam
return Flux.error(new MissingRequiredParameterException("clientId, lastName"));
}

Criteria queryCriteria = where("clientIdentification").is(clientId).ignoreCase(true)
.and("clientName").is(lastName).ignoreCase(true);
Criteria queryCriteria = where(CLIENT_IDENTIFICATION).is(clientId).ignoreCase(true)
.and(CLIENT_NAME).is(lastName).ignoreCase(true);

return searchClientByQuery(queryCriteria, ForestClientEntity.class)
.map(forestClientMapper::toDto)
Expand Down Expand Up @@ -260,7 +262,7 @@ public Flux<ForestClientDto> findByIdentification(String idType, String identifi
}

Criteria queryCriteria = where("clientIdTypeCode").is(idType).ignoreCase(true)
.and("clientIdentification").is(identification).ignoreCase(true)
.and(CLIENT_IDENTIFICATION).is(identification).ignoreCase(true)
.and("clientTypeCode").is("I").ignoreCase(true);

return searchClientByQuery(queryCriteria, ForestClientEntity.class)
Expand Down Expand Up @@ -467,6 +469,13 @@ public Flux<ForestClientDto> findByContact(ContactSearchDto contact) {
);
}

/**
* Finds clients by their acronym. Logs the search process and results. If the acronym is blank,
* returns a MissingRequiredParameterException.
*
* @param acronym the acronym to search for
* @return a Flux containing the matching ForestClientDto objects
*/
public Flux<ForestClientDto> findByAcronym(String acronym) {
log.info("Searching for client with acronym {}", acronym);

Expand All @@ -487,6 +496,15 @@ public Flux<ForestClientDto> findByAcronym(String acronym) {
);
}

/**
* Finds clients by their doing business as (DBA) name. Logs the search process and results. If
* the DBA name is blank, returns a MissingRequiredParameterException. If the isFuzzy parameter is
* true, performs a fuzzy search.
*
* @param doingBusinessAs the DBA name to search for
* @param isFuzzy whether to perform a fuzzy search
* @return a Flux containing the matching ForestClientDto objects
*/
public Flux<ForestClientDto> findByDoingBusinessAs(String doingBusinessAs, boolean isFuzzy) {

if (StringUtils.isBlank(doingBusinessAs)) {
Expand Down Expand Up @@ -521,18 +539,23 @@ public Flux<ForestClientDto> findByDoingBusinessAs(String doingBusinessAs, boole
doingBusinessAs,
dto.clientNumber(), dto.clientName())
);


}

/**
* Finds clients by their name. Logs the search process and results. If the client name is blank,
* returns a MissingRequiredParameterException.
*
* @param clientName the name of the client to search for
* @return a Flux containing the matching ForestClientDto objects
*/
public Flux<ForestClientDto> findByClientName(String clientName) {
log.info("Searching for client with name {}", clientName);

if (StringUtils.isBlank(clientName)) {
return Flux.error(new MissingRequiredParameterException("clientName"));
return Flux.error(new MissingRequiredParameterException(CLIENT_NAME));
}

Criteria queryCriteria = where("clientName").is(clientName).ignoreCase(true);
Criteria queryCriteria = where(CLIENT_NAME).is(clientName).ignoreCase(true);

return searchClientByQuery(queryCriteria, ForestClientEntity.class)
.map(forestClientMapper::toDto)
Expand All @@ -544,7 +567,15 @@ public Flux<ForestClientDto> findByClientName(String clientName) {
dto.clientNumber(), dto.clientName())
);
}


/**
* Finds client details by their client number. Logs the search process and results. If the client
* number is blank, returns a MissingRequiredParameterException. If no client is found, returns a
* NoValueFoundException.
*
* @param clientNumber the client number to search for
* @return a Mono containing the matching ForestClientDetailsDto object
*/
public Mono<ForestClientDetailsDto> findByClientNumber(String clientNumber) {
log.info("Searching for client with number {}", clientNumber);

Expand All @@ -560,15 +591,15 @@ public Mono<ForestClientDetailsDto> findByClientNumber(String clientNumber) {
.collectList()
.map(dto::withAddresses)
.defaultIfEmpty(dto)
)
)
.flatMap(dto ->
contactRepository
.findAllByClientNumber(clientNumber)
.map(contactMapper::toDto)
.collectList()
.map(dto::withContacts)
.defaultIfEmpty(dto)
)
)
.switchIfEmpty(
Mono.error(
new NoValueFoundException("Client with number: " + clientNumber)
Expand All @@ -581,6 +612,16 @@ public Mono<ForestClientDetailsDto> findByClientNumber(String clientNumber) {
);
}

/**
* Performs a complex search for clients based on a predictive search value. Logs the search
* process and results. If the search value is blank, returns a
* MissingRequiredParameterException.
*
* @param value the predictive search value
* @param page the pagination information
* @return a Flux containing pairs of PredictiveSearchResultDto objects and the total count of
* matching clients
*/
public Flux<Pair<PredictiveSearchResultDto, Long>> complexSearch(String value, Pageable page) {
// This condition is for predictive search, and we will stop here if no query param is provided
if (StringUtils.isBlank(value)) {
Expand All @@ -601,6 +642,14 @@ public Flux<Pair<PredictiveSearchResultDto, Long>> complexSearch(String value, P
);
}

/**
* Retrieves the latest entries of predictive search results. Logs the search process and
* results.
*
* @param page the pagination information
* @return a Flux containing pairs of PredictiveSearchResultDto objects and the total count of
* matching clients
*/
public Flux<Pair<PredictiveSearchResultDto, Long>> latestEntries(Pageable page) {
return
forestClientRepository
Expand Down

0 comments on commit abf26b2

Please sign in to comment.