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

Changes to remove usage of clob for student information. #595

Open
wants to merge 3 commits into
base: grad-release
Choose a base branch
from
Open
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 @@ -39,7 +39,7 @@ public ProcessorData fire(ProcessorData processorData) {
gradStatusService.saveStudentRecordProjectedRun(projectedRunClob, processorData.getStudentID(), processorData.getBatchId(), exception);
gradResponse = gradStatusService.processProjectedResults(gradResponse, graduationDataStatus);
List<StudentOptionalProgram> projectedOptionalGradResponse = optionalProgramService.projectedOptionalPrograms(graduationDataStatus, processorData.getStudentID());
ReportData data = reportService.prepareAchievementReportData(graduationDataStatus, projectedOptionalGradResponse, exception);
ReportData data = reportService.prepareAchievementReportData(gradResponse.getPen(), graduationDataStatus, projectedOptionalGradResponse, exception);
if (checkExceptions(data.getException(), algorithmResponse,processorData)) {
return processorData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import java.util.UUID;

import ca.bc.gov.educ.api.graduation.util.ThreadLocalStateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;

import ca.bc.gov.educ.api.graduation.model.dto.ExceptionMessage;
import ca.bc.gov.educ.api.graduation.model.dto.GraduationData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.modelmapper.Conditions;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
Expand All @@ -41,6 +43,7 @@ public class ReportService {
SchoolService schoolService;
OptionalProgramService optionalProgramService;
RESTService restService;
ModelMapper modelMapper;

@Autowired
public ReportService(JsonTransformer jsonTransformer, EducGraduationApiConstants educGraduationApiConstants, SchoolService schoolService, OptionalProgramService optionalProgramService, RESTService restService) {
Expand All @@ -49,6 +52,7 @@ public ReportService(JsonTransformer jsonTransformer, EducGraduationApiConstants
this.schoolService = schoolService;
this.optionalProgramService = optionalProgramService;
this.restService = restService;
this.modelMapper = new ModelMapper();
}

public ProgramCertificateTranscript getTranscript(GraduationStudentRecord gradResponse, ca.bc.gov.educ.api.graduation.model.dto.GraduationData graduationDataStatus, ExceptionMessage exception) {
Expand Down Expand Up @@ -200,9 +204,8 @@ public ReportData prepareTranscriptData(ca.bc.gov.educ.api.graduation.model.dto.

public ReportData prepareTranscriptData(String pen, boolean xml, ExceptionMessage exception) {
try {
GraduationStudentRecord graduationStudentRecord = getGraduationStudentRecordByPen(pen);
ca.bc.gov.educ.api.graduation.model.dto.GraduationData graduationData = (ca.bc.gov.educ.api.graduation.model.dto.GraduationData) jsonTransformer.unmarshall(graduationStudentRecord.getStudentGradData(), ca.bc.gov.educ.api.graduation.model.dto.GraduationData.class);
return prepareTranscriptData(graduationData, graduationStudentRecord, xml, exception);
Pair<GraduationStudentRecord,ca.bc.gov.educ.api.graduation.model.dto.GraduationData> graduationStudentRecord = getGraduationStudentRecordAndGraduationData(pen);
return prepareTranscriptData(graduationStudentRecord.getRight(), graduationStudentRecord.getLeft(), xml, exception);
} catch (Exception e) {
exception.setExceptionName("PREPARE TRANSCRIPT REPORT DATA FROM PEN");
exception.setExceptionDetails(e.getCause() == null ? e.getLocalizedMessage() : e.getCause().getLocalizedMessage());
Expand Down Expand Up @@ -955,9 +958,8 @@ private String getEncodedStringFromBytes(byte[] bytes) {

public ReportData prepareCertificateData(String pen, ExceptionMessage exception) {
try {
GraduationStudentRecord graduationStudentRecord = getGraduationStudentRecordByPen(pen);
ca.bc.gov.educ.api.graduation.model.dto.GraduationData graduationData = (ca.bc.gov.educ.api.graduation.model.dto.GraduationData) jsonTransformer.unmarshall(graduationStudentRecord.getStudentGradData(), ca.bc.gov.educ.api.graduation.model.dto.GraduationData.class);
return prepareCertificateData(graduationStudentRecord, graduationData);
Pair<GraduationStudentRecord,ca.bc.gov.educ.api.graduation.model.dto.GraduationData> graduationStudentRecord = getGraduationStudentRecordAndGraduationData(pen);
return prepareCertificateData(graduationStudentRecord.getLeft(), graduationStudentRecord.getRight());
} catch (Exception e) {
exception.setExceptionName("PREPARE CERTIFICATE REPORT DATA FROM PEN");
exception.setExceptionDetails(e.getCause() == null ? e.getLocalizedMessage() : e.getCause().getLocalizedMessage());
Expand Down Expand Up @@ -1099,12 +1101,14 @@ private String generateStudentAchievementReportJasper(ReportData data) {
}
}

public ReportData prepareAchievementReportData(ca.bc.gov.educ.api.graduation.model.dto.GraduationData graduationDataStatus, List<StudentOptionalProgram> optionalProgramList, ExceptionMessage exception) {
public ReportData prepareAchievementReportData(String pen, ca.bc.gov.educ.api.graduation.model.dto.GraduationData graduationDataStatus, List<StudentOptionalProgram> optionalProgramList, ExceptionMessage exception) {
try {
School schoolAtGrad = getSchoolAtGradData(graduationDataStatus);
School schoolOfRecord = getSchoolData(graduationDataStatus.getSchool());
ReportData data = new ReportData();
data.setSchool(schoolOfRecord);
//Override student demog information
overrideDemogProperties(getStudentByPenFromStudentApi(pen),graduationDataStatus);
data.setStudent(getStudentDataAchvReport(graduationDataStatus.getGradStudent(), optionalProgramList));
data.setOrgCode(StringUtils.startsWith(data.getSchool().getMincode(), "098") ? "YU" : "BC");
data.setGraduationStatus(getGraduationStatus(graduationDataStatus, schoolAtGrad, schoolOfRecord));
Expand All @@ -1126,25 +1130,29 @@ public ReportData prepareAchievementReportData(ca.bc.gov.educ.api.graduation.mod
public Pair<GraduationStudentRecord, ca.bc.gov.educ.api.graduation.model.dto.GraduationData> getGraduationStudentRecordAndGraduationData(String pen) {
String graduationDataJson = "{}";
try {
GraduationStudentRecord graduationStudentRecord = getGraduationStudentRecordByPen(pen);
graduationDataJson = graduationStudentRecord.getStudentGradData();
ca.bc.gov.educ.api.graduation.model.dto.GraduationData graduationData = (ca.bc.gov.educ.api.graduation.model.dto.GraduationData) jsonTransformer.unmarshall(graduationDataJson, ca.bc.gov.educ.api.graduation.model.dto.GraduationData.class);
GradSearchStudent student = getStudentByPenFromStudentApi(pen);
GraduationStudentRecord graduationStudentRecord = getGradStatusFromGradStudentApi(student.getStudentID());
if (graduationStudentRecord.getStudentGradData() == null) {
throw new EntityNotFoundException(
ReportService.class,
String.format("Student with PEN %s doesn't have graduation data in GRAD Student system", pen));
}
ca.bc.gov.educ.api.graduation.model.dto.GraduationData graduationData = (ca.bc.gov.educ.api.graduation.model.dto.GraduationData) jsonTransformer.unmarshall(graduationStudentRecord.getStudentGradData(), ca.bc.gov.educ.api.graduation.model.dto.GraduationData.class);
//Override student demog information
overrideDemogProperties(student,graduationData);
return Pair.of(graduationStudentRecord, graduationData);
} catch (Exception e) {
log.error("GraduationData {} unmarshal error for student {}: {}", graduationDataJson, pen, e.getLocalizedMessage());
return null;
}
}

private GraduationStudentRecord getGraduationStudentRecordByPen(String pen) {
GradSearchStudent student = getStudentByPenFromStudentApi(pen);
GraduationStudentRecord graduationStudentRecord = getGradStatusFromGradStudentApi(student.getStudentID());
if (graduationStudentRecord.getStudentGradData() == null) {
throw new EntityNotFoundException(
ReportService.class,
String.format("Student with PEN %s doesn't have graduation data in GRAD Student system", pen));
private void overrideDemogProperties(GradSearchStudent student, ca.bc.gov.educ.api.graduation.model.dto.GraduationData graduationData) {
if (student == null || graduationData == null || graduationData.getGradStudent() == null) {
return;
}
return graduationStudentRecord;
modelMapper.getConfiguration().setPropertyCondition(Conditions.isNotNull()); // Copy only non-null values
modelMapper.map(student, graduationData.getGradStudent());
}

private List<OptionalProgram> getOptionalProgramAchvReport(String gradProgramCode, List<StudentOptionalProgram> optionalProgramList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void testGraduateStudent() {
std.setFirstName("Sreepad");
data.setStudent(std);
Mockito.when(gradStatusService.saveStudentRecordProjectedRun(projectedRunClob, studentID, null, exception)).thenReturn(gradResponse);
Mockito.when(reportService.prepareAchievementReportData(graduationDataStatus, list, exception)).thenReturn(data);
Mockito.when(reportService.prepareAchievementReportData(gradResponse.getPen(), graduationDataStatus, list, exception)).thenReturn(data);
Mockito.when(gradStatusService.getGradStatus(studentID, exception)).thenReturn(gradResponse);
Mockito.when(gradAlgorithmService.runProjectedAlgorithm(gradResponse.getStudentID(), gradResponse.getProgram())).thenReturn(graduationDataStatus);
Mockito.when(gradStatusService.processProjectedResults(gradResponse,graduationDataStatus)).thenReturn(gradResponse);
Expand Down Expand Up @@ -248,7 +248,7 @@ public void testGraduateStudent_excep_1() {
std.setFirstName("Sreepad");
data.setStudent(std);
Mockito.when(gradStatusService.saveStudentRecordProjectedRun(projectedRunClob, studentID, null, exception)).thenReturn(gradResponse);
Mockito.when(reportService.prepareAchievementReportData(graduationDataStatus, list, exception)).thenReturn(data);
Mockito.when(reportService.prepareAchievementReportData(gradResponse.getPen(), graduationDataStatus, list, exception)).thenReturn(data);
Mockito.when(gradStatusService.getGradStatus(studentID, exception)).thenReturn(gradResponse);
Mockito.when(gradAlgorithmService.runProjectedAlgorithm(gradResponse.getStudentID(), gradResponse.getProgram())).thenReturn(graduationDataStatus);
Mockito.when(gradStatusService.processProjectedResults(gradResponse,graduationDataStatus)).thenReturn(gradResponse);
Expand Down Expand Up @@ -312,7 +312,7 @@ public void testGraduateStudent_excep_2() {
std.setFirstName("Sreepad");
data.setStudent(std);
Mockito.when(gradStatusService.saveStudentRecordProjectedRun(projectedRunClob, studentID, null, exception)).thenReturn(gradResponse);
Mockito.when(reportService.prepareAchievementReportData(graduationDataStatus, list, exception)).thenReturn(data);
Mockito.when(reportService.prepareAchievementReportData(gradResponse.getPen(), graduationDataStatus, list, exception)).thenReturn(data);
Mockito.when(gradStatusService.getGradStatus(studentID, exception)).thenReturn(gradResponse);
Mockito.when(gradAlgorithmService.runProjectedAlgorithm(gradResponse.getStudentID(), gradResponse.getProgram())).thenReturn(graduationDataStatus);
Mockito.when(gradStatusService.processProjectedResults(gradResponse,graduationDataStatus)).thenReturn(gradResponse);
Expand Down Expand Up @@ -374,7 +374,7 @@ public void testGraduateStudent_error() {
std.setFirstName("Sreepad");
data.setStudent(std);
Mockito.when(gradStatusService.saveStudentRecordProjectedRun(projectedRunClob, studentID, null, exception)).thenReturn(gradResponse);
Mockito.when(reportService.prepareAchievementReportData(graduationDataStatus, list, exception)).thenReturn(data);
Mockito.when(reportService.prepareAchievementReportData(gradResponse.getPen(), graduationDataStatus, list, exception)).thenReturn(data);

Mockito.when(gradStatusService.getGradStatus(studentID, exception)).thenReturn(gradResponse);
Mockito.when(gradAlgorithmService.runProjectedAlgorithm(gradResponse.getStudentID(), gradResponse.getProgram())).thenReturn(graduationDataStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1421,10 +1421,16 @@ public void testStudentAchievementReport() throws Exception {
spc.setDescription("wasd");
spc.setSpCase("A");
spc.setPassFlag("Y");
GradSearchStudent gradSearchStudent = new GradSearchStudent();
gradSearchStudent.setPen(gradStatus.getGradStudent().getPen());
gradSearchStudent.setLegalFirstName(gradStatus.getGradStudent().getLegalFirstName());
gradSearchStudent.setLegalMiddleNames(gradStatus.getGradStudent().getLegalMiddleNames());
gradSearchStudent.setLegalLastName(gradStatus.getGradStudent().getLegalLastName());
gradSearchStudent.setStudentID(gradStatus.getGradStudent().getStudentID());

when(this.restService.get(String.format(constants.getSpecialCase(),"A"), SpecialCase.class)).thenReturn(spc);

ReportData data = reportService.prepareAchievementReportData(gradStatus,optionalProgram, exception);
when(this.restService.get(String.format(constants.getPenStudentApiByPenUrl(),gradStatus.getGradStudent().getPen()), List.class)).thenReturn(List.of(gradSearchStudent));
ReportData data = reportService.prepareAchievementReportData(gradStatus.getGradStudent().getPen(), gradStatus,optionalProgram, exception);
assertNotNull(data);
assertNotNull(data.getStudentExams());
assertNotNull(data.getStudentCourses());
Expand Down
Loading