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

Develop/alex grad2 2377 #253

Merged
merged 10 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ca.bc.gov.educ.api.grad.report.model.transformer.*;
import ca.bc.gov.educ.api.grad.report.repository.*;
import ca.bc.gov.educ.api.grad.report.util.EducGradReportApiConstants;
import ca.bc.gov.educ.api.grad.report.util.Generated;
import ca.bc.gov.educ.api.grad.report.util.ThreadLocalStateUtil;
import jakarta.transaction.Transactional;
import org.apache.commons.codec.binary.Base64;
Expand Down Expand Up @@ -357,6 +358,7 @@ public List<SchoolReports> getAllSchoolReportListByReportType(String reportType,
return reportList;
}

@Generated
private void populateSchoolRepors(List<SchoolReports> reportList) {
reportList.forEach(rep -> {
String accessToken = fetchAccessToken();
Expand Down Expand Up @@ -606,6 +608,7 @@ public boolean deleteSchoolReports(String minCode, String reportTypeCode) {
return false;
}

@Generated
private School getSchool(String minCode, String accessToken) {
try {
return webClient.get()
Expand All @@ -623,6 +626,7 @@ private School getSchool(String minCode, String accessToken) {
}
}

@Generated
private District getDistrict(String districtCode, String accessToken) {
try {
return webClient.get()
Expand Down Expand Up @@ -696,6 +700,7 @@ public List<ReportGradStudentData> getSchoolReportGradStudentData() {
return processReportGradStudentDataList(students, new ArrayList<>());
}

@Generated
private List<ReportGradStudentData> processReportGradStudentDataList(Page<SchoolReportEntity> students, List<String> schools) {
List<ReportGradStudentData> result = new ArrayList<>();
long startTime = System.currentTimeMillis();
Expand All @@ -719,18 +724,21 @@ private List<ReportGradStudentData> processReportGradStudentDataList(Page<School
return result;
}

@Generated
private synchronized List<ReportGradStudentData> getNextPageStudentsFromGradStudentApi(Page<SchoolReportEntity> students, List<String> schools) {
List<ReportGradStudentData> result = new ArrayList<>();
List<UUID> studentGuidsInBatch = students.getContent().stream().map(SchoolReportEntity::getGraduationStudentRecordId).distinct().toList();
List<ReportGradStudentData> studentsInBatch = getReportGradStudentData(fetchAccessToken(), studentGuidsInBatch);
if(studentsInBatch != null && !schools.isEmpty()) {
boolean isDistrictSchool = schools.get(0).length() == 3;
if(isDistrictSchool) {
studentsInBatch.removeIf(st -> (!schools.contains(StringUtils.substring(st.getMincode(), 0, 3))));
studentsInBatch.removeIf(st -> ((StringUtils.isBlank(st.getMincodeAtGrad()) || StringUtils.equals(st.getMincode(), st.getMincodeAtGrad())) && !schools.contains(StringUtils.substring(st.getMincode(), 0, 3))));
studentsInBatch.removeIf(st -> ((StringUtils.isNotBlank(st.getMincodeAtGrad()) && !StringUtils.equals(st.getMincode(), st.getMincodeAtGrad())) && !schools.contains(StringUtils.substring(st.getMincodeAtGrad(), 0, 3))));
}
boolean isSchoolSchool = schools.get(0).length() > 3;
if(isSchoolSchool) {
studentsInBatch.removeIf(st -> (!schools.contains(StringUtils.trimToEmpty(st.getMincode()))));
studentsInBatch.removeIf(st -> ((StringUtils.isBlank(st.getMincodeAtGrad()) || StringUtils.equals(st.getMincode(), st.getMincodeAtGrad())) && !schools.contains(StringUtils.trimToEmpty(st.getMincode()))));
studentsInBatch.removeIf(st -> ((StringUtils.isNotBlank(st.getMincodeAtGrad()) && !StringUtils.equals(st.getMincode(), st.getMincodeAtGrad())) && !schools.contains(StringUtils.trimToEmpty(st.getMincodeAtGrad()))));
}
}
for(SchoolReportEntity e: students.getContent()) {
Expand All @@ -756,6 +764,7 @@ private synchronized List<ReportGradStudentData> getNextPageStudentsFromGradStud
return result;
}

@Generated
private synchronized ReportGradStudentData getReportGradStudentDataByGraduationStudentRecordIdFromList(UUID id, List<ReportGradStudentData> studentsInBatch) {
for(ReportGradStudentData s: studentsInBatch) {
if(s.getGraduationStudentRecordId().equals(id)) {
Expand All @@ -765,6 +774,7 @@ private synchronized ReportGradStudentData getReportGradStudentDataByGraduationS
return null;
}

@Generated
private synchronized List<ReportGradStudentData> getReportGradStudentData(String accessToken, List<UUID> studentGuids) {
final ParameterizedTypeReference<List<ReportGradStudentData>> responseType = new ParameterizedTypeReference<>() {
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ca.bc.gov.educ.api.grad.report.util;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Documented
@Retention(RUNTIME)
@Target({TYPE, METHOD, CONSTRUCTOR})
public @interface Generated {
}
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,7 @@ public void testGetSchoolReportGradStudentData() {
ReportGradStudentData reportGradStudentData = new ReportGradStudentData();
reportGradStudentData.setGraduationStudentRecordId(studentId);
reportGradStudentData.setTranscriptTypeCode("BC2018-IND");
reportGradStudentData.setMincode("12345678");

GradCertificateTypes certificateTypes = new GradCertificateTypes();
certificateTypes.setCode("E");
Expand All @@ -1485,6 +1486,8 @@ public void testGetSchoolReportGradStudentData() {
reportGradStudentData = new ReportGradStudentData();
reportGradStudentData.setGraduationStudentRecordId(studentId);
reportGradStudentData.setTranscriptTypeCode("BC2004-IND");
reportGradStudentData.setMincode("12345678");
reportGradStudentData.setMincodeAtGrad("09876543");

reportGradStudentDataList.add(reportGradStudentData);

Expand Down Expand Up @@ -1673,6 +1676,224 @@ public Page map(Function converter) {
assertThat(result).isNotEmpty();
}

@Test
@SneakyThrows
public void testGetSchoolReportGradStudentDataForSchools() {
UUID studentId = UUID.randomUUID();

String mincode = "12345678";

List<ReportGradStudentData> reportGradStudentDataList = new ArrayList<>();
ReportGradStudentData reportGradStudentData = new ReportGradStudentData();
reportGradStudentData.setGraduationStudentRecordId(studentId);
reportGradStudentData.setTranscriptTypeCode("BC2018-IND");
reportGradStudentData.setMincode(mincode);

GradCertificateTypes certificateTypes = new GradCertificateTypes();
certificateTypes.setCode("E");
certificateTypes.setDescription("Dogwood");
reportGradStudentData.setCertificateTypes(List.of(certificateTypes));

reportGradStudentDataList.add(reportGradStudentData);

reportGradStudentData = new ReportGradStudentData();
reportGradStudentData.setGraduationStudentRecordId(studentId);

reportGradStudentDataList.add(reportGradStudentData);

reportGradStudentData = new ReportGradStudentData();
reportGradStudentData.setGraduationStudentRecordId(studentId);
reportGradStudentData.setTranscriptTypeCode("BC2004-IND");
reportGradStudentData.setMincode(mincode);
reportGradStudentData.setMincodeAtGrad("09876543");

reportGradStudentDataList.add(reportGradStudentData);

SchoolReportEntity schoolReportEntity = new SchoolReportEntity();
schoolReportEntity.setSchoolReportEntityId(new SchoolReportEntityId(studentId, "EBDR", "E"));

when(schoolReportYearEndRepository.findStudentForSchoolYearEndReport(PageRequest.of(0, PAGE_SIZE))).thenReturn(new Page() {

@Override
public Iterator<SchoolReportEntity> iterator() {
return getContent().listIterator();
}

@Override
public int getNumber() {
return 1;
}

@Override
public int getSize() {
return 1;
}

@Override
public int getNumberOfElements() {
return 1;
}

@Override
public List<SchoolReportEntity> getContent() {
return List.of(schoolReportEntity);
}

@Override
public boolean hasContent() {
return !getContent().isEmpty();
}

@Override
public Sort getSort() {
return null;
}

@Override
public boolean isFirst() {
return false;
}

@Override
public boolean isLast() {
return false;
}

@Override
public boolean hasNext() {
return false;
}

@Override
public boolean hasPrevious() {
return false;
}

@Override
public Pageable nextPageable() {
return null;
}

@Override
public Pageable previousPageable() {
return null;
}

@Override
public int getTotalPages() {
return getContent().size();
}

@Override
public long getTotalElements() {
return getContent().size();
}

@Override
public Page map(Function converter) {
return null;
}
});

when(schoolReportMonthlyRepository.findStudentForSchoolReport(PageRequest.of(0, PAGE_SIZE))).thenReturn(new Page() {

@Override
public Iterator<SchoolReportEntity> iterator() {
return getContent().listIterator();
}

@Override
public int getNumber() {
return 1;
}

@Override
public int getSize() {
return 1;
}

@Override
public int getNumberOfElements() {
return 1;
}

@Override
public List<SchoolReportEntity> getContent() {
return List.of(schoolReportEntity);
}

@Override
public boolean hasContent() {
return !getContent().isEmpty();
}

@Override
public Sort getSort() {
return null;
}

@Override
public boolean isFirst() {
return false;
}

@Override
public boolean isLast() {
return false;
}

@Override
public boolean hasNext() {
return false;
}

@Override
public boolean hasPrevious() {
return false;
}

@Override
public Pageable nextPageable() {
return null;
}

@Override
public Pageable previousPageable() {
return null;
}

@Override
public int getTotalPages() {
return getContent().size();
}

@Override
public long getTotalElements() {
return getContent().size();
}

@Override
public Page map(Function converter) {
return null;
}
});

when(this.webClient.post()).thenReturn(this.requestBodyUriMock);
when(this.requestBodyUriMock.uri(constants.getStudentsForSchoolDistribution())).thenReturn(this.requestBodyUriMock);
when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock);
when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
when(this.responseMock.bodyToMono(new ParameterizedTypeReference<List<ReportGradStudentData>>() {})).thenReturn(Mono.just(reportGradStudentDataList));

mockAccessToken();

var result = commonService.getSchoolYearEndReportGradStudentData(List.of(mincode));
assertThat(result).isNotEmpty();

result = commonService.getSchoolReportGradStudentData();
assertThat(result).isNotEmpty();
}

private void mockAccessToken() {
final TokenResponse tokenObject = new TokenResponse();
tokenObject.setAccess_token(MOCK_TOKEN);
Expand Down
Loading