diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/SilvaOracleConstants.java b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/SilvaOracleConstants.java new file mode 100644 index 00000000..68f3732c --- /dev/null +++ b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/SilvaOracleConstants.java @@ -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"; +} diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/dto/OpeningSearchFiltersDto.java b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/dto/OpeningSearchFiltersDto.java index c9fb4bc9..62fc0296 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/dto/OpeningSearchFiltersDto.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/dto/OpeningSearchFiltersDto.java @@ -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; @@ -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. */ @@ -95,15 +82,6 @@ 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. * @@ -111,45 +89,30 @@ public void setRequestUserId(String requestUserId) { * @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; } - } + }; } } diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/repository/OpeningSearchRepository.java b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/repository/OpeningSearchRepository.java index 56fb66c0..4c79aed8 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/repository/OpeningSearchRepository.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/repository/OpeningSearchRepository.java @@ -3,6 +3,7 @@ import ca.bc.gov.restapi.results.common.SilvaConstants; import ca.bc.gov.restapi.results.common.pagination.PaginatedResult; import ca.bc.gov.restapi.results.common.pagination.PaginationParameters; +import ca.bc.gov.restapi.results.oracle.SilvaOracleConstants; import ca.bc.gov.restapi.results.oracle.dto.OpeningSearchFiltersDto; import ca.bc.gov.restapi.results.oracle.dto.OpeningSearchResponseDto; import ca.bc.gov.restapi.results.oracle.enums.OpeningCategoryEnum; @@ -241,7 +242,7 @@ private Query setQueryParameters(OpeningSearchFiltersDto filtersDto, String nati Query query = em.createNativeQuery(nativeQuery); // set parameters - if (filtersDto.hasValue(OpeningSearchFiltersDto.MAIN_SEARCH_TERM)) { + if (filtersDto.hasValue(SilvaOracleConstants.MAIN_SEARCH_TERM)) { boolean itsNumeric = filtersDto.getMainSearchTerm().replaceAll("[0-9]", "").isEmpty(); if (itsNumeric) { log.info("Setting mainSearchTerm as numeric filter value"); @@ -255,83 +256,83 @@ private Query setQueryParameters(OpeningSearchFiltersDto filtersDto, String nati } // 1. Org Unit code - if (filtersDto.hasValue(OpeningSearchFiltersDto.ORG_UNIT)) { + if (filtersDto.hasValue(SilvaOracleConstants.ORG_UNIT)) { log.info("Setting orgUnit filter value"); query.setParameter("orgUnit", filtersDto.getOrgUnit()); } // 2. Category code - if (filtersDto.hasValue(OpeningSearchFiltersDto.CATEGORY)) { + if (filtersDto.hasValue(SilvaOracleConstants.CATEGORY)) { log.info("Setting category filter value"); query.setParameter("category", filtersDto.getCategory()); } // 3. Status list codes - if (filtersDto.hasValue(OpeningSearchFiltersDto.STATUS_LIST)) { + if (filtersDto.hasValue(SilvaOracleConstants.STATUS_LIST)) { log.info("Setting statusList filter values"); // No need to set value since the query already dit it. Didn't work set through named param } // 4. User entry id - if (filtersDto.hasValue(OpeningSearchFiltersDto.MY_OPENINGS)) { + if (filtersDto.hasValue(SilvaOracleConstants.MY_OPENINGS)) { log.info("Setting myOpenings filter value"); query.setParameter("entryUserId", filtersDto.getRequestUserId()); } // 5. Submitted to FRPA Section 108 - if (filtersDto.hasValue(OpeningSearchFiltersDto.SUBMITTED_TO_FRPA)) { + if (filtersDto.hasValue(SilvaOracleConstants.SUBMITTED_TO_FRPA)) { log.info("Setting submitted to FRPA filter!"); // No need to set value since the query already dit it. } // 6. Disturbance start date - if (filtersDto.hasValue(OpeningSearchFiltersDto.DISTURBANCE_DATE_START)) { + if (filtersDto.hasValue(SilvaOracleConstants.DISTURBANCE_DATE_START)) { log.info("Setting disturbanceDateStart filter value"); query.setParameter("disturbStartDate", filtersDto.getDisturbanceDateStart()); } // 7. Disturbance end date - if (filtersDto.hasValue(OpeningSearchFiltersDto.DISTURBANCE_DATE_END)) { + if (filtersDto.hasValue(SilvaOracleConstants.DISTURBANCE_DATE_END)) { log.info("Setting disturbanceDateEnd filter value"); query.setParameter("disturbEndDate", filtersDto.getDisturbanceDateEnd()); } // 8. Regen delay start date - if (filtersDto.hasValue(OpeningSearchFiltersDto.REGEN_DELAY_DATE_START)) { + if (filtersDto.hasValue(SilvaOracleConstants.REGEN_DELAY_DATE_START)) { log.info("Setting regenDelayDateStart filter value"); query.setParameter("regenDelayDateStart", filtersDto.getRegenDelayDateStart()); } // 9. Regen delay end date - if (filtersDto.hasValue(OpeningSearchFiltersDto.REGEN_DELAY_DATE_END)) { + if (filtersDto.hasValue(SilvaOracleConstants.REGEN_DELAY_DATE_END)) { log.info("Setting regenDelayDateEnd filter value"); query.setParameter("regenDelayDateEnd", filtersDto.getRegenDelayDateEnd()); } // 10. Free growing start date - if (filtersDto.hasValue(OpeningSearchFiltersDto.FREE_GROWING_DATE_START)) { + if (filtersDto.hasValue(SilvaOracleConstants.FREE_GROWING_DATE_START)) { log.info("Setting freeGrowingDateStart filter value"); query.setParameter("freeGrowingDateStart", filtersDto.getFreeGrowingDateStart()); } // 11. Free growing end date - if (filtersDto.hasValue(OpeningSearchFiltersDto.FREE_GROWING_DATE_END)) { + if (filtersDto.hasValue(SilvaOracleConstants.FREE_GROWING_DATE_END)) { log.info("Setting freeGrowingDateEnd filter value"); query.setParameter("freeGrowingDateEnd", filtersDto.getFreeGrowingDateEnd()); } // 12. Update date start - if (filtersDto.hasValue(OpeningSearchFiltersDto.UPDATE_DATE_START)) { + if (filtersDto.hasValue(SilvaOracleConstants.UPDATE_DATE_START)) { log.info("Setting updateDateStart filter value"); query.setParameter("updateStartDate", filtersDto.getUpdateDateStart()); } // 13. Update date end - if (filtersDto.hasValue(OpeningSearchFiltersDto.UPDATE_DATE_END)) { + if (filtersDto.hasValue(SilvaOracleConstants.UPDATE_DATE_END)) { log.info("Setting updateDateEnd filter value"); query.setParameter("updateEndDate", filtersDto.getUpdateDateEnd()); } // 14. Cutting permit id - if (filtersDto.hasValue(OpeningSearchFiltersDto.CUTTING_PERMIT_ID)) { + if (filtersDto.hasValue(SilvaOracleConstants.CUTTING_PERMIT_ID)) { log.info("Setting cuttingPermitId filter value"); query.setParameter("cuttingPermitId", filtersDto.getCuttingPermitId()); } // 15. Cut block id - if (filtersDto.hasValue(OpeningSearchFiltersDto.CUT_BLOCK_ID)) { + if (filtersDto.hasValue(SilvaOracleConstants.CUT_BLOCK_ID)) { log.info("Setting cutBlockId filter value"); query.setParameter("cutBlockId", filtersDto.getCutBlockId()); } // 16. Timber mark - if (filtersDto.hasValue(OpeningSearchFiltersDto.TIMBER_MARK)) { + if (filtersDto.hasValue(SilvaOracleConstants.TIMBER_MARK)) { log.info("Setting timberMark filter value"); query.setParameter("timberMark", filtersDto.getTimberMark()); } @@ -392,7 +393,7 @@ private String createNativeSqlQuery(OpeningSearchFiltersDto filtersDto) { // 0. Main number filter [opening_id, opening_number, timber_mark, file_id] // if it's a number, filter by openingId or fileId, otherwise filter by timber mark and opening // number - if (filtersDto.hasValue(OpeningSearchFiltersDto.MAIN_SEARCH_TERM)) { + if (filtersDto.hasValue(SilvaOracleConstants.MAIN_SEARCH_TERM)) { log.info("Filter mainSearchTerm detected! mainSearchTerm={}", filtersDto.getMainSearchTerm()); boolean itsNumeric = filtersDto.getMainSearchTerm().replaceAll("[0-9]", "").isEmpty(); if (itsNumeric) { @@ -412,28 +413,28 @@ private String createNativeSqlQuery(OpeningSearchFiltersDto filtersDto) { } // 1. Org Unit code - if (filtersDto.hasValue(OpeningSearchFiltersDto.ORG_UNIT)) { + if (filtersDto.hasValue(SilvaOracleConstants.ORG_UNIT)) { log.info("Filter orgUnit detected! orgUnit={}", filtersDto.getOrgUnit()); builder.append("AND ou.ORG_UNIT_CODE = :orgUnit "); } // 2. Category code - if (filtersDto.hasValue(OpeningSearchFiltersDto.CATEGORY)) { + if (filtersDto.hasValue(SilvaOracleConstants.CATEGORY)) { log.info("Filter category detected! category={}", filtersDto.getCategory()); builder.append("AND o.OPEN_CATEGORY_CODE = :category "); } // 3. Status code - if (filtersDto.hasValue(OpeningSearchFiltersDto.STATUS_LIST)) { + if (filtersDto.hasValue(SilvaOracleConstants.STATUS_LIST)) { String statuses = String.join(",", filtersDto.getStatusList()); log.info("Filter statusList detected! statusList={}", statuses); builder.append(String.format("AND o.OPENING_STATUS_CODE IN (%s) ", statuses)); } // 4. My openings - if (filtersDto.hasValue(OpeningSearchFiltersDto.MY_OPENINGS)) { + if (filtersDto.hasValue(SilvaOracleConstants.MY_OPENINGS)) { log.info("Filter myOpenings detected! entryUserId={}", filtersDto.getRequestUserId()); builder.append("AND o.ENTRY_USERID = :entryUserId "); } // 5. Submitted to FRPA - if (filtersDto.hasValue(OpeningSearchFiltersDto.SUBMITTED_TO_FRPA)) { + if (filtersDto.hasValue(SilvaOracleConstants.SUBMITTED_TO_FRPA)) { Boolean value = filtersDto.getSubmittedToFrpa(); if (Boolean.FALSE.equals(value)) { log.info( @@ -446,34 +447,34 @@ private String createNativeSqlQuery(OpeningSearchFiltersDto filtersDto) { } } // 6. Disturbance start date - if (filtersDto.hasValue(OpeningSearchFiltersDto.DISTURBANCE_DATE_START)) { + if (filtersDto.hasValue(SilvaOracleConstants.DISTURBANCE_DATE_START)) { log.info( "Filter disturbanceDateStart detected! date={}", filtersDto.getDisturbanceDateStart()); builder.append( "AND cboa.DISTURBANCE_START_DATE >= to_timestamp(:disturbStartDate, 'YYYY-MM-DD') "); } // 7. Disturbance end date - if (filtersDto.hasValue(OpeningSearchFiltersDto.DISTURBANCE_DATE_END)) { + if (filtersDto.hasValue(SilvaOracleConstants.DISTURBANCE_DATE_END)) { log.info("Filter disturbanceDateEnd detected! date={}", filtersDto.getDisturbanceDateEnd()); builder.append( "AND cboa.DISTURBANCE_START_DATE <= to_timestamp(:disturbEndDate, 'YYYY-MM-DD') "); } // 8. Regen delay start date - if (filtersDto.hasValue(OpeningSearchFiltersDto.REGEN_DELAY_DATE_START)) { + if (filtersDto.hasValue(SilvaOracleConstants.REGEN_DELAY_DATE_START)) { log.info("Filter regenDelayDateStart detected! date={}", filtersDto.getRegenDelayDateStart()); builder.append("AND ADD_MONTHS(cboa.DISTURBANCE_START_DATE, "); builder.append("COALESCE(SMRG.LATE_OFFSET_YEARS,0)*12) "); builder.append("> to_timestamp(:regenDelayDateStart,'YYYY-MM-DD')"); } // 9. Regen delay end date - if (filtersDto.hasValue(OpeningSearchFiltersDto.REGEN_DELAY_DATE_END)) { + if (filtersDto.hasValue(SilvaOracleConstants.REGEN_DELAY_DATE_END)) { log.info("Filter regenDelayDateEnd detected! date={}", filtersDto.getRegenDelayDateEnd()); builder.append("AND ADD_MONTHS(cboa.DISTURBANCE_START_DATE, "); builder.append("COALESCE(SMRG.LATE_OFFSET_YEARS,0)*12) "); builder.append("< to_timestamp(:regenDelayDateEnd,'YYYY-MM-DD')"); } // 10. Free growing start date - if (filtersDto.hasValue(OpeningSearchFiltersDto.FREE_GROWING_DATE_START)) { + if (filtersDto.hasValue(SilvaOracleConstants.FREE_GROWING_DATE_START)) { log.info( "Filter freeGrowingDateStart detected! date={}", filtersDto.getFreeGrowingDateStart()); builder.append("AND ADD_MONTHS(cboa.DISTURBANCE_START_DATE, "); @@ -481,35 +482,35 @@ private String createNativeSqlQuery(OpeningSearchFiltersDto filtersDto) { builder.append("> to_timestamp(:freeGrowingDateStart,'YYYY-MM-DD')"); } // 11. Free growing end date - if (filtersDto.hasValue(OpeningSearchFiltersDto.FREE_GROWING_DATE_END)) { + if (filtersDto.hasValue(SilvaOracleConstants.FREE_GROWING_DATE_END)) { log.info("Filter freeGrowingDateEnd detected! date={}", filtersDto.getFreeGrowingDateEnd()); builder.append("AND ADD_MONTHS(cboa.DISTURBANCE_START_DATE, "); builder.append("COALESCE(SMFG.LATE_OFFSET_YEARS,0)*12) "); builder.append("< to_timestamp(:freeGrowingDateEnd, 'YYYY-MM-DD')"); } // 12. Update date start - if (filtersDto.hasValue(OpeningSearchFiltersDto.UPDATE_DATE_START)) { + if (filtersDto.hasValue(SilvaOracleConstants.UPDATE_DATE_START)) { log.info("Filter updateDateStart detected! date={}", filtersDto.getUpdateDateStart()); builder.append("AND o.UPDATE_TIMESTAMP >= to_timestamp(:updateStartDate, 'YYYY-MM-DD') "); } // 13. Update date end - if (filtersDto.hasValue(OpeningSearchFiltersDto.UPDATE_DATE_END)) { + if (filtersDto.hasValue(SilvaOracleConstants.UPDATE_DATE_END)) { log.info("Filter updateDateEnd detected! date={}", filtersDto.getUpdateDateEnd()); builder.append("AND o.UPDATE_TIMESTAMP <= to_timestamp(:updateEndDate, 'YYYY-MM-DD') "); } // 14. Cutting permit id - if (filtersDto.hasValue(OpeningSearchFiltersDto.CUTTING_PERMIT_ID)) { + if (filtersDto.hasValue(SilvaOracleConstants.CUTTING_PERMIT_ID)) { log.info( "Filter cuttingPermitId detected! cuttingPermitId={}", filtersDto.getCuttingPermitId()); builder.append("AND cboa.CUTTING_PERMIT_ID = :cuttingPermitId "); } // 15. Cut block id - if (filtersDto.hasValue(OpeningSearchFiltersDto.CUT_BLOCK_ID)) { + if (filtersDto.hasValue(SilvaOracleConstants.CUT_BLOCK_ID)) { log.info("Filter cutBlockId detected! cutBlockId={}", filtersDto.getCutBlockId()); builder.append("AND cboa.CUT_BLOCK_ID = :cutBlockId "); } // 16. Timber mark - if (filtersDto.hasValue(OpeningSearchFiltersDto.TIMBER_MARK)) { + if (filtersDto.hasValue(SilvaOracleConstants.TIMBER_MARK)) { log.info("Filter timberMark detected! timberMark={}", filtersDto.getTimberMark()); builder.append("AND cboa.TIMBER_MARK = :timberMark "); } diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/service/OpenCategoryCodeService.java b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/service/OpenCategoryCodeService.java index e6b4db83..c4d6ddd5 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/service/OpenCategoryCodeService.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/service/OpenCategoryCodeService.java @@ -6,6 +6,7 @@ import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.BooleanUtils; import org.springframework.stereotype.Service; /** This class contains methods to handle Opening Categories. */ @@ -25,15 +26,15 @@ public class OpenCategoryCodeService { public List findAllCategories(boolean includeExpired) { log.info("Getting all open category codes. Include expired: {}", includeExpired); - if (includeExpired) { - List openCategoryCodes = openCategoryCodeRepository.findAll(); - log.info("Found {} open category codes (including expired)", openCategoryCodes.size()); - return openCategoryCodes; - } - List openCategoryCodes = - openCategoryCodeRepository.findAllByExpiryDateAfter(LocalDate.now()); - log.info("Found {} open category codes (excluding expired)", openCategoryCodes.size()); + includeExpired ? + openCategoryCodeRepository.findAll() + : openCategoryCodeRepository.findAllByExpiryDateAfter(LocalDate.now()); + + log.info("Found {} open category codes ({}cluding expired)", + openCategoryCodes.size(), + BooleanUtils.toString(includeExpired, "in", "ex") + ); return openCategoryCodes; } } diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/service/OpeningService.java b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/service/OpeningService.java index 402cb6de..967535cc 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/service/OpeningService.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/service/OpeningService.java @@ -7,6 +7,7 @@ import ca.bc.gov.restapi.results.common.pagination.PaginationParameters; import ca.bc.gov.restapi.results.common.provider.ForestClientApiProvider; import ca.bc.gov.restapi.results.common.security.LoggedUserService; +import ca.bc.gov.restapi.results.oracle.SilvaOracleConstants; import ca.bc.gov.restapi.results.oracle.dto.OpeningSearchFiltersDto; import ca.bc.gov.restapi.results.oracle.dto.OpeningSearchResponseDto; import ca.bc.gov.restapi.results.oracle.dto.RecentOpeningDto; @@ -165,7 +166,7 @@ public PaginatedResult openingSearch( } // Set the user in the filter, if required - if (filtersDto.hasValue(OpeningSearchFiltersDto.MY_OPENINGS)) { + if (filtersDto.hasValue(SilvaOracleConstants.MY_OPENINGS)) { String userId = loggedUserService.getLoggedUserId().replace("@", "\\"); if (!userId.startsWith("IDIR")) { userId = "BCEID" + userId.substring(5); diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/util/PaginationUtil.java b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/util/PaginationUtil.java index 93e0d6b4..90c070c7 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/util/PaginationUtil.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/util/PaginationUtil.java @@ -1,8 +1,12 @@ package ca.bc.gov.restapi.results.oracle.util; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + /** * This class contains methods for manual pagination. */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class PaginationUtil { /** @@ -13,11 +17,7 @@ public class PaginationUtil { * @return The last page number, representing the total number of pages. */ public static int getLastPage(int totalElements, int pageSize) { - if (pageSize == 0) { - return 0; - } - int lastPage = (int) Math.ceil((double) totalElements / pageSize); - return lastPage; + return (pageSize == 0) ? 0 : (int) Math.ceil((double) totalElements / pageSize); } /** @@ -28,8 +28,7 @@ public static int getLastPage(int totalElements, int pageSize) { * @return The start index */ public static int getStartIndex(int currentPage, int pageSize) { - int startIndex = currentPage * pageSize; - return startIndex; + return currentPage * pageSize; } /** @@ -41,8 +40,7 @@ public static int getStartIndex(int currentPage, int pageSize) { * @return The last index */ public static int getEndIndex(int startIndex, int pageSize, int totalElements) { - int endIndex = Math.min(startIndex + pageSize, totalElements); - return endIndex; + return Math.min(startIndex + pageSize, totalElements); } } diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/postgres/SilvaPostgresConstants.java b/backend/src/main/java/ca/bc/gov/restapi/results/postgres/SilvaPostgresConstants.java new file mode 100644 index 00000000..069fd46e --- /dev/null +++ b/backend/src/main/java/ca/bc/gov/restapi/results/postgres/SilvaPostgresConstants.java @@ -0,0 +1,16 @@ +package ca.bc.gov.restapi.results.postgres; + +import java.util.Map; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SilvaPostgresConstants { + + public static final Map LABELS_MAP = Map.of( + 0, "0 - 5 months", + 1, "6 - 11 months", + 2, "12 - 17 months", + 3, "18 months" + ); +} diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/postgres/repository/OpeningsActivityRepository.java b/backend/src/main/java/ca/bc/gov/restapi/results/postgres/repository/OpeningsActivityRepository.java index dd3e50d5..a1c956ec 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/postgres/repository/OpeningsActivityRepository.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/postgres/repository/OpeningsActivityRepository.java @@ -5,14 +5,14 @@ import java.util.List; import org.springframework.data.domain.Sort; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -/** This interface provides access to the database for the OpeningsActivityEntity entity. */ +/** + * This interface provides access to the database for the OpeningsActivityEntity entity. + */ public interface OpeningsActivityRepository extends JpaRepository { - @Query("from OpeningsActivityEntity o where o.openingId in (?1)") - List findAllByOpeningId(List openingIds); + List findAllByOpeningIdIn(List openingIds); List findAllByEntryUserid(String userId, Sort sort); } diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/postgres/repository/OpeningsLastYearRepository.java b/backend/src/main/java/ca/bc/gov/restapi/results/postgres/repository/OpeningsLastYearRepository.java index 064743ae..1a70cd42 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/postgres/repository/OpeningsLastYearRepository.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/postgres/repository/OpeningsLastYearRepository.java @@ -10,8 +10,7 @@ /** This interface provides access to the database for the OpeningsLastYearEntity entity. */ public interface OpeningsLastYearRepository extends JpaRepository { - @Query("from OpeningsLastYearEntity o where o.openingId in ?1") - List findAllByOpeningIdInList(List openingIdList); + List findAllByOpeningIdIn(List openingIdList); @Query("from OpeningsLastYearEntity o where o.entryTimestamp >= ?1 or o.updateTimestamp >= ?1") List findAllFromLastYear(LocalDateTime baseDateTime, Sort sort); diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/postgres/repository/UserOpeningRepository.java b/backend/src/main/java/ca/bc/gov/restapi/results/postgres/repository/UserOpeningRepository.java index 377be33c..f56ebd49 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/postgres/repository/UserOpeningRepository.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/postgres/repository/UserOpeningRepository.java @@ -4,14 +4,13 @@ import ca.bc.gov.restapi.results.postgres.entity.UserOpeningEntityId; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -/** This interface holds methods for handling {@link UserOpeningEntity} data in the database. */ +/** + * This interface holds methods for handling {@link UserOpeningEntity} data in the database. + */ public interface UserOpeningRepository extends JpaRepository { List findAllByUserId(String userId); - @Query("from UserOpeningEntity o where o.openingId in ?1 and o.userId = ?2") - List findAllByOpeningIdInAndUserId(List openingIdList, String userId); } diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/postgres/service/DashboardMetricsService.java b/backend/src/main/java/ca/bc/gov/restapi/results/postgres/service/DashboardMetricsService.java index 5827bfa3..2e87214e 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/postgres/service/DashboardMetricsService.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/postgres/service/DashboardMetricsService.java @@ -2,6 +2,7 @@ import ca.bc.gov.restapi.results.common.security.LoggedUserService; import ca.bc.gov.restapi.results.common.util.TimestampUtil; +import ca.bc.gov.restapi.results.postgres.SilvaPostgresConstants; import ca.bc.gov.restapi.results.postgres.dto.DashboardFiltersDto; import ca.bc.gov.restapi.results.postgres.dto.FreeGrowingMilestonesDto; import ca.bc.gov.restapi.results.postgres.dto.MyRecentActionsRequestsDto; @@ -154,12 +155,6 @@ public List getFreeGrowingMilestoneChartData( resultMap.put(i, new ArrayList<>()); } - Map labelsMap = new HashMap<>(); - labelsMap.put(0, "0 - 5 months"); - labelsMap.put(1, "6 - 11 months"); - labelsMap.put(2, "12 - 17 months"); - labelsMap.put(3, "18 months"); - int totalRecordsFiltered = 0; // Iterate over the found records filtering and putting them into the right piece @@ -205,7 +200,7 @@ public List getFreeGrowingMilestoneChartData( BigDecimal hundredSum = new BigDecimal("100"); for (Integer index : resultMap.keySet()) { List groupList = resultMap.get(index); - String label = labelsMap.get(index); + String label = SilvaPostgresConstants.LABELS_MAP.get(index); int value = groupList.size(); log.info("{} openings of {} for label '{}'", value, totalRecordsFiltered, label); diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/postgres/service/UserOpeningService.java b/backend/src/main/java/ca/bc/gov/restapi/results/postgres/service/UserOpeningService.java index b26448a3..421ca6b5 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/postgres/service/UserOpeningService.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/postgres/service/UserOpeningService.java @@ -47,7 +47,7 @@ public List getUserTrackedOpenings() { List openingIds = userList.stream().map(UserOpeningEntity::getOpeningId).toList(); List openingActivities = - openingsActivityRepository.findAllByOpeningId(openingIds); + openingsActivityRepository.findAllByOpeningIdIn(openingIds); if (openingActivities.isEmpty()) { log.info("No records found on the opening activity table for the opening ID list!"); diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 91e89b55..10478eea 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -51,7 +51,7 @@ spring: # Common database settings jpa: - show-sql: true + show-sql: false # FAM security: diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/converter/OpeningCategoryConverterTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/converter/OpeningCategoryConverterTest.java new file mode 100644 index 00000000..6acaabb8 --- /dev/null +++ b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/converter/OpeningCategoryConverterTest.java @@ -0,0 +1,44 @@ +package ca.bc.gov.restapi.results.oracle.converter; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import ca.bc.gov.restapi.results.oracle.enums.OpeningCategoryEnum; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("Unit Test | Opening Category Converter") +class OpeningCategoryConverterTest { + + private final OpeningCategoryConverter converter = new OpeningCategoryConverter(); + + @Test + @DisplayName("To database") + void convertToDatabaseColumnWithValidEnum() { + assertEquals("FTML", converter.convertToDatabaseColumn(OpeningCategoryEnum.FTML)); + } + + @Test + @DisplayName("Null to database") + void convertToDatabaseColumnWithNull() { + assertNull(converter.convertToDatabaseColumn(null)); + } + + @Test + @DisplayName("From database") + void convertToEntityAttributeWithValidCode() { + assertEquals(OpeningCategoryEnum.FTML, converter.convertToEntityAttribute("FTML")); + } + + @Test + @DisplayName("Invalid code") + void convertToEntityAttributeWithInvalidCode() { + assertNull(converter.convertToEntityAttribute("INVALID")); + } + + @Test + @DisplayName("Null") + void convertToEntityAttributeWithNull() { + assertNull(converter.convertToEntityAttribute(null)); + } +} \ No newline at end of file diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/converter/OpeningStatusConverterTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/converter/OpeningStatusConverterTest.java new file mode 100644 index 00000000..45a7b5b5 --- /dev/null +++ b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/converter/OpeningStatusConverterTest.java @@ -0,0 +1,45 @@ +package ca.bc.gov.restapi.results.oracle.converter; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import ca.bc.gov.restapi.results.oracle.enums.OpeningStatusEnum; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("Unit Test | Opening Status Converter") +class OpeningStatusConverterTest { + + private final OpeningStatusConverter converter = new OpeningStatusConverter(); + + @Test + @DisplayName("To database") + void convertToDatabaseColumnWithValidEnum() { + assertEquals("APP", converter.convertToDatabaseColumn(OpeningStatusEnum.APP)); + } + + @Test + @DisplayName("Null to database") + void convertToDatabaseColumnWithNull() { + assertNull(converter.convertToDatabaseColumn(null)); + } + + @Test + @DisplayName("From database") + void convertToEntityAttributeWithValidCode() { + assertEquals(OpeningStatusEnum.APP, converter.convertToEntityAttribute("APP")); + } + + @Test + @DisplayName("Invalid code") + void convertToEntityAttributeWithInvalidCode() { + assertNull(converter.convertToEntityAttribute("INVALID")); + } + + @Test + @DisplayName("Null") + void convertToEntityAttributeWithNull() { + assertNull(converter.convertToEntityAttribute(null)); + } + +} \ No newline at end of file diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/enums/OpeningCategoryEnumTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/enums/OpeningCategoryEnumTest.java index b725e5e5..f71b0197 100644 --- a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/enums/OpeningCategoryEnumTest.java +++ b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/enums/OpeningCategoryEnumTest.java @@ -1,23 +1,65 @@ package ca.bc.gov.restapi.results.oracle.enums; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.stream.Stream; +import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +@DisplayName("Unit Test | OpeningCategoryEnum") class OpeningCategoryEnumTest { - @Test - void getByCodeTest() { - String code = "FTML"; - OpeningCategoryEnum ftml = OpeningCategoryEnum.of(code); - - Assertions.assertNotNull(ftml); - Assertions.assertEquals(ftml, OpeningCategoryEnum.FTML); - Assertions.assertEquals(code, ftml.getCode()); - Assertions.assertFalse(ftml.getDescription().isBlank()); + @DisplayName("Test enum conversion") + @ParameterizedTest(name = "Test enum conversion for code {0} and description {1}") + @MethodSource("enumConversion") + void testEnumConversion(String code, String description, OpeningCategoryEnum expected) { + OpeningCategoryEnum actual = OpeningCategoryEnum.of(code); + assertEquals(expected, actual); + if (expected != null) { + assertEquals(expected.getCode(), actual.getCode()); + assertEquals(description, actual.getDescription()); + } } - @Test - void getByNonExistingCodeTest() { - Assertions.assertNull(OpeningCategoryEnum.of("RESULTS")); + private static Stream enumConversion() { + return Stream.of( + Arguments.of("CONT", "SP as a part of contractual agreement", OpeningCategoryEnum.CONT), + Arguments.of("EXCLU", "Openings excluded from Crown managed forests", OpeningCategoryEnum.EXCLU), + Arguments.of("FFTFLTC", "Forest For Tomorrow - Forestry Licence to Cut", OpeningCategoryEnum.FFTFLTC), + Arguments.of("FFTITSL", "Forest For Tomorrow - Innovative Timber Sale Licence", OpeningCategoryEnum.FFTITSL), + Arguments.of("FTCF", "Forest Tenure - Site Plan under Community Forest", OpeningCategoryEnum.FTCF), + Arguments.of("FTFSM", "Forest Tenure - Forest Stand Management FPC s.71", OpeningCategoryEnum.FTFSM), + Arguments.of("FTLEVY", "Forest Stand Levy under FSM Fund Reg.", OpeningCategoryEnum.FTLEVY), + Arguments.of("FTML", "Forest Tenure - Major Licensee", OpeningCategoryEnum.FTML), + Arguments.of("FTMSL", "Forest Tenure Ministry Silviculture Liability", OpeningCategoryEnum.FTMSL), + Arguments.of( + "FTNOLVY", + "Post April 1/09 blocks (1-5 ha) for which there is no opportunity within the appraisal" + + " manual to collect a levy.", + OpeningCategoryEnum.FTNOLVY), + Arguments.of("FTPI", "Forest Tenure - pilot agreement", OpeningCategoryEnum.FTPI), + Arguments.of("FTSBF", "Forest Tenure - Small Business Forest Enterprise Program", OpeningCategoryEnum.FTSBF), + Arguments.of("FTWL", "Forest Tenure - Woodlot: Site Plan", OpeningCategoryEnum.FTWL), + Arguments.of("NDAML", "Natural Disturbance - area-based Major Licensee", OpeningCategoryEnum.NDAML), + Arguments.of("NDCF", "Natural Disturbance - Community Forest", OpeningCategoryEnum.NDCF), + Arguments.of("NDVML", "Natural Disturbance - volume-based Major Licensee", OpeningCategoryEnum.NDVML), + Arguments.of("NDWL", "Natural Disturbance - Woodlot License", OpeningCategoryEnum.NDWL), + Arguments.of("NREQ", "Areas where SP/SMP's are not required by law", OpeningCategoryEnum.NREQ), + Arguments.of( + "SPEX", + "Areas with no reforestation or FG obligations and the area is exempt from a site plan" + + " requirement", + OpeningCategoryEnum.SPEX), + Arguments.of("UHRV", "Unauthorized Harvesting", OpeningCategoryEnum.UHRV), + Arguments.of(StringUtils.EMPTY, null, null), + Arguments.of(null, null, null), + Arguments.of(" ", null, null), + Arguments.of("ABC", null, null) + ); } } diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/enums/OpeningStatusEnumTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/enums/OpeningStatusEnumTest.java index ba0a8ca5..d04a21d4 100644 --- a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/enums/OpeningStatusEnumTest.java +++ b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/enums/OpeningStatusEnumTest.java @@ -1,23 +1,45 @@ package ca.bc.gov.restapi.results.oracle.enums; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import ca.bc.gov.restapi.results.common.enums.ForestClientStatusEnum; +import java.util.stream.Stream; +import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +@DisplayName("Unit Test | OpeningStatusEnum") class OpeningStatusEnumTest { - @Test - void getByCodeTest() { - String code = "APP"; - OpeningStatusEnum app = OpeningStatusEnum.of(code); - - Assertions.assertNotNull(app); - Assertions.assertEquals(app, OpeningStatusEnum.APP); - Assertions.assertEquals(code, app.getCode()); - Assertions.assertFalse(app.getDescription().isBlank()); + @DisplayName("Test enum conversion") + @ParameterizedTest(name = "Test enum conversion for code {0} and description {1}") + @MethodSource("enumConversion") + void testEnumConversion(String code, String description, OpeningStatusEnum expected) { + OpeningStatusEnum actual = OpeningStatusEnum.of(code); + assertEquals(expected, actual); + if (expected != null) { + assertEquals(expected.getCode(), actual.getCode()); + assertEquals(description, actual.getDescription()); + } } - @Test - void getByNonExistingCodeTest() { - Assertions.assertNull(OpeningStatusEnum.of("RESULTS")); + private static Stream enumConversion() { + return Stream.of( + Arguments.of("AMD", "Amended", OpeningStatusEnum.AMD), + Arguments.of("AMG", "Amalgamate", OpeningStatusEnum.AMG), + Arguments.of("APP", "Approved", OpeningStatusEnum.APP), + Arguments.of("DFT", "Draft", OpeningStatusEnum.DFT), + Arguments.of("FG", "Free Growing", OpeningStatusEnum.FG), + Arguments.of("RET", "Retired", OpeningStatusEnum.RET), + Arguments.of("SUB", "Submitted", OpeningStatusEnum.SUB), + Arguments.of(StringUtils.EMPTY, null, null), + Arguments.of(null, null, null), + Arguments.of(" ", null, null), + Arguments.of("ABC", null, null) + ); } } diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/CutBlockOpenAdminRepositoryIntegrationTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/CutBlockOpenAdminRepositoryIntegrationTest.java deleted file mode 100644 index c90a5c22..00000000 --- a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/CutBlockOpenAdminRepositoryIntegrationTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package ca.bc.gov.restapi.results.oracle.repository; - -import ca.bc.gov.restapi.results.extensions.AbstractTestContainerIntegrationTest; -import ca.bc.gov.restapi.results.oracle.entity.CutBlockOpenAdminEntity; -import java.util.List; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -@DisplayName("Integration Test | CutBlockOpenAdminRepository") -class CutBlockOpenAdminRepositoryIntegrationTest extends AbstractTestContainerIntegrationTest { - - @Autowired - private CutBlockOpenAdminRepository cutBlockOpenAdminRepository; - - @Test - @DisplayName("find all openings given a list of opening ids") - void findAllByOpeningIdIn() { - List openingIdList = List.of(101L, 102L); - - List cutBlocks = - cutBlockOpenAdminRepository.findAllByOpeningIdIn(openingIdList); - - Assertions.assertNotNull(cutBlocks); - Assertions.assertEquals(2, cutBlocks.size()); - } -} diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OpenCategoryCodeRepositoryIntegrationTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OpenCategoryCodeRepositoryIntegrationTest.java deleted file mode 100644 index fb1ed851..00000000 --- a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OpenCategoryCodeRepositoryIntegrationTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package ca.bc.gov.restapi.results.oracle.repository; - -import ca.bc.gov.restapi.results.extensions.AbstractTestContainerIntegrationTest; -import ca.bc.gov.restapi.results.oracle.entity.OpenCategoryCodeEntity; -import java.time.LocalDate; -import java.util.List; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.jdbc.Sql; - -class OpenCategoryCodeRepositoryIntegrationTest extends AbstractTestContainerIntegrationTest { - - @Autowired private OpenCategoryCodeRepository openCategoryCodeRepository; - - @Test - @DisplayName("Find all by expiry date after happy path should succeed") - void findAllByExpiryDateAfter_happyPath_shouldSucceed() { - List list = - openCategoryCodeRepository.findAllByExpiryDateAfter(LocalDate.now()); - - Assertions.assertNotNull(list); - Assertions.assertEquals(22, list.size()); - - OpenCategoryCodeEntity category = list.get(0); - Assertions.assertEquals("CONT", category.getCode()); - Assertions.assertEquals("SP as a part of contractual agreement", category.getDescription()); - Assertions.assertTrue(category.getExpiryDate().isAfter(LocalDate.now())); - } -} diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OpeningRepositoryIntegrationTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OpeningRepositoryIntegrationTest.java deleted file mode 100644 index b33bd96a..00000000 --- a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OpeningRepositoryIntegrationTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package ca.bc.gov.restapi.results.oracle.repository; - -import ca.bc.gov.restapi.results.extensions.AbstractTestContainerIntegrationTest; -import ca.bc.gov.restapi.results.oracle.entity.OpeningEntity; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; - -class OpeningRepositoryIntegrationTest extends AbstractTestContainerIntegrationTest { - - @Autowired - private OpeningRepository openingRepository; - - @Test - @DisplayName("Finds all openings by entry user ID") - void findAllByEntryUserIdTest() { - String entryUserId = "idir-here"; - Pageable pageable = PageRequest.of(0, 5); - - Page openingPage = openingRepository.findAllByEntryUserId(entryUserId, pageable); - - Assertions.assertNotNull(openingPage.getContent()); - Assertions.assertEquals(1, openingPage.getContent().size()); - Assertions.assertEquals(entryUserId, openingPage.getContent().get(0).getEntryUserId()); - } -} diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OrgUnitRepositoryIntegrationTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OrgUnitRepositoryIntegrationTest.java deleted file mode 100644 index 324b32bf..00000000 --- a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OrgUnitRepositoryIntegrationTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package ca.bc.gov.restapi.results.oracle.repository; - -import ca.bc.gov.restapi.results.extensions.AbstractTestContainerIntegrationTest; -import ca.bc.gov.restapi.results.oracle.entity.OrgUnitEntity; -import java.time.LocalDate; -import java.util.List; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -class OrgUnitRepositoryIntegrationTest extends AbstractTestContainerIntegrationTest { - - @Autowired - private OrgUnitRepository orgUnitRepository; - - @Test - @DisplayName("Find all by org unit code unit in happy path should succeed") - void findAllByOrgUnitCodeIn_happyPath_shouldSucceed() { - List list = orgUnitRepository.findAllByOrgUnitCodeIn(List.of("DAS")); - - Assertions.assertNotNull(list); - Assertions.assertEquals(1, list.size()); - - OrgUnitEntity orgUnit = list.get(0); - Assertions.assertEquals(1L, orgUnit.getOrgUnitNo()); - Assertions.assertEquals("DAS", orgUnit.getOrgUnitCode()); - Assertions.assertEquals("Org one", orgUnit.getOrgUnitName()); - Assertions.assertEquals("001", orgUnit.getLocationCode()); - Assertions.assertEquals("AAA", orgUnit.getAreaCode()); - Assertions.assertEquals("1122334", orgUnit.getTelephoneNo()); - Assertions.assertEquals('H', orgUnit.getOrgLevelCode()); - Assertions.assertEquals("VI", orgUnit.getOfficeNameCode()); - Assertions.assertEquals(111L, orgUnit.getRollupRegionNo()); - Assertions.assertEquals("1Code", orgUnit.getRollupRegionCode()); - Assertions.assertEquals(222L, orgUnit.getRollupDistNo()); - Assertions.assertEquals("22Code", orgUnit.getRollupDistCode()); - Assertions.assertTrue(orgUnit.getEffectiveDate().isBefore(LocalDate.now())); - Assertions.assertTrue(orgUnit.getExpiryDate().isAfter(LocalDate.now())); - } -} diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/CutBlockOpenAdminServiceTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/CutBlockOpenAdminServiceTest.java index a23c8ef7..cd14a33e 100644 --- a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/CutBlockOpenAdminServiceTest.java +++ b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/CutBlockOpenAdminServiceTest.java @@ -1,45 +1,38 @@ package ca.bc.gov.restapi.results.oracle.service; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - +import ca.bc.gov.restapi.results.extensions.AbstractTestContainerIntegrationTest; import ca.bc.gov.restapi.results.oracle.entity.CutBlockOpenAdminEntity; -import ca.bc.gov.restapi.results.oracle.repository.CutBlockOpenAdminRepository; import java.util.List; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith(SpringExtension.class) -class CutBlockOpenAdminServiceTest { +import org.springframework.beans.factory.annotation.Autowired; - @Mock CutBlockOpenAdminRepository cutBlockOpenAdminRepository; +@DisplayName("Integrated Test | CutBlockOpenAdminService") +class CutBlockOpenAdminServiceTest extends AbstractTestContainerIntegrationTest { + @Autowired private CutBlockOpenAdminService cutBlockOpenAdminService; - @BeforeEach - void setup() { - cutBlockOpenAdminService = new CutBlockOpenAdminService(cutBlockOpenAdminRepository); - } - @Test @DisplayName("Find all openings by opening id list") void findAllByOpeningIdIn_simpleFetch_shouldSucceed() { - Long openingId = 12563L; - CutBlockOpenAdminEntity entity = new CutBlockOpenAdminEntity(); - entity.setId(123L); - entity.setOpeningId(openingId); - - when(cutBlockOpenAdminRepository.findAllByOpeningIdIn(any())).thenReturn(List.of(entity)); List entityList = - cutBlockOpenAdminService.findAllByOpeningIdIn(List.of(openingId)); + cutBlockOpenAdminService.findAllByOpeningIdIn(List.of(101L)); Assertions.assertNotNull(entityList); Assertions.assertEquals(1, entityList.size()); } + + @Test + @DisplayName("Find no openings by opening id list") + void findAllByOpeningIdIn_simpleFetch_shouldEmpty() { + + List entityList = + cutBlockOpenAdminService.findAllByOpeningIdIn(List.of(192L)); + + Assertions.assertNotNull(entityList); + Assertions.assertEquals(0, entityList.size()); + } } diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/OpenCategoryCodeServiceTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/OpenCategoryCodeServiceTest.java index 8a2561df..d221bd79 100644 --- a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/OpenCategoryCodeServiceTest.java +++ b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/OpenCategoryCodeServiceTest.java @@ -1,71 +1,38 @@ package ca.bc.gov.restapi.results.oracle.service; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - +import ca.bc.gov.restapi.results.extensions.AbstractTestContainerIntegrationTest; import ca.bc.gov.restapi.results.oracle.entity.OpenCategoryCodeEntity; -import ca.bc.gov.restapi.results.oracle.repository.OpenCategoryCodeRepository; import java.time.LocalDate; import java.util.List; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith(SpringExtension.class) -class OpenCategoryCodeServiceTest { +import org.springframework.beans.factory.annotation.Autowired; - @Mock OpenCategoryCodeRepository openCategoryCodeRepository; +@DisplayName("Integrated Test | Open Category Code Service") +class OpenCategoryCodeServiceTest extends AbstractTestContainerIntegrationTest { + @Autowired private OpenCategoryCodeService openCategoryCodeService; - @BeforeEach - void setup() { - openCategoryCodeService = new OpenCategoryCodeService(openCategoryCodeRepository); - } - @Test @DisplayName("Find all categories include expired false should succeed") void findAllCategories_includeExpiredFalse_shouldSucceed() { - OpenCategoryCodeEntity category = new OpenCategoryCodeEntity(); - category.setCode("FTML"); - category.setDescription("Free Growing"); - category.setEffectiveDate(LocalDate.now().minusYears(3L)); - category.setExpiryDate(LocalDate.now().plusYears(3L)); - category.setUpdateTimestamp(LocalDate.now()); - when(openCategoryCodeRepository.findAllByExpiryDateAfter(any())).thenReturn(List.of(category)); List entities = openCategoryCodeService.findAllCategories(false); Assertions.assertNotNull(entities); - Assertions.assertEquals(1, entities.size()); + Assertions.assertEquals(22, entities.size()); Assertions.assertTrue(entities.get(0).getExpiryDate().isAfter(LocalDate.now())); - - verify(openCategoryCodeRepository, times(0)).findAll(); } @Test @DisplayName("Find all categories include expired true should succeed") void findAllCategories_includeExpiredTrue_shouldSucceed() { - OpenCategoryCodeEntity category = new OpenCategoryCodeEntity(); - category.setCode("FTML"); - category.setDescription("Free Growing"); - category.setEffectiveDate(LocalDate.now().minusYears(3L)); - category.setExpiryDate(LocalDate.now().minusYears(1L)); - category.setUpdateTimestamp(LocalDate.now()); - - when(openCategoryCodeRepository.findAll()).thenReturn(List.of(category)); List entities = openCategoryCodeService.findAllCategories(true); Assertions.assertNotNull(entities); - Assertions.assertEquals(1, entities.size()); + Assertions.assertEquals(39, entities.size()); Assertions.assertTrue(entities.get(0).getExpiryDate().isBefore(LocalDate.now())); - - verify(openCategoryCodeRepository, times(0)).findAllByExpiryDateAfter(any()); } } diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/postgres/repository/OpeningsLastYearRepositoryIntegrationTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/postgres/repository/OpeningsLastYearRepositoryIntegrationTest.java index 7474da18..d4c1ec5f 100644 --- a/backend/src/test/java/ca/bc/gov/restapi/results/postgres/repository/OpeningsLastYearRepositoryIntegrationTest.java +++ b/backend/src/test/java/ca/bc/gov/restapi/results/postgres/repository/OpeningsLastYearRepositoryIntegrationTest.java @@ -18,7 +18,7 @@ class OpeningsLastYearRepositoryIntegrationTest extends AbstractTestContainerInt void findAllByOpeningIdIsInTest() { List idList = List.of(7012511L, 7012512L, 7012513L); List openingList = - openingsLastYearRepository.findAllByOpeningIdInList(idList); + openingsLastYearRepository.findAllByOpeningIdIn(idList); Assertions.assertFalse(openingList.isEmpty()); Assertions.assertEquals(3, openingList.size()); diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/postgres/service/UserOpeningServiceTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/postgres/service/UserOpeningServiceTest.java index 0666a3a5..89bbcc27 100644 --- a/backend/src/test/java/ca/bc/gov/restapi/results/postgres/service/UserOpeningServiceTest.java +++ b/backend/src/test/java/ca/bc/gov/restapi/results/postgres/service/UserOpeningServiceTest.java @@ -63,7 +63,7 @@ void getUserTrackedOpenings_happyPath_shouldSucceed() { openingEntity.setLastUpdated(now); openingEntity.setEntryUserid(USER_ID); - when(openingsActivityRepository.findAllByOpeningId(List.of(223344L))) + when(openingsActivityRepository.findAllByOpeningIdIn(List.of(223344L))) .thenReturn(List.of(openingEntity)); List openings = userOpeningService.getUserTrackedOpenings();