Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add free growing and regen delay filters #361

Merged
merged 4 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ jobs:
-p RESULTS_ENV_OPENSEARCH=production
-p AWS_COGNITO_ISSUER_URI=https://cognito-idp.${{ vars.AWS_REGION }}.amazonaws.com/${{ vars.VITE_USER_POOLS_ID }}
-p DASHBOARD_JOB_IDIR_USERS=${{ vars.DASHBOARD_JOB_IDIR_USERS }}
-p WMS_LAYERS_WHITELIST_USERS=${{ vars.WMS_LAYERS_WHITELIST_USERS }}
- name: frontend
file: frontend/openshift.deploy.yml
parameters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,13 @@ Identifier for a cut block of a harvesting tenure (within a cutting permit for
private String clientAcronym;

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

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

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

@Schema(description = "The date and time of the last update.")
private LocalDateTime updateTimestamp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,39 @@ private List<OpeningSearchResponseDto> buildResultListDto(List<?> result) {
searchOpeningDto.setClientNumber(clientNumber);
}

// HERE
if (row.length > 13) {
searchOpeningDto.setRegenDelayDate(getValue(String.class, row[13], "regenTemporary"));
Timestamp regenDelayDate = getValue(Timestamp.class, row[13], "regenDelayDate");
if (!Objects.isNull(regenDelayDate)) {
searchOpeningDto.setRegenDelayDate(regenDelayDate.toLocalDateTime());
}
}

// HERE
if (row.length > 14) {
searchOpeningDto.setFreeGrowingDate(getValue(String.class, row[14], "freeGrowTemporary"));
Timestamp earlyDate = getValue(Timestamp.class, row[14], "earlyFreeGrowingDate");
if (!Objects.isNull(earlyDate)) {
searchOpeningDto.setEarlyFreeGrowingDate(earlyDate.toLocalDateTime());
}
}

if (row.length > 15) {
Timestamp updateTimestamp = getValue(Timestamp.class, row[15], "updateTimestamp");
searchOpeningDto.setUpdateTimestamp(updateTimestamp.toLocalDateTime());
Timestamp dateDate = getValue(Timestamp.class, row[15], "lateFreeGrowingDate");
if (!Objects.isNull(dateDate)) {
searchOpeningDto.setLateFreeGrowingDate(dateDate.toLocalDateTime());
}
}

if (row.length > 16) {
String entryUserId = getValue(String.class, row[16], "entryUserId");
searchOpeningDto.setEntryUserId(entryUserId);
Timestamp updateTimestamp = getValue(Timestamp.class, row[16], "updateTimestamp");
searchOpeningDto.setUpdateTimestamp(updateTimestamp.toLocalDateTime());
}

if (row.length > 17) {
BigDecimal silvaReliefAppId = getValue(BigDecimal.class, row[17], "submittedToFrpa108");
String entryUserId = getValue(String.class, row[17], "entryUserId");
searchOpeningDto.setEntryUserId(entryUserId);
}

if (row.length > 18) {
BigDecimal silvaReliefAppId = getValue(BigDecimal.class, row[18], "submittedToFrpa108");
boolean submittedApp = silvaReliefAppId.compareTo(BigDecimal.ZERO) > 0;
searchOpeningDto.setSubmittedToFrpa(submittedApp);
if (submittedApp) {
Expand Down Expand Up @@ -270,19 +281,23 @@ private Query setQueryParameters(OpeningSearchFiltersDto filtersDto, String nati
}
// 8. Regen delay start date
if (filtersDto.hasValue(OpeningSearchFiltersDto.REGEN_DELAY_DATE_START)) {
log.info("Skipping filter regenDelayDateStart value. Filter not ready!");
log.info("Setting regenDelayDateStart filter value");
query.setParameter("regenDelayDateStart", filtersDto.getRegenDelayDateStart());
}
// 9. Regen delay end date
if (filtersDto.hasValue(OpeningSearchFiltersDto.REGEN_DELAY_DATE_END)) {
log.info("Skipping filter regenDelayDateEnd value. Filter not ready!");
log.info("Setting regenDelayDateEnd filter value");
query.setParameter("regenDelayDateEnd", filtersDto.getRegenDelayDateEnd());
}
// 10. Free growing start date
if (filtersDto.hasValue(OpeningSearchFiltersDto.FREE_GROWING_DATE_START)) {
log.info("Skipping filter freeGrowingDateStart value. Filter not ready!");
log.info("Setting freeGrowingDateStart filter value");
query.setParameter("freeGrowingDateStart", filtersDto.getFreeGrowingDateStart());
}
// 11. Free growing end date
if (filtersDto.hasValue(OpeningSearchFiltersDto.FREE_GROWING_DATE_END)) {
log.info("Skipping filter freeGrowingDateEnd value. Filter not ready!");
log.info("Setting freeGrowingDateEnd filter value");
query.setParameter("freeGrowingDateEnd", filtersDto.getFreeGrowingDateEnd());
}
// 12. Update date start
if (filtersDto.hasValue(OpeningSearchFiltersDto.UPDATE_DATE_START)) {
Expand Down Expand Up @@ -313,8 +328,17 @@ private String createNativeSqlQuery(OpeningSearchFiltersDto filtersDto) {
builder.append(",ou.ORG_UNIT_CODE AS orgUnitCode");
builder.append(",ou.ORG_UNIT_NAME AS orgUnitName");
builder.append(",res.CLIENT_NUMBER AS clientNumber");
builder.append(",'TDB' AS regenDelayDate");
builder.append(",'TBD' AS freeGrowingDate");

String sql;
sql = ",ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMRG.LATE_OFFSET_YEARS,0)*12))";
builder.append(sql).append(" AS regenDelayDate");

sql = ",ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMFG.EARLY_OFFSET_YEARS,0)*12))";
builder.append(sql).append(" AS earlyFreeGrowingDate");

sql = ",ADD_MONTHS(cboa.DISTURBANCE_START_DATE, (COALESCE(SMFG.LATE_OFFSET_YEARS,0)*12))";
builder.append(sql).append(" AS lateFreeGrowingDate");

builder.append(",o.UPDATE_TIMESTAMP AS updateTimestamp");
builder.append(",o.ENTRY_USERID AS entryUserId");
builder.append(",COALESCE(sra.SILV_RELIEF_APPLICATION_ID, 0) AS submittedToFrpa108 ");
Expand All @@ -328,7 +352,14 @@ private String createNativeSqlQuery(OpeningSearchFiltersDto filtersDto) {
builder.append("LEFT JOIN THE.ACTIVITY_TREATMENT_UNIT atu ON (atu.OPENING_ID = o.OPENING_ID)");
builder.append("LEFT JOIN THE.SILV_RELIEF_APPLICATION sra ON (");
builder.append(" sra.ACTIVITY_TREATMENT_UNIT_ID = atu.ACTIVITY_TREATMENT_UNIT_ID");
builder.append(" AND sra.SILV_RELIEF_APPL_STATUS_CODE = 'APP')");
builder.append(" AND sra.SILV_RELIEF_APPL_STATUS_CODE = 'APP') ");
builder.append("LEFT JOIN THE.STOCKING_STANDARD_UNIT ssu ON (ssu.OPENING_ID = o.OPENING_ID) ");
builder.append("LEFT JOIN THE.STOCKING_MILESTONE smrg ON (");
builder.append(" smrg.STOCKING_STANDARD_UNIT_ID = ssu.STOCKING_STANDARD_UNIT_ID");
builder.append(" AND SMRG.SILV_MILESTONE_TYPE_CODE = 'RG') ");
builder.append("LEFT JOIN THE.STOCKING_MILESTONE smfg ON (");
builder.append(" smfg.STOCKING_STANDARD_UNIT_ID = ssu.STOCKING_STANDARD_UNIT_ID");
builder.append(" AND smfg.SILV_MILESTONE_TYPE_CODE = 'FG') ");
builder.append("WHERE 1=1 ");

/* Filters */
Expand Down Expand Up @@ -400,23 +431,31 @@ private String createNativeSqlQuery(OpeningSearchFiltersDto filtersDto) {
// 8. Regen delay start date
if (filtersDto.hasValue(OpeningSearchFiltersDto.REGEN_DELAY_DATE_START)) {
log.info("Filter regenDelayDateStart detected! date={}", filtersDto.getRegenDelayDateStart());
log.info("Skipping Filter regenDelayDateStart. Filter not ready!");
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)) {
log.info("Filter regenDelayDateEnd detected! date={}", filtersDto.getRegenDelayDateEnd());
log.info("Skipping Filter regenDelayDateEnd. Filter not ready!");
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)) {
log.info(
"Filter freeGrowingDateStart detected! date={}", filtersDto.getFreeGrowingDateStart());
log.info("Skipping Filter freeGrowingDateStart. Filter not ready!");
builder.append("AND ADD_MONTHS(cboa.DISTURBANCE_START_DATE, ");
builder.append("COALESCE(SMFG.EARLY_OFFSET_YEARS,0)*12) ");
builder.append("> to_timestamp(:freeGrowingDateStart,'YYYY-MM-DD')");
}
// 11. Free growing end date
if (filtersDto.hasValue(OpeningSearchFiltersDto.FREE_GROWING_DATE_END)) {
log.info("Filter freeGrowingDateEnd detected! date={}", filtersDto.getFreeGrowingDateEnd());
log.info("Skipping Filter freeGrowingDateEnd. Filter not ready!");
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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ void openingSearch_happyPath_shouldSucceed() throws Exception {
response.setClientNumber(null);
response.setClientAcronym(null);
response.setRegenDelayDate(null);
response.setFreeGrowingDate(null);
response.setEarlyFreeGrowingDate(null);
response.setLateFreeGrowingDate(null);
response.setUpdateTimestamp(LocalDateTime.now());
response.setEntryUserId("TEST");
response.setSubmittedToFrpa(true);
Expand Down Expand Up @@ -94,7 +95,10 @@ void openingSearch_happyPath_shouldSucceed() throws Exception {
.andExpect(jsonPath("$.data[0].orgUnitName").value(response.getOrgUnitName()))
.andExpect(jsonPath("$.data[0].clientNumber").value(response.getClientNumber()))
.andExpect(jsonPath("$.data[0].regenDelayDate").value(response.getRegenDelayDate()))
.andExpect(jsonPath("$.data[0].freeGrowingDate").value(response.getFreeGrowingDate()))
.andExpect(
jsonPath("$.data[0].earlyFreeGrowingDate").value(response.getEarlyFreeGrowingDate()))
.andExpect(
jsonPath("$.data[0].lateFreeGrowingDate").value(response.getLateFreeGrowingDate()))
.andExpect(jsonPath("$.data[0].entryUserId").value(response.getEntryUserId()))
.andExpect(jsonPath("$.data[0].submittedToFrpa").value(response.getSubmittedToFrpa()))
.andExpect(jsonPath("$.data[0].silvaReliefAppId").value(response.getSilvaReliefAppId()))
Expand Down
Loading