diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/dto/OpeningSearchResponseDto.java b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/dto/OpeningSearchResponseDto.java index 64289f98..7056fc5a 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/dto/OpeningSearchResponseDto.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/dto/OpeningSearchResponseDto.java @@ -128,7 +128,7 @@ Identifier for a cut block of a harvesting tenure (within a cutting permit for private Boolean submittedToFrpa; @Schema(description = "Uniquely identifies the attached file.", example = "407") - private Integer fileId; + private String forestFileId; @Schema( description = "Uniquely identifies an Application for Relief from obligations.", diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningSearchEndpoint.java b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningSearchEndpoint.java index 0458c937..fbf57546 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningSearchEndpoint.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningSearchEndpoint.java @@ -83,8 +83,8 @@ public PaginatedResult openingSearch( in = ParameterIn.QUERY, description = "Search term representing one of Opening ID | Opening Number | Timber Mark ID |" - + " File ID. E.g.: Opening ID 1022833, Opening Number 1012, Timber Mark" - + " EM2184, File ID 407", + + " Forest File ID. Eg: Opening ID 1022833, Opening Number 1012, Timber Mark" + + " EM2184, Forest File ID TFL47", required = false) String mainSearchTerm, @RequestParam(value = "orgUnit", required = 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 bb9ff576..5bd14122 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 @@ -1,5 +1,6 @@ package ca.bc.gov.restapi.results.oracle.repository; +import ca.bc.gov.restapi.results.common.config.ConstantsConfig; 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.dto.OpeningSearchFiltersDto; @@ -40,8 +41,8 @@ public PaginatedResult searchOpeningQuery( final String sqlQuery = createNativeSqlQuery(filtersDto); final Query query = setQueryParameters(filtersDto, sqlQuery); - // Limit to 100 records at the database - query.setMaxResults(100); + // Limit to 500 records at the database + query.setMaxResults(ConstantsConfig.MAX_PAGE_SIZE); List result = query.getResultList(); int lastPage = PaginationUtil.getLastPage(result.size(), pagination.perPage()); @@ -129,8 +130,8 @@ private List buildResultListDto(List result) { } if (row.length > 9) { - Integer fileId = getValue(Integer.class, row[9], "fileId"); - searchOpeningDto.setFileId(fileId); + String forestFileId = getValue(String.class, row[9], "forestFileId"); + searchOpeningDto.setForestFileId(forestFileId); } if (row.length > 10) { @@ -239,7 +240,7 @@ private Query setQueryParameters(OpeningSearchFiltersDto filtersDto, String nati query.setParameter("openingOrFile", filtersDto.getMainSearchTerm()); } else { log.info("Setting mainSearchTerm as non-numeric filter value"); - // Opening number or Timber Mark + // Opening number, Timber Mark, or Forest File Id query.setParameter("numberOrTimber", filtersDto.getMainSearchTerm()); } } @@ -324,7 +325,7 @@ private String createNativeSqlQuery(OpeningSearchFiltersDto filtersDto) { builder.append(",cboa.CUT_BLOCK_ID AS cutBlockId"); builder.append(",cboa.OPENING_GROSS_AREA AS openingGrossArea"); builder.append(",cboa.DISTURBANCE_START_DATE AS disturbanceStartDate"); - builder.append(",oa.OPENING_ATTACHMENT_FILE_ID AS fileId"); + builder.append(",cboa.FOREST_FILE_ID AS forestFileId"); builder.append(",ou.ORG_UNIT_CODE AS orgUnitCode"); builder.append(",ou.ORG_UNIT_NAME AS orgUnitName"); builder.append(",res.CLIENT_NUMBER AS clientNumber"); @@ -343,7 +344,6 @@ private String createNativeSqlQuery(OpeningSearchFiltersDto filtersDto) { builder.append(",o.ENTRY_USERID AS entryUserId"); builder.append(",COALESCE(sra.SILV_RELIEF_APPLICATION_ID, 0) AS submittedToFrpa108 "); builder.append("FROM THE.OPENING o "); - builder.append("LEFT JOIN THE.OPENING_ATTACHMENT oa ON (oa.OPENING_ID = o.OPENING_ID)"); builder.append("LEFT JOIN THE.CUT_BLOCK_OPEN_ADMIN cboa ON (cboa.OPENING_ID = o.OPENING_ID)"); builder.append("LEFT JOIN THE.ORG_UNIT ou ON (ou.ORG_UNIT_NO = o.ADMIN_DISTRICT_NO)"); builder.append("LEFT JOIN the.RESULTS_ELECTRONIC_SUBMISSION res ON ("); @@ -370,15 +370,18 @@ private String createNativeSqlQuery(OpeningSearchFiltersDto filtersDto) { log.info("Filter mainSearchTerm detected! mainSearchTerm={}", filtersDto.getMainSearchTerm()); boolean itsNumeric = filtersDto.getMainSearchTerm().replaceAll("[0-9]", "").isEmpty(); if (itsNumeric) { - log.info("Filter mainSearchTerm it's numeric! Looking for Opening ID or File ID"); - // Opening id or File id - builder.append("AND (o.OPENING_ID = :openingOrFile or "); - builder.append("oa.OPENING_ATTACHMENT_FILE_ID = :openingOrFile) "); + log.info("Filter mainSearchTerm it's numeric! Looking for Opening ID"); + // Opening id + builder.append("AND o.OPENING_ID = :openingOrFile "); } else { - log.info("Filter mainSearchTerm NOT numeric! Looking for Opening Number or Timber Mark"); - // Opening number or Timber Mark - builder.append( - "AND (o.OPENING_NUMBER = :numberOrTimber or cboa.TIMBER_MARK = :numberOrTimber) "); + log.info( + "Filter mainSearchTerm NOT numeric! Looking for Opening Number, Timber Mark, or Forest" + + " File Id"); + // Opening number, Timber Mark, or Forest File Id + builder.append("AND ("); + builder.append("o.OPENING_NUMBER = :numberOrTimber "); + builder.append(" or cboa.TIMBER_MARK = :numberOrTimber "); + builder.append(" or cboa.FOREST_FILE_ID = :numberOrTimber)"); } } @@ -468,6 +471,34 @@ private String createNativeSqlQuery(OpeningSearchFiltersDto filtersDto) { builder.append("AND o.UPDATE_TIMESTAMP <= to_timestamp(:updateEndDate, 'YYYY-MM-DD') "); } + /* Group by - to avoid duplications */ + builder.append("GROUP BY o.OPENING_ID "); + builder.append(",o.OPENING_NUMBER "); + builder.append(",o.OPEN_CATEGORY_CODE "); + builder.append(",o.OPENING_STATUS_CODE "); + builder.append(",cboa.CUTTING_PERMIT_ID "); + builder.append(",cboa.TIMBER_MARK "); + builder.append(",cboa.CUT_BLOCK_ID "); + builder.append(",cboa.OPENING_GROSS_AREA "); + builder.append(",cboa.DISTURBANCE_START_DATE "); + builder.append(",cboa.FOREST_FILE_ID "); + builder.append(",ou.ORG_UNIT_CODE "); + builder.append(",ou.ORG_UNIT_NAME "); + builder.append(",res.CLIENT_NUMBER "); + + sql = ",ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMRG.LATE_OFFSET_YEARS, 0) * 12)) "; + builder.append(sql); + + sql = ",ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMFG.EARLY_OFFSET_YEARS, 0) * 12)) "; + builder.append(sql); + + sql = ",ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMFG.LATE_OFFSET_YEARS, 0) * 12)) "; + builder.append(sql); + + builder.append(",o.UPDATE_TIMESTAMP "); + builder.append(",o.ENTRY_USERID "); + builder.append(",COALESCE(sra.SILV_RELIEF_APPLICATION_ID, 0) "); + // Order by builder.append("ORDER BY o.OPENING_ID DESC"); diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningSearchEndpointTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningSearchEndpointTest.java index 051b54f4..048218dc 100644 --- a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningSearchEndpointTest.java +++ b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningSearchEndpointTest.java @@ -73,7 +73,7 @@ void openingSearch_happyPath_shouldSucceed() throws Exception { response.setEntryUserId("TEST"); response.setSubmittedToFrpa(true); response.setSilvaReliefAppId(333L); - response.setFileId(407); + response.setForestFileId("TFL47"); paginatedResult.setData(List.of(response)); @@ -100,7 +100,7 @@ void openingSearch_happyPath_shouldSucceed() throws Exception { .andExpect(jsonPath("$.data[0].openingGrossAreaHa").value(response.getOpeningGrossAreaHa())) .andExpect( jsonPath("$.data[0].disturbanceStartDate").value(response.getDisturbanceStartDate())) - .andExpect(jsonPath("$.data[0].fileId").value(response.getFileId())) + .andExpect(jsonPath("$.data[0].forestFileId").value(response.getForestFileId())) .andExpect(jsonPath("$.data[0].orgUnitCode").value(response.getOrgUnitCode())) .andExpect(jsonPath("$.data[0].orgUnitName").value(response.getOrgUnitName())) .andExpect(jsonPath("$.data[0].clientNumber").value(response.getClientNumber())) diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OpeningSearchRepositoryTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OpeningSearchRepositoryTest.java index 4f1d1671..96d7fc7a 100644 --- a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OpeningSearchRepositoryTest.java +++ b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/repository/OpeningSearchRepositoryTest.java @@ -301,7 +301,7 @@ void searchOpeningQuery_mainFilterNumeric_shouldSucceed() { String cutBlockId = null; BigDecimal openingGrossArea = new BigDecimal("11"); Timestamp disturbanceStartDate = Timestamp.valueOf(LocalDateTime.now()); - Integer fileId = 407; + String forestFileId = "TFL47"; String orgUnitCode = null; String orgUnitName = null; String clientNumber = null; @@ -323,7 +323,7 @@ void searchOpeningQuery_mainFilterNumeric_shouldSucceed() { cutBlockId, openingGrossArea, disturbanceStartDate, - fileId, + forestFileId, orgUnitCode, orgUnitName, clientNumber, @@ -356,7 +356,7 @@ void searchOpeningQuery_mainFilterNumeric_shouldSucceed() { Assertions.assertEquals(cutBlockId, dto.getCutBlockId()); Assertions.assertEquals(openingGrossArea, dto.getOpeningGrossAreaHa()); Assertions.assertEquals(disturbanceStartDate.toLocalDateTime(), dto.getDisturbanceStartDate()); - Assertions.assertEquals(fileId, dto.getFileId()); + Assertions.assertEquals(forestFileId, dto.getForestFileId()); Assertions.assertEquals(orgUnitCode, dto.getOrgUnitCode()); Assertions.assertEquals(orgUnitName, dto.getOrgUnitName()); Assertions.assertEquals(clientNumber, dto.getClientNumber()); @@ -386,7 +386,7 @@ void searchOpeningQuery_mainFilterString_shouldSucceed() { BigDecimal openingGrossArea = new BigDecimal("11"); Timestamp disturbanceStartDate = Timestamp.valueOf(LocalDateTime.now()); ; - Integer fileId = 407; + String forestFileId = "TFL47"; String orgUnitCode = null; String orgUnitName = null; String clientNumber = null; @@ -408,7 +408,7 @@ void searchOpeningQuery_mainFilterString_shouldSucceed() { cutBlockId, openingGrossArea, disturbanceStartDate, - fileId, + forestFileId, orgUnitCode, orgUnitName, clientNumber, @@ -441,7 +441,7 @@ void searchOpeningQuery_mainFilterString_shouldSucceed() { Assertions.assertEquals(cutBlockId, dto.getCutBlockId()); Assertions.assertEquals(openingGrossArea, dto.getOpeningGrossAreaHa()); Assertions.assertEquals(disturbanceStartDate.toLocalDateTime(), dto.getDisturbanceStartDate()); - Assertions.assertEquals(fileId, dto.getFileId()); + Assertions.assertEquals(forestFileId, dto.getForestFileId()); Assertions.assertEquals(orgUnitCode, dto.getOrgUnitCode()); Assertions.assertEquals(orgUnitName, dto.getOrgUnitName()); Assertions.assertEquals(clientNumber, dto.getClientNumber()); @@ -469,7 +469,7 @@ void searchOpeningQuery_orgUnitFilter_shouldSucceed() { String cutBlockId = null; BigDecimal openingGrossArea = new BigDecimal("11"); Timestamp disturbanceStartDate = Timestamp.valueOf(LocalDateTime.now()); - Integer fileId = 407; + String forestFileId = "TFL47"; String orgUnitCode = "DCR"; String orgUnitName = null; String clientNumber = null; @@ -491,7 +491,7 @@ void searchOpeningQuery_orgUnitFilter_shouldSucceed() { cutBlockId, openingGrossArea, disturbanceStartDate, - fileId, + forestFileId, orgUnitCode, orgUnitName, clientNumber, @@ -524,7 +524,7 @@ void searchOpeningQuery_orgUnitFilter_shouldSucceed() { Assertions.assertEquals(cutBlockId, dto.getCutBlockId()); Assertions.assertEquals(openingGrossArea, dto.getOpeningGrossAreaHa()); Assertions.assertEquals(disturbanceStartDate.toLocalDateTime(), dto.getDisturbanceStartDate()); - Assertions.assertEquals(fileId, dto.getFileId()); + Assertions.assertEquals(forestFileId, dto.getForestFileId()); Assertions.assertEquals(orgUnitCode, dto.getOrgUnitCode()); Assertions.assertEquals(orgUnitName, dto.getOrgUnitName()); Assertions.assertEquals(clientNumber, dto.getClientNumber()); @@ -552,7 +552,7 @@ void searchOpeningQuery_allFilters_shouldSucceed() { String cutBlockId = "456"; BigDecimal openingGrossArea = new BigDecimal("11"); Timestamp disturbanceStartDate = Timestamp.valueOf(LocalDateTime.now()); - Integer fileId = 407; + String forestFileId = "TFL47"; String orgUnitCode = filters.getOrgUnit(); String orgUnitName = "Org Name"; String clientNumber = "00012797"; @@ -574,7 +574,7 @@ void searchOpeningQuery_allFilters_shouldSucceed() { cutBlockId, openingGrossArea, disturbanceStartDate, - fileId, + forestFileId, orgUnitCode, orgUnitName, clientNumber, @@ -607,7 +607,7 @@ void searchOpeningQuery_allFilters_shouldSucceed() { Assertions.assertEquals(cutBlockId, dto.getCutBlockId()); Assertions.assertEquals(openingGrossArea, dto.getOpeningGrossAreaHa()); Assertions.assertEquals(disturbanceStartDate.toLocalDateTime(), dto.getDisturbanceStartDate()); - Assertions.assertEquals(fileId, dto.getFileId()); + Assertions.assertEquals(forestFileId, dto.getForestFileId()); Assertions.assertEquals(orgUnitCode, dto.getOrgUnitCode()); Assertions.assertEquals(orgUnitName, dto.getOrgUnitName()); Assertions.assertEquals(clientNumber, dto.getClientNumber()); diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/OpeningServiceTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/OpeningServiceTest.java index 56d0e9e6..98973878 100644 --- a/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/OpeningServiceTest.java +++ b/backend/src/test/java/ca/bc/gov/restapi/results/oracle/service/OpeningServiceTest.java @@ -271,7 +271,7 @@ void openingSearch_fileId_shouldSucceed() { dto.setUpdateTimestamp(LocalDateTime.now()); dto.setEntryUserId(""); dto.setSubmittedToFrpa(false); - dto.setFileId(407); + dto.setForestFileId("TFL47"); paginated.setData(List.of(dto)); OpeningSearchFiltersDto filters = mockMainFilter("407"); @@ -296,7 +296,7 @@ void openingSearch_fileId_shouldSucceed() { dto.getOpeningGrossAreaHa(), result.getData().get(0).getOpeningGrossAreaHa()); Assertions.assertEquals( dto.getDisturbanceStartDate(), result.getData().get(0).getDisturbanceStartDate()); - Assertions.assertEquals(dto.getFileId(), result.getData().get(0).getFileId()); + Assertions.assertEquals(dto.getForestFileId(), result.getData().get(0).getForestFileId()); Assertions.assertEquals(dto.getOrgUnitCode(), result.getData().get(0).getOrgUnitCode()); Assertions.assertEquals(dto.getOrgUnitName(), result.getData().get(0).getOrgUnitName()); Assertions.assertEquals(dto.getClientNumber(), result.getData().get(0).getClientNumber()); @@ -340,7 +340,7 @@ void openingSearch_orgUnit_shouldSucceed() { dto.setUpdateTimestamp(LocalDateTime.now()); dto.setEntryUserId(""); dto.setSubmittedToFrpa(false); - dto.setFileId(407); + dto.setForestFileId("TFL47"); paginated.setData(List.of(dto)); OpeningSearchFiltersDto filters = mockOrgUnit("DCR"); @@ -365,7 +365,7 @@ void openingSearch_orgUnit_shouldSucceed() { dto.getOpeningGrossAreaHa(), result.getData().get(0).getOpeningGrossAreaHa()); Assertions.assertEquals( dto.getDisturbanceStartDate(), result.getData().get(0).getDisturbanceStartDate()); - Assertions.assertEquals(dto.getFileId(), result.getData().get(0).getFileId()); + Assertions.assertEquals(dto.getForestFileId(), result.getData().get(0).getForestFileId()); Assertions.assertEquals(dto.getOrgUnitCode(), result.getData().get(0).getOrgUnitCode()); Assertions.assertEquals(dto.getOrgUnitName(), result.getData().get(0).getOrgUnitName()); Assertions.assertEquals(dto.getClientNumber(), result.getData().get(0).getClientNumber());