Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(SILVA-539): added autocomplete for client location #505

Merged
merged 26 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c28747a
feat(SILVA-539): added search by acronym, name or number on FC api
paulushcgcj Nov 22, 2024
bb71446
feat(SILVA-539): added backend code to do client search
paulushcgcj Nov 25, 2024
0e4956e
feat(SILVA-539): added frontend code to do client search
paulushcgcj Nov 25, 2024
f17a4a5
Merge branch 'main' into feat/SILVA-539
paulushcgcj Nov 25, 2024
dfc77a9
Merge branch 'main' into feat/SILVA-539
paulushcgcj Nov 25, 2024
0849cc5
fix(SILVA-539): fixing lodash issues
paulushcgcj Nov 25, 2024
98c4d63
Merge branch 'main' into feat/SILVA-539
paulushcgcj Nov 25, 2024
b29c6c2
chore(SILVA-539): increasing the size of locations page
paulushcgcj Nov 28, 2024
feef21f
feat(SILVA-539): adding search with location code as param
paulushcgcj Nov 28, 2024
197f705
chore: fixing test
paulushcgcj Nov 28, 2024
1c2db7d
Merge remote-tracking branch 'origin/feat/SILVA-539' into feat/SILVA-539
paulushcgcj Nov 28, 2024
b318040
feat(SILVA-539): adding changes to frontend
paulushcgcj Nov 28, 2024
fa2ff42
Merge branch 'main' into feat/SILVA-539
paulushcgcj Nov 28, 2024
e2b9a70
test: fixing FE tests
paulushcgcj Nov 28, 2024
499d120
chore: adding loading
paulushcgcj Nov 28, 2024
4ae3f22
test(SILVA-539): adding test to autocomplete
paulushcgcj Nov 28, 2024
dc96131
chore: sonar fixes
paulushcgcj Nov 28, 2024
37d5c46
chore: fixing sonar issues
paulushcgcj Nov 28, 2024
cd828df
test(SILVA-539): adding tests
paulushcgcj Nov 28, 2024
d98ecdc
chore: sonar fix
paulushcgcj Dec 2, 2024
6fe45d7
chore: clearning up components
paulushcgcj Dec 2, 2024
f6ba29b
chore: fixing tests
paulushcgcj Dec 2, 2024
d43784d
chore: fixing build
paulushcgcj Dec 2, 2024
7a89341
chore: sonar fixes
paulushcgcj Dec 2, 2024
fa71b61
chore: fixing test
paulushcgcj Dec 2, 2024
b03f922
Merge branch 'main' into feat/SILVA-539
paulushcgcj Dec 2, 2024
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
@@ -0,0 +1,12 @@
package ca.bc.gov.restapi.results.common.dto;

import lombok.With;

