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-200 Add objective type code fields and update codes table endpoint #406

Merged
merged 11 commits into from
Jan 15, 2025
1 change: 1 addition & 0 deletions client/wfprev-war/src/main/angular/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/node_modules
npm-debug.log
yarn-error.log
yarn.lock
ssylver93 marked this conversation as resolved.
Show resolved Hide resolved

# IDEs and editors
.idea/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ private CodeTables() {}
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";
public static final String OBJECTIVE_TYPE_CODE = "objectiveTypeCodes";
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public ResponseEntity<CollectionModel<?>> getCodes(@PathVariable("codeTable") St
case CodeTables.FOREST_DISTRICT_CODE -> result = codesService.getAllForestDistrictCodes();
case CodeTables.BC_PARKS_REGION_CODE -> result = codesService.getAllBCParksRegionCodes();
case CodeTables.BC_PARKS_SECTION_CODE -> result = codesService.getAllBCParksSectionCodes();
case CodeTables.OBJECTIVE_TYPE_CODE -> result = codesService.getAllObjectiveTypeCodes();
default -> {
log.error("Invalid code table: {}", codeTable);
return internalServerError();
Expand Down Expand Up @@ -129,6 +130,7 @@ private CommonModel<?> fetchCodeById(String codeTable, String id) throws Service
case CodeTables.FOREST_DISTRICT_CODE -> codesService.getForestDistrictCodeById(Integer.parseInt(id));
case CodeTables.BC_PARKS_REGION_CODE -> codesService.getBCParksRegionCodeById(Integer.parseInt(id));
case CodeTables.BC_PARKS_SECTION_CODE -> codesService.getBCParksSectionCodeById(Integer.parseInt(id));
case CodeTables.OBJECTIVE_TYPE_CODE -> codesService.getObjectiveTypeCodeById(id);
default -> null;
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package ca.bc.gov.nrs.wfprev.data.assemblers;

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

import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport;
import org.springframework.stereotype.Component;

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.ObjectiveTypeCodeEntity;
import ca.bc.gov.nrs.wfprev.data.models.ObjectiveTypeCodeModel;

@Component
public class ObjectiveTypeCodeResourceAssembler extends RepresentationModelAssemblerSupport<ObjectiveTypeCodeEntity, ObjectiveTypeCodeModel> {

public ObjectiveTypeCodeResourceAssembler() {
super(CodesController.class, ObjectiveTypeCodeModel.class);
}

public ObjectiveTypeCodeEntity toEntity(ObjectiveTypeCodeModel resource) {
ObjectiveTypeCodeEntity entity = new ObjectiveTypeCodeEntity();

entity.setObjectiveTypeCode(resource.getObjectiveTypeCode());
entity.setDescription(resource.getDescription());
entity.setDisplayOrder(resource.getDisplayOrder());
entity.setEffectiveDate(resource.getEffectiveDate());
entity.setExpiryDate(resource.getExpiryDate());
entity.setRevisionCount(resource.getRevisionCount());
entity.setCreateUser(resource.getCreateUser());
entity.setCreateDate(resource.getCreateDate());
entity.setUpdateUser(resource.getUpdateUser());
entity.setUpdateDate(resource.getUpdateDate());

return entity;
}

@Override
public ObjectiveTypeCodeModel toModel(ObjectiveTypeCodeEntity entity) {
ObjectiveTypeCodeModel resource = instantiateModel(entity);

resource.add(linkTo(
methodOn(CodesController.class)
.getCodeById(CodeTables.GENERAL_SCOPE_CODE, entity.getObjectiveTypeCode()))
.withSelfRel());

resource.setObjectiveTypeCode(entity.getObjectiveTypeCode());
resource.setDescription(entity.getDescription());
resource.setDisplayOrder(entity.getDisplayOrder());
resource.setEffectiveDate(entity.getEffectiveDate());
resource.setExpiryDate(entity.getExpiryDate());
resource.setRevisionCount(entity.getRevisionCount());
resource.setCreateUser(entity.getCreateUser());
resource.setCreateDate(entity.getCreateDate());
resource.setUpdateUser(entity.getUpdateUser());
resource.setUpdateDate(entity.getUpdateDate());

return resource;
}

@Override
public CollectionModel<ObjectiveTypeCodeModel> toCollectionModel(Iterable<? extends ObjectiveTypeCodeEntity> entities)
{
CollectionModel<ObjectiveTypeCodeModel> resources = super.toCollectionModel(entities);

resources.add(linkTo(methodOn(CodesController.class).getCodes(CodeTables.GENERAL_SCOPE_CODE)).withSelfRel());

return resources;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public ProjectEntity toEntity(ProjectModel resource) {
entity.setCreateDate(resource.getCreateDate());
entity.setUpdateUser(resource.getUpdateUser());
entity.setUpdateDate(resource.getUpdateDate());
entity.setPrimaryObjectiveTypeCode(resource.getPrimaryObjectiveTypeCode());
entity.setSecondaryObjectiveTypeCode(resource.getSecondaryObjectiveTypeCode());
entity.setTertiaryObjectiveTypeCode(resource.getTertiaryObjectiveTypeCode());

return entity;
}
Expand Down Expand Up @@ -124,6 +127,9 @@ public ProjectModel toModel(ProjectEntity entity) {
resource.setCreateDate(entity.getCreateDate());
resource.setUpdateUser(entity.getUpdateUser());
resource.setUpdateDate(entity.getUpdateDate());
resource.setPrimaryObjectiveTypeCode(entity.getPrimaryObjectiveTypeCode());
resource.setSecondaryObjectiveTypeCode(entity.getSecondaryObjectiveTypeCode());
resource.setTertiaryObjectiveTypeCode(entity.getTertiaryObjectiveTypeCode());

return resource;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package ca.bc.gov.nrs.wfprev.data.entities;

import java.io.Serializable;

import java.util.Date;
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 com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import jakarta.persistence.Id;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

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

@Id
@Column(name = "objective_type_code")
@NotNull
private String objectiveTypeCode;

@NotNull
@Column(name = "description", length = 200)
private String description;

@Column(name = "display_order", length = 3)
private Integer displayOrder;

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

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

@Column(name = "revision_count", columnDefinition="Decimal(10) default '0'")
@NotNull
@Version
private Integer revisionCount;

@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
Expand Up @@ -169,4 +169,13 @@ public class ProjectEntity implements Serializable {
@NotNull
@Column(name = "update_date")
private Date updateDate;

@Column(name = "primary_objective_type_code")
private String primaryObjectiveTypeCode;

@Column(name = "secondary_objective_type_code")
private String secondaryObjectiveTypeCode;

@Column(name = "tertiary_objective_type_code")
private String tertiaryObjectiveTypeCode;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ca.bc.gov.nrs.wfprev.data.models;

import java.util.Date;

import org.springframework.hateoas.server.core.Relation;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonRootName;

import ca.bc.gov.nrs.wfprev.common.entities.CommonModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;


@Data
@EqualsAndHashCode(callSuper = false)
@JsonRootName(value = "objectiveTypeCode")
@Relation(collectionRelation = "objectiveTypeCode")
@JsonInclude(Include.NON_NULL)
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ObjectiveTypeCodeModel extends CommonModel<ObjectiveTypeCodeModel> {
private String objectiveTypeCode;
private String description;
private Integer displayOrder;
private Date effectiveDate;
private Date expiryDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ public class ProjectModel extends CommonModel<ProjectModel> {
private BigDecimal latitude;
private BigDecimal longitude;
private Date lastProgressUpdateTimestamp;
private String primaryObjectiveTypeCode;
private String secondaryObjectiveTypeCode;
private String tertiaryObjectiveTypeCode;

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

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

@RepositoryRestResource(exported = false)
public interface ObjectiveTypeCodeRepository extends CommonRepository<ObjectiveTypeCodeEntity, String> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@

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.assemblers.*;
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.entities.ObjectiveTypeCodeEntity;
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;
Expand All @@ -24,12 +18,8 @@
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;
import ca.bc.gov.nrs.wfprev.data.repositories.ProgramAreaRepository;
import ca.bc.gov.nrs.wfprev.data.repositories.ProjectTypeCodeRepository;
import ca.bc.gov.nrs.wfprev.data.models.ObjectiveTypeCodeModel;
import ca.bc.gov.nrs.wfprev.data.repositories.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.hateoas.CollectionModel;
import org.springframework.stereotype.Component;
Expand All @@ -56,13 +46,16 @@ public class CodesService implements CommonService {
private final BCParksRegionCodeResourceAssembler bcParksRegionCodeResourceAssembler;
private final BCParksSectionCodeResourceAssembler bcParksSectionCodeResourceAssembler;
private final BCParksOrgUnitCodeRepository bcParksOrgUnitCodeRepository;
private final ObjectiveTypeCodeResourceAssembler objectiveTypeCodeResourceAssembler;
private final ObjectiveTypeCodeRepository objectiveTypeCodeRepository;


public CodesService(ForestAreaCodeRepository forestAreaCodeRepository, ForestAreaCodeResourceAssembler forestAreaCodeResourceAssembler,
GeneralScopeCodeRepository generalScopeCodeRepository, GeneralScopeCodeResourceAssembler generalScopeCodeResourceAssembler,
ProjectTypeCodeRepository projectTypeCodeRepository, ProjectTypeCodeResourceAssembler projectTypeCodeResourceAssembler, ProgramAreaRepository programAreaRepository, ProgramAreaResourceAssembler programAreaResourceAssembler,
ForestOrgUnitCodeRepository forestRegionCodeRepository, ForestRegionUnitCodeResourceAssembler forestRegionCodeResourceAssembler, ForestDistrictUnitCodeResourceAssembler forestDistrictUnitCodeResourceAssembler,
BCParksOrgUnitCodeRepository bcParksOrgUnitCodeRepository, BCParksRegionCodeResourceAssembler bcParksRegionCodeResourceAssembler, BCParksSectionCodeResourceAssembler bcParksSectionCodeResourceAssembler) {
BCParksOrgUnitCodeRepository bcParksOrgUnitCodeRepository, BCParksRegionCodeResourceAssembler bcParksRegionCodeResourceAssembler, BCParksSectionCodeResourceAssembler bcParksSectionCodeResourceAssembler,
ObjectiveTypeCodeResourceAssembler objectiveTypeCodeResourceAssembler, ObjectiveTypeCodeRepository objectiveTypeCodeRepository) {
this.forestAreaCodeRepository = forestAreaCodeRepository;
this.forestAreaCodeResourceAssembler = forestAreaCodeResourceAssembler;
this.generalScopeCodeRepository = generalScopeCodeRepository;
Expand All @@ -77,6 +70,8 @@ public CodesService(ForestAreaCodeRepository forestAreaCodeRepository, ForestAre
this.bcParksOrgUnitCodeRepository = bcParksOrgUnitCodeRepository;
this.bcParksRegionCodeResourceAssembler = bcParksRegionCodeResourceAssembler;
this.bcParksSectionCodeResourceAssembler = bcParksSectionCodeResourceAssembler;
this.objectiveTypeCodeResourceAssembler = objectiveTypeCodeResourceAssembler;
this.objectiveTypeCodeRepository = objectiveTypeCodeRepository;
}

/**
Expand Down Expand Up @@ -226,4 +221,21 @@ public BCParksSectionCodeModel getBCParksSectionCodeById(Integer bcParksSectionI
throw new ServiceException(e.getLocalizedMessage(), e);
}
}

public CollectionModel<ObjectiveTypeCodeModel> getAllObjectiveTypeCodes() throws ServiceException {
try {
List<ObjectiveTypeCodeEntity> entities = objectiveTypeCodeRepository.findAll();
return objectiveTypeCodeResourceAssembler.toCollectionModel(entities);
} catch (Exception e) {
throw new ServiceException(e.getLocalizedMessage(), e);
}
}

public ObjectiveTypeCodeModel getObjectiveTypeCodeById(String id) throws ServiceException {
try {
return objectiveTypeCodeRepository.findById(id).map(objectiveTypeCodeResourceAssembler::toModel).orElse(null);
} catch (Exception e) {
throw new ServiceException(e.getLocalizedMessage(), e);
}
}
}
Loading
Loading