Skip to content

Commit

Permalink
feat: 1435 different parent tree gw values and date update (#1491)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigyu authored Aug 13, 2024
1 parent 5fe2642 commit f404764
Show file tree
Hide file tree
Showing 80 changed files with 1,836 additions and 1,285 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ca.bc.gov.backendstartapi.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import java.math.BigDecimal;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/** This class represents a response body when a genetic worth entity is requested. */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class GeneticWorthDto extends CodeDescriptionDto {
@Schema(description = "The default breeding value", example = "0.0")
private BigDecimal defaultBv;

public GeneticWorthDto(String code, String description, BigDecimal defaultBv) {
super(code, description);
this.defaultBv = defaultBv;
}
}
88 changes: 55 additions & 33 deletions backend/src/main/java/ca/bc/gov/backendstartapi/dto/OrchardDto.java
Original file line number Diff line number Diff line change
@@ -1,49 +1,71 @@
package ca.bc.gov.backendstartapi.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

/**
* This record represents the OrchardLotTypeDescriptionDto object found in the oracle-api service.
*/
@Schema(description = "Represents an Orchard object received from oracle-api.")
public record OrchardDto(
@Schema(
description =
"""
@Schema(description = "Represents an Orchard object received from oracle-api except spuId.")
@Getter
@Setter
public class OrchardDto {
@Schema(
description =
"""
A unique identifier which is assigned to a location where cuttings or
A class seed is produced.
""",
example = "339")
String id,
@Schema(
description = "The name of a location where cuttings or A class seed is produced.",
example = "EAGLEROCK")
String name,
@Schema(description = "A code which represents a species of tree or brush.", example = "PLI")
String vegetationCode,
@Schema(
description =
"""
example = "339")
private String id;

@Schema(
description = "The name of a location where cuttings or A class seed is produced.",
example = "EAGLEROCK")
private String name;

@Schema(description = "A code which represents a species of tree or brush.", example = "PLI")
private String vegetationCode;

@Schema(
description =
"""
A code representing a type of orchard. The two values will be 'S' (Seed Lot) or
'C' (Cutting Lot).
""",
example = "S")
Character lotTypeCode,
@Schema(
description =
"""
example = "S")
private Character lotTypeCode;

@Schema(
description =
"""
A description of the Orchard Lot Type code. The two values will be 'Seed Lot'
or 'Cutting Lot'.
""",
example = "Seed Lot")
String lotTypeDescription,
@Schema(
description = "A code which represents the current stage or status of an orchard.",
example = "PRD")
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) {}
example = "Seed Lot")
private String lotTypeDescription;

@Schema(
description = "A code which represents the current stage or status of an orchard.",
example = "PRD")
private String stageCode;

@Schema(description = "The bgc zone code", example = "SBS")
private String becZoneCode;

@Schema(description = "The description of a bgc zone code", example = "Sub-Boreal Spruce")
private String becZoneDescription;

@Schema(description = "The bgc sub-zone code", example = "wk")
private String becSubzoneCode;

@Schema(description = "The variant.", example = "1")
private Character variant;

@Schema(description = "The bec version id.", example = "5")
private Integer becVersionId;

@Schema(description = "Seed Plan Unit id", example = "7")
private Integer spuId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@ public record ParentTreeGeneticQualityDto(
@Schema(
description =
"""
Describes the comparative measure of genetic value for a specific genetic trait of a
parent tree. Examples are BV (Breeding Value) and CV (Clonal Value).
""",
Describes the comparative measure of genetic value for a specific genetic trait of a
parent tree. Examples are BV (Breeding Value) and CV (Clonal Value).
""",
example = "BV")
String geneticTypeCode,
@Schema(description = "A code describing various Genetic Worths.", example = "GVO")
String geneticWorthCode,
@Schema(
description =
"""
The genetic quality value based on the test assessment for a Parent Tree from a test
no. and series.
""",
The genetic quality value based on the test assessment for a Parent Tree from a test
no. and series.
""",
example = "18")
BigDecimal geneticQualityValue) {}
BigDecimal geneticQualityValue,
@Schema(description = "Whether the parent tree is tested", example = "true")
Boolean isParentTreeTested,
@Schema(
description = "Whether the genetic quality value is using default value.",
example = "false")
Boolean isEstimated) {}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class SameSpeciesTreeDto {
@Schema(description = "The seed plan unit this tree belongs to.", example = "7")
private Long spu;

@Schema(description = "Whether the tree is tested.", example = "True")
private Boolean tested;

private List<ParentTreeGeneticQualityDto> parentTreeGeneticQualities;

public SameSpeciesTreeDto() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package ca.bc.gov.backendstartapi.endpoint;

import ca.bc.gov.backendstartapi.dto.CodeDescriptionDto;
import ca.bc.gov.backendstartapi.dto.GeneticWorthDto;
import ca.bc.gov.backendstartapi.entity.GeneticWorthEntity;
import ca.bc.gov.backendstartapi.security.RoleAccessConfig;
import ca.bc.gov.backendstartapi.service.GeneticWorthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.SchemaProperty;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -47,34 +46,14 @@ public class GeneticWorthEndpoint {
value = {
@ApiResponse(
responseCode = "200",
description = "An array of objects containing code and description for each value.",
content =
@Content(
array = @ArraySchema(schema = @Schema(type = "object")),
mediaType = "application/json",
schemaProperties = {
@SchemaProperty(
name = "code",
schema =
@Schema(
type = "string",
description = "This object represents a genetic worth code",
example = "AD")),
@SchemaProperty(
name = "description",
schema =
@Schema(
type = "string",
description = "The description of a genetic worth",
example = "Animal browse resistance (deer)"))
})),
description = "An array of objects containing code and description for each value."),
@ApiResponse(
responseCode = "401",
description = "Access token is missing or invalid",
content = @Content(schema = @Schema(implementation = Void.class)))
})
@RoleAccessConfig({"SPAR_TSC_ADMIN", "SPAR_MINISTRY_ORCHARD", "SPAR_NONMINISTRY_ORCHARD"})
public List<CodeDescriptionDto> getAllGeneticWorth() {
public List<GeneticWorthDto> getAllGeneticWorth() {
return geneticWorthService.getAllGeneticWorth();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package ca.bc.gov.backendstartapi.endpoint;

import ca.bc.gov.backendstartapi.dto.OrchardDto;
import ca.bc.gov.backendstartapi.dto.OrchardSpuDto;
import ca.bc.gov.backendstartapi.dto.ParentTreeDto;
import ca.bc.gov.backendstartapi.dto.SameSpeciesTreeDto;
import ca.bc.gov.backendstartapi.security.RoleAccessConfig;
import ca.bc.gov.backendstartapi.service.OrchardService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand Down Expand Up @@ -66,38 +64,31 @@ public OrchardSpuDto getParentTreeGeneticQualityData(
}

/**
* Get all parent trees under a species (VegCode).
* Get all Orchards under a species (VegCode).
*
* @return A list of {@link ParentTreeDto}
* @return A list of {@link OrchardDto}
*/
@GetMapping(path = "/parent-trees/vegetation-codes/{vegCode}", produces = "application/json")
@GetMapping("/vegetation-codes/{vegCode}")
@Operation(
summary = "Retrieves all parent trees under a species (VegCode)",
description = "Returns a list containing all parent trees under a species (VegCode).")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "An array of parent tree dto.",
content =
@Content(
array =
@ArraySchema(schema = @Schema(implementation = SameSpeciesTreeDto.class)),
mediaType = "application/json")),
@ApiResponse(responseCode = "200", description = "An array of parent tree dto."),
@ApiResponse(
responseCode = "401",
description = "Access token is missing or invalid",
content = @Content(schema = @Schema(implementation = Void.class)))
})
@RoleAccessConfig({"SPAR_TSC_ADMIN", "SPAR_MINISTRY_ORCHARD", "SPAR_NONMINISTRY_ORCHARD"})
public List<SameSpeciesTreeDto> getAllParentTreeByVegCode(
public List<OrchardDto> getAllOrchards(
@PathVariable("vegCode")
@Pattern(regexp = "^[a-zA-Z]{1,8}$")
@Parameter(
name = "vegCode",
in = ParameterIn.PATH,
description = "Identifier of the Orchard.")
String vegCode) {
return orchardService.findParentTreesByVegCode(vegCode);
return orchardService.findAllOrchardsByVegCode(vegCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import jakarta.persistence.PrePersist;
import jakarta.persistence.PreUpdate;
import jakarta.persistence.Table;
import java.time.Clock;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down Expand Up @@ -58,12 +59,12 @@ public FavouriteActivityEntity() {

@PrePersist
private void prePersist() {
entryTimestamp = LocalDateTime.now();
entryTimestamp = LocalDateTime.now(Clock.systemUTC());
updateTimestamp = entryTimestamp;
}

@PreUpdate
private void preUpdate() {
updateTimestamp = LocalDateTime.now();
updateTimestamp = LocalDateTime.now(Clock.systemUTC());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.math.BigDecimal;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -20,9 +21,17 @@ public class GeneticWorthEntity extends CodeDescriptionEntity {
@Column(name = "genetic_worth_code", length = 3)
private String geneticWorthCode;

@Column(name = "default_bv", nullable = false, precision = 3, scale = 1)
private BigDecimal defaultBv;

/** Constructor. */
public GeneticWorthEntity(
String geneticWorthCode, String description, EffectiveDateRange effectiveDateRange) {
String geneticWorthCode,
String description,
EffectiveDateRange effectiveDateRange,
BigDecimal defaultBv) {
super(description, effectiveDateRange);
this.geneticWorthCode = geneticWorthCode;
this.defaultBv = defaultBv;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.persistence.PreUpdate;
import java.io.Serial;
import java.io.Serializable;
import java.time.Clock;
import java.time.LocalDateTime;
import lombok.Generated;
import lombok.Getter;
Expand Down Expand Up @@ -46,12 +47,12 @@ public AuditInformation(@NonNull String userId) {

@PrePersist
private void prePersist() {
entryTimestamp = LocalDateTime.now();
entryTimestamp = LocalDateTime.now(Clock.systemUTC());
updateTimestamp = entryTimestamp;
}

@PreUpdate
private void preUpdate() {
updateTimestamp = LocalDateTime.now();
updateTimestamp = LocalDateTime.now(Clock.systemUTC());
}
}
Loading

0 comments on commit f404764

Please sign in to comment.