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..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,6 +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; @@ -361,7 +364,10 @@ 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)); + 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)); } @GetMapping (EducGradStudentApiConstants.STUDENT_LIST_FOR_SCHOOL_REPORT) @@ -403,8 +409,11 @@ 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) { + 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)); } @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..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,4 +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 INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_BATCH_ID_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, + :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_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 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, + 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_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); + } 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 ca504475..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 @@ -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 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..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 @@ -1395,22 +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); - for(UUID graduationStudentRecordGuid: graduationStudentRecordGuids) { - saveStudentHistoryRecordArchiveStudentsRun(graduationStudentRecordGuid, batchId, "USERSTUDARC"); - } - 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); - for(UUID graduationStudentRecordGuid: graduationStudentRecordGuids) { - saveStudentHistoryRecordArchiveStudentsRun(graduationStudentRecordGuid, batchId, "USERSTUDARC"); - } - 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 ebaad7ab..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; @@ -163,31 +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()) { - 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); - 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..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 @@ -26,10 +26,8 @@ import java.sql.Date; import java.time.LocalDate; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; +import java.time.LocalDateTime; +import java.util.*; import static org.assertj.core.api.Assertions.assertThat; @@ -560,9 +558,12 @@ 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()); + 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()); } @Test @@ -635,9 +636,12 @@ 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"); + 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); } @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 726828c0..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; @@ -3059,6 +3060,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 +3070,17 @@ 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); + 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); } @Test public void testArchiveStudentEmpty() { + LocalDateTime updateDate = LocalDateTime.now(); UUID studentID = new UUID(1, 1); GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity(); graduationStatusEntity.setStudentID(studentID); @@ -3083,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.archiveStudents("CUR", "ARC", 1L)).thenReturn(1); - Integer count = graduationStatusService.archiveStudents(1L, new ArrayList<>(), "CUR"); + Mockito.when(graduationStatusRepository.findByStudentStatus("CUR")).thenReturn(List.of(studentID)); + Mockito.when(graduationStatusRepository.archiveStudents("CUR", "ARC", 1L, "USER")).thenReturn(1); + 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 d2e0dd0c..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 @@ -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,28 @@ 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.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)); + 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); } }