Skip to content

Commit

Permalink
Grad release 1.10.0
Browse files Browse the repository at this point in the history
Grad release 1.10.0
  • Loading branch information
kamal-mohammed authored Nov 16, 2023
2 parents 7f0fdf1 + 8f2e052 commit dd3e70c
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 69 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>ca.bc.gov</groupId>
<artifactId>educ-grad-business-api</artifactId>
<version>1.8.23</version>
<version>1.8.24</version>
<name>educ-grad-business-api</name>
<description>GRAD Business API for external clients</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,20 @@ public ResponseEntity<byte[]> schoolReportByMincode(@PathVariable String mincode

@GetMapping(EducGraduationApiConstants.STUDENT_CREDENTIAL_PDF)
@PreAuthorize("hasAuthority('SCOPE_GET_GRADUATION_DATA')")
@Operation(summary = "Get School Report pdf from graduation by mincode and report type", description = "Get School Report pdf from graduation by mincode and report type", tags = { "Graduation Data" })
@Operation(summary = "Get Student Transcript or TVR Report pdf by PEN and report type", description = "Get Student Transcript or TVR Report pdf by PEN and report type", tags = { "Graduation Data" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<byte[]> studentCredentialByType(@PathVariable String pen, @PathVariable String type, @RequestHeader(name="Authorization") String accessToken) {
return gradBusinessService.getStudentCredentialPDFByType(pen, type, accessToken.replace(BEARER, ""));
}

@GetMapping(EducGraduationApiConstants.STUDENT_TRANSCRIPT_PDF)
@PreAuthorize("hasAuthority('SCOPE_GET_GRADUATION_DATA')")
@Operation(summary = "Get Transcript Report pdf by PEN and optional xml type parameter", description = "Get Transcript Report pdf by PEN and optional xml type parameter", tags = { "Graduation Data" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<byte[]> studentTranscriptByType(@PathVariable String pen, @RequestParam(required = false) String type, @RequestHeader(name="Authorization") String accessToken) {
return gradBusinessService.getStudentTranscriptPDFByType(pen, type, accessToken.replace(BEARER, ""));
}

@GetMapping(EducGraduationApiConstants.AMALGAMATED_SCHOOL_REPORT_PDF)
@PreAuthorize("hasAuthority('SCOPE_GET_GRADUATION_DATA')")
@Operation(summary = "Get School Report pdf from graduation by mincode and report type", description = "Get School Report pdf from graduation by mincode and report type", tags = { "Graduation Data" })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package ca.bc.gov.educ.api.gradbusiness.service;

import ca.bc.gov.educ.api.gradbusiness.model.dto.Student;
import ca.bc.gov.educ.api.gradbusiness.util.EducGradBusinessUtil;
import ca.bc.gov.educ.api.gradbusiness.util.EducGradBusinessApiConstants;
import ca.bc.gov.educ.api.gradbusiness.util.EducGradBusinessUtil;
import ca.bc.gov.educ.api.gradbusiness.util.EducGraduationApiConstants;
import io.github.resilience4j.retry.annotation.Retry;
import jakarta.transaction.Transactional;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -19,7 +20,6 @@
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;

import jakarta.transaction.Transactional;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
Expand All @@ -35,6 +35,7 @@ public class GradBusinessService {
private static final String BEARER = "Bearer ";
private static final String APPLICATION_JSON = "application/json";
private static final String APPLICATION_PDF = "application/pdf";
private static final String ACCEPT = "*/*";
/**
* The Web client.
*/
Expand Down Expand Up @@ -86,7 +87,9 @@ public ResponseEntity<byte[]> prepareReportDataByPen(String pen, String type, St
type = Optional.ofNullable(type).orElse("");
try {
byte[] result = webClient.get().uri(String.format(educGraduationApiConstants.getGraduateReportDataByPenUrl(), pen) + "?type=" + type).headers(h -> h.setBearerAuth(accessToken)).retrieve().bodyToMono(byte[].class).block();
assert result != null;
if(result == null) {
result = new byte[0];
}
return handleBinaryResponse(result, "graduation_report_data.json", MediaType.APPLICATION_JSON);
} catch (Exception e) {
return getInternalServerErrorResponse(e);
Expand All @@ -108,7 +111,9 @@ public ResponseEntity<byte[]> prepareReportDataByGraduation(String graduationDat
headers.put(HttpHeaders.ACCEPT, Collections.singletonList(APPLICATION_JSON));
headers.put(HttpHeaders.CONTENT_TYPE, Collections.singletonList(APPLICATION_JSON));
byte[] result = webClient.post().uri(educGraduationApiConstants.getGraduateReportDataByGraduation() + "?type=" + type).headers(h -> h.addAll(headers)).body(BodyInserters.fromValue(graduationData)).retrieve().bodyToMono(byte[].class).block();
assert result != null;
if(result == null) {
result = new byte[0];
}
return handleBinaryResponse(result, "graduation_report_data.json", MediaType.APPLICATION_JSON);
} catch (Exception e) {
return getInternalServerErrorResponse(e);
Expand All @@ -129,7 +134,9 @@ public ResponseEntity<byte[]> prepareXmlTranscriptReportDataByXmlRequest(String
headers.put(HttpHeaders.ACCEPT, Collections.singletonList(APPLICATION_JSON));
headers.put(HttpHeaders.CONTENT_TYPE, Collections.singletonList(APPLICATION_JSON));
byte[] result = webClient.post().uri(educGraduationApiConstants.getXmlTranscriptReportData()).headers(h -> h.addAll(headers)).body(BodyInserters.fromValue(xmlRequest)).retrieve().bodyToMono(byte[].class).block();
assert result != null;
if(result == null) {
result = new byte[0];
}
return handleBinaryResponse(result, "xml_transcript_report_data.json", MediaType.APPLICATION_JSON);
} catch (Exception e) {
return getInternalServerErrorResponse(e);
Expand All @@ -150,7 +157,9 @@ public ResponseEntity<byte[]> getStudentDemographicsByPen(String pen, String acc
headers.put(HttpHeaders.ACCEPT, Collections.singletonList(APPLICATION_JSON));
headers.put(HttpHeaders.CONTENT_TYPE, Collections.singletonList(APPLICATION_JSON));
byte[] result = webClient.get().uri(String.format(educGradStudentApiConstants.getPenDemographicStudentApiUrl(), pen)).headers(h -> h.setBearerAuth(accessToken)).retrieve().bodyToMono(byte[].class).block();
assert result != null;
if(result == null) {
result = new byte[0];
}
return handleBinaryResponse(result, "student_demog_data.json", MediaType.APPLICATION_JSON);
} catch (Exception e) {
return getInternalServerErrorResponse(e);
Expand Down Expand Up @@ -209,8 +218,10 @@ public ResponseEntity<byte[]> getSchoolReportPDFByMincode(String mincode, String
headers.put(HttpHeaders.ACCEPT, Collections.singletonList(APPLICATION_PDF));
headers.put(HttpHeaders.CONTENT_TYPE, Collections.singletonList(APPLICATION_PDF));
InputStreamResource result = webClient.get().uri(String.format(educGraduationApiConstants.getSchoolReportByMincode(), mincode,type)).headers(h -> h.setBearerAuth(accessToken)).retrieve().bodyToMono(InputStreamResource.class).block();
assert result != null;
byte[] res = IOUtils.toByteArray(result.getInputStream());
byte[] res = new byte[0];
if(result != null) {
res = result.getInputStream().readAllBytes();
}
return handleBinaryResponse(res, EducGradBusinessUtil.getFileNameSchoolReports(mincode,year,month,type), MediaType.APPLICATION_PDF);
} catch (Exception e) {
return getInternalServerErrorResponse(e);
Expand Down Expand Up @@ -253,7 +264,6 @@ public ResponseEntity<byte[]> getAmalgamatedSchoolReportPDFByMincode(String minc
return null;
}


@Transactional
public ResponseEntity<byte[]> getStudentCredentialPDFByType(String pen, String type, String accessToken) {
List<Student> stud = getStudentByPenFromStudentAPI(pen,accessToken);
Expand All @@ -264,16 +274,43 @@ public ResponseEntity<byte[]> getStudentCredentialPDFByType(String pen, String t
headers.put(HttpHeaders.ACCEPT, Collections.singletonList(APPLICATION_PDF));
headers.put(HttpHeaders.CONTENT_TYPE, Collections.singletonList(APPLICATION_PDF));
InputStreamResource result = webClient.get().uri(String.format(educGraduationApiConstants.getStudentCredentialByType(), studObj.getStudentID(),type)).headers(h -> h.setBearerAuth(accessToken)).retrieve().bodyToMono(InputStreamResource.class).block();
assert result != null;
byte[] res = IOUtils.toByteArray(result.getInputStream());
byte[] res = new byte[0];
if(result != null) {
res = result.getInputStream().readAllBytes();
}
return handleBinaryResponse(res, EducGradBusinessUtil.getFileNameStudentCredentials(studObj.getMincode(),pen,type), MediaType.APPLICATION_PDF);
} catch (Exception e) {
return getInternalServerErrorResponse(e);
}
}





@Transactional
public ResponseEntity<byte[]> getStudentTranscriptPDFByType(String pen, String type, String accessToken) {
try {
byte[] reportData = prepareReportDataByPen(pen, type, accessToken).getBody();
StringBuilder reportRequest = new StringBuilder();
String reportOptions = "\"options\": {\n" +
" \"cacheReport\": false,\n" +
" \"convertTo\": \"pdf\",\n" +
" \"overwrite\": false,\n" +
" \"reportName\": \"transcript\",\n" +
" \"reportFile\": \""+pen+" Transcript Report.pdf\"\n" +
" },\n";
reportRequest.append("{\n");
reportRequest.append(reportOptions);
reportRequest.append("\"data\":\n");
reportRequest.append(new String(reportData)).append("\n");
reportRequest.append("}\n");
HttpHeaders headers = new HttpHeaders();
headers.put(HttpHeaders.AUTHORIZATION, Collections.singletonList(BEARER + accessToken));
headers.put(HttpHeaders.ACCEPT, Collections.singletonList(ACCEPT));
headers.put(HttpHeaders.CONTENT_TYPE, Collections.singletonList(APPLICATION_JSON));
byte[] result = webClient.post().uri(educGraduationApiConstants.getStudentTranscriptReportByRequest()).headers(h -> h.addAll(headers)).body(BodyInserters.fromValue(reportRequest.toString())).retrieve().bodyToMono(byte[].class).block();
assert result != null;
return handleBinaryResponse(result, pen + " Transcript Report.pdf", MediaType.APPLICATION_PDF);
} catch (Exception e) {
return getInternalServerErrorResponse(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class EducGraduationApiConstants {
public static final String SCHOOL_REPORT_PDF = "/schoolreport/{mincode}";
public static final String AMALGAMATED_SCHOOL_REPORT_PDF = "/amalgamated/schoolreport/{mincode}";
public static final String STUDENT_CREDENTIAL_PDF = "/studentcredential/{pen}/type/{type}";
public static final String STUDENT_TRANSCRIPT_PDF = "/studenttranscript/{pen}";

//Default Date format constants
public static final String DEFAULT_CREATED_BY = "API_GRADUATION";
Expand All @@ -50,5 +51,8 @@ public class EducGraduationApiConstants {
@Value("${endpoint.grad-graduation-report-api.student-credential-by-type.url}")
private String studentCredentialByType;

@Value("${endpoint.grad-report-api.transcript-by-request.url}")
private String studentTranscriptReportByRequest;


}
2 changes: 2 additions & 0 deletions api/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ endpoint:
grad-report-api:
report-data-by-xml:
url: ${REPORT_API}api/v1/reports/xmltranscriptreport
transcript-by-request:
url: ${REPORT_API}api/v1/reports/transcriptreport
grad-student-api:
demographic:
url: ${GRAD_STUDENT_API}api/v1/student/demog/pen/%s
Expand Down
Loading

0 comments on commit dd3e70c

Please sign in to comment.