From 06aa0dc2284533281e573dd4c57d4f7b4ea7eea9 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 27 Aug 2024 16:11:47 -0600 Subject: [PATCH 1/2] GRAD2-2817 TVR Delete Process - Backend Changes Endpoints --- .../grad/report/controller/CommonController.java | 4 ++-- .../repository/GradStudentReportsRepository.java | 15 ++++++++++++--- .../api/grad/report/service/CommonService.java | 11 +++++++---- .../report/controller/CommonControllerTest.java | 6 +++--- .../grad/report/service/CommonServiceTest.java | 13 +++++++------ 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/controller/CommonController.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/controller/CommonController.java index 3c91ca41..6e2e4ac2 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/controller/CommonController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/controller/CommonController.java @@ -412,8 +412,8 @@ public ResponseEntity getReportsCount(@RequestParam String reportType, @PreAuthorize(PermissionsConstants.READ_GRADUATION_STUDENT_REPORTS) @Operation(summary = "Get Report Students Guids by mincode and type", description = "Get Report Students Guids by mincode and type", tags = { "Business" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) - public ResponseEntity> getStudentIDsByIdentityAndReportType(@RequestParam String reportType, @RequestBody List reportContainerIds) { - return response.GET(commonService.getStudentIDsByStudentGuidsAndReportType(reportContainerIds, reportType)); + public ResponseEntity> getStudentIDsByIdentityAndReportType(@RequestParam String reportType, @RequestParam Integer rowCount, @RequestBody List reportContainerIds) { + return response.GET(commonService.getStudentIDsByStudentGuidsAndReportType(reportContainerIds, reportType, rowCount)); } @PostMapping (EducGradReportApiConstants.REPORT_ARCHIVE) diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/GradStudentReportsRepository.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/GradStudentReportsRepository.java index 3966fbe2..08ebad8f 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/GradStudentReportsRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/GradStudentReportsRepository.java @@ -2,7 +2,10 @@ import ca.bc.gov.educ.api.grad.report.model.dto.SchoolStudentCredentialDistribution; import ca.bc.gov.educ.api.grad.report.model.entity.GradStudentReportsEntity; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @@ -17,11 +20,17 @@ public interface GradStudentReportsRepository extends JpaRepository existsByReportTypeCode(String reportType); - + + @Modifying + @Query(value="DELETE from STUDENT_REPORT where GRADUATION_STUDENT_RECORD_ID in (:studentIDs) and REPORT_TYPE_CODE = :gradReportTypeCode", nativeQuery = true) Integer deleteByStudentIDInAndGradReportTypeCode(List studentIDs, String gradReportTypeCode); + @Modifying + @Query(value="DELETE from STUDENT_REPORT where REPORT_TYPE_CODE = :gradReportTypeCode", nativeQuery = true) Integer deleteByGradReportTypeCode(String gradReportTypeCode); + @Modifying + @Query(value="DELETE from STUDENT_REPORT where GRADUATION_STUDENT_RECORD_ID = :studentID and REPORT_TYPE_CODE = :gradReportTypeCode", nativeQuery = true) Integer deleteByStudentIDAndGradReportTypeCode(UUID studentID, String gradReportTypeCode); List findByStudentID(UUID studentID); @@ -39,11 +48,11 @@ public interface GradStudentReportsRepository extends JpaRepository studentGuids, String reportType); @Query("select c.studentID from GradStudentReportsEntity c where c.studentID IN (:studentGuids) and c.gradReportTypeCode=:reportType") - List getReportStudentIDsByStudentIDsAndReportType(List studentGuids, String reportType); + Page getReportStudentIDsByStudentIDsAndReportType(List studentGuids, String reportType, Pageable page); @Query("select count(*) from GradStudentReportsEntity c where c.gradReportTypeCode=:reportType") Integer countByReportType(String reportType); @Query("select c.studentID from GradStudentReportsEntity c where c.gradReportTypeCode=:reportType") - List getReportStudentIDsByReportType(String reportType); + Page findStudentIDByGradReportTypeCode(String reportType, Pageable page); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/CommonService.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/CommonService.java index 0e93008f..07230d69 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/CommonService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/CommonService.java @@ -20,6 +20,7 @@ import org.springframework.core.io.InputStreamResource; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -870,16 +871,18 @@ public Integer countByStudentGuidsAndReportType(List studentGuidsString, return reportsCount; } - public List getStudentIDsByStudentGuidsAndReportType(List studentGuidsString, String reportType) { - List result; + public List getStudentIDsByStudentGuidsAndReportType(List studentGuidsString, String reportType, Integer rowCount) { + List result = new ArrayList<>(); + rowCount = (rowCount) == 0 ? Integer.MAX_VALUE : rowCount; + Pageable paging = PageRequest.of(0, rowCount); if(studentGuidsString != null && !studentGuidsString.isEmpty()) { List studentGuids = new ArrayList<>(); for(String guid: studentGuidsString) { studentGuids.add(UUID.fromString(guid)); } - result = gradStudentReportsRepository.getReportStudentIDsByStudentIDsAndReportType(studentGuids, reportType); + result.addAll(gradStudentReportsRepository.getReportStudentIDsByStudentIDsAndReportType(studentGuids, reportType, paging).getContent()); } else { - result = gradStudentReportsRepository.getReportStudentIDsByReportType(reportType); + result.addAll(gradStudentReportsRepository.findStudentIDByGradReportTypeCode(reportType, paging).getContent()); } return result; } diff --git a/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/CommonControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/CommonControllerTest.java index 93e527d1..5c241d8f 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/CommonControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/CommonControllerTest.java @@ -554,9 +554,9 @@ public void testGetStudentIDsByIdentityAndReportType() { final UUID studentID = UUID.randomUUID(); final String reportType = "ACHV"; - Mockito.when(commonService.getStudentIDsByStudentGuidsAndReportType(List.of(studentID.toString()), reportType)).thenReturn(List.of(studentID)); - commonController.getStudentIDsByIdentityAndReportType(reportType, List.of(studentID.toString())); - Mockito.verify(commonService).getStudentIDsByStudentGuidsAndReportType(List.of(studentID.toString()), reportType); + Mockito.when(commonService.getStudentIDsByStudentGuidsAndReportType(List.of(studentID.toString()), reportType, 1)).thenReturn(List.of(studentID)); + commonController.getStudentIDsByIdentityAndReportType(reportType, 1, List.of(studentID.toString())); + Mockito.verify(commonService).getStudentIDsByStudentGuidsAndReportType(List.of(studentID.toString()), reportType, 1); } @Test diff --git a/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java index 0fdc3499..d8b79adb 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java @@ -1705,13 +1705,14 @@ public void testCountByStudentGuidsAndReportType() { public void testGetStudentIDsByStudentGuidsAndReportType() { UUID uuid = UUID.randomUUID(); - Mockito.when(gradStudentReportsRepository.getReportStudentIDsByStudentIDsAndReportType(List.of(uuid), "reportType")).thenReturn(List.of(uuid)); - List result = commonService.getStudentIDsByStudentGuidsAndReportType(List.of(uuid.toString()), "reportType"); - assertThat(result).isNotNull().isNotEmpty(); + Pageable paging = PageRequest.of(0, 1); + Mockito.when(gradStudentReportsRepository.getReportStudentIDsByStudentIDsAndReportType(List.of(uuid), "reportType", paging)).thenReturn(Page.empty()); + List result = commonService.getStudentIDsByStudentGuidsAndReportType(List.of(uuid.toString()), "reportType", 100); + assertThat(result).isNotNull().isEmpty(); - Mockito.when(gradStudentReportsRepository.getReportStudentIDsByReportType("reportType")).thenReturn(List.of(uuid)); - result = commonService.getStudentIDsByStudentGuidsAndReportType(List.of(), "reportType"); - assertThat(result).isNotNull().isNotEmpty(); + Mockito.when(gradStudentReportsRepository.findStudentIDByGradReportTypeCode("reportType", paging)).thenReturn(Page.empty()); + result = commonService.getStudentIDsByStudentGuidsAndReportType(List.of(), "reportType", 100); + assertThat(result).isNotNull().isEmpty(); } From d96374f5a0cc74d1198bb14f2aa5ba901c6b7b91 Mon Sep 17 00:00:00 2001 From: arybakov Date: Wed, 28 Aug 2024 10:31:38 -0600 Subject: [PATCH 2/2] GRAD2-2817 TVR Delete Process - Backend Changes Endpoints --- .../report/service/CommonServiceTest.java | 88 ++++++++++++++++++- 1 file changed, 84 insertions(+), 4 deletions(-) diff --git a/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java index d8b79adb..1d0e6cb6 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java @@ -1706,12 +1706,92 @@ public void testGetStudentIDsByStudentGuidsAndReportType() { UUID uuid = UUID.randomUUID(); Pageable paging = PageRequest.of(0, 1); - Mockito.when(gradStudentReportsRepository.getReportStudentIDsByStudentIDsAndReportType(List.of(uuid), "reportType", paging)).thenReturn(Page.empty()); - List result = commonService.getStudentIDsByStudentGuidsAndReportType(List.of(uuid.toString()), "reportType", 100); - assertThat(result).isNotNull().isEmpty(); + Mockito.when(gradStudentReportsRepository.getReportStudentIDsByStudentIDsAndReportType(List.of(uuid), "reportType", paging)).thenReturn(new Page() { + @Override + public Iterator iterator() { + return getContent().listIterator(); + } + + @Override + public int getNumber() { + return 1; + } + + @Override + public int getSize() { + return 1; + } + + @Override + public int getNumberOfElements() { + return 1; + } + + @Override + public List getContent() { + return List.of(uuid); + } + + @Override + public boolean hasContent() { + return !getContent().isEmpty(); + } + + @Override + public Sort getSort() { + return null; + } + + @Override + public boolean isFirst() { + return false; + } + + @Override + public boolean isLast() { + return false; + } + + @Override + public boolean hasNext() { + return false; + } + + @Override + public boolean hasPrevious() { + return false; + } + + @Override + public Pageable nextPageable() { + return null; + } + + @Override + public Pageable previousPageable() { + return null; + } + + @Override + public int getTotalPages() { + return getContent().size(); + } + + @Override + public long getTotalElements() { + return getContent().size(); + } + + @Override + public Page map(Function converter) { + return null; + } + }); + List result = commonService.getStudentIDsByStudentGuidsAndReportType(List.of(uuid.toString()), "reportType", 1); + assertThat(result).isNotNull().isNotEmpty(); Mockito.when(gradStudentReportsRepository.findStudentIDByGradReportTypeCode("reportType", paging)).thenReturn(Page.empty()); - result = commonService.getStudentIDsByStudentGuidsAndReportType(List.of(), "reportType", 100); + result = commonService.getStudentIDsByStudentGuidsAndReportType(List.of(), "reportType", 1); assertThat(result).isNotNull().isEmpty(); }