Skip to content

Commit

Permalink
GRAD2-2315
Browse files Browse the repository at this point in the history
HD-21698 (GRAD) Distribution reports in the YE Distribution are randomly picking up Independent Schools
  • Loading branch information
arybakov-cgi committed Jun 5, 2024
1 parent 07ec90f commit b765767
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import ca.bc.gov.educ.api.graduation.exception.ServiceException;
import ca.bc.gov.educ.api.graduation.util.EducGraduationApiConstants;
import ca.bc.gov.educ.api.graduation.util.ThreadLocalStateUtil;
import ca.bc.gov.educ.api.graduation.util.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
Expand All @@ -21,16 +20,14 @@ public class RESTService {

private final WebClient webClient;
private final WebClient graduationServiceWebClient;
private final TokenUtils tokenUtils;

private static final String ERROR_5xx = "5xx error.";
private static final String SERVICE_FAILED_ERROR = "Service failed to process after max retries.";

@Autowired
public RESTService(@Qualifier("graduationClient") WebClient graduationServiceWebClient, WebClient webClient, TokenUtils tokenUtils) {
public RESTService(@Qualifier("graduationClient") WebClient graduationServiceWebClient, WebClient webClient) {
this.webClient = webClient;
this.graduationServiceWebClient = graduationServiceWebClient;
this.tokenUtils = tokenUtils;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public Integer createAndStoreSchoolLabelsReportsFromSchools(String reportType, L
}
if (pdfs == null) {
String schoolLabelMinCode = (schools != null && schools.size() == 1) ? schools.get(0).getMincode() : "000000000";
saveDistrictOrSchoolOrLabelsReport(accessToken, schoolLabelMinCode, reportType, reportAsBytes);
saveDistrictOrSchoolOrLabelsReport(schoolLabelMinCode, reportType, reportAsBytes);
}
reportsCount++;
return reportsCount;
Expand Down Expand Up @@ -284,7 +284,7 @@ private Integer createAndStoreSchoolReports(String reportType, List<ReportGradSt
pdfs.add(is);
}
if (pdfs == null) {
saveDistrictOrSchoolOrLabelsReport(accessToken, reportRequest.getData().getSchool().getMincode(), reportType, reportAsBytes);
saveDistrictOrSchoolOrLabelsReport(reportRequest.getData().getSchool().getMincode(), reportType, reportAsBytes);
}
reportsCount++;
}
Expand All @@ -310,7 +310,7 @@ private Integer createAndStoreSchoolReports(String reportType, List<ReportGradSt
pdfs.add(is);
}
if (pdfs == null) {
saveDistrictOrSchoolOrLabelsReport(accessToken, reportRequest.getData().getSchool().getMincode(), reportType, reportAsBytes);
saveDistrictOrSchoolOrLabelsReport(reportRequest.getData().getSchool().getMincode(), reportType, reportAsBytes);
}
reportsCount++;
}
Expand Down Expand Up @@ -350,15 +350,15 @@ private Integer createAndStoreDistrictReports(String reportType, List<ReportGrad
pdfs.add(is);
}
if (pdfs == null) {
saveDistrictOrSchoolOrLabelsReport(accessToken, reportRequest.getData().getSchool().getMincode(), reportType, reportAsBytes);
saveDistrictOrSchoolOrLabelsReport(reportRequest.getData().getSchool().getMincode(), reportType, reportAsBytes);
}
reportsCount++;
}
return reportsCount;
}

@Generated
private void saveDistrictOrSchoolOrLabelsReport(String accessToken, String mincode, String reportType, byte[] reportAsBytes) {
private void saveDistrictOrSchoolOrLabelsReport(String mincode, String reportType, byte[] reportAsBytes) {
String encodedPdf = getEncodedPdfFromBytes(reportAsBytes);
SchoolReports schoolReports = getSchoolReports(mincode, encodedPdf, reportType);
updateSchoolReport(schoolReports);
Expand Down Expand Up @@ -609,11 +609,9 @@ private Student populateStudentObjectByReportGradStudentData(ReportGradStudentDa
}

private void updateSchoolReport(SchoolReports requestObj) {
String accessToken = getAccessToken();
this.restService.post(educGraduationApiConstants.getUpdateSchoolReport(),
requestObj,
SchoolReports.class,
accessToken);
SchoolReports.class);
}

private String getEncodedPdfFromBytes(byte[] bytesSAR) {
Expand All @@ -633,10 +631,6 @@ private Pair<String, Long> getAccessToken(String accessToken) {
return tokenUtils.getAccessToken(accessToken);
}

private String getAccessToken() {
return tokenUtils.getAccessToken();
}

@SneakyThrows
private byte[] mergeDocuments(List<InputStream> sources) {
ByteArrayOutputStream tempOutStream = new ByteArrayOutputStream();
Expand Down
8 changes: 5 additions & 3 deletions api/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ spring:
#Logging properties
logging:
file:
max-history: 1
clean-history-on-start: true
max-size: 20MB
name: /logs/app.log
#pattern:
# file: %d | [${HOSTNAME}] | %clr(%5p) | [%t] | %logger{36}:%L | %msg%n
Expand All @@ -60,6 +57,11 @@ logging:
boot:
autoconfigure:
logging: INFO
logback:
rollingpolicy:
max-history: 1
clean-history-on-start: true
max-file-size: 20MB

authorization:
user: batch-api
Expand Down

0 comments on commit b765767

Please sign in to comment.