generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Recent backend changes and adjustments (#71)
* Bring over backend changes (mostly deletions) * Consume old secrets
- Loading branch information
1 parent
d715e63
commit 5eeeeec
Showing
10 changed files
with
541 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...c/main/java/ca/bc/gov/backendstartapi/endpoint/ActiveOrchardSeedPlanningUnitEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package ca.bc.gov.backendstartapi.endpoint; | ||
|
||
import ca.bc.gov.backendstartapi.entity.ActiveOrchardSeedPlanningUnit; | ||
import ca.bc.gov.backendstartapi.repository.ActiveOrchardSeedPlanningUnitRepository; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.util.MimeTypeUtils; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** Rest controller to fetch relations between orchards and Seed Plan Units (SPU). */ | ||
@RestController | ||
@RequestMapping(path = "/api/orchards", produces = MimeTypeUtils.APPLICATION_JSON_VALUE) | ||
@Tag(name = "Orchard") | ||
@RequiredArgsConstructor | ||
public class ActiveOrchardSeedPlanningUnitEndpoint { | ||
|
||
private final ActiveOrchardSeedPlanningUnitRepository repository; | ||
|
||
@Operation( | ||
operationId = "findSpuByOrchard", | ||
summary = "Find associations between seed plan units and an orchard", | ||
description = | ||
"Find the associations of seed plan units and the orchard identified by `orchardId`.", | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "A list of the associations between the orchard and seed plan units.") | ||
}) | ||
@GetMapping(path = "/{orchardId}/seed-plan-units") | ||
@PreAuthorize("hasRole('user_read')") | ||
public List<ActiveOrchardSeedPlanningUnit> findByOrchard( | ||
@Parameter(description = "The identifier of an orchard") @PathVariable(name = "orchardId") | ||
String orchardId, | ||
@Parameter(description = "If the association must be active or not") | ||
@RequestParam(name = "active", defaultValue = "true") | ||
boolean active) { | ||
return repository.findByOrchardIdAndActive(orchardId, active); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
backend/src/main/java/ca/bc/gov/backendstartapi/entity/ActiveOrchardSeedPlanningUnit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package ca.bc.gov.backendstartapi.entity; | ||
|
||
import ca.bc.gov.backendstartapi.entity.idclass.ActiveOrchardSeedPlanningUnitId; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.IdClass; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Setter; | ||
|
||
/** Auxiliary entity connecting an Orchard and a Seed Plan Unit (SPU). */ | ||
@Entity | ||
@Table(name = "active_orchard_spu") | ||
@IdClass(ActiveOrchardSeedPlanningUnitId.class) | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@RequiredArgsConstructor | ||
@Getter | ||
@Setter | ||
@Schema(description = "An association between an orchard and a Seed Plan Unit (SPU).") | ||
public class ActiveOrchardSeedPlanningUnit { | ||
|
||
@Id | ||
@Column(name = "orchard_id", length = 3, nullable = false) | ||
@NonNull | ||
private String orchardId; | ||
|
||
@Id | ||
@Column(name = "seed_plan_unit_id", nullable = false) | ||
@NonNull | ||
private int seedPlanningUnitId; | ||
|
||
@Column(name = "active_ind", nullable = false) | ||
@NonNull | ||
@Schema( | ||
description = | ||
"If this association is active; if `false`, it should not be used for new registries.") | ||
private boolean active; | ||
|
||
@Column(name = "retired_ind", nullable = false) | ||
@NonNull | ||
@Schema( | ||
description = | ||
""" | ||
If the orchard has been retired (e.g. is out of business); could be the reason for the | ||
inactivity of this association.""") | ||
private boolean retired; | ||
|
||
/** | ||
* If the orchard hasn't had a SPU assigned to it. If {@code true}, {@link #seedPlanningUnitId}'s | ||
* value will most likely be {@code -1}. | ||
*/ | ||
@Column(name = "no_spu_ind", nullable = false) | ||
@NonNull | ||
@Schema(description = "If this orchard has never had a SPU assigned to it.") | ||
private boolean spuNotAssigned; | ||
} |
19 changes: 19 additions & 0 deletions
19
...c/main/java/ca/bc/gov/backendstartapi/entity/idclass/ActiveOrchardSeedPlanningUnitId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ca.bc.gov.backendstartapi.entity.idclass; | ||
|
||
import ca.bc.gov.backendstartapi.entity.ActiveOrchardSeedPlanningUnit; | ||
import lombok.AccessLevel; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
/** Composite key for {@link ActiveOrchardSeedPlanningUnit}. */ | ||
@Data | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@RequiredArgsConstructor | ||
public class ActiveOrchardSeedPlanningUnitId { | ||
|
||
@NonNull private String orchardId; | ||
|
||
@NonNull private int seedPlanningUnitId; | ||
} |
13 changes: 13 additions & 0 deletions
13
...in/java/ca/bc/gov/backendstartapi/repository/ActiveOrchardSeedPlanningUnitRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ca.bc.gov.backendstartapi.repository; | ||
|
||
import ca.bc.gov.backendstartapi.entity.ActiveOrchardSeedPlanningUnit; | ||
import ca.bc.gov.backendstartapi.entity.idclass.ActiveOrchardSeedPlanningUnitId; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
/** The repository for {@link ActiveOrchardSeedPlanningUnit ActiveOrchardSeedPlanningUnits}. */ | ||
public interface ActiveOrchardSeedPlanningUnitRepository | ||
extends JpaRepository<ActiveOrchardSeedPlanningUnit, ActiveOrchardSeedPlanningUnitId> { | ||
|
||
List<ActiveOrchardSeedPlanningUnit> findByOrchardIdAndActive(String orchardId, boolean active); | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/resources/db/migration/V14__create_active_orchard_spu.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
create table spar.active_orchard_spu ( | ||
orchard_id varchar(3) not null, | ||
seed_plan_unit_id int not null, | ||
active_ind boolean not null, | ||
retired_ind boolean not null, | ||
no_spu_ind boolean not null, | ||
constraint active_orchard_spu_pk | ||
primary key(orchard_id, seed_plan_unit_id)); |
Oops, something went wrong.