From 9560466bea5e1c47bf26da706a0e1b23d493c5fb Mon Sep 17 00:00:00 2001 From: githubmamatha Date: Thu, 9 Jan 2025 10:14:05 -0800 Subject: [PATCH] Reading school details from Trax api by mincode and send schoolOfRecordId to retrieve amalgamated school reports. --- .../service/GradBusinessService.java | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java index dafa620..6a96502 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java @@ -236,32 +236,35 @@ public ResponseEntity getDistrictReportPDFByDistcode(String distCode, St public ResponseEntity getAmalgamatedSchoolReportPDFByMincode(String mincode, String type, String accessToken) { logger.debug("******** Retrieve List of Students for Amalgamated School Report ******"); - List studentList = webClient.get().uri(String.format(educGradStudentApiConstants.getStudentsForAmalgamatedReport(), mincode, type)).headers(h -> h.setBearerAuth(accessToken)).retrieve().bodyToMono(new ParameterizedTypeReference>() { - }).block(); List locations = new ArrayList<>(); - if (studentList != null && !studentList.isEmpty()) { - logger.debug("******** Fetched {} students ******", studentList.size()); - List> partitions = ListUtils.partition(studentList, 200); - getStudentAchievementReports(partitions, locations); - Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("PST"), Locale.CANADA); - int year = cal.get(Calendar.YEAR); - String month = "00"; - String fileName = EducGradBusinessUtil.getReportsFileNameForSchoolAndDistrict(mincode, year, month, type, MediaType.APPLICATION_PDF); - try { - logger.debug("******** Merging Documents Started ******"); - byte[] res = EducGradBusinessUtil.mergeDocumentsPDFs(locations); - logger.debug("******** Merged {} Documents ******", locations.size()); - HttpHeaders headers = new HttpHeaders(); - headers.put(HttpHeaders.AUTHORIZATION, Collections.singletonList(BEARER + accessToken)); - headers.put(HttpHeaders.ACCEPT, Collections.singletonList(APPLICATION_PDF)); - headers.put(HttpHeaders.CONTENT_TYPE, Collections.singletonList(APPLICATION_PDF)); - saveBinaryResponseToFile(res, fileName); - return handleBinaryResponse(res, fileName, MediaType.APPLICATION_PDF); - } catch (Exception e) { - return getInternalServerErrorResponse(e); + Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("PST"), Locale.CANADA); + int year = cal.get(Calendar.YEAR); + String month = "00"; + + try { + List schoolDetails = schoolService.getSchoolDetails(mincode); + if (schoolDetails.isEmpty()) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); } + String schoolOfRecordId = schoolDetails.get(0).getSchoolId(); + + List studentList = webClient.get().uri(String.format(educGradStudentApiConstants.getStudentsForAmalgamatedReport(), schoolOfRecordId, type)).headers(h -> h.setBearerAuth(accessToken)).retrieve().bodyToMono(new ParameterizedTypeReference>() {}).block(); + + if (studentList != null && !studentList.isEmpty()) { + logger.debug("******** Fetched {} students ******", studentList.size()); + List> partitions = ListUtils.partition(studentList, 200); + getStudentAchievementReports(partitions, locations); + } + String fileName = EducGradBusinessUtil.getReportsFileNameForSchoolAndDistrict(mincode, year, month, type, MediaType.APPLICATION_PDF); + logger.debug("******** Merging Documents Started ******"); + byte[] res = EducGradBusinessUtil.mergeDocumentsPDFs(locations); + logger.debug("******** Merged {} Documents ******", locations.size()); + saveBinaryResponseToFile(res, fileName); + return handleBinaryResponse(res, fileName, MediaType.APPLICATION_PDF); + } catch (Exception e) { + logger.error("Error getting amalgamated report PDF by mincode: {}", e.getMessage()); + return getInternalServerErrorResponse(e); } - return null; } @Transactional