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: logical lock for the seedlot #1455

Merged
merged 11 commits into from
Aug 2, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import ca.bc.gov.backendstartapi.enums.parser.ConeAndPollenCountHeader;
import ca.bc.gov.backendstartapi.enums.parser.CsvParsingHeader;
import ca.bc.gov.backendstartapi.enums.parser.SmpMixHeader;
import ca.bc.gov.backendstartapi.util.ValueUtil;
import ca.bc.gov.backendstartapi.vo.parser.ConeAndPollenCount;
import ca.bc.gov.backendstartapi.vo.parser.SmpMixVolume;
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
Expand Down Expand Up @@ -136,6 +137,7 @@
CsvParsingHeader.class,
SmpMixHeader.class,
SeedlotSaveInMemoryDto.class,
ValueUtil.class,
})
@ImportRuntimeHints(value = {HttpServletRequestRuntimeHint.class})
public class NativeImageConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalDate;
import java.util.List;

/** This record represents the seedlot form step 1. */
Expand Down Expand Up @@ -36,7 +36,7 @@ The actual start date (year, month, and day) that the cones (source for seedlots
""",
example = "2023/11/20")
@NotNull
LocalDateTime collectionStartDate,
LocalDate collectionStartDate,
@Schema(
description =
"""
Expand All @@ -45,7 +45,7 @@ The actual end date (year, month, and day) that the cones (source for seedlots)
""",
example = "2023/11/30")
@NotNull
LocalDateTime collectionEndDate,
LocalDate collectionEndDate,
@Schema(
description = "The number of containers (sacks of cones) that were collected.",
example = "2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.time.LocalDate;

/** This record represents the seedlot form step 6. */
@Schema(description = "Seedlot extration and storage information. Form step 6")
Expand Down Expand Up @@ -34,7 +34,7 @@ The actual start date (year, month, and day) when the seed was extracted from th
""",
example = "2023/11/23",
nullable = true)
LocalDateTime extractionStDate,
LocalDate extractionStDate,
@Schema(
description =
"""
Expand All @@ -43,7 +43,7 @@ The actual end date (year, month, and day) when the seed was extracted from the
""",
example = "2023/11/23",
nullable = true)
LocalDateTime extractionEndDate,
LocalDate extractionEndDate,
@Schema(
description =
"""
Expand All @@ -66,9 +66,9 @@ A code to uniquely identify, within each client (storage), the addresses of diff
description = "Commencement date of temporary Seedlot storage.",
example = "2023/11/23",
nullable = true)
LocalDateTime temporaryStrgStartDate,
LocalDate temporaryStrgStartDate,
@Schema(
description = "End date of Seedlot temporary storage.",
example = "2023/11/23",
nullable = true)
LocalDateTime temporaryStrgEndDate) {}
LocalDate temporaryStrgEndDate) {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.time.LocalDate;

/** This record represents the seedlot form step 3. */
@Schema(description = "Seedlot interim information. Form step 3")
Expand Down Expand Up @@ -34,7 +34,7 @@ The actual start date (year, month, and day) when the cone was stored during int
""",
example = "2023/12/20")
@NotNull
LocalDateTime intermStrgStDate,
LocalDate intermStrgStDate,
@Schema(
description =
"""
Expand All @@ -43,9 +43,10 @@ The actual end date (year, month, and day) when the cone was stored during inter
""",
example = "2023/12/21")
@NotNull
LocalDateTime intermStrgEndDate,
LocalDate intermStrgEndDate,
@Schema(
description = """
description =
"""
Description of the storage facility type when 'Other' option is chosen.
""",
example = "Mini fridge",
Expand Down
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.config.SparLog;
import ca.bc.gov.backendstartapi.dto.RevisionCountDto;
import ca.bc.gov.backendstartapi.dto.SaveSeedlotFormDtoClassA;
import ca.bc.gov.backendstartapi.dto.SeedlotAclassFormDto;
Expand Down Expand Up @@ -31,6 +32,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.io.IOException;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -166,7 +168,7 @@ private Resource getFileResource(MultipartFile file) {
/**
* Created a new Seedlot in the system.
*
* @param createDto A {@link SeedlotCreateDto} containig all required field to get a new
* @param createDto A {@link SeedlotCreateDto} containing all required field to get a new
* registration started.
* @return A {@link SeedlotStatusResponseDto} with all created values.
*/
Expand Down Expand Up @@ -206,7 +208,10 @@ public ResponseEntity<SeedlotStatusResponseDto> createSeedlot(
@RequestBody
@Valid
SeedlotCreateDto createDto) {
long started = Instant.now().toEpochMilli();
SeedlotStatusResponseDto response = seedlotService.createSeedlot(createDto);
long finished = Instant.now().toEpochMilli();
SparLog.info("Time spent: {} ms - create seedlot first step", (finished - started));
return ResponseEntity.status(HttpStatus.CREATED).body(response);
}

Expand Down Expand Up @@ -454,9 +459,12 @@ public ResponseEntity<SeedlotStatusResponseDto> submitSeedlotForm(
@PathVariable
String seedlotNumber,
@RequestBody SeedlotFormSubmissionDto form) {
long started = Instant.now().toEpochMilli();
boolean isTscAdmin = loggedUserService.isTscAdminLogged();
SeedlotStatusResponseDto createDto =
seedlotService.updateSeedlotWithForm(seedlotNumber, form, isTscAdmin, true, "SUB");
long finished = Instant.now().toEpochMilli();
SparLog.info("Time spent: {} ms - submit seedlot regular form", (finished - started));
return ResponseEntity.status(HttpStatus.CREATED).body(createDto);
}

Expand Down
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.config.SparLog;
import ca.bc.gov.backendstartapi.dto.SeedlotFormSubmissionDto;
import ca.bc.gov.backendstartapi.dto.SeedlotStatusResponseDto;
import ca.bc.gov.backendstartapi.entity.seedlot.Seedlot;
Expand All @@ -17,6 +18,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.time.Instant;
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -130,7 +132,10 @@ public ResponseEntity<Void> updateSeedlotStatus(
schema = @Schema(type = "string", example = "true"))
@PathVariable
String status) {
long started = Instant.now().toEpochMilli();
tscAdminService.updateSeedlotStatus(seedlotNumber, status.toUpperCase());
long finished = Instant.now().toEpochMilli();
SparLog.info("Time spent: {} ms - approve or disapprove seedlot by tsc", (finished - started));
return ResponseEntity.noContent().build();
}

Expand Down Expand Up @@ -184,13 +189,16 @@ public ResponseEntity<SeedlotStatusResponseDto> submitSeedlotForm(
@RequestParam
String statusOnSave,
@RequestBody SeedlotFormSubmissionDto form) {
long started = Instant.now().toEpochMilli();
String formattedStatus = statusOnSave.toUpperCase();
if (!List.of("PND", "SUB", "APP").contains(formattedStatus)) {
throw new InvalidSeedlotStatusException(formattedStatus);
}

SeedlotStatusResponseDto updatedDto =
seedlotService.updateSeedlotWithForm(seedlotNumber, form, true, false, formattedStatus);
long finished = Instant.now().toEpochMilli();
SparLog.info("Time spent: {} ms - edit seedlot review form by tsc", (finished - started));
return ResponseEntity.status(HttpStatus.OK).body(updatedDto);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.JoinColumn;
Expand Down Expand Up @@ -33,13 +34,13 @@ public class SeedlotGeneticWorth {
// region Identifier
@Id
@JoinColumn(name = "seedlot_number")
@ManyToOne(optional = false)
@ManyToOne(fetch = FetchType.LAZY)
@NonNull
private Seedlot seedlot;

@Id
@JoinColumn(name = "genetic_worth_code")
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@NonNull
private GeneticWorthEntity geneticWorth;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.JoinColumn;
Expand Down Expand Up @@ -35,7 +36,7 @@ public class SeedlotParentTree {
// region Identifier
@Id
@JoinColumn(name = "seedlot_number")
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@NonNull
private Seedlot seedlot;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.JoinColumn;
Expand Down Expand Up @@ -33,7 +34,7 @@ public class SeedlotParentTreeGeneticQuality {
@Id
@JoinColumn(name = "seedlot_number", referencedColumnName = "seedlot_number")
@JoinColumn(name = "parent_tree_id", referencedColumnName = "parent_tree_id")
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@NonNull
private SeedlotParentTree seedlotParentTree;

Expand All @@ -44,7 +45,7 @@ public class SeedlotParentTreeGeneticQuality {

@Id
@JoinColumn(name = "genetic_worth_code")
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@NonNull
private GeneticWorthEntity geneticWorth;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.JoinColumn;
Expand Down Expand Up @@ -37,7 +38,7 @@ public class SeedlotParentTreeSmpMix {
@Id
@JoinColumn(name = "seedlot_number", referencedColumnName = "seedlot_number")
@JoinColumn(name = "parent_tree_id", referencedColumnName = "parent_tree_id")
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@NonNull
private SeedlotParentTree seedlotParentTree;

Expand All @@ -48,7 +49,7 @@ public class SeedlotParentTreeSmpMix {

@Id
@JoinColumn(name = "genetic_worth_code")
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@NonNull
private GeneticWorthEntity geneticWorth;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.JoinColumn;
Expand All @@ -32,7 +33,7 @@ public class SeedlotSeedPlanZoneEntity {
// region Identifier
@Id
@JoinColumn(name = "seedlot_number")
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@NonNull
private Seedlot seedlot;

Expand All @@ -42,7 +43,7 @@ public class SeedlotSeedPlanZoneEntity {
private String spzCode;

// endregion
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "genetic_class_code")
@NonNull
private GeneticClassEntity geneticClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.JoinColumn;
Expand Down Expand Up @@ -37,13 +38,14 @@ public class SmpMix {
// region Identifier
@Id
@JoinColumn(name = "seedlot_number")
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@NonNull
private Seedlot seedlot;

@Id
@Column(name = "parent_tree_id", nullable = false)
private int parentTreeId;

// endregion

@Column(name = "parent_tree_number", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.JoinColumn;
Expand Down Expand Up @@ -34,7 +35,7 @@ public class SmpMixGeneticQuality {
@Id
@JoinColumn(name = "seedlot_number", referencedColumnName = "seedlot_number")
@JoinColumn(name = "parent_tree_id", referencedColumnName = "parent_tree_id")
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@NonNull
private SmpMix smpMix;

Expand All @@ -45,7 +46,7 @@ public class SmpMixGeneticQuality {

@Id
@JoinColumn(name = "genetic_worth_code")
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@NonNull
private GeneticWorthEntity geneticWorth;

Expand Down
Loading