Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/bcgov/nr-bcws-wfprev into f…
Browse files Browse the repository at this point in the history
…ix_token_validation_test
  • Loading branch information
ssylver93 committed Dec 9, 2024
2 parents cec8d42 + ca16ca7 commit ec32448
Show file tree
Hide file tree
Showing 18 changed files with 1,050 additions and 149 deletions.
27 changes: 27 additions & 0 deletions db/main-changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,33 @@
{ "sql": "DROP TABLE wfprev.project_type_code" }
]
}
},
{
"changeSet": {
"id": "01_00_02_00",
"author": "agordon",
"tagDatabase": { "tag" : "version_01_00_02_00" },
"changes": [
{
"sqlFile": {
"dbms": "postgresql",
"endDelimiter": ";",
"path": "scripts/01_00_02/00/ddl/sequences/WFPREV.project_number_seq.sql"
}
},
{
"sqlFile": {
"dbms": "postgresql",
"endDelimiter": ";",
"path": "scripts/01_00_02/00/ddl/tables/WFPREV.project_update.sql"
}
}
],
"rollback": [
{ "sql": "ALTER TABLE wfprev.project ALTER COLUMN project_number DROP DEFAULT" },
{ "sql": "DROP SEQUENCE wfprev.project_number_seq" }
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE SEQUENCE "wfprev"."project_number_seq" INCREMENT BY 1 START WITH 1000 MAXVALUE 9999999999 MINVALUE 1000 NO CYCLE;

GRANT USAGE ON SEQUENCE "wfprev"."project_number_seq" TO PROXY_WF1_PREV_REST;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "wfprev"."project" ALTER COLUMN "project_number" SET DEFAULT nextval('wfprev.project_number_seq');
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
services:
api:
profiles:
- api
build:
context: .
dockerfile: server/wfprev-api/Dockerfile.graalvm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Date;
import java.util.UUID;

import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.hateoas.CollectionModel;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand Down Expand Up @@ -113,6 +114,9 @@ public ResponseEntity<ProjectModel> createProject(@RequestBody ProjectModel reso

ProjectModel newResource = projectService.createOrUpdateProject(resource);
response = newResource == null ? badRequest() : created(newResource);
} catch (DataIntegrityViolationException e) {
response = conflict();
log.error(" ### Error while creating resource", e);
} catch(ServiceException e) {
response = internalServerError();
log.error(" ### Error while creating resource", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,23 @@ public ProjectEntity toEntity(ProjectModel resource) {
ProjectEntity entity = new ProjectEntity();

entity.setProjectGuid(UUID.fromString(resource.getProjectGuid()));
entity.setProjectTypeCode(toProjectTypeCodeEntity(resource.getProjectTypeCode()));
entity.setProjectNumber(resource.getProjectNumber());
if (resource.getProjectTypeCode() != null) {
entity.setProjectTypeCode(toProjectTypeCodeEntity(resource.getProjectTypeCode()));
}
// Only set project number if it exists (for updates)
if (resource.getProjectNumber() != null) {
entity.setProjectNumber(resource.getProjectNumber());
}
entity.setSiteUnitName(resource.getSiteUnitName());
entity.setForestAreaCode(toForestAreaCodeEntity(resource.getForestAreaCode()));
entity.setGeneralScopeCode(toGeneralScopeCodeEntity(resource.getGeneralScopeCode()));
entity.setProgramAreaGuid(UUID.fromString(resource.getProgramAreaGuid()));
if (resource.getForestAreaCode() != null) {
entity.setForestAreaCode(toForestAreaCodeEntity(resource.getForestAreaCode()));
}
if (resource.getGeneralScopeCode() != null) {
entity.setGeneralScopeCode(toGeneralScopeCodeEntity(resource.getGeneralScopeCode()));
}
if (resource.getProgramAreaGuid() != null) {
entity.setProgramAreaGuid(UUID.fromString(resource.getProgramAreaGuid()));
}
entity.setForestRegionOrgUnitId(resource.getForestRegionOrgUnitId());
entity.setForestDistrictOrgUnitId(resource.getForestDistrictOrgUnitId());
entity.setFireCentreOrgUnitId(resource.getFireCentreOrgUnitId());
Expand Down Expand Up @@ -79,8 +90,12 @@ public ProjectModel toModel(ProjectEntity entity) {
resource.setProjectTypeCode(toProjectTypeCodeModel(entity.getProjectTypeCode()));
resource.setProjectNumber(entity.getProjectNumber());
resource.setSiteUnitName(entity.getSiteUnitName());
resource.setForestAreaCode(toForestAreaCodeModel(entity.getForestAreaCode()));
resource.setGeneralScopeCode(toGeneralScopeCodeModel(entity.getGeneralScopeCode()));
if (entity.getForestAreaCode() != null) {
resource.setForestAreaCode(toForestAreaCodeModel(entity.getForestAreaCode()));
}
if (entity.getGeneralScopeCode() != null) {
resource.setGeneralScopeCode(toGeneralScopeCodeModel(entity.getGeneralScopeCode()));
}
resource.setProgramAreaGuid(entity.getProgramAreaGuid().toString());
resource.setForestRegionOrgUnitId(entity.getForestRegionOrgUnitId());
resource.setForestDistrictOrgUnitId(entity.getForestDistrictOrgUnitId());
Expand Down Expand Up @@ -125,6 +140,7 @@ private ProjectTypeCodeModel toProjectTypeCodeModel(ProjectTypeCodeEntity code)
}

private ProjectTypeCodeEntity toProjectTypeCodeEntity(ProjectTypeCodeModel code) {
if (code == null) return null;
ProjectTypeCodeResourceAssembler ra = new ProjectTypeCodeResourceAssembler();
return ra.toEntity(code);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package ca.bc.gov.nrs.wfprev.data.assemblers;

import ca.bc.gov.nrs.wfprev.controllers.CodesController;
import ca.bc.gov.nrs.wfprev.data.entities.ProjectStatusCodeEntity;
import ca.bc.gov.nrs.wfprev.data.models.ProjectStatusCodeModel;
import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport;
import org.springframework.stereotype.Component;

@Component
public class ProjectStatusCodeResourceAssembler extends RepresentationModelAssemblerSupport<ProjectStatusCodeEntity, ProjectStatusCodeModel> {
public ProjectStatusCodeResourceAssembler() {
super(CodesController.class, ProjectStatusCodeModel.class);
}

@Override
public ProjectStatusCodeModel toModel(ProjectStatusCodeEntity entity) {
ProjectStatusCodeModel model = instantiateModel(entity);

model.setProjectStatusCode(entity.getProjectStatusCode());
model.setDescription(entity.getDescription());
model.setDisplayOrder(entity.getDisplayOrder());
model.setEffectiveDate(entity.getEffectiveDate());
model.setExpiryDate(entity.getExpiryDate());
model.setDisplayOrder(entity.getDisplayOrder());
model.setCreateDate(entity.getCreateDate());
model.setCreateUser(entity.getCreateUser());
model.setUpdateDate(entity.getUpdateDate());
model.setUpdateUser(entity.getUpdateUser());
model.setRevisionCount(entity.getRevisionCount());

return model;
}

public ProjectStatusCodeEntity toEntity(ProjectStatusCodeModel model) {
if (model == null) {
return null;
}

ProjectStatusCodeEntity entity = new ProjectStatusCodeEntity();

entity.setProjectStatusCode(model.getProjectStatusCode());
entity.setDescription(model.getDescription());
entity.setDisplayOrder(model.getDisplayOrder());
entity.setEffectiveDate(model.getEffectiveDate());
entity.setExpiryDate(model.getExpiryDate());
entity.setCreateDate(model.getCreateDate());
entity.setCreateUser(model.getCreateUser());
entity.setUpdateDate(model.getUpdateDate());
entity.setUpdateUser(model.getUpdateUser());
entity.setRevisionCount(model.getRevisionCount());

return entity;
}
}
Loading

0 comments on commit ec32448

Please sign in to comment.