Skip to content

Commit

Permalink
GRAD2-3036: task is completed.
Browse files Browse the repository at this point in the history
GRAD2-3036: task is completed.
  • Loading branch information
infstar committed Jan 3, 2025
1 parent 7fa014f commit 01e263d
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import static ca.bc.gov.educ.api.graduation.service.SchoolReportsService.*;

Expand Down Expand Up @@ -108,7 +109,7 @@ public ResponseEntity<ReportData> reportDataFromGraduation(@RequestBody @NotNull
@PreAuthorize(PermissionsContants.GRADUATE_STUDENT)
@Operation(summary = "School Report Creation", description = "When triggered, School Reports are created", tags = { "Reports" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<Integer> createAndStoreSchoolReports(@RequestBody List<String> uniqueSchools, @RequestHeader(name="Authorization") String accessToken,@RequestParam(required = false) String type ) {
public ResponseEntity<Integer> createAndStoreSchoolReports(@RequestBody List<UUID> uniqueSchools, @RequestHeader(name="Authorization") String accessToken, @RequestParam(required = false) String type ) {
return response.GET(gradService.createAndStoreSchoolReports(uniqueSchools,type));
}

Expand Down Expand Up @@ -364,7 +365,7 @@ public ResponseEntity<byte[]> getSchoolDistrictSuppReports(
@PreAuthorize(PermissionsContants.GRADUATE_STUDENT)
@Operation(summary = "School Report Generation", description = "When triggered, School Report is generated", tags = { "Reports", "type=GRADREG", "type=NONGRADREG", "type=NONGRADPRJ" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<byte[]> getSchoolReports(@RequestBody List<String> uniqueSchools, @RequestParam(required = true) String type ) {
public ResponseEntity<byte[]> getSchoolReports(@RequestBody List<UUID> uniqueSchools, @RequestParam(required = true) String type ) {
byte[] resultBinary = gradService.getSchoolReports(uniqueSchools,type);
if(resultBinary == null || resultBinary.length == 0) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public class SchoolReports extends BaseModel {
private String reportTypeCode;
private String reportTypeLabel;
private String schoolOfRecord;
private UUID schoolOfRecordId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.web.reactive.function.client.WebClient;

import java.util.List;
import java.util.UUID;

@Service
public class GradStatusService {
Expand Down Expand Up @@ -107,8 +108,8 @@ public void restoreStudentGradStatus(String studentID, boolean isGraduated) {
restService.get(String.format(educGraduationApiConstants.getUpdateGradStatusAlgoError(),studentID,isGraduated), Boolean.class);
}

public List<GraduationStudentRecord> getStudentListByMinCode(String schoolOfRecord) {
var response = this.restService.get(String.format(educGraduationApiConstants.getGradStudentListSchoolReport(),schoolOfRecord), List.class);
public List<GraduationStudentRecord> getStudentListBySchoolId(UUID schoolId) {
var response = this.restService.get(String.format(educGraduationApiConstants.getGradStudentListSchoolReport(),schoolId), List.class);
return jsonTransformer.convertValue(response, new TypeReference<>(){});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

@Service
public class GraduationService {
Expand Down Expand Up @@ -191,14 +192,13 @@ private boolean isGraduated(GraduationStudentRecord graduationStudentRecord, Gra
return graduationData.isGraduated() && graduationStudentRecord.getProgramCompletionDate() != null;
}

public byte[] getSchoolReports(List<String> uniqueSchoolList, String type) {
public byte[] getSchoolReports(List<UUID> uniqueSchoolList, String type) {
byte[] result = new byte[0];
for (String usl : uniqueSchoolList) {
for (UUID usl : uniqueSchoolList) {
try {
List<GraduationStudentRecord> stdList = gradStatusService.getStudentListByMinCode(usl);
List<ca.bc.gov.educ.api.graduation.model.dto.institute.School> schoolDetails = schoolService.getSchoolDetails(usl);
if (schoolDetails != null && !schoolDetails.isEmpty()) {
ca.bc.gov.educ.api.graduation.model.dto.institute.School schoolDetail = schoolDetails.get(0);
List<GraduationStudentRecord> stdList = gradStatusService.getStudentListBySchoolId(usl);
ca.bc.gov.educ.api.graduation.model.dto.institute.School schoolDetail = schoolService.getSchoolDetails(usl);
if (schoolDetail != null) {
School schoolObj = new School();
schoolObj.setSchoolId(schoolDetail.getSchoolId());
schoolObj.setMincode(schoolDetail.getMincode());
Expand All @@ -222,25 +222,24 @@ public byte[] getSchoolReports(List<String> uniqueSchoolList, String type) {
}
}
} catch (Exception e) {
logger.error("Failed to generate {} report for mincode: {} due to: {}", type, usl, e.getLocalizedMessage());
logger.error("Failed to generate {} report for schoolId: {} due to: {}", type, usl, e.getLocalizedMessage());
}
}
return result;
}

public Integer createAndStoreSchoolReports(List<String> uniqueSchoolList, String type) {
public Integer createAndStoreSchoolReports(List<UUID> uniqueSchoolList, String type) {
int numberOfReports = 0;
for (String usl : uniqueSchoolList) {
for (UUID usl : uniqueSchoolList) {
try {
List<GraduationStudentRecord> stdList = gradStatusService.getStudentListByMinCode(usl);
List<GraduationStudentRecord> stdList = gradStatusService.getStudentListBySchoolId(usl);
if(logger.isDebugEnabled()) {
int totalStudents = ObjectUtils.defaultIfNull(stdList.size(), 0);
String listOfStudents = jsonTransformer.marshall(stdList);
logger.debug("*** Student List of {} Acquired {}", totalStudents, listOfStudents);
}
List<ca.bc.gov.educ.api.graduation.model.dto.institute.School> schoolDetails = schoolService.getSchoolDetails(usl);
if (schoolDetails != null && !schoolDetails.isEmpty()) {
ca.bc.gov.educ.api.graduation.model.dto.institute.School schoolDetail = schoolDetails.get(0);
ca.bc.gov.educ.api.graduation.model.dto.institute.School schoolDetail = schoolService.getSchoolDetails(usl);
if (schoolDetail != null) {
logger.debug("*** School Details Acquired {}", schoolDetail.getDisplayName());
if (stdList != null && !stdList.isEmpty()) {
School schoolObj = new School();
Expand All @@ -262,7 +261,7 @@ public Integer createAndStoreSchoolReports(List<String> uniqueSchoolList, String
}
}
} catch (Exception e) {
logger.error("Failed to generate {} report for mincode: {} due to: {}", type, usl, e.getLocalizedMessage());
logger.error("Failed to generate {} report for schoolId: {} due to: {}", type, usl, e.getLocalizedMessage());
}
}
return numberOfReports;
Expand All @@ -283,38 +282,38 @@ private List<GraduationStudentRecord> filterStudentList(List<GraduationStudentRe
}
}

private int processGradRegReport(School schoolObj, List<Student> stdList, String mincode, int numberOfReports) {
Integer studentsCount = countStudentsForAmalgamatedSchoolReport(schoolObj.getMincode());
private int processGradRegReport(School schoolObj, List<Student> stdList, UUID schoolId, int numberOfReports) {
Integer studentsCount = countStudentsForAmalgamatedSchoolReport(schoolId);
if(studentsCount > 0) {
ReportData gradReport = getReportDataObj(schoolObj, stdList);
createAndSaveSchoolReportGradRegReport(gradReport, mincode);
createAndSaveSchoolReportGradRegReport(gradReport, schoolObj.getMincode());
numberOfReports++;
}
return numberOfReports;
}

private int processNonGradRegReport(School schoolObj, List<Student> stdList, String mincode, int numberOfReports) {
Integer studentsCount = countStudentsForAmalgamatedSchoolReport(schoolObj.getMincode());
private int processNonGradRegReport(School schoolObj, List<Student> stdList, UUID schoolId, int numberOfReports) {
Integer studentsCount = countStudentsForAmalgamatedSchoolReport(schoolId);
if(studentsCount > 0) {
ReportData gradReport = getReportDataObj(schoolObj, stdList);
createAndSaveSchoolReportNonGradRegReport(gradReport, mincode);
createAndSaveSchoolReportNonGradRegReport(gradReport, schoolId, schoolObj.getMincode());
numberOfReports++;
}
return numberOfReports;
}

private int processStudentNonGradPrjReport(School schoolObj, List<Student> stdList, String mincode, int numberOfReports) {
Integer studentsCount = countStudentsForAmalgamatedSchoolReport(schoolObj.getMincode());
private int processStudentNonGradPrjReport(School schoolObj, List<Student> stdList, UUID schoolId, int numberOfReports) {
Integer studentsCount = countStudentsForAmalgamatedSchoolReport(schoolId);
if(studentsCount > 0) {
ReportData nongradProjected = getReportDataObj(schoolObj, stdList);
createAndSaveSchoolReportStudentNonGradPrjReport(nongradProjected, mincode);
createAndSaveSchoolReportStudentNonGradPrjReport(nongradProjected, schoolId, schoolObj.getMincode());
numberOfReports++;
}
return numberOfReports;
}

private int countStudentsForAmalgamatedSchoolReport(String mincode) {
return restService.get(String.format(educGraduationApiConstants.getGradStudentCountSchoolReport(), mincode), Integer.class);
private int countStudentsForAmalgamatedSchoolReport(UUID schoolId) {
return restService.get(String.format(educGraduationApiConstants.getGradStudentCountSchoolReport(), schoolId), Integer.class);
}

private ReportData getReportDataObj(School schoolObj, List<Student> stdList) {
Expand Down Expand Up @@ -417,8 +416,9 @@ private byte[] createAndSaveSchoolReportGradRegReport(ReportData data, String mi
byte[] bytesSAR = getSchoolReportGradRegReport(data, mincode);

String encodedPdf = getEncodedPdfFromBytes(bytesSAR);
UUID schoolId = UUID.fromString(data.getSchool().getSchoolId());

SchoolReports requestObj = getSchoolReports(mincode, encodedPdf, GRADREG);
SchoolReports requestObj = getSchoolReports(schoolId, mincode, encodedPdf, GRADREG);

updateSchoolReport(requestObj);

Expand Down Expand Up @@ -451,10 +451,10 @@ private byte[] getSchoolReportNonGradRegReport(ReportData data, String mincode)
}

@Generated
private void createAndSaveSchoolReportNonGradRegReport(ReportData data, String mincode) {
private void createAndSaveSchoolReportNonGradRegReport(ReportData data, UUID schoolId, String mincode) {
byte[] bytesSAR = getSchoolReportNonGradRegReport(data, mincode);
String encodedPdf = getEncodedPdfFromBytes(bytesSAR);
SchoolReports requestObj = getSchoolReports(mincode, encodedPdf, NONGRADREG);
SchoolReports requestObj = getSchoolReports(schoolId, mincode, encodedPdf, NONGRADREG);
updateSchoolReport(requestObj);
}

Expand Down Expand Up @@ -490,10 +490,10 @@ private byte[] getSchoolReportStudentNonGradReport(ReportData data, String minco
accessToken);
}

private void createAndSaveSchoolReportStudentNonGradPrjReport(ReportData data, String mincode) {
private void createAndSaveSchoolReportStudentNonGradPrjReport(ReportData data, UUID schoolId, String mincode) {
byte[] bytesSAR = getSchoolReportStudentNonGradPrjReport(data, mincode);
String encodedPdf = getEncodedPdfFromBytes(bytesSAR);
SchoolReports requestObj = getSchoolReports(mincode, encodedPdf, NONGRADPRJ);
SchoolReports requestObj = getSchoolReports(schoolId, mincode, encodedPdf, NONGRADPRJ);
updateSchoolReport(requestObj);
}

Expand All @@ -505,9 +505,10 @@ private void createAndSaveSchoolReportStudentNonGradReport(ReportData data, Stri
updateSchoolReport(accessToken, requestObj);
} **/

private SchoolReports getSchoolReports(String mincode, String encodedPdf, String nongradreg) {
private SchoolReports getSchoolReports(UUID schoolId, String mincode, String encodedPdf, String nongradreg) {
SchoolReports requestObj = new SchoolReports();
requestObj.setReport(encodedPdf);
requestObj.setSchoolOfRecordId(schoolId);
requestObj.setSchoolOfRecord(mincode);
requestObj.setReportTypeCode(nongradreg);
return requestObj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ private GraduationStatus getGraduationStatus(ca.bc.gov.educ.api.graduation.model
//--> Revert code back to school of record GRAD2-2758
/** gradMessage = StringUtils.replace(gradMessage, schoolOfRecord.getName(), schoolAtGrad.getName());**/
//<--
gradStatus.setSchoolAtGrad(schoolAtGrad.getMincode());
log.debug("Replace school of record {} to school at graduation {}", schoolOfRecord.getName(), schoolAtGrad.getName());
}
gradStatus.setGraduationMessage(gradMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public SchoolService(EducGraduationApiConstants educGraduationApiConstants, REST
this.jsonTransformer = jsonTransformer;
}

public List<ca.bc.gov.educ.api.graduation.model.dto.institute.School> getSchoolDetails(String mincode) {
var response = this.restService.get(String.format(educGraduationApiConstants.getSchoolDetails(),mincode), List.class);
return jsonTransformer.convertValue(response, new TypeReference<>() {});
public ca.bc.gov.educ.api.graduation.model.dto.institute.School getSchoolDetails(UUID schoolId) {
if (schoolId == null) return null;
return this.restService.get(String.format(educGraduationApiConstants.getSchoolDetails(),schoolId), ca.bc.gov.educ.api.graduation.model.dto.institute.School.class);
}

public School getSchoolClob(String schoolId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public class EducGraduationApiConstants {
@Value("${endpoint.grad-trax-api.school-clob-by-school-id.url}")
private String schoolClobBySchoolIdUrl;

@Value("${endpoint.grad-trax-api.search-schools-by-min-code.url}")
@Value("${endpoint.grad-trax-api.school-detail-by-school-id.url}")
private String schoolDetails;

@Value("${endpoint.grad-trax-api.district-by-min-code.url}")
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ endpoint:
url: ${PEN_API}api/v1/student?pen=%s

grad-trax-api:
search-schools-by-min-code:
url: ${GRAD_TRAX_API}api/v2/trax/school/search?mincode=%s
school-detail-by-school-id:
url: ${GRAD_TRAX_API}api/v2/trax/school/%s
school-clob-by-school-id:
url: ${GRAD_TRAX_API}api/v2/trax/school-clob/%s
district-by-min-code:
Expand Down
Loading

0 comments on commit 01e263d

Please sign in to comment.