From 3eebf764cc8bded0b901f6deecbdc4a834567494 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 30 Jan 2024 13:07:43 -0700 Subject: [PATCH] GRAD2-2464 Backend changes for Optional Program CRUD --- .../gradstudent/controller/CommonController.java | 8 ++++---- .../model/entity/StudentCareerProgramEntity.java | 11 +++++++---- .../repository/StudentCareerProgramRepository.java | 2 +- .../service/GraduationStatusService.java | 14 ++++++++++---- .../controller/CommonControllerTest.java | 6 +++--- .../service/GraduationStatusServiceTest.java | 2 +- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/CommonController.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/CommonController.java index c1a4f53e..4306ceb5 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/CommonController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/CommonController.java @@ -281,10 +281,10 @@ public ResponseEntity> getDeceasedStudentIDs(@RequestBody List @PreAuthorize(PermissionsConstants.UPDATE_GRADUATION_STUDENT_OPTIONAL_PROGRAM) @Operation(summary = "Create Student Optional Grad Program by Student ID", description = "Create Student Optional Grad Program by Student ID", tags = { "Optional Student Graduation Status" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) - public ResponseEntity createStudentGradOptionalProgram(@PathVariable UUID studentID, @RequestBody StudentOptionalProgram gradStudentOptionalProgram, + public ResponseEntity createStudentGradOptionalProgram(@PathVariable UUID studentID, @RequestBody StudentOptionalProgram gradStudentOptionalProgram, @RequestParam (value = "careerProgramCode", required = false) String careerProgramCode, @RequestHeader(name="Authorization") String accessToken) { logger.debug("Create student Optional Grad Program for Student ID: {}", studentID); - graduationStatusService.createStudentGradOptionalProgram(studentID, gradStudentOptionalProgram); + graduationStatusService.createStudentGradOptionalProgram(studentID, gradStudentOptionalProgram, careerProgramCode); return response.GET(graduationStatusService.getGraduationStatus(studentID, accessToken.replace(BEARER, ""))); } @@ -303,10 +303,10 @@ public ResponseEntity updateStudentGradOptionalProgram( @PreAuthorize(PermissionsConstants.UPDATE_GRADUATION_STUDENT_OPTIONAL_PROGRAM) @Operation(summary = "Delete Student Optional Grad Program by Student ID", description = "Delete Student Optional Grad Program by Student ID", tags = { "Optional Student Graduation Status" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) - public ResponseEntity deleteStudentGradOptionalProgram(@PathVariable UUID studentID, @PathVariable UUID optionalProgramID, @RequestParam (value = "careerProgramID", required = false) String careerProgramID, + public ResponseEntity deleteStudentGradOptionalProgram(@PathVariable UUID studentID, @PathVariable UUID optionalProgramID, @RequestParam (value = "careerProgramCode", required = false) String careerProgramCode, @RequestHeader(name="Authorization") String accessToken) { logger.debug("Delete student Optional Program for Student ID: {}", studentID); - graduationStatusService.deleteStudentGradOptionalProgram(studentID, optionalProgramID, careerProgramID); + graduationStatusService.deleteStudentGradOptionalProgram(studentID, optionalProgramID, careerProgramCode); return response.GET(graduationStatusService.getGraduationStatus(studentID, accessToken.replace(BEARER, ""))); } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/StudentCareerProgramEntity.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/StudentCareerProgramEntity.java index be831583..f97d26cd 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/StudentCareerProgramEntity.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/StudentCareerProgramEntity.java @@ -1,12 +1,10 @@ package ca.bc.gov.educ.api.gradstudent.model.entity; +import jakarta.persistence.*; import lombok.Data; import lombok.EqualsAndHashCode; +import org.hibernate.annotations.GenericGenerator; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; import java.util.UUID; @Data @@ -16,6 +14,11 @@ public class StudentCareerProgramEntity extends BaseEntity { @Id + @GeneratedValue(generator = "UUID") + @GenericGenerator( + name = "UUID", + strategy = "org.hibernate.id.UUIDGenerator" + ) @Column(name = "STUDENT_CAREER_PROGRAM_ID", nullable = false) private UUID id; diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/StudentCareerProgramRepository.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/StudentCareerProgramRepository.java index 1a83189c..87c8a10c 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/StudentCareerProgramRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/StudentCareerProgramRepository.java @@ -23,5 +23,5 @@ public interface StudentCareerProgramRepository extends JpaRepository gradStudentOptionalOptional = gradStudentOptionalProgramRepository.findByStudentIDAndOptionalProgramID(studentID, optionalProgramID); @@ -840,8 +846,8 @@ public void deleteStudentGradOptionalProgram(UUID studentID, UUID optionalProgra logger.debug(" -> Student Optional Program Entity is found for ID: {} === Entity ID: {}", optionalProgramID, optionalProgramID); gradStudentOptionalProgramRepository.delete(gradEnity); historyService.createStudentOptionalProgramHistory(gradEnity, USER_DELETE); - if(StringUtils.isNotBlank(careerProgramID)) { - gradStudentCareerProgramRepository.deleteStudentCareerProgramEntityByStudentIDAndId(studentID, UUID.fromString(careerProgramID)); + if(StringUtils.isNotBlank(careerProgramCode)) { + gradStudentCareerProgramRepository.deleteStudentCareerProgramEntityByStudentIDAndCareerProgramCode(studentID, careerProgramCode); } graduationStatusRepository.updateGradStudentRecalculationFlags(studentID, "Y", "Y"); } else { diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/CommonControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/CommonControllerTest.java index 3b77db29..3c091de4 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/CommonControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/CommonControllerTest.java @@ -365,13 +365,13 @@ public void testCreateStudentGradOptionalProgram() { BeanUtils.copyProperties(gradStudentOptionalProgramEntity, studentOptionalProgram); studentOptionalProgram.setOptionalProgramCompletionDate(EducGradStudentApiUtils.formatDate(gradStudentOptionalProgramEntity.getOptionalProgramCompletionDate(), "yyyy-MM-dd" )); - Mockito.when(graduationStatusService.createStudentGradOptionalProgram(studentID, studentOptionalProgram)).thenReturn(studentOptionalProgram); + Mockito.when(graduationStatusService.createStudentGradOptionalProgram(studentID, studentOptionalProgram, "CP")).thenReturn(studentOptionalProgram); Mockito.when(graduationStatusService.getGraduationStatus(studentID, "accessToken")).thenReturn(graduationStudentRecord); Mockito.when(responseHelper.GET(graduationStudentRecord)).thenReturn(ResponseEntity.ok().body(graduationStudentRecord)); - var result = commonController.createStudentGradOptionalProgram(studentID, studentOptionalProgram,"accessToken"); - Mockito.verify(graduationStatusService).createStudentGradOptionalProgram(studentID, studentOptionalProgram); + var result = commonController.createStudentGradOptionalProgram(studentID, studentOptionalProgram, "CP", "accessToken"); + Mockito.verify(graduationStatusService).createStudentGradOptionalProgram(studentID, studentOptionalProgram, "CP"); assertThat(result).isNotNull(); assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); } diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java index 4355deae..1a3778ed 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java @@ -1035,7 +1035,7 @@ public void testCreateCRUDStudentGradOptionalProgram() { doNothing().when(historyService).createStudentOptionalProgramHistory(gradStudentOptionalProgramEntity, "USER_CREATE"); doNothing().when(graduationStatusRepository).updateGradStudentRecalculationFlags(studentID, "Y", "Y"); - var result = graduationStatusService.createStudentGradOptionalProgram(studentID, studentOptionalProgram); + var result = graduationStatusService.createStudentGradOptionalProgram(studentID, studentOptionalProgram, "CP"); assertThat(result).isNotNull();