diff --git a/api/pom.xml b/api/pom.xml index 23d9ba05..e8f4392a 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -6,7 +6,7 @@ ca.bc.gov.educ educ-grad-student-api - 1.8.64 + 1.8.65 educ-grad-student-api Student Demographics API for GRAD team 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 46045085..2573f43b 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 @@ -1118,6 +1118,15 @@ public Pair undoCompletionStudent(UUID if (gradStatusEvent != null) { gradStatusEventRepository.save(gradStatusEvent); } + List studentOptionalProgramEntities = gradStudentOptionalProgramRepository.findByStudentID(studentID); + for(StudentOptionalProgramEntity studentOptionalProgramEntity: studentOptionalProgramEntities) { + studentOptionalProgramEntity.setOptionalProgramCompletionDate(null); + studentOptionalProgramEntity.setStudentOptionalProgramData(null); + studentOptionalProgramEntity.setUpdateDate(LocalDateTime.now()); + studentOptionalProgramEntity.setUpdateUser(ThreadLocalStateUtil.getCurrentUser()); + gradStudentOptionalProgramRepository.save(studentOptionalProgramEntity); + historyService.createStudentOptionalProgramHistory(studentOptionalProgramEntity,USER_UNDO_CMPL); + } return Pair.of(graduationStatusTransformer.transformToDTOWithModifiedProgramCompletionDate(gradEntity), gradStatusEvent); } else { validation.addErrorAndStop(String.format("Student ID [%s] does not exists", studentID)); 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 b2268093..c70a33f2 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 @@ -2030,6 +2030,14 @@ public void testUgradStudent() throws JsonProcessingException { when(graduationStatusRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity)); when(graduationStatusRepository.save(responseGraduationStatus)).thenReturn(responseGraduationStatus); + StudentOptionalProgramEntity studentOptionalProgramEntity = new StudentOptionalProgramEntity(); + studentOptionalProgramEntity.setId(UUID.randomUUID()); + studentOptionalProgramEntity.setStudentID(studentID); + studentOptionalProgramEntity.setOptionalProgramCompletionDate(new Date(System.currentTimeMillis())); + + when(gradStudentOptionalProgramRepository.findByStudentID(studentID)).thenReturn(List.of(studentOptionalProgramEntity)); + doNothing().when(historyService).createStudentOptionalProgramHistory(any(), any()); + var response = graduationStatusService.undoCompletionStudent(studentID, ungradReasonCode,ungradReasonDesc, "accessToken"); assertThat(response).isNotNull();