@With
public record ForestClientAutocompleteResultDto(
String id,
String name,
String acronym
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import ca.bc.gov.restapi.results.common.enums.ForestClientStatusEnum;
import ca.bc.gov.restapi.results.common.enums.ForestClientTypeEnum;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.Builder;
import lombok.With;
import org.springframework.data.annotation.Transient;

/**
* This record represents a Forest Client object.
Expand All @@ -20,4 +24,16 @@ public record ForestClientDto(
String acronym
) {

@Transient
public String name() {
if (Objects.equals(this.clientTypeCode, "I")) {
return Stream.of(this.legalFirstName, this.legalMiddleName, this.clientName)
.filter(Objects::nonNull)
.map(String::trim)
.collect(Collectors.joining(" "));
} else {
return this.clientName;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ca.bc.gov.restapi.results.common.dto;

import ca.bc.gov.restapi.results.common.enums.YesNoEnum;
import java.time.LocalDate;
import lombok.With;

@With
public record ForestClientLocationDto(
String clientNumber,
String locationCode,
String locationName,
String companyCode,
String address1,
String address2,
String address3,
String city,
String province,
String postalCode,
String country,
String businessPhone,
String homePhone,
String cellPhone,
String faxNumber,
String email,
YesNoEnum expired,
YesNoEnum trusted,
LocalDate returnedMailDate,
String comment
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ca.bc.gov.restapi.results.common.dto;

import lombok.With;

@With
public record IdNameDto(
String id,
String name
) {

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package ca.bc.gov.restapi.results.common.endpoint;

import ca.bc.gov.restapi.results.common.dto.ForestClientAutocompleteResultDto;
import ca.bc.gov.restapi.results.common.dto.ForestClientDto;
import ca.bc.gov.restapi.results.common.dto.IdNameDto;
import ca.bc.gov.restapi.results.common.exception.ForestClientNotFoundException;
import ca.bc.gov.restapi.results.common.service.ForestClientService;
import java.util.List;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
Expand All @@ -32,4 +36,18 @@ public ForestClientDto getForestClient(@PathVariable String clientNumber) {
.getClientByNumber(clientNumber)
.orElseThrow(ForestClientNotFoundException::new);
}

@GetMapping("/byNameAcronymNumber")
public List<ForestClientAutocompleteResultDto> searchForestClients(
@RequestParam(value = "page",required = false,defaultValue = "0") Integer page,
@RequestParam(value = "size",required = false,defaultValue = "10") Integer size,
@RequestParam(value = "value") String value
) {
return forestClientService.searchClients(page,size,value);
}

@GetMapping("/{clientNumber}/locations")
public List<IdNameDto> getForestClientLocations(@PathVariable String clientNumber) {
return forestClientService.getClientLocations(clientNumber);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ca.bc.gov.restapi.results.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

public enum YesNoEnum {
YES("Y"),
NO("N");

private final String value;

YesNoEnum(String value) {
this.value = value;
}

@JsonValue
public String value() {
return this.value;
}

@JsonCreator
public static YesNoEnum fromValue(String value) {
for (YesNoEnum c : values()) {
if (c.value().equalsIgnoreCase(value)) {
return c;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package ca.bc.gov.restapi.results.common.provider;

import ca.bc.gov.restapi.results.common.dto.ForestClientDto;
import ca.bc.gov.restapi.results.common.dto.ForestClientLocationDto;
import java.util.List;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestClient;

/**
Expand Down Expand Up @@ -44,10 +48,63 @@ public Optional<ForestClientDto> fetchClientByNumber(String number) {
.retrieve()
.body(ForestClientDto.class)
);
} catch (HttpClientErrorException httpExc) {
} catch (HttpClientErrorException | HttpServerErrorException httpExc) {
log.error("Finished {} request - Response code error: {}", PROVIDER, httpExc.getStatusCode());
}

return Optional.empty();
}

public List<ForestClientDto> searchClients(
int page,
int size,
String value
) {
log.info("Starting {} request to /clients/search/by?name={}&acronym={}&number={}", PROVIDER,value,value,value);

try {
return
restClient
.get()
.uri(uriBuilder ->
uriBuilder
.path("/clients/search/by")
.queryParam("page", page)
.queryParam("size", size)
.queryParam("name", value)
.queryParam("acronym", value)
.queryParam("number", value)
.build()
)
.retrieve()
.body(new ParameterizedTypeReference<>() {});
} catch (HttpClientErrorException | HttpServerErrorException httpExc) {
log.error("{} requested on search by - Response code error: {}", PROVIDER, httpExc.getStatusCode());
}

return List.of();
}

public List<ForestClientLocationDto> fetchLocationsByClientNumber(String clientNumber) {
log.info("Starting {} request to /clients/{}/locations", PROVIDER, clientNumber);

try {
return
restClient
.get()
.uri(uriBuilder ->
uriBuilder
.path("/clients/{clientNumber}/locations")
.queryParam("page",0)
.queryParam("size",100)
.build(clientNumber)
)
.retrieve()
.body(new ParameterizedTypeReference<>() {});
} catch (HttpClientErrorException | HttpServerErrorException httpExc) {
log.error("Client location {} request - Response code error: {}", PROVIDER, httpExc.getStatusCode());
}

return List.of();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package ca.bc.gov.restapi.results.common.service;

import ca.bc.gov.restapi.results.common.dto.ForestClientAutocompleteResultDto;
import ca.bc.gov.restapi.results.common.dto.ForestClientDto;
import ca.bc.gov.restapi.results.common.dto.IdNameDto;
import ca.bc.gov.restapi.results.common.provider.ForestClientApiProvider;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -34,6 +38,42 @@ public Optional<ForestClientDto> getClientByNumber(String clientNumber) {
return forestClientApiProvider.fetchClientByNumber(fixedNumber);
}

public List<ForestClientAutocompleteResultDto> searchClients(
int page,
int size,
String value
) {
log.info("Searching forest client by {} as name, acronym or number with page {} and size {}",
value, page, size);
return forestClientApiProvider
.searchClients(page, size, value)
.stream()
.map(client -> new ForestClientAutocompleteResultDto(
client.clientNumber(),
client.name(),
client.acronym()
)
)
.toList();
}

public List<IdNameDto> getClientLocations(String clientNumber) {
String fixedNumber = checkClientNumber(clientNumber);

log.info("Fetching locations for client number {}", fixedNumber);

return
forestClientApiProvider
.fetchLocationsByClientNumber(fixedNumber)
.stream()
.map(location -> new IdNameDto(
location.locationCode(),
Objects.toString(location.locationName(), "No name provided")
))
.toList();
}


private String checkClientNumber(String clientNumber) {
if (StringUtils.isEmpty(clientNumber)) {
return "00000000";
Expand All @@ -46,4 +86,5 @@ private String checkClientNumber(String clientNumber) {
return "00000000";
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class SilvaOracleConstants {
public static final String ORG_UNIT = "orgUnit";
public static final String CATEGORY = "category";
public static final String STATUS_LIST = "statusList";
public static final String OPENING_IDS = "openingIds";
public static final String MY_OPENINGS = "myOpenings";
public static final String SUBMITTED_TO_FRPA = "submittedToFrpa";
public static final String DISTURBANCE_DATE_START = "disturbanceDateStart";
Expand All @@ -24,4 +23,5 @@ public class SilvaOracleConstants {
public static final String CUT_BLOCK_ID = "cutBlockId";
public static final String TIMBER_MARK = "timberMark";
public static final String MAIN_SEARCH_TERM = "mainSearchTerm";
public static final String LOCATION_CODE = "clientLocationCode";
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class OpeningSearchFiltersDto {
private final String timberMark;
// Main input, it can be one of Opening ID, Opening Number, Timber Mark ID, or File ID
private final String mainSearchTerm;
private final String clientLocationCode;

@Setter
private String requestUserId;
Expand All @@ -54,6 +55,7 @@ public OpeningSearchFiltersDto(
String cuttingPermitId,
String cutBlockId,
String timberMark,
String clientLocationCode,
String mainSearchTerm) {
this.orgUnit = !Objects.isNull(orgUnit) ? orgUnit : null;
this.category = !Objects.isNull(category) ? category : null;
Expand Down Expand Up @@ -84,6 +86,8 @@ public OpeningSearchFiltersDto(
this.timberMark = Objects.isNull(timberMark) ? null : timberMark.toUpperCase().trim();
this.mainSearchTerm =
Objects.isNull(mainSearchTerm) ? null : mainSearchTerm.toUpperCase().trim();
this.clientLocationCode =
Objects.isNull(clientLocationCode) ? null : clientLocationCode.trim();
}

/**
Expand Down Expand Up @@ -113,6 +117,7 @@ public boolean hasValue(String prop) {
case SilvaOracleConstants.CUT_BLOCK_ID -> !Objects.isNull(this.cutBlockId);
case SilvaOracleConstants.TIMBER_MARK -> !Objects.isNull(this.timberMark);
case SilvaOracleConstants.MAIN_SEARCH_TERM -> !Objects.isNull(this.mainSearchTerm);
case SilvaOracleConstants.LOCATION_CODE -> !Objects.isNull(this.clientLocationCode);
default -> {
log.warn("Prop not found {}", prop);
yield false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public PaginatedResult<OpeningSearchResponseDto> openingSearch(
String cuttingPermitId,
@RequestParam(value = "cutBlockId", required = false)
String cutBlockId,
@RequestParam(value = "clientLocationCode", required = false)
String clientLocationCode,
@RequestParam(value = "timberMark", required = false)
String timberMark,
@Valid PaginationParameters paginationParameters) {
Expand All @@ -113,6 +115,7 @@ public PaginatedResult<OpeningSearchResponseDto> openingSearch(
cuttingPermitId,
cutBlockId,
timberMark,
clientLocationCode,
mainSearchTerm);
return openingService.openingSearch(filtersDto, paginationParameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ LEFT JOIN THE.STOCKING_MILESTONE smfg ON (smfg.STOCKING_STANDARD_UNIT_ID = ssu.S
)
AND (
NVL(:#{#filter.timberMark},'NOVALUE') = 'NOVALUE' OR TIMBER_MARK = :#{#filter.timberMark}
)
AND (
NVL(:#{#filter.clientLocationCode},'NOVALUE') = 'NOVALUE' OR client_location = :#{#filter.clientLocationCode}
)""",
countQuery = """
SELECT count(o.OPENING_ID) as total
Expand Down Expand Up @@ -276,6 +279,9 @@ LEFT JOIN THE.STOCKING_MILESTONE smfg ON (smfg.STOCKING_STANDARD_UNIT_ID = ssu.S
)
AND (
NVL(:#{#filter.timberMark},'NOVALUE') = 'NOVALUE' OR cboa.TIMBER_MARK = :#{#filter.timberMark}
)
AND (
NVL(:#{#filter.clientLocationCode},'NOVALUE') = 'NOVALUE' OR res.CLIENT_LOCN_CODE = :#{#filter.clientLocationCode}
)""",
nativeQuery = true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.With;

Expand All @@ -19,6 +20,7 @@
@With
@Builder
@Entity
@EqualsAndHashCode(exclude = {"id","lastViewed"})
@Table(schema = "silva", name = "user_recent_openings")
public class UserRecentOpeningEntity {

Expand Down
Loading
Loading