From f5ac5f8707b933d26c0b43210f8190b98b2ad51f Mon Sep 17 00:00:00 2001 From: Ricardo Campos Date: Fri, 2 Aug 2024 16:29:48 -0300 Subject: [PATCH] feat: logical lock for the seedlot (#1455) --- .../config/NativeImageConfig.java | 2 + .../dto/SeedlotFormCollectionDto.java | 6 +- .../dto/SeedlotFormExtractionDto.java | 10 +- .../dto/SeedlotFormInterimDto.java | 9 +- .../endpoint/SeedlotEndpoint.java | 10 +- .../endpoint/TscAdminEndpoint.java | 8 ++ .../entity/SeedlotGeneticWorth.java | 5 +- .../entity/SeedlotParentTree.java | 3 +- .../SeedlotParentTreeGeneticQuality.java | 5 +- .../entity/SeedlotParentTreeSmpMix.java | 5 +- .../entity/SeedlotSeedPlanZoneEntity.java | 5 +- .../bc/gov/backendstartapi/entity/SmpMix.java | 4 +- .../entity/SmpMixGeneticQuality.java | 5 +- .../entity/seedlot/Seedlot.java | 29 ++--- .../seedlot/SeedlotCollectionMethod.java | 9 +- .../entity/seedlot/SeedlotOrchard.java | 5 +- .../entity/seedlot/SeedlotOwnerQuantity.java | 20 ++-- .../provider/ForestClientApiProvider.java | 4 +- .../ConeCollectionMethodRepository.java | 6 +- .../repository/MethodOfPaymentRepository.java | 6 +- .../SeedlotCollectionMethodRepository.java | 2 + .../SeedlotOwnerQuantityRepository.java | 2 + .../service/ConeCollectionMethodService.java | 14 +++ .../service/MethodOfPaymentService.java | 14 +++ .../SeedlotCollectionMethodService.java | 88 ++++++++++----- .../service/SeedlotOrchardService.java | 38 ++++++- .../service/SeedlotOwnerQuantityService.java | 52 ++++----- .../service/SeedlotParentTreeService.java | 5 +- .../service/SeedlotService.java | 59 +++++----- .../service/SeedlotStatusService.java | 10 ++ .../service/TscAdminService.java | 6 +- .../gov/backendstartapi/util/ValueUtil.java | 101 ++++++++++++++++++ .../src/main/resources/application.properties | 1 + ...SeedlotCollectionMethodRelationalTest.java | 10 +- .../seedlot/SeedlotEntityRelationalTest.java | 29 +++-- .../SeedlotGeneticWorthRelationalTest.java | 10 +- .../seedlot/SeedlotOrchardRelationalTest.java | 10 +- .../SeedlotOwnerQuantityRelationalTest.java | 12 ++- ...arentTreeGeneticQualityRelationalTest.java | 10 +- .../SeedlotParentTreeRelationalTest.java | 10 +- ...SeedlotParentTreeSmpMixRelationalTest.java | 10 +- .../seedlot/SeedlotRelationalTest.java | 10 +- .../SmpMixGeneticQualityRelationalTest.java | 10 +- .../seedlot/SmpMixRelationalTest.java | 10 +- .../SeedlotCollectionMethodServiceTest.java | 19 ++-- .../service/SeedlotFormPutTest.java | 29 ++--- .../SeedlotOwnerQuantityServiceTest.java | 50 ++++----- .../service/SeedlotServiceTest.java | 37 +++---- .../backendstartapi/util/ValueUtilTest.java | 91 ++++++++++++++++ .../gov/oracleapi/entity/OrchardEntity.java | 8 +- .../bc/gov/oracleapi/entity/SeedPlanZone.java | 9 +- .../entity/TestedPtAreaOfUseSpz.java | 9 +- 52 files changed, 671 insertions(+), 260 deletions(-) create mode 100644 backend/src/main/java/ca/bc/gov/backendstartapi/util/ValueUtil.java create mode 100644 backend/src/test/java/ca/bc/gov/backendstartapi/util/ValueUtilTest.java diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/config/NativeImageConfig.java b/backend/src/main/java/ca/bc/gov/backendstartapi/config/NativeImageConfig.java index c9017901a..3599f87b2 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/config/NativeImageConfig.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/config/NativeImageConfig.java @@ -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; @@ -136,6 +137,7 @@ CsvParsingHeader.class, SmpMixHeader.class, SeedlotSaveInMemoryDto.class, + ValueUtil.class, }) @ImportRuntimeHints(value = {HttpServletRequestRuntimeHint.class}) public class NativeImageConfig { diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/dto/SeedlotFormCollectionDto.java b/backend/src/main/java/ca/bc/gov/backendstartapi/dto/SeedlotFormCollectionDto.java index e30a75df8..adbd7f32e 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/dto/SeedlotFormCollectionDto.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/dto/SeedlotFormCollectionDto.java @@ -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. */ @@ -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 = """ @@ -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") diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/dto/SeedlotFormExtractionDto.java b/backend/src/main/java/ca/bc/gov/backendstartapi/dto/SeedlotFormExtractionDto.java index bbf2f8879..6b083ac6f 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/dto/SeedlotFormExtractionDto.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/dto/SeedlotFormExtractionDto.java @@ -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") @@ -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 = """ @@ -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 = """ @@ -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) {} diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/dto/SeedlotFormInterimDto.java b/backend/src/main/java/ca/bc/gov/backendstartapi/dto/SeedlotFormInterimDto.java index eb12df33c..7ad99a5ee 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/dto/SeedlotFormInterimDto.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/dto/SeedlotFormInterimDto.java @@ -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") @@ -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 = """ @@ -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", diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/endpoint/SeedlotEndpoint.java b/backend/src/main/java/ca/bc/gov/backendstartapi/endpoint/SeedlotEndpoint.java index 1306bcc9a..987abfd44 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/endpoint/SeedlotEndpoint.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/endpoint/SeedlotEndpoint.java @@ -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; @@ -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; @@ -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. */ @@ -206,7 +208,10 @@ public ResponseEntity 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); } @@ -454,9 +459,12 @@ public ResponseEntity 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); } diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/endpoint/TscAdminEndpoint.java b/backend/src/main/java/ca/bc/gov/backendstartapi/endpoint/TscAdminEndpoint.java index 47261b14e..4bf385f35 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/endpoint/TscAdminEndpoint.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/endpoint/TscAdminEndpoint.java @@ -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; @@ -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; @@ -130,7 +132,10 @@ public ResponseEntity 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(); } @@ -184,6 +189,7 @@ public ResponseEntity 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); @@ -191,6 +197,8 @@ public ResponseEntity submitSeedlotForm( 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); } } diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotGeneticWorth.java b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotGeneticWorth.java index cb4a7978a..4eb65cff1 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotGeneticWorth.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotGeneticWorth.java @@ -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; @@ -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; diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotParentTree.java b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotParentTree.java index 4b41698fd..3d74f9f56 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotParentTree.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotParentTree.java @@ -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; @@ -35,7 +36,7 @@ public class SeedlotParentTree { // region Identifier @Id @JoinColumn(name = "seedlot_number") - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @NonNull private Seedlot seedlot; diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotParentTreeGeneticQuality.java b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotParentTreeGeneticQuality.java index a5e5730d5..31989dd71 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotParentTreeGeneticQuality.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotParentTreeGeneticQuality.java @@ -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; @@ -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; @@ -44,7 +45,7 @@ public class SeedlotParentTreeGeneticQuality { @Id @JoinColumn(name = "genetic_worth_code") - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @NonNull private GeneticWorthEntity geneticWorth; diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotParentTreeSmpMix.java b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotParentTreeSmpMix.java index 28e222d09..172403908 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotParentTreeSmpMix.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotParentTreeSmpMix.java @@ -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; @@ -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; @@ -48,7 +49,7 @@ public class SeedlotParentTreeSmpMix { @Id @JoinColumn(name = "genetic_worth_code") - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @NonNull private GeneticWorthEntity geneticWorth; diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotSeedPlanZoneEntity.java b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotSeedPlanZoneEntity.java index 0536acb5f..febfa7057 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotSeedPlanZoneEntity.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SeedlotSeedPlanZoneEntity.java @@ -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; @@ -32,7 +33,7 @@ public class SeedlotSeedPlanZoneEntity { // region Identifier @Id @JoinColumn(name = "seedlot_number") - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @NonNull private Seedlot seedlot; @@ -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; diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SmpMix.java b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SmpMix.java index 75abe863f..bf7bf5b6b 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SmpMix.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SmpMix.java @@ -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; @@ -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) diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SmpMixGeneticQuality.java b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SmpMixGeneticQuality.java index cdadbce4e..eaddbc5df 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SmpMixGeneticQuality.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/SmpMixGeneticQuality.java @@ -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; @@ -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; @@ -45,7 +46,7 @@ public class SmpMixGeneticQuality { @Id @JoinColumn(name = "genetic_worth_code") - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @NonNull private GeneticWorthEntity geneticWorth; diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/seedlot/Seedlot.java b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/seedlot/Seedlot.java index bdd67e701..2d907bd5a 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/seedlot/Seedlot.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/seedlot/Seedlot.java @@ -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.JoinColumn; import jakarta.persistence.ManyToOne; @@ -14,8 +15,10 @@ import jakarta.persistence.Version; import java.io.Serializable; import java.math.BigDecimal; +import java.time.LocalDate; import java.time.LocalDateTime; import lombok.AccessLevel; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -30,14 +33,16 @@ @Getter @Setter @ToString +@EqualsAndHashCode public class Seedlot implements Serializable { @Id @Column(name = "seedlot_number", length = 5) @NonNull private String id; - @JoinColumn(name = "seedlot_status_code") - @ManyToOne + @JoinColumn(name = "seedlot_status_code", nullable = false) + @ManyToOne(fetch = FetchType.LAZY) + @NonNull private SeedlotStatusEntity seedlotStatus; @Column(name = "seedlot_comment", length = 2000) @@ -60,11 +65,11 @@ public class Seedlot implements Serializable { private String vegetationCode; @JoinColumn(name = "genetic_class_code") - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) private GeneticClassEntity geneticClass; @JoinColumn(name = "seedlot_source_code") - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) private SeedlotSourceEntity seedlotSource; @Column(name = "to_be_registrd_ind") @@ -83,10 +88,10 @@ public class Seedlot implements Serializable { private String collectionLocationCode; @Column(name = "collection_start_date") - private LocalDateTime collectionStartDate; + private LocalDate collectionStartDate; @Column(name = "collection_end_date") - private LocalDateTime collectionEndDate; + private LocalDate collectionEndDate; @Column(name = "no_of_containers", precision = 6, scale = 2) private BigDecimal numberOfContainers; @@ -111,10 +116,10 @@ public class Seedlot implements Serializable { private String interimStorageLocationCode; @Column(name = "interm_strg_st_date") - private LocalDateTime interimStorageStartDate; + private LocalDate interimStorageStartDate; @Column(name = "interm_strg_end_date") - private LocalDateTime interimStorageEndDate; + private LocalDate interimStorageEndDate; @Column(name = "interm_facility_code", length = 3) private String interimStorageFacilityCode; @@ -178,10 +183,10 @@ public class Seedlot implements Serializable { private String extractionLocationCode; @Column(name = "extraction_st_date") - private LocalDateTime extractionStartDate; + private LocalDate extractionStartDate; @Column(name = "extraction_end_date") - private LocalDateTime extractionEndDate; + private LocalDate extractionEndDate; @Column(name = "temporary_strg_client_number", length = 8) private String storageClientNumber; @@ -190,10 +195,10 @@ public class Seedlot implements Serializable { private String storageLocationCode; @Column(name = "temporary_strg_start_date") - private LocalDateTime temporaryStorageStartDate; + private LocalDate temporaryStorageStartDate; @Column(name = "temporary_strg_end_date") - private LocalDateTime temporaryStorageEndDate; + private LocalDate temporaryStorageEndDate; // endregion diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/seedlot/SeedlotCollectionMethod.java b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/seedlot/SeedlotCollectionMethod.java index 68ee6ffe0..1e4bc46a5 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/seedlot/SeedlotCollectionMethod.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/seedlot/SeedlotCollectionMethod.java @@ -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; @@ -32,14 +33,14 @@ public class SeedlotCollectionMethod { // region Identifier @Id - @JoinColumn(name = "seedlot_number") - @ManyToOne + @JoinColumn(name = "seedlot_number", updatable = false, nullable = false) + @ManyToOne(fetch = FetchType.LAZY) @NonNull private Seedlot seedlot; @Id - @JoinColumn(name = "cone_collection_method_code") - @ManyToOne + @JoinColumn(name = "cone_collection_method_code", updatable = false, nullable = false) + @ManyToOne(fetch = FetchType.LAZY) @NonNull private ConeCollectionMethodEntity coneCollectionMethod; diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/seedlot/SeedlotOrchard.java b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/seedlot/SeedlotOrchard.java index 8b664ead9..fec7e1d83 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/seedlot/SeedlotOrchard.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/seedlot/SeedlotOrchard.java @@ -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; @@ -33,8 +34,8 @@ public class SeedlotOrchard { // region Identifier @Id - @JoinColumn(name = "seedlot_number") - @ManyToOne + @JoinColumn(name = "seedlot_number", updatable = false) + @ManyToOne(fetch = FetchType.LAZY) @NonNull private Seedlot seedlot; diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/seedlot/SeedlotOwnerQuantity.java b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/seedlot/SeedlotOwnerQuantity.java index 5317e00e2..3329b4d40 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/entity/seedlot/SeedlotOwnerQuantity.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/entity/seedlot/SeedlotOwnerQuantity.java @@ -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; @@ -32,8 +33,8 @@ public class SeedlotOwnerQuantity { // region Identifier @Id - @JoinColumn(name = "seedlot_number") - @ManyToOne + @JoinColumn(name = "seedlot_number", updatable = false, nullable = false) + @ManyToOne(fetch = FetchType.LAZY) @NonNull private Seedlot seedlot; @@ -58,8 +59,9 @@ public class SeedlotOwnerQuantity { @Column(name = "original_pct_srpls", precision = 4, scale = 1, nullable = false) private BigDecimal originalPercentageSurplus; - @JoinColumn(name = "method_of_payment_code") - @ManyToOne + @JoinColumn(name = "method_of_payment_code", updatable = false, nullable = false) + @ManyToOne(fetch = FetchType.LAZY) + @NonNull private MethodOfPaymentEntity methodOfPayment; @Column(name = "spar_fund_srce_code", length = 3) @@ -71,14 +73,4 @@ public class SeedlotOwnerQuantity { @Version @Setter(AccessLevel.NONE) private int revisionCount; - - /** - * Returns the SeedlotOwnerQuantity id, fields: seedlot number, owner cliend code, and owner - * client location. - * - * @return a {@link SeedlotOwnerQuantityId} - */ - public SeedlotOwnerQuantityId getId() { - return new SeedlotOwnerQuantityId(seedlot.getId(), ownerClientNumber, ownerLocationCode); - } } diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/provider/ForestClientApiProvider.java b/backend/src/main/java/ca/bc/gov/backendstartapi/provider/ForestClientApiProvider.java index 4c600e018..0b78d9c27 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/provider/ForestClientApiProvider.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/provider/ForestClientApiProvider.java @@ -355,9 +355,9 @@ private boolean shouldMock() { if (Arrays.stream(environment.getActiveProfiles()) .anyMatch(env -> !env.equalsIgnoreCase("prod"))) { String byPass = environment.getProperty("BYPASS_FOREST_CLIENT"); - SparLog.info("BYPASS_FOREST_CLIENT={}", byPass); + SparLog.debug("BYPASS_FOREST_CLIENT={}", byPass); boolean shouldMockValue = "Y".equals(byPass); - SparLog.info("Should mock ForestClient API request: {}", shouldMockValue); + SparLog.debug("Should mock ForestClient API request: {}", shouldMockValue); return shouldMockValue; } return false; diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/repository/ConeCollectionMethodRepository.java b/backend/src/main/java/ca/bc/gov/backendstartapi/repository/ConeCollectionMethodRepository.java index 0f3c9aed7..685a03947 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/repository/ConeCollectionMethodRepository.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/repository/ConeCollectionMethodRepository.java @@ -1,8 +1,12 @@ package ca.bc.gov.backendstartapi.repository; import ca.bc.gov.backendstartapi.entity.ConeCollectionMethodEntity; +import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; /** Repository for {@link ConeCollectionMethodEntity}. */ public interface ConeCollectionMethodRepository - extends JpaRepository {} + extends JpaRepository { + + List findAllByConeCollectionMethodCodeIn(List ids); +} diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/repository/MethodOfPaymentRepository.java b/backend/src/main/java/ca/bc/gov/backendstartapi/repository/MethodOfPaymentRepository.java index c11dc2fc2..ba0e2b593 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/repository/MethodOfPaymentRepository.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/repository/MethodOfPaymentRepository.java @@ -1,7 +1,11 @@ package ca.bc.gov.backendstartapi.repository; import ca.bc.gov.backendstartapi.entity.MethodOfPaymentEntity; +import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; /** Repository for {@link MethodOfPaymentEntity}. */ -public interface MethodOfPaymentRepository extends JpaRepository {} +public interface MethodOfPaymentRepository extends JpaRepository { + + List findAllByMethodOfPaymentCodeIn(List methods); +} diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/repository/SeedlotCollectionMethodRepository.java b/backend/src/main/java/ca/bc/gov/backendstartapi/repository/SeedlotCollectionMethodRepository.java index a022d6e91..aba8ecd23 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/repository/SeedlotCollectionMethodRepository.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/repository/SeedlotCollectionMethodRepository.java @@ -10,4 +10,6 @@ public interface SeedlotCollectionMethodRepository extends JpaRepository { List findAllBySeedlot_id(String seedlotNumber); + + void deleteAllBySeedlot_id(String seedlotNumber); } diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/repository/SeedlotOwnerQuantityRepository.java b/backend/src/main/java/ca/bc/gov/backendstartapi/repository/SeedlotOwnerQuantityRepository.java index 44e8afb84..c17a0e616 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/repository/SeedlotOwnerQuantityRepository.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/repository/SeedlotOwnerQuantityRepository.java @@ -10,4 +10,6 @@ public interface SeedlotOwnerQuantityRepository extends JpaRepository { List findAllBySeedlot_id(String seedlotNumber); + + void deleteAllBySeedlot_id(String seedlotNumber); } diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/service/ConeCollectionMethodService.java b/backend/src/main/java/ca/bc/gov/backendstartapi/service/ConeCollectionMethodService.java index 55021c83f..e6f20992d 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/service/ConeCollectionMethodService.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/service/ConeCollectionMethodService.java @@ -50,4 +50,18 @@ public List getAllValidConeCollectionMethods() { SparLog.info("{} Cone Collection Methods found.", list.size()); return list; } + + /** + * Get all cone collection methods by id in a single query. + * + * @param ids All cone collection method ids. + * @return List of found cone collection method entities. + */ + public List getAllByIdIn(List ids) { + SparLog.info("Fetching list of Cone Collection Methods by Id with ids {}", ids); + List list = + coneCollectionMethodRepository.findAllByConeCollectionMethodCodeIn(ids); + SparLog.info("{} Cone Collection Methods found.", list.size()); + return list; + } } diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/service/MethodOfPaymentService.java b/backend/src/main/java/ca/bc/gov/backendstartapi/service/MethodOfPaymentService.java index 9a3c3e6a1..6a0210574 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/service/MethodOfPaymentService.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/service/MethodOfPaymentService.java @@ -49,4 +49,18 @@ public List getAllValidMethodOfPayments() { return list; } + + /** + * Get all methods of payments given its codes. + * + * @param methods All the method of payment codes. + * @return List of the method of payment entity. + */ + public List getAllMethodsByCodeList(List methods) { + SparLog.info("Fetching list of payment methods with methods {}", methods); + List list = + methodOfPaymentRepository.findAllByMethodOfPaymentCodeIn(methods); + SparLog.info("{} payment methods found", list.size()); + return list; + } } diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotCollectionMethodService.java b/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotCollectionMethodService.java index ec3117e02..3877a8598 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotCollectionMethodService.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotCollectionMethodService.java @@ -5,15 +5,14 @@ import ca.bc.gov.backendstartapi.entity.ConeCollectionMethodEntity; import ca.bc.gov.backendstartapi.entity.seedlot.Seedlot; import ca.bc.gov.backendstartapi.entity.seedlot.SeedlotCollectionMethod; -import ca.bc.gov.backendstartapi.entity.seedlot.idclass.SeedlotCollectionMethodId; -import ca.bc.gov.backendstartapi.exception.ConeCollectionMethodNotFoundException; import ca.bc.gov.backendstartapi.exception.SeedlotConflictDataException; import ca.bc.gov.backendstartapi.repository.SeedlotCollectionMethodRepository; import ca.bc.gov.backendstartapi.security.LoggedUserService; +import ca.bc.gov.backendstartapi.util.ValueUtil; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.function.Function; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @@ -42,37 +41,48 @@ public void saveSeedlotFormStep1( seedlot.setCollectionClientNumber(formStep1.collectionClientNumber()); seedlot.setCollectionLocationCode(formStep1.collectionLocnCode()); - seedlot.setCollectionStartDate(formStep1.collectionStartDate()); - seedlot.setCollectionEndDate(formStep1.collectionEndDate()); - seedlot.setNumberOfContainers(formStep1.noOfContainers()); - seedlot.setContainerVolume(formStep1.volPerContainer()); - seedlot.setTotalConeVolume(formStep1.clctnVolume()); + if (!ValueUtil.isValueEqual( + seedlot.getCollectionStartDate(), formStep1.collectionStartDate())) { + seedlot.setCollectionStartDate(formStep1.collectionStartDate()); + } + if (!ValueUtil.isValueEqual(seedlot.getCollectionEndDate(), formStep1.collectionEndDate())) { + seedlot.setCollectionEndDate(formStep1.collectionEndDate()); + } + if (!ValueUtil.isValueEqual(formStep1.noOfContainers(), seedlot.getNumberOfContainers())) { + seedlot.setNumberOfContainers(formStep1.noOfContainers()); + } + if (!ValueUtil.isValueEqual(formStep1.volPerContainer(), seedlot.getContainerVolume())) { + seedlot.setContainerVolume(formStep1.volPerContainer()); + } + if (!ValueUtil.isValueEqual(formStep1.clctnVolume(), seedlot.getTotalConeVolume())) { + seedlot.setTotalConeVolume(formStep1.clctnVolume()); + } seedlot.setComment(formStep1.seedlotComment()); SparLog.info( - "Received {} SeedlotCollectionMethod record(s) for seedlot number {}", + "Received {} collection method(s) for seedlot number {}", formStep1.coneCollectionMethodCodes().size(), seedlot.getId()); List seedlotCollectionList = seedlotCollectionMethodRepository.findAllBySeedlot_id(seedlot.getId()); + boolean allEqual = + areExistingEqualsNewOnes(seedlotCollectionList, formStep1.coneCollectionMethodCodes()); + + if (allEqual) { + SparLog.info("Do not need to touch seedlot cone collection methods, they are the same"); + return; + } + if (!seedlotCollectionList.isEmpty() && canDelete) { SparLog.info( "Deleting {} previous records on the SeedlotCollectionMethod table for seedlot number {}", seedlotCollectionList.size(), seedlot.getId()); - List idsToDelete = new ArrayList<>(); - - for (SeedlotCollectionMethod methdCodeToRemove : seedlotCollectionList) { - idsToDelete.add( - new SeedlotCollectionMethodId( - seedlot.getId(), - methdCodeToRemove.getConeCollectionMethod().getConeCollectionMethodCode())); - } - - seedlotCollectionMethodRepository.deleteAllById(idsToDelete); + seedlotCollectionMethodRepository.deleteAllBySeedlot_id(seedlot.getId()); + seedlotCollectionMethodRepository.flush(); } else if (!seedlotCollectionList.isEmpty() && !canDelete) { SparLog.info("Update seedlot {} collection data failed due to conflict.", seedlot.getId()); throw new SeedlotConflictDataException(seedlot.getId()); @@ -81,6 +91,23 @@ public void saveSeedlotFormStep1( addSeedlotCollectionMethod(seedlot, formStep1.coneCollectionMethodCodes()); } + private boolean areExistingEqualsNewOnes( + List existing, List newOnes) { + List existingOnes = + existing.stream() + .map( + scm -> Integer.valueOf(scm.getConeCollectionMethod().getConeCollectionMethodCode())) + .toList(); + + List sortedList1 = new ArrayList<>(existingOnes); + List sortedList2 = new ArrayList<>(newOnes); + + Collections.sort(sortedList1); + Collections.sort(sortedList2); + + return sortedList1.equals(sortedList2); + } + /** * Saves each Collection method for a given Seedlot. * @@ -101,9 +128,9 @@ private void addSeedlotCollectionMethod(Seedlot seedlot, List methods) methods.size(), seedlot.getId()); - // Map of Cone Collection Methots + // Map of Cone Collection Methods Map ccmeMap = - coneCollectionMethodService.getAllValidConeCollectionMethods().stream() + coneCollectionMethodService.getAllByIdIn(methods).stream() .collect( Collectors.toMap( ConeCollectionMethodEntity::getConeCollectionMethodCode, Function.identity())); @@ -111,14 +138,9 @@ private void addSeedlotCollectionMethod(Seedlot seedlot, List methods) List scmList = new ArrayList<>(); for (Integer methodCode : methods) { - ConeCollectionMethodEntity coneCollectionEntity = ccmeMap.get(methodCode); - if (Objects.isNull(coneCollectionEntity)) { - throw new ConeCollectionMethodNotFoundException(); - } - SeedlotCollectionMethod methodEntity = new SeedlotCollectionMethod(); methodEntity.setSeedlot(seedlot); - methodEntity.setConeCollectionMethod(coneCollectionEntity); + methodEntity.setConeCollectionMethod(ccmeMap.get(methodCode)); methodEntity.setAuditInformation(loggedUserService.createAuditCurrentUser()); scmList.add(methodEntity); @@ -126,4 +148,16 @@ private void addSeedlotCollectionMethod(Seedlot seedlot, List methods) seedlotCollectionMethodRepository.saveAll(scmList); } + + /** + * Get All Seedlot collection method codes given a seedlot number. + * + * @param seedlotNumber The seedlot number. + * @return List of collection method codes or an empty list. + */ + public List getAllSeedlotCollectionMethodsBySeedlot(String seedlotNumber) { + return seedlotCollectionMethodRepository.findAllBySeedlot_id(seedlotNumber).stream() + .map(col -> col.getConeCollectionMethod().getConeCollectionMethodCode()) + .collect(Collectors.toList()); + } } diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotOrchardService.java b/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotOrchardService.java index 8f02c28e6..eeb12d2fb 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotOrchardService.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotOrchardService.java @@ -7,6 +7,7 @@ import ca.bc.gov.backendstartapi.exception.SeedlotConflictDataException; import ca.bc.gov.backendstartapi.repository.SeedlotOrchardRepository; import ca.bc.gov.backendstartapi.security.LoggedUserService; +import ca.bc.gov.backendstartapi.util.ValueUtil; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -38,7 +39,10 @@ public void saveSeedlotFormStep4( seedlot.setProducedWithBiotechnologicalProcesses(formStep4.biotechProcessesInd()); seedlot.setPollenContaminationPresentInOrchard(formStep4.pollenContaminationInd()); seedlot.setPollenContaminationPercentage(formStep4.pollenContaminationPct()); - seedlot.setPollenContaminantBreedingValue(formStep4.contaminantPollenBv()); + if (!ValueUtil.isValueEqual( + formStep4.contaminantPollenBv(), seedlot.getPollenContaminantBreedingValue())) { + seedlot.setPollenContaminantBreedingValue(formStep4.contaminantPollenBv()); + } seedlot.setPollenContaminationMethodCode(formStep4.pollenContaminationMthdCode()); SparLog.info( @@ -54,6 +58,12 @@ public void saveSeedlotFormStep4( } List seedlotOrchards = getAllSeedlotOrchardBySeedlotNumber(seedlot.getId()); + boolean allEqual = areExistingEqualsNewOnes(seedlotOrchards, formStep4); + if (allEqual) { + SparLog.info("Do not need to touch seedlot orchards, they are the same"); + return; + } + if (!seedlotOrchards.isEmpty() && canDelete) { SparLog.info( "Deleting {} previous records on the SeedlotOrchard table for seedlot number {}", @@ -61,6 +71,7 @@ public void saveSeedlotFormStep4( seedlot.getId()); seedlotOrchardRepository.deleteAllBySeedlot_id(seedlot.getId()); + seedlotOrchardRepository.flush(); } else if (!seedlotOrchards.isEmpty() && !canDelete) { SparLog.info("Update seedlot {} orchard data failed due to conflict.", seedlot.getId()); throw new SeedlotConflictDataException(seedlot.getId()); @@ -69,6 +80,31 @@ public void saveSeedlotFormStep4( saveSeedlotOrchards(seedlot, formStep4.primaryOrchardId(), formStep4.secondaryOrchardId()); } + private boolean areExistingEqualsNewOnes( + List seedlotOrchards, SeedlotFormOrchardDto formStep4) { + // Primary + Optional primaryOpt = + seedlotOrchards.stream().filter(SeedlotOrchard::getIsPrimary).findFirst(); + + if (primaryOpt.isEmpty()) { + return false; + } + + boolean primaryEqual = ValueUtil.isValueEqual(primaryOpt.get(), formStep4.primaryOrchardId()); + + // Secondary + Optional secondaryOpt = + seedlotOrchards.stream().filter(so -> !so.getIsPrimary()).findFirst(); + + if (secondaryOpt.isEmpty()) { + return primaryEqual; + } + + boolean secondaryEqual = + ValueUtil.isValueEqual(secondaryOpt.get(), formStep4.secondaryOrchardId()); + return secondaryEqual && primaryEqual; + } + private void saveSeedlotOrchards( Seedlot seedlot, String primaryOrchardId, String secondaryOrchardId) { diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotOwnerQuantityService.java b/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotOwnerQuantityService.java index 48aba9da5..f1d2fedd9 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotOwnerQuantityService.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotOwnerQuantityService.java @@ -5,15 +5,14 @@ import ca.bc.gov.backendstartapi.entity.MethodOfPaymentEntity; import ca.bc.gov.backendstartapi.entity.seedlot.Seedlot; import ca.bc.gov.backendstartapi.entity.seedlot.SeedlotOwnerQuantity; -import ca.bc.gov.backendstartapi.entity.seedlot.idclass.SeedlotOwnerQuantityId; -import ca.bc.gov.backendstartapi.exception.MethodOfPaymentNotFoundException; import ca.bc.gov.backendstartapi.exception.SeedlotConflictDataException; import ca.bc.gov.backendstartapi.repository.SeedlotOwnerQuantityRepository; import ca.bc.gov.backendstartapi.security.LoggedUserService; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Objects; +import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @@ -42,23 +41,19 @@ public List saveSeedlotFormStep2( SparLog.info("Saving Seedlot Form Step 2-Ownership for seedlot number {}", seedlot.getId()); SparLog.info( - "Received {} SeedlotOwerQuantity record(s) for seedlot number {}", - formStep2List.size(), - seedlot.getId()); + "Received {} owner record(s) for seedlot number {}", formStep2List.size(), seedlot.getId()); List soqList = seedlotOwnerQuantityRepository.findAllBySeedlot_id(seedlot.getId()); if (!soqList.isEmpty() && canDelete) { SparLog.info( - "Deleting {} previous records on the SeedlotOwerQuantity table for seedlot number {}", + "Deleting {} previous owner records for seedlot number {}", soqList.size(), seedlot.getId()); - List idsToDelete = - soqList.stream().map(x -> x.getId()).collect(Collectors.toList()); - - seedlotOwnerQuantityRepository.deleteAllById(idsToDelete); + seedlotOwnerQuantityRepository.deleteAllBySeedlot_id(seedlot.getId()); + seedlotOwnerQuantityRepository.flush(); } else if (!soqList.isEmpty() && !canDelete) { SparLog.info("Update seedlot {} ownership data failed due to conflict.", seedlot.getId()); throw new SeedlotConflictDataException(seedlot.getId()); @@ -70,19 +65,22 @@ public List saveSeedlotFormStep2( private List addSeedlotOwnerQuantityFromForm( Seedlot seedlot, List sfodList) { if (sfodList.isEmpty()) { - SparLog.info( - "No new records to be inserted on the SeedlotOwnerQuantity table for seedlot number {}", - seedlot.getId()); + SparLog.info("No new owner records to be inserted for seedlot number {}", seedlot.getId()); return List.of(); } SparLog.info( - "{} record(s) to be inserted on the SeedlotOwnerQuantity table for seedlot number {}", + "{} owner record(s) to be inserted for seedlot number {}", sfodList.size(), seedlot.getId()); + // Using Set here to avoid duplications + Set paymentMethods = + new HashSet<>(sfodList.stream().map(SeedlotFormOwnershipDto::methodOfPaymentCode).toList()); + List methods = paymentMethods.stream().toList(); + Map mopeMap = - methodOfPaymentService.getAllValidMethodOfPayments().stream() + methodOfPaymentService.getAllMethodsByCodeList(methods).stream() .collect( Collectors.toMap( MethodOfPaymentEntity::getMethodOfPaymentCode, Function.identity())); @@ -91,22 +89,28 @@ private List addSeedlotOwnerQuantityFromForm( for (SeedlotFormOwnershipDto ownershipDto : sfodList) { SeedlotOwnerQuantity ownerQuantityEntity = new SeedlotOwnerQuantity( - seedlot, ownershipDto.ownerClientNumber(), ownershipDto.ownerLocnCode()); + seedlot, + ownershipDto.ownerClientNumber(), + ownershipDto.ownerLocnCode(), + mopeMap.get(ownershipDto.methodOfPaymentCode())); ownerQuantityEntity.setOriginalPercentageOwned(ownershipDto.originalPctOwned()); ownerQuantityEntity.setOriginalPercentageReserved(ownershipDto.originalPctRsrvd()); ownerQuantityEntity.setOriginalPercentageSurplus(ownershipDto.originalPctSrpls()); ownerQuantityEntity.setFundingSourceCode(ownershipDto.sparFundSrceCode()); ownerQuantityEntity.setAuditInformation(loggedUserService.createAuditCurrentUser()); - - MethodOfPaymentEntity mope = mopeMap.get(ownershipDto.methodOfPaymentCode()); - if (Objects.isNull(mope)) { - throw new MethodOfPaymentNotFoundException(); - } - ownerQuantityEntity.setMethodOfPayment(mope); - soqList.add(ownerQuantityEntity); } return seedlotOwnerQuantityRepository.saveAll(soqList); } + + /** + * Find all seedlot owner quantity given a seedlot number. + * + * @param seedlotNumber The seedlot number. + * @return A list of found records, or an empty list. + */ + public List findAllBySeedlot(String seedlotNumber) { + return seedlotOwnerQuantityRepository.findAllBySeedlot_id(seedlotNumber); + } } diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotParentTreeService.java b/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotParentTreeService.java index e77c0c850..aec567a7e 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotParentTreeService.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotParentTreeService.java @@ -50,7 +50,7 @@ public class SeedlotParentTreeService { * @return A list of {@link SeedlotParentTree} */ public List getAllSeedlotParentTree(String seedlotNumber) { - SparLog.info("Get All SeedlotPrentTree for seedlot number {}", seedlotNumber); + SparLog.info("Get All SeedlotParentTree for seedlot number {}", seedlotNumber); return seedlotParentTreeRepository.findAllBySeedlot_id(seedlotNumber); } @@ -212,9 +212,6 @@ private List addSeedlotParentTree( seedlotPtListToInsert.add(seedlotParentTree); } - SparLog.info( - "3. seedlotParentTreeRepository size: {}", seedlotParentTreeRepository.findAll().size()); - return seedlotParentTreeRepository.saveAll(seedlotPtListToInsert); } } diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotService.java b/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotService.java index 14990f608..e98dc514e 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotService.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotService.java @@ -52,14 +52,12 @@ import ca.bc.gov.backendstartapi.exception.SeedlotStatusNotFoundException; import ca.bc.gov.backendstartapi.provider.Provider; import ca.bc.gov.backendstartapi.repository.GeneticClassRepository; -import ca.bc.gov.backendstartapi.repository.SeedlotCollectionMethodRepository; -import ca.bc.gov.backendstartapi.repository.SeedlotOwnerQuantityRepository; import ca.bc.gov.backendstartapi.repository.SeedlotRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSeedPlanZoneRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSourceRepository; -import ca.bc.gov.backendstartapi.repository.SeedlotStatusRepository; import ca.bc.gov.backendstartapi.security.LoggedUserService; import ca.bc.gov.backendstartapi.security.UserInfo; +import ca.bc.gov.backendstartapi.util.ValueUtil; import jakarta.transaction.Transactional; import java.math.BigDecimal; import java.time.LocalDateTime; @@ -67,7 +65,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; @@ -90,20 +87,14 @@ public class SeedlotService { private final SeedlotSourceRepository seedlotSourceRepository; - private final SeedlotStatusRepository seedlotStatusRepository; - private final GeneticClassRepository geneticClassRepository; private final LoggedUserService loggedUserService; private final SeedlotCollectionMethodService seedlotCollectionMethodService; - private final SeedlotCollectionMethodRepository seedlotCollectionMethodRepository; - private final SeedlotOwnerQuantityService seedlotOwnerQuantityService; - private final SeedlotOwnerQuantityRepository seedlotOwnerQuantityRepository; - private final SeedlotOrchardService seedlotOrchardService; private final SeedlotParentTreeService seedlotParentTreeService; @@ -145,7 +136,7 @@ public SeedlotStatusResponseDto createSeedlot(SeedlotCreateDto createDto) { Seedlot seedlot = new Seedlot(nextSeedlotNumber(createDto.geneticClassCode())); Optional seedLotStatusEntity = - seedlotStatusRepository.findById(Constants.CLASS_A_SEEDLOT_STATUS); + seedlotStatusService.findById(Constants.CLASS_A_SEEDLOT_STATUS); seedlot.setSeedlotStatus(seedLotStatusEntity.orElseThrow(InvalidSeedlotRequestException::new)); seedlot.setApplicantClientNumber(createDto.applicantClientNumber()); @@ -193,7 +184,7 @@ private String nextSeedlotNumber(Character seedlotClassCode) { seedlotRepository.findNextSeedlotNumber( Constants.CLASS_A_SEEDLOT_NUM_MIN, Constants.CLASS_A_SEEDLOT_NUM_MAX); - if (Objects.isNull(seedlotNumber)) { + if (!ValueUtil.hasValue(seedlotNumber)) { seedlotNumber = Constants.CLASS_A_SEEDLOT_NUM_MIN; } @@ -533,9 +524,7 @@ public SeedlotAclassFormDto getAclassSeedlotFormInfo(@NonNull String seedlotNumb seedlotRepository.findById(seedlotNumber).orElseThrow(SeedlotNotFoundException::new); List seedlotCollectionList = - seedlotCollectionMethodRepository.findAllBySeedlot_id(seedlotInfo.getId()).stream() - .map(col -> col.getConeCollectionMethod().getConeCollectionMethodCode()) - .collect(Collectors.toList()); + seedlotCollectionMethodService.getAllSeedlotCollectionMethodsBySeedlot(seedlotInfo.getId()); // Divide the seedlot data to each respective step SeedlotFormCollectionDto collectionStep = @@ -551,7 +540,7 @@ public SeedlotAclassFormDto getAclassSeedlotFormInfo(@NonNull String seedlotNumb seedlotCollectionList); List ownershipStep = - seedlotOwnerQuantityRepository.findAllBySeedlot_id(seedlotInfo.getId()).stream() + seedlotOwnerQuantityService.findAllBySeedlot(seedlotInfo.getId()).stream() .filter( owner -> owner.getOriginalPercentageOwned() != null @@ -788,7 +777,7 @@ public SeedlotStatusResponseDto updateSeedlotWithForm( // Calculate Seedlot GeoSpatial (for Seedlot, mean latitude, mean longitude, mean elevation) // Calculate Genetic Worth // Update Seedlot Ne, collection elevation, and collection lat long - // Saved the Seedlot calculated Genetic Worth + // Saves the Seedlot calculated Genetic Worth setParentTreeContribution( seedlot, form.seedlotFormParentTreeDtoList(), form.seedlotFormParentTreeSmpDtoList()); @@ -879,7 +868,11 @@ private void setParentTreeContribution( ptCalculationResDto.calculatedPtVals().getGeospatialData(); // Ne value - seedlot.setEffectivePopulationSize(ptCalculationResDto.calculatedPtVals().getNeValue()); + if (!ValueUtil.isValueEqual( + ptCalculationResDto.calculatedPtVals().getNeValue(), + seedlot.getEffectivePopulationSize())) { + seedlot.setEffectivePopulationSize(ptCalculationResDto.calculatedPtVals().getNeValue()); + } // Elevation seedlot.setCollectionElevation(collectionGeoData.getMeanElevation()); @@ -981,7 +974,7 @@ private void setAreaOfUse( SparLog.info("Begin to set Area of Use values"); Integer activeSpuId = inMemoryDto.getPrimarySpuId(); - if (Objects.isNull(activeSpuId)) { + if (!ValueUtil.hasValue(activeSpuId)) { ActiveOrchardSpuEntity activeSpuEntity = orchardService .findSpuIdByOrchardWithActive(primaryOrchardId, true) @@ -1097,8 +1090,14 @@ private void saveSeedlotFormStep3(Seedlot seedlot, SeedlotFormInterimDto formSte seedlot.setInterimStorageClientNumber(formStep3.intermStrgClientNumber()); seedlot.setInterimStorageLocationCode(formStep3.intermStrgLocnCode()); - seedlot.setInterimStorageStartDate(formStep3.intermStrgStDate()); - seedlot.setInterimStorageEndDate(formStep3.intermStrgEndDate()); + if (!ValueUtil.isValueEqual( + seedlot.getInterimStorageStartDate(), formStep3.intermStrgStDate())) { + seedlot.setInterimStorageStartDate(formStep3.intermStrgStDate()); + } + if (!ValueUtil.isValueEqual( + seedlot.getInterimStorageEndDate(), formStep3.intermStrgEndDate())) { + seedlot.setInterimStorageEndDate(formStep3.intermStrgEndDate()); + } seedlot.setInterimStorageFacilityCode(formStep3.intermFacilityCode()); // If the facility type is Other, then a description is required. SparLog.info("{} FACILITY TYPE CODE", formStep3.intermFacilityCode()); @@ -1145,12 +1144,22 @@ private void saveSeedlotFormStep6(Seedlot seedlot, SeedlotFormExtractionDto form seedlot.setExtractionClientNumber(formStep6.extractoryClientNumber()); seedlot.setExtractionLocationCode(formStep6.extractoryLocnCode()); - seedlot.setExtractionStartDate(formStep6.extractionStDate()); - seedlot.setExtractionEndDate(formStep6.extractionEndDate()); + if (!ValueUtil.isValueEqual(seedlot.getExtractionStartDate(), formStep6.extractionStDate())) { + seedlot.setExtractionStartDate(formStep6.extractionStDate()); + } + if (!ValueUtil.isValueEqual(seedlot.getExtractionEndDate(), formStep6.extractionEndDate())) { + seedlot.setExtractionEndDate(formStep6.extractionEndDate()); + } seedlot.setStorageClientNumber(formStep6.storageClientNumber()); seedlot.setStorageLocationCode(formStep6.storageLocnCode()); - seedlot.setTemporaryStorageStartDate(formStep6.temporaryStrgStartDate()); - seedlot.setTemporaryStorageEndDate(formStep6.temporaryStrgEndDate()); + if (!ValueUtil.isValueEqual( + seedlot.getTemporaryStorageStartDate(), formStep6.temporaryStrgStartDate())) { + seedlot.setTemporaryStorageStartDate(formStep6.temporaryStrgStartDate()); + } + if (!ValueUtil.isValueEqual( + seedlot.getTemporaryStorageEndDate(), formStep6.temporaryStrgEndDate())) { + seedlot.setTemporaryStorageEndDate(formStep6.temporaryStrgEndDate()); + } } } diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotStatusService.java b/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotStatusService.java index 3298da4e2..c8254a880 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotStatusService.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/service/SeedlotStatusService.java @@ -72,4 +72,14 @@ public Optional getValidSeedlotStatus(String statusCode) { return optionalSeedlot; } + + /** + * Get a Seedlot Status entity by id. + * + * @param id The status code. + * @return Optional of a Seedlot Status Entity. + */ + public Optional findById(String id) { + return seedlotStatusRepository.findById(id); + } } diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/service/TscAdminService.java b/backend/src/main/java/ca/bc/gov/backendstartapi/service/TscAdminService.java index 92dc5cdc2..b58292fed 100644 --- a/backend/src/main/java/ca/bc/gov/backendstartapi/service/TscAdminService.java +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/service/TscAdminService.java @@ -15,6 +15,7 @@ import ca.bc.gov.backendstartapi.repository.SeedlotRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSeedPlanZoneRepository; import ca.bc.gov.backendstartapi.security.LoggedUserService; +import ca.bc.gov.backendstartapi.util.ValueUtil; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -202,7 +203,10 @@ public void overrideElevLatLongMinMax( public void overrideSeedlotCollElevLatLong( Seedlot seedlot, SeedlotReviewGeoInformationDto seedlotReviewDto) { // Ne value - seedlot.setEffectivePopulationSize(seedlotReviewDto.effectivePopulationSize()); + if (!ValueUtil.isValueEqual( + seedlot.getEffectivePopulationSize(), seedlotReviewDto.effectivePopulationSize())) { + seedlot.setEffectivePopulationSize(seedlotReviewDto.effectivePopulationSize()); + } // Elevation seedlot.setCollectionElevation(seedlotReviewDto.meanElevation()); diff --git a/backend/src/main/java/ca/bc/gov/backendstartapi/util/ValueUtil.java b/backend/src/main/java/ca/bc/gov/backendstartapi/util/ValueUtil.java new file mode 100644 index 000000000..cd2720e9f --- /dev/null +++ b/backend/src/main/java/ca/bc/gov/backendstartapi/util/ValueUtil.java @@ -0,0 +1,101 @@ +package ca.bc.gov.backendstartapi.util; + +import ca.bc.gov.backendstartapi.config.SparLog; +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Optional; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.springframework.data.domain.Page; + +/** This class contains methods for handling objects values and comparing. */ +@NoArgsConstructor(access = AccessLevel.NONE) +public final class ValueUtil { + + /** + * Check if a variable has value. Note that only objects should be handled here, meaning that + * primitive as int, char, long should not be used here. If the class it's a Boolean, will return + * true if it's different from null, because 'false' it's a value. + * + * @param obj The variable to check + * @return true if has, false otherwise. + */ + public static boolean hasValue(Object obj) { + if (obj == null) { + return false; + } + if (obj instanceof String str) { + return !str.isBlank(); + } + if (obj instanceof BigDecimal big) { + return big.compareTo(BigDecimal.ZERO) != 0; + } + if (obj instanceof Integer intVal) { + return intVal != 0; + } + if (obj instanceof Character charVal) { + return charVal.charValue() != ' '; + } + if (obj instanceof LocalDateTime localDateTime) { + ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault()); + return zdt.toInstant().toEpochMilli() > 0L; + } + if (obj instanceof LocalDate localDate) { + ZonedDateTime zdt = localDate.atStartOfDay(ZoneId.systemDefault()); + return zdt.toInstant().toEpochMilli() > 0L; + } + if (obj instanceof Long longValue) { + return longValue != 0L; + } + if (obj instanceof Double doubleValue) { + return doubleValue != 0D; + } + if (obj instanceof Page page) { + return page.hasContent(); + } + if (obj instanceof List list) { + return !list.isEmpty(); + } + if (obj instanceof Boolean) { + return true; + } + if (obj instanceof Optional opt) { + return opt.isPresent(); + } + SparLog.warn("Class not handled {}", obj.getClass()); + return false; + } + + /** + * Compare two objects checking if they have the same content/value. If one of the objects are + * null, then will return false. If they have different classes, will return null. If it's not an + * expected class, will log in the WARN level and return false. + * + * @param objOne First object to compare. + * @param objTwo Second object to compare. + * @return true if they are, false otherwise. + */ + public static boolean isValueEqual(Object objOne, Object objTwo) { + if (!hasValue(objOne) || !hasValue(objTwo)) { + return false; + } + if (objOne.getClass() != objTwo.getClass()) { + return false; + } + + if (objOne.getClass() == BigDecimal.class) { + return BigDecimal.class.cast(objOne).compareTo(BigDecimal.class.cast(objTwo)) == 0; + } + if (objOne.getClass() == LocalDateTime.class) { + return LocalDateTime.class.cast(objOne).isEqual(LocalDateTime.class.cast(objTwo)); + } + if (objOne.getClass() == LocalDate.class) { + return LocalDate.class.cast(objOne).isEqual(LocalDate.class.cast(objTwo)); + } + return objOne.equals(objTwo); + } +} diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index c109fe15b..7a1295878 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -33,6 +33,7 @@ spring.datasource.hikari.minimumIdle = 1 spring.datasource.hikari.maximumPoolSize = 3 spring.jpa.properties.hibernate.default_schema=spar spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect +spring.jpa.show-sql=false spring.flyway.enabled = true spring.flyway.baseline-on-migrate = true spring.flyway.locations = classpath:db/migration diff --git a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotCollectionMethodRelationalTest.java b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotCollectionMethodRelationalTest.java index afb5f96f8..faa0eb924 100644 --- a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotCollectionMethodRelationalTest.java +++ b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotCollectionMethodRelationalTest.java @@ -14,6 +14,7 @@ import ca.bc.gov.backendstartapi.repository.SeedlotCollectionMethodRepository; import ca.bc.gov.backendstartapi.repository.SeedlotRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSourceRepository; +import ca.bc.gov.backendstartapi.repository.SeedlotStatusRepository; import java.time.LocalDate; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -34,9 +35,14 @@ protected SeedlotCollectionMethodRelationalTest( SeedlotCollectionMethodRepository seedlotCollectionMethodRepo, ConeCollectionMethodRepository coneCollectionMethodRepo, GeneticWorthRepository geneticWorthRepository, - SeedlotSourceRepository seedlotSourceRepository) { + SeedlotSourceRepository seedlotSourceRepository, + SeedlotStatusRepository seedlotStatusRepository) { super( - seedlotRepository, geneticClassRepository, geneticWorthRepository, seedlotSourceRepository); + seedlotRepository, + geneticClassRepository, + geneticWorthRepository, + seedlotSourceRepository, + seedlotStatusRepository); seedlotCollectionMethodTestRepo = seedlotCollectionMethodRepo; coneCollectionMethodTestRepo = coneCollectionMethodRepo; } diff --git a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotEntityRelationalTest.java b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotEntityRelationalTest.java index 2a5186555..3f7d44837 100644 --- a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotEntityRelationalTest.java +++ b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotEntityRelationalTest.java @@ -3,6 +3,7 @@ import ca.bc.gov.backendstartapi.entity.GeneticClassEntity; import ca.bc.gov.backendstartapi.entity.GeneticWorthEntity; import ca.bc.gov.backendstartapi.entity.SeedlotSourceEntity; +import ca.bc.gov.backendstartapi.entity.SeedlotStatusEntity; import ca.bc.gov.backendstartapi.entity.embeddable.AuditInformation; import ca.bc.gov.backendstartapi.entity.embeddable.EffectiveDateRange; import ca.bc.gov.backendstartapi.entity.seedlot.Seedlot; @@ -10,6 +11,7 @@ import ca.bc.gov.backendstartapi.repository.GeneticWorthRepository; import ca.bc.gov.backendstartapi.repository.SeedlotRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSourceRepository; +import ca.bc.gov.backendstartapi.repository.SeedlotStatusRepository; import java.math.BigDecimal; import java.time.LocalDate; import java.time.LocalDateTime; @@ -20,16 +22,19 @@ abstract class SeedlotEntityRelationalTest { protected GeneticClassRepository geneticClassRepository; protected GeneticWorthRepository geneticWorthRepository; protected SeedlotSourceRepository seedlotSourceRepository; + protected SeedlotStatusRepository seedlotStatusRepository; protected SeedlotEntityRelationalTest( SeedlotRepository seedlotRepository, GeneticClassRepository geneticClassRepository, GeneticWorthRepository geneticWorthRepository, - SeedlotSourceRepository seedlotSourceRepository) { + SeedlotSourceRepository seedlotSourceRepository, + SeedlotStatusRepository seedlotStatusRepository) { this.seedlotRepository = seedlotRepository; this.geneticClassRepository = geneticClassRepository; this.geneticWorthRepository = geneticWorthRepository; this.seedlotSourceRepository = seedlotSourceRepository; + this.seedlotStatusRepository = seedlotStatusRepository; } protected Seedlot createSeedlot(String id) { @@ -48,12 +53,18 @@ protected Seedlot createSeedlot(String id) { var seedlotSource = new SeedlotSourceEntity("CUS", "Custom Lot", effectiveDateRange, null); seedlotSourceRepository.saveAndFlush(seedlotSource); + EffectiveDateRange range = + new EffectiveDateRange(LocalDate.now().minusYears(3L), LocalDate.now().plusYears(15L)); + var seedlotStatus = new SeedlotStatusEntity("PND", "Pending", range); + seedlotStatusRepository.saveAndFlush(seedlotStatus); + var seedlot = new Seedlot(id); seedlot.setComment("A seedlot."); seedlot.setApplicantClientNumber("00000001"); seedlot.setApplicantLocationCode("02"); seedlot.setApplicantEmailAddress("applicant@email.com"); + seedlot.setSeedlotStatus(seedlotStatus); seedlot.setVegetationCode("VEG"); seedlot.setGeneticClass(geneticClass); @@ -63,16 +74,16 @@ protected Seedlot createSeedlot(String id) { seedlot.setCollectionClientNumber("00000003"); seedlot.setCollectionLocationCode("04"); - seedlot.setCollectionStartDate(LocalDateTime.now()); - seedlot.setCollectionEndDate(LocalDateTime.now()); + seedlot.setCollectionStartDate(LocalDate.now()); + seedlot.setCollectionEndDate(LocalDate.now()); seedlot.setNumberOfContainers(new BigDecimal(10)); seedlot.setContainerVolume(new BigDecimal(20)); seedlot.setTotalConeVolume(new BigDecimal(200)); seedlot.setInterimStorageClientNumber("00000005"); seedlot.setInterimStorageLocationCode("06"); - seedlot.setInterimStorageStartDate(LocalDateTime.now()); - seedlot.setInterimStorageEndDate(LocalDateTime.now()); + seedlot.setInterimStorageStartDate(LocalDate.now()); + seedlot.setInterimStorageEndDate(LocalDate.now()); seedlot.setInterimStorageFacilityCode("007"); seedlot.setFemaleGameticContributionMethod("F"); @@ -92,12 +103,12 @@ protected Seedlot createSeedlot(String id) { seedlot.setExtractionClientNumber("00000009"); seedlot.setExtractionLocationCode("10"); - seedlot.setExtractionStartDate(LocalDateTime.now()); - seedlot.setExtractionEndDate(LocalDateTime.now()); + seedlot.setExtractionStartDate(LocalDate.now()); + seedlot.setExtractionEndDate(LocalDate.now()); seedlot.setStorageClientNumber("00000011"); seedlot.setStorageLocationCode("12"); - seedlot.setTemporaryStorageStartDate(LocalDateTime.now()); - seedlot.setTemporaryStorageEndDate(LocalDateTime.now()); + seedlot.setTemporaryStorageStartDate(LocalDate.now()); + seedlot.setTemporaryStorageEndDate(LocalDate.now()); seedlot.setDeclarationOfTrueInformationUserId("user1"); seedlot.setDeclarationOfTrueInformationTimestamp(LocalDateTime.now()); diff --git a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotGeneticWorthRelationalTest.java b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotGeneticWorthRelationalTest.java index 649311227..6702ae5e2 100644 --- a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotGeneticWorthRelationalTest.java +++ b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotGeneticWorthRelationalTest.java @@ -10,6 +10,7 @@ import ca.bc.gov.backendstartapi.repository.SeedlotGeneticWorthRepository; import ca.bc.gov.backendstartapi.repository.SeedlotRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSourceRepository; +import ca.bc.gov.backendstartapi.repository.SeedlotStatusRepository; import java.math.BigDecimal; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -28,9 +29,14 @@ class SeedlotGeneticWorthRelationalTest extends SeedlotEntityRelationalTest { GeneticClassRepository geneticClassRepository, GeneticWorthRepository geneticWorthRepository, SeedlotGeneticWorthRepository seedlotGeneticWorthRepository, - SeedlotSourceRepository seedlotSourceRepository) { + SeedlotSourceRepository seedlotSourceRepository, + SeedlotStatusRepository seedlotStatusRepository) { super( - seedlotRepository, geneticClassRepository, geneticWorthRepository, seedlotSourceRepository); + seedlotRepository, + geneticClassRepository, + geneticWorthRepository, + seedlotSourceRepository, + seedlotStatusRepository); this.seedlotGeneticWorthRepository = seedlotGeneticWorthRepository; } diff --git a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotOrchardRelationalTest.java b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotOrchardRelationalTest.java index 418aa88d9..175c7d664 100644 --- a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotOrchardRelationalTest.java +++ b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotOrchardRelationalTest.java @@ -10,6 +10,7 @@ import ca.bc.gov.backendstartapi.repository.SeedlotOrchardRepository; import ca.bc.gov.backendstartapi.repository.SeedlotRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSourceRepository; +import ca.bc.gov.backendstartapi.repository.SeedlotStatusRepository; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; @@ -27,9 +28,14 @@ protected SeedlotOrchardRelationalTest( GeneticClassRepository geneticClassRepository, SeedlotOrchardRepository seedlotOrchardRepository, GeneticWorthRepository geneticWorthRepository, - SeedlotSourceRepository seedlotSourceRepository) { + SeedlotSourceRepository seedlotSourceRepository, + SeedlotStatusRepository seedlotStatusRepository) { super( - seedlotRepository, geneticClassRepository, geneticWorthRepository, seedlotSourceRepository); + seedlotRepository, + geneticClassRepository, + geneticWorthRepository, + seedlotSourceRepository, + seedlotStatusRepository); repository = seedlotOrchardRepository; } diff --git a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotOwnerQuantityRelationalTest.java b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotOwnerQuantityRelationalTest.java index e7497cdd9..43854dc8f 100644 --- a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotOwnerQuantityRelationalTest.java +++ b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotOwnerQuantityRelationalTest.java @@ -13,6 +13,7 @@ import ca.bc.gov.backendstartapi.repository.SeedlotOwnerQuantityRepository; import ca.bc.gov.backendstartapi.repository.SeedlotRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSourceRepository; +import ca.bc.gov.backendstartapi.repository.SeedlotStatusRepository; import java.math.BigDecimal; import java.time.LocalDate; import org.junit.jupiter.api.Test; @@ -34,9 +35,14 @@ class SeedlotOwnerQuantityRelationalTest extends SeedlotEntityRelationalTest { SeedlotOwnerQuantityRepository seedlotOwnerQuantityRepository, GeneticWorthRepository geneticWorthRepository, MethodOfPaymentRepository methodOfPaymentRepository, - SeedlotSourceRepository seedlotSourceRepository) { + SeedlotSourceRepository seedlotSourceRepository, + SeedlotStatusRepository seedlotStatusRepository) { super( - seedlotRepository, geneticClassRepository, geneticWorthRepository, seedlotSourceRepository); + seedlotRepository, + geneticClassRepository, + geneticWorthRepository, + seedlotSourceRepository, + seedlotStatusRepository); repository = seedlotOwnerQuantityRepository; this.methodOfPaymentRepository = methodOfPaymentRepository; } @@ -44,7 +50,6 @@ class SeedlotOwnerQuantityRelationalTest extends SeedlotEntityRelationalTest { @Test void create() { var seedlot = createSeedlot("00000"); - var seedlotOwnerQuantity = new SeedlotOwnerQuantity(seedlot, "00020", "21"); LocalDate now = LocalDate.now(); var effectiveDate = now.minusDays(2); @@ -53,6 +58,7 @@ void create() { var methodOfPayment = new MethodOfPaymentEntity("ITC", "Invoice to Client Address", effectiveDateRange); + var seedlotOwnerQuantity = new SeedlotOwnerQuantity(seedlot, "00020", "21", methodOfPayment); methodOfPaymentRepository.saveAndFlush(methodOfPayment); seedlotOwnerQuantity.setOriginalPercentageOwned(new BigDecimal(0)); diff --git a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotParentTreeGeneticQualityRelationalTest.java b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotParentTreeGeneticQualityRelationalTest.java index 07cd02d35..b1b35e278 100644 --- a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotParentTreeGeneticQualityRelationalTest.java +++ b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotParentTreeGeneticQualityRelationalTest.java @@ -13,6 +13,7 @@ import ca.bc.gov.backendstartapi.repository.SeedlotParentTreeRepository; import ca.bc.gov.backendstartapi.repository.SeedlotRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSourceRepository; +import ca.bc.gov.backendstartapi.repository.SeedlotStatusRepository; import java.math.BigDecimal; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -34,9 +35,14 @@ class SeedlotParentTreeGeneticQualityRelationalTest extends SeedlotEntityRelatio SeedlotParentTreeRepository seedlotParentTreeRepository, GeneticWorthRepository geneticWorthRepository, SeedlotParentTreeGeneticQualityRepository seedlotParentTreeGeneticQualityRepository, - SeedlotSourceRepository seedlotSourceRepository) { + SeedlotSourceRepository seedlotSourceRepository, + SeedlotStatusRepository seedlotStatusRepository) { super( - seedlotRepository, geneticClassRepository, geneticWorthRepository, seedlotSourceRepository); + seedlotRepository, + geneticClassRepository, + geneticWorthRepository, + seedlotSourceRepository, + seedlotStatusRepository); this.seedlotParentTreeRepository = seedlotParentTreeRepository; this.seedlotParentTreeGeneticQualityRepository = seedlotParentTreeGeneticQualityRepository; } diff --git a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotParentTreeRelationalTest.java b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotParentTreeRelationalTest.java index 1df6db53b..444b443d8 100644 --- a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotParentTreeRelationalTest.java +++ b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotParentTreeRelationalTest.java @@ -10,6 +10,7 @@ import ca.bc.gov.backendstartapi.repository.SeedlotParentTreeRepository; import ca.bc.gov.backendstartapi.repository.SeedlotRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSourceRepository; +import ca.bc.gov.backendstartapi.repository.SeedlotStatusRepository; import java.math.BigDecimal; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -28,9 +29,14 @@ class SeedlotParentTreeRelationalTest extends SeedlotEntityRelationalTest { GeneticClassRepository geneticClassRepository, SeedlotParentTreeRepository seedlotParentTreeRepository, GeneticWorthRepository geneticWorthRepository, - SeedlotSourceRepository seedlotSourceRepository) { + SeedlotSourceRepository seedlotSourceRepository, + SeedlotStatusRepository seedlotStatusRepository) { super( - seedlotRepository, geneticClassRepository, geneticWorthRepository, seedlotSourceRepository); + seedlotRepository, + geneticClassRepository, + geneticWorthRepository, + seedlotSourceRepository, + seedlotStatusRepository); this.repository = seedlotParentTreeRepository; } diff --git a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotParentTreeSmpMixRelationalTest.java b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotParentTreeSmpMixRelationalTest.java index 7aa92a01d..6ab3bcc60 100644 --- a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotParentTreeSmpMixRelationalTest.java +++ b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotParentTreeSmpMixRelationalTest.java @@ -13,6 +13,7 @@ import ca.bc.gov.backendstartapi.repository.SeedlotParentTreeSmpMixRepository; import ca.bc.gov.backendstartapi.repository.SeedlotRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSourceRepository; +import ca.bc.gov.backendstartapi.repository.SeedlotStatusRepository; import java.math.BigDecimal; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -34,9 +35,14 @@ class SeedlotParentTreeSmpMixRelationalTest extends SeedlotEntityRelationalTest SeedlotParentTreeRepository seedlotParentTreeRepository, SeedlotParentTreeSmpMixRepository seedlotParentTreeSmpMixRepository, GeneticWorthRepository geneticWorthRepository, - SeedlotSourceRepository seedlotSourceRepository) { + SeedlotSourceRepository seedlotSourceRepository, + SeedlotStatusRepository seedlotStatusRepository) { super( - seedlotRepository, geneticClassRepository, geneticWorthRepository, seedlotSourceRepository); + seedlotRepository, + geneticClassRepository, + geneticWorthRepository, + seedlotSourceRepository, + seedlotStatusRepository); this.seedlotParentTreeRepository = seedlotParentTreeRepository; this.seedlotParentTreeSmpMixRepository = seedlotParentTreeSmpMixRepository; } diff --git a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotRelationalTest.java b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotRelationalTest.java index 300501739..b9db55804 100644 --- a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotRelationalTest.java +++ b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SeedlotRelationalTest.java @@ -8,6 +8,7 @@ import ca.bc.gov.backendstartapi.repository.GeneticWorthRepository; import ca.bc.gov.backendstartapi.repository.SeedlotRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSourceRepository; +import ca.bc.gov.backendstartapi.repository.SeedlotStatusRepository; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import org.junit.jupiter.api.Test; @@ -23,9 +24,14 @@ class SeedlotRelationalTest extends SeedlotEntityRelationalTest { SeedlotRepository seedlotRepository, GeneticClassRepository geneticClassRepository, GeneticWorthRepository geneticWorthRepository, - SeedlotSourceRepository seedlotSourceRepository) { + SeedlotSourceRepository seedlotSourceRepository, + SeedlotStatusRepository seedlotStatusRepository) { super( - seedlotRepository, geneticClassRepository, geneticWorthRepository, seedlotSourceRepository); + seedlotRepository, + geneticClassRepository, + geneticWorthRepository, + seedlotSourceRepository, + seedlotStatusRepository); } @Test diff --git a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SmpMixGeneticQualityRelationalTest.java b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SmpMixGeneticQualityRelationalTest.java index f58d24b8a..f56d4c4b4 100644 --- a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SmpMixGeneticQualityRelationalTest.java +++ b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SmpMixGeneticQualityRelationalTest.java @@ -11,6 +11,7 @@ import ca.bc.gov.backendstartapi.repository.GeneticWorthRepository; import ca.bc.gov.backendstartapi.repository.SeedlotRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSourceRepository; +import ca.bc.gov.backendstartapi.repository.SeedlotStatusRepository; import ca.bc.gov.backendstartapi.repository.SmpMixGeneticQualityRepository; import ca.bc.gov.backendstartapi.repository.SmpMixRepository; import java.math.BigDecimal; @@ -34,9 +35,14 @@ class SmpMixGeneticQualityRelationalTest extends SeedlotEntityRelationalTest { SmpMixRepository smpMixRepository, SmpMixGeneticQualityRepository smpMixGeneticQualityRepository, GeneticWorthRepository geneticWorthRepository, - SeedlotSourceRepository seedlotSourceRepository) { + SeedlotSourceRepository seedlotSourceRepository, + SeedlotStatusRepository seedlotStatusRepository) { super( - seedlotRepository, geneticClassRepository, geneticWorthRepository, seedlotSourceRepository); + seedlotRepository, + geneticClassRepository, + geneticWorthRepository, + seedlotSourceRepository, + seedlotStatusRepository); this.smpMixRepository = smpMixRepository; repository = smpMixGeneticQualityRepository; } diff --git a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SmpMixRelationalTest.java b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SmpMixRelationalTest.java index 41a5012aa..4469cbc20 100644 --- a/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SmpMixRelationalTest.java +++ b/backend/src/test/java/ca/bc/gov/backendstartapi/repository/seedlot/SmpMixRelationalTest.java @@ -9,6 +9,7 @@ import ca.bc.gov.backendstartapi.repository.GeneticWorthRepository; import ca.bc.gov.backendstartapi.repository.SeedlotRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSourceRepository; +import ca.bc.gov.backendstartapi.repository.SeedlotStatusRepository; import ca.bc.gov.backendstartapi.repository.SmpMixRepository; import java.math.BigDecimal; import org.junit.jupiter.api.Test; @@ -28,9 +29,14 @@ class SmpMixRelationalTest extends SeedlotEntityRelationalTest { GeneticClassRepository geneticClassRepository, SmpMixRepository smpMixRepository, GeneticWorthRepository geneticWorthRepository, - SeedlotSourceRepository seedlotSourceRepository) { + SeedlotSourceRepository seedlotSourceRepository, + SeedlotStatusRepository seedlotStatusRepository) { super( - seedlotRepository, geneticClassRepository, geneticWorthRepository, seedlotSourceRepository); + seedlotRepository, + geneticClassRepository, + geneticWorthRepository, + seedlotSourceRepository, + seedlotStatusRepository); repository = smpMixRepository; } diff --git a/backend/src/test/java/ca/bc/gov/backendstartapi/service/SeedlotCollectionMethodServiceTest.java b/backend/src/test/java/ca/bc/gov/backendstartapi/service/SeedlotCollectionMethodServiceTest.java index 297bda1ea..786bf164e 100644 --- a/backend/src/test/java/ca/bc/gov/backendstartapi/service/SeedlotCollectionMethodServiceTest.java +++ b/backend/src/test/java/ca/bc/gov/backendstartapi/service/SeedlotCollectionMethodServiceTest.java @@ -12,7 +12,7 @@ import ca.bc.gov.backendstartapi.repository.SeedlotCollectionMethodRepository; import ca.bc.gov.backendstartapi.security.LoggedUserService; import java.math.BigDecimal; -import java.time.LocalDateTime; +import java.time.LocalDate; import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -37,8 +37,8 @@ private SeedlotFormCollectionDto createFormDto(Integer... methods) { return new SeedlotFormCollectionDto( "00012797", "02", - LocalDateTime.now(), - LocalDateTime.now(), + LocalDate.now(), + LocalDate.now(), new BigDecimal("2"), new BigDecimal("4"), new BigDecimal("8"), @@ -60,7 +60,7 @@ void saveSeedlotFormStep1_firstSubmit_shouldSucceed() { ConeCollectionMethodEntity ccme = new ConeCollectionMethodEntity(); ccme.setConeCollectionMethodCode(1); - when(coneCollectionMethodService.getAllValidConeCollectionMethods()).thenReturn(List.of(ccme)); + when(coneCollectionMethodService.getAllByIdIn(List.of(1))).thenReturn(List.of(ccme)); AuditInformation audit = new AuditInformation("userId"); when(loggedUserService.createAuditCurrentUser()).thenReturn(audit); @@ -95,8 +95,7 @@ void saveSeedlotFormStep1_updateSeedlotAdd_shouldSucceed() { ConeCollectionMethodEntity ccme2 = new ConeCollectionMethodEntity(); ccme2.setConeCollectionMethodCode(2); - when(coneCollectionMethodService.getAllValidConeCollectionMethods()) - .thenReturn(List.of(ccme1, ccme2)); + when(coneCollectionMethodService.getAllByIdIn(List.of(1, 2))).thenReturn(List.of(ccme1, ccme2)); AuditInformation audit = new AuditInformation("userId"); when(loggedUserService.createAuditCurrentUser()).thenReturn(audit); @@ -134,8 +133,7 @@ void saveSeedlotFormStep1_updateSeedlotEqual_shouldSucceed() { when(seedlotCollectionMethodRepository.findAllBySeedlot_id("54321")) .thenReturn(List.of(scm, scm2)); - when(coneCollectionMethodService.getAllValidConeCollectionMethods()) - .thenReturn(List.of(ccme1, ccme2)); + when(coneCollectionMethodService.getAllByIdIn(List.of(1, 2))).thenReturn(List.of(ccme1, ccme2)); AuditInformation audit = new AuditInformation("userId"); when(loggedUserService.createAuditCurrentUser()).thenReturn(audit); @@ -171,15 +169,14 @@ void saveSeedlotFormStep1_updateSeedlotRemove_shouldSucceed() { when(seedlotCollectionMethodRepository.findAllBySeedlot_id("54321")) .thenReturn(List.of(scm, scm2)); - when(coneCollectionMethodService.getAllValidConeCollectionMethods()) - .thenReturn(List.of(ccme1, ccme2)); + when(coneCollectionMethodService.getAllByIdIn(List.of(1))).thenReturn(List.of(ccme1, ccme2)); AuditInformation audit = new AuditInformation("userId"); when(loggedUserService.createAuditCurrentUser()).thenReturn(audit); when(seedlotCollectionMethodRepository.saveAllAndFlush(any())).thenReturn(List.of()); - SeedlotFormCollectionDto formDto = createFormDto(); + SeedlotFormCollectionDto formDto = createFormDto(1); seedCollectionMethodService.saveSeedlotFormStep1(seedlot, formDto, true); Assertions.assertNotNull(seedlot); diff --git a/backend/src/test/java/ca/bc/gov/backendstartapi/service/SeedlotFormPutTest.java b/backend/src/test/java/ca/bc/gov/backendstartapi/service/SeedlotFormPutTest.java index 23f58341e..6373affa6 100644 --- a/backend/src/test/java/ca/bc/gov/backendstartapi/service/SeedlotFormPutTest.java +++ b/backend/src/test/java/ca/bc/gov/backendstartapi/service/SeedlotFormPutTest.java @@ -37,14 +37,12 @@ import ca.bc.gov.backendstartapi.exception.SmpMixNotFoundException; import ca.bc.gov.backendstartapi.provider.Provider; import ca.bc.gov.backendstartapi.repository.GeneticClassRepository; -import ca.bc.gov.backendstartapi.repository.SeedlotCollectionMethodRepository; -import ca.bc.gov.backendstartapi.repository.SeedlotOwnerQuantityRepository; import ca.bc.gov.backendstartapi.repository.SeedlotRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSeedPlanZoneRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSourceRepository; -import ca.bc.gov.backendstartapi.repository.SeedlotStatusRepository; import ca.bc.gov.backendstartapi.security.LoggedUserService; import java.math.BigDecimal; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; import java.util.Optional; @@ -63,20 +61,14 @@ class SeedlotFormPutTest { @Mock SeedlotSourceRepository seedlotSourceRepository; - @Mock SeedlotStatusRepository seedlotStatusRepository; - @Mock GeneticClassRepository geneticClassRepository; @Mock LoggedUserService loggedUserService; @Mock SeedlotCollectionMethodService seedlotCollectionMethodService; - @Mock SeedlotCollectionMethodRepository seedlotCollectionMethodRepository; - @Mock SeedlotOwnerQuantityService seedlotOwnerQuantityService; - @Mock SeedlotOwnerQuantityRepository seedlotOwnerQuantityRepository; - @Mock SeedlotOrchardService seedlotOrchardService; @Mock SeedlotParentTreeService seedlotParentTreeService; @@ -109,13 +101,10 @@ void setup() { new SeedlotService( seedlotRepository, seedlotSourceRepository, - seedlotStatusRepository, geneticClassRepository, loggedUserService, seedlotCollectionMethodService, - seedlotCollectionMethodRepository, seedlotOwnerQuantityService, - seedlotOwnerQuantityRepository, seedlotOrchardService, seedlotParentTreeService, seedlotParentTreeGeneticQualityService, @@ -143,8 +132,8 @@ private SeedlotFormSubmissionDto mockSeedlotFormDto( new SeedlotFormCollectionDto( "00012797", "02", - LocalDateTime.now(), - LocalDateTime.now(), + LocalDate.now(), + LocalDate.now(), new BigDecimal("2"), new BigDecimal("4"), new BigDecimal("8"), @@ -167,8 +156,8 @@ private SeedlotFormSubmissionDto mockSeedlotFormDto( new SeedlotFormInterimDto( "00012797", "02", - LocalDateTime.now(), - LocalDateTime.now(), + LocalDate.now(), + LocalDate.now(), itermFacilityDesc, optionalFacilityCode); @@ -198,12 +187,12 @@ private SeedlotFormSubmissionDto mockSeedlotFormDto( new SeedlotFormExtractionDto( "00012797", "02", - LocalDateTime.now(), - LocalDateTime.now(), + LocalDate.now(), + LocalDate.now(), "00012797", "02", - LocalDateTime.now(), - LocalDateTime.now()); + LocalDate.now(), + LocalDate.now()); return new SeedlotFormSubmissionDto( collectionDto, diff --git a/backend/src/test/java/ca/bc/gov/backendstartapi/service/SeedlotOwnerQuantityServiceTest.java b/backend/src/test/java/ca/bc/gov/backendstartapi/service/SeedlotOwnerQuantityServiceTest.java index d6d18f7cb..646bb461f 100644 --- a/backend/src/test/java/ca/bc/gov/backendstartapi/service/SeedlotOwnerQuantityServiceTest.java +++ b/backend/src/test/java/ca/bc/gov/backendstartapi/service/SeedlotOwnerQuantityServiceTest.java @@ -71,13 +71,13 @@ void saveSeedlotFormStep2_firstSubmit_shouldSucceed() { MethodOfPaymentEntity mope = new MethodOfPaymentEntity(); mope.setMethodOfPaymentCode("CLA"); - when(methodOfPaymentService.getAllValidMethodOfPayments()).thenReturn(List.of(mope)); + when(methodOfPaymentService.getAllMethodsByCodeList(List.of("CLA"))).thenReturn(List.of(mope)); AuditInformation audit = new AuditInformation("userId"); when(loggedUserService.createAuditCurrentUser()).thenReturn(audit); Seedlot seedlot = new Seedlot("54321"); - SeedlotOwnerQuantity soq = new SeedlotOwnerQuantity(seedlot, "00012797", "02"); + SeedlotOwnerQuantity soq = new SeedlotOwnerQuantity(seedlot, "00012797", "02", mope); when(seedlotOwnerQuantityRepository.saveAll(any())).thenReturn(List.of(soq)); List soqList = @@ -90,22 +90,22 @@ void saveSeedlotFormStep2_firstSubmit_shouldSucceed() { @Test @DisplayName("Save Seedlot Owner Quantity with one new method") void saveSeedlotFormStep2_updateSeedlotAdd_shouldSucceed() { - Seedlot seedlot = new Seedlot("54321"); - ConeCollectionMethodEntity ccme1 = new ConeCollectionMethodEntity(); ccme1.setConeCollectionMethodCode(1); - SeedlotOwnerQuantity soq = new SeedlotOwnerQuantity(seedlot, "00012797", "01"); - when(seedlotOwnerQuantityRepository.findAllBySeedlot_id("54321")).thenReturn(List.of(soq)); - MethodOfPaymentEntity mope = new MethodOfPaymentEntity(); mope.setMethodOfPaymentCode("CLA"); - when(methodOfPaymentService.getAllValidMethodOfPayments()).thenReturn(List.of(mope)); + when(methodOfPaymentService.getAllMethodsByCodeList(List.of("CLA"))).thenReturn(List.of(mope)); + + Seedlot seedlot = new Seedlot("54321"); + + SeedlotOwnerQuantity soq = new SeedlotOwnerQuantity(seedlot, "00012797", "01", mope); + when(seedlotOwnerQuantityRepository.findAllBySeedlot_id("54321")).thenReturn(List.of(soq)); AuditInformation audit = new AuditInformation("userId"); when(loggedUserService.createAuditCurrentUser()).thenReturn(audit); - SeedlotOwnerQuantity soq2 = new SeedlotOwnerQuantity(seedlot, "00012797", "02"); + SeedlotOwnerQuantity soq2 = new SeedlotOwnerQuantity(seedlot, "00012797", "02", mope); when(seedlotOwnerQuantityRepository.saveAll(any())).thenReturn(List.of(soq, soq2)); List soqList = @@ -118,19 +118,19 @@ void saveSeedlotFormStep2_updateSeedlotAdd_shouldSucceed() { @Test @DisplayName("Save Seedlot Owner Quantity with two already existing") void saveSeedlotFormStep2_updateSeedlotEqual_shouldSucceed() { - Seedlot seedlot = new Seedlot("54321"); - ConeCollectionMethodEntity ccme1 = new ConeCollectionMethodEntity(); ccme1.setConeCollectionMethodCode(1); - SeedlotOwnerQuantity soq = new SeedlotOwnerQuantity(seedlot, "00012797", "01"); - SeedlotOwnerQuantity soq2 = new SeedlotOwnerQuantity(seedlot, "00012797", "02"); - when(seedlotOwnerQuantityRepository.findAllBySeedlot_id("54321")) - .thenReturn(List.of(soq, soq2)); - MethodOfPaymentEntity mope = new MethodOfPaymentEntity(); mope.setMethodOfPaymentCode("CLA"); - when(methodOfPaymentService.getAllValidMethodOfPayments()).thenReturn(List.of(mope)); + when(methodOfPaymentService.getAllMethodsByCodeList(List.of("CLA"))).thenReturn(List.of(mope)); + + Seedlot seedlot = new Seedlot("54321"); + + SeedlotOwnerQuantity soq = new SeedlotOwnerQuantity(seedlot, "00012797", "01", mope); + SeedlotOwnerQuantity soq2 = new SeedlotOwnerQuantity(seedlot, "00012797", "02", mope); + when(seedlotOwnerQuantityRepository.findAllBySeedlot_id("54321")) + .thenReturn(List.of(soq, soq2)); AuditInformation audit = new AuditInformation("userId"); when(loggedUserService.createAuditCurrentUser()).thenReturn(audit); @@ -146,19 +146,19 @@ void saveSeedlotFormStep2_updateSeedlotEqual_shouldSucceed() { @Test @DisplayName("Save Seedlot Owner Quantity with one method removed") void saveSeedlotFormStep2_updateSeedlotRemove_shouldSucceed() { - Seedlot seedlot = new Seedlot("54321"); - ConeCollectionMethodEntity ccme1 = new ConeCollectionMethodEntity(); ccme1.setConeCollectionMethodCode(1); - SeedlotOwnerQuantity soq = new SeedlotOwnerQuantity(seedlot, "00012797", "01"); - SeedlotOwnerQuantity soq2 = new SeedlotOwnerQuantity(seedlot, "00012797", "02"); - when(seedlotOwnerQuantityRepository.findAllBySeedlot_id("54321")) - .thenReturn(List.of(soq, soq2)); - MethodOfPaymentEntity mope = new MethodOfPaymentEntity(); mope.setMethodOfPaymentCode("CLA"); - when(methodOfPaymentService.getAllValidMethodOfPayments()).thenReturn(List.of(mope)); + when(methodOfPaymentService.getAllMethodsByCodeList(List.of("CLA"))).thenReturn(List.of(mope)); + + Seedlot seedlot = new Seedlot("54321"); + + SeedlotOwnerQuantity soq = new SeedlotOwnerQuantity(seedlot, "00012797", "01", mope); + SeedlotOwnerQuantity soq2 = new SeedlotOwnerQuantity(seedlot, "00012797", "02", mope); + when(seedlotOwnerQuantityRepository.findAllBySeedlot_id("54321")) + .thenReturn(List.of(soq, soq2)); AuditInformation audit = new AuditInformation("userId"); when(loggedUserService.createAuditCurrentUser()).thenReturn(audit); diff --git a/backend/src/test/java/ca/bc/gov/backendstartapi/service/SeedlotServiceTest.java b/backend/src/test/java/ca/bc/gov/backendstartapi/service/SeedlotServiceTest.java index 7e3f93e1e..4b3e90754 100644 --- a/backend/src/test/java/ca/bc/gov/backendstartapi/service/SeedlotServiceTest.java +++ b/backend/src/test/java/ca/bc/gov/backendstartapi/service/SeedlotServiceTest.java @@ -55,18 +55,16 @@ import ca.bc.gov.backendstartapi.exception.SeedlotSourceNotFoundException; import ca.bc.gov.backendstartapi.provider.Provider; import ca.bc.gov.backendstartapi.repository.GeneticClassRepository; -import ca.bc.gov.backendstartapi.repository.SeedlotCollectionMethodRepository; -import ca.bc.gov.backendstartapi.repository.SeedlotOwnerQuantityRepository; import ca.bc.gov.backendstartapi.repository.SeedlotRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSeedPlanZoneRepository; import ca.bc.gov.backendstartapi.repository.SeedlotSourceRepository; -import ca.bc.gov.backendstartapi.repository.SeedlotStatusRepository; import ca.bc.gov.backendstartapi.security.LoggedUserService; import ca.bc.gov.backendstartapi.security.UserInfo; import java.math.BigDecimal; import java.time.LocalDate; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -84,20 +82,14 @@ class SeedlotServiceTest { @Mock SeedlotSourceRepository seedlotSourceRepository; - @Mock SeedlotStatusRepository seedlotStatusRepository; - @Mock GeneticClassRepository geneticClassRepository; @Mock LoggedUserService loggedUserService; @Mock SeedlotCollectionMethodService seedlotCollectionMethodService; - @Mock SeedlotCollectionMethodRepository seedlotCollectionMethodRepository; - @Mock SeedlotOwnerQuantityService seedlotOwnerQuantityService; - @Mock SeedlotOwnerQuantityRepository seedlotOwnerQuantityRepository; - @Mock SeedlotOrchardService seedlotOrchardService; @Mock SeedlotParentTreeService seedlotParentTreeService; @@ -163,13 +155,10 @@ void setup() { new SeedlotService( seedlotRepository, seedlotSourceRepository, - seedlotStatusRepository, geneticClassRepository, loggedUserService, seedlotCollectionMethodService, - seedlotCollectionMethodRepository, seedlotOwnerQuantityService, - seedlotOwnerQuantityRepository, seedlotOrchardService, seedlotParentTreeService, seedlotParentTreeGeneticQualityService, @@ -191,7 +180,7 @@ void createSeedlotTest_happyPath_shouldSucceed() { when(seedlotRepository.findNextSeedlotNumber(anyInt(), anyInt())).thenReturn(63000); SeedlotStatusEntity statusEntity = new SeedlotStatusEntity("PND", "Pending", DATE_RANGE); - when(seedlotStatusRepository.findById("PND")).thenReturn(Optional.of(statusEntity)); + when(seedlotStatusService.findById("PND")).thenReturn(Optional.of(statusEntity)); SeedlotSourceEntity sourceEntity = new SeedlotSourceEntity("TPT", "Tested Parent Trees", DATE_RANGE, null); @@ -233,7 +222,7 @@ void createSeedlotTest_bClassSeedlot_shouldThrowException() { void createSeedlotTest_noSeedlotStatus_shouldThrowException() { when(seedlotRepository.findNextSeedlotNumber(anyInt(), anyInt())).thenReturn(63000); - when(seedlotStatusRepository.findById("PND")).thenReturn(Optional.empty()); + when(seedlotStatusService.findById("PND")).thenReturn(Optional.empty()); Exception exc = Assertions.assertThrows( @@ -249,7 +238,7 @@ void createSeedlotTest_noSeedlotStatus_shouldThrowException() { @DisplayName("createSeedlotAClassWithoutGeneticClassEntity") void createSeedlotTest_noGeneticClass_shouldThrowException() { SeedlotStatusEntity statusEntity = new SeedlotStatusEntity("PND", "Pending", DATE_RANGE); - when(seedlotStatusRepository.findById("PND")).thenReturn(Optional.of(statusEntity)); + when(seedlotStatusService.findById("PND")).thenReturn(Optional.of(statusEntity)); when(geneticClassRepository.findById("A")).thenReturn(Optional.empty()); @@ -269,7 +258,7 @@ void createSeedlotTest_noSeedlotSource_shouldThrowException() { when(seedlotRepository.findNextSeedlotNumber(anyInt(), anyInt())).thenReturn(63000); SeedlotStatusEntity statusEntity = new SeedlotStatusEntity("PND", "Pending", DATE_RANGE); - when(seedlotStatusRepository.findById("PND")).thenReturn(Optional.of(statusEntity)); + when(seedlotStatusService.findById("PND")).thenReturn(Optional.of(statusEntity)); GeneticClassEntity classEntity = new GeneticClassEntity("A", "A class seedlot", DATE_RANGE); when(geneticClassRepository.findById("A")).thenReturn(Optional.of(classEntity)); @@ -539,11 +528,12 @@ void findAclassSeedlotFormFullDataSuccessTest() { final List collectionMethods = List.of(new SeedlotCollectionMethod(seedlotEntity, new ConeCollectionMethodEntity())); + MethodOfPaymentEntity mope = new MethodOfPaymentEntity(methodOfPayment, "", null); SeedlotOwnerQuantity seedlotOwners = - new SeedlotOwnerQuantity(seedlotEntity, ownerNumber, ownerLoc); + new SeedlotOwnerQuantity(seedlotEntity, ownerNumber, ownerLoc, mope); BigDecimal originalPercentOwned = new BigDecimal(100); seedlotOwners.setOriginalPercentageOwned(originalPercentOwned); - seedlotOwners.setMethodOfPayment(new MethodOfPaymentEntity(methodOfPayment, "", null)); + seedlotOwners.setMethodOfPayment(mope); String orchardId = "100"; @@ -561,9 +551,14 @@ void findAclassSeedlotFormFullDataSuccessTest() { when(seedlotParentTreeSmpMixService.getAllBySeedlotNumber(seedlotNumber)) .thenReturn(parentTreeSmpMixData); when(seedlotGeneticWorthService.getAllBySeedlotNumber(seedlotNumber)).thenReturn(genWorthData); - when(seedlotCollectionMethodRepository.findAllBySeedlot_id(seedlotNumber)) - .thenReturn(collectionMethods); - when(seedlotOwnerQuantityRepository.findAllBySeedlot_id(seedlotNumber)) + + when(seedlotCollectionMethodService.getAllSeedlotCollectionMethodsBySeedlot(seedlotNumber)) + .thenReturn( + collectionMethods.stream() + .map(col -> col.getConeCollectionMethod().getConeCollectionMethodCode()) + .collect(Collectors.toList())); + + when(seedlotOwnerQuantityService.findAllBySeedlot(seedlotNumber)) .thenReturn(List.of(seedlotOwners)); when(seedlotOrchardService.getAllSeedlotOrchardBySeedlotNumber(seedlotNumber)) .thenReturn(seedlotOrchards); diff --git a/backend/src/test/java/ca/bc/gov/backendstartapi/util/ValueUtilTest.java b/backend/src/test/java/ca/bc/gov/backendstartapi/util/ValueUtilTest.java new file mode 100644 index 000000000..e4f24a165 --- /dev/null +++ b/backend/src/test/java/ca/bc/gov/backendstartapi/util/ValueUtilTest.java @@ -0,0 +1,91 @@ +package ca.bc.gov.backendstartapi.util; + +import ca.bc.gov.backendstartapi.entity.seedlot.Seedlot; +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class ValueUtilTest { + + @Test + void hasValueFalseTest() { + Assertions.assertFalse(ValueUtil.hasValue(null)); + Assertions.assertFalse(ValueUtil.hasValue("")); + Assertions.assertFalse(ValueUtil.hasValue(" ")); + Assertions.assertFalse(ValueUtil.hasValue(BigDecimal.ZERO)); + Assertions.assertFalse(ValueUtil.hasValue(Integer.valueOf(0))); + Assertions.assertFalse(ValueUtil.hasValue(Character.valueOf(' '))); + Assertions.assertFalse(ValueUtil.hasValue(Long.valueOf(0L))); + Assertions.assertFalse(ValueUtil.hasValue(Double.valueOf(0D))); + Assertions.assertFalse(ValueUtil.hasValue(List.of())); + Assertions.assertFalse(ValueUtil.hasValue(Optional.empty())); + // Class not handled: + Assertions.assertFalse(ValueUtil.hasValue(new Seedlot("1"))); + } + + @Test + void hasValueTrueTest() { + Assertions.assertTrue(ValueUtil.hasValue("any")); + Assertions.assertTrue(ValueUtil.hasValue(BigDecimal.ONE)); + Assertions.assertTrue(ValueUtil.hasValue(BigDecimal.ONE.negate())); + Assertions.assertTrue(ValueUtil.hasValue(Integer.valueOf(155))); + Assertions.assertTrue(ValueUtil.hasValue(Integer.MIN_VALUE)); + Assertions.assertTrue(ValueUtil.hasValue(Character.valueOf('A'))); + Assertions.assertTrue(ValueUtil.hasValue(Character.valueOf('\\'))); + Assertions.assertTrue(ValueUtil.hasValue(Character.valueOf('@'))); + Assertions.assertTrue(ValueUtil.hasValue(LocalDateTime.now())); + Assertions.assertTrue(ValueUtil.hasValue(LocalDate.now())); + Assertions.assertTrue(ValueUtil.hasValue(Long.valueOf(155L))); + Assertions.assertTrue(ValueUtil.hasValue(Long.MIN_VALUE)); + Assertions.assertTrue(ValueUtil.hasValue(Double.valueOf(999.698D))); + Assertions.assertTrue(ValueUtil.hasValue(Double.valueOf(-999.698D))); + Assertions.assertTrue(ValueUtil.hasValue(List.of(11))); + Assertions.assertTrue(ValueUtil.hasValue(List.of("23"))); + Assertions.assertTrue(ValueUtil.hasValue(Boolean.TRUE)); + Assertions.assertTrue(ValueUtil.hasValue(Boolean.FALSE)); + Assertions.assertTrue(ValueUtil.hasValue(Optional.of(123))); + } + + @Test + void isValueEqualFalseTest() { + Assertions.assertFalse(ValueUtil.isValueEqual(null, null)); + Assertions.assertFalse(ValueUtil.isValueEqual(0, "0")); + Assertions.assertFalse(ValueUtil.isValueEqual(Integer.valueOf(99), "99")); + Assertions.assertFalse(ValueUtil.isValueEqual("0", "00")); + Assertions.assertFalse(ValueUtil.isValueEqual(new BigDecimal("11"), new BigDecimal("1"))); + Assertions.assertFalse(ValueUtil.isValueEqual(Integer.valueOf(0), Integer.valueOf(0))); + Assertions.assertFalse(ValueUtil.isValueEqual(Integer.valueOf(0), Integer.valueOf(1))); + Assertions.assertFalse(ValueUtil.isValueEqual(Integer.valueOf(0), 0)); + Assertions.assertFalse(ValueUtil.isValueEqual(Character.valueOf('A'), Character.valueOf(' '))); + Assertions.assertFalse(ValueUtil.isValueEqual(' ', Character.valueOf(' '))); + Assertions.assertFalse(ValueUtil.isValueEqual(LocalDateTime.now(), LocalDateTime.now())); + Assertions.assertFalse( + ValueUtil.isValueEqual(LocalDateTime.now(), LocalDateTime.now().minusSeconds(1L))); + Assertions.assertFalse(ValueUtil.isValueEqual(LocalDate.now(), LocalDate.now().minusDays(1L))); + Assertions.assertFalse(ValueUtil.isValueEqual(Long.valueOf(1L), Long.valueOf(0L))); + Assertions.assertFalse(ValueUtil.isValueEqual(Double.valueOf(1D), Double.valueOf(0D))); + Assertions.assertFalse(ValueUtil.isValueEqual(Boolean.FALSE, Boolean.TRUE)); + } + + @Test + void isValueEqualTrueTest() { + final LocalDateTime localDateTime = LocalDateTime.now(); + final LocalDate localDate = LocalDate.now(); + + Assertions.assertTrue(ValueUtil.isValueEqual("0", "0")); + Assertions.assertTrue(ValueUtil.isValueEqual(new BigDecimal("11"), new BigDecimal("11.00"))); + Assertions.assertTrue(ValueUtil.isValueEqual(Integer.valueOf(1), Integer.valueOf(1))); + Assertions.assertTrue(ValueUtil.isValueEqual('A', Character.valueOf('A'))); + Assertions.assertTrue(ValueUtil.isValueEqual(localDateTime, localDateTime)); + Assertions.assertTrue(ValueUtil.isValueEqual(localDate, localDate)); + Assertions.assertTrue(ValueUtil.isValueEqual(Long.valueOf(1L), Long.valueOf(1L))); + Assertions.assertTrue(ValueUtil.isValueEqual(Double.valueOf(1D), Double.valueOf(1D))); + Assertions.assertTrue(ValueUtil.isValueEqual(Boolean.FALSE, Boolean.FALSE)); + Assertions.assertTrue(ValueUtil.isValueEqual(Boolean.TRUE, Boolean.TRUE)); + Assertions.assertTrue(ValueUtil.isValueEqual(true, Boolean.TRUE)); + } +} diff --git a/oracle-api/src/main/java/ca/bc/gov/oracleapi/entity/OrchardEntity.java b/oracle-api/src/main/java/ca/bc/gov/oracleapi/entity/OrchardEntity.java index d3517532d..9eaedabf0 100644 --- a/oracle-api/src/main/java/ca/bc/gov/oracleapi/entity/OrchardEntity.java +++ b/oracle-api/src/main/java/ca/bc/gov/oracleapi/entity/OrchardEntity.java @@ -3,6 +3,7 @@ import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; @@ -29,8 +30,11 @@ public class OrchardEntity { @Column(name = "VEGETATION_CODE", length = 8) private String vegetationCode; - @ManyToOne(cascade = CascadeType.ALL) - @JoinColumn(name = "ORCHARD_LOT_TYPE_CODE", referencedColumnName = "ORCHARD_LOT_TYPE_CODE") + @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + @JoinColumn( + name = "ORCHARD_LOT_TYPE_CODE", + referencedColumnName = "ORCHARD_LOT_TYPE_CODE", + updatable = false) private OrchardLotTypeCode orchardLotTypeCode; @Column(name = "ORCHARD_STAGE_CODE", length = 3) diff --git a/oracle-api/src/main/java/ca/bc/gov/oracleapi/entity/SeedPlanZone.java b/oracle-api/src/main/java/ca/bc/gov/oracleapi/entity/SeedPlanZone.java index 2c4128f44..22038fbe4 100644 --- a/oracle-api/src/main/java/ca/bc/gov/oracleapi/entity/SeedPlanZone.java +++ b/oracle-api/src/main/java/ca/bc/gov/oracleapi/entity/SeedPlanZone.java @@ -2,6 +2,7 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; @@ -26,11 +27,11 @@ public class SeedPlanZone { @Column(name = "GENETIC_CLASS_CODE", nullable = false) private Character geneticClassCode; - @ManyToOne - @JoinColumn(name = "SEED_PLAN_ZONE_CODE") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "SEED_PLAN_ZONE_CODE", updatable = false) private SeedPlanZoneCode seedPlanZoneCode; - @ManyToOne - @JoinColumn(name = "VEGETATION_CODE") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "VEGETATION_CODE", updatable = false) private VegetationCode vegetationCode; } diff --git a/oracle-api/src/main/java/ca/bc/gov/oracleapi/entity/TestedPtAreaOfUseSpz.java b/oracle-api/src/main/java/ca/bc/gov/oracleapi/entity/TestedPtAreaOfUseSpz.java index 39141cbea..e53727a7e 100644 --- a/oracle-api/src/main/java/ca/bc/gov/oracleapi/entity/TestedPtAreaOfUseSpz.java +++ b/oracle-api/src/main/java/ca/bc/gov/oracleapi/entity/TestedPtAreaOfUseSpz.java @@ -4,6 +4,7 @@ import jakarta.persistence.Column; import jakarta.persistence.Convert; import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; import jakarta.persistence.Id; import jakarta.persistence.IdClass; import jakarta.persistence.JoinColumn; @@ -26,14 +27,14 @@ @Table(name = "TESTED_PT_AREA_OF_USE_SPZ") public class TestedPtAreaOfUseSpz { @Id - @JoinColumn(name = "TESTED_PT_AREA_OF_USE_ID") - @ManyToOne + @JoinColumn(name = "TESTED_PT_AREA_OF_USE_ID", updatable = false) + @ManyToOne(fetch = FetchType.LAZY) @NonNull private TestedPtAreaOfUse testedPtAreaOfUse; @Id - @JoinColumn(name = "SEED_PLAN_ZONE_CODE") - @ManyToOne + @JoinColumn(name = "SEED_PLAN_ZONE_CODE", updatable = false) + @ManyToOne(fetch = FetchType.LAZY) @NonNull private SeedPlanZoneCode seedPlanZoneCode;