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

GRAD2-2306, GRAD2-2242 #495

Merged
merged 16 commits into from
Nov 21, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public ResponseEntity<byte[]> reportTranscriptByPen(@PathVariable @NotNull Strin
@RequestHeader(name="Authorization") String accessToken) {
LOGGER.debug("Report Data By Student Pen: {}", pen);
byte[] resultBinary = gradService.prepareTranscriptReport(pen, interim, preview, accessToken.replace(BEARER, ""));
if(resultBinary == null) {
if(resultBinary == null || resultBinary.length == 0) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
byte[] encoded = Base64.encodeBase64(resultBinary);
Expand Down Expand Up @@ -372,7 +372,7 @@ public ResponseEntity<byte[]> getSchoolDistrictSuppReports(
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<byte[]> getSchoolReports(@RequestBody List<String> uniqueSchools, @RequestHeader(name="Authorization") String accessToken,@RequestParam(required = true) String type ) {
byte[] resultBinary = gradService.getSchoolReports(uniqueSchools,type,accessToken.replace(BEARER, ""));
if(resultBinary == null) {
if(resultBinary == null || resultBinary.length == 0) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
return handleBinaryResponse(resultBinary, String.format("%sSchoolReport.pdf", type), MediaType.APPLICATION_PDF);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ca.bc.gov.educ.api.graduation.service;

import ca.bc.gov.educ.api.graduation.exception.ServiceException;
import ca.bc.gov.educ.api.graduation.model.dto.GradRequirement;
import ca.bc.gov.educ.api.graduation.model.dto.GraduationData;
import ca.bc.gov.educ.api.graduation.model.dto.*;
Expand All @@ -18,6 +19,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
Expand Down Expand Up @@ -138,10 +140,25 @@ public byte[] prepareTranscriptReport(String pen, String interim, String preview
reportParams.setOptions(options);
reportParams.setData(reportData);

return webClient.post().uri(educGraduationApiConstants.getTranscriptReport())
.headers(h -> { h.setBearerAuth(accessToken); h.set(EducGraduationApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID()); }
).body(BodyInserters.fromValue(reportParams)).retrieve().bodyToMono(byte[].class).block();

try {
return webClient.post().uri(educGraduationApiConstants.getTranscriptReport())
.headers(h -> {
h.setBearerAuth(accessToken);
h.set(EducGraduationApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID());
}
).body(BodyInserters.fromValue(reportParams)).retrieve()
.onStatus(
HttpStatus.NO_CONTENT::equals,
response -> response.bodyToMono(String.class).thenReturn(new ServiceException("NO_CONTENT", response.statusCode().value()))
)
.bodyToMono(byte[].class).block();
} catch (ServiceException ex) {
if(HttpStatus.NO_CONTENT.value() == ex.getStatusCode()) {
return new byte[0];
} else {
throw ex;
}
}
}

/**
Expand Down
Loading
Loading