Skip to content

Commit

Permalink
fix: problems identified at collab (#1359)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigyu authored Jul 8, 2024
1 parent 046fc9a commit 7560e03
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ca.bc.gov.backendstartapi.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

/** An object containing the revision count of a record. */
@Schema(description = "An object containing the revision count of a record.")
public record RevisionCountDto(@NotNull Integer revisionCount) {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ca.bc.gov.backendstartapi.endpoint;

import ca.bc.gov.backendstartapi.dto.RevisionCountDto;
import ca.bc.gov.backendstartapi.dto.SaveSeedlotFormDtoClassA;
import ca.bc.gov.backendstartapi.dto.SeedlotAclassFormDto;
import ca.bc.gov.backendstartapi.dto.SeedlotApplicationPatchDto;
Expand Down Expand Up @@ -469,7 +470,7 @@ public ResponseEntity<SeedlotStatusResponseDto> submitSeedlotForm(
+ " for form submission.")
@ApiResponses(
value = {
@ApiResponse(responseCode = "204", description = "Successfully saved or updated."),
@ApiResponse(responseCode = "200", description = "Successfully saved or updated."),
@ApiResponse(
responseCode = "401",
description = "Access token is missing or invalid",
Expand All @@ -484,7 +485,7 @@ public ResponseEntity<SeedlotStatusResponseDto> submitSeedlotForm(
content = @Content(schema = @Schema(implementation = Void.class)))
})
@RoleAccessConfig({"SPAR_TSC_ADMIN", "SPAR_MINISTRY_ORCHARD", "SPAR_NONMINISTRY_ORCHARD"})
public ResponseEntity<Void> saveFormProgressClassA(
public RevisionCountDto saveFormProgressClassA(
@Parameter(
name = "seedlotNumber",
in = ParameterIn.PATH,
Expand All @@ -496,9 +497,9 @@ public ResponseEntity<Void> saveFormProgressClassA(
String seedlotNumber,
@RequestBody SaveSeedlotFormDtoClassA data) {

saveSeedlotFormService.saveFormClassA(seedlotNumber, data);
RevisionCountDto revCountDto = saveSeedlotFormService.saveFormClassA(seedlotNumber, data);

return new ResponseEntity<>(HttpStatus.NO_CONTENT);
return revCountDto;
}

/** Retrieves the saved Seedlot reg form. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ca.bc.gov.backendstartapi.service;

import ca.bc.gov.backendstartapi.config.SparLog;
import ca.bc.gov.backendstartapi.dto.RevisionCountDto;
import ca.bc.gov.backendstartapi.dto.SaveSeedlotFormDtoClassA;
import ca.bc.gov.backendstartapi.entity.SaveSeedlotProgressEntityClassA;
import ca.bc.gov.backendstartapi.entity.seedlot.Seedlot;
Expand Down Expand Up @@ -34,7 +35,8 @@ public class SaveSeedlotFormService {
private final LoggedUserService loggedUserService;

/** Saves the {@link SaveSeedlotFormDtoClassA} to table. */
public void saveFormClassA(@NonNull String seedlotNumber, SaveSeedlotFormDtoClassA data) {
public RevisionCountDto saveFormClassA(
@NonNull String seedlotNumber, SaveSeedlotFormDtoClassA data) {
SparLog.info("Saving A-Class seedlot progress for seedlot number: {}", seedlotNumber);

Seedlot relatedSeedlot =
Expand Down Expand Up @@ -68,7 +70,7 @@ public void saveFormClassA(@NonNull String seedlotNumber, SaveSeedlotFormDtoClas
Integer prevRevCount = data.revisionCount();
Integer currRevCount = optionalEntityToSave.get().getRevisionCount();

if (!prevRevCount.equals(currRevCount)) {
if (prevRevCount != null && !prevRevCount.equals(currRevCount)) {
// Conflict detected
SparLog.info(
"Save progress failed due to revision count mismatch, prev revision count: {}, curr"
Expand All @@ -86,9 +88,13 @@ public void saveFormClassA(@NonNull String seedlotNumber, SaveSeedlotFormDtoClas
entityToSave.setProgressStatus(parsedProgressStatus);
}

saveSeedlotProgressRepositoryClassA.save(entityToSave);
SaveSeedlotProgressEntityClassA saved = saveSeedlotProgressRepositoryClassA.save(entityToSave);

SparLog.info("A-class seedlot progress for seedlot number {} saved!", seedlotNumber);
return;

RevisionCountDto revCountDto = new RevisionCountDto(saved.getRevisionCount());

return revCountDto;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -755,10 +755,14 @@ public SeedlotStatusResponseDto updateSeedlotWithForm(
setParentTreeContribution(
seedlot, form.seedlotFormParentTreeDtoList(), form.seedlotFormParentTreeSmpDtoList());

// If there is no area of use data already set:
// Update elevation min max, latitude min max, longitude min max, and SPZ
// Set values in the Seedlot instance and update tables [seedlot_seed_plan_zone]
// Fetch data from Oracle to get the active Seed Plan Unit id
setAreaOfUse(seedlot, form.seedlotFormOrchardDto().primaryOrchardId());
if (!hasAreaOfUseData(seedlot)) {
SparLog.info("Area of Use data has NOT been set previously, setting area of use data");
setAreaOfUse(seedlot, form.seedlotFormOrchardDto().primaryOrchardId());
}
} else {
updateApplicantAndSeedlot(seedlot, form.applicantAndSeedlotInfo());
// Override Seedlot elevation min max, latitude min max, and longitude min max (area of use)
Expand Down Expand Up @@ -903,6 +907,24 @@ private List<GeneticWorthTraitsDto> getGeneticTraitList(
return genTraitList;
}

private boolean hasAreaOfUseData(Seedlot seedlot) {
return seedlot.getElevationMax() != null
|| seedlot.getElevationMin() != null
|| seedlot.getLatitudeDegMax() != null
|| seedlot.getLatitudeDegMin() != null
|| seedlot.getLatitudeMinMax() != null
|| seedlot.getLatitudeMinMin() != null
|| seedlot.getLatitudeSecMax() != null
|| seedlot.getLatitudeSecMin() != null
|| seedlot.getLongitudeDegMax() != null
|| seedlot.getLongitudeDegMin() != null
|| seedlot.getLongitudeMinMax() != null
|| seedlot.getLongitudeMinMin() != null
|| seedlot.getLongitudeSecMax() != null
|| seedlot.getLongitudeSecMin() != null
|| seedlot.getAreaOfUseComment() != null;
}

/**
* Reference Legacy Procedure: get_tested_area_of_use_geog from database/ddl/pkg/SPR_SEEDLOT.PKS
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
Expand All @@ -16,6 +15,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import ca.bc.gov.backendstartapi.dto.RevisionCountDto;
import ca.bc.gov.backendstartapi.dto.SaveSeedlotFormDtoClassA;
import ca.bc.gov.backendstartapi.dto.SeedlotAclassFormDto;
import ca.bc.gov.backendstartapi.dto.SeedlotDto;
Expand Down Expand Up @@ -614,7 +614,7 @@ void saveSeedlotFormProgress_notFoundSeedlot_shouldThrowException() throws Excep
@Test
@DisplayName("Save seedlot form progress should Succeed")
void saveSeedlotFormProgress_notFoundSeedlot_shouldSucceed() throws Exception {
doNothing().when(saveSeedlotFormService).saveFormClassA(any(), any());
when(saveSeedlotFormService.saveFormClassA(any(), any())).thenReturn(new RevisionCountDto(0));

mockMvc
.perform(
Expand All @@ -623,7 +623,7 @@ void saveSeedlotFormProgress_notFoundSeedlot_shouldSucceed() throws Exception {
.header("Content-Type", MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.content(SEEDLOT_FORM_PROGRESS_JSON))
.andExpect(status().isNoContent())
.andExpect(status().isOk())
.andReturn();
}

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/api-service/seedlotAPI.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import RevisionCountDto from '../types/RevisionCountDto';
import { SeedlotPatchPayloadType, SeedlotRegPayloadType } from '../types/SeedlotRegistrationTypes';
import {
RichSeedlotType, SeedlotAClassFullResponseType, SeedlotAClassSubmitType,
Expand Down Expand Up @@ -54,7 +55,7 @@ export const putAClassSeedlotProgress = (
payload: SeedlotProgressPayloadType
) => {
const url = `${ApiConfig.seedlots}/${seedlotNumber}/a-class-form-progress`;
return api.put(url, payload);
return api.put(url, payload).then((res): RevisionCountDto => res.data);
};

export const getAClassSeedlotProgressStatus = (seedlotNumber: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const CalculateMetrics = ({ disableOptions, setShowInfoSections, isReview }: pro
isFormSubmitted,
popSizeAndDiversityConfig,
setPopSizeAndDiversityConfig,
meanGeomInfos,
setMeanGeomInfos,
setIsCalculatingPt,
setGeoInfoVals,
Expand All @@ -43,7 +42,6 @@ const CalculateMetrics = ({ disableOptions, setShowInfoSections, isReview }: pro
setGenWorthInfoItems,
popSizeAndDiversityConfig,
setPopSizeAndDiversityConfig,
meanGeomInfos,
setMeanGeomInfos,
setIsCalculatingPt,
setGeoInfoVals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,47 @@ import { formatEmptyStr } from '../../SeedlotReviewSteps/ParentTrees/utils';
import {
validateElevationRange, validateDegreeRange, validateMinuteOrSecondRange
} from '../../SeedlotReviewSteps/AreaOfUse/utils';
import ReadOnlyInput from '../../ReadOnlyInput';

const SpatialData = () => {
/**
* Colletion
*/
const SpatialData = ({ isReviewRead }: { isReviewRead: boolean }) => {
const {
isFetchingData,
isCalculatingPt,
geoInfoVals,
setGeoInfoInputObj
} = useContext(ClassAContext);

if (isReviewRead) {
return (
<Row>
<Column className="info-col" sm={4} md={4} lg={4}>
<ReadOnlyInput
id="collection-mean-lat"
label="Mean latitude"
value={`${geoInfoVals.meanLatDeg.value}° ${geoInfoVals.meanLatMinute.value}' ${geoInfoVals.meanLatSec.value}"`}
/>
</Column>
<Column className="info-col" sm={4} md={4} lg={4}>
<ReadOnlyInput
id="collection-mean-long"
label="Mean longitude"
value={`${geoInfoVals.meanLongDeg.value}° ${geoInfoVals.meanLongMinute.value}' ${geoInfoVals.meanLongSec.value}"`}
/>
</Column>
<Column className="info-col" sm={4} md={4} lg={4}>
<ReadOnlyInput
id="collection-mean-elev"
label="Mean elevation"
value={`${geoInfoVals.meanElevation.value} m`}
/>
</Column>
</Row>
);
}

const handleInput = (key: keyof GeoInfoValType, value: string | null) => {
let newObj = structuredClone(geoInfoVals[key]);

Expand Down
Loading

0 comments on commit 7560e03

Please sign in to comment.