Skip to content

Commit

Permalink
feat: 1221 spz list endpoint modification (#1225)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigyu authored Jun 24, 2024
1 parent 7da1c94 commit 1d02c07
Show file tree
Hide file tree
Showing 21 changed files with 482 additions and 443 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public HttpHeaders addHttpHeaders() {
*/
@Override
public Optional<AreaOfUseDto> getAreaOfUseData(Integer spuId) {
String oracleApiUrl = String.format("%s/api/orchards/area-of-use/spu/{spuId}", rootUri);
String oracleApiUrl = String.format("%s/api/area-of-use/spu/{spuId}", rootUri);

SparLog.info("Starting {} - {} request to {}", PROVIDER, "getAreaOfUseData", oracleApiUrl);

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api-service/ApiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const ApiConfig = {

oracleOrchards: `${oracleServerHost}/api/orchards`,

areaOfUseTestedPtSpz: `${oracleServerHost}/api/area-of-use/tested-parent-trees/spz-list`
areaOfUseSpzList: `${oracleServerHost}/api/area-of-use/spz-list/vegetation-code`
};

export default ApiConfig;
4 changes: 2 additions & 2 deletions frontend/src/api-service/areaOfUseAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import api from './api';

import { SeedPlanZoneOracleDto } from '../types/SeedlotType';

export const getSpzList = () => {
const url = ApiConfig.areaOfUseTestedPtSpz;
export const getSpzByVegCodeList = (vegCode: string) => {
const url = `${ApiConfig.areaOfUseSpzList}/${vegCode}`;
return api.get(url).then((res): SeedPlanZoneOracleDto[] => res.data);
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ClassAContext from '../../../../views/Seedlot/ContextContainerClassA/cont
import { AreaOfUseDataType } from '../../../../views/Seedlot/ContextContainerClassA/definitions';
import { FilterObj, filterInput } from '../../../../utils/FilterUtils';
import ComboBoxEvent from '../../../../types/ComboBoxEvent';
import { getSpzList } from '../../../../api-service/areaOfUseAPI';
import { getSpzByVegCodeList } from '../../../../api-service/areaOfUseAPI';
import { THREE_HALF_HOURS, THREE_HOURS } from '../../../../config/TimeUnits';
import MultiOptionsObj from '../../../../types/MultiOptionsObject';
import { EmptyMultiOptObj } from '../../../../shared-constants/shared-constants';
Expand All @@ -29,14 +29,15 @@ import { COMMENT_ERR_MSG, MAX_COMMENT_LENGTH } from '../constants';
const AreaOfUseEdit = () => {
const {
isFetchingData: isFetchingContextData, areaOfUseData,
setAreaOfUseData
seedlotData, setAreaOfUseData
} = useContext(ClassAContext);

const spzListQuery = useQuery({
queryKey: ['area-of-use', 'tested-parent-trees', 'spz-list'],
queryFn: () => getSpzList(),
queryKey: ['area-of-use', 'spz-list', 'vegetation-code', seedlotData?.vegetationCode!],
queryFn: () => getSpzByVegCodeList(seedlotData!.vegetationCode!),
staleTime: THREE_HOURS,
cacheTime: THREE_HALF_HOURS,
enabled: !!seedlotData?.vegetationCode,
select: (data) => spzListToMultiObj(data)
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from '@carbon/react';

import ClassAContext from '../../../../views/Seedlot/ContextContainerClassA/context';
import { PLACE_HOLDER } from '../../../../shared-constants/shared-constants';
import ReadOnlyInput from '../../../ReadOnlyInput';
import { formatLatLong, formatSpz, spzListToString } from '../utils';
import Divider from '../../../Divider';
Expand Down Expand Up @@ -157,7 +158,7 @@ const AreaOfUseRead = () => {
labelText="Area of use comment:"
readOnly
value={
richSeedlotData?.seedlot.areaOfUseComment ?? ''
richSeedlotData?.seedlot.areaOfUseComment ?? PLACE_HOLDER
}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
} from '@carbon/react';

import ClassAContext from '../../../views/Seedlot/ContextContainerClassA/context';

import { PLACE_HOLDER } from './constants';
import { PLACE_HOLDER } from '../../../shared-constants/shared-constants';

type props = {
isRead?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
Row, Column, TextInput, TextInputSkeleton
} from '@carbon/react';
import ClassAContext from '../../../views/Seedlot/ContextContainerClassA/context';
import { PLACE_HOLDER } from './constants';
import { GeoInfoValType } from '../../../views/Seedlot/SeedlotReview/definitions';
import { PLACE_HOLDER } from '../../../shared-constants/shared-constants';
import { formatEmptyStr } from './utils';

type props = {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PLACE_HOLDER } from '../../../shared-constants/shared-constants';
import { CodeDescResType } from '../../../types/CodeDescResType';
import { PLACE_HOLDER } from './constants';

/**
* Format collection codes into human friendly words, e.g. [4, 5] -> "raking, picking".
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/shared-constants/shared-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ export const MEDIUM_SCREEN_WIDTH = 672;
export const LARGE_SCREEN_WIDTH = 1056;

export const TSC_ADMIN_ROLE = 'SPAR_TSC_ADMIN';

export const PLACE_HOLDER = '--';
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package ca.bc.gov.backendstartapi.endpoint;

import ca.bc.gov.backendstartapi.config.SparLog;
import ca.bc.gov.backendstartapi.dto.AreaOfUseDto;
import ca.bc.gov.backendstartapi.dto.SpzDto;
import ca.bc.gov.backendstartapi.entity.FundingSource;
import ca.bc.gov.backendstartapi.security.RoleAccessConfig;
import ca.bc.gov.backendstartapi.service.AreaOfUseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
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.util.List;
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.RestController;

Expand All @@ -29,20 +33,23 @@ public class AreaOfUseEndpoint {
}

/**
* Retrieve a list of SPZ under tested parent tree area of use.
* Retrieve a list of SPZ under a vegetation code.
*
* @return A list of {@link SpzDto} with all found result.
*/
@GetMapping("/tested-parent-trees/spz-list")
@GetMapping("/spz-list/vegetation-code/{vegCode}")
@Operation(
summary = "Get a list of Seed Plan Zone",
description = "Retrieve a list of SPZ under tested parent tree area of use.")
summary = "Get a list of Seed Plan Zone with a given vegetation code",
description = "Retrieve a list of SPZ that is under a vegetation code.")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description =
"Successfully returned a list of SPZ under tested parent tree area of use.",
"""
Successfully returned a list of SPZ under a vegetation code, an empty list is
returned if nothing is found.
""",
content =
@Content(
mediaType = "application/json",
Expand All @@ -53,9 +60,44 @@ public class AreaOfUseEndpoint {
content = @Content(schema = @Schema(implementation = Void.class)))
})
@RoleAccessConfig({"SPAR_TSC_ADMIN", "SPAR_MINISTRY_ORCHARD", "SPAR_NONMINISTRY_ORCHARD"})
public List<SpzDto> getAllSpz() {
SparLog.info("Recevied request to fetch all SPZs for tested parent trees.");
public List<SpzDto> getSpzByVegCode(
@PathVariable
@Parameter(
name = "vegCode",
in = ParameterIn.PATH,
description = "The vegetation code.",
required = true)
String vegCode) {

return areaOfUseService.getAllSpz();
SparLog.info("Received request to fetch all SPZs for vegetation code: {}", vegCode);

return areaOfUseService.getSpzByVegCode(vegCode.toUpperCase());
}

/**
* Get SPZ and SPU-geospatial information.
*
* @param spuId A seed plan unit id.
* @return A {@link SpzSpuGeoDto} containing the results.
*/
@GetMapping("/spu/{spuId}")
@Operation(
summary = "Get area of use information given an SPU id",
description = "Fetch geospatial data for the SPU along with a list of SPZ information.",
responses = {
@ApiResponse(
responseCode = "200",
description = "A data object containing information found."),
@ApiResponse(
responseCode = "401",
description = "Access token is missing or invalid",
content = @Content(schema = @Schema(implementation = Void.class)))
})
@RoleAccessConfig({"SPAR_TSC_ADMIN", "SPAR_MINISTRY_ORCHARD", "SPAR_NONMINISTRY_ORCHARD"})
public AreaOfUseDto getAreaOfUseData(
@Parameter(description = "The SPU (Seed Planning Unit) ID", required = true, example = "7")
@PathVariable("spuId")
Integer spuId) {
return areaOfUseService.calcAreaOfUseData(spuId);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ca.bc.gov.backendstartapi.endpoint;

import ca.bc.gov.backendstartapi.config.SparLog;
import ca.bc.gov.backendstartapi.dto.AreaOfUseDto;
import ca.bc.gov.backendstartapi.dto.OrchardDto;
import ca.bc.gov.backendstartapi.dto.OrchardParentTreeDto;
import ca.bc.gov.backendstartapi.dto.ParentTreeDto;
Expand Down Expand Up @@ -188,30 +187,4 @@ public ResponseEntity<List<SameSpeciesTreeDto>> findParentTreesWithVegCode(
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage(), e);
}
}

/**
* Get SPZ and SPU-geospatial information.
*
* @param spuId A seed plan unit id.
* @return A {@link SpzSpuGeoDto} containing the results.
*/
@GetMapping(path = "/area-of-use/spu/{spuId}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(
summary = "Get area of use information given an SPU id",
description = "Fetch geospatial data for the SPU along with a list of SPZ information.",
responses = {
@ApiResponse(
responseCode = "200",
description = "A data object containing information found."),
@ApiResponse(
responseCode = "401",
description = "Access token is missing or invalid",
content = @Content(schema = @Schema(implementation = Void.class)))
})
@RoleAccessConfig({"SPAR_TSC_ADMIN", "SPAR_MINISTRY_ORCHARD", "SPAR_NONMINISTRY_ORCHARD"})
public AreaOfUseDto getAreaOfUseData(
@Parameter(description = "The SPU (Seed Planning Unit) ID") @PathVariable("spuId")
Integer spuId) {
return orchardService.calcAreaOfUseData(spuId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/** This class represents a Seed Plan Zone record in the database. */
@Getter
@Setter
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "SEED_PLAN_ZONE")
public class SeedPlanZone {
@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package ca.bc.gov.backendstartapi.repository;

import ca.bc.gov.backendstartapi.entity.SeedPlanZone;
import java.util.Optional;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

/** This class holds methods for retrieving {@link SeedPlanZone} data from the database. */
public interface SeedPlanZoneRepository extends JpaRepository<SeedPlanZone, Integer> {

Optional<SeedPlanZone> findBySeedPlanZoneCode_spzCode_AndVegetationCode_id(
String spzCode, String vegCode);
List<SeedPlanZone> findAllByGeneticClassCode_AndVegetationCode_id(
Character genClassCode, String vegCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
import ca.bc.gov.backendstartapi.entity.idclass.TestedPtAreaOfUseSpzId;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

/** This class holds methods for retrieving {@link TestedPtAreaOfUseSpz} data from the database. */
public interface TestedPtAreaOfUseSpzRepository
extends JpaRepository<TestedPtAreaOfUseSpz, TestedPtAreaOfUseSpzId> {

List<TestedPtAreaOfUseSpz> findAllByTestedPtAreaOfUse_testedPtAreaOfUseId(
Integer testedPtAreaOfUseId);

@Query("SELECT DISTINCT t.seedPlanZoneCode.spzCode FROM TestedPtAreaOfUseSpz t")
List<String> findAllDistinctSpz();
}
Loading

0 comments on commit 1d02c07

Please sign in to comment.