Skip to content

Commit

Permalink
Merge branch 'refs/heads/grad-release'
Browse files Browse the repository at this point in the history
  • Loading branch information
chris.ditcher authored and chris.ditcher committed Oct 9, 2024
2 parents f49926b + 21783fa commit b0f8c14
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,18 @@ 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 encoded binary from graduation by student pen", description = "Get Transcript encoded binary from graduation by student pen", tags = { "Graduation Data" })
@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[]> 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 @@ -92,17 +94,6 @@ 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,12 +1,7 @@
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 @@ -67,19 +62,8 @@ 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.parsingCourseTraxDate(this.course.getSessionDate()) : null;
return this.mark != null? this.mark.getCompletedCoursePercentage() : 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, xml);
addIntoTranscriptList(result, tList);
}
}
}
Expand All @@ -320,28 +320,18 @@ private boolean isValidCutOffCourse(List<StudentCourse> studentCourseList, Stude
}

@Generated
private void addIntoTranscriptList(TranscriptResult transcriptResult, List<TranscriptResult> tList, boolean xml) {
private void addIntoTranscriptList(TranscriptResult transcriptResult, List<TranscriptResult> tList) {
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 duplicatedTranscriptResult = dups.get(0);
TranscriptResult tr = 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(duplicatedTranscriptResult.getRequirement()) && duplicatedTranscriptResult.getCompletedPercentage() < transcriptResult.getCompletedPercentage()) {
if (StringUtils.isBlank(tr.getRequirement()) && tr.getCompletedPercentage() < transcriptResult.getCompletedPercentage()) {
// replace
tList.remove(duplicatedTranscriptResult);
tList.add(transcriptResult);
return;
}
if (xml &&
(duplicatedTranscriptResult.getCompletedPercentage() < transcriptResult.getInterimPercentage()) &&
transcriptResult.getInterimPercentage() > 49) {
// replace
tList.remove(duplicatedTranscriptResult);
tList.remove(tr);
tList.add(transcriptResult);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ 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,15 +164,6 @@ 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,14 +98,6 @@ 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

0 comments on commit b0f8c14

Please sign in to comment.