Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ public Flux<ClientPublicViewDto> searchClients(
* @param acronym the acronym of the client to search for (optional).
* @param number the unique number of the client to search for (optional).
* @param serverResponse the {@link ServerHttpResponse} to include response headers.
* @return a reactive stream of {@link ClientPublicViewDto} objects representing matching
* clients.
* @return a reactive stream of {@link ClientPublicViewDto} objects representing matching
* clients.
*
* @apiNote This method provides a paginated, fuzzy search for client details. Results
* include a total record count in the response headers under {@code X-Total-Count}.
* @apiNote This method provides a paginated, fuzzy search for client details. Results
* include a total record count in the response headers under {@code X-Total-Count}.
*/
@GetMapping("/by")
@Operation(
Expand Down Expand Up @@ -163,24 +163,28 @@ public Flux<ClientPublicViewDto> searchClients(
}
)
public Flux<ClientPublicViewDto> searchByAcronymNameNumber(
@Parameter(description = "The one index page number, defaults to 0", example = "0")
@Parameter(description = "The one index page number, defaults to 0",
example = "0")
@RequestParam(value = "page", required = false, defaultValue = "0")
Integer page,

@Parameter(description = "The amount of data to be returned per page, defaults to 10",
example = "10")
example = "10")
@RequestParam(value = "size", required = false, defaultValue = "10")
Integer size,

@Parameter(description = "The name of the client you're searching", example = "Western Forest Products")
@Parameter(description = "The name of the client you're searching",
example = "Western Forest Products")
@RequestParam(value = "name", required = false)
String name,

@Parameter(description = "The acronym of the client you're searching", example = "WFPS")
@Parameter(description = "The acronym of the client you're searching",
example = "WFPS")
@RequestParam(value = "acronym", required = false)
String acronym,

@Parameter(description = "The number of the client you're searching", example = "00000001")
@Parameter(description = "The number of the client you're searching",
example = "00000001")
@RequestParam(value = "number", required = false)
String number,

Expand All @@ -190,7 +194,7 @@ public Flux<ClientPublicViewDto> searchByAcronymNameNumber(
log.info("Searching for clients with name {}, acronym {}, number {}", name, acronym, number);
return
clientSearchService
.searchByAcronymNameNumber(name, acronym, number)
.searchByAcronymNameNumber(name, acronym, number, page, size)
.flatMapMany(criteria -> clientSearchService.searchClientByQuery(criteria, page, size))
.doOnNext(client -> log.info("Found client with id {}", client.getClientNumber()))
.doOnNext(dto -> serverResponse.getHeaders()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ca.bc.gov.api.oracle.legacy.dto;

public interface SearchNumberScoreProjection {

Check warning on line 3 in src/main/java/ca/bc/gov/api/oracle/legacy/dto/SearchNumberScoreProjection.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck

Missing a Javadoc comment.
String getClientNumber();
Integer getScore();

Check warning on line 5 in src/main/java/ca/bc/gov/api/oracle/legacy/dto/SearchNumberScoreProjection.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparatorCheck

'METHOD_DEF' should be separated from previous line.
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ca.bc.gov.api.oracle.legacy.repository;

import ca.bc.gov.api.oracle.legacy.dto.SearchNumberScoreProjection;
import ca.bc.gov.api.oracle.legacy.entity.ForestClientEntity;
import org.springframework.data.domain.Pageable;
import org.springframework.data.r2dbc.repository.Query;
Expand All @@ -10,7 +11,7 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Repository

Check warning on line 14 in src/main/java/ca/bc/gov/api/oracle/legacy/repository/ForestClientRepository.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck

Missing a Javadoc comment.
public interface ForestClientRepository extends ReactiveCrudRepository<ForestClientEntity, String>,
ReactiveQueryByExampleExecutor<ForestClientEntity>,
ReactiveSortingRepository<ForestClientEntity, String> {
Expand All @@ -28,18 +29,25 @@
String clientName);


@Query(value = """

Check warning on line 32 in src/main/java/ca/bc/gov/api/oracle/legacy/repository/ForestClientRepository.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck

Line contains a tab character.

Check warning on line 32 in src/main/java/ca/bc/gov/api/oracle/legacy/repository/ForestClientRepository.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck

'method def modifier' has incorrect indentation level 8, expected level should be 2.
SELECT
CLIENT_NUMBER
CLIENT_NUMBER,
(
CASE WHEN CLIENT_ACRONYM = :acronym THEN 800 ELSE 0 END +
CASE WHEN CLIENT_NUMBER = :clientNumber THEN 1000 ELSE 0 END +
UTL_MATCH.JARO_WINKLER_SIMILARITY(TRIM(COALESCE(LEGAL_FIRST_NAME || ' ', '') || TRIM(COALESCE(LEGAL_MIDDLE_NAME || ' ', '')) || COALESCE(CLIENT_NAME, '')), :clientName)

Check warning on line 38 in src/main/java/ca/bc/gov/api/oracle/legacy/repository/ForestClientRepository.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck

Line is longer than 100 characters (found 176).
) AS score
FROM THE.FOREST_CLIENT
WHERE
UTL_MATCH.JARO_WINKLER_SIMILARITY(CLIENT_NAME, :clientName) >= 80
OR UTL_MATCH.JARO_WINKLER_SIMILARITY(LEGAL_FIRST_NAME, :clientName) >= 80
OR UTL_MATCH.JARO_WINKLER_SIMILARITY(LEGAL_MIDDLE_NAME, :clientName) >= 80
OR UTL_MATCH.JARO_WINKLER_SIMILARITY(TRIM(COALESCE(LEGAL_FIRST_NAME || ' ', '') || TRIM(COALESCE(LEGAL_MIDDLE_NAME || ' ', '')) || COALESCE(CLIENT_NAME, '')), :clientName) >= 80
UTL_MATCH.JARO_WINKLER_SIMILARITY(TRIM(COALESCE(LEGAL_FIRST_NAME || ' ', '') || TRIM(COALESCE(LEGAL_MIDDLE_NAME || ' ', '')) || COALESCE(CLIENT_NAME, '')), :clientName) >= 80

Check warning on line 42 in src/main/java/ca/bc/gov/api/oracle/legacy/repository/ForestClientRepository.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck

Line is longer than 100 characters (found 180).
OR CLIENT_ACRONYM = :acronym
OR CLIENT_NUMBER = :clientNumber
ORDER BY CLIENT_NUMBER""")
Flux<String> searchNumberByNameAcronymNumber(String clientName, String acronym, String clientNumber);

ORDER BY score DESC
OFFSET :offset ROWS FETCH NEXT :size ROWS ONLY""")
Flux<SearchNumberScoreProjection> searchNumberByNameAcronymNumber(

Check warning on line 47 in src/main/java/ca/bc/gov/api/oracle/legacy/repository/ForestClientRepository.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck

Line contains a tab character.
String clientName,

Check warning on line 48 in src/main/java/ca/bc/gov/api/oracle/legacy/repository/ForestClientRepository.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck

'String' has incorrect indentation level 6, expected level should be 12.
String acronym,

Check warning on line 49 in src/main/java/ca/bc/gov/api/oracle/legacy/repository/ForestClientRepository.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck

'String' has incorrect indentation level 6, expected level should be 12.
String clientNumber,

Check warning on line 50 in src/main/java/ca/bc/gov/api/oracle/legacy/repository/ForestClientRepository.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck

'String' has incorrect indentation level 6, expected level should be 12.
long offset,

Check warning on line 51 in src/main/java/ca/bc/gov/api/oracle/legacy/repository/ForestClientRepository.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck

'long' has incorrect indentation level 6, expected level should be 12.
int size);

Check warning on line 52 in src/main/java/ca/bc/gov/api/oracle/legacy/repository/ForestClientRepository.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck

'int' has incorrect indentation level 6, expected level should be 12.
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import static org.springframework.data.relational.core.query.Criteria.where;

import ca.bc.gov.api.oracle.legacy.dto.ClientPublicViewDto;
import ca.bc.gov.api.oracle.legacy.dto.SearchNumberScoreProjection;
import ca.bc.gov.api.oracle.legacy.entity.ForestClientEntity;
import ca.bc.gov.api.oracle.legacy.repository.ForestClientRepository;
import ca.bc.gov.api.oracle.legacy.util.ClientMapper;
import java.time.Duration;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
import org.springframework.data.relational.core.query.Criteria;
Expand All @@ -19,7 +22,7 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Service

Check warning on line 25 in src/main/java/ca/bc/gov/api/oracle/legacy/service/ClientSearchService.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck

Missing a Javadoc comment.
@RequiredArgsConstructor
@Slf4j
public class ClientSearchService {
Expand Down Expand Up @@ -110,41 +113,49 @@
}

/**
* Constructs a search {@link Criteria} object based on the provided client name, acronym, or
* number.
* This method normalizes input values for case-insensitive searches and validates the client
* number.
* Constructs a search {@link Criteria} object based on the provided client name, acronym, or
* number. This method normalizes input values for case-insensitive searches and validates the
* client number.
*
* @param name the name of the client to search for, or null if not specified.
* @param name the name of the client to search for, or null if not specified.
* @param acronym the acronym of the client to search for, or null if not specified.
* @param number the unique number of the client to search for, or null if not specified.
* @param number the unique number of the client to search for, or null if not specified.
* @param size the number of results to return.
* @return a {@link Mono} emitting the constructed {@link Criteria} object for the search.
*
* @implNote Input values are transformed to uppercase for case-insensitivity. The client
* number is validated using {@link #checkClientNumber(String)}. Repository results are
* mapped to a search criteria object.
* @implNote Input values are transformed to uppercase for case-insensitivity. The client number
* is validated using {@link #checkClientNumber(String)}. Repository results are mapped to a

Check warning on line 126 in src/main/java/ca/bc/gov/api/oracle/legacy/service/ClientSearchService.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTagContinuationIndentationCheck

Line continuation have incorrect indentation level, expected level should be 4.
* search criteria object.

Check warning on line 127 in src/main/java/ca/bc/gov/api/oracle/legacy/service/ClientSearchService.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTagContinuationIndentationCheck

Line continuation have incorrect indentation level, expected level should be 4.
*/
public Mono<Criteria> searchByAcronymNameNumber(String name, String acronym, String number) {
public Mono<Criteria> searchByAcronymNameNumber(
String name,
String acronym,
String number,
int page,
int size) {
log.info("Searching for clients with name {}, acronym {} or number {}", name, acronym, number);

String searchName = StringUtils.isNotBlank(name) ? name.toUpperCase() : null;
String searchAcronym = StringUtils.isNotBlank(acronym) ? acronym.toUpperCase() : null;
String searchNumber = StringUtils.isNotBlank(number) ? checkClientNumber(number) : null;
Pageable pageRequest = PageRequest.of(page, size);

return
forestClientRepository
.searchNumberByNameAcronymNumber(
searchName,
searchAcronym,
searchNumber
)
.collectList()
.map(this::searchById);
forestClientRepository
.searchNumberByNameAcronymNumber(
searchName,
searchAcronym,
searchNumber,
pageRequest.getOffset(),
pageRequest.getPageSize()
)
.map(SearchNumberScoreProjection::getClientNumber)
.collectList()
.map(this::searchById);

}

private String checkClientNumber(String clientNumber) {
if(StringUtils.isBlank(clientNumber)) {
if (StringUtils.isBlank(clientNumber)) {
return clientNumber;
}

Expand Down
Loading