Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WFPREV-145 - Added bc parks code tables #367

Merged
merged 7 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public class CodeTables {
public static final String PROGRAM_AREA_CODE = "programAreaCodes";
public static final String FOREST_REGION_CODE = "forestRegionCodes";
public static final String FOREST_DISTRICT_CODE = "forestDistrictCodes";
public static final String BC_PARKS_REGION_CODE = "bcParksRegionCodes";
public static final String BC_PARKS_SECTION_CODE = "bcParksSectionCodes";
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public ResponseEntity getCodes(@PathVariable("codeTable") String codeTable) {
case CodeTables.FOREST_DISTRICT_CODE -> {
response = ok(codesService.getAllForestDistrictCodes());
}
case CodeTables.BC_PARKS_REGION_CODE -> {
response = ok(codesService.getAllBCParksRegionCodes());
}
case CodeTables.BC_PARKS_SECTION_CODE -> {
response = ok(codesService.getAllBCParksSectionCodes());
}

default -> {
response = internalServerError();
Expand Down Expand Up @@ -118,6 +124,12 @@ public ResponseEntity getCodeById(@PathVariable("codeTable") String codeTable, @
case CodeTables.FOREST_DISTRICT_CODE -> {
resource = codesService.getForestDistrictCodeById(Integer.parseInt(id));
}
case CodeTables.BC_PARKS_REGION_CODE -> {
resource = codesService.getBCParksRegionCodeById(Integer.parseInt(id));
}
case CodeTables.BC_PARKS_SECTION_CODE -> {
resource = codesService.getBCParksSectionCodeById(Integer.parseInt(id));
}
default -> {
resource = null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ca.bc.gov.nrs.wfprev.data.assemblers;

import ca.bc.gov.nrs.wfprev.common.enums.CodeTables;
import ca.bc.gov.nrs.wfprev.controllers.CodesController;
import ca.bc.gov.nrs.wfprev.data.entities.BCParksOrgUnitEntity;
import ca.bc.gov.nrs.wfprev.data.models.BCParksRegionCodeModel;
import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport;
import org.springframework.stereotype.Component;

import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

@Component
public class BCParksRegionCodeResourceAssembler extends RepresentationModelAssemblerSupport<BCParksOrgUnitEntity, BCParksRegionCodeModel> {

public BCParksRegionCodeResourceAssembler() {
super(CodesController.class, BCParksRegionCodeModel.class);
}


@Override
public BCParksRegionCodeModel toModel(BCParksOrgUnitEntity entity) {
BCParksRegionCodeModel resource = instantiateModel(entity);
resource.add(linkTo(
methodOn(CodesController.class)
.getCodeById(CodeTables.BC_PARKS_REGION_CODE, entity.getOrgUnitIdentifier().toString()))
.withSelfRel());
resource.setOrgUnitId(entity.getOrgUnitIdentifier());
resource.setEffectiveDate(entity.getEffectiveDate());
resource.setExpiryDate(entity.getExpiryDate());
resource.setBcParksOrgUnitTypeCode(entity.getBcParksOrgUnitTypeCode());
if (entity.getParentOrgUnitIdentifier() != null) {
resource.setParentOrgUnitId(entity.getParentOrgUnitIdentifier().toString());
}
resource.setOrgUnitName(entity.getOrgUnitName());
resource.setIntegerAlias(entity.getIntegerAlias());
resource.setCharacterAlias(entity.getCharacterAlias());
return resource;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ca.bc.gov.nrs.wfprev.data.assemblers;

import ca.bc.gov.nrs.wfprev.common.enums.CodeTables;
import ca.bc.gov.nrs.wfprev.controllers.CodesController;
import ca.bc.gov.nrs.wfprev.data.entities.BCParksOrgUnitEntity;
import ca.bc.gov.nrs.wfprev.data.models.BCParksRegionCodeModel;
import ca.bc.gov.nrs.wfprev.data.models.BCParksSectionCodeModel;
import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport;
import org.springframework.stereotype.Component;

import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;

@Component
public class BCParksSectionCodeResourceAssembler extends RepresentationModelAssemblerSupport<BCParksOrgUnitEntity, BCParksSectionCodeModel> {

public BCParksSectionCodeResourceAssembler() {
super(CodesController.class, BCParksSectionCodeModel.class);
}
@Override
public BCParksSectionCodeModel toModel(BCParksOrgUnitEntity entity) {
BCParksSectionCodeModel resource = instantiateModel(entity);
resource.add(linkTo(
methodOn(CodesController.class)
.getCodeById(CodeTables.BC_PARKS_SECTION_CODE, entity.getOrgUnitIdentifier().toString()))
.withSelfRel());
resource.setOrgUnitId(entity.getOrgUnitIdentifier());
resource.setEffectiveDate(entity.getEffectiveDate());
resource.setExpiryDate(entity.getExpiryDate());
resource.setBcParksOrgUnitTypeCode(entity.getBcParksOrgUnitTypeCode());
if (entity.getParentOrgUnitIdentifier() != null) {
resource.setParentOrgUnitId(entity.getParentOrgUnitIdentifier().toString());
}
resource.setOrgUnitName(entity.getOrgUnitName());
resource.setIntegerAlias(entity.getIntegerAlias());
resource.setCharacterAlias(entity.getCharacterAlias());
return resource;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package ca.bc.gov.nrs.wfprev.data.entities;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;

import java.io.Serializable;
import java.util.Date;

@Entity
@Table(name = "bc_parks_org_unit")
@JsonIgnoreProperties(ignoreUnknown = false)
@Data
@EqualsAndHashCode(callSuper = false)
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class BCParksOrgUnitEntity implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@Column(name = "org_unit_identifier")
@NotNull
private Integer orgUnitIdentifier;

@NotNull
@Column(name = "effective_date")
private Date effectiveDate;

@NotNull
@Column(name = "expiry_date")
private Date expiryDate;

@NotNull
@Column(name = "bc_parks_org_unit_type_code")
private String bcParksOrgUnitTypeCode;

@Column(name = "parent_org_unit_identifier")
private Integer parentOrgUnitIdentifier;

@NotNull
@Column(name = "org_unit_name")
private String orgUnitName;

@Column(name = "integer_alias")
private Integer integerAlias;

@Column(name = "character_alias")
private String characterAlias;

@CreatedBy
@NotNull
@Column(name = "create_user", length = 64)
private String createUser;

@CreatedDate
@NotNull
@Column(name = "create_date")
private Date createDate;

@LastModifiedBy
@NotNull
@Column(name = "update_user", length = 64)
private String updateUser;

@LastModifiedDate
@NotNull
@Column(name = "update_date")
private Date updateDate;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ca.bc.gov.nrs.wfprev.data.models;

import ca.bc.gov.nrs.wfprev.common.entities.CommonModel;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonRootName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.hateoas.server.core.Relation;

import java.util.Date;

@Data
@EqualsAndHashCode(callSuper = false)
@JsonRootName(value = "bcParksRegionCode")
@Relation(collectionRelation = "bcParksRegionCode")
@JsonInclude(JsonInclude.Include.NON_NULL)
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class BCParksRegionCodeModel extends CommonModel<BCParksRegionCodeModel> {
private Integer orgUnitId;
private Date effectiveDate;
private Date expiryDate;
private String bcParksOrgUnitTypeCode;
private String parentOrgUnitId;
private String orgUnitName;
private Integer integerAlias;
private String characterAlias;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ca.bc.gov.nrs.wfprev.data.models;

import ca.bc.gov.nrs.wfprev.common.entities.CommonModel;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonRootName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.hateoas.server.core.Relation;

import java.util.Date;

@Data
@EqualsAndHashCode(callSuper = false)
@JsonRootName(value = "bcParksSectionCode")
@Relation(collectionRelation = "bcParksSectionCode")
@JsonInclude(JsonInclude.Include.NON_NULL)
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class BCParksSectionCodeModel extends CommonModel<BCParksSectionCodeModel> {
private Integer orgUnitId;
private Date effectiveDate;
private Date expiryDate;
private String bcParksOrgUnitTypeCode;
private String parentOrgUnitId;
private String orgUnitName;
private Integer integerAlias;
private String characterAlias;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ca.bc.gov.nrs.wfprev.data.repositories;

import ca.bc.gov.nrs.wfprev.common.repository.CommonRepository;
import ca.bc.gov.nrs.wfprev.data.entities.BCParksOrgUnitEntity;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import java.util.List;

@RepositoryRestResource(exported = false)
public interface BCParksOrgUnitCodeRepository extends CommonRepository<BCParksOrgUnitEntity, Integer>{
List<BCParksOrgUnitEntity> findByBcParksOrgUnitTypeCode(String bcParksOrgUnitTypeCode);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@

import ca.bc.gov.nrs.wfone.common.service.api.ServiceException;
import ca.bc.gov.nrs.wfprev.common.services.CommonService;
import ca.bc.gov.nrs.wfprev.data.assemblers.BCParksRegionCodeResourceAssembler;
import ca.bc.gov.nrs.wfprev.data.assemblers.BCParksSectionCodeResourceAssembler;
import ca.bc.gov.nrs.wfprev.data.assemblers.ForestAreaCodeResourceAssembler;
import ca.bc.gov.nrs.wfprev.data.assemblers.ForestDistrictUnitCodeResourceAssembler;
import ca.bc.gov.nrs.wfprev.data.assemblers.ForestRegionUnitCodeResourceAssembler;
import ca.bc.gov.nrs.wfprev.data.assemblers.GeneralScopeCodeResourceAssembler;
import ca.bc.gov.nrs.wfprev.data.assemblers.ProgramAreaResourceAssembler;
import ca.bc.gov.nrs.wfprev.data.assemblers.ProjectTypeCodeResourceAssembler;
import ca.bc.gov.nrs.wfprev.data.entities.BCParksOrgUnitEntity;
import ca.bc.gov.nrs.wfprev.data.entities.ForestAreaCodeEntity;
import ca.bc.gov.nrs.wfprev.data.entities.ForestOrgUnitCodeEntity;
import ca.bc.gov.nrs.wfprev.data.entities.GeneralScopeCodeEntity;
import ca.bc.gov.nrs.wfprev.data.entities.ProgramAreaEntity;
import ca.bc.gov.nrs.wfprev.data.entities.ProjectTypeCodeEntity;
import ca.bc.gov.nrs.wfprev.data.models.BCParksRegionCodeModel;
import ca.bc.gov.nrs.wfprev.data.models.BCParksSectionCodeModel;
import ca.bc.gov.nrs.wfprev.data.models.ForestAreaCodeModel;
import ca.bc.gov.nrs.wfprev.data.models.ForestDistrictUnitCodeModel;
import ca.bc.gov.nrs.wfprev.data.models.ForestRegionUnitCodeModel;
import ca.bc.gov.nrs.wfprev.data.models.GeneralScopeCodeModel;
import ca.bc.gov.nrs.wfprev.data.models.ProgramAreaModel;
import ca.bc.gov.nrs.wfprev.data.models.ProjectTypeCodeModel;
import ca.bc.gov.nrs.wfprev.data.repositories.BCParksOrgUnitCodeRepository;
import ca.bc.gov.nrs.wfprev.data.repositories.ForestAreaCodeRepository;
import ca.bc.gov.nrs.wfprev.data.repositories.ForestOrgUnitCodeRepository;
import ca.bc.gov.nrs.wfprev.data.repositories.GeneralScopeCodeRepository;
Expand All @@ -29,11 +35,13 @@
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

@Slf4j
@Component
public class CodesService implements CommonService {
public static final String BC_PARKS_REGION_ORG_UNIT_TYPE_CODE = "REGION";
private ForestAreaCodeRepository forestAreaCodeRepository;
private ForestAreaCodeResourceAssembler forestAreaCodeResourceAssembler;
private GeneralScopeCodeRepository generalScopeCodeRepository;
Expand All @@ -45,11 +53,16 @@ public class CodesService implements CommonService {
private ForestOrgUnitCodeRepository forestOrgUnitCodeRepository;
private ForestRegionUnitCodeResourceAssembler forestRegionCodeResourceAssembler;
private final ForestDistrictUnitCodeResourceAssembler forestDistrictCodeResourceAssembler;
private final BCParksRegionCodeResourceAssembler bcParksRegionCodeResourceAssembler;
private final BCParksSectionCodeResourceAssembler bcParksSectionCodeResourceAssembler;
private final BCParksOrgUnitCodeRepository bcParksOrgUnitCodeRepository;


public CodesService(ForestAreaCodeRepository forestAreaCodeRepository, ForestAreaCodeResourceAssembler forestAreaCodeResourceAssembler,
GeneralScopeCodeRepository generalScopeCodeRepository, GeneralScopeCodeResourceAssembler generalScopeCodeResourceAssembler,
ProjectTypeCodeRepository projectTypeCodeRepository, ProjectTypeCodeResourceAssembler projectTypeCodeResourceAssembler, ProgramAreaRepository programAreaRepository, ProgramAreaResourceAssembler programAreaResourceAssembler,
ForestOrgUnitCodeRepository forestRegionCodeRepository, ForestRegionUnitCodeResourceAssembler forestRegionCodeResourceAssembler, ForestDistrictUnitCodeResourceAssembler forestDistrictUnitCodeResourceAssembler) {
ForestOrgUnitCodeRepository forestRegionCodeRepository, ForestRegionUnitCodeResourceAssembler forestRegionCodeResourceAssembler, ForestDistrictUnitCodeResourceAssembler forestDistrictUnitCodeResourceAssembler,
BCParksOrgUnitCodeRepository bcParksOrgUnitCodeRepository, BCParksRegionCodeResourceAssembler bcParksRegionCodeResourceAssembler, BCParksSectionCodeResourceAssembler bcParksSectionCodeResourceAssembler) {
this.forestAreaCodeRepository = forestAreaCodeRepository;
this.forestAreaCodeResourceAssembler = forestAreaCodeResourceAssembler;
this.generalScopeCodeRepository = generalScopeCodeRepository;
Expand All @@ -61,6 +74,9 @@ public CodesService(ForestAreaCodeRepository forestAreaCodeRepository, ForestAre
this.forestOrgUnitCodeRepository = forestRegionCodeRepository;
this.forestRegionCodeResourceAssembler = forestRegionCodeResourceAssembler;
this.forestDistrictCodeResourceAssembler = forestDistrictUnitCodeResourceAssembler;
this.bcParksOrgUnitCodeRepository = bcParksOrgUnitCodeRepository;
this.bcParksRegionCodeResourceAssembler = bcParksRegionCodeResourceAssembler;
this.bcParksSectionCodeResourceAssembler = bcParksSectionCodeResourceAssembler;
}

/**
Expand Down Expand Up @@ -143,7 +159,7 @@ public ProgramAreaModel getProgramAreaCodeById(String id) {

public CollectionModel<ForestRegionUnitCodeModel> getAllForestRegionCodes() {
try {
List<ForestOrgUnitCodeEntity> entities = forestOrgUnitCodeRepository.findByForestOrgUnitTypeCode("REGION");
List<ForestOrgUnitCodeEntity> entities = forestOrgUnitCodeRepository.findByForestOrgUnitTypeCode(BC_PARKS_REGION_ORG_UNIT_TYPE_CODE);
return forestRegionCodeResourceAssembler.toCollectionModel(entities);
} catch (Exception e) {
throw new ServiceException(e.getLocalizedMessage(), e);
Expand Down Expand Up @@ -175,4 +191,39 @@ public ForestDistrictUnitCodeModel getForestDistrictCodeById(Integer forestDistr
throw new ServiceException(e.getLocalizedMessage(), e);
}
}

public CollectionModel<BCParksRegionCodeModel> getAllBCParksRegionCodes() {
try {
List<BCParksOrgUnitEntity> entities = bcParksOrgUnitCodeRepository.findByBcParksOrgUnitTypeCode(BC_PARKS_REGION_ORG_UNIT_TYPE_CODE);
return bcParksRegionCodeResourceAssembler.toCollectionModel(entities);
} catch (Exception e) {
throw new ServiceException(e.getLocalizedMessage(), e);
}
}

public BCParksRegionCodeModel getBCParksRegionCodeById(Integer number) {
try {
Optional<BCParksOrgUnitEntity> byId = bcParksOrgUnitCodeRepository.findById(number);
return byId.map(bcParksRegionCodeResourceAssembler::toModel).orElse(null);
} catch (Exception e) {
throw new ServiceException(e.getLocalizedMessage(), e);
}
}

public CollectionModel<BCParksSectionCodeModel> getAllBCParksSectionCodes() {
try {
List<BCParksOrgUnitEntity> entities = bcParksOrgUnitCodeRepository.findByBcParksOrgUnitTypeCode("SECTION");
return bcParksSectionCodeResourceAssembler.toCollectionModel(entities);
} catch (Exception e) {
throw new ServiceException(e.getLocalizedMessage(), e);
}
}

public BCParksSectionCodeModel getBCParksSectionCodeById(Integer bcParksSectionId) {
try {
return bcParksOrgUnitCodeRepository.findById(bcParksSectionId).map(bcParksSectionCodeResourceAssembler::toModel).orElse(null);
} catch (Exception e) {
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
}
Loading
Loading