Skip to content

Commit

Permalink
feat(be:FSADT1-1722): Adjust province and country information in Clie…
Browse files Browse the repository at this point in the history
…nt Details API (#1431)

* feat(be:FSADT1-1722): Adjust province and country information on API to Get Client Details

* Fixed SonarCloud issues
  • Loading branch information
mamartinezmejia authored Mar 4, 2025
1 parent 030fc09 commit 77dd877
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public record ForestClientDetailsDto(
String goodStandingInd,
LocalDateTime birthdate,

List<ForestClientLocationDto> addresses,
List<ForestClientLocationDetailsDto> addresses,
List<ForestClientContactDto> contacts,
List<ForestClientDoingBusinessAsDto> doingBusinessAs
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ca.bc.gov.app.dto.legacy;

import lombok.With;

@With
public record ForestClientLocationDetailsDto(
String clientNumber,
String clientLocnCode,
String clientLocnName,
String addressOne,
String addressTwo,
String addressThree,
String city,
String provinceCode,
String provinceDesc,
String countryCode,
String countryDesc,
String postalCode,
String businessPhone,
String homePhone,
String cellPhone,
String faxNumber,
String emailAddress,
String locnExpiredInd,
String cliLocnComment
) {

}

Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
package ca.bc.gov.app.service.client;

import ca.bc.gov.app.dto.legacy.ForestClientContactDto;
import ca.bc.gov.app.dto.legacy.ForestClientLocationDto;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.junit.jupiter.api.Test;
import ca.bc.gov.app.dto.bcregistry.BcRegistryAddressDto;
import ca.bc.gov.app.dto.bcregistry.BcRegistryAlternateNameDto;
import ca.bc.gov.app.dto.bcregistry.BcRegistryBusinessAdressesDto;
Expand All @@ -20,9 +9,20 @@
import ca.bc.gov.app.dto.bcregistry.BcRegistryOfficesDto;
import ca.bc.gov.app.dto.bcregistry.BcRegistryPartyDto;
import ca.bc.gov.app.dto.bcregistry.BcRegistryRoleDto;
import ca.bc.gov.app.dto.legacy.ForestClientContactDto;
import ca.bc.gov.app.dto.legacy.ForestClientDetailsDto;
import ca.bc.gov.app.dto.legacy.ForestClientLocationDetailsDto;
import ca.bc.gov.app.extensions.AbstractTestContainerIntegrationTest;
import ca.bc.gov.app.service.bcregistry.BcRegistryService;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
Expand Down Expand Up @@ -396,7 +396,7 @@ void shouldSearchByClientNumberAndgetResultWithContactAndLocation(){
null,
null,
List.of(
new ForestClientLocationDto(
new ForestClientLocationDetailsDto(
clientNumber,
"00",
"Location",
Expand All @@ -405,20 +405,17 @@ void shouldSearchByClientNumberAndgetResultWithContactAndLocation(){
null,
"City",
"BC",
"A1B2C3",
"British Columbia",
"CA",
"Canada",
"A1B2C3",
"1234567890",
"0987654321",
"1234567890",
"0987654321",
"[email protected]",
"N",
null,
null,
null,
"Admin",
"Admin",
70L
null
)
),
List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import java.util.List;
import lombok.With;

/**
* DTO representing detailed information about a forest client, including personal information,
* status, type, identification, comments, and related lists of addresses, contacts, and DBAs.
*/
@With
public record ForestClientDetailsDto(
String clientNumber,
Expand All @@ -27,7 +31,7 @@ public record ForestClientDetailsDto(
String goodStandingInd,
LocalDateTime birthdate,

List<ForestClientLocationDto> addresses,
List<ForestClientLocationDetailsDto> addresses,
List<ForestClientContactDto> contacts,
List<ClientDoingBusinessAsDto> doingBusinessAs
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ca.bc.gov.app.dto;

import lombok.With;

/**
* DTO representing location details for a forest client, including addresses, contact numbers,
* and additional comments.
*/
@With
public record ForestClientLocationDetailsDto(
String clientNumber,
String clientLocnCode,
String clientLocnName,
String addressOne,
String addressTwo,
String addressThree,
String city,
String provinceCode,
String provinceDesc,
String countryCode,
String countryDesc,
String postalCode,
String businessPhone,
String homePhone,
String cellPhone,
String faxNumber,
String emailAddress,
String locnExpiredInd,
String cliLocnComment
) {

}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ca.bc.gov.app.repository;

import ca.bc.gov.app.dto.ForestClientLocationDetailsDto;
import ca.bc.gov.app.entity.ForestClientLocationEntity;
import ca.bc.gov.app.entity.ForestClientLocationEntityId;
import org.springframework.data.r2dbc.repository.Query;
Expand Down Expand Up @@ -77,5 +78,33 @@ Flux<ForestClientLocationEntity> matchaddress(
* @return a Flux containing the matching ForestClientLocationEntity objects
*/
Flux<ForestClientLocationEntity> findAllByClientNumber(String clientNumber);

@Query("""
select
client_number,
client_locn_code,
client_locn_name,
address_1 as address_one,
address_2 as address_two,
address_3 as address_three,
city,
province as province_code,
province_state_name as province_desc,
country_code,
country as country_desc,
postal_code,
business_phone,
home_phone,
cell_phone,
fax_number,
email_address,
locn_expired_ind,
cli_locn_comment
from the.client_location l left outer join the.mailing_province_state p
on l.province = p.province_state_code
left outer join the.mailing_country c
on l.country = c.country_name
where client_number = :clientNumber""")
Flux<ForestClientLocationDetailsDto> findLocationsByClientNumber(String clientNumber);

}
99 changes: 65 additions & 34 deletions legacy/src/main/java/ca/bc/gov/app/service/ClientSearchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import ca.bc.gov.app.dto.ForestClientContactDto;
import ca.bc.gov.app.dto.ForestClientDetailsDto;
import ca.bc.gov.app.dto.ForestClientDto;
import ca.bc.gov.app.dto.ForestClientLocationDto;
import ca.bc.gov.app.dto.PredictiveSearchResultDto;
import ca.bc.gov.app.entity.ClientDoingBusinessAsEntity;
import ca.bc.gov.app.entity.ForestClientContactEntity;
Expand Down Expand Up @@ -62,14 +61,18 @@ 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<ForestClientDto, ForestClientEntity>
forestClientMapper;
private final AbstractForestClientMapper<ForestClientContactDto, ForestClientContactEntity>
contactMapper;

private final R2dbcEntityTemplate template;
private final ForestClientConfiguration configuration;

Expand Down Expand Up @@ -124,37 +127,68 @@ public Flux<ForestClientDto> findByRegistrationNumberOrCompanyName(String regist
* @param identification The identification of the client to be searched for. Optional.
* @return A Flux stream of ForestClientDto objects that match the search criteria.
*/
public Flux<ForestClientDto> findByIndividual(String firstName, String lastName, LocalDate dob,
String identification, boolean fuzzy) {
public Flux<ForestClientDto> findByIndividual(
String firstName, String lastName, LocalDate dob, String identification, boolean fuzzy) {

if (StringUtils.isAnyBlank(firstName, lastName) || dob == null) {
log.error("Missing required parameter to search for individual");
return Flux.error(new MissingRequiredParameterException("firstName, lastName, or dob"));
return Flux.error(
new MissingRequiredParameterException("firstName, lastName, or dob"));
}

log.info("Searching for individual: {} {} {} {}", firstName, lastName, dob,
log.info(
"Searching for individual: {} {} {} {}",
firstName,
lastName,
dob,
StringUtils.defaultString(identification));

if (StringUtils.isBlank(identification) && fuzzy) {
return clientRepository.findByIndividualFuzzy(String.format("%s %s", firstName, lastName),
dob.atStartOfDay()).map(forestClientMapper::toDto).distinct(ForestClientDto::clientNumber)
.sort(Comparator.comparing(ForestClientDto::clientNumber)).doOnNext(
dto -> log.info("Found individual matching {} {} {} as {} {}", firstName, lastName,
dob, dto.clientNumber(), dto.clientName()));
return clientRepository
.findByIndividualFuzzy(String.format("%s %s", firstName, lastName), dob.atStartOfDay())
.map(forestClientMapper::toDto)
.distinct(ForestClientDto::clientNumber)
.sort(Comparator.comparing(ForestClientDto::clientNumber))
.doOnNext(dto ->
log.info(
"Found individual matching {} {} {} as {} {}",
firstName,
lastName,
dob,
dto.clientNumber(),
dto.clientName()));
}

Criteria queryCriteria = where("legalFirstName").is(firstName).ignoreCase(true).and(CLIENT_NAME)
.is(lastName).ignoreCase(true).and("birthdate").is(dob.atStartOfDay()).and("clientTypeCode")
.is("I").ignoreCase(true);
Criteria queryCriteria = where("legalFirstName")
.is(firstName)
.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(CLIENT_IDENTIFICATION).is(identification).ignoreCase(true);
queryCriteria = queryCriteria
.and(CLIENT_IDENTIFICATION)
.is(identification)
.ignoreCase(true);
}

return searchClientByQuery(queryCriteria, ForestClientEntity.class).map(
forestClientMapper::toDto).doOnNext(
dto -> log.info("Found individual matching {} {} {} {} as {} {}", firstName, lastName, dob,
StringUtils.defaultString(identification), dto.clientNumber(), dto.clientName()));
return searchClientByQuery(queryCriteria, ForestClientEntity.class)
.map(forestClientMapper::toDto)
.doOnNext(dto ->
log.info(
"Found individual matching {} {} {} {} as {} {}",
firstName,
lastName,
dob,
StringUtils.defaultString(identification),
dto.clientNumber(),
dto.clientName()));
}

/**
Expand Down Expand Up @@ -466,8 +500,8 @@ public Mono<ForestClientDetailsDto> findByClientNumber(String clientNumber) {
.defaultIfEmpty(dto)
)
.flatMap(dto -> locationRepository
.findAllByClientNumber(clientNumber)
.map(locationMapper::toDto)
.findLocationsByClientNumber(clientNumber)
//.map(locationMapper::toDto)
.collectList()
.map(dto::withAddresses)
.defaultIfEmpty(dto)
Expand Down Expand Up @@ -562,20 +596,17 @@ private BinaryOperator<ForestClientContactDto> mergeContactLocations() {
);
}

private Function<List<ForestClientContactDto>, ArrayList<ForestClientContactDto>> contactMapper() {
private Function<List<ForestClientContactDto>, ArrayList<ForestClientContactDto>>
contactMapper() {
return contacts ->
new ArrayList<>(
contacts
.stream()
contacts.stream()
.collect(
Collectors
.toMap(
ForestClientContactDto::contactName,
contact -> contact,
mergeContactLocations())
)
.values()
);
Collectors.toMap(
ForestClientContactDto::contactName,
contact -> contact,
mergeContactLocations()))
.values());
}

}

0 comments on commit 77dd877

Please sign in to comment.