Skip to content

Commit

Permalink
fix(FSADT1-1477): fixed location matcher (#1117)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj authored Aug 27, 2024
1 parent ab40663 commit a88339b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private Flux<MatchResult> processSingleLocation(ClientAddressDto location) {
location.city(),
location.province().value(),
location.postalCode(),
location.country().value()
location.country().text()
)
),
FIELD_NAME_PREFIX + location.index() + "].streetAddress",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,32 @@ public interface ForestClientLocationRepository
from the.client_location
where
(
upper(address_1) like upper(concat(:address, '%'))
or upper(address_2) like upper(concat(:address, '%'))
or upper(address_3) like upper(concat(:address, '%'))
upper(replace(replace(address_1,'-',' '),' ',' ')) like upper(replace(replace(concat(:address, '%'),'-',' '),' ',' '))
or upper(replace(replace(address_2,'-',' '),' ',' ')) like upper(replace(replace(concat(:address, '%'),'-',' '),' ',' '))
or upper(replace(replace(address_3,'-',' '),' ',' ')) like upper(replace(replace(concat(:address, '%'),'-',' '),' ',' '))
)
and upper(postal_code) = upper(replace(:postalCode, ' ', ''))""")
Flux<ForestClientLocationEntity> matchBy(String address, String postalCode);

@Query("""
select *
from the.client_location
where
(
upper(replace(replace(address_1,'-',' '),' ',' ')) like upper(replace(replace(concat(:address, '%'),'-',' '),' ',' '))
or upper(replace(replace(address_2,'-',' '),' ',' ')) like upper(replace(replace(concat(:address, '%'),'-',' '),' ',' '))
or upper(replace(replace(address_3,'-',' '),' ',' ')) like upper(replace(replace(concat(:address, '%'),'-',' '),' ',' '))
)
and upper(city) = upper(:city)
and upper(province) = upper(:province)
and upper(country) = upper(:country)
and upper(postal_code) = upper(replace(:postalCode, ' ', ''))""")
Flux<ForestClientLocationEntity> matchaddress(
String address,
String postalCode,
String city,
String province,
String country
);

}
49 changes: 24 additions & 25 deletions legacy/src/main/java/ca/bc/gov/app/service/ClientSearchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import ca.bc.gov.app.mappers.AbstractForestClientMapper;
import ca.bc.gov.app.repository.ClientDoingBusinessAsRepository;
import ca.bc.gov.app.repository.ForestClientContactRepository;
import ca.bc.gov.app.repository.ForestClientLocationRepository;
import ca.bc.gov.app.repository.ForestClientRepository;
import io.micrometer.observation.annotation.Observed;
import java.time.LocalDate;
Expand Down Expand Up @@ -49,6 +50,7 @@ public class ClientSearchService {
private final ClientDoingBusinessAsRepository doingBusinessAsRepository;
private final ForestClientRepository clientRepository;
private final ForestClientContactRepository contactRepository;
private final ForestClientLocationRepository locationRepository;
private final AbstractForestClientMapper<ForestClientDto, ForestClientEntity> forestClientMapper;
private final R2dbcEntityTemplate template;

Expand Down Expand Up @@ -380,32 +382,29 @@ public Flux<ForestClientDto> findByEntireAddress(AddressSearchDto address) {
return Flux.error(new MissingRequiredParameterException("address"));
}

Criteria queryCriteria =
where("city").is(address.city()).ignoreCase(true)
.and("province").is(address.province()).ignoreCase(true)
.and("postalCode").is(address.postalCode()).ignoreCase(true)
.and("country").is(address.country()).ignoreCase(true)
.and(
where("addressOne").is(address.address()).ignoreCase(true)
.or("addressTwo").is(address.address()).ignoreCase(true)
.or("addressThree").is(address.address()).ignoreCase(true)
);

return searchClientByQuery(queryCriteria, ForestClientLocationEntity.class)
.flatMap(entity ->
searchClientByQuery(
where(ApplicationConstants.CLIENT_NUMBER_LITERAL).is(entity.getClientNumber()),
ForestClientEntity.class
return
locationRepository
.matchaddress(
address.address(),
address.postalCode(),
address.city(),
address.province(),
address.country()
)
)
.map(forestClientMapper::toDto)
.distinct(ForestClientDto::clientNumber)
.sort(Comparator.comparing(ForestClientDto::clientNumber))
.doOnNext(
dto -> log.info("Found client with address {} as [{}] {}",
address,
dto.clientNumber(), dto.clientName())
);
.flatMap(entity ->
searchClientByQuery(
where(ApplicationConstants.CLIENT_NUMBER_LITERAL).is(entity.getClientNumber()),
ForestClientEntity.class
)
)
.map(forestClientMapper::toDto)
.distinct(ForestClientDto::clientNumber)
.sort(Comparator.comparing(ForestClientDto::clientNumber))
.doOnNext(
dto -> log.info("Found client with address {} as [{}] {}",
address,
dto.clientNumber(), dto.clientName())
);
}

/**
Expand Down

0 comments on commit a88339b

Please sign in to comment.