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 86f77819..3179d6ff 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 @@ -417,11 +417,12 @@ public StudentDemographic getStudentDemographics(String pen, String accessToken) String gradDate = null; String formerStudent = "F"; + GraduationStudentRecordEntity graduationStudentRecordEntity = null; Optional graduationStudentRecordEntityOptional = graduationStatusRepository.findById(UUID.fromString(gradSearchStudent.getStudentID())); + GraduationData graduationData = null; if(graduationStudentRecordEntityOptional.isPresent()) { - GraduationStudentRecordEntity graduationStudentRecordEntity = graduationStudentRecordEntityOptional.get(); + graduationStudentRecordEntity = graduationStudentRecordEntityOptional.get(); long sessionInterval = Integer.MAX_VALUE; - GraduationData graduationData = null; if(StringUtils.isNotBlank(graduationStudentRecordEntity.getStudentGradData())) { try { graduationData = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).readValue(graduationStudentRecordEntity.getStudentGradData(), GraduationData.class); @@ -473,7 +474,16 @@ public StudentDemographic getStudentDemographics(String pen, String accessToken) break; } } - assert schoolClob != null; + + + if(graduationStudentRecordEntity == null) { + validation.addErrorAndStop("Student Id %s not found", gradSearchStudent.getStudentID()); + } + School school = getSchool(graduationStudentRecordEntity.getSchoolAtGradId(), accessToken); + if(school == null) { + validation.addErrorAndStop("School with school at graduation Id %s not found", graduationStudentRecordEntity.getSchoolAtGradId()); + } + String schoolMincode = (school.getMincode() != null && !school.getMincode().isEmpty() ? school.getMincode() : null); return StudentDemographic.builder() .studentID(gradSearchStudent.getStudentID()) .pen(pen) @@ -503,7 +513,7 @@ public StudentDemographic getStudentDemographics(String pen, String accessToken) .englishCert(englishCert) .sccDate(sccDate) .transcriptEligibility(gradSearchStudent.getTranscriptEligibility()) - .mincode(schoolClob.getMinCode()) + .mincode(schoolMincode) .schoolCategory(schoolClob.getSchoolCategoryLegacyCode()) .schoolType("02".equalsIgnoreCase(schoolClob.getSchoolCategoryLegacyCode()) ? "02" : "") .schoolName(schoolClob.getSchoolName()) 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 f1247c49..e68c76b0 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 @@ -7,6 +7,7 @@ import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Publisher; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Subscriber; import ca.bc.gov.educ.api.gradstudent.model.dto.*; +import ca.bc.gov.educ.api.gradstudent.model.dto.institute.School; import ca.bc.gov.educ.api.gradstudent.model.dto.messaging.GradStudentRecord; import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordEntity; import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordView; @@ -496,13 +497,12 @@ public void testStudentDemographics() { final UUID studentID = UUID.fromString("ac339d70-7649-1a2e-8176-4a336df2204b"); final String pen = "123456789"; - final String firstName = "FirstName"; - final String lastName = "LastName"; final String program = "2018-EN"; final String gradStatus = "A"; final String stdGrade = "12"; final UUID schoolId = UUID.randomUUID(); final String schoolName = "Test School"; + final UUID schoolAtGradID = UUID.randomUUID(); String graduationData = readFile("json/studentGradData.json"); @@ -515,6 +515,7 @@ public void testStudentDemographics() { graduationStatusEntity.setProgram(program); graduationStatusEntity.setProgramCompletionDate(new Date()); graduationStatusEntity.setSchoolOfRecordId(schoolId); + graduationStatusEntity.setSchoolAtGradId(schoolAtGradID); graduationStatusEntity.setStudentGradData(graduationData); when(this.graduationStatusRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity)); @@ -547,6 +548,16 @@ public void testStudentDemographics() { when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(certificatesType)).thenReturn(Mono.just(List.of(certificate))); + School school = new School(); + school.setSchoolId(schoolId.toString()); + school.setMincode("07171040"); + + when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolBySchoolIdUrl(), graduationStatusEntity.getSchoolAtGradId(), "accessToken"))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(School.class)).thenReturn(Mono.just(school)); + var studentDemog = graduationStatusService.getStudentDemographics(pen, "accessToken"); assertThat(studentDemog).isNotNull(); @@ -609,6 +620,16 @@ public void testStudentDemographics_whenCertificateType_isE() { when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(certificatesType)).thenReturn(Mono.just(List.of(certificate))); + School school = new School(); + school.setSchoolId(schoolId.toString()); + school.setMincode("07171040"); + + when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolBySchoolIdUrl(), graduationStatusEntity.getSchoolAtGradId(), "accessToken"))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(School.class)).thenReturn(Mono.just(school)); + var studentDemog = graduationStatusService.getStudentDemographics(pen, "accessToken"); assertThat(studentDemog).isNotNull(); @@ -671,6 +692,16 @@ public void testStudentDemographics_whenCertificateType_isF() { when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(certificatesType)).thenReturn(Mono.just(List.of(certificate))); + School school = new School(); + school.setSchoolId(schoolId.toString()); + school.setMincode("07171040"); + + when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolBySchoolIdUrl(), graduationStatusEntity.getSchoolAtGradId(), "accessToken"))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(School.class)).thenReturn(Mono.just(school)); + var studentDemog = graduationStatusService.getStudentDemographics(pen, "accessToken"); assertThat(studentDemog).isNotNull();