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 db2955d8..ca0c016d 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,9 +23,6 @@ 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; @@ -63,7 +60,7 @@ public ResponseEntity getStudentGradStatus(@PathVariabl GraduationStudentRecord gradResponse = gradStatusService.getGraduationStatus(UUID.fromString(studentID),accessToken.replace(BEARER, "")); if(gradResponse != null) { return response.GET(gradResponse); - }else { + } else { return response.NO_CONTENT(); } } @@ -407,10 +404,7 @@ 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) { - 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)); + return response.GET(gradStatusService.archiveStudents(batchId, schoolOfRecords, studentStatus, userName)); } @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/GraduationStudentRecordRepository.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordRepository.java index d0d7c188..09b101c1 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 @@ -56,6 +56,9 @@ public interface GraduationStudentRecordRepository extends JpaRepository findByStudentStatus(String studentStatus); + @Query("select c.studentID from GraduationStudentRecordEntity c where c.studentStatus=:studentStatus") + Page findByStudentStatus(String studentStatus, Pageable paging); + @Query("select distinct c.studentID from GraduationStudentRecordEntity c") List findAllStudentGuids(); @@ -127,6 +130,10 @@ void updateStudentGuidPenXrefRecord( @Query( "update GraduationStudentRecordEntity e set e.batchId = :batchId where e.studentID in :studentIDs") Integer updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(Long batchId, List studentIDs); + @Modifying + @Query( "update GraduationStudentRecordEntity e set e.batchId = :batchId where e.studentStatus = :studentStatus") + Integer updateGraduationStudentRecordEntitiesBatchIdWhereStudentStatus(Long batchId, String studentStatus); + /** * 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/GraduationStatusService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java index 2ceadd89..0e8fcc5a 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 @@ -50,6 +50,8 @@ public class GraduationStatusService { public static final int PAGE_SIZE = 500; + public static final long MAX_ROWS_COUNT = 50000; + private static final Logger logger = LoggerFactory.getLogger(GraduationStatusService.class); private static final String CREATE_USER = "createUser"; @@ -1395,19 +1397,23 @@ public Long countBySchoolOfRecordsAndStudentStatus(List schoolOfRecords, } @Transactional - public Integer archiveStudents(long batchId, List schoolOfRecords, String studentStatus, String user, LocalDateTime updateDate) { + public Integer archiveStudents(long batchId, List schoolOfRecords, String studentStatus, String user) { String recordStudentStatus = StringUtils.defaultString(studentStatus, "CUR"); - Integer archivedStudentsCount; + Integer archivedStudentsCount = 0; + Integer historyStudentsCount = 0; List graduationStudentRecordGuids = new ArrayList<>(); if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) { graduationStudentRecordGuids.addAll(graduationStatusRepository.findBySchoolOfRecordInAndStudentStatus(schoolOfRecords, recordStudentStatus)); archivedStudentsCount = graduationStatusRepository.archiveStudents(schoolOfRecords, recordStudentStatus, "ARC", batchId, user); } else { - graduationStudentRecordGuids.addAll(graduationStatusRepository.findByStudentStatus(recordStudentStatus)); - archivedStudentsCount = graduationStatusRepository.archiveStudents(recordStudentStatus, "ARC", batchId, user); + Integer numberOfUpdated = graduationStatusRepository.updateGraduationStudentRecordEntitiesBatchIdWhereStudentStatus(batchId, recordStudentStatus); + if(numberOfUpdated > 0) { + archivedStudentsCount = graduationStatusRepository.archiveStudents(recordStudentStatus, "ARC", batchId, user); + } + } + if(archivedStudentsCount > 0) { + historyStudentsCount = historyService.updateStudentRecordHistoryDistributionRun(batchId, user, "USERSTUDARC", graduationStudentRecordGuids); } - Integer historyRecordsUpdated = historyService.updateStudentRecordHistoryDistributionRun(batchId, user, "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 4b190d9a..251fc456 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 @@ -169,6 +169,8 @@ public Integer updateStudentRecordHistoryDistributionRun(Long batchId, String up Integer studentRecordsCreated = graduationStatusRepository.updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(batchId, studentGuids); historyRecordsCreated = graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(batchId, studentGuids, activityCode, updateUser); assert Objects.equals(studentRecordsCreated, historyRecordsCreated); + } else if(StringUtils.equalsIgnoreCase(activityCode, "USERSTUDARC")) { + historyRecordsCreated = graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchId(batchId, activityCode, updateUser); } else if(StringUtils.isBlank(activityCode) || StringUtils.equalsIgnoreCase(activityCode, "null")) { historyRecordsCreated = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, updateUser); } else { 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 0a956274..27c6710e 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,8 +26,10 @@ import java.sql.Date; import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; @@ -633,12 +635,9 @@ public void testGetStudentsCount() { public void testArchiveStudents() { // ID String mincode = "123456789"; - 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); + Mockito.when(graduationStatusService.archiveStudents(1L, List.of(mincode), "CUR", "Batch Archive Process")).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"); } @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 8c1e447a..b2268093 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 @@ -3060,7 +3060,6 @@ public void testCountBySchoolOfRecordsAndStudentStatus() { @Test public void testArchiveStudents() { - LocalDateTime updateDate = LocalDateTime.now(); UUID studentID = new UUID(1, 1); GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity(); graduationStatusEntity.setStudentID(studentID); @@ -3074,7 +3073,7 @@ public void testArchiveStudents() { Mockito.when(graduationStatusRepository.updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(1L, List.of(studentID))).thenReturn(1); Mockito.when(historyService.updateStudentRecordHistoryDistributionRun(1L, "USER", "USERSTUDARC", List.of(studentID))).thenReturn(1); - Integer count = graduationStatusService.archiveStudents(1L, List.of("12345678"), "CUR", "USER", updateDate); + Integer count = graduationStatusService.archiveStudents(1L, List.of("12345678"), "CUR", "USER"); assertThat(count).isNotNull().isEqualTo(1); } @@ -3093,8 +3092,8 @@ public void testArchiveStudentEmpty() { Mockito.when(graduationStatusRepository.archiveStudents("CUR", "ARC", 1L, "USER")).thenReturn(1); Mockito.when(historyService.updateStudentRecordHistoryDistributionRun(1L, "USER", "USERSTUDARC", List.of(studentID))).thenReturn(1); - Integer count = graduationStatusService.archiveStudents(1L, List.of(), "CUR", "USER", updateDate); - assertThat(count).isNotNull().isEqualTo(1); + Integer count = graduationStatusService.archiveStudents(1L, List.of(), "CUR", "USER"); + assertThat(count).isNotNull().isEqualTo(0); } @Test 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 0202a292..107bdd6e 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 @@ -318,6 +318,7 @@ public void testUpdateStudentRecordHistoryDistributionRun() { when(graduationStudentRecordRepository.updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(4000L, List.of(studentID))).thenReturn(1); when(graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(4000L, List.of(studentID), "activityCode", "USER")).thenReturn(1); when(graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchId(4000L, "activityCode", "USER")).thenReturn(1); + when(graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchId(4000L, "USERSTUDARC", "USER")).thenReturn(1); var result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", "activityCode", List.of(studentID)); assertThat(result).isNotNull().isEqualTo(1); @@ -335,5 +336,8 @@ public void testUpdateStudentRecordHistoryDistributionRun() { result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", "", List.of()); assertThat(result).isNotNull().isEqualTo(1); + + result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", "USERSTUDARC", List.of()); + assertThat(result).isNotNull().isEqualTo(1); } }