Skip to content

Commit

Permalink
Merge pull request #528 from bcgov/develop/alex-GRAD2-2315
Browse files Browse the repository at this point in the history
GRAD2-2315
  • Loading branch information
arybakov-cgi authored Jun 6, 2024
2 parents 65d86df + b765767 commit 73cce04
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ public void prepareGraduationStatusData(GraduationStudentRecord obj, GraduationD
}

public GraduationStudentRecord saveStudentGradStatus(String studentID,Long batchId,String accessToken, GraduationStudentRecord toBeSaved, ExceptionMessage exception) {
if(logger.isDebugEnabled()) {
logger.debug("saveStudentGradStatus {}", jsonTransformer.marshall(toBeSaved));
}
try {
String url = educGraduationApiConstants.getUpdateGradStatus();
if(batchId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,20 @@ private List<GraduationStudentRecord> filterStudentList(List<GraduationStudentRe
}

private int processGradRegReport(School schoolObj, List<Student> stdList, String mincode, String accessToken, int numberOfReports) {
ReportData gradReport = getReportDataObj(schoolObj, stdList);
createAndSaveSchoolReportGradRegReport(gradReport, mincode, accessToken);
numberOfReports++;
if(stdList != null && !stdList.isEmpty()) {
ReportData gradReport = getReportDataObj(schoolObj, stdList);
createAndSaveSchoolReportGradRegReport(gradReport, mincode, accessToken);
numberOfReports++;
}
return numberOfReports;
}

private int processNonGradRegReport(School schoolObj, List<Student> stdList, String mincode, int numberOfReports) {
ReportData gradReport = getReportDataObj(schoolObj, stdList);
createAndSaveSchoolReportNonGradRegReport(gradReport, mincode);
numberOfReports++;
if(stdList != null && !stdList.isEmpty()) {
ReportData gradReport = getReportDataObj(schoolObj, stdList);
createAndSaveSchoolReportNonGradRegReport(gradReport, mincode);
numberOfReports++;
}
return numberOfReports;
}

Expand All @@ -330,9 +334,11 @@ private ReportData getReportDataObj(School schoolObj, List<Student> stdList) {
}

private int processStudentNonGradPrjReport(School schoolObj, List<Student> stdList, String mincode, String accessToken, int numberOfReports) {
ReportData nongradProjected = getReportDataObj(schoolObj, stdList);
createAndSaveSchoolReportStudentNonGradPrjReport(nongradProjected, mincode, accessToken);
numberOfReports++;
if(stdList != null && !stdList.isEmpty()) {
ReportData nongradProjected = getReportDataObj(schoolObj, stdList);
createAndSaveSchoolReportStudentNonGradPrjReport(nongradProjected, mincode, accessToken);
numberOfReports++;
}
return numberOfReports;
}

Expand Down Expand Up @@ -421,7 +427,7 @@ private byte[] getSchoolReportGradRegReport(ReportData data, String mincode, Str

}


@Generated
private byte[] createAndSaveSchoolReportGradRegReport(ReportData data, String mincode, String accessToken) {

byte[] bytesSAR = getSchoolReportGradRegReport(data, mincode, accessToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,4 @@ public <T> T post(String url, Object body, Class<T> clazz) {
private String getErrorMessage(String url, String errorMessage) {
return "Service failed to process at url: " + url + " due to: " + errorMessage;
}


}
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 All @@ -323,8 +323,15 @@ private Integer createAndStoreDistrictReports(String reportType, List<ReportGrad
Integer reportsCount = 0;
Map<School, List<School>> districtSchoolsMap = new HashMap<>();
for (ReportGradStudentData reportGradStudentData : reportGradStudentDataList) {
School district = populateDistrictObjectByReportGradStudentData(districtSchoolsMap, reportGradStudentData);
processDistrictSchoolMap(districtSchoolsMap.get(district), reportGradStudentData);
String mincode = StringUtils.isBlank(reportGradStudentData.getMincodeAtGrad()) ? reportGradStudentData.getMincode() : reportGradStudentData.getMincodeAtGrad();
String districtCode = StringUtils.substring(mincode, 0, 3);
String schoolCategoryCode = reportService.getSchoolCategoryCode(accessToken, mincode);
if(!StringUtils.equalsAnyIgnoreCase(schoolCategoryCode, "02")) {
School district = populateDistrictObjectByReportGradStudentData(districtSchoolsMap, reportGradStudentData);
processDistrictSchoolMap(districtSchoolsMap.get(district), reportGradStudentData);
} else {
logger.debug("Skip {} independent school {} for district {}", schoolCategoryCode, mincode, districtCode);
}
}
for (var entry : districtSchoolsMap.entrySet()) {
School district = entry.getKey();
Expand All @@ -343,25 +350,22 @@ 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);
}

@Generated
private byte[] getSchoolYearEndReportJasper(ReportRequest reportRequest, String accessToken) {
if(logger.isDebugEnabled()) {
logger.debug("getSchoolYearEndReportJasper(ReportRequest): {}", jsonTransformer.marshall(reportRequest));
}
return webClient.post().uri(educGraduationApiConstants.getSchoolDistributionYearEnd())
.headers(h -> {
h.setBearerAuth(accessToken);
Expand All @@ -372,9 +376,6 @@ private byte[] getSchoolYearEndReportJasper(ReportRequest reportRequest, String

@Generated
private byte[] getSchoolLabelsReportJasper(ReportRequest reportRequest, String accessToken) {
if(logger.isDebugEnabled()) {
logger.debug("getSchoolLabelsReportJasper(ReportRequest): {}", jsonTransformer.marshall(reportRequest));
}
return webClient.post().uri(educGraduationApiConstants.getSchoolLabels())
.headers(h -> {
h.setBearerAuth(accessToken);
Expand All @@ -385,9 +386,6 @@ private byte[] getSchoolLabelsReportJasper(ReportRequest reportRequest, String a

@Generated
private byte[] getDistrictYearEndReportJasper(ReportRequest reportRequest, String accessToken) {
if(logger.isDebugEnabled()) {
logger.debug("getDistrictYearEndReportJasper(ReportRequest): {}", jsonTransformer.marshall(reportRequest));
}
return webClient.post().uri(educGraduationApiConstants.getDistrictDistributionYearEnd())
.headers(h -> {
h.setBearerAuth(accessToken);
Expand All @@ -398,9 +396,6 @@ private byte[] getDistrictYearEndReportJasper(ReportRequest reportRequest, Strin

@Generated
private byte[] getDistrictYearEndNonGradReportJasper(ReportRequest reportRequest, String accessToken) {
if(logger.isDebugEnabled()) {
logger.debug("getDistrictYearEndNonGradReportJasper(ReportRequest): {}", jsonTransformer.marshall(reportRequest));
}
return webClient.post().uri(educGraduationApiConstants.getDistrictDistributionYearEndNonGrad())
.headers(h -> {
h.setBearerAuth(accessToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,19 @@
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class GradLocalDateTimeSerializer extends JsonSerializer<LocalDateTime> {

private static final Logger logger = LoggerFactory.getLogger(GradLocalDateTimeSerializer.class);

@Override
public void serialize(LocalDateTime localDate, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
String fieldName = jsonGenerator.getOutputContext().getCurrentName();
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
if(localDate != null) {
String value = localDate.format(formatter);
logger.debug("Serialize LocalDateTime of {} to value {}", fieldName, value);
jsonGenerator.writeString(value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
import org.junit.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
Expand Down Expand Up @@ -2040,7 +2038,11 @@ public void testCreateAndStoreSchoolReports() {
Mockito.when(gradStatusService.getStudentListByMinCode(mincode, "accessToken")).thenReturn(sList);
Mockito.when(schoolService.getTraxSchoolDetails(mincode, "accessToken", exception)).thenReturn(sTrax);
int numberOfRecord = graduationService.createAndStoreSchoolReports(uniqueList,"REGALG","accessToken");
assertEquals(2,numberOfRecord);
assertEquals(1,numberOfRecord);

Mockito.when(gradStatusService.getStudentListByMinCode(mincode, "accessToken")).thenReturn(List.of());
numberOfRecord = graduationService.createAndStoreSchoolReports(uniqueList,"REGALG","accessToken");
assertEquals(0,numberOfRecord);
}

@Test
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 73cce04

Please sign in to comment.