diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java index 2ed6dd89..c6fb24df 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java @@ -362,18 +362,14 @@ public GraduationStudentRecordSearchResult searchGraduationStudentRecords(final } if(searchRequest.getDistricts() != null && !searchRequest.getDistricts().isEmpty()) { - List schools = new ArrayList<>(getSchools(accessToken)); - for(Iterator it = schools.iterator(); it.hasNext();) { - CommonSchool school = it.next(); - if(!searchRequest.getDistricts().contains(school.getDistNo())) { + List schools = new ArrayList<>(getSchoolsByDistricts(searchRequest.getDistricts(), accessToken)); + for(Iterator it = schools.iterator(); it.hasNext();) { + School school = it.next(); + List schoolCategoryCodes = searchRequest.getSchoolCategoryCodes().stream().filter(StringUtils::isNotBlank).toList(); + if(!schoolCategoryCodes.isEmpty() && !schoolCategoryCodes.contains(school.getSchoolCategoryCode())) { it.remove(); } else { - List 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()); } } } @@ -521,13 +517,22 @@ private List getGradStudentCertificates(String studentI }).block(); } - public List getSchools(String accessToken) { - return webClient.get().uri((constants.getSchoolsSchoolApiUrl())) + public List getSchoolsByDistricts(List districts, String accessToken) { + List results = new ArrayList<>(); + for (String distNo : districts) { + results.addAll(getSchoolsByDistrictNumber(distNo, accessToken)); + } + return results; + } + + public List 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>() { + .retrieve().bodyToMono(new ParameterizedTypeReference>() { }).block(); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java index a930ac1f..aef7ff5b 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java @@ -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}") diff --git a/api/src/main/resources/application.yaml b/api/src/main/resources/application.yaml index b89b26ec..28009a5b 100644 --- a/api/src/main/resources/application.yaml +++ b/api/src/main/resources/application.yaml @@ -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: diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java index 8ee2f046..14847d5c 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java @@ -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); diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java index c70a33f2..40336332 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java @@ -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 districts = new ArrayList<>(); districts.add(distCode); @@ -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> commonSchoolsType = new ParameterizedTypeReference<>() { + final ParameterizedTypeReference> 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); @@ -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 districts = new ArrayList<>(); districts.add(distCode); @@ -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> commonSchoolsType = new ParameterizedTypeReference<>() { + final ParameterizedTypeReference> 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); diff --git a/api/src/test/resources/application.yaml b/api/src/test/resources/application.yaml index d10e3d05..c949ad89 100644 --- a/api/src/test/resources/application.yaml +++ b/api/src/test/resources/application.yaml @@ -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: