Skip to content

Commit

Permalink
fix: opening filters (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Campos authored Oct 8, 2024
1 parent b7e0385 commit 19e3bb3
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
public class ConstantsConfig {

public static final Integer MAX_PAGE_SIZE = 500;
public static final Integer MAX_PAGE_SIZE_OPENING_SEARCH = 2000;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ca.bc.gov.restapi.results.common.exception;

import ca.bc.gov.restapi.results.common.config.ConstantsConfig;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.server.ResponseStatusException;
Expand All @@ -10,9 +9,9 @@
public class MaxPageSizeException extends ResponseStatusException {

/** Creates an MaxPageSizeException exception with http status and message. */
public MaxPageSizeException() {
public MaxPageSizeException(Integer max) {
super(
HttpStatus.BAD_REQUEST,
"Max page size limit exceeded! Choose a number below " + ConstantsConfig.MAX_PAGE_SIZE);
"Max page size limit exceeded! Choose a number below " + max);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ca.bc.gov.restapi.results.oracle.dto;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -10,8 +12,8 @@
public class OpeningSearchFiltersDto {
private final String orgUnit;
private final String category;
private final String status;
private final String entryUserId;
private final List<String> statusList;
private final Boolean myOpenings;
private final Boolean submittedToFrpa;
private final String disturbanceDateStart;
private final String disturbanceDateEnd;
Expand All @@ -21,13 +23,16 @@ public class OpeningSearchFiltersDto {
private final String freeGrowingDateEnd;
private final String updateDateStart;
private final String updateDateEnd;
private final String cuttingPermitId;
private final String cutBlockId;
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;

public static final String ORG_UNIT = "orgUnit";
public static final String CATEGORY = "category";
public static final String STATUS = "status";
public static final String ENTRY_USER_ID = "entryUserId";
public static final String STATUS_LIST = "statusList";
public static final String MY_OPENINGS = "myOpenings";
public static final String SUBMITTED_TO_FRPA = "submittedToFrpa";
public static final String DISTURBANCE_DATE_START = "disturbanceDateStart";
public static final String DISTURBANCE_DATE_END = "disturbanceDateEnd";
Expand All @@ -37,14 +42,19 @@ public class OpeningSearchFiltersDto {
public static final String FREE_GROWING_DATE_END = "freeGrowingDateEnd";
public static final String UPDATE_DATE_START = "updateDateStart";
public static final String UPDATE_DATE_END = "updateDateEnd";
public static final String CUTTING_PERMIT_ID = "cuttingPermitId";
public static final String CUT_BLOCK_ID = "cutBlockId";
public static final String TIMBER_MARK = "timberMark";
public static final String MAIN_SEARCH_TERM = "mainSearchTerm";

private String requestUserId;

/** Creates an instance of the search opening filter dto. */
public OpeningSearchFiltersDto(
String orgUnit,
String category,
String status,
String entryUserId,
List<String> statusList,
Boolean myOpenings,
Boolean submittedToFrpa,
String disturbanceDateStart,
String disturbanceDateEnd,
Expand All @@ -54,11 +64,17 @@ public OpeningSearchFiltersDto(
String freeGrowingDateEnd,
String updateDateStart,
String updateDateEnd,
String cuttingPermitId,
String cutBlockId,
String timberMark,
String mainSearchTerm) {
this.orgUnit = Objects.isNull(orgUnit) ? null : orgUnit.toUpperCase().trim();
this.category = Objects.isNull(category) ? null : category.toUpperCase().trim();
this.status = Objects.isNull(status) ? null : status.toUpperCase().trim();
this.entryUserId = Objects.isNull(entryUserId) ? null : entryUserId.toUpperCase().trim();
this.statusList = new ArrayList<>();
if (!Objects.isNull(statusList)) {
this.statusList.addAll(statusList.stream().map(s -> String.format("'%s'", s)).toList());
}
this.myOpenings = myOpenings;
this.submittedToFrpa = submittedToFrpa;
this.disturbanceDateStart =
Objects.isNull(disturbanceDateStart) ? null : disturbanceDateStart.trim();
Expand All @@ -71,10 +87,23 @@ public OpeningSearchFiltersDto(
this.freeGrowingDateEnd = Objects.isNull(freeGrowingDateEnd) ? null : freeGrowingDateEnd.trim();
this.updateDateStart = Objects.isNull(updateDateStart) ? null : updateDateStart.trim();
this.updateDateEnd = Objects.isNull(updateDateEnd) ? null : updateDateEnd.trim();
this.cuttingPermitId =
Objects.isNull(cuttingPermitId) ? null : cuttingPermitId.toUpperCase().trim();
this.cutBlockId = Objects.isNull(cutBlockId) ? null : cutBlockId.toUpperCase().trim();
this.timberMark = Objects.isNull(timberMark) ? null : timberMark.toUpperCase().trim();
this.mainSearchTerm =
Objects.isNull(mainSearchTerm) ? null : mainSearchTerm.toUpperCase().trim();
}

/**
* Set the Request User Id.
*
* @param requestUserId The id to be set.
*/
public void setRequestUserId(String requestUserId) {
this.requestUserId = requestUserId;
}

/**
* Define if a property has value.
*
Expand All @@ -87,10 +116,10 @@ public boolean hasValue(String prop) {
return !Objects.isNull(this.orgUnit);
case CATEGORY:
return !Objects.isNull(this.category);
case STATUS:
return !Objects.isNull(this.status);
case ENTRY_USER_ID:
return !Objects.isNull(this.entryUserId);
case STATUS_LIST:
return !this.statusList.isEmpty();
case MY_OPENINGS:
return !Objects.isNull(this.myOpenings);
case SUBMITTED_TO_FRPA:
return !Objects.isNull(this.submittedToFrpa);
case DISTURBANCE_DATE_START:
Expand All @@ -109,6 +138,12 @@ public boolean hasValue(String prop) {
return !Objects.isNull(this.updateDateStart);
case UPDATE_DATE_END:
return !Objects.isNull(this.updateDateEnd);
case CUTTING_PERMIT_ID:
return !Objects.isNull(this.cuttingPermitId);
case CUT_BLOCK_ID:
return !Objects.isNull(this.cutBlockId);
case TIMBER_MARK:
return !Objects.isNull(this.timberMark);
case MAIN_SEARCH_TERM:
return !Objects.isNull(this.mainSearchTerm);
default: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ Identifier for a cut block of a harvesting tenure (within a cutting permit for
example = "00012797")
private String clientNumber;

@Schema(
description = "Sequentially assigned number to identify a ministry client location.",
example = "01")
private String clientLocation;

@Schema(
description =
"""
Expand All @@ -109,6 +114,8 @@ Identifier for a cut block of a harvesting tenure (within a cutting permit for
example = "MOF")
private String clientAcronym;

private String clientName;

@Schema(description = "The final date based on the EARLY and LATE offset years.")
private LocalDateTime regenDelayDate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public class OpeningSearchEndpoint {
* File
* @param orgUnit Org Unit code filter, same as District.
* @param category Opening category code filter.
* @param status Opening status code filter.
* @param entryUserId Opening entry user id filter.
* @param statusList Opening statuses codes filter.
* @param myOpenings Openings created by the request user
* @param submittedToFrpa Submitted to FRPA
* @param disturbanceDateStart Disturbance start date filter
* @param disturbanceDateEnd Disturbance end date filter
Expand All @@ -58,6 +58,9 @@ public class OpeningSearchEndpoint {
* @param freeGrowingDateEnd Free growing end date filter
* @param updateDateStart Opening update start date filter
* @param updateDateEnd Opening update end date filter
* @param cuttingPermitId The cutting permit identification filter
* @param cutBlockId Cute block identification filter
* @param timberMark Timber mark filter
* @param paginationParameters Pagination settings
* @return PaginatedResult with found records.
*/
Expand Down Expand Up @@ -101,20 +104,20 @@ public PaginatedResult<OpeningSearchResponseDto> openingSearch(
description = "Opening category code filter. E.g.: FTML",
required = false)
String category,
@RequestParam(value = "status", required = false)
@RequestParam(value = "statusList", required = false)
@Parameter(
name = "status",
name = "statusList",
in = ParameterIn.QUERY,
description = "Opening status code filter. E.g.: APP",
required = false)
String status,
@RequestParam(value = "entryUserId", required = false)
List<String> statusList,
@RequestParam(value = "myOpenings", required = false)
@Parameter(
name = "entryUserId",
name = "myOpenings",
in = ParameterIn.QUERY,
description = "Opening entry user id filter",
description = "Openings created by the request user",
required = false)
String entryUserId,
Boolean myOpenings,
@RequestParam(value = "submittedToFrpa", required = false)
@Parameter(
name = "submittedToFrpa",
Expand Down Expand Up @@ -178,13 +181,40 @@ public PaginatedResult<OpeningSearchResponseDto> openingSearch(
description = "Opening update end date filter, format yyyy-MM-dd.",
required = false)
String updateDateEnd,
@RequestParam(value = "cuttingPermitId", required = false)
@Parameter(
name = "cuttingPermitId",
in = ParameterIn.QUERY,
description =
"Identifier for a cutting permit associated with a quota type harvesting tenure.",
required = false)
String cuttingPermitId,
@RequestParam(value = "cutBlockId", required = false)
@Parameter(
name = "cutBlockId",
in = ParameterIn.QUERY,
description =
"Identifier for a cut block of a harvesting tenure (within a cutting permit for"
+ " tenures with cp's).",
required = false)
String cutBlockId,
@RequestParam(value = "timberMark", required = false)
@Parameter(
name = "timberMark",
in = ParameterIn.QUERY,
description =
"Unique identifying set of characters to be stamped or marked on the end of each"
+ " log to associate the log with the specific authority to harvest and move"
+ " timber.",
required = false)
String timberMark,
@Valid PaginationParameters paginationParameters) {
OpeningSearchFiltersDto filtersDto =
new OpeningSearchFiltersDto(
orgUnit,
category,
status,
entryUserId,
statusList,
myOpenings,
submittedToFrpa,
disturbanceDateStart,
disturbanceDateEnd,
Expand All @@ -194,6 +224,9 @@ public PaginatedResult<OpeningSearchResponseDto> openingSearch(
freeGrowingDateEnd,
updateDateStart,
updateDateEnd,
cuttingPermitId,
cutBlockId,
timberMark,
mainSearchTerm);
return openingService.openingSearch(filtersDto, paginationParameters);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ca.bc.gov.restapi.results.oracle.enums;

import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Objects;

/**
* This enumeration represents all possible values for the Opening Status column from the Opening
Expand Down Expand Up @@ -49,6 +50,9 @@ public String getDescription() {
* @return OpeningStatusEnum or null if not found.
*/
public static OpeningStatusEnum of(String code) {
if (!Objects.isNull(code) && code.contains("\'")) {
code = code.replace("'", "");
}
for (OpeningStatusEnum status : values()) {
if (status.code.equals(code)) {
return status;
Expand Down
Loading

0 comments on commit 19e3bb3

Please sign in to comment.