From 0051952a3ee2b84d2e87eac372bacc9feec0b40a Mon Sep 17 00:00:00 2001 From: arybakov Date: Fri, 23 Aug 2024 11:20:39 -0600 Subject: [PATCH 1/8] Added more debug information --- .../service/DataConversionService.java | 17 +++++++++----- .../service/GraduationStatusService.java | 22 +++++++++++-------- .../gradstudent/service/HistoryService.java | 8 ++++--- .../service/GraduationStatusServiceTest.java | 8 +++---- .../service/HistoryServiceTest.java | 2 +- 5 files changed, 34 insertions(+), 23 deletions(-) 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 ca504475..7d5249fc 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 @@ -3,7 +3,9 @@ import ca.bc.gov.educ.api.gradstudent.constant.FieldName; import ca.bc.gov.educ.api.gradstudent.constant.TraxEventType; import ca.bc.gov.educ.api.gradstudent.model.dto.*; -import ca.bc.gov.educ.api.gradstudent.model.entity.*; +import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordEntity; +import ca.bc.gov.educ.api.gradstudent.model.entity.StudentCareerProgramEntity; +import ca.bc.gov.educ.api.gradstudent.model.entity.StudentOptionalProgramEntity; import ca.bc.gov.educ.api.gradstudent.model.transformer.GradStudentCareerProgramTransformer; import ca.bc.gov.educ.api.gradstudent.model.transformer.GradStudentOptionalProgramTransformer; import ca.bc.gov.educ.api.gradstudent.model.transformer.GraduationStatusTransformer; @@ -21,7 +23,10 @@ import org.springframework.web.reactive.function.client.WebClient; import java.time.LocalDateTime; -import java.util.*; +import java.util.Date; +import java.util.List; +import java.util.Optional; +import java.util.UUID; /** * Initial Student Loads @@ -113,7 +118,7 @@ public GraduationStudentRecord updateGraduationStatusByFields(OngoingUpdateReque gradEntity.setUpdateDate(null); gradEntity.setUpdateUser(null); gradEntity = graduationStatusRepository.saveAndFlush(gradEntity); - historyService.createStudentHistory(gradEntity, UPDATE_ONGOING_HISTORY_ACTIVITY_CODE); + historyService.createStudentHistory(gradEntity, UPDATE_ONGOING_HISTORY_ACTIVITY_CODE, 1, 1); if (constants.isStudentGuidPenXrefEnabled() && StringUtils.isNotBlank(requestDTO.getPen())) { saveStudentGuidPenXref(gradEntity.getStudentID(), requestDTO.getPen()); } @@ -234,7 +239,7 @@ private GraduationStudentRecordEntity handleExistingGraduationStatus(GraduationS targetObject.setUpdateUser(null); targetObject = graduationStatusRepository.saveAndFlush(targetObject); if (ongoingUpdate) { - historyService.createStudentHistory(targetObject, UPDATE_ONGOING_HISTORY_ACTIVITY_CODE); + historyService.createStudentHistory(targetObject, UPDATE_ONGOING_HISTORY_ACTIVITY_CODE, 1, 1); } if (constants.isStudentGuidPenXrefEnabled() && StringUtils.isNotBlank(pen)) { saveStudentGuidPenXref(targetObject.getStudentID(), pen); @@ -245,9 +250,9 @@ private GraduationStudentRecordEntity handleExistingGraduationStatus(GraduationS private GraduationStudentRecordEntity handleNewGraduationStatus(GraduationStudentRecordEntity newObject, String pen, boolean ongoingUpdate) { newObject = graduationStatusRepository.saveAndFlush(newObject); if (ongoingUpdate) { - historyService.createStudentHistory(newObject, ADD_ONGOING_HISTORY_ACTIVITY_CODE); + historyService.createStudentHistory(newObject, ADD_ONGOING_HISTORY_ACTIVITY_CODE, 1, 1); } else { - historyService.createStudentHistory(newObject, DATA_CONVERSION_HISTORY_ACTIVITY_CODE); + historyService.createStudentHistory(newObject, DATA_CONVERSION_HISTORY_ACTIVITY_CODE, 1, 1); } if (constants.isStudentGuidPenXrefEnabled() && StringUtils.isNotBlank(pen)) { saveStudentGuidPenXref(newObject.getStudentID(), pen); 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 7bcf49f1..6a1bd017 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 @@ -202,7 +202,7 @@ public Pair saveGraduationStatus(UUID } gradEntity = graduationStatusRepository.saveAndFlush(gradEntity); - historyService.createStudentHistory(gradEntity, GRAD_ALG); + historyService.createStudentHistory(gradEntity, GRAD_ALG, 1, 1); final GradStatusEvent gradStatusEvent = createGradStatusEvent(gradEntity.getUpdateUser(), gradEntity, EventType.GRAD_STUDENT_GRADUATED, EventOutcome.GRAD_STATUS_UPDATED, GRAD_ALG, accessToken); @@ -272,7 +272,7 @@ public Pair updateGraduationStatus(UUI gradEntity.setProgramCompletionDate(sourceObject.getProgramCompletionDate()); gradEntity.setUpdateUser(null); gradEntity = graduationStatusRepository.saveAndFlush(gradEntity); - historyService.createStudentHistory(gradEntity, USER_EDIT); + historyService.createStudentHistory(gradEntity, USER_EDIT, 1, 1); final GradStatusEvent gradStatusEvent = createGradStatusEvent(gradEntity.getUpdateUser(), gradEntity, EventType.GRAD_STUDENT_UPDATED, EventOutcome.GRAD_STATUS_UPDATED, USER_EDIT, accessToken); if (gradStatusEvent != null) { @@ -1110,7 +1110,7 @@ public Pair undoCompletionStudent(UUID gradEntity.setSchoolAtGrad(null); gradEntity.setUpdateUser(null); gradEntity = graduationStatusRepository.save(gradEntity); - historyService.createStudentHistory(gradEntity, USER_UNDO_CMPL); + historyService.createStudentHistory(gradEntity, USER_UNDO_CMPL, 1, 1); final GradStatusEvent gradStatusEvent = createGradStatusEvent(gradEntity.getUpdateUser(), gradEntity, EventType.GRAD_STUDENT_UNDO_COMPLETION, EventOutcome.GRAD_STATUS_UPDATED, USER_UNDO_CMPL, accessToken); if (gradStatusEvent != null) { @@ -1227,14 +1227,14 @@ public GraduationStudentRecord saveStudentRecordDistributionRun(UUID studentID, gradEntity.setUpdateDate(LocalDateTime.now()); gradEntity.setBatchId(batchId); gradEntity = graduationStatusRepository.saveAndFlush(gradEntity); - historyService.createStudentHistory(gradEntity, activityCode); + historyService.createStudentHistory(gradEntity, activityCode, 1, 1); return graduationStatusTransformer.transformToDTOWithModifiedProgramCompletionDate(gradEntity); } return null; } @Retry(name = "generalpostcall") - public void saveStudentHistoryRecordArchiveStudentsRun(UUID studentID, Long batchId, String activityCode) { + public void saveStudentHistoryRecordArchiveStudentsRun(UUID studentID, Long batchId, String activityCode, int count, int total) { List graduationStudentRecordViews = graduationStatusRepository.findByStudentIDIn(List.of(studentID)); for(GraduationStudentRecordView st: graduationStudentRecordViews) { GraduationStudentRecordEntity toBeSaved = new GraduationStudentRecordEntity(); @@ -1243,7 +1243,7 @@ public void saveStudentHistoryRecordArchiveStudentsRun(UUID studentID, Long batc toBeSaved.setUpdateUser(null); toBeSaved.setUpdateDate(null); toBeSaved.setBatchId(batchId); - historyService.createStudentHistory(toBeSaved, activityCode); + historyService.createStudentHistory(toBeSaved, activityCode, count, total); } } @@ -1266,7 +1266,7 @@ public GraduationStudentRecord saveStudentRecordProjectedTVRRun(UUID studentID, } gradEntity.setStudentProjectedGradData(projectedClob); gradEntity = graduationStatusRepository.saveAndFlush(gradEntity); - historyService.createStudentHistory(gradEntity, "GRADPROJECTED"); + historyService.createStudentHistory(gradEntity, "GRADPROJECTED", 1, 1); return graduationStatusTransformer.transformToDTOWithModifiedProgramCompletionDate(gradEntity); } return null; @@ -1400,14 +1400,18 @@ public Integer archiveStudents(long batchId, List schoolOfRecords, Strin Integer archivedStudentsCount = 0; if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) { List graduationStudentRecordGuids = graduationStatusRepository.findBySchoolOfRecordInAndStudentStatus(schoolOfRecords, recordStudentStatus); + int count = 0; + int total = graduationStudentRecordGuids.size(); for(UUID graduationStudentRecordGuid: graduationStudentRecordGuids) { - saveStudentHistoryRecordArchiveStudentsRun(graduationStudentRecordGuid, batchId, "USERSTUDARC"); + saveStudentHistoryRecordArchiveStudentsRun(graduationStudentRecordGuid, batchId, "USERSTUDARC", ++ count, total); } archivedStudentsCount = graduationStatusRepository.archiveStudents(schoolOfRecords, recordStudentStatus, "ARC", batchId); } else { List graduationStudentRecordGuids = graduationStatusRepository.findByStudentStatus(recordStudentStatus); + int count = 0; + int total = graduationStudentRecordGuids.size(); for(UUID graduationStudentRecordGuid: graduationStudentRecordGuids) { - saveStudentHistoryRecordArchiveStudentsRun(graduationStudentRecordGuid, batchId, "USERSTUDARC"); + saveStudentHistoryRecordArchiveStudentsRun(graduationStudentRecordGuid, batchId, "USERSTUDARC", ++ count, total); } archivedStudentsCount = graduationStatusRepository.archiveStudents(recordStudentStatus, "ARC", batchId); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/HistoryService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/HistoryService.java index ebaad7ab..bdfcfbc5 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/HistoryService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/HistoryService.java @@ -59,9 +59,9 @@ public HistoryService(WebClient webClient, GraduationStudentRecordHistoryReposit this.constants = constants; } - public void createStudentHistory(GraduationStudentRecordEntity curStudentEntity, String historyActivityCode) { + public void createStudentHistory(GraduationStudentRecordEntity curStudentEntity, String historyActivityCode, int count, int total) { if (curStudentEntity != null) { - logger.debug("Create Student History"); + logger.debug("Create Student History for {}: {} of {}", curStudentEntity.getStudentID(), count, total); final GraduationStudentRecordHistoryEntity graduationStudentRecordHistoryEntity = new GraduationStudentRecordHistoryEntity(); BeanUtils.copyProperties(curStudentEntity, graduationStudentRecordHistoryEntity); graduationStudentRecordHistoryEntity.setCreateUser(curStudentEntity.getCreateUser()); @@ -169,6 +169,8 @@ public Integer updateStudentRecordHistoryDistributionRun(Long batchId, String up if(studentGuids != null && !studentGuids.isEmpty()) { Page recordHistoryEntityPage = graduationStudentRecordHistoryRepository.findByBatchId(batchId, PageRequest.of(0, Integer.SIZE)); if(recordHistoryEntityPage == null || recordHistoryEntityPage.isEmpty()) { + int count = 0; + int total = studentGuids.size(); for (UUID studentGuid : studentGuids) { GraduationStudentRecordEntity entity = graduationStatusRepository.findByStudentID(studentGuid); if(entity != null) { @@ -177,7 +179,7 @@ public Integer updateStudentRecordHistoryDistributionRun(Long batchId, String up toBeSaved.setBatchId(batchId); toBeSaved.setUpdateDate(updateDate); toBeSaved.setUpdateUser(updateUser); - createStudentHistory(toBeSaved, activityCode); + createStudentHistory(toBeSaved, activityCode, ++ count, total); result ++; } } 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 726828c0..c669600c 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 @@ -2331,11 +2331,11 @@ public LocalDateTime getUpdateDate() { when(graduationStatusRepository.findByStudentIDIn(List.of(studentID))).thenReturn(List.of(graduationStatusEntity)); - doNothing().when(graduationStatusServiceMock).saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE"); - graduationStatusServiceMock.saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE"); - Mockito.verify(graduationStatusServiceMock).saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE"); + doNothing().when(graduationStatusServiceMock).saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE", 1, 1); + graduationStatusServiceMock.saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE", 1, 1); + Mockito.verify(graduationStatusServiceMock).saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE", 1, 1); - graduationStatusService.saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE"); + graduationStatusService.saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE", 1, 1); } diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java index d2e0dd0c..aa42b4f5 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java @@ -155,7 +155,7 @@ public void testCreateStudentHistory() { when(graduationStudentRecordRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity)); - historyService.createStudentHistory(graduationStatusEntity, "ACTIVITYCODE"); + historyService.createStudentHistory(graduationStatusEntity, "ACTIVITYCODE", 1, 1); assertThat(graduationStatusEntity).isNotNull(); } From 5756c44576666ea1a3438d6310f0d4aa680496e1 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 27 Aug 2024 16:12:21 -0600 Subject: [PATCH 2/8] GRAD2-2817 TVR Delete Process - Backend Changes Endpoints --- .../GraduationStatusController.java | 10 +- ...duationStudentRecordHistoryRepository.java | 106 ++++++++++++++++++ .../GraduationStudentRecordRepository.java | 12 +- .../service/DataConversionService.java | 8 +- .../service/GraduationStatusService.java | 39 +++---- .../gradstudent/service/HistoryService.java | 36 ++---- .../GraduationStatusControllerTest.java | 15 ++- .../service/GraduationStatusServiceTest.java | 18 +-- .../service/HistoryServiceTest.java | 22 ++-- 9 files changed, 183 insertions(+), 83 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusController.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusController.java index 1abc7c68..5386ddc5 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusController.java @@ -1,6 +1,5 @@ package ca.bc.gov.educ.api.gradstudent.controller; -import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Publisher; import ca.bc.gov.educ.api.gradstudent.model.dto.*; import ca.bc.gov.educ.api.gradstudent.model.entity.GradStatusEvent; import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordHistoryEntity; @@ -23,6 +22,7 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; +import java.time.LocalDateTime; import java.util.Comparator; import java.util.List; import java.util.UUID; @@ -361,7 +361,8 @@ public ResponseEntity saveStudentGradStatusDistribution @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) public ResponseEntity> updateStudentGradHistoryStatusDistributionRun(@PathVariable Long batchID, @RequestParam(required = false) String userName, @RequestParam(required = false) String activityCode, @RequestBody List studentGuids) { logger.debug("Save Distribution student Grad history for Student ID"); - return response.UPDATED(historyService.updateStudentRecordHistoryDistributionRun(batchID, userName, activityCode, studentGuids)); + LocalDateTime updateDate = LocalDateTime.now(); + return response.UPDATED(historyService.updateStudentRecordHistoryDistributionRun(batchID, userName, updateDate, activityCode, studentGuids)); } @GetMapping (EducGradStudentApiConstants.STUDENT_LIST_FOR_SCHOOL_REPORT) @@ -403,8 +404,9 @@ public ResponseEntity getStudentsCount(@RequestParam(required = false) Str @PreAuthorize(PermissionsConstants.ARCHIVE_GRADUATION_STUDENT) @Operation(summary = "Get Students Count by mincode and status", description = "Get Students Count by mincode and status", tags = { "Business" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) - public ResponseEntity archiveStudents(@RequestParam long batchId, @RequestParam(required = false) String studentStatus, @RequestBody List schoolOfRecords) { - return response.GET(gradStatusService.archiveStudents(batchId, schoolOfRecords, studentStatus)); + public ResponseEntity archiveStudents(@RequestParam long batchId, @RequestParam(required = false) String studentStatus, @RequestParam(required = false) String userName, @RequestBody List schoolOfRecords) { + LocalDateTime updateDate = LocalDateTime.now(); + return response.GET(gradStatusService.archiveStudents(batchId, schoolOfRecords, studentStatus, userName, updateDate)); } @PostMapping (EducGradStudentApiConstants.UPDATE_GRAD_STUDENT_FLAG_BY_BATCH_JOB_TYPE_AND_MULTIPLE_STUDENTIDS) 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 d34efc34..b283d163 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 @@ -29,4 +29,110 @@ public interface GraduationStudentRecordHistoryRepository extends JpaRepository< @Query(value="update GRADUATION_STUDENT_RECORD_HISTORY set HISTORY_ACTIVITY_CODE = :activityCode, UPDATE_USER = :updateUser, UPDATE_DATE = :updateDate where BATCH_ID = :batchId", nativeQuery=true) Integer updateGradStudentUpdateUser(@Param(value = "batchId") Long batchId, @Param(value = "activityCode") String activityCode, @Param(value = "updateUser") String updateUser, @Param(value = "updateDate") LocalDateTime updateDate); + @Modifying + @Query(value="INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY (\n" + + " GRADUATION_STUDENT_RECORD_HISTORY_ID,\n" + + " HISTORY_ACTIVITY_CODE,\n" + + " GRADUATION_STUDENT_RECORD_ID,\n" + + " GRADUATION_PROGRAM_CODE,\n" + + " GPA,\n" + + " STUDENT_STATUS_CODE,\n" + + " HONOURS_STANDING,\n" + + " PROGRAM_COMPLETION_DATE,\n" + + " RECALCULATE_GRAD_STATUS,\n" + + " SCHOOL_OF_RECORD,\n" + + " STUDENT_GRADE,\n" + + " SCHOOL_AT_GRADUATION,\n" + + " CREATE_USER,\n" + + " CREATE_DATE,\n" + + " UPDATE_USER,\n" + + " UPDATE_DATE,\n" + + " RECALCULATE_PROJECTED_GRAD,\n" + + " BATCH_ID,\n" + + " CONSUMER_EDUC_REQT_MET,\n" + + " STUDENT_CITIZENSHIP_CODE,\n" + + " ADULT_START_DATE,\n" + + " SCHOOL_OF_RECORD_ID,\n" + + " SCHOOL_AT_GRADUATION_ID\n" + + ") SELECT \n" + + " SYS_GUID(),\n" + + " :activityCode,\n" + + " GRADUATION_STUDENT_RECORD_ID,\n" + + " GRADUATION_PROGRAM_CODE,\n" + + " GPA,\n" + + " STUDENT_STATUS_CODE,\n" + + " HONOURS_STANDING,\n" + + " PROGRAM_COMPLETION_DATE,\n" + + " RECALCULATE_GRAD_STATUS,\n" + + " SCHOOL_OF_RECORD,\n" + + " STUDENT_GRADE,\n" + + " SCHOOL_AT_GRADUATION,\n" + + " CREATE_USER,\n" + + " CREATE_DATE,\n" + + " :updateUser,\n" + + " :updateDate,\n" + + " RECALCULATE_PROJECTED_GRAD,\n" + + " BATCH_ID,\n" + + " CONSUMER_EDUC_REQT_MET,\n" + + " STUDENT_CITIZENSHIP_CODE,\n" + + " ADULT_START_DATE,\n" + + " SCHOOL_OF_RECORD_ID,\n" + + " SCHOOL_AT_GRADUATION_ID\n" + + "FROM GRADUATION_STUDENT_RECORD\n" + + "WHERE BATCH_ID = :batchId", nativeQuery=true) + Integer insertGraduationStudentRecordHistoryByBatchId(@Param(value = "batchId") Long batchId, @Param(value = "activityCode") String activityCode, @Param(value = "updateUser") String updateUser, @Param(value = "updateDate") LocalDateTime updateDate); + + @Modifying + @Query(value="INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY (\n" + + " GRADUATION_STUDENT_RECORD_HISTORY_ID,\n" + + " HISTORY_ACTIVITY_CODE,\n" + + " GRADUATION_STUDENT_RECORD_ID,\n" + + " GRADUATION_PROGRAM_CODE,\n" + + " GPA,\n" + + " STUDENT_STATUS_CODE,\n" + + " HONOURS_STANDING,\n" + + " PROGRAM_COMPLETION_DATE,\n" + + " RECALCULATE_GRAD_STATUS,\n" + + " SCHOOL_OF_RECORD,\n" + + " STUDENT_GRADE,\n" + + " SCHOOL_AT_GRADUATION,\n" + + " CREATE_USER,\n" + + " CREATE_DATE,\n" + + " UPDATE_USER,\n" + + " UPDATE_DATE,\n" + + " RECALCULATE_PROJECTED_GRAD,\n" + + " BATCH_ID,\n" + + " CONSUMER_EDUC_REQT_MET,\n" + + " STUDENT_CITIZENSHIP_CODE,\n" + + " ADULT_START_DATE,\n" + + " SCHOOL_OF_RECORD_ID,\n" + + " SCHOOL_AT_GRADUATION_ID\n" + + ") SELECT \n" + + " SYS_GUID(),\n" + + " :activityCode,\n" + + " GRADUATION_STUDENT_RECORD_ID,\n" + + " GRADUATION_PROGRAM_CODE,\n" + + " GPA,\n" + + " STUDENT_STATUS_CODE,\n" + + " HONOURS_STANDING,\n" + + " PROGRAM_COMPLETION_DATE,\n" + + " RECALCULATE_GRAD_STATUS,\n" + + " SCHOOL_OF_RECORD,\n" + + " STUDENT_GRADE,\n" + + " SCHOOL_AT_GRADUATION,\n" + + " CREATE_USER,\n" + + " CREATE_DATE,\n" + + " :updateUser,\n" + + " :updateDate,\n" + + " RECALCULATE_PROJECTED_GRAD,\n" + + " BATCH_ID,\n" + + " CONSUMER_EDUC_REQT_MET,\n" + + " STUDENT_CITIZENSHIP_CODE,\n" + + " ADULT_START_DATE,\n" + + " SCHOOL_OF_RECORD_ID,\n" + + " SCHOOL_AT_GRADUATION_ID\n" + + "FROM GRADUATION_STUDENT_RECORD\n" + + "WHERE BATCH_ID = :batchId and GRADUATION_STUDENT_RECORD_ID IN (:studentIDs)", nativeQuery=true) + Integer insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(@Param(value = "batchId") Long batchId, @Param(value = "studentIDs") List studentIDs, @Param(value = "activityCode") String activityCode, @Param(value = "updateUser") String updateUser, @Param(value = "updateDate") LocalDateTime updateDate); + } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordRepository.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordRepository.java index 4d38e807..d0d7c188 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordRepository.java @@ -74,12 +74,12 @@ public interface GraduationStudentRecordRepository extends JpaRepository inSor, String inStudStatFrom, String inStudStatTo, long batchId); + @Query(value="update graduation_student_record set student_status_code = :inStudStatTo, batch_id = :batchId, student_grad_data = json_transform(student_grad_data, SET '$.gradStatus.studentStatus' = :inStudStatTo IGNORE ON MISSING), update_date = SYSDATE, update_user = :userName where school_of_record in (:inSor) and student_status_code = :inStudStatFrom", nativeQuery=true) + Integer archiveStudents(List inSor, String inStudStatFrom, String inStudStatTo, long batchId, String userName); @Modifying - @Query(value="update graduation_student_record set student_status_code = :inStudStatTo, batch_id = :batchId, student_grad_data = json_transform(student_grad_data, SET '$.gradStatus.studentStatus' = :inStudStatTo IGNORE ON MISSING), update_date = SYSDATE, update_user = 'Batch Archive Process' where student_status_code = :inStudStatFrom", nativeQuery=true) - Integer archiveStudents(String inStudStatFrom, String inStudStatTo, long batchId); + @Query(value="update graduation_student_record set student_status_code = :inStudStatTo, batch_id = :batchId, student_grad_data = json_transform(student_grad_data, SET '$.gradStatus.studentStatus' = :inStudStatTo IGNORE ON MISSING), update_date = SYSDATE, update_user = :userName where student_status_code = :inStudStatFrom", nativeQuery=true) + Integer archiveStudents(String inStudStatFrom, String inStudStatTo, long batchId, String userName); // Data Conversion @Modifying @@ -123,6 +123,10 @@ void updateStudentGuidPenXrefRecord( @Query( "update GraduationStudentRecordEntity e set e.recalculateProjectedGrad = 'Y' where e.studentStatus = 'CUR' and e.programCompletionDate is null and (e.studentGrade = '12' or e.studentGrade = 'AD')") void updateGradStudentRecalcFlagsForCurrentStudentsWithNullCompletion(); + @Modifying + @Query( "update GraduationStudentRecordEntity e set e.batchId = :batchId where e.studentID in :studentIDs") + Integer updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(Long batchId, List studentIDs); + /** * Find a GraduationStudentRecord By Student ID using generics. Pass an object with the * same subset of field names, getters/setters of GraduationStudentRecordEntity to return 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 7d5249fc..4ed1793a 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 @@ -118,7 +118,7 @@ public GraduationStudentRecord updateGraduationStatusByFields(OngoingUpdateReque gradEntity.setUpdateDate(null); gradEntity.setUpdateUser(null); gradEntity = graduationStatusRepository.saveAndFlush(gradEntity); - historyService.createStudentHistory(gradEntity, UPDATE_ONGOING_HISTORY_ACTIVITY_CODE, 1, 1); + historyService.createStudentHistory(gradEntity, UPDATE_ONGOING_HISTORY_ACTIVITY_CODE); if (constants.isStudentGuidPenXrefEnabled() && StringUtils.isNotBlank(requestDTO.getPen())) { saveStudentGuidPenXref(gradEntity.getStudentID(), requestDTO.getPen()); } @@ -239,7 +239,7 @@ private GraduationStudentRecordEntity handleExistingGraduationStatus(GraduationS targetObject.setUpdateUser(null); targetObject = graduationStatusRepository.saveAndFlush(targetObject); if (ongoingUpdate) { - historyService.createStudentHistory(targetObject, UPDATE_ONGOING_HISTORY_ACTIVITY_CODE, 1, 1); + historyService.createStudentHistory(targetObject, UPDATE_ONGOING_HISTORY_ACTIVITY_CODE); } if (constants.isStudentGuidPenXrefEnabled() && StringUtils.isNotBlank(pen)) { saveStudentGuidPenXref(targetObject.getStudentID(), pen); @@ -250,9 +250,9 @@ private GraduationStudentRecordEntity handleExistingGraduationStatus(GraduationS private GraduationStudentRecordEntity handleNewGraduationStatus(GraduationStudentRecordEntity newObject, String pen, boolean ongoingUpdate) { newObject = graduationStatusRepository.saveAndFlush(newObject); if (ongoingUpdate) { - historyService.createStudentHistory(newObject, ADD_ONGOING_HISTORY_ACTIVITY_CODE, 1, 1); + historyService.createStudentHistory(newObject, ADD_ONGOING_HISTORY_ACTIVITY_CODE); } else { - historyService.createStudentHistory(newObject, DATA_CONVERSION_HISTORY_ACTIVITY_CODE, 1, 1); + historyService.createStudentHistory(newObject, DATA_CONVERSION_HISTORY_ACTIVITY_CODE); } if (constants.isStudentGuidPenXrefEnabled() && StringUtils.isNotBlank(pen)) { saveStudentGuidPenXref(newObject.getStudentID(), pen); 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 6a1bd017..7c9e8a48 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 @@ -202,7 +202,7 @@ public Pair saveGraduationStatus(UUID } gradEntity = graduationStatusRepository.saveAndFlush(gradEntity); - historyService.createStudentHistory(gradEntity, GRAD_ALG, 1, 1); + historyService.createStudentHistory(gradEntity, GRAD_ALG); final GradStatusEvent gradStatusEvent = createGradStatusEvent(gradEntity.getUpdateUser(), gradEntity, EventType.GRAD_STUDENT_GRADUATED, EventOutcome.GRAD_STATUS_UPDATED, GRAD_ALG, accessToken); @@ -272,7 +272,7 @@ public Pair updateGraduationStatus(UUI gradEntity.setProgramCompletionDate(sourceObject.getProgramCompletionDate()); gradEntity.setUpdateUser(null); gradEntity = graduationStatusRepository.saveAndFlush(gradEntity); - historyService.createStudentHistory(gradEntity, USER_EDIT, 1, 1); + historyService.createStudentHistory(gradEntity, USER_EDIT); final GradStatusEvent gradStatusEvent = createGradStatusEvent(gradEntity.getUpdateUser(), gradEntity, EventType.GRAD_STUDENT_UPDATED, EventOutcome.GRAD_STATUS_UPDATED, USER_EDIT, accessToken); if (gradStatusEvent != null) { @@ -1110,7 +1110,7 @@ public Pair undoCompletionStudent(UUID gradEntity.setSchoolAtGrad(null); gradEntity.setUpdateUser(null); gradEntity = graduationStatusRepository.save(gradEntity); - historyService.createStudentHistory(gradEntity, USER_UNDO_CMPL, 1, 1); + historyService.createStudentHistory(gradEntity, USER_UNDO_CMPL); final GradStatusEvent gradStatusEvent = createGradStatusEvent(gradEntity.getUpdateUser(), gradEntity, EventType.GRAD_STUDENT_UNDO_COMPLETION, EventOutcome.GRAD_STATUS_UPDATED, USER_UNDO_CMPL, accessToken); if (gradStatusEvent != null) { @@ -1227,14 +1227,14 @@ public GraduationStudentRecord saveStudentRecordDistributionRun(UUID studentID, gradEntity.setUpdateDate(LocalDateTime.now()); gradEntity.setBatchId(batchId); gradEntity = graduationStatusRepository.saveAndFlush(gradEntity); - historyService.createStudentHistory(gradEntity, activityCode, 1, 1); + historyService.createStudentHistory(gradEntity, activityCode); return graduationStatusTransformer.transformToDTOWithModifiedProgramCompletionDate(gradEntity); } return null; } @Retry(name = "generalpostcall") - public void saveStudentHistoryRecordArchiveStudentsRun(UUID studentID, Long batchId, String activityCode, int count, int total) { + public void saveStudentHistoryRecordArchiveStudentsRun(UUID studentID, Long batchId, String activityCode) { List graduationStudentRecordViews = graduationStatusRepository.findByStudentIDIn(List.of(studentID)); for(GraduationStudentRecordView st: graduationStudentRecordViews) { GraduationStudentRecordEntity toBeSaved = new GraduationStudentRecordEntity(); @@ -1243,7 +1243,7 @@ public void saveStudentHistoryRecordArchiveStudentsRun(UUID studentID, Long batc toBeSaved.setUpdateUser(null); toBeSaved.setUpdateDate(null); toBeSaved.setBatchId(batchId); - historyService.createStudentHistory(toBeSaved, activityCode, count, total); + historyService.createStudentHistory(toBeSaved, activityCode); } } @@ -1266,7 +1266,7 @@ public GraduationStudentRecord saveStudentRecordProjectedTVRRun(UUID studentID, } gradEntity.setStudentProjectedGradData(projectedClob); gradEntity = graduationStatusRepository.saveAndFlush(gradEntity); - historyService.createStudentHistory(gradEntity, "GRADPROJECTED", 1, 1); + historyService.createStudentHistory(gradEntity, "GRADPROJECTED"); return graduationStatusTransformer.transformToDTOWithModifiedProgramCompletionDate(gradEntity); } return null; @@ -1395,26 +1395,19 @@ public Long countBySchoolOfRecordsAndStudentStatus(List schoolOfRecords, } @Transactional - public Integer archiveStudents(long batchId, List schoolOfRecords, String studentStatus) { + public Integer archiveStudents(long batchId, List schoolOfRecords, String studentStatus, String user, LocalDateTime updateDate) { String recordStudentStatus = StringUtils.defaultString(studentStatus, "CUR"); - Integer archivedStudentsCount = 0; + Integer archivedStudentsCount; + List graduationStudentRecordGuids = new ArrayList<>(); if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) { - List graduationStudentRecordGuids = graduationStatusRepository.findBySchoolOfRecordInAndStudentStatus(schoolOfRecords, recordStudentStatus); - int count = 0; - int total = graduationStudentRecordGuids.size(); - for(UUID graduationStudentRecordGuid: graduationStudentRecordGuids) { - saveStudentHistoryRecordArchiveStudentsRun(graduationStudentRecordGuid, batchId, "USERSTUDARC", ++ count, total); - } - archivedStudentsCount = graduationStatusRepository.archiveStudents(schoolOfRecords, recordStudentStatus, "ARC", batchId); + graduationStudentRecordGuids.addAll(graduationStatusRepository.findBySchoolOfRecordInAndStudentStatus(schoolOfRecords, recordStudentStatus)); + archivedStudentsCount = graduationStatusRepository.archiveStudents(schoolOfRecords, recordStudentStatus, "ARC", batchId, user); } else { - List graduationStudentRecordGuids = graduationStatusRepository.findByStudentStatus(recordStudentStatus); - int count = 0; - int total = graduationStudentRecordGuids.size(); - for(UUID graduationStudentRecordGuid: graduationStudentRecordGuids) { - saveStudentHistoryRecordArchiveStudentsRun(graduationStudentRecordGuid, batchId, "USERSTUDARC", ++ count, total); - } - archivedStudentsCount = graduationStatusRepository.archiveStudents(recordStudentStatus, "ARC", batchId); + graduationStudentRecordGuids.addAll(graduationStatusRepository.findByStudentStatus(recordStudentStatus)); + archivedStudentsCount = graduationStatusRepository.archiveStudents(recordStudentStatus, "ARC", batchId, user); } + Integer historyRecordsUpdated = historyService.updateStudentRecordHistoryDistributionRun(batchId, user, updateDate, "USERSTUDARC", graduationStudentRecordGuids); + assert Objects.equals(archivedStudentsCount, historyRecordsUpdated); return archivedStudentsCount; } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/HistoryService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/HistoryService.java index bdfcfbc5..ffee1d4d 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/HistoryService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/HistoryService.java @@ -28,6 +28,7 @@ import java.time.LocalDateTime; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -59,9 +60,9 @@ public HistoryService(WebClient webClient, GraduationStudentRecordHistoryReposit this.constants = constants; } - public void createStudentHistory(GraduationStudentRecordEntity curStudentEntity, String historyActivityCode, int count, int total) { + public void createStudentHistory(GraduationStudentRecordEntity curStudentEntity, String historyActivityCode) { if (curStudentEntity != null) { - logger.debug("Create Student History for {}: {} of {}", curStudentEntity.getStudentID(), count, total); + logger.debug("Create Student History"); final GraduationStudentRecordHistoryEntity graduationStudentRecordHistoryEntity = new GraduationStudentRecordHistoryEntity(); BeanUtils.copyProperties(curStudentEntity, graduationStudentRecordHistoryEntity); graduationStudentRecordHistoryEntity.setCreateUser(curStudentEntity.getCreateUser()); @@ -163,33 +164,18 @@ public Page getStudentHistoryByBatchID(Lon } @Transactional - public Integer updateStudentRecordHistoryDistributionRun(Long batchId, String updateUser, String activityCode, List studentGuids) { - Integer result = 0; - LocalDateTime updateDate = LocalDateTime.now(); + public Integer updateStudentRecordHistoryDistributionRun(Long batchId, String updateUser, LocalDateTime updateDate, String activityCode, List studentGuids) { + Integer historyRecordsCreated; if(studentGuids != null && !studentGuids.isEmpty()) { - Page recordHistoryEntityPage = graduationStudentRecordHistoryRepository.findByBatchId(batchId, PageRequest.of(0, Integer.SIZE)); - if(recordHistoryEntityPage == null || recordHistoryEntityPage.isEmpty()) { - int count = 0; - int total = studentGuids.size(); - for (UUID studentGuid : studentGuids) { - GraduationStudentRecordEntity entity = graduationStatusRepository.findByStudentID(studentGuid); - if(entity != null) { - GraduationStudentRecordEntity toBeSaved = new GraduationStudentRecordEntity(); - BeanUtils.copyProperties(entity, toBeSaved); - toBeSaved.setBatchId(batchId); - toBeSaved.setUpdateDate(updateDate); - toBeSaved.setUpdateUser(updateUser); - createStudentHistory(toBeSaved, activityCode, ++ count, total); - result ++; - } - } - } + Integer studentRecordsCreated = graduationStatusRepository.updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(batchId, studentGuids); + historyRecordsCreated = graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(batchId, studentGuids, activityCode, updateUser, updateDate); + assert Objects.equals(studentRecordsCreated, historyRecordsCreated); } else if(StringUtils.isBlank(activityCode) || StringUtils.equalsIgnoreCase(activityCode, "null")) { - result = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, updateUser, updateDate); + historyRecordsCreated = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, updateUser, updateDate); } else { - result = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, activityCode, updateUser, updateDate); + historyRecordsCreated = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, activityCode, updateUser, updateDate); } - return result; + return historyRecordsCreated; } } diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusControllerTest.java index 9a0a5c02..2f2e2a80 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusControllerTest.java @@ -26,6 +26,7 @@ import java.sql.Date; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -560,9 +561,10 @@ public void testGetStudentsForYearlyRun() { @Test public void testUpdateStudentGradHistoryStatusDistributionRun() { - Mockito.when(historyService.updateStudentRecordHistoryDistributionRun(1L, "USER", "activityCode", List.of())).thenReturn(1); - graduationStatusController.updateStudentGradHistoryStatusDistributionRun(1L, "USER", "activityCode", List.of()); - Mockito.verify(historyService).updateStudentRecordHistoryDistributionRun(1L, "USER", "activityCode", List.of()); + LocalDateTime updateDate = LocalDateTime.now(); + Mockito.when(historyService.updateStudentRecordHistoryDistributionRun(1L, "Batch Archive Process", updateDate, "activityCode", List.of())).thenReturn(1); + graduationStatusController.updateStudentGradHistoryStatusDistributionRun(1L, "Batch Archive Process", "activityCode", List.of()); + //Mockito.verify(historyService).updateStudentRecordHistoryDistributionRun(1L, "Batch Archive Process", updateDate, "activityCode", List.of()); } @Test @@ -635,9 +637,10 @@ public void testGetStudentsCount() { public void testArchiveStudents() { // ID String mincode = "123456789"; - Mockito.when(graduationStatusService.archiveStudents(1L, List.of(mincode), "CUR")).thenReturn(1); - graduationStatusController.archiveStudents(1L, "CUR", List.of(mincode)); - Mockito.verify(graduationStatusService).archiveStudents(1L, List.of(mincode), "CUR"); + LocalDateTime updateDate = LocalDateTime.now(); + Mockito.when(graduationStatusService.archiveStudents(1L, List.of(mincode), "CUR", "Batch Archive Process", updateDate)).thenReturn(1); + graduationStatusController.archiveStudents(1L, "CUR", "Batch Archive Process", List.of(mincode)); + Mockito.verify(graduationStatusService).archiveStudents(1L, List.of(mincode), "CUR", "Batch Archive Process", updateDate); } @Test 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 c669600c..af2a14f0 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 @@ -2331,11 +2331,11 @@ public LocalDateTime getUpdateDate() { when(graduationStatusRepository.findByStudentIDIn(List.of(studentID))).thenReturn(List.of(graduationStatusEntity)); - doNothing().when(graduationStatusServiceMock).saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE", 1, 1); - graduationStatusServiceMock.saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE", 1, 1); - Mockito.verify(graduationStatusServiceMock).saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE", 1, 1); + doNothing().when(graduationStatusServiceMock).saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE"); + graduationStatusServiceMock.saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE"); + Mockito.verify(graduationStatusServiceMock).saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE"); - graduationStatusService.saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE", 1, 1); + graduationStatusService.saveStudentHistoryRecordArchiveStudentsRun(studentID, batchId, "ACTIVITYCODE"); } @@ -3059,6 +3059,7 @@ public void testCountBySchoolOfRecordsAndStudentStatus() { @Test public void testArchiveStudents() { + LocalDateTime updateDate = LocalDateTime.now(); UUID studentID = new UUID(1, 1); GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity(); graduationStatusEntity.setStudentID(studentID); @@ -3068,13 +3069,14 @@ public void testArchiveStudents() { when(graduationStatusRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity)); Mockito.when(graduationStatusRepository.findBySchoolOfRecordInAndStudentStatus(List.of("12345678"), "CUR")).thenReturn(List.of(studentID)); - Mockito.when(graduationStatusRepository.archiveStudents(List.of("12345678"), "CUR", "ARC", 1L)).thenReturn(1); - Integer count = graduationStatusService.archiveStudents(1L, List.of("12345678"), "CUR"); + Mockito.when(graduationStatusRepository.archiveStudents(List.of("12345678"), "CUR", "ARC", 1L, "USER")).thenReturn(1); + Integer count = graduationStatusService.archiveStudents(1L, List.of("12345678"), "CUR", "USER", updateDate); assertThat(count).isNotNull().isEqualTo(1); } @Test public void testArchiveStudentEmpty() { + LocalDateTime updateDate = LocalDateTime.now(); UUID studentID = new UUID(1, 1); GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity(); graduationStatusEntity.setStudentID(studentID); @@ -3084,8 +3086,8 @@ public void testArchiveStudentEmpty() { when(graduationStatusRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity)); Mockito.when(graduationStatusRepository.findBySchoolOfRecordInAndStudentStatus(List.of("12345678"), "CUR")).thenReturn(List.of(studentID)); - Mockito.when(graduationStatusRepository.archiveStudents("CUR", "ARC", 1L)).thenReturn(1); - Integer count = graduationStatusService.archiveStudents(1L, new ArrayList<>(), "CUR"); + Mockito.when(graduationStatusRepository.archiveStudents("CUR", "ARC", 1L, "USER")).thenReturn(1); + Integer count = graduationStatusService.archiveStudents(1L, new ArrayList<>(), "CUR", "USER", updateDate); assertThat(count).isNotNull().isEqualTo(1); } diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java index aa42b4f5..443ec717 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java @@ -155,7 +155,7 @@ public void testCreateStudentHistory() { when(graduationStudentRecordRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity)); - historyService.createStudentHistory(graduationStatusEntity, "ACTIVITYCODE", 1, 1); + historyService.createStudentHistory(graduationStatusEntity, "ACTIVITYCODE"); assertThat(graduationStatusEntity).isNotNull(); } @@ -274,6 +274,7 @@ public void testUpdateStudentRecordHistoryDistributionRun() { // ID UUID studentID = UUID.randomUUID(); List histList = new ArrayList<>(); + LocalDateTime updateDate = LocalDateTime.now(); Student std = new Student(); std.setPen("123123"); @@ -311,24 +312,27 @@ public void testUpdateStudentRecordHistoryDistributionRun() { when(graduationStudentRecordHistoryRepository.findByBatchId(4000L, PageRequest.of(0, Integer.SIZE))).thenReturn(hPage); when(graduationStudentRecordHistoryRepository.findByStudentID(studentID)).thenReturn(List.of(graduationStudentRecordHistoryEntity)); - when(graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(4000L, "USER", LocalDateTime.now())).thenReturn(1); + when(graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(4000L, "USER", updateDate)).thenReturn(1); when(graduationStudentRecordRepository.findByStudentID(studentID)).thenReturn(graduationStudentRecordEntity); - var result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", "activityCode", List.of(studentID)); - assertThat(result).isNotNull().isZero(); + when(graduationStudentRecordRepository.updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(4000L, List.of(studentID))).thenReturn(1); + when(graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchId(4000L, "activityCode", "USER", updateDate)).thenReturn(1); + + var result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", updateDate, "activityCode", List.of(studentID)); + assertThat(result).isNotNull().isEqualTo(1); when(graduationStudentRecordHistoryRepository.findByBatchId(4000L, PageRequest.of(0, Integer.SIZE))).thenReturn(null); - result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", "activityCode", List.of(studentID)); + result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", updateDate, "activityCode", List.of(studentID)); assertThat(result).isNotNull().isEqualTo(1); when(graduationStudentRecordHistoryRepository.findByBatchId(4000L, PageRequest.of(0, Integer.SIZE))).thenReturn(new PageImpl(List.of())); - result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", "activityCode", List.of(studentID)); + result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", updateDate, "activityCode", List.of(studentID)); assertThat(result).isNotNull().isEqualTo(1); - result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", "activityCode", List.of()); + result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", updateDate, "activityCode", List.of()); assertThat(result).isNotNull().isZero(); - result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", "", List.of()); - assertThat(result).isNotNull().isZero(); + result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", updateDate, "", List.of()); + assertThat(result).isNotNull().isEqualTo(1); } } From dcb8da863d252071fad44cdcf43bc88a3d146cbc Mon Sep 17 00:00:00 2001 From: arybakov Date: Wed, 28 Aug 2024 10:19:53 -0600 Subject: [PATCH 3/8] Tests fix --- .../service/GraduationStatusServiceTest.java | 10 ++++++++-- .../api/gradstudent/service/HistoryServiceTest.java | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) 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 af2a14f0..ec312bbf 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 @@ -64,6 +64,7 @@ public class GraduationStatusServiceTest { @MockBean StudentCareerProgramRepository gradStudentCareerProgramRepository; @MockBean ReportGradStudentDataRepository reportGradStudentDataRepository; @MockBean StudentNonGradReasonRepository studentNonGradReasonRepository; + @MockBean GraduationStudentRecordHistoryRepository graduationStudentRecordHistoryRepository; @MockBean CommonService commonService; @MockBean GradValidation validation; @MockBean WebClient webClient; @@ -3070,6 +3071,9 @@ public void testArchiveStudents() { when(graduationStatusRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity)); Mockito.when(graduationStatusRepository.findBySchoolOfRecordInAndStudentStatus(List.of("12345678"), "CUR")).thenReturn(List.of(studentID)); Mockito.when(graduationStatusRepository.archiveStudents(List.of("12345678"), "CUR", "ARC", 1L, "USER")).thenReturn(1); + Mockito.when(graduationStatusRepository.updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(1L, List.of(studentID))).thenReturn(1); + Mockito.when(historyService.updateStudentRecordHistoryDistributionRun(1L, "USER", updateDate, "USERSTUDARC", List.of(studentID))).thenReturn(1); + Integer count = graduationStatusService.archiveStudents(1L, List.of("12345678"), "CUR", "USER", updateDate); assertThat(count).isNotNull().isEqualTo(1); } @@ -3085,9 +3089,11 @@ public void testArchiveStudentEmpty() { graduationStatusEntity.setSchoolOfRecord("12345678"); when(graduationStatusRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity)); - Mockito.when(graduationStatusRepository.findBySchoolOfRecordInAndStudentStatus(List.of("12345678"), "CUR")).thenReturn(List.of(studentID)); + Mockito.when(graduationStatusRepository.findByStudentStatus("CUR")).thenReturn(List.of(studentID)); Mockito.when(graduationStatusRepository.archiveStudents("CUR", "ARC", 1L, "USER")).thenReturn(1); - Integer count = graduationStatusService.archiveStudents(1L, new ArrayList<>(), "CUR", "USER", updateDate); + Mockito.when(historyService.updateStudentRecordHistoryDistributionRun(1L, "USER", updateDate, "USERSTUDARC", List.of(studentID))).thenReturn(1); + + Integer count = graduationStatusService.archiveStudents(1L, List.of(), "CUR", "USER", updateDate); assertThat(count).isNotNull().isEqualTo(1); } diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java index 443ec717..daae380c 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java @@ -316,6 +316,7 @@ public void testUpdateStudentRecordHistoryDistributionRun() { when(graduationStudentRecordRepository.findByStudentID(studentID)).thenReturn(graduationStudentRecordEntity); when(graduationStudentRecordRepository.updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(4000L, List.of(studentID))).thenReturn(1); + when(graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(4000L, List.of(studentID), "activityCode", "USER", updateDate)).thenReturn(1); when(graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchId(4000L, "activityCode", "USER", updateDate)).thenReturn(1); var result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", updateDate, "activityCode", List.of(studentID)); From 08bac8e2f9b12da65d4db3ec5260e5ce3c500e92 Mon Sep 17 00:00:00 2001 From: arybakov Date: Wed, 28 Aug 2024 10:53:44 -0600 Subject: [PATCH 4/8] Tests fix --- .../api/gradstudent/controller/GraduationStatusController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusController.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusController.java index 5386ddc5..c0249c2f 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusController.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.gradstudent.controller; +import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Publisher; import ca.bc.gov.educ.api.gradstudent.model.dto.*; import ca.bc.gov.educ.api.gradstudent.model.entity.GradStatusEvent; import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordHistoryEntity; From 9eab7afca5a9c40ecc88fac00678df259a63218e Mon Sep 17 00:00:00 2001 From: arybakov Date: Wed, 28 Aug 2024 11:04:23 -0600 Subject: [PATCH 5/8] Tests fix --- .../gradstudent/controller/GraduationStatusControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusControllerTest.java index 2f2e2a80..cebe6869 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusControllerTest.java @@ -640,7 +640,7 @@ public void testArchiveStudents() { LocalDateTime updateDate = LocalDateTime.now(); Mockito.when(graduationStatusService.archiveStudents(1L, List.of(mincode), "CUR", "Batch Archive Process", updateDate)).thenReturn(1); graduationStatusController.archiveStudents(1L, "CUR", "Batch Archive Process", List.of(mincode)); - Mockito.verify(graduationStatusService).archiveStudents(1L, List.of(mincode), "CUR", "Batch Archive Process", updateDate); + //Mockito.verify(graduationStatusService).archiveStudents(1L, List.of(mincode), "CUR", "Batch Archive Process", updateDate); } @Test From cec2286e7ac6b026dc7b2bf49921839399d2f7bd Mon Sep 17 00:00:00 2001 From: arybakov Date: Wed, 28 Aug 2024 11:19:11 -0600 Subject: [PATCH 6/8] Tests fix --- .../controller/GraduationStatusController.java | 10 ++++++++-- .../GraduationStatusControllerTest.java | 17 +++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusController.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusController.java index c0249c2f..99e251bb 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusController.java @@ -23,7 +23,9 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; +import java.sql.Date; import java.time.LocalDateTime; +import java.util.Calendar; import java.util.Comparator; import java.util.List; import java.util.UUID; @@ -362,7 +364,9 @@ public ResponseEntity saveStudentGradStatusDistribution @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) public ResponseEntity> updateStudentGradHistoryStatusDistributionRun(@PathVariable Long batchID, @RequestParam(required = false) String userName, @RequestParam(required = false) String activityCode, @RequestBody List studentGuids) { logger.debug("Save Distribution student Grad history for Student ID"); - LocalDateTime updateDate = LocalDateTime.now(); + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date(System.currentTimeMillis())); + LocalDateTime updateDate = LocalDateTime.of(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR), cal.get(Calendar.MINUTE)); return response.UPDATED(historyService.updateStudentRecordHistoryDistributionRun(batchID, userName, updateDate, activityCode, studentGuids)); } @@ -406,7 +410,9 @@ public ResponseEntity getStudentsCount(@RequestParam(required = false) Str @Operation(summary = "Get Students Count by mincode and status", description = "Get Students Count by mincode and status", tags = { "Business" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) public ResponseEntity archiveStudents(@RequestParam long batchId, @RequestParam(required = false) String studentStatus, @RequestParam(required = false) String userName, @RequestBody List schoolOfRecords) { - LocalDateTime updateDate = LocalDateTime.now(); + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date(System.currentTimeMillis())); + LocalDateTime updateDate = LocalDateTime.of(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR), cal.get(Calendar.MINUTE)); return response.GET(gradStatusService.archiveStudents(batchId, schoolOfRecords, studentStatus, userName, updateDate)); } diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusControllerTest.java index cebe6869..6aeb67d9 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusControllerTest.java @@ -27,10 +27,7 @@ import java.sql.Date; import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; +import java.util.*; import static org.assertj.core.api.Assertions.assertThat; @@ -561,10 +558,12 @@ public void testGetStudentsForYearlyRun() { @Test public void testUpdateStudentGradHistoryStatusDistributionRun() { - LocalDateTime updateDate = LocalDateTime.now(); + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date(System.currentTimeMillis())); + LocalDateTime updateDate = LocalDateTime.of(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR), cal.get(Calendar.MINUTE)); Mockito.when(historyService.updateStudentRecordHistoryDistributionRun(1L, "Batch Archive Process", updateDate, "activityCode", List.of())).thenReturn(1); graduationStatusController.updateStudentGradHistoryStatusDistributionRun(1L, "Batch Archive Process", "activityCode", List.of()); - //Mockito.verify(historyService).updateStudentRecordHistoryDistributionRun(1L, "Batch Archive Process", updateDate, "activityCode", List.of()); + Mockito.verify(historyService).updateStudentRecordHistoryDistributionRun(1L, "Batch Archive Process", updateDate, "activityCode", List.of()); } @Test @@ -637,10 +636,12 @@ public void testGetStudentsCount() { public void testArchiveStudents() { // ID String mincode = "123456789"; - LocalDateTime updateDate = LocalDateTime.now(); + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date(System.currentTimeMillis())); + LocalDateTime updateDate = LocalDateTime.of(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR), cal.get(Calendar.MINUTE)); Mockito.when(graduationStatusService.archiveStudents(1L, List.of(mincode), "CUR", "Batch Archive Process", updateDate)).thenReturn(1); graduationStatusController.archiveStudents(1L, "CUR", "Batch Archive Process", List.of(mincode)); - //Mockito.verify(graduationStatusService).archiveStudents(1L, List.of(mincode), "CUR", "Batch Archive Process", updateDate); + Mockito.verify(graduationStatusService).archiveStudents(1L, List.of(mincode), "CUR", "Batch Archive Process", updateDate); } @Test From 08618197db287dcb046ea050d2ad493723a83a5e Mon Sep 17 00:00:00 2001 From: arybakov Date: Wed, 28 Aug 2024 11:40:08 -0600 Subject: [PATCH 7/8] Tests fix --- ...duationStudentRecordHistoryRepository.java | 206 +++++++++--------- 1 file changed, 106 insertions(+), 100 deletions(-) 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 b283d163..ba74bd9b 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 @@ -29,110 +29,116 @@ public interface GraduationStudentRecordHistoryRepository extends JpaRepository< @Query(value="update GRADUATION_STUDENT_RECORD_HISTORY set HISTORY_ACTIVITY_CODE = :activityCode, UPDATE_USER = :updateUser, UPDATE_DATE = :updateDate where BATCH_ID = :batchId", nativeQuery=true) Integer updateGradStudentUpdateUser(@Param(value = "batchId") Long batchId, @Param(value = "activityCode") String activityCode, @Param(value = "updateUser") String updateUser, @Param(value = "updateDate") LocalDateTime updateDate); + String insertGraduationStudentRecordHistoryByBatchIdSql = """ + 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, + :updateUser, + :updateDate, + 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 BATCH_ID = :batchId + """; @Modifying - @Query(value="INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY (\n" + - " GRADUATION_STUDENT_RECORD_HISTORY_ID,\n" + - " HISTORY_ACTIVITY_CODE,\n" + - " GRADUATION_STUDENT_RECORD_ID,\n" + - " GRADUATION_PROGRAM_CODE,\n" + - " GPA,\n" + - " STUDENT_STATUS_CODE,\n" + - " HONOURS_STANDING,\n" + - " PROGRAM_COMPLETION_DATE,\n" + - " RECALCULATE_GRAD_STATUS,\n" + - " SCHOOL_OF_RECORD,\n" + - " STUDENT_GRADE,\n" + - " SCHOOL_AT_GRADUATION,\n" + - " CREATE_USER,\n" + - " CREATE_DATE,\n" + - " UPDATE_USER,\n" + - " UPDATE_DATE,\n" + - " RECALCULATE_PROJECTED_GRAD,\n" + - " BATCH_ID,\n" + - " CONSUMER_EDUC_REQT_MET,\n" + - " STUDENT_CITIZENSHIP_CODE,\n" + - " ADULT_START_DATE,\n" + - " SCHOOL_OF_RECORD_ID,\n" + - " SCHOOL_AT_GRADUATION_ID\n" + - ") SELECT \n" + - " SYS_GUID(),\n" + - " :activityCode,\n" + - " GRADUATION_STUDENT_RECORD_ID,\n" + - " GRADUATION_PROGRAM_CODE,\n" + - " GPA,\n" + - " STUDENT_STATUS_CODE,\n" + - " HONOURS_STANDING,\n" + - " PROGRAM_COMPLETION_DATE,\n" + - " RECALCULATE_GRAD_STATUS,\n" + - " SCHOOL_OF_RECORD,\n" + - " STUDENT_GRADE,\n" + - " SCHOOL_AT_GRADUATION,\n" + - " CREATE_USER,\n" + - " CREATE_DATE,\n" + - " :updateUser,\n" + - " :updateDate,\n" + - " RECALCULATE_PROJECTED_GRAD,\n" + - " BATCH_ID,\n" + - " CONSUMER_EDUC_REQT_MET,\n" + - " STUDENT_CITIZENSHIP_CODE,\n" + - " ADULT_START_DATE,\n" + - " SCHOOL_OF_RECORD_ID,\n" + - " SCHOOL_AT_GRADUATION_ID\n" + - "FROM GRADUATION_STUDENT_RECORD\n" + - "WHERE BATCH_ID = :batchId", nativeQuery=true) + @Query(value=insertGraduationStudentRecordHistoryByBatchIdSql, nativeQuery=true) Integer insertGraduationStudentRecordHistoryByBatchId(@Param(value = "batchId") Long batchId, @Param(value = "activityCode") String activityCode, @Param(value = "updateUser") String updateUser, @Param(value = "updateDate") LocalDateTime updateDate); + String insertGraduationStudentRecordHistoryByBatchIdAndStudentIDsSql = """ + 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, + :updateUser, + :updateDate, + 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 BATCH_ID = :batchId and GRADUATION_STUDENT_RECORD_ID IN (:studentIDs) + """; @Modifying - @Query(value="INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY (\n" + - " GRADUATION_STUDENT_RECORD_HISTORY_ID,\n" + - " HISTORY_ACTIVITY_CODE,\n" + - " GRADUATION_STUDENT_RECORD_ID,\n" + - " GRADUATION_PROGRAM_CODE,\n" + - " GPA,\n" + - " STUDENT_STATUS_CODE,\n" + - " HONOURS_STANDING,\n" + - " PROGRAM_COMPLETION_DATE,\n" + - " RECALCULATE_GRAD_STATUS,\n" + - " SCHOOL_OF_RECORD,\n" + - " STUDENT_GRADE,\n" + - " SCHOOL_AT_GRADUATION,\n" + - " CREATE_USER,\n" + - " CREATE_DATE,\n" + - " UPDATE_USER,\n" + - " UPDATE_DATE,\n" + - " RECALCULATE_PROJECTED_GRAD,\n" + - " BATCH_ID,\n" + - " CONSUMER_EDUC_REQT_MET,\n" + - " STUDENT_CITIZENSHIP_CODE,\n" + - " ADULT_START_DATE,\n" + - " SCHOOL_OF_RECORD_ID,\n" + - " SCHOOL_AT_GRADUATION_ID\n" + - ") SELECT \n" + - " SYS_GUID(),\n" + - " :activityCode,\n" + - " GRADUATION_STUDENT_RECORD_ID,\n" + - " GRADUATION_PROGRAM_CODE,\n" + - " GPA,\n" + - " STUDENT_STATUS_CODE,\n" + - " HONOURS_STANDING,\n" + - " PROGRAM_COMPLETION_DATE,\n" + - " RECALCULATE_GRAD_STATUS,\n" + - " SCHOOL_OF_RECORD,\n" + - " STUDENT_GRADE,\n" + - " SCHOOL_AT_GRADUATION,\n" + - " CREATE_USER,\n" + - " CREATE_DATE,\n" + - " :updateUser,\n" + - " :updateDate,\n" + - " RECALCULATE_PROJECTED_GRAD,\n" + - " BATCH_ID,\n" + - " CONSUMER_EDUC_REQT_MET,\n" + - " STUDENT_CITIZENSHIP_CODE,\n" + - " ADULT_START_DATE,\n" + - " SCHOOL_OF_RECORD_ID,\n" + - " SCHOOL_AT_GRADUATION_ID\n" + - "FROM GRADUATION_STUDENT_RECORD\n" + - "WHERE BATCH_ID = :batchId and GRADUATION_STUDENT_RECORD_ID IN (:studentIDs)", nativeQuery=true) + @Query(value=insertGraduationStudentRecordHistoryByBatchIdAndStudentIDsSql, nativeQuery=true) Integer insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(@Param(value = "batchId") Long batchId, @Param(value = "studentIDs") List studentIDs, @Param(value = "activityCode") String activityCode, @Param(value = "updateUser") String updateUser, @Param(value = "updateDate") LocalDateTime updateDate); } From ed392dfb439b3f5641024dd1f5b7e378606968ca Mon Sep 17 00:00:00 2001 From: arybakov Date: Wed, 28 Aug 2024 15:59:13 -0600 Subject: [PATCH 8/8] Tests fix --- .../GraduationStudentRecordHistoryRepository.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 ba74bd9b..b02b5863 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 @@ -29,7 +29,7 @@ public interface GraduationStudentRecordHistoryRepository extends JpaRepository< @Query(value="update GRADUATION_STUDENT_RECORD_HISTORY set HISTORY_ACTIVITY_CODE = :activityCode, UPDATE_USER = :updateUser, UPDATE_DATE = :updateDate where BATCH_ID = :batchId", nativeQuery=true) Integer updateGradStudentUpdateUser(@Param(value = "batchId") Long batchId, @Param(value = "activityCode") String activityCode, @Param(value = "updateUser") String updateUser, @Param(value = "updateDate") LocalDateTime updateDate); - String insertGraduationStudentRecordHistoryByBatchIdSql = """ + String INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_BATCH_ID_SQL = """ INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY ( GRADUATION_STUDENT_RECORD_HISTORY_ID, HISTORY_ACTIVITY_CODE, @@ -82,10 +82,10 @@ INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY ( WHERE BATCH_ID = :batchId """; @Modifying - @Query(value=insertGraduationStudentRecordHistoryByBatchIdSql, nativeQuery=true) + @Query(value= INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_BATCH_ID_SQL, nativeQuery=true) Integer insertGraduationStudentRecordHistoryByBatchId(@Param(value = "batchId") Long batchId, @Param(value = "activityCode") String activityCode, @Param(value = "updateUser") String updateUser, @Param(value = "updateDate") LocalDateTime updateDate); - String insertGraduationStudentRecordHistoryByBatchIdAndStudentIDsSql = """ + String INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_BATCH_ID_AND_STUDENT_ID_IN_SQL = """ INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY ( GRADUATION_STUDENT_RECORD_HISTORY_ID, HISTORY_ACTIVITY_CODE, @@ -138,7 +138,7 @@ INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY ( WHERE BATCH_ID = :batchId and GRADUATION_STUDENT_RECORD_ID IN (:studentIDs) """; @Modifying - @Query(value=insertGraduationStudentRecordHistoryByBatchIdAndStudentIDsSql, nativeQuery=true) + @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, @Param(value = "updateDate") LocalDateTime updateDate); }