Skip to content

Commit

Permalink
Grad2-3187 Certificates are now using school of graduation (#731)
Browse files Browse the repository at this point in the history
* Json response mincode is mapped with school mincode using schoolatgraduationid from Graduation student record table

* Improved test coverage

* Improved test coverage 2

* Removed assertion and performed null checks.

* clean up
  • Loading branch information
githubmamatha authored Jan 22, 2025
1 parent 1baffdd commit 3e6f39a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,12 @@ public StudentDemographic getStudentDemographics(String pen, String accessToken)

String gradDate = null;
String formerStudent = "F";
GraduationStudentRecordEntity graduationStudentRecordEntity = null;
Optional<GraduationStudentRecordEntity> 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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand All @@ -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));
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 3e6f39a

Please sign in to comment.