Skip to content

Commit

Permalink
Merge branch 'main' into feat/SILVA-514
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj authored Oct 29, 2024
2 parents dcea8aa + 1eb273a commit 037aed9
Show file tree
Hide file tree
Showing 42 changed files with 848 additions and 568 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ca.bc.gov.restapi.results.common.endpoint;

import ca.bc.gov.restapi.results.common.service.OpenMapsService;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -12,7 +12,7 @@
*/
@RestController
@RequestMapping("/api/feature-service")
@AllArgsConstructor
@RequiredArgsConstructor
public class FeatureServiceEndpoint {

private final OpenMapsService openMapsService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package ca.bc.gov.restapi.results.common.pagination;

import java.util.List;
import lombok.Getter;
import lombok.Setter;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.With;

/** Holds an API response with pagination information and data. */
@Getter
@Setter
/**
* Holds an API response with pagination information and data.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@With
@Builder
public class PaginatedResult<T> {

private int pageIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.PositiveOrZero;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

/**
* Pagination parameters to be used in the processing of HTTP GET requests.
*
* @param page The page to be returned. Zero-based, and must be non-negative; defaults to 0
* @param perPage The maximum number of results in each page. Defaults to 20
*/
public record PaginationParameters(@PositiveOrZero Integer page, @Positive Integer perPage) {
public record PaginationParameters(
@PositiveOrZero(message = "Page number needs to be zero or a positive value")
Integer page,
@Positive(message = "Page size needs to be a positive value")
Integer perPage
) {

/**
* Build an instance of {@link PaginationParameters}, using the default values for {@code page}
Expand All @@ -23,4 +30,8 @@ public record PaginationParameters(@PositiveOrZero Integer page, @Positive Integ
perPage = 5;
}
}

public Pageable toPageable(int maxPageSize) {
return PageRequest.of(page, maxPageSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ForestClientApiProvider {
*/
public Optional<ForestClientDto> fetchClientByNumber(String number) {

log.info("Starting {} request to /clients/findByClientNumber/{number}", PROVIDER);
log.info("Starting {} request to /clients/findByClientNumber/{}", PROVIDER,number);

try {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ca.bc.gov.restapi.results.oracle;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
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 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";
public static final String REGEN_DELAY_DATE_START = "regenDelayDateStart";
public static final String REGEN_DELAY_DATE_END = "regenDelayDateEnd";
public static final String FREE_GROWING_DATE_START = "freeGrowingDateStart";
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";
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package ca.bc.gov.restapi.results.oracle.dto;

import ca.bc.gov.restapi.results.oracle.SilvaOracleConstants;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

/** This record contains all possible filters when using the Opening Search API. */
@Slf4j
@Getter
@ToString
public class OpeningSearchFiltersDto {
private final String orgUnit;
private final String category;
Expand All @@ -29,24 +33,7 @@ public class OpeningSearchFiltersDto {
// 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_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";
public static final String REGEN_DELAY_DATE_START = "regenDelayDateStart";
public static final String REGEN_DELAY_DATE_END = "regenDelayDateEnd";
public static final String FREE_GROWING_DATE_START = "freeGrowingDateStart";
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";

@Setter
private String requestUserId;

/** Creates an instance of the search opening filter dto. */
Expand Down Expand Up @@ -95,61 +82,37 @@ public OpeningSearchFiltersDto(
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.
*
* @param prop The property to be checked.
* @return True if it has, false otherwise.
*/
public boolean hasValue(String prop) {
switch (prop) {
case ORG_UNIT:
return !Objects.isNull(this.orgUnit);
case CATEGORY:
return !Objects.isNull(this.category);
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:
return !Objects.isNull(this.disturbanceDateStart);
case DISTURBANCE_DATE_END:
return !Objects.isNull(this.disturbanceDateEnd);
case REGEN_DELAY_DATE_START:
return !Objects.isNull(this.regenDelayDateStart);
case REGEN_DELAY_DATE_END:
return !Objects.isNull(this.regenDelayDateEnd);
case FREE_GROWING_DATE_START:
return !Objects.isNull(this.freeGrowingDateStart);
case FREE_GROWING_DATE_END:
return !Objects.isNull(this.freeGrowingDateEnd);
case UPDATE_DATE_START:
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: {
return switch (prop) {
case SilvaOracleConstants.ORG_UNIT -> !Objects.isNull(this.orgUnit);
case SilvaOracleConstants.CATEGORY -> !Objects.isNull(this.category);
case SilvaOracleConstants.STATUS_LIST -> !this.statusList.isEmpty();
case SilvaOracleConstants.MY_OPENINGS -> !Objects.isNull(this.myOpenings);
case SilvaOracleConstants.SUBMITTED_TO_FRPA -> !Objects.isNull(this.submittedToFrpa);
case SilvaOracleConstants.DISTURBANCE_DATE_START ->
!Objects.isNull(this.disturbanceDateStart);
case SilvaOracleConstants.DISTURBANCE_DATE_END -> !Objects.isNull(this.disturbanceDateEnd);
case SilvaOracleConstants.REGEN_DELAY_DATE_START -> !Objects.isNull(this.regenDelayDateStart);
case SilvaOracleConstants.REGEN_DELAY_DATE_END -> !Objects.isNull(this.regenDelayDateEnd);
case SilvaOracleConstants.FREE_GROWING_DATE_START ->
!Objects.isNull(this.freeGrowingDateStart);
case SilvaOracleConstants.FREE_GROWING_DATE_END -> !Objects.isNull(this.freeGrowingDateEnd);
case SilvaOracleConstants.UPDATE_DATE_START -> !Objects.isNull(this.updateDateStart);
case SilvaOracleConstants.UPDATE_DATE_END -> !Objects.isNull(this.updateDateEnd);
case SilvaOracleConstants.CUTTING_PERMIT_ID -> !Objects.isNull(this.cuttingPermitId);
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);
default -> {
log.warn("Prop not found {}", prop);
return false;
yield false;
}
}
};
}
}
Loading

0 comments on commit 037aed9

Please sign in to comment.