Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop/alex grad2 2905 #543

Open
wants to merge 7 commits into
base: grad-release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,16 @@ public ResponseEntity<AlgorithmResponse> 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<ReportData> 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));
}

@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<byte[]> reportTranscriptByPen(@PathVariable @NotNull String pen,
@RequestParam(required = false) String interim,
@RequestParam(required = false) String preview) {
LOGGER.debug("Report Data By Student Pen: {}", pen);
byte[] resultBinary = gradService.prepareTranscriptReport(pen, interim, preview);
if(resultBinary == null || resultBinary.length == 0) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
Expand All @@ -94,6 +92,17 @@ public ResponseEntity<byte[]> 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<byte[]> reportTranscriptPdfByPen(@PathVariable @NotNull String pen,
@RequestParam(required = false) String interim,
@RequestParam(required = false) String preview) {
byte[] resultBinary = gradService.prepareTranscriptReport(pen, interim, preview);
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" })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +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 {
Expand Down Expand Up @@ -62,8 +67,19 @@ public void setUsedForGrad(String value) {
this.usedForGrad = value;
}

@JsonIgnore
public Double getCompletedPercentage() {
return this.mark != null? this.mark.getCompletedCoursePercentage() : null;
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.parsingCourseTraxDate(this.course.getSessionDate()) : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private void createCourseListForTranscript(List<StudentCourse> 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);
}
}
}
Expand All @@ -320,18 +320,28 @@ private boolean isValidCutOffCourse(List<StudentCourse> studentCourseList, Stude
}

@Generated
private void addIntoTranscriptList(TranscriptResult transcriptResult, List<TranscriptResult> tList) {
private void addIntoTranscriptList(TranscriptResult transcriptResult, List<TranscriptResult> tList, boolean xml) {
List<TranscriptResult> 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()
).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.getCompletedPercentage() < transcriptResult.getInterimPercentage()) &&
transcriptResult.getInterimPercentage() > 49) {
// replace
tList.remove(duplicatedTranscriptResult);
tList.add(transcriptResult);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class EducGraduationApiConstants {
public static final String GRADUATE_REPORT_DATA_BY_PEN = "/report/data/{pen}";
public static final String GRADUATE_REPORT_DATA = "/report/data";
public static final String GRADUATE_TRANSCRIPT_REPORT = "/report/transcript/{pen}";
public static final String GRADUATE_TRANSCRIPT_PDF_REPORT = "/report/transcriptpdf/{pen}";
public static final String GRADUATE_CERTIFICATE_REPORT = "/report/certificate/{pen}";
public static final String GRADUATE_ACHIEVEMENT_REPORT = "/report/achievement/{pen}";
public static final String SCHOOL_REPORTS = "/report/school";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ public static Date parsingTraxDate(String sessionDate) {
return toLastDayOfMonth(EducGraduationApiUtils.parseDate(sDates, EducGraduationApiConstants.DEFAULT_DATE_FORMAT));
}

public static Date parsingCourseTraxDate(String sessionDate) {
int countMatches = StringUtils.countMatches(sessionDate, "/");
if (countMatches == 0) {
StringBuilder sb = new StringBuilder(sessionDate);
sessionDate = sb.insert(4, '/').toString();
}
return parsingTraxDate(sessionDate);
}

public static LocalDate parsingTraxDateLocalDate(String sessionDate) {
return DateUtils.toLocalDate(parsingTraxDate(sessionDate));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ void testReportTranscriptByPen() {
Mockito.verify(graduationService).prepareTranscriptReport("12312312312","Interim",null);
}

@Test
void testReportTranscriptPdfByPen() {
byte[] bytesSAR = "Any String you want".getBytes();
Mockito.when(graduationService.prepareTranscriptReport("12312312312","Interim", null)).thenReturn(bytesSAR);
graduationController.reportTranscriptPdfByPen("12312312312","Interim",null);
Mockito.verify(graduationService).prepareTranscriptReport("12312312312","Interim",null);
}

@Test
void testReportTranscriptByPen_empty() {
byte[] bytesSAR = new byte[0];
Expand Down
Loading