From 649e37561c0ac94dd41b20a3d98294b6657ee1f9 Mon Sep 17 00:00:00 2001 From: arybakov Date: Wed, 31 Jan 2024 10:41:26 -0700 Subject: [PATCH] GRAD2-2464 Backend changes for Optional Program CRUD --- .../gradstudent/service/GraduationStatusService.java | 11 +++++++---- .../service/GraduationStatusServiceTest.java | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java index 5485a60d..24044602 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java @@ -801,10 +801,13 @@ public StudentOptionalProgram createStudentGradOptionalProgram(UUID studentID, S gradEnity.setOptionalProgramCompletionDate(sourceObject.getOptionalProgramCompletionDate()); StudentOptionalProgramEntity gradEnitySaved = gradStudentOptionalProgramRepository.save(gradEnity); if(StringUtils.equalsIgnoreCase(careerProgramCode, "CP")) { - StudentCareerProgramEntity studentCareerProgramEntity = new StudentCareerProgramEntity(); - studentCareerProgramEntity.setStudentID(studentID); - studentCareerProgramEntity.setCareerProgramCode(careerProgramCode); - gradStudentCareerProgramRepository.save(studentCareerProgramEntity); + Optional optionalStudentCareerProgramEntity = gradStudentCareerProgramRepository.findByStudentIDAndCareerProgramCode(studentID, careerProgramCode); + if(!optionalStudentCareerProgramEntity.isPresent()) { + StudentCareerProgramEntity studentCareerProgramEntity = new StudentCareerProgramEntity(); + studentCareerProgramEntity.setStudentID(studentID); + studentCareerProgramEntity.setCareerProgramCode(careerProgramCode); + gradStudentCareerProgramRepository.save(studentCareerProgramEntity); + } } historyService.createStudentOptionalProgramHistory(gradEnitySaved, USER_CREATE); graduationStatusRepository.updateGradStudentRecalculationFlags(studentID, "Y", "Y"); 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 1a3778ed..1e39f58d 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 @@ -1031,6 +1031,7 @@ public void testCreateCRUDStudentGradOptionalProgram() { Optional optionalGraduationStudentRecordEntity = Optional.of(graduationStudentRecordEntity); when(graduationStatusRepository.findById(studentID)).thenReturn(optionalGraduationStudentRecordEntity); + when(gradStudentCareerProgramRepository.findByStudentIDAndCareerProgramCode(studentID, "CP")).thenReturn(Optional.empty()); when(gradStudentOptionalProgramRepository.save(gradStudentOptionalProgramEntity)).thenReturn(gradStudentOptionalProgramEntity); doNothing().when(historyService).createStudentOptionalProgramHistory(gradStudentOptionalProgramEntity, "USER_CREATE"); doNothing().when(graduationStatusRepository).updateGradStudentRecalculationFlags(studentID, "Y", "Y");