From 5207c0bff8247de6e8ea14ee043a5339fd2d2e70 Mon Sep 17 00:00:00 2001 From: Jinil Sung Date: Mon, 4 Nov 2024 14:54:07 -0800 Subject: [PATCH] GRAD2-3019: task is complete. GRAD2-3019: task is complete. --- .../gradstudent/constant/TraxEventType.java | 1 - .../model/dto/GraduationStudentRecord.java | 2 +- ...duationStudentRecordHistoryRepository.java | 56 +++++++++++++++ .../service/DataConversionService.java | 22 +++++- .../service/DataConversionServiceTest.java | 68 ++++++++++++++++++- 5 files changed, 142 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/TraxEventType.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/TraxEventType.java index 81724cc4..19334f90 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/TraxEventType.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/TraxEventType.java @@ -10,7 +10,6 @@ public enum TraxEventType { NEWSTUDENT, UPD_DEMOG, UPD_GRAD, - UPD_STD_STATUS, XPROGRAM, ASSESSMENT, COURSE, diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GraduationStudentRecord.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GraduationStudentRecord.java index c45f03e0..ff8dba84 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GraduationStudentRecord.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GraduationStudentRecord.java @@ -27,7 +27,7 @@ public class GraduationStudentRecord extends BaseModel { private String schoolOfRecord; private UUID schoolOfRecordId; private String schoolName; - private String studentGrade; + private String studentGrade; private String studentStatus; private String studentStatusName; private UUID studentID; diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordHistoryRepository.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordHistoryRepository.java index 90816cbf..fad9f87a 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordHistoryRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordHistoryRepository.java @@ -140,4 +140,60 @@ INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY ( @Query(value= INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_BATCH_ID_AND_STUDENT_ID_IN_SQL, nativeQuery=true) Integer insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(@Param(value = "batchId") Long batchId, @Param(value = "studentIDs") List studentIDs, @Param(value = "activityCode") String activityCode, @Param(value = "updateUser") String updateUser); + @Modifying + @Query(value= INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_STUDENT_ID_IN_SQL, nativeQuery=true) + Integer insertGraduationStudentRecordHistoryByStudentId(@Param(value = "studentID") UUID studentID, @Param(value = "activityCode") String activityCode); + + String INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_STUDENT_ID_IN_SQL = """ + INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY ( + GRADUATION_STUDENT_RECORD_HISTORY_ID, + HISTORY_ACTIVITY_CODE, + GRADUATION_STUDENT_RECORD_ID, + GRADUATION_PROGRAM_CODE, + GPA, + STUDENT_STATUS_CODE, + HONOURS_STANDING, + PROGRAM_COMPLETION_DATE, + RECALCULATE_GRAD_STATUS, + SCHOOL_OF_RECORD, + STUDENT_GRADE, + SCHOOL_AT_GRADUATION, + CREATE_USER, + CREATE_DATE, + UPDATE_USER, + UPDATE_DATE, + RECALCULATE_PROJECTED_GRAD, + BATCH_ID, + CONSUMER_EDUC_REQT_MET, + STUDENT_CITIZENSHIP_CODE, + ADULT_START_DATE, + SCHOOL_OF_RECORD_ID, + SCHOOL_AT_GRADUATION_ID + ) SELECT + SYS_GUID(), + :activityCode, + GRADUATION_STUDENT_RECORD_ID, + GRADUATION_PROGRAM_CODE, + GPA, + STUDENT_STATUS_CODE, + HONOURS_STANDING, + PROGRAM_COMPLETION_DATE, + RECALCULATE_GRAD_STATUS, + SCHOOL_OF_RECORD, + STUDENT_GRADE, + SCHOOL_AT_GRADUATION, + CREATE_USER, + CREATE_DATE, + UPDATE_USER, + SYSDATE, + RECALCULATE_PROJECTED_GRAD, + BATCH_ID, + CONSUMER_EDUC_REQT_MET, + STUDENT_CITIZENSHIP_CODE, + ADULT_START_DATE, + SCHOOL_OF_RECORD_ID, + SCHOOL_AT_GRADUATION_ID + FROM GRADUATION_STUDENT_RECORD + WHERE GRADUATION_STUDENT_RECORD_ID = :studentID + """; } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionService.java index f5ceee17..f99a0749 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionService.java @@ -120,8 +120,13 @@ public GraduationStudentRecord updateGraduationStatusByFields(OngoingUpdateReque gradEntity.setUpdateDate(null); gradEntity.setUpdateUser(null); validateStudentStatusAndResetBatchFlags(gradEntity); - gradEntity = graduationStatusRepository.saveAndFlush(gradEntity); - historyService.createStudentHistory(gradEntity, UPDATE_ONGOING_HISTORY_ACTIVITY_CODE); + if (isBatchFlagUpdatesOnly(eventType)) { + gradEntity = saveBatchFlagsWithAuditHistory(gradEntity.getStudentID(), gradEntity.getRecalculateGradStatus(), + gradEntity.getRecalculateProjectedGrad(), UPDATE_ONGOING_HISTORY_ACTIVITY_CODE); + } else { + gradEntity = graduationStatusRepository.saveAndFlush(gradEntity); + historyService.createStudentHistory(gradEntity, UPDATE_ONGOING_HISTORY_ACTIVITY_CODE); + } if (constants.isStudentGuidPenXrefEnabled() && StringUtils.isNotBlank(requestDTO.getPen())) { saveStudentGuidPenXref(gradEntity.getStudentID(), requestDTO.getPen()); } @@ -130,6 +135,10 @@ public GraduationStudentRecord updateGraduationStatusByFields(OngoingUpdateReque return null; } + private boolean isBatchFlagUpdatesOnly(TraxEventType eventType) { + return TraxEventType.NEWSTUDENT != eventType && TraxEventType.UPD_GRAD != eventType; + } + @Transactional @Retry(name = "generalpostcall") public StudentOptionalProgram saveStudentOptionalProgram(StudentOptionalProgramRequestDTO studentOptionalProgramReq, String accessToken) { @@ -214,6 +223,15 @@ private void saveStudentGuidPenXref(UUID studentId, String pen) { } } + /** + * Update Batch Flags in Graduation Status for Ongoing Updates + */ + private GraduationStudentRecordEntity saveBatchFlagsWithAuditHistory(UUID studentID, String recalculateGradStatus, String recalculateProjectedGrad, String historyActivityCode) { + graduationStatusRepository.updateGradStudentRecalculationAllFlags(studentID, recalculateGradStatus, recalculateProjectedGrad); + gradStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByStudentId(studentID, historyActivityCode); + return graduationStatusRepository.findByStudentID(studentID); + } + @Transactional public void deleteGraduationStatus(UUID studentID) { // graduation_student_record diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionServiceTest.java index 9e11bc9a..b06bf784 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionServiceTest.java @@ -289,7 +289,7 @@ public void testGraduationStudentRecordAsOngoingUpdateForStudentStatus() { OngoingUpdateRequestDTO requestDTO = new OngoingUpdateRequestDTO(); requestDTO.setPen(pen); requestDTO.setStudentID(studentID.toString()); - requestDTO.setEventType(TraxEventType.UPD_STD_STATUS); + requestDTO.setEventType(TraxEventType.UPD_GRAD); OngoingUpdateFieldDTO field = OngoingUpdateFieldDTO.builder() .type(FieldType.STRING).name(FieldName.STUDENT_STATUS).value(newStatus) @@ -322,6 +322,68 @@ public void testGraduationStudentRecordAsOngoingUpdateForStudentStatus() { assertThat(result.getRecalculateGradStatus()).isNull(); } + @Test + public void testGraduationStudentRecordAsOngoingUpdateForBatchFlags() { + // ID + UUID studentID = UUID.randomUUID(); + String pen = "123456789"; + String mincode = "12345678"; + + GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity(); + graduationStatusEntity.setStudentID(studentID); + graduationStatusEntity.setPen(pen); + graduationStatusEntity.setStudentStatus("CUR"); + graduationStatusEntity.setRecalculateGradStatus(null); + graduationStatusEntity.setRecalculateProjectedGrad("Y"); + graduationStatusEntity.setProgram("2018-EN"); + graduationStatusEntity.setSchoolOfRecord(mincode); + graduationStatusEntity.setSchoolAtGrad(mincode); + graduationStatusEntity.setGpa("4"); + graduationStatusEntity.setProgramCompletionDate(new Date(System.currentTimeMillis())); + + OngoingUpdateRequestDTO requestDTO = new OngoingUpdateRequestDTO(); + requestDTO.setPen(pen); + requestDTO.setStudentID(studentID.toString()); + requestDTO.setEventType(TraxEventType.COURSE); + + OngoingUpdateFieldDTO field1 = OngoingUpdateFieldDTO.builder() + .type(FieldType.STRING).name(FieldName.RECALC_GRAD_ALG).value("Y") + .build(); + requestDTO.getUpdateFields().add(field1); + + OngoingUpdateFieldDTO field2 = OngoingUpdateFieldDTO.builder() + .type(FieldType.STRING).name(FieldName.RECALC_TVR).value("NULL") + .build(); + requestDTO.getUpdateFields().add(field2); + + GraduationStudentRecordEntity savedGraduationStatus = new GraduationStudentRecordEntity(); + BeanUtils.copyProperties(graduationStatusEntity, savedGraduationStatus); + savedGraduationStatus.setRecalculateGradStatus("Y"); + savedGraduationStatus.setRecalculateProjectedGrad(null); + + when(graduationStatusRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity)); + when(graduationStatusRepository.findByStudentID(studentID)).thenReturn(savedGraduationStatus); + when(graduationStatusRepository.saveAndFlush(graduationStatusEntity)).thenReturn(savedGraduationStatus); + + when(this.webClient.delete()).thenReturn(this.requestHeadersUriMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getDeleteStudentAchievements(),studentID))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); + when(this.requestBodyMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(Integer.class)).thenReturn(Mono.just(0)); + + var result = dataConversionService.updateGraduationStatusByFields(requestDTO, "accessToken"); + + assertThat(result).isNotNull(); + assertThat(result.getStudentID()).isEqualTo(graduationStatusEntity.getStudentID()); + assertThat(result.getPen()).isEqualTo(graduationStatusEntity.getPen()); + + assertThat(result.getSchoolOfRecord()).isEqualTo(graduationStatusEntity.getSchoolOfRecord()); + assertThat(result.getGpa()).isEqualTo(graduationStatusEntity.getGpa()); + + assertThat(result.getRecalculateGradStatus()).isEqualTo("Y"); + assertThat(result.getRecalculateProjectedGrad()).isNull(); + } + @Test public void testGraduationStudentRecordAsOngoingUpdateForStudentMergedStatus() { // ID @@ -345,7 +407,7 @@ public void testGraduationStudentRecordAsOngoingUpdateForStudentMergedStatus() { OngoingUpdateRequestDTO requestDTO = new OngoingUpdateRequestDTO(); requestDTO.setPen(pen); requestDTO.setStudentID(studentID.toString()); - requestDTO.setEventType(TraxEventType.UPD_STD_STATUS); + requestDTO.setEventType(TraxEventType.UPD_GRAD); OngoingUpdateFieldDTO field = OngoingUpdateFieldDTO.builder() .type(FieldType.STRING).name(FieldName.STUDENT_STATUS).value(newStatus) @@ -407,7 +469,7 @@ public void testGraduationStudentRecordAsOngoingUpdateForStudentArchivedStatus() OngoingUpdateRequestDTO requestDTO = new OngoingUpdateRequestDTO(); requestDTO.setPen(pen); requestDTO.setStudentID(studentID.toString()); - requestDTO.setEventType(TraxEventType.UPD_STD_STATUS); + requestDTO.setEventType(TraxEventType.UPD_GRAD); OngoingUpdateFieldDTO field = OngoingUpdateFieldDTO.builder() .type(FieldType.STRING).name(FieldName.STUDENT_STATUS).value(newStatus)