From 1d02aa0972fa298f035a957b10ca6f0845c7b59e Mon Sep 17 00:00:00 2001 From: arybakov Date: Thu, 27 Jun 2024 16:30:53 -0600 Subject: [PATCH] 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);