From 11f80bee63913b4cb7277561e1e0fe4ec60a5a17 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 3 Sep 2024 19:49:31 -0600 Subject: [PATCH 1/6] Performance --- .../GraduationStudentRecordRepository.java | 7 +++++++ .../service/GraduationStatusService.java | 19 +++++++++++++------ .../gradstudent/service/HistoryService.java | 2 ++ .../GraduationStatusControllerTest.java | 13 ++++++------- .../service/GraduationStatusServiceTest.java | 7 +++---- 5 files changed, 31 insertions(+), 17 deletions(-) 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..3ea0692b 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,24 @@ 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); + assert Objects.equals(historyStudentsCount, archivedStudentsCount); 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 From 35f7a821ffd5d692d52cfc37000b091ce15b49dc Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 3 Sep 2024 19:59:47 -0600 Subject: [PATCH 2/6] Performance --- .../api/gradstudent/controller/GraduationStatusController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..ea1d9a8b 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 @@ -63,7 +63,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(); } } From ae689c7ee0ed159b89f3e0aa4aae3126415d0fd8 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 3 Sep 2024 20:04:27 -0600 Subject: [PATCH 3/6] Performance --- .../controller/GraduationStatusController.java | 8 +------- 1 file changed, 1 insertion(+), 7 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 ea1d9a8b..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; @@ -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) From 9f37d5127148fa09d722b8fdf11465184cc8d809 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 3 Sep 2024 20:09:08 -0600 Subject: [PATCH 4/6] Performance --- .../gov/educ/api/gradstudent/service/HistoryServiceTest.java | 3 +++ 1 file changed, 3 insertions(+) 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..bfaf195b 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 @@ -335,5 +335,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); } } From c8b27f901f6ef62b9243625f567538e7bf6cf869 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 3 Sep 2024 20:12:32 -0600 Subject: [PATCH 5/6] Performance --- .../bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java | 1 + 1 file changed, 1 insertion(+) 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 bfaf195b..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); From e653bdc477032adfc773e479980ce886c64fa039 Mon Sep 17 00:00:00 2001 From: Alexander Rybakov <83988488+arybakov-cgi@users.noreply.github.com> Date: Wed, 4 Sep 2024 08:29:46 -0600 Subject: [PATCH 6/6] Remove assert --- .../educ/api/gradstudent/service/GraduationStatusService.java | 1 - 1 file changed, 1 deletion(-) 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 3ea0692b..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 @@ -1414,7 +1414,6 @@ public Integer archiveStudents(long batchId, List schoolOfRecords, Strin if(archivedStudentsCount > 0) { historyStudentsCount = historyService.updateStudentRecordHistoryDistributionRun(batchId, user, "USERSTUDARC", graduationStudentRecordGuids); } - assert Objects.equals(historyStudentsCount, archivedStudentsCount); return archivedStudentsCount; }