Skip to content

Commit 6295392

Browse files
authored
feat(#971): integrate forest cover history backend with frontend (#1027)
1 parent 42b0c89 commit 6295392

18 files changed

Lines changed: 1009 additions & 193 deletions

File tree

backend/src/main/java/ca/bc/gov/restapi/results/oracle/SilvaOracleQueryConstants.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,16 @@ SELECT MAX(ols2.OPENING_LAND_STATUS_DATE)
13311331
)
13321332
THEN 'true'
13331333
ELSE 'false'
1334-
END AS IS_CURRENT_HISTORY
1334+
END AS IS_CURRENT,
1335+
CASE
1336+
WHEN ols.OPENING_LAND_STATUS_DATE = (
1337+
SELECT MIN(ols2.OPENING_LAND_STATUS_DATE)
1338+
FROM THE.OPENING_LAND_STATUS ols2
1339+
WHERE ols2.OPENING_ID = ols.OPENING_ID
1340+
)
1341+
THEN 'true'
1342+
ELSE 'false'
1343+
END AS IS_OLDEST
13351344
FROM THE.OPENING_LAND_STATUS ols
13361345
LEFT JOIN fca_deduped fca
13371346
ON ols.OPENING_ID = fca.OPENING_ID
@@ -1399,6 +1408,25 @@ LEFT JOIN (
13991408
WHERE
14001409
fc.OPENING_ID = :openingId
14011410
AND TRUNC(fc.UPDATE_TIMESTAMP) = TO_DATE(:updateDate, 'YYYY-MM-DD')
1411+
AND (
1412+
NVL(:mainSearchTerm,'NOVALUE') = 'NOVALUE'
1413+
OR (
1414+
fc.SILV_POLYGON_NO LIKE '%' || :mainSearchTerm || '%'
1415+
OR ssu.STANDARDS_UNIT_ID LIKE '%' || :mainSearchTerm || '%'
1416+
OR UPPER(stcnma.DESCRIPTION) LIKE '%' || :mainSearchTerm || '%'
1417+
OR fcnma.STOCKING_TYPE_CODE LIKE '%' || :mainSearchTerm || '%'
1418+
OR fc.STOCKING_STATUS_CODE LIKE '%' || :mainSearchTerm || '%'
1419+
OR UPPER(ssc.DESCRIPTION) LIKE '%' || :mainSearchTerm || '%'
1420+
OR fc.STOCKING_TYPE_CODE LIKE '%' || :mainSearchTerm || '%'
1421+
OR UPPER(stc.DESCRIPTION) LIKE '%' || :mainSearchTerm || '%'
1422+
OR (REGEXP_LIKE(:mainSearchTerm, '^\\d+(\\.\\d+)?$')
1423+
AND fc.SILV_POLYGON_AREA = TO_NUMBER(:mainSearchTerm DEFAULT 0 ON CONVERSION ERROR, '999999.999999'))
1424+
OR (REGEXP_LIKE(:mainSearchTerm, '^\\d+(\\.\\d+)?$')
1425+
AND fc.SILV_POLYGON_NET_AREA = TO_NUMBER(:mainSearchTerm DEFAULT 0 ON CONVERSION ERROR, '999999.999999'))
1426+
OR (REGEXP_LIKE(:mainSearchTerm, '^\\d+(\\.\\d+)?$')
1427+
AND fc.REFERENCE_YEAR = TO_NUMBER(:mainSearchTerm DEFAULT 0 ON CONVERSION ERROR, '999999.999999'))
1428+
)
1429+
)
14021430
""";
14031431

14041432
public static final String GET_OPENING_FOREST_COVER_HISTORY_LIST_SPECIES =

backend/src/main/java/ca/bc/gov/restapi/results/oracle/dto/cover/history/OpeningForestCoverHistoryOverviewDto.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@ public record OpeningForestCoverHistoryOverviewDto(
2727
boolean hasDetails,
2828

2929
@Schema(types = {"boolean"}, requiredMode = Schema.RequiredMode.REQUIRED)
30-
boolean isCurrentHistory) {
31-
}
30+
boolean isCurrent,
31+
32+
@Schema(types = {"boolean"}, requiredMode = Schema.RequiredMode.REQUIRED)
33+
boolean isOldest)
34+
{}

backend/src/main/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningEndpoint.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ca.bc.gov.restapi.results.oracle.endpoint;
22

3+
import ca.bc.gov.restapi.results.common.exception.NotFoundGenericException;
34
import ca.bc.gov.restapi.results.common.exception.OpeningNotFoundException;
45
import ca.bc.gov.restapi.results.oracle.dto.activity.OpeningActivityBaseDto;
56
import ca.bc.gov.restapi.results.oracle.dto.cover.OpeningForestCoverDetailsDto;
@@ -130,24 +131,52 @@ public OpeningForestCoverDetailsDto getCoverDetails(
130131
return openingService.getOpeningForestCoverDetails(forestCoverId);
131132
}
132133

134+
/**
135+
* Retrieves the forest cover history overview for a given opening.
136+
*
137+
* @param openingId the ID of the opening
138+
* @return a list of {@link OpeningForestCoverHistoryOverviewDto} representing the forest cover history overview
139+
* @throws NotFoundGenericException if no overview is found for the given opening ID
140+
*/
133141
@GetMapping("/{openingId}/cover/history/overview")
134142
public List<OpeningForestCoverHistoryOverviewDto> getCoverHistoryOverview(
135-
@PathVariable Long openingId) {
143+
@PathVariable Long openingId) throws NotFoundGenericException {
136144
return openingService.getOpeningForestCoverHistoryOverviewList(openingId);
137145
}
138146

147+
/**
148+
* Retrieves the forest cover history for a given opening and update date, optionally filtered by a search term.
149+
*
150+
* @param openingId the ID of the opening
151+
* @param updateDate the update date to filter history (required, format: yyyy-MM-dd)
152+
* @param mainSearchTerm an optional search term to filter results
153+
* @return a list of {@link OpeningForestCoverHistoryDto} representing the forest cover history
154+
* @throws NotFoundGenericException if no history is found for the given parameters
155+
*/
139156
@GetMapping("/{openingId}/cover/history")
140157
public List<OpeningForestCoverHistoryDto> getCoverHistory(
141158
@PathVariable Long openingId,
142-
@RequestParam(name = "updateDate", required = true) String updateDate) {
143-
return openingService.getOpeningForestCoverHistoryList(openingId, updateDate);
159+
@RequestParam(name = "updateDate", required = true) String updateDate,
160+
@RequestParam(name = "mainSearchTerm", required = false) String mainSearchTerm)
161+
throws NotFoundGenericException {
162+
return openingService.getOpeningForestCoverHistoryList(openingId, updateDate, mainSearchTerm);
144163
}
145164

165+
/**
166+
* Retrieves the details of a specific forest cover history entry for a given opening, forest cover ID, and archive date.
167+
*
168+
* @param openingId the ID of the opening
169+
* @param forestCoverId the ID of the forest cover
170+
* @param archiveDate the archive date of the forest cover history (required, format: yyyy-MM-dd)
171+
* @return the {@link OpeningForestCoverHistoryDetailsDto} containing detailed information
172+
* @throws NotFoundGenericException if no details are found for the given parameters
173+
*/
146174
@GetMapping("/{openingId}/cover/history/{forestCoverId}")
147175
public OpeningForestCoverHistoryDetailsDto getForestCoverHistoryDetails(
148176
@PathVariable Long openingId,
149177
@PathVariable Long forestCoverId,
150-
@RequestParam(name = "archiveDate", required = true) String archiveDate) {
178+
@RequestParam(name = "archiveDate", required = true) String archiveDate)
179+
throws NotFoundGenericException {
151180
return openingService.getOpeningForestCoverHistoryDetails(forestCoverId, archiveDate);
152181
}
153182

backend/src/main/java/ca/bc/gov/restapi/results/oracle/entity/cover/history/ForestCoverHistoryOverviewProjection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ public interface ForestCoverHistoryOverviewProjection {
1111
Double getOther();
1212
Double getTotal();
1313
Boolean getHasDetails();
14-
Boolean getIsCurrentHistory();
14+
Boolean getIsCurrent();
15+
Boolean getIsOldest();
1516
}

backend/src/main/java/ca/bc/gov/restapi/results/oracle/repository/ForestCoverEntityRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public interface ForestCoverEntityRepository extends JpaRepository<ForestCoverEn
4545
List<ForestCoverHistoryOverviewProjection> findHistoryOverviewByOpeningId(Long openingId);
4646

4747
@Query(nativeQuery = true, value = SilvaOracleQueryConstants.GET_OPENING_FOREST_COVER_HISTORY_LIST)
48-
List<ForestCoverHistoryProjection> findHistoryByOpeningDetails(Long openingId, String updateDate);
48+
List<ForestCoverHistoryProjection> findHistoryByOpeningDetails(Long openingId, String updateDate, String mainSearchTerm);
4949

5050
@Query(nativeQuery = true, value = SilvaOracleQueryConstants.GET_OPENING_FOREST_COVER_HISTORY_LIST_SPECIES)
5151
List<ForestCoverHistorySpeciesProjection> findHistoryByOpeningDetailsSpecies(

backend/src/main/java/ca/bc/gov/restapi/results/oracle/service/opening/details/OpeningDetailsService.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,25 @@ public OpeningForestCoverDetailsDto getOpeningForestCoverDetails(Long forestCove
124124
public List<OpeningForestCoverHistoryOverviewDto> getOpeningForestCoverHistoryOverviewList(
125125
Long openingId) {
126126
log.info("Fetching forest cover history overview list for opening ID: {}", openingId);
127-
return forestCoverHistoryService.getOpeningForestCoverHistoryOverviewList(openingId);
127+
128+
List<OpeningForestCoverHistoryOverviewDto> result = forestCoverHistoryService
129+
.getOpeningForestCoverHistoryOverviewList(openingId);
130+
131+
if (result.isEmpty()) {
132+
throw new NotFoundGenericException("Forest cover history overview list for opening with id " + openingId);
133+
}
134+
135+
return result;
128136
}
129137

130138
public List<OpeningForestCoverHistoryDto> getOpeningForestCoverHistoryList(
131-
Long openingId, String updateDate) {
139+
Long openingId, String updateDate, String mainSearchTerm) {
132140
log.info(
133141
"Fetching forest cover history list for opening ID: {} and update date: {}",
134142
openingId,
135143
updateDate);
136144
List<OpeningForestCoverHistoryDto> result =
137-
forestCoverHistoryService.getOpeningForestCoverList(openingId, updateDate);
145+
forestCoverHistoryService.getOpeningForestCoverList(openingId, updateDate, mainSearchTerm);
138146

139147
if (result.isEmpty()) {
140148
throw new NotFoundGenericException(

backend/src/main/java/ca/bc/gov/restapi/results/oracle/service/opening/history/OpeningForestCoverHistoryService.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
package ca.bc.gov.restapi.results.oracle.service.opening.history;
22

33
import ca.bc.gov.restapi.results.oracle.dto.CodeDescriptionDto;
4-
import ca.bc.gov.restapi.results.oracle.dto.cover.*;
54
import ca.bc.gov.restapi.results.oracle.dto.cover.history.*;
6-
import ca.bc.gov.restapi.results.oracle.entity.cover.ForestCoverPolygonProjection;
75
import ca.bc.gov.restapi.results.oracle.entity.cover.history.ForestCoverHistoryOverviewProjection;
86
import ca.bc.gov.restapi.results.oracle.entity.cover.history.ForestCoverHistoryPolygonProjection;
97
import ca.bc.gov.restapi.results.oracle.repository.ForestCoverEntityRepository;
10-
import ca.bc.gov.restapi.results.oracle.repository.OpeningRepository;
118
import lombok.RequiredArgsConstructor;
129
import lombok.extern.slf4j.Slf4j;
1310
import org.springframework.stereotype.Service;
1411
import org.springframework.util.CollectionUtils;
1512

13+
import java.util.Comparator;
1614
import java.util.List;
1715
import java.util.Optional;
1816
import java.util.function.Function;
@@ -34,9 +32,9 @@ public List<OpeningForestCoverHistoryOverviewDto> getOpeningForestCoverHistoryOv
3432
}
3533

3634
public List<OpeningForestCoverHistoryDto> getOpeningForestCoverList(
37-
Long openingId, String updateDate) {
35+
Long openingId, String updateDate, String mainSearchTerm) {
3836

39-
return coverRepository.findHistoryByOpeningDetails(openingId, updateDate).stream()
37+
return coverRepository.findHistoryByOpeningDetails(openingId, updateDate, mainSearchTerm).stream()
4038
.map(
4139
projection -> {
4240
boolean isSingleLayer =
@@ -83,6 +81,7 @@ public List<OpeningForestCoverHistoryDto> getOpeningForestCoverList(
8381
.withInventoryLayer(
8482
dto.inventoryLayer().withSpecies(getLayerSpecies(dto.coverId(), "I", projection.getArchiveDate().toString())));
8583
})
84+
.sorted(Comparator.comparingLong(OpeningForestCoverHistoryDto::coverId))
8685
.toList();
8786
}
8887

@@ -105,7 +104,8 @@ private Function<ForestCoverHistoryOverviewProjection, OpeningForestCoverHistory
105104
projection.getOther(),
106105
projection.getTotal(),
107106
projection.getHasDetails(),
108-
projection.getIsCurrentHistory()
107+
projection.getIsCurrent(),
108+
projection.getIsOldest()
109109
);
110110
}
111111

0 commit comments

Comments
 (0)