From 1d02aa0972fa298f035a957b10ca6f0845c7b59e Mon Sep 17 00:00:00 2001 From: arybakov Date: Thu, 27 Jun 2024 16:30:53 -0600 Subject: [PATCH 1/5] GRAD2-2817 TVR Delete Process - Backend Changes Endpoints --- .../report/controller/CommonController.java | 25 ++++++++++++++- .../GradStudentReportsRepository.java | 4 ++- .../grad/report/service/CommonService.java | 32 ++++++++++++++++++- .../util/EducGradReportApiConstants.java | 2 ++ .../controller/CommonControllerTest.java | 4 +-- .../report/service/CommonServiceTest.java | 6 ++-- 6 files changed, 65 insertions(+), 8 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 dd2f48c8..cd77ea12 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 @@ -65,7 +65,7 @@ public ResponseEntity getStudentReport(@PathVariable String reportTypeC public ResponseEntity> saveStudentReport(@RequestBody GradStudentReports gradStudentReports,@RequestParam(value = "isGraduated", required = false, defaultValue = "false") boolean isGraduated) { logger.debug("Save student Grad Report for Student ID: {}",gradStudentReports.getStudentID()); validation.requiredField(gradStudentReports.getStudentID(), "Student ID"); - return response.UPDATED(commonService.saveGradReports(gradStudentReports,isGraduated)); + return response.UPDATED(commonService.saveGradStudentReports(gradStudentReports,isGraduated)); } @GetMapping(EducGradReportApiConstants.STUDENT_REPORT) @@ -80,6 +80,29 @@ public ResponseEntity getStudentReportByType( return commonService.getStudentReportByType(UUID.fromString(studentID),reportType,documentStatusCode); } + @DeleteMapping(EducGradReportApiConstants.STUDENT_REPORT_BY_STUDENTID) + @PreAuthorize(PermissionsConstants.READ_GRADUATION_STUDENT_REPORTS) + @Operation(summary = "Read Student Reports by Student ID and Report Type", description = "Read Student Reports by Student ID and Report Type", tags = { "Reports" }) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) + public ResponseEntity deleteStudentReportByType( + @RequestParam(value = "reportType") String reportType, + @PathVariable UUID uuid) { + logger.debug("getStudentReportByType : "); + return response.GET(commonService.deleteStudentReports(uuid, reportType)); + } + + @PostMapping(EducGradReportApiConstants.STUDENT_REPORTS) + @PreAuthorize(PermissionsConstants.READ_GRADUATION_STUDENT_REPORTS) + @Operation(summary = "Read Student Reports by Student ID and Report Type", description = "Read Student Reports by Student ID and Report Type", tags = { "Reports" }) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) + public ResponseEntity processStudentReports( + @RequestParam(value = "reportTypeCode") String reportTypeCode, + @RequestParam(value = "actionType") String actionType, + @RequestBody List studentIDs) { + logger.debug("processStudentReports : "); + return response.GET(commonService.processStudentReports(studentIDs, reportTypeCode, actionType)); + } + @GetMapping(EducGradReportApiConstants.STUDENT_CERTIFICATES) @PreAuthorize(PermissionsConstants.READ_GRADUATION_STUDENT_CERTIFICATES) @Operation(summary = "Read Student Certificates by Student ID", description = "Read Student Certificates by Student ID", tags = { "Reports" }) 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 7a5e1402..034c2bea 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 @@ -18,7 +18,9 @@ public interface GradStudentReportsRepository extends JpaRepository existsByReportTypeCode(String reportType); - long deleteByStudentID(UUID studentID); + long deleteByStudentIDInAndGradReportTypeCode(List studentIDs, String gradReportTypeCode); + + long deleteByStudentIDAndGradReportTypeCode(UUID studentID, String gradReportTypeCode); List findByStudentID(UUID studentID); 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 1064aaca..574694cb 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 @@ -10,6 +10,7 @@ import ca.bc.gov.educ.api.grad.report.util.ThreadLocalStateUtil; import jakarta.transaction.Transactional; import org.apache.commons.codec.binary.Base64; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.SerializationUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; @@ -88,7 +89,7 @@ public class CommonService extends BaseService { private static final List SCCP_CERT_TYPES = Arrays.asList("SC", "SCF", "SCI"); @Transactional - public GradStudentReports saveGradReports(GradStudentReports gradStudentReports, boolean isGraduated) { + public GradStudentReports saveGradStudentReports(GradStudentReports gradStudentReports, boolean isGraduated) { GradStudentReportsEntity toBeSaved = gradStudentReportsTransformer.transformToEntity(gradStudentReports); Optional existingEntity = gradStudentReportsRepository.findByStudentIDAndGradReportTypeCodeAndDocumentStatusCodeNot(gradStudentReports.getStudentID(), gradStudentReports.getGradReportTypeCode(), "ARCH"); if (existingEntity.isPresent()) { @@ -319,6 +320,35 @@ public int deleteAllStudentAchievement(UUID studentID) { } + @Transactional + public long processStudentReports(List studentIDs, String reportType, String actionType) { + String reportCode = StringUtils.replace(reportType, "TVRRUN", "ACHV"); + if(StringUtils.containsIgnoreCase(actionType, "DELETE")) { + return deleteStudentReports(studentIDs, reportCode); + } + long reportsCount = 0L; + for(UUID uuid: studentIDs) { + Optional existingEntity = gradStudentReportsRepository.findByStudentIDAndGradReportTypeCode(uuid, reportType); + if(existingEntity.isPresent()) { + GradStudentReportsEntity reportsEntity = existingEntity.get(); + reportsEntity.setReportUpdateDate(new Date()); + gradStudentReportsRepository.save(reportsEntity); + reportsCount ++; + } + } + return reportsCount; + } + + @Transactional + public long deleteStudentReports(List studentIDs, String reportType) { + return gradStudentReportsRepository.deleteByStudentIDInAndGradReportTypeCode(studentIDs, ObjectUtils.defaultIfNull(reportType, "ACHV").toUpperCase()); + } + + @Transactional + public long deleteStudentReports(UUID studentID, String reportType) { + return gradStudentReportsRepository.deleteByStudentIDAndGradReportTypeCode(studentID, ObjectUtils.defaultIfNull(reportType, "ACHV").toUpperCase()); + } + public List getAllStudentReportList(UUID studentID) { List reportList = gradStudentReportsTransformer.transformToDTO(gradStudentReportsRepository.findByStudentID(studentID)); reportList.forEach(rep -> { diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/util/EducGradReportApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/util/EducGradReportApiConstants.java index 468d4237..d5707ea2 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/util/EducGradReportApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/util/EducGradReportApiConstants.java @@ -42,6 +42,8 @@ private EducGradReportApiConstants(){} public static final String UPDATE_SCHOOL_REPORTS = "/updateschoolreport"; public static final String STUDENT_REPORT = "/studentreport"; + public static final String STUDENT_REPORT_BY_STUDENTID = "/studentreport/{studentID}"; + public static final String STUDENT_REPORTS = "/studentreports"; public static final String SCHOOL_REPORT = "/schoolreport"; public static final String STUDENT_CERTIFICATE = "/studentcertificate"; public static final String STUDENT_CERTIFICATES = "/studentcertificates"; 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 c98cc1ea..6856471b 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 @@ -107,9 +107,9 @@ public void testSaveStudentReport() { gradStudentReport.setReport("TEST Report Body"); gradStudentReport.setDocumentStatusCode("IP"); - Mockito.when(commonService.saveGradReports(gradStudentReport,isGraduated)).thenReturn(gradStudentReport); + Mockito.when(commonService.saveGradStudentReports(gradStudentReport,isGraduated)).thenReturn(gradStudentReport); commonController.saveStudentReport(gradStudentReport,isGraduated); - Mockito.verify(commonService).saveGradReports(gradStudentReport,isGraduated); + Mockito.verify(commonService).saveGradStudentReports(gradStudentReport,isGraduated); } @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 93f923fc..375bbda3 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 @@ -222,7 +222,7 @@ public void testSaveGradReports_thenReturnCreateSuccess() { when(this.gradStudentReportsRepository.findByStudentIDAndGradReportTypeCodeAndDocumentStatusCodeNot(studentID, reportTypeCode,documentStatusCode)).thenReturn(optionalEmpty); when(this.gradStudentReportsRepository.save(any(GradStudentReportsEntity.class))).thenReturn(gradStudentReportEntity); - var result = commonService.saveGradReports(gradStudentReport,isGraduated); + var result = commonService.saveGradStudentReports(gradStudentReport,isGraduated); assertThat(result).isNotNull(); assertThat(result.getStudentID()).isEqualTo(studentID); @@ -258,7 +258,7 @@ public void testSaveGradReportsWithExistingOne_thenReturnUpdateSuccess() { when(this.gradStudentReportsRepository.findByStudentIDAndGradReportTypeCodeAndDocumentStatusCodeNot(studentID, reportTypeCode,"ARCH")).thenReturn(optional); when(this.gradStudentReportsRepository.save(any(GradStudentReportsEntity.class))).thenReturn(gradStudentReportEntity); - var result = commonService.saveGradReports(gradStudentReport,isGraduated); + var result = commonService.saveGradStudentReports(gradStudentReport,isGraduated); assertThat(result).isNotNull(); assertThat(result.getStudentID()).isEqualTo(studentID); @@ -294,7 +294,7 @@ public void testSaveGradReportsWithExistingOne_whenReportClobIsChanged_thenRetur when(this.gradStudentReportsRepository.findByStudentIDAndGradReportTypeCodeAndDocumentStatusCodeNot(studentID, reportTypeCode,"ARCH")).thenReturn(optional); when(this.gradStudentReportsRepository.save(any(GradStudentReportsEntity.class))).thenReturn(gradStudentReportEntity); - var result = commonService.saveGradReports(gradStudentReport,isGraduated); + var result = commonService.saveGradStudentReports(gradStudentReport,isGraduated); assertThat(result).isNotNull(); assertThat(result.getStudentID()).isEqualTo(studentID); From bcc61c7165b0f39bd9c97f0f73ca72ce1f14a566 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 2 Jul 2024 16:28:45 -0600 Subject: [PATCH 2/5] GRAD2-2817 TVR Delete Process - Backend Changes Endpoints --- .../gov/educ/api/grad/report/controller/CommonController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 cd77ea12..6fa340a0 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 @@ -86,9 +86,9 @@ public ResponseEntity getStudentReportByType( @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) public ResponseEntity deleteStudentReportByType( @RequestParam(value = "reportType") String reportType, - @PathVariable UUID uuid) { + @PathVariable UUID studentID) { logger.debug("getStudentReportByType : "); - return response.GET(commonService.deleteStudentReports(uuid, reportType)); + return response.GET(commonService.deleteStudentReports(studentID, reportType)); } @PostMapping(EducGradReportApiConstants.STUDENT_REPORTS) From 937ec4805ecf01363ad7e64ec660093064937d76 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 2 Jul 2024 16:45:01 -0600 Subject: [PATCH 3/5] GRAD2-2817 TVR Delete Process - Backend Changes Endpoints --- .../report/controller/CommonControllerTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 6856471b..766248d6 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 @@ -52,6 +52,22 @@ public void testGetStudentCertificate() { Mockito.verify(commonService).getStudentCertificate(certificateTypeCode); } + @Test + public void testProcessStudentReports() { + final UUID studentGuid = UUID.randomUUID(); + Mockito.when(commonService.processStudentReports(List.of(studentGuid), "TVRRUN", "TVRDELETE")).thenReturn(1L); + commonController.processStudentReports("TVRRUN", "TVRDELETE", List.of(studentGuid)); + Mockito.verify(commonService).processStudentReports(List.of(studentGuid), "TVRRUN", "TVRDELETE"); + } + + @Test + public void testDeleteStudentReportByType() { + final UUID studentGuid = UUID.randomUUID(); + Mockito.when(commonService.deleteStudentReports(studentGuid, "TVRRUN")).thenReturn(1L); + commonController.deleteStudentReportByType("TVRRUN", studentGuid); + Mockito.verify(commonService).deleteStudentReports(studentGuid, "TVRRUN"); + } + @Test public void testGetStudentCertificateByGuid() { final UUID studentGuid = UUID.randomUUID(); From 5da8620cdb0968e28a1d8821552fdcd7e616b399 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 2 Jul 2024 17:18:15 -0600 Subject: [PATCH 4/5] GRAD2-2817 TVR Delete Process - Backend Changes Endpoints --- .../report/service/CommonServiceTest.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) 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 375bbda3..9c35f640 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 @@ -330,6 +330,51 @@ public void testGetStudentReportByType() { } + @Test + public void testDeleteStudentReports() { + // ID + final UUID studentID = UUID.randomUUID(); + final String reportTypeCode = "TEST"; + + when(gradStudentReportsRepository.deleteByStudentIDAndGradReportTypeCode(studentID, reportTypeCode)).thenReturn(1L); + var result = commonService.deleteStudentReports(studentID, reportTypeCode); + assertThat(result).isEqualTo(1); + + when(gradStudentReportsRepository.deleteByStudentIDInAndGradReportTypeCode(List.of(studentID), reportTypeCode)).thenReturn(1L); + result = commonService.deleteStudentReports(studentID, reportTypeCode); + assertThat(result).isEqualTo(1); + + } + + @Test + public void testProcessStudentReports() { + // ID + final UUID studentID = UUID.randomUUID(); + final String reportTypeCode = "TVRRUN"; + String actionType = "TVRDELETE"; + + when(gradStudentReportsRepository.deleteByStudentIDInAndGradReportTypeCode(List.of(studentID), reportTypeCode)).thenReturn(0L); + var result = commonService.processStudentReports(List.of(studentID), reportTypeCode, actionType); + assertThat(result).isEqualTo(0); + + final UUID reportID = UUID.randomUUID(); + final String pen = "123456789"; + + final GradStudentReportsEntity gradStudentReport = new GradStudentReportsEntity(); + gradStudentReport.setId(reportID); + gradStudentReport.setGradReportTypeCode(reportTypeCode); + gradStudentReport.setPen(pen); + gradStudentReport.setStudentID(studentID); + gradStudentReport.setReport("TEST Report Body"); + actionType = "TVRCREATE"; + + when(gradStudentReportsRepository.findByStudentIDAndGradReportTypeCode(studentID, reportTypeCode)).thenReturn(Optional.of(gradStudentReport)); + when(gradStudentReportsRepository.save(gradStudentReport)).thenReturn(gradStudentReport); + result = commonService.processStudentReports(List.of(studentID), reportTypeCode, actionType); + assertThat(result).isEqualTo(1); + + } + @Test public void testGetStudentCertificateByType() { // UUID From aa504ea6a4b9de633cc1f1060b44949353aebf32 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 2 Jul 2024 17:21:02 -0600 Subject: [PATCH 5/5] GRAD2-2817 TVR Delete Process - Backend Changes Endpoints --- .../bc/gov/educ/api/grad/report/service/CommonServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9c35f640..75f4d963 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 @@ -355,7 +355,7 @@ public void testProcessStudentReports() { when(gradStudentReportsRepository.deleteByStudentIDInAndGradReportTypeCode(List.of(studentID), reportTypeCode)).thenReturn(0L); var result = commonService.processStudentReports(List.of(studentID), reportTypeCode, actionType); - assertThat(result).isEqualTo(0); + assertThat(result).isZero(); final UUID reportID = UUID.randomUUID(); final String pen = "123456789";