From 7b700341d948ae670d5e1dae5f7de4fbc3f81435 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 17 Sep 2024 15:52:14 -0600 Subject: [PATCH 1/6] GRAD2-2905 P3 - GRAD System - XML In Progress Course selection issue --- .../model/report/TranscriptResult.java | 7 ++++++- .../api/graduation/service/ReportService.java | 21 +++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/model/report/TranscriptResult.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/model/report/TranscriptResult.java index 4eb73b18..11ef8734 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/model/report/TranscriptResult.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/model/report/TranscriptResult.java @@ -1,6 +1,7 @@ package ca.bc.gov.educ.api.graduation.model.report; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.apache.commons.lang3.math.NumberUtils; import java.util.Objects; @@ -63,7 +64,11 @@ public void setUsedForGrad(String value) { } public Double getCompletedPercentage() { - return this.mark != null? this.mark.getCompletedCoursePercentage() : null; + return this.mark != null ? this.mark.getCompletedCoursePercentage() : null; + } + + public Double getInterimPercentage() { + return this.mark != null && NumberUtils.isDigits(this.mark.getInterimPercent()) ? NumberUtils.createDouble(this.mark.getInterimPercent()) : 0d; } @Override diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/ReportService.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/ReportService.java index 1c7bebf7..ca18cae8 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/ReportService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/ReportService.java @@ -341,7 +341,7 @@ private void createCourseListForTranscript(List studentCourseList } result.setUsedForGrad(sc.getCreditsUsedForGrad() != null ? sc.getCreditsUsedForGrad().toString() : ""); result.setEquivalency(sc.getSpecialCase() != null && sc.getSpecialCase().compareTo("C") == 0 ? "C" : equivOrChallenge); - addIntoTranscriptList(result, tList); + addIntoTranscriptList(result, tList, xml); } } } @@ -366,18 +366,27 @@ private boolean isValidCutOffCourse(List studentCourseList, Stude } @Generated - private void addIntoTranscriptList(TranscriptResult transcriptResult, List tList) { + private void addIntoTranscriptList(TranscriptResult transcriptResult, List tList, boolean xml) { List dups = tList.stream().filter(tr -> tr.getCourse().isDuplicate(transcriptResult.getCourse()) && !tr.getCourse().equals(transcriptResult.getCourse()) - ).sorted(Comparator.comparing(TranscriptResult::getCompletedPercentage, Comparator.nullsLast(Double::compareTo)).reversed()).toList(); + ).sorted( + Comparator.comparing(TranscriptResult::getCompletedPercentage, Comparator.nullsLast(Double::compareTo)).reversed() + .thenComparing(TranscriptResult::getInterimPercentage, Comparator.nullsLast(Double::compareTo)).reversed() + ).toList(); // Handling duplicates if (!dups.isEmpty()) { - TranscriptResult tr = dups.get(0); + TranscriptResult duplicatedTranscriptResult = dups.get(0); // GRAD2-2394: only if a course taken previously was not used for grad(= requirementMet is blank), then the highest course will be taken - if (StringUtils.isBlank(tr.getRequirement()) && tr.getCompletedPercentage() < transcriptResult.getCompletedPercentage()) { + if (StringUtils.isBlank(duplicatedTranscriptResult.getRequirement()) && duplicatedTranscriptResult.getCompletedPercentage() < transcriptResult.getCompletedPercentage()) { // replace - tList.remove(tr); + tList.remove(duplicatedTranscriptResult); + tList.add(transcriptResult); + return; + } + if (xml && (duplicatedTranscriptResult.getInterimPercentage() < transcriptResult.getInterimPercentage())) { + // replace + tList.remove(duplicatedTranscriptResult); tList.add(transcriptResult); return; } From 510d6a22760dfd346cf8f050faed94cabedd516f Mon Sep 17 00:00:00 2001 From: arybakov Date: Wed, 18 Sep 2024 16:38:47 -0600 Subject: [PATCH 2/6] GRAD2-2905 P3 - GRAD System - XML In Progress Course selection issue --- .../controller/GraduationController.java | 15 ++++++++++++++- .../model/report/TranscriptResult.java | 11 +++++++++++ .../graduation/service/GraduationService.java | 2 +- .../api/graduation/service/ReportService.java | 16 ++++++++++++++-- .../util/EducGraduationApiConstants.java | 1 + .../graduation/util/EducGraduationApiUtils.java | 8 +++++++- .../controller/GraduationControllerTest.java | 8 ++++++++ 7 files changed, 56 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/controller/GraduationController.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/controller/GraduationController.java index 7584dbfd..ee405325 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/controller/GraduationController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/controller/GraduationController.java @@ -82,7 +82,7 @@ public ResponseEntity reportDataByPen(@PathVariable @NotNull String @GetMapping(EducGraduationApiConstants.GRADUATE_TRANSCRIPT_REPORT) @PreAuthorize(PermissionsContants.GRADUATE_TRANSCRIPT) - @Operation(summary = "Get Transcript binary from graduation by student pen", description = "Get Transcript binary from graduation by student pen", tags = { "Graduation Data" }) + @Operation(summary = "Get Transcript encoded binary from graduation by student pen", description = "Get Transcript encoded binary from graduation by student pen", tags = { "Graduation Data" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) public ResponseEntity reportTranscriptByPen(@PathVariable @NotNull String pen, @RequestParam(required = false) String interim, @@ -97,6 +97,19 @@ public ResponseEntity reportTranscriptByPen(@PathVariable @NotNull Strin return handleBinaryResponse(encoded, String.format("%sTranscript%sReport.pdfencoded", pen, interim), MediaType.TEXT_PLAIN); } + @GetMapping(EducGraduationApiConstants.GRADUATE_TRANSCRIPT_PDF_REPORT) + @PreAuthorize(PermissionsContants.GRADUATE_TRANSCRIPT) + @Operation(summary = "Get Transcript binary from graduation by student pen", description = "Get Transcript binary from graduation by student pen", tags = { "Graduation Data" }) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) + public ResponseEntity reportTranscriptPdfByPen(@PathVariable @NotNull String pen, + @RequestParam(required = false) String interim, + @RequestParam(required = false) String preview, + @RequestHeader(name="Authorization") String accessToken) { + LOGGER.debug("Report Data By Student Pen: {}", pen); + byte[] resultBinary = gradService.prepareTranscriptReport(pen, interim, preview, accessToken.replace(BEARER, "")); + return handleBinaryResponse(resultBinary, String.format("%sTranscript%sReport.pdf", pen, interim), MediaType.APPLICATION_PDF); + } + @PostMapping(EducGraduationApiConstants.GRADUATE_REPORT_DATA) @PreAuthorize(PermissionsContants.GRADUATE_DATA) @Operation(summary = "Adapt graduation data for reporting", description = "Adapt graduation data for reporting", tags = { "Graduation Data" }) diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/model/report/TranscriptResult.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/model/report/TranscriptResult.java index 11ef8734..d14846c0 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/model/report/TranscriptResult.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/model/report/TranscriptResult.java @@ -1,8 +1,12 @@ package ca.bc.gov.educ.api.graduation.model.report; +import ca.bc.gov.educ.api.graduation.util.EducGraduationApiUtils; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; +import java.util.Date; import java.util.Objects; public class TranscriptResult { @@ -63,14 +67,21 @@ public void setUsedForGrad(String value) { this.usedForGrad = value; } + @JsonIgnore public Double getCompletedPercentage() { return this.mark != null ? this.mark.getCompletedCoursePercentage() : null; } + @JsonIgnore public Double getInterimPercentage() { return this.mark != null && NumberUtils.isDigits(this.mark.getInterimPercent()) ? NumberUtils.createDouble(this.mark.getInterimPercent()) : 0d; } + @JsonIgnore + public Date getSessionDate() { + return this.course != null && StringUtils.isNotBlank(this.course.getSessionDate()) ? EducGraduationApiUtils.parsingTraxDate(this.course.getSessionDate()) : null; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/GraduationService.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/GraduationService.java index b2471da1..6283fc25 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/GraduationService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/GraduationService.java @@ -134,7 +134,7 @@ public byte[] prepareTranscriptReport(String pen, String interim, String preview ReportOptions options = new ReportOptions(); options.setReportFile("transcript"); - options.setReportName("Transcript Report.pdf"); + options.setReportName(String.format("%sTranscript%sReport.pdf", pen, interim)); options.setPreview(isPreview); ReportRequest reportParams = new ReportRequest(); reportParams.setOptions(options); diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/ReportService.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/ReportService.java index ca18cae8..8ad20434 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/ReportService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/ReportService.java @@ -371,7 +371,7 @@ private void addIntoTranscriptList(TranscriptResult transcriptResult, List Date: Thu, 19 Sep 2024 13:59:25 -0600 Subject: [PATCH 3/6] GRAD2-2905 P3 - GRAD System - XML In Progress Course selection issue --- .../model/report/TranscriptResult.java | 2 +- .../graduation/service/GraduationService.java | 2 +- .../api/graduation/service/ReportService.java | 17 +++-------------- .../graduation/util/EducGraduationApiUtils.java | 15 +++++++++------ 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/model/report/TranscriptResult.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/model/report/TranscriptResult.java index d14846c0..b5da80e6 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/model/report/TranscriptResult.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/model/report/TranscriptResult.java @@ -79,7 +79,7 @@ public Double getInterimPercentage() { @JsonIgnore public Date getSessionDate() { - return this.course != null && StringUtils.isNotBlank(this.course.getSessionDate()) ? EducGraduationApiUtils.parsingTraxDate(this.course.getSessionDate()) : null; + return this.course != null && StringUtils.isNotBlank(this.course.getSessionDate()) ? EducGraduationApiUtils.parsingCourseTraxDate(this.course.getSessionDate()) : null; } @Override diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/GraduationService.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/GraduationService.java index 6283fc25..b2471da1 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/GraduationService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/GraduationService.java @@ -134,7 +134,7 @@ public byte[] prepareTranscriptReport(String pen, String interim, String preview ReportOptions options = new ReportOptions(); options.setReportFile("transcript"); - options.setReportName(String.format("%sTranscript%sReport.pdf", pen, interim)); + options.setReportName("Transcript Report.pdf"); options.setPreview(isPreview); ReportRequest reportParams = new ReportRequest(); reportParams.setOptions(options); diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/ReportService.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/ReportService.java index 8ad20434..89bc3aa7 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/service/ReportService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/service/ReportService.java @@ -371,7 +371,6 @@ private void addIntoTranscriptList(TranscriptResult transcriptResult, List 49) { // replace tList.remove(duplicatedTranscriptResult); tList.add(transcriptResult); return; } - } tList.add(transcriptResult); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/util/EducGraduationApiUtils.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/util/EducGraduationApiUtils.java index a67dabcf..ec36ae68 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/util/EducGraduationApiUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/util/EducGraduationApiUtils.java @@ -158,16 +158,19 @@ public static String parsingDateForCertificate(String sessionDate) { } public static Date parsingTraxDate(String sessionDate) { + String actualSessionDate = StringUtils.countMatches(sessionDate, "/") == 2 ? sessionDate : sessionDate + "/01"; + Date temp = EducGraduationApiUtils.parseDate(actualSessionDate, EducGraduationApiConstants.SECONDARY_DATE_FORMAT); + String sDates = EducGraduationApiUtils.formatDate(temp, EducGraduationApiConstants.DEFAULT_DATE_FORMAT); + return toLastDayOfMonth(EducGraduationApiUtils.parseDate(sDates, EducGraduationApiConstants.DEFAULT_DATE_FORMAT)); + } + + public static Date parsingCourseTraxDate(String sessionDate) { int countMatches = StringUtils.countMatches(sessionDate, "/"); - if(countMatches == 0) { + if (countMatches == 0) { StringBuilder sb = new StringBuilder(sessionDate); sessionDate = sb.insert(4, '/').toString(); - countMatches = 1; } - String actualSessionDate = countMatches == 2 ? sessionDate : sessionDate + "/01"; - Date temp = EducGraduationApiUtils.parseDate(actualSessionDate, EducGraduationApiConstants.SECONDARY_DATE_FORMAT); - String sDates = EducGraduationApiUtils.formatDate(temp, EducGraduationApiConstants.DEFAULT_DATE_FORMAT); - return toLastDayOfMonth(EducGraduationApiUtils.parseDate(sDates, EducGraduationApiConstants.DEFAULT_DATE_FORMAT)); + return parsingTraxDate(sessionDate); } public static LocalDate parsingTraxDateLocalDate(String sessionDate) { From fd215e7d69e55675b8f85561982b006a4fea85be Mon Sep 17 00:00:00 2001 From: arybakov Date: Thu, 19 Sep 2024 15:40:12 -0600 Subject: [PATCH 4/6] GRAD2-2905 P3 - GRAD System - XML In Progress Course selection issue Fix merge issues --- .../api/graduation/controller/GraduationController.java | 5 ++--- .../api/graduation/controller/GraduationControllerTest.java | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/controller/GraduationController.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/controller/GraduationController.java index 9a454dba..77ae6eb4 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/controller/GraduationController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/controller/GraduationController.java @@ -100,10 +100,9 @@ public ResponseEntity reportTranscriptByPen(@PathVariable @NotNull Strin @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) public ResponseEntity reportTranscriptPdfByPen(@PathVariable @NotNull String pen, @RequestParam(required = false) String interim, - @RequestParam(required = false) String preview, - @RequestHeader(name="Authorization") String accessToken) { + @RequestParam(required = false) String preview) { LOGGER.debug("Report Data By Student Pen: {}", pen); - byte[] resultBinary = gradService.prepareTranscriptReport(pen, interim, preview, accessToken.replace(BEARER, "")); + byte[] resultBinary = gradService.prepareTranscriptReport(pen, interim, preview); return handleBinaryResponse(resultBinary, String.format("%sTranscript%sReport.pdf", pen, interim), MediaType.APPLICATION_PDF); } diff --git a/api/src/test/java/ca/bc/gov/educ/api/graduation/controller/GraduationControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/graduation/controller/GraduationControllerTest.java index cc37bb2b..a176a52f 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/graduation/controller/GraduationControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/graduation/controller/GraduationControllerTest.java @@ -101,9 +101,9 @@ void testReportTranscriptByPen() { @Test void testReportTranscriptPdfByPen() { byte[] bytesSAR = "Any String you want".getBytes(); - Mockito.when(graduationService.prepareTranscriptReport("12312312312","Interim", null,"accessToken")).thenReturn(bytesSAR); - graduationController.reportTranscriptPdfByPen("12312312312","Interim",null,"accessToken"); - Mockito.verify(graduationService).prepareTranscriptReport("12312312312","Interim",null,"accessToken"); + Mockito.when(graduationService.prepareTranscriptReport("12312312312","Interim", null)).thenReturn(bytesSAR); + graduationController.reportTranscriptPdfByPen("12312312312","Interim",null); + Mockito.verify(graduationService).prepareTranscriptReport("12312312312","Interim",null); } @Test From 132fb2083da54d38fcfda0e55054d28fb443357b Mon Sep 17 00:00:00 2001 From: arybakov Date: Thu, 19 Sep 2024 15:54:28 -0600 Subject: [PATCH 5/6] GRAD2-2905 P3 - GRAD System - XML In Progress Course selection issue Fix merge issues --- .../educ/api/graduation/controller/GraduationController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/controller/GraduationController.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/controller/GraduationController.java index 77ae6eb4..ff100955 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/controller/GraduationController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/controller/GraduationController.java @@ -85,7 +85,7 @@ public ResponseEntity reportDataByPen(@PathVariable @NotNull String public ResponseEntity reportTranscriptByPen(@PathVariable @NotNull String pen, @RequestParam(required = false) String interim, @RequestParam(required = false) String preview) { - LOGGER.debug("Report Data By Student Pen: {}", pen); + LOGGER.debug("Report Data By Student Pen"); byte[] resultBinary = gradService.prepareTranscriptReport(pen, interim, preview); if(resultBinary == null || resultBinary.length == 0) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); @@ -101,7 +101,7 @@ public ResponseEntity reportTranscriptByPen(@PathVariable @NotNull Strin public ResponseEntity reportTranscriptPdfByPen(@PathVariable @NotNull String pen, @RequestParam(required = false) String interim, @RequestParam(required = false) String preview) { - LOGGER.debug("Report Data By Student Pen: {}", pen); + LOGGER.debug("Report Data By Student Pen"); byte[] resultBinary = gradService.prepareTranscriptReport(pen, interim, preview); return handleBinaryResponse(resultBinary, String.format("%sTranscript%sReport.pdf", pen, interim), MediaType.APPLICATION_PDF); } From 25b9d82132ade37f4b6e0e298391b517d6f0d81a Mon Sep 17 00:00:00 2001 From: arybakov Date: Thu, 19 Sep 2024 15:55:22 -0600 Subject: [PATCH 6/6] GRAD2-2905 P3 - GRAD System - XML In Progress Course selection issue Fix merge issues --- .../educ/api/graduation/controller/GraduationController.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/graduation/controller/GraduationController.java b/api/src/main/java/ca/bc/gov/educ/api/graduation/controller/GraduationController.java index ff100955..7f74816b 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/graduation/controller/GraduationController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/graduation/controller/GraduationController.java @@ -74,7 +74,6 @@ public ResponseEntity graduateStudentNew(@PathVariable String @Operation(summary = "Get Report data from graduation by student pen", description = "Get Report data from graduation by student pen", tags = { "Graduation Data" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) public ResponseEntity reportDataByPen(@PathVariable @NotNull String pen, @RequestParam(required = false) String type) { - LOGGER.debug("Report Data By Student Pen: {}", pen); return response.GET(gradService.prepareReportData(pen, type)); } @@ -85,7 +84,6 @@ public ResponseEntity reportDataByPen(@PathVariable @NotNull String public ResponseEntity reportTranscriptByPen(@PathVariable @NotNull String pen, @RequestParam(required = false) String interim, @RequestParam(required = false) String preview) { - LOGGER.debug("Report Data By Student Pen"); byte[] resultBinary = gradService.prepareTranscriptReport(pen, interim, preview); if(resultBinary == null || resultBinary.length == 0) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); @@ -101,7 +99,6 @@ public ResponseEntity reportTranscriptByPen(@PathVariable @NotNull Strin public ResponseEntity reportTranscriptPdfByPen(@PathVariable @NotNull String pen, @RequestParam(required = false) String interim, @RequestParam(required = false) String preview) { - LOGGER.debug("Report Data By Student Pen"); byte[] resultBinary = gradService.prepareTranscriptReport(pen, interim, preview); return handleBinaryResponse(resultBinary, String.format("%sTranscript%sReport.pdf", pen, interim), MediaType.APPLICATION_PDF); }