Skip to content

Commit

Permalink
feat: remove updates from the tables when no changes happened
Browse files Browse the repository at this point in the history
issue #1308
  • Loading branch information
RMCampos committed Jul 29, 2024
1 parent 4ac6878 commit 3dd04f6
Show file tree
Hide file tree
Showing 34 changed files with 279 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalDate;
import java.util.List;

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

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

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

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

/** This record represents the seedlot form step 3. */
@Schema(description = "Seedlot interim information. Form step 3")
Expand Down Expand Up @@ -34,7 +34,7 @@ The actual start date (year, month, and day) when the cone was stored during int
""",
example = "2023/12/20")
@NotNull
LocalDateTime intermStrgStDate,
LocalDate intermStrgStDate,
@Schema(
description =
"""
Expand All @@ -43,9 +43,10 @@ The actual end date (year, month, and day) when the cone was stored during inter
""",
example = "2023/12/21")
@NotNull
LocalDateTime intermStrgEndDate,
LocalDate intermStrgEndDate,
@Schema(
description = """
description =
"""
Description of the storage facility type when 'Other' option is chosen.
""",
example = "Mini fridge",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ca.bc.gov.backendstartapi.endpoint;

import ca.bc.gov.backendstartapi.config.SparLog;
import ca.bc.gov.backendstartapi.dto.RevisionCountDto;
import ca.bc.gov.backendstartapi.dto.SaveSeedlotFormDtoClassA;
import ca.bc.gov.backendstartapi.dto.SeedlotAclassFormDto;
Expand Down Expand Up @@ -31,6 +32,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.io.IOException;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -206,7 +208,10 @@ public ResponseEntity<SeedlotStatusResponseDto> createSeedlot(
@RequestBody
@Valid
SeedlotCreateDto createDto) {
long started = Instant.now().toEpochMilli();
SeedlotStatusResponseDto response = seedlotService.createSeedlot(createDto);
long finished = Instant.now().toEpochMilli();
SparLog.info("Time spent: {} ms", (finished - started));
return ResponseEntity.status(HttpStatus.CREATED).body(response);
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// endregion

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,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;
Expand All @@ -31,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")
@JoinColumn(name = "seedlot_status_code", nullable = false)
@ManyToOne(fetch = FetchType.LAZY)
@NonNull
private SeedlotStatusEntity seedlotStatus;

@Column(name = "seedlot_comment", length = 2000)
Expand Down Expand Up @@ -84,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;
Expand All @@ -112,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;
Expand Down Expand Up @@ -179,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;
Expand All @@ -191,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

Expand Down
Loading

0 comments on commit 3dd04f6

Please sign in to comment.