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-2822: School Report Regeneration Process - Backend Changes #526

Merged
merged 7 commits into from
Sep 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,9 @@ public ResponseEntity<BatchJobResponse> launchRegenerateSchoolReportsBatch(@Requ

try {
String studentSearchData = jsonTransformer.marshall(searchRequest);
builder.addString(SEARCH_REQUEST, studentSearchData);
if(searchRequest != null) {
builder.addString(SEARCH_REQUEST, jsonTransformer.marshall(searchRequest));
}
response.setJobParameters(studentSearchData);
JobExecution jobExecution = asyncJobLauncher.run(jobRegistry.getJob(REGENERATE_SCHOOL_REPORTS_BATCH_JOB), builder.toJobParameters());
response.setBatchId(jobExecution.getId());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ca.bc.gov.educ.api.batchgraduation.model;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.UUID;

@Data
@EqualsAndHashCode(callSuper = false)
public class SchoolReport extends BaseModel {

private UUID id;
private String report;
private String reportTypeCode;
private String reportTypeLabel;
private String schoolOfRecord;
private String schoolOfRecordName;
private String schoolCategory;

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.beans.factory.annotation.Value;

import java.util.*;
import java.util.stream.Collectors;

import static ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants.SEARCH_REQUEST;

Expand Down Expand Up @@ -57,26 +58,44 @@ public Map<String, ExecutionContext> partition(int gridSize) {
Long schoolReportsCount = 0L;

List<String> finalSchoolDistricts = new ArrayList<>();
List<SchoolReport> schoolReportsLite = new ArrayList<>();

for (String schoolOfRecord : schoolDistricts) {
if(processAllReports) {
if (reportTypes != null && !reportTypes.isEmpty()) {
if ("NONGRADPRJ".compareToIgnoreCase(reportTypes.get(0)) == 0) {
schoolReportsCount += restUtils.getTotalReportsForProcessing(List.of(schoolOfRecord), "NONGRADPRJ", summaryDTO);
schoolReportsLite = restUtils.getSchoolReportsLiteByReportType("NONGRADPRJ", summaryDTO);
} else {
schoolReportsCount += restUtils.getTotalReportsForProcessing(List.of(schoolOfRecord), "GRADREG", summaryDTO);
schoolReportsLite = restUtils.getSchoolReportsLiteByReportType( "GRADREG", summaryDTO);
}
if (schoolReportsCount == 0) {
//finalSchoolDistricts.remove(schoolOfRecord);
log.debug("Skip School : {}", schoolOfRecord);
}
else {
finalSchoolDistricts.add(schoolOfRecord);
School school = new School(schoolOfRecord);
school.setNumberOfSchoolReports(schoolReportsCount);
summaryDTO.getSchools().add(school);
totalSchoolReportsCount += schoolReportsCount;
}

if (schoolReportsLite != null && !schoolReportsLite.isEmpty()) {
finalSchoolDistricts = schoolReportsLite.stream().map(SchoolReport::getSchoolOfRecord)
.collect(Collectors.toList());
schoolReportsCount = (long)finalSchoolDistricts.size();
}

School school = new School("ALL_SCHOOLS");
school.setNumberOfSchoolReports(schoolReportsCount);
summaryDTO.getSchools().add(school);
totalSchoolReportsCount += finalSchoolDistricts.size();
} else {
for (String schoolOfRecord : schoolDistricts) {
if (reportTypes != null && !reportTypes.isEmpty()) {
if ("NONGRADPRJ".compareToIgnoreCase(reportTypes.get(0)) == 0) {
schoolReportsCount += restUtils.getTotalReportsForProcessing(List.of(schoolOfRecord), "NONGRADPRJ", summaryDTO);
} else {
schoolReportsCount += restUtils.getTotalReportsForProcessing(List.of(schoolOfRecord), "GRADREG", summaryDTO);
}
if (schoolReportsCount > 0) {
finalSchoolDistricts.add(schoolOfRecord);
School school = new School(schoolOfRecord);
school.setNumberOfSchoolReports(schoolReportsCount);
summaryDTO.getSchools().add(school);
totalSchoolReportsCount += schoolReportsCount;
}
schoolReportsCount = 0L;
}
schoolReportsCount = 0L;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,29 @@ public Long getTotalReportsForProcessing(List<String> finalSchoolDistricts, Stri
return reportsCount;
}

public List<SchoolReport> getSchoolReportsLiteByReportType(String reportType, SchoolReportsRegenSummaryDTO summaryDTO) {

UUID correlationID = UUID.randomUUID();
final ParameterizedTypeReference<List<SchoolReport>> responseType = new ParameterizedTypeReference<>() {};
List<SchoolReport> schoolReportsLite = new ArrayList<>();
try {
String accessToken = getAccessToken();
schoolReportsLite = this.webClient.get()
.uri(String.format(constants.getSchoolReportsLiteByReportTypeUrl(), reportType))
.headers(h -> { h.setBearerAuth(accessToken); h.set(EducGradBatchGraduationApiConstants.CORRELATION_ID, correlationID.toString()); })
.retrieve().bodyToMono(responseType).block();
} catch(Exception e) {
LOGGER.error("Unable to retrieve school reports data for ALL", e);
summaryDTO.getErrors().add(new ProcessError(null,"Unable to retrieve schools reports data for ALL", e.getLocalizedMessage()));
summaryDTO.setException(e.getLocalizedMessage());
}
if(LOGGER.isDebugEnabled()) {
LOGGER.debug("Total {} of {} reports available",
schoolReportsLite == null || schoolReportsLite.isEmpty() ? 0 : schoolReportsLite.size(), reportType);
}
return schoolReportsLite;
}

public List<UUID> getReportStudentIDsByStudentIDsAndReportType(List<String> finalSchoolDistricts, String reportType, Integer rowCount, DistributionSummaryDTO summaryDTO) {
List<UUID> result = new ArrayList<>();
UUID correlationID = UUID.randomUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ public class EducGradBatchGraduationApiConstants {
@Value("${endpoint.grad-graduation-report-api.get-certificate-types.url}")
private String certificateTypes;

@Value("${endpoint.grad-graduation-report-api.get-school-reports-lite-by-report-type.url}")
private String schoolReportsLiteByReportTypeUrl;

@Value("${endpoint.grad-student-api.update-student-record}")
private String updateStudentRecord;

Expand Down
2 changes: 2 additions & 0 deletions api/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ endpoint:
url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/districtdataearly
get-certificate-types:
url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/certificatetype/%s
get-school-reports-lite-by-report-type:
url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/schoolreport/type/%s
update-school-report:
url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/updateschoolreport?mincode=%s&reportTypeCode=%s
update-student-report:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -929,13 +929,61 @@ public void whenCreateAndStoreSchoolReports_WithParams_ThenThrowException() {
when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock);
when(this.requestBodyMock.contentType(any())).thenReturn(this.requestBodyMock);
when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
when(this.requestHeadersMock.retrieve()).thenThrow(new RuntimeException(""));
when(this.responseMock.bodyToMono(Integer.class)).thenThrow(Exception.class);
when(LOGGER.isDebugEnabled()).thenReturn(true);

var result = this.restUtils.createAndStoreSchoolReports("12345", type, new SchoolReportsRegenSummaryDTO());
}

@Test
public void testGetSchoolReportsLiteByReportType() {

UUID uuid = UUID.randomUUID();
SchoolReport sr = new SchoolReport();
sr.setId(uuid);
sr.setReportTypeCode("GRADREG");
final ParameterizedTypeReference<List<SchoolReport>> responseType = new ParameterizedTypeReference<>() {};
List<SchoolReport> schoolReportsLite = new ArrayList<>();
schoolReportsLite.add(sr);

mockTokenResponseObject();

when(this.webClient.get()).thenReturn(this.requestHeadersUriMock);
when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolReportsLiteByReportTypeUrl(), "GRADREG"))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
when(this.responseMock.bodyToMono(responseType)).thenReturn(Mono.just(schoolReportsLite));
when(this.responseMock.onStatus(any(), any())).thenReturn(this.responseMock);
when(LOGGER.isDebugEnabled()).thenReturn(true);

val result = this.restUtils.getSchoolReportsLiteByReportType("GRADREG", new SchoolReportsRegenSummaryDTO());
assertThat(result).hasSize(1);
}

@Test(expected = Exception.class)
public void whenGetSchoolReportsLiteByReportType_ThenThrowException() {
UUID uuid = UUID.randomUUID();
SchoolReport sr = new SchoolReport();
sr.setId(uuid);
sr.setReportTypeCode("GRADREG");
final ParameterizedTypeReference<List<SchoolReport>> responseType = new ParameterizedTypeReference<>() {};
List<SchoolReport> schoolReportsLite = new ArrayList<>();
schoolReportsLite.add(sr);

mockTokenResponseObject();

when(this.webClient.get()).thenReturn(this.requestHeadersUriMock);
when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolReportsLiteByReportTypeUrl(), "GRADREG"))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.retrieve()).thenThrow(new RuntimeException(""));
when(this.responseMock.bodyToMono(responseType)).thenThrow(Exception.class);
when(this.responseMock.onStatus(any(), any())).thenReturn(this.responseMock);
when(LOGGER.isDebugEnabled()).thenReturn(true);

val result = this.restUtils.getSchoolReportsLiteByReportType("GRADREG", new SchoolReportsRegenSummaryDTO());
}

@Test
public void testRunGradAlgorithm() {
final String studentID = UUID.randomUUID().toString();
Expand Down
2 changes: 2 additions & 0 deletions api/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ endpoint:
url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/districtdataearly
get-certificate-types:
url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/certificatetype/%s
get-school-reports-lite-by-report-type:
url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/schoolreport/type/%s
update-school-report:
url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/updateschoolreports?mincode=%s&reportTypeCode=%s
update-student-report:
Expand Down
Loading