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

GRA2-2951: task is complete. #698

Merged
merged 2 commits into from
Nov 6, 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 @@ -362,18 +362,14 @@ public GraduationStudentRecordSearchResult searchGraduationStudentRecords(final
}

if(searchRequest.getDistricts() != null && !searchRequest.getDistricts().isEmpty()) {
List<CommonSchool> schools = new ArrayList<>(getSchools(accessToken));
for(Iterator<CommonSchool> it = schools.iterator(); it.hasNext();) {
CommonSchool school = it.next();
if(!searchRequest.getDistricts().contains(school.getDistNo())) {
List<School> schools = new ArrayList<>(getSchoolsByDistricts(searchRequest.getDistricts(), accessToken));
for(Iterator<School> it = schools.iterator(); it.hasNext();) {
School school = it.next();
List<String> schoolCategoryCodes = searchRequest.getSchoolCategoryCodes().stream().filter(StringUtils::isNotBlank).toList();
if(!schoolCategoryCodes.isEmpty() && !schoolCategoryCodes.contains(school.getSchoolCategoryCode())) {
it.remove();
} else {
List<String> schoolCategoryCodes = searchRequest.getSchoolCategoryCodes().stream().filter(StringUtils::isNotBlank).toList();
if(!schoolCategoryCodes.isEmpty() && !schoolCategoryCodes.contains(school.getSchoolCategoryCode())) {
it.remove();
} else {
searchRequest.getSchoolOfRecords().add(school.getDistNo() + school.getSchlNo());
}
searchRequest.getSchoolOfRecords().add(school.getMinCode());
}
}
}
Expand Down Expand Up @@ -521,13 +517,22 @@ private List<GradStudentCertificates> getGradStudentCertificates(String studentI
}).block();
}

public List<CommonSchool> getSchools(String accessToken) {
return webClient.get().uri((constants.getSchoolsSchoolApiUrl()))
public List<School> getSchoolsByDistricts(List<String> districts, String accessToken) {
List<School> results = new ArrayList<>();
for (String distNo : districts) {
results.addAll(getSchoolsByDistrictNumber(distNo, accessToken));
}
return results;
}

public List<School> getSchoolsByDistrictNumber(String distNo, String accessToken) {
return webClient.get()
.uri(String.format(constants.getSchoolsByDistrictNumberUrl(), distNo))
.headers(h -> {
h.setBearerAuth(accessToken);
h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID());
})
.retrieve().bodyToMono(new ParameterizedTypeReference<List<CommonSchool>>() {
.retrieve().bodyToMono(new ParameterizedTypeReference<List<School>>() {
}).block();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,8 @@ public class EducGradStudentApiConstants {
@Value("${endpoint.grad-graduation-report-api.archive-student-achievement.url}")
private String archiveStudentAchievements;

@Value("${endpoint.grad-trax-api.commonschool-by-mincode.url}")
private String schoolByMincodeSchoolApiUrl;

@Value("${endpoint.grad-trax-api.all-commonschools.url}")
private String schoolsSchoolApiUrl;
@Value("${endpoint.grad-trax-api.all-schools-by-district.url}")
private String schoolsByDistrictNumberUrl;

// Splunk LogHelper Enabled
@Value("${splunk.log-helper.enabled}")
Expand Down
6 changes: 2 additions & 4 deletions api/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,12 @@ resilience4j.retry:
#Endpoint properties
endpoint:
grad-trax-api:
all-commonschools:
url: ${GRAD_TRAX_API}api/v1/trax/school/common
all-schools-by-district:
url: ${GRAD_TRAX_API}api/v2/trax/schools-by-district/%s
school-by-min-code:
url: ${GRAD_TRAX_API}api/v2/trax/school-clob/%s
district-by-district-code:
url: ${GRAD_TRAX_API}api/v2/trax/district/%s
commonschool-by-mincode:
url: ${GRAD_TRAX_API}api/v1/trax/school/common/%s

grad-program-api:
optional_program_name_by_optional_program_id:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,17 @@ public void testStudentDemographics() {
commonSchool.setSchoolName(schoolName);
commonSchool.setSchoolCategoryCode("02");

School school = new School();
school.setMinCode(mincode);
school.setSchoolName(schoolName);
school.setSchoolCategoryCode("02");
school.setSchoolCategoryCodeInstitute("INDEPEN");

when(this.webClient.get()).thenReturn(this.requestHeadersUriMock);
when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolByMincodeSchoolApiUrl(),mincode))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolByMincodeUrl(),mincode))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
when(this.responseMock.bodyToMono(CommonSchool.class)).thenReturn(Mono.just(commonSchool));
when(this.responseMock.bodyToMono(School.class)).thenReturn(Mono.just(school));

GradStudentCertificates certificate = new GradStudentCertificates();
certificate.setStudentID(studentID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1655,11 +1655,8 @@ public void testSearchGraduationStudentRecords() {
School school = new School();
school.setMinCode(schoolOfRecord);
school.setSchoolName("Test School");

CommonSchool commonSchool = new CommonSchool();
commonSchool.setSchlNo(schoolOfRecord);
commonSchool.setSchoolName(school.getSchoolName());
commonSchool.setSchoolCategoryCode("02");
school.setSchoolCategoryCode("02");
school.setSchoolCategoryCodeInstitute("INDEPEN");

List<String> districts = new ArrayList<>();
districts.add(distCode);
Expand Down Expand Up @@ -1724,20 +1721,14 @@ public void testSearchGraduationStudentRecords() {
when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
when(this.responseMock.bodyToMono(School.class)).thenReturn(Mono.just(school));

when(this.webClient.get()).thenReturn(this.requestHeadersUriMock);
when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolByMincodeSchoolApiUrl(),schoolOfRecord))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
when(this.responseMock.bodyToMono(CommonSchool.class)).thenReturn(Mono.just(commonSchool));

final ParameterizedTypeReference<List<CommonSchool>> commonSchoolsType = new ParameterizedTypeReference<>() {
final ParameterizedTypeReference<List<School>> schoolsType = new ParameterizedTypeReference<>() {
};

when(this.webClient.get()).thenReturn(this.requestHeadersUriMock);
when(this.requestHeadersUriMock.uri(constants.getSchoolsSchoolApiUrl())).thenReturn(this.requestHeadersMock);
when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolsByDistrictNumberUrl(),distCode))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
when(this.responseMock.bodyToMono(commonSchoolsType)).thenReturn(Mono.just(List.of(commonSchool)));
when(this.responseMock.bodyToMono(schoolsType)).thenReturn(Mono.just(List.of(school)));

when(this.webClient.get()).thenReturn(this.requestHeadersUriMock);
when(this.requestHeadersUriMock.uri(String.format(constants.getDistrictByDistrictCodeUrl(),distCode))).thenReturn(this.requestHeadersMock);
Expand Down Expand Up @@ -1804,11 +1795,8 @@ public void testSearchGraduationStudentRecords_validateTrue() {
School school = new School();
school.setMinCode(schoolOfRecord);
school.setSchoolName("Test School");

CommonSchool commonSchool = new CommonSchool();
commonSchool.setSchlNo(schoolOfRecord);
commonSchool.setSchoolName(school.getSchoolName());
commonSchool.setSchoolCategoryCode("02");
school.setSchoolCategoryCode("02");
school.setSchoolCategoryCodeInstitute("INDEPEN");

List<String> districts = new ArrayList<>();
districts.add(distCode);
Expand Down Expand Up @@ -1873,20 +1861,14 @@ public void testSearchGraduationStudentRecords_validateTrue() {
when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
when(this.responseMock.bodyToMono(School.class)).thenReturn(Mono.just(school));

when(this.webClient.get()).thenReturn(this.requestHeadersUriMock);
when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolByMincodeSchoolApiUrl(),schoolOfRecord))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
when(this.responseMock.bodyToMono(CommonSchool.class)).thenReturn(Mono.just(commonSchool));

final ParameterizedTypeReference<List<CommonSchool>> commonSchoolsType = new ParameterizedTypeReference<>() {
final ParameterizedTypeReference<List<School>> schoolsType = new ParameterizedTypeReference<>() {
};

when(this.webClient.get()).thenReturn(this.requestHeadersUriMock);
when(this.requestHeadersUriMock.uri(constants.getSchoolsSchoolApiUrl())).thenReturn(this.requestHeadersMock);
when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolsByDistrictNumberUrl(),distCode))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
when(this.responseMock.bodyToMono(commonSchoolsType)).thenReturn(Mono.just(List.of(commonSchool)));
when(this.responseMock.bodyToMono(schoolsType)).thenReturn(Mono.just(List.of(school)));

when(this.webClient.get()).thenReturn(this.requestHeadersUriMock);
when(this.requestHeadersUriMock.uri(String.format(constants.getDistrictByDistrictCodeUrl(),distCode))).thenReturn(this.requestHeadersMock);
Expand Down
6 changes: 2 additions & 4 deletions api/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,11 @@ cron:
#Endpoint properties
endpoint:
grad-trax-api:
all-commonschools:
all-schools-by-district:
url: http://test
school-by-min-code:
url: https://educ-grad-trax-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v2/trax/school-clob/%s
url: http://test
district-by-district-code:
url: https://educ-grad-trax-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v2/trax/district/%s
commonschool-by-mincode:
url: http://test
grad-program-api:
optional_program_name_by_optional_program_id:
Expand Down
Loading