Skip to content

Commit

Permalink
Recent backend changes and adjustments (#71)
Browse files Browse the repository at this point in the history
* Bring over backend changes (mostly deletions)

* Consume old secrets
  • Loading branch information
DerekRoberts committed May 14, 2024
1 parent d715e63 commit 5eeeeec
Show file tree
Hide file tree
Showing 10 changed files with 541 additions and 5 deletions.
8 changes: 4 additions & 4 deletions backend/openshift.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ objects:
- name: ALLOWED_ORIGINS
valueFrom:
secretKeyRef:
name: ${NAME}
name: ${NAME}-backend
key: allowed_origins
- name: KEYCLOAK_REALM_URL
valueFrom:
secretKeyRef:
name: ${NAME}
name: ${NAME}-backend
key: keycloak-realm-url
- name: POSTGRESQL_HOST
value: ${NAME}-${ZONE}-database
Expand All @@ -130,12 +130,12 @@ objects:
- name: FORESTCLIENTAPI_ADDRESS
valueFrom:
secretKeyRef:
name: ${NAME}
name: ${NAME}-backend
key: forest-client-api.address
- name: FORESTCLIENTAPI_KEY
valueFrom:
secretKeyRef:
name: ${NAME}
name: ${NAME}-backend
key: forest-client-api.key
ports:
- containerPort: 8090
Expand Down
2 changes: 1 addition & 1 deletion backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>ca.bc.gov</groupId>
<artifactId>nr-spar-backend</artifactId>
<version>0.18.5</version>
<version>0.19.1</version>
<name>nr-spar-backend</name>
<description>Starting backend API project</description>

Expand Down
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);
}
}
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;
}
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;
}
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);
}
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));
Loading

0 comments on commit 5eeeeec

Please sign in to comment.