Skip to content

Commit

Permalink
feat: 977 967 fetch and fill bec values (#1187)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigyu authored Jun 3, 2024
1 parent 9753f62 commit d5c7264
Show file tree
Hide file tree
Showing 22 changed files with 894 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
@Schema(description = "Represents an Orchard object received from oracle-api.")
public record OrchardDto(
@Schema(
description = """
A unique identifier of an orchard
description =
"""
A unique identifier which is assigned to a location where cuttings or
A class seed is produced.
""",
example = "339")
String id,
Expand Down Expand Up @@ -38,4 +40,10 @@ public record OrchardDto(
@Schema(
description = "A code which represents the current stage or status of an orchard.",
example = "PRD")
String stageCode) {}
String stageCode,
@Schema(description = "The bgc zone code", example = "SBS") String becZoneCode,
@Schema(description = "The description of a bgc zone code", example = "Sub-Boreal Spruce")
String becZoneDescription,
@Schema(description = "The bgc sub-zone code", example = "wk") String becSubzoneCode,
@Schema(description = "The variant.", example = "1") Character variant,
@Schema(description = "The bec version id.", example = "5") Integer becVersionId) {}
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ public class Seedlot implements Serializable {
@Column(name = "bgc_zone_code", length = 4)
private String bgcZoneCode;

@Column(name = "bgc_zone_description", length = 120)
private String bgcZoneDescription;

@Column(name = "bgc_subzone_code", length = 3)
private String bgcSubzoneCode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,28 @@ public Optional<AreaOfUseDto> getAreaOfUseData(Integer spuId) {

return Optional.empty();
}

@Override
public Optional<OrchardDto> findOrchardById(String orchardId) {
String oracleApiUrl = String.format("%s/api/orchards/{orchardId}", rootUri);

SparLog.info("Starting {} - {} request to {}", PROVIDER, "findOrchardById", oracleApiUrl);

try {
ResponseEntity<OrchardDto> areaOfUseRes =
restTemplate.exchange(
oracleApiUrl,
HttpMethod.GET,
new HttpEntity<>(addHttpHeaders()),
new ParameterizedTypeReference<OrchardDto>() {},
createParamsMap("orchardId", orchardId));
SparLog.info("GET orchard by id - Success response!");
return Optional.of(areaOfUseRes.getBody());
} catch (HttpClientErrorException httpExc) {
SparLog.error(
"GET orchards by vegCode from oracle - Response code error: {}", httpExc.getStatusCode());
}

return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ default Optional<AreaOfUseDto> getAreaOfUseData(Integer spuId) {
return Optional.empty();
}

default Optional<OrchardDto> findOrchardById(String orchardId) {
return Optional.empty();
}

// Common methods
String[] addAuthorizationHeader();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ca.bc.gov.backendstartapi.dto.GeneticWorthTraitsDto;
import ca.bc.gov.backendstartapi.dto.GeospatialRequestDto;
import ca.bc.gov.backendstartapi.dto.GeospatialRespondDto;
import ca.bc.gov.backendstartapi.dto.OrchardDto;
import ca.bc.gov.backendstartapi.dto.OrchardParentTreeValsDto;
import ca.bc.gov.backendstartapi.dto.ParentTreeGeneticQualityDto;
import ca.bc.gov.backendstartapi.dto.PtCalculationResDto;
Expand Down Expand Up @@ -591,6 +592,8 @@ public SeedlotStatusResponseDto updateSeedlotWithForm(
// Extraction Step 6
saveSeedlotFormStep6(seedlot, form.seedlotFormExtractionDto());

setBecValues(seedlot, form.seedlotFormOrchardDto().primaryOrchardId());

setParentTreeContribution(
seedlot, form.seedlotFormParentTreeDtoList(), form.seedlotFormParentTreeSmpDtoList());

Expand All @@ -606,11 +609,30 @@ public SeedlotStatusResponseDto updateSeedlotWithForm(
seedlotNumber, seedlot.getSeedlotStatus().getSeedlotStatusCode());
}

private void setBecValues(Seedlot seedlot, String primaryOrchardId) {
SparLog.info("Begin to set BEC values");

OrchardDto orchardDto =
oracleApiProvider
.findOrchardById(primaryOrchardId)
.orElseThrow(OracleApiProviderException::new);

// Not sure why it's called Bgc in seedlot instead of Bec in orchard
seedlot.setBgcZoneCode(orchardDto.becZoneCode());
seedlot.setBgcZoneDescription(orchardDto.becZoneDescription());
seedlot.setBgcSubzoneCode(orchardDto.becSubzoneCode());
seedlot.setVariant(orchardDto.variant());
seedlot.setBecVersionId(orchardDto.becVersionId());

SparLog.info("BEC values set");
}

private void setParentTreeContribution(
Seedlot seedlot,
List<SeedlotFormParentTreeSmpDto> orchardPtDtoList,
List<SeedlotFormParentTreeSmpDto> smpPtDtoList) {

SparLog.info("Begin to set parent trees contribution");
List<OrchardParentTreeValsDto> orchardPtVals = convertToPtVals(orchardPtDtoList);
List<GeospatialRequestDto> smpMixIdAndProps = convertToGeoRes(smpPtDtoList);

Expand All @@ -633,6 +655,7 @@ private void setParentTreeContribution(
seedlot.setCollectionLongitudeDeg(collectionGeoData.getMeanLongitudeDegree());
seedlot.setCollectionLongitudeMin(collectionGeoData.getMeanLongitudeMinute());
seedlot.setCollectionLongitudeSec(collectionGeoData.getMeanLongitudeSecond());
SparLog.info("Parent trees contribution set");
}

private List<OrchardParentTreeValsDto> convertToPtVals(
Expand Down Expand Up @@ -695,6 +718,7 @@ private List<GeneticWorthTraitsDto> getGeneticTraitList(
* @param primaryOrchardId the primary orchard Id to find the spu for
*/
private void setAreaOfUse(Seedlot seedlot, String primaryOrchardId) {
SparLog.info("Begin to set Area of Use values");
ActiveOrchardSpuEntity activeSpuEntity =
orchardService
.findSpuIdByOrchardWithActive(primaryOrchardId, true)
Expand Down Expand Up @@ -776,6 +800,8 @@ private void setAreaOfUse(Seedlot seedlot, String primaryOrchardId) {
spzSaveList.add(sspzToSave);
});
seedlotSeedPlanZoneRepository.saveAll(spzSaveList);

SparLog.info("Area of Use values set");
}

private void setSeedlotStatus(Seedlot seedlot, String newStatus) {
Expand Down
Loading

0 comments on commit d5c7264

Please sign in to comment.