From 68ab4697cc72240c12d42a5b8f3387c04b0f8db3 Mon Sep 17 00:00:00 2001 From: Jinil Sung Date: Fri, 20 Sep 2024 16:44:12 -0700 Subject: [PATCH 1/2] GRAD2-2934, 2922, & 2950: tasks are completed. GRAD2-2934, 2922, 2950: tasks are completed. --- .../process/StudentProcess.java | 4 +- .../service/student/StudentBaseService.java | 51 +- .../StudentGraduationUpdateBaseService.java | 269 +++++++ .../StudentGraduationUpdateEventService.java | 185 ++--- ...udentGraduationUpdateEventServiceTest.java | 698 +++++++++++++++++- 5 files changed, 1034 insertions(+), 173 deletions(-) create mode 100644 api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentGraduationUpdateBaseService.java diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/process/StudentProcess.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/process/StudentProcess.java index 70f5988..198312d 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/process/StudentProcess.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/process/StudentProcess.java @@ -185,7 +185,7 @@ private void convertStudentData(ConvGradStudent student, Student penStudent, Gra gradStudent.setStudentGrade(student.getStudentGrade()); gradStudent.setStudentStatus(getGradStudentStatus(student.getStudentStatus(), student.getArchiveFlag())); - handleAdultStartRule(student, penStudent, gradStudent); + handleAdultStartRule(penStudent, gradStudent); // flags if (StringUtils.equalsIgnoreCase(gradStudent.getStudentStatus(), STUDENT_STATUS_MERGED)) { @@ -610,7 +610,7 @@ public void triggerGraduationBatchRun(EventType eventType, UUID studentID, Strin } } - private void handleAdultStartRule(ConvGradStudent student, Student penStudent, GraduationStudentRecord gradStudent) { + private void handleAdultStartRule(Student penStudent, GraduationStudentRecord gradStudent) { if ("1950".equalsIgnoreCase(gradStudent.getProgram())) { Date dob = EducGradDataConversionApiUtils.parseDate(penStudent.getDob()); Date adultStartDate = DateUtils.addYears(dob, 18); diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentBaseService.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentBaseService.java index c2afcb9..7d4d6bf 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentBaseService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentBaseService.java @@ -10,7 +10,10 @@ import java.util.Arrays; import java.util.List; -public class StudentBaseService { +public abstract class StudentBaseService { + + // NULL String => Nullify (set to NULL) + public static final String NULL_VALUE = "NULL"; // Student Status public static final String STUDENT_STATUS_CURRENT = "CUR"; @@ -109,14 +112,44 @@ protected String getGradProgram(String graduationRequirementYear, String schoolO } protected void populateNewBatchFlags(StudentGradDTO currentStudent) { - if (STUDENT_STATUS_ARCHIVED.equalsIgnoreCase(currentStudent.getStudentStatus())) { - // Transcript - currentStudent.setNewRecalculateGradStatus("Y"); - } else { - // Transcript - currentStudent.setNewRecalculateGradStatus("Y"); - // TVR - currentStudent.setNewRecalculateProjectedGrad("Y"); + switch(currentStudent.getStudentStatus()) { + case STUDENT_STATUS_CURRENT -> { + // Transcript + currentStudent.setNewRecalculateGradStatus("Y"); + // TVR + currentStudent.setNewRecalculateProjectedGrad("Y"); + } + case STUDENT_STATUS_ARCHIVED, STUDENT_STATUS_TERMINATED -> + // Transcript + currentStudent.setNewRecalculateGradStatus("Y"); + default -> { + // do not set flags to Y + currentStudent.setNewRecalculateGradStatus(null); + currentStudent.setNewRecalculateProjectedGrad(null); + } + } + } + + protected void validateAndAdjustNewBatchFlags(StudentGradDTO currentStudent) { + String currentStudentStatus = currentStudent.getStudentStatus(); + String newStudentStatus = currentStudent.getNewStudentStatus(); + // 1. If a student in GRAD is ARC/TER then do not set TVR flag + if (STUDENT_STATUS_ARCHIVED.equalsIgnoreCase(currentStudentStatus) || STUDENT_STATUS_TERMINATED.equalsIgnoreCase(currentStudentStatus)) { + currentStudent.setNewRecalculateProjectedGrad(null); + } + // 2. If a student in GRAD is MER then do not set Transcript & TVR flags + if (STUDENT_STATUS_MERGED.equalsIgnoreCase(currentStudentStatus)) { + currentStudent.setNewRecalculateGradStatus(null); + currentStudent.setNewRecalculateProjectedGrad(null); + } + // 3. If a student in GRAD is changed to ARC/TER then set TVR flag to NULL + if (STUDENT_STATUS_ARCHIVED.equalsIgnoreCase(newStudentStatus) || STUDENT_STATUS_TERMINATED.equalsIgnoreCase(newStudentStatus)) { + currentStudent.setNewRecalculateProjectedGrad(NULL_VALUE); + } + // 4. If a student in GRAD is changed to MER then set Transcript & TVR flags to NULL + if (STUDENT_STATUS_MERGED.equalsIgnoreCase(newStudentStatus)) { + currentStudent.setNewRecalculateGradStatus(NULL_VALUE); + currentStudent.setNewRecalculateProjectedGrad(NULL_VALUE); } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentGraduationUpdateBaseService.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentGraduationUpdateBaseService.java new file mode 100644 index 0000000..1486cfd --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentGraduationUpdateBaseService.java @@ -0,0 +1,269 @@ +package ca.bc.gov.educ.api.dataconversion.service.student; + +import ca.bc.gov.educ.api.dataconversion.model.StudentGradDTO; +import ca.bc.gov.educ.api.dataconversion.util.EducGradDataConversionApiUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateUtils; + +import java.util.Date; + +public abstract class StudentGraduationUpdateBaseService extends StudentBaseService { + + protected abstract boolean hasAnyFrenchImmersionCourse(String gradProgramCode, String pen, String accessToken); + + protected void handleProgramChange(String newGradProgram, StudentGradDTO currentStudent, String pen, String accessToken) { + boolean addDualDogwood = false; + boolean addFrenchImmersion = false; + + if (!currentStudent.isSCCP() && currentStudent.isGraduated()) { + currentStudent.setNewProgram(null); + return; + } + + if (newGradProgram.endsWith("-PF")) { + // from EN to PF + // from PF to PF + // from 1950 to PF + // from SCCP to PF + addDualDogwood = true; + } else if (newGradProgram.endsWith("-EN") && (currentStudent.getProgram().endsWith("-PF") || hasAnyFrenchImmersionCourse(newGradProgram, pen, accessToken))) { + // from PF to EN - allowed for SD93/Yukon PF schools + // from EN to EN + // from 1950 to EN + // from SCCP to EN + addFrenchImmersion = true; + } + + currentStudent.setAddDualDogwood(addDualDogwood); + currentStudent.setAddFrenchImmersion(addFrenchImmersion); + + currentStudent.setNewProgram(newGradProgram); + } + + protected void handleAdultStartDate(StudentGradDTO currentStudent) { + if (StringUtils.equalsIgnoreCase(currentStudent.getNewProgram(), "1950") && StringUtils.isBlank(currentStudent.getAdultStartDate())) { + Date dob = EducGradDataConversionApiUtils.parseDate(currentStudent.getBirthday()); + Date adultStartDate = DateUtils.addYears(dob, 18); + currentStudent.setNewAdultStartDate(EducGradDataConversionApiUtils.formatDate(adultStartDate)); // yyyy-MM-dd + } + } + + protected boolean processSchoolOfRecord(StudentGradDTO currentStudent, String value) { + boolean isChanged = false; + switch(currentStudent.getStudentStatus()) { + case STUDENT_STATUS_CURRENT -> { + // UpdData + currentStudent.setNewSchoolOfRecord(value); + // Transcript + currentStudent.setNewRecalculateGradStatus("Y"); + // TVR + currentStudent.setNewRecalculateProjectedGrad("Y"); + isChanged = true; + } + case STUDENT_STATUS_ARCHIVED -> { + if (!currentStudent.isGraduated()) { + // UpdData + currentStudent.setNewSchoolOfRecord(value); + // Transcript + currentStudent.setNewRecalculateGradStatus("Y"); + isChanged = true; + } + } + case STUDENT_STATUS_TERMINATED -> { + // UpdData + currentStudent.setNewSchoolOfRecord(value); + // Transcript + currentStudent.setNewRecalculateGradStatus("Y"); + isChanged = true; + } + default -> { // MER or DEC + // UpdData + currentStudent.setNewSchoolOfRecord(value); + // Do not set flags to Y + isChanged = true; + } + } + return isChanged; + } + + protected boolean processStudentGrade(StudentGradDTO currentStudent, String value) { + boolean isChanged = false; + switch(currentStudent.getStudentStatus()) { + case STUDENT_STATUS_CURRENT -> { + // UpdData + currentStudent.setNewStudentGrade(value); + // TVR + currentStudent.setNewRecalculateProjectedGrad("Y"); + if (!currentStudent.isGraduated()) { + // Transcript + currentStudent.setNewRecalculateGradStatus("Y"); + } + isChanged = true; + } + case STUDENT_STATUS_ARCHIVED -> { + if (!currentStudent.isGraduated()) { + // UpdData + currentStudent.setNewStudentGrade(value); + // Transcript + currentStudent.setNewRecalculateGradStatus("Y"); + isChanged = true; + } + } + case STUDENT_STATUS_TERMINATED -> { + // UpdData + currentStudent.setNewStudentGrade(value); + // Transcript + currentStudent.setNewRecalculateGradStatus("Y"); + isChanged = true; + } + default -> { // MER or DEC + // UpdData + currentStudent.setNewStudentGrade(value); + // Do not set flags to Y + isChanged = true; + } + } + return isChanged; + } + + protected boolean processGraduationProgram(StudentGradDTO currentStudent, String pen, String gradProgram, String accessToken) { + boolean isChanged = false; + switch(currentStudent.getStudentStatus()) { + case STUDENT_STATUS_CURRENT -> { + if (!currentStudent.isGraduated() || currentStudent.isSCCP()) { + // UpdData + handleProgramChange(gradProgram, currentStudent, pen, accessToken); + handleAdultStartDate(currentStudent); + // Transcript + currentStudent.setNewRecalculateGradStatus("Y"); + // TVR + currentStudent.setNewRecalculateProjectedGrad("Y"); + isChanged = true; + } + } + case STUDENT_STATUS_ARCHIVED, STUDENT_STATUS_TERMINATED -> { + if (!currentStudent.isGraduated() || currentStudent.isSCCP()) { + // UpdData + handleProgramChange(gradProgram, currentStudent, pen, accessToken); + handleAdultStartDate(currentStudent); + // Transcript + currentStudent.setNewRecalculateGradStatus("Y"); + isChanged = true; + } + } + default -> { // MER or DEC + if (!currentStudent.isGraduated() || currentStudent.isSCCP()) { + // UpdData + handleProgramChange(gradProgram, currentStudent, pen, accessToken); + handleAdultStartDate(currentStudent); + // Do not set flags to Y + isChanged = true; + } + } + + } + return isChanged; + } + + protected boolean processSlpDate(StudentGradDTO currentStudent, String value) { + boolean isChanged = false; + switch(currentStudent.getStudentStatus()) { + case STUDENT_STATUS_CURRENT -> { + if (!currentStudent.isGraduated()) { + // UpdData + currentStudent.setNewGradDate(value); + // Transcript + currentStudent.setNewRecalculateGradStatus("Y"); + // TVR + currentStudent.setNewRecalculateProjectedGrad("Y"); + isChanged = true; + } + } + case STUDENT_STATUS_ARCHIVED, STUDENT_STATUS_TERMINATED -> { + if (!currentStudent.isGraduated()) { + // UpdData + currentStudent.setNewGradDate(value); + // Transcript + currentStudent.setNewRecalculateGradStatus("Y"); + isChanged = true; + } + } + default -> { // MER or DEC + if (!currentStudent.isGraduated()) { + // UpdData + currentStudent.setNewGradDate(value); + // Do not set flags to Y + isChanged = true; + } + } + + } + return isChanged; + } + + protected boolean processCitizenship(StudentGradDTO currentStudent, String value) { + boolean isChanged = false; + switch(currentStudent.getStudentStatus()) { + case STUDENT_STATUS_CURRENT -> { + // UpdData + currentStudent.setNewCitizenship(value); + // TVR + currentStudent.setNewRecalculateProjectedGrad("Y"); + if (!currentStudent.isGraduated()) { + // Transcript + currentStudent.setNewRecalculateGradStatus("Y"); + } + isChanged = true; + } + case STUDENT_STATUS_ARCHIVED -> { + if (!currentStudent.isGraduated()) { + // UpdData + currentStudent.setNewCitizenship(value); + // Transcript + currentStudent.setNewRecalculateGradStatus("Y"); + isChanged = true; + } + } + case STUDENT_STATUS_TERMINATED -> { + // UpdData + currentStudent.setNewCitizenship(value); + // Transcript + currentStudent.setNewRecalculateGradStatus("Y"); + isChanged = true; + } + default -> { // MER or DEC + // UpdData + currentStudent.setNewCitizenship(value); + // Do not set flags to Y + isChanged = true; + } + + } + return isChanged; + } + + protected void processStudentStatus(StudentGradDTO currentStudent, String value) { + // UpdData + currentStudent.setNewStudentStatus(value); + switch(value) { + case STUDENT_STATUS_ARCHIVED, STUDENT_STATUS_MERGED -> { + // TVR + currentStudent.setNewRecalculateProjectedGrad(NULL_VALUE); + } + case STUDENT_STATUS_CURRENT -> { + // Transcript + currentStudent.setNewRecalculateGradStatus("Y"); + // TVR + currentStudent.setNewRecalculateProjectedGrad("Y"); + } + case STUDENT_STATUS_TERMINATED -> { + // Transcript + currentStudent.setNewRecalculateGradStatus("Y"); + // TVR + currentStudent.setNewRecalculateProjectedGrad(NULL_VALUE); + } + default -> { // DEC + } + } + } +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentGraduationUpdateEventService.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentGraduationUpdateEventService.java index d96b951..011901e 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentGraduationUpdateEventService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentGraduationUpdateEventService.java @@ -6,23 +6,20 @@ import ca.bc.gov.educ.api.dataconversion.repository.EventRepository; import ca.bc.gov.educ.api.dataconversion.service.EventService; import ca.bc.gov.educ.api.dataconversion.util.EducGradDataConversionApiConstants; -import ca.bc.gov.educ.api.dataconversion.util.EducGradDataConversionApiUtils; import ca.bc.gov.educ.api.dataconversion.util.RestUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.DateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.time.LocalDateTime; -import java.util.Date; import static ca.bc.gov.educ.api.dataconversion.constant.EventStatus.PROCESSED; import static ca.bc.gov.educ.api.dataconversion.constant.EventType.UPD_GRAD; @Service @Slf4j -public class StudentGraduationUpdateEventService extends StudentBaseService implements EventService { +public class StudentGraduationUpdateEventService extends StudentGraduationUpdateBaseService implements EventService { private final EventRepository eventRepository; @@ -71,154 +68,72 @@ public void processEvent(T request, Event event) { public void processStudent(TraxGraduationUpdateDTO updateGrad, StudentGradDTO currentStudent, String accessToken) { boolean isChanged = false; + boolean isStudentStatusChanged = false; log.info(" Process Student : studentID = {}, pen = {}", currentStudent.getStudentID(), updateGrad.getPen()); // Processing order is important for the first 3 fields below. + // 1. School of record + if (!StringUtils.equals(updateGrad.getSchoolOfRecord(), currentStudent.getSchoolOfRecord())) { + isChanged = processSchoolOfRecord(currentStudent, updateGrad.getSchoolOfRecord()); + log.info(" => school of record : current = {}, request = {}", currentStudent.getSchoolOfRecord(), currentStudent.getNewSchoolOfRecord()); + } + // 2. Grad Program + String gradProgram = getGradProgram(updateGrad.getGraduationRequirementYear(), currentStudent.getUpToDateSchoolOfRecord(), null); + if (!StringUtils.equals(gradProgram, currentStudent.getProgram())) { + isChanged = processGraduationProgram(currentStudent, updateGrad.getPen(), gradProgram, accessToken); + if (isChanged && StringUtils.isNotBlank(currentStudent.getNewProgram())) { + log.info(" => grad program : current = {}, request = {}", currentStudent.getProgram(), currentStudent.getNewProgram()); + } else { + log.info(" => grad program : current = {}, request = {} => no change(undo completion is required instead)", currentStudent.getProgram(), gradProgram); + } + } + // 3. SLP Date + String slpDate = updateGrad.getSlpDateWithDefaultFormat(); + if (slpDate != null && "SCCP".equalsIgnoreCase(currentStudent.getUpToDateGradProgram()) + && !StringUtils.equals(slpDate, currentStudent.getGradDate())) { + isChanged = processSlpDate(currentStudent, slpDate); + if (isChanged) { + log.info(" => slp date : current = {}, request = {}", currentStudent.getGradDate(), slpDate); + } else { + log.info(" => slp date : current = {}, request = {} => no change(undo completion is required instead)", currentStudent.getGradDate(), slpDate); + } + } + // 4. Student Grade + if (!StringUtils.equals(updateGrad.getStudentGrade(), currentStudent.getStudentGrade())) { + isChanged = processStudentGrade(currentStudent, updateGrad.getStudentGrade()); + log.info(" => student grade : current = {}, request = {}", currentStudent.getStudentGrade(), currentStudent.getNewStudentGrade()); + } + // 5. Citizenship + if (!StringUtils.equals(updateGrad.getCitizenship(), currentStudent.getCitizenship())) { + isChanged = processCitizenship(currentStudent, updateGrad.getCitizenship()); + log.info(" => student citizenship : current = {}, request = {}", currentStudent.getCitizenship(), currentStudent.getNewCitizenship()); + } String newStudentStatus = getGradStudentStatus(updateGrad.getStudentStatus(), updateGrad.getArchiveFlag()); - // 0. Student Status + // 6. Student Status if (!StringUtils.equals(newStudentStatus, currentStudent.getStudentStatus())) { - currentStudent.setNewStudentStatus(newStudentStatus); - if (StringUtils.equalsIgnoreCase(currentStudent.getNewStudentStatus(), STUDENT_STATUS_CURRENT) - || StringUtils.equalsIgnoreCase(currentStudent.getNewStudentStatus(), STUDENT_STATUS_TERMINATED) - || StringUtils.equalsIgnoreCase(currentStudent.getNewStudentStatus(), STUDENT_STATUS_DECEASED)) { - // Transcript - currentStudent.setNewRecalculateGradStatus("Y"); - // TVR - currentStudent.setNewRecalculateProjectedGrad("Y"); - } + processStudentStatus(currentStudent, newStudentStatus); log.info(" => student status : current = {}, request = {}", currentStudent.getStudentStatus(), currentStudent.getNewStudentStatus()); isChanged = true; - } - if (!currentStudent.isArchived() || !currentStudent.isGraduated()) { - // 1. School of record - if (!StringUtils.equals(updateGrad.getSchoolOfRecord(), currentStudent.getSchoolOfRecord())) { - currentStudent.setNewSchoolOfRecord(updateGrad.getSchoolOfRecord()); - // Transcript - currentStudent.setNewRecalculateGradStatus("Y"); - if (!currentStudent.isArchived()) { - // TVR - currentStudent.setNewRecalculateProjectedGrad("Y"); - } - log.info(" => school of record : current = {}, request = {}", currentStudent.getSchoolOfRecord(), currentStudent.getNewSchoolOfRecord()); - isChanged = true; - } - // 2. Grad Program - String gradProgram = getGradProgram(updateGrad.getGraduationRequirementYear(), currentStudent.getUpToDateSchoolOfRecord(), null); - if (!StringUtils.equals(gradProgram, currentStudent.getProgram())) { - handleProgramChange(gradProgram, currentStudent, updateGrad.getPen(), accessToken); - handleAdultStartDate(currentStudent); - if (StringUtils.isNotBlank(currentStudent.getNewProgram())) { - // Transcript - currentStudent.setNewRecalculateGradStatus("Y"); - if (!currentStudent.isArchived()) { - // TVR - currentStudent.setNewRecalculateProjectedGrad("Y"); - } - log.info(" => grad program : current = {}, request = {}", currentStudent.getProgram(), currentStudent.getNewProgram()); - isChanged = true; - } else { - log.info(" => grad program : current = {}, request = {} => no change(undo completion is required instead)", currentStudent.getProgram(), gradProgram); - } - } - // 3. SLP Date - String slpDate = updateGrad.getSlpDateWithDefaultFormat(); - if (slpDate != null && "SCCP".equalsIgnoreCase(currentStudent.getUpToDateGradProgram()) - && !StringUtils.equals(slpDate, currentStudent.getGradDate())) { - if (!currentStudent.isGraduated()) { - currentStudent.setNewGradDate(slpDate); - // Transcript - currentStudent.setNewRecalculateGradStatus("Y"); - if (!currentStudent.isArchived()) { - // TVR - currentStudent.setNewRecalculateProjectedGrad("Y"); - } - log.info(" => slp date : current = {}, request = {}", currentStudent.getGradDate(), slpDate); - isChanged = true; - } else { - log.info(" => slp date : current = {}, request = {} => no change(undo completion is required instead)", currentStudent.getGradDate(), slpDate); - } - } - // Student Grade - if (!StringUtils.equals(updateGrad.getStudentGrade(), currentStudent.getStudentGrade())) { - currentStudent.setNewStudentGrade(updateGrad.getStudentGrade()); - if (!currentStudent.isGraduated()) { // non grad - // Transcript - currentStudent.setNewRecalculateGradStatus("Y"); - if (!currentStudent.isArchived()) { - // TVR - currentStudent.setNewRecalculateProjectedGrad("Y"); - } - } else { - // TVR - currentStudent.setNewRecalculateProjectedGrad("Y"); - } - log.info(" => student grade : current = {}, request = {}", currentStudent.getStudentGrade(), currentStudent.getNewStudentGrade()); - isChanged = true; - } - // Citizenship - if (!StringUtils.equals(updateGrad.getCitizenship(), currentStudent.getCitizenship())) { - currentStudent.setNewCitizenship(updateGrad.getCitizenship()); - if (!currentStudent.isGraduated()) { // non grad - // Transcript - currentStudent.setNewRecalculateGradStatus("Y"); - if (!currentStudent.isArchived()) { - // TVR - currentStudent.setNewRecalculateProjectedGrad("Y"); - } - } else { - // TVR - currentStudent.setNewRecalculateProjectedGrad("Y"); - } - log.info(" => student citizenship : current = {}, request = {}", currentStudent.getCitizenship(), currentStudent.getNewCitizenship()); - isChanged = true; - } + isStudentStatusChanged = true; } if (isChanged) { + if (isStudentStatusChanged) { + validateAndAdjustNewBatchFlags(currentStudent); + } log.info(" Save Student : studentID = {}, pen = {}", currentStudent.getStudentID(), updateGrad.getPen()); studentProcess.saveGraduationStudent(updateGrad.getPen(), currentStudent, UPD_GRAD, accessToken); } } - private void handleProgramChange(String newGradProgram, StudentGradDTO currentStudent, String pen, String accessToken) { - boolean addDualDogwood = false; - boolean addFrenchImmersion = false; - - if (!currentStudent.isSCCP() && currentStudent.isGraduated()) { - currentStudent.setNewProgram(null); - return; - } - - if (newGradProgram.endsWith("-PF")) { - // from EN to PF - // from PF to PF - // from 1950 to PF - // from SCCP to PF - addDualDogwood = true; - } else if (newGradProgram.endsWith("-EN") && (currentStudent.getProgram().endsWith("-PF") || studentProcess.hasAnyFrenchImmersionCourse(newGradProgram, pen, accessToken))) { - // from PF to EN - allowed for SD93/Yukon PF schools - // from EN to EN - // from 1950 to EN - // from SCCP to EN - addFrenchImmersion = true; - } - - currentStudent.setAddDualDogwood(addDualDogwood); - currentStudent.setAddFrenchImmersion(addFrenchImmersion); - - currentStudent.setNewProgram(newGradProgram); - } - - private void handleAdultStartDate(StudentGradDTO currentStudent) { - if (StringUtils.equalsIgnoreCase(currentStudent.getNewProgram(), "1950") && StringUtils.isBlank(currentStudent.getAdultStartDate())) { - Date dob = EducGradDataConversionApiUtils.parseDate(currentStudent.getBirthday()); - Date adultStartDate = DateUtils.addYears(dob, 18); - currentStudent.setNewAdultStartDate(EducGradDataConversionApiUtils.formatDate(adultStartDate)); // yyyy-MM-dd - } - } - @Override public String getEventType() { return UPD_GRAD.toString(); } + + @Override + public boolean hasAnyFrenchImmersionCourse(String gradProgramCode, String pen, String accessToken) { + return studentProcess.hasAnyFrenchImmersionCourse(gradProgramCode, pen, accessToken); + } + } diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentGraduationUpdateEventServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentGraduationUpdateEventServiceTest.java index afa2c8b..57af61a 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentGraduationUpdateEventServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentGraduationUpdateEventServiceTest.java @@ -315,6 +315,137 @@ public void testProcessCurrentGraduatedStudentForGrad2018ENProgram_givenUpdated_ assertThat(event.getEventStatus()).isEqualTo(EventStatus.PROCESSED.name()); } + @Test + public void testProcessTerminatedGraduatedStudentForGrad2018ENProgram_givenUpdated_whenGradeAndSchoolAreChanged_then_returnsAPICallSuccess() { + // ID + UUID studentID = UUID.randomUUID(); + String pen = "111222333"; + + // Program & School + String program = "2018-EN"; + String mincode = "222333"; + + String newMincode = "333444"; + + String updateType = "UPD_GRAD"; + + // TraxGraduationUpdateDTO + TraxGraduationUpdateDTO traxGraduationUpdate = new TraxGraduationUpdateDTO(); + traxGraduationUpdate.setPen(pen); + traxGraduationUpdate.setGraduationRequirementYear("2018"); + traxGraduationUpdate.setCitizenship("C"); + traxGraduationUpdate.setStudentGrade("11"); + traxGraduationUpdate.setSchoolOfRecord(newMincode); + traxGraduationUpdate.setStudentStatus("T"); + traxGraduationUpdate.setArchiveFlag("A"); + + // Event + Event event = new Event(); + event.setEventType(EventType.UPD_GRAD.name()); + event.setEventStatus(EventStatus.DB_COMMITTED.name()); + event.setActivityCode(updateType); + event.setEventId(UUID.randomUUID()); + + // current GRAD Student + StudentGradDTO currentStudent = new StudentGradDTO(); + // GraduationStudentRecord + currentStudent.setStudentID(studentID); + currentStudent.setProgram(program); + currentStudent.setStudentGrade("12"); + currentStudent.setStudentStatus("TER"); + currentStudent.setCitizenship("C"); + currentStudent.setSchoolOfRecord(mincode); + currentStudent.setSchoolAtGrad(mincode); + currentStudent.setGradDate("2022/02"); + // Optional Program Codes + currentStudent.getProgramCodes().add("XC"); + currentStudent.getProgramCodes().add("FI"); + // Courses + StudentCourse course1 = new StudentCourse(); + course1.setCourseCode("Test"); + course1.setCourseLevel("12"); + course1.setCourseName("Test Course"); + course1.setCreditsUsedForGrad(Integer.valueOf("4")); + course1.setCompletedCoursePercentage(Double.valueOf("92.00")); + course1.setCredits(Integer.valueOf("4")); + course1.setPen(pen); + currentStudent.getCourses().add(course1); + + when(this.studentProcess.loadStudentData(eq(pen), any())).thenReturn(currentStudent); + when(this.eventRepository.findByEventId(event.getEventId())).thenReturn(Optional.of(event)); + + studentGraduationUpdateEventService.processEvent(traxGraduationUpdate, event); + + assertThat(event).isNotNull(); + assertThat(event.getEventStatus()).isEqualTo(EventStatus.PROCESSED.name()); + } + + @Test + public void testProcessDeceasedGraduatedStudentForGrad2018ENProgram_givenUpdated_whenGradeAndSchoolAreChanged_then_returnsAPICallSuccess() { + // ID + UUID studentID = UUID.randomUUID(); + String pen = "111222333"; + + // Program & School + String program = "2018-EN"; + String mincode = "222333"; + + String newMincode = "333444"; + + String updateType = "UPD_GRAD"; + + // TraxGraduationUpdateDTO + TraxGraduationUpdateDTO traxGraduationUpdate = new TraxGraduationUpdateDTO(); + traxGraduationUpdate.setPen(pen); + traxGraduationUpdate.setGraduationRequirementYear("2018"); + traxGraduationUpdate.setCitizenship("C"); + traxGraduationUpdate.setStudentGrade("11"); + traxGraduationUpdate.setSchoolOfRecord(newMincode); + traxGraduationUpdate.setStudentStatus("D"); + traxGraduationUpdate.setArchiveFlag("I"); + + // Event + Event event = new Event(); + event.setEventType(EventType.UPD_GRAD.name()); + event.setEventStatus(EventStatus.DB_COMMITTED.name()); + event.setActivityCode(updateType); + event.setEventId(UUID.randomUUID()); + + // current GRAD Student + StudentGradDTO currentStudent = new StudentGradDTO(); + // GraduationStudentRecord + currentStudent.setStudentID(studentID); + currentStudent.setProgram(program); + currentStudent.setStudentGrade("12"); + currentStudent.setStudentStatus("DEC"); + currentStudent.setCitizenship("C"); + currentStudent.setSchoolOfRecord(mincode); + currentStudent.setSchoolAtGrad(mincode); + currentStudent.setGradDate("2022/02"); + // Optional Program Codes + currentStudent.getProgramCodes().add("XC"); + currentStudent.getProgramCodes().add("FI"); + // Courses + StudentCourse course1 = new StudentCourse(); + course1.setCourseCode("Test"); + course1.setCourseLevel("12"); + course1.setCourseName("Test Course"); + course1.setCreditsUsedForGrad(Integer.valueOf("4")); + course1.setCompletedCoursePercentage(Double.valueOf("92.00")); + course1.setCredits(Integer.valueOf("4")); + course1.setPen(pen); + currentStudent.getCourses().add(course1); + + when(this.studentProcess.loadStudentData(eq(pen), any())).thenReturn(currentStudent); + when(this.eventRepository.findByEventId(event.getEventId())).thenReturn(Optional.of(event)); + + studentGraduationUpdateEventService.processEvent(traxGraduationUpdate, event); + + assertThat(event).isNotNull(); + assertThat(event.getEventStatus()).isEqualTo(EventStatus.PROCESSED.name()); + } + + @Test public void testProcessCurrentStudentForGrad2018ENProgram_givenUpdated_Archived_STUDENT_whenGradeAndSchoolAreChanged_then_returnsAPICallSuccess() { // ID @@ -325,7 +456,329 @@ public void testProcessCurrentStudentForGrad2018ENProgram_givenUpdated_Archived_ String program = "2018-EN"; String mincode = "222333"; - String newMincode = "333444"; + String newMincode = "333444"; + + String updateType = "UPD_GRAD"; + + // TraxGraduationUpdateDTO + TraxGraduationUpdateDTO traxGraduationUpdate = new TraxGraduationUpdateDTO(); + traxGraduationUpdate.setPen(pen); + traxGraduationUpdate.setGraduationRequirementYear("2018"); + traxGraduationUpdate.setCitizenship("C"); + traxGraduationUpdate.setStudentGrade("11"); + traxGraduationUpdate.setSchoolOfRecord(newMincode); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("I"); + + // Event + Event event = new Event(); + event.setEventType(EventType.UPD_GRAD.name()); + event.setEventStatus(EventStatus.DB_COMMITTED.name()); + event.setActivityCode(updateType); + event.setEventId(UUID.randomUUID()); + + // current GRAD Student + StudentGradDTO currentStudent = new StudentGradDTO(); + // GraduationStudentRecord + currentStudent.setStudentID(studentID); + currentStudent.setProgram(program); + currentStudent.setStudentGrade("12"); + currentStudent.setStudentStatus("CUR"); + currentStudent.setCitizenship("C"); + currentStudent.setSchoolOfRecord(mincode); + currentStudent.setSchoolAtGrad(mincode); + // Optional Program Codes + currentStudent.getProgramCodes().add("XC"); + currentStudent.getProgramCodes().add("FI"); + // Courses + StudentCourse course1 = new StudentCourse(); + course1.setCourseCode("Test"); + course1.setCourseLevel("12"); + course1.setCourseName("Test Course"); + course1.setCreditsUsedForGrad(Integer.valueOf("4")); + course1.setCompletedCoursePercentage(Double.valueOf("92.00")); + course1.setCredits(Integer.valueOf("4")); + course1.setPen(pen); + currentStudent.getCourses().add(course1); + + when(this.studentProcess.loadStudentData(eq(pen), any())).thenReturn(currentStudent); + when(this.eventRepository.findByEventId(event.getEventId())).thenReturn(Optional.of(event)); + + studentGraduationUpdateEventService.processEvent(traxGraduationUpdate, event); + + assertThat(event).isNotNull(); + assertThat(event.getEventStatus()).isEqualTo(EventStatus.PROCESSED.name()); + } + + @Test + public void testProcessArchivedStudentForGrad2018ENProgram_givenUpdated_Current_STUDENT_whenGradeAndSchoolAreChangedAndStatusIsCurrent_then_returnsAPICallSuccess() { + // ID + UUID studentID = UUID.randomUUID(); + String pen = "111222333"; + + // Program & School + String program = "2018-EN"; + String mincode = "222333"; + + String newMincode = "333444"; + + String updateType = "UPD_GRAD"; + + // TraxGraduationUpdateDTO + TraxGraduationUpdateDTO traxGraduationUpdate = new TraxGraduationUpdateDTO(); + traxGraduationUpdate.setPen(pen); + traxGraduationUpdate.setGraduationRequirementYear("2018"); + traxGraduationUpdate.setCitizenship("C"); + traxGraduationUpdate.setStudentGrade("11"); + traxGraduationUpdate.setSchoolOfRecord(newMincode); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("A"); + + // Event + Event event = new Event(); + event.setEventType(EventType.UPD_GRAD.name()); + event.setEventStatus(EventStatus.DB_COMMITTED.name()); + event.setActivityCode(updateType); + event.setEventId(UUID.randomUUID()); + + // current GRAD Student + StudentGradDTO currentStudent = new StudentGradDTO(); + // GraduationStudentRecord + currentStudent.setStudentID(studentID); + currentStudent.setProgram(program); + currentStudent.setStudentGrade("12"); + currentStudent.setStudentStatus("ARC"); + currentStudent.setCitizenship("C"); + currentStudent.setSchoolOfRecord(mincode); + currentStudent.setSchoolAtGrad(mincode); + // Optional Program Codes + currentStudent.getProgramCodes().add("XC"); + currentStudent.getProgramCodes().add("FI"); + // Courses + StudentCourse course1 = new StudentCourse(); + course1.setCourseCode("Test"); + course1.setCourseLevel("12"); + course1.setCourseName("Test Course"); + course1.setCreditsUsedForGrad(Integer.valueOf("4")); + course1.setCompletedCoursePercentage(Double.valueOf("92.00")); + course1.setCredits(Integer.valueOf("4")); + course1.setPen(pen); + currentStudent.getCourses().add(course1); + + when(this.studentProcess.loadStudentData(eq(pen), any())).thenReturn(currentStudent); + when(this.eventRepository.findByEventId(event.getEventId())).thenReturn(Optional.of(event)); + + studentGraduationUpdateEventService.processEvent(traxGraduationUpdate, event); + + assertThat(event).isNotNull(); + assertThat(event.getEventStatus()).isEqualTo(EventStatus.PROCESSED.name()); + } + + @Test + public void testProcessArchivedStudentForGrad2018ENProgram_givenUpdated_whenGradeAndSchoolAreChangedAndStatusIsTerminated_then_returnsAPICallSuccess() { + // ID + UUID studentID = UUID.randomUUID(); + String pen = "111222333"; + + // Program & School + String program = "2018-EN"; + String mincode = "222333"; + + String newMincode = "333444"; + + String updateType = "UPD_GRAD"; + + // TraxGraduationUpdateDTO + TraxGraduationUpdateDTO traxGraduationUpdate = new TraxGraduationUpdateDTO(); + traxGraduationUpdate.setPen(pen); + traxGraduationUpdate.setGraduationRequirementYear("2018"); + traxGraduationUpdate.setCitizenship("C"); + traxGraduationUpdate.setStudentGrade("11"); + traxGraduationUpdate.setSchoolOfRecord(newMincode); + traxGraduationUpdate.setStudentStatus("T"); + traxGraduationUpdate.setArchiveFlag("A"); + + // Event + Event event = new Event(); + event.setEventType(EventType.UPD_GRAD.name()); + event.setEventStatus(EventStatus.DB_COMMITTED.name()); + event.setActivityCode(updateType); + event.setEventId(UUID.randomUUID()); + + // current GRAD Student + StudentGradDTO currentStudent = new StudentGradDTO(); + // GraduationStudentRecord + currentStudent.setStudentID(studentID); + currentStudent.setProgram(program); + currentStudent.setStudentGrade("12"); + currentStudent.setStudentStatus("ARC"); + currentStudent.setCitizenship("C"); + currentStudent.setSchoolOfRecord(mincode); + currentStudent.setSchoolAtGrad(mincode); + // Optional Program Codes + currentStudent.getProgramCodes().add("XC"); + currentStudent.getProgramCodes().add("FI"); + // Courses + StudentCourse course1 = new StudentCourse(); + course1.setCourseCode("Test"); + course1.setCourseLevel("12"); + course1.setCourseName("Test Course"); + course1.setCreditsUsedForGrad(Integer.valueOf("4")); + course1.setCompletedCoursePercentage(Double.valueOf("92.00")); + course1.setCredits(Integer.valueOf("4")); + course1.setPen(pen); + currentStudent.getCourses().add(course1); + + when(this.studentProcess.loadStudentData(eq(pen), any())).thenReturn(currentStudent); + when(this.eventRepository.findByEventId(event.getEventId())).thenReturn(Optional.of(event)); + + studentGraduationUpdateEventService.processEvent(traxGraduationUpdate, event); + + assertThat(event).isNotNull(); + assertThat(event.getEventStatus()).isEqualTo(EventStatus.PROCESSED.name()); + } + + @Test + public void testProcessStudentForGrad2018ENProgram_givenUpdated_STUDENT_whenCitizenshipIsChanged_then_returnsAPICallSuccess() { + // ID + UUID studentID = UUID.randomUUID(); + String pen = "111222333"; + + // Program & School + String program = "2018-EN"; + String mincode = "222333"; + + String newCitizenship = "C"; + + String updateType = "UPD_GRAD"; + + // TraxGraduationUpdateDTO + TraxGraduationUpdateDTO traxGraduationUpdate = new TraxGraduationUpdateDTO(); + traxGraduationUpdate.setPen(pen); + traxGraduationUpdate.setGraduationRequirementYear("2018"); + traxGraduationUpdate.setStudentGrade("12"); + traxGraduationUpdate.setSchoolOfRecord(mincode); + traxGraduationUpdate.setCitizenship(newCitizenship); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("A"); + + // Event + Event event = new Event(); + event.setEventType(EventType.UPD_GRAD.name()); + event.setEventStatus(EventStatus.DB_COMMITTED.name()); + event.setActivityCode(updateType); + event.setEventId(UUID.randomUUID()); + + // current GRAD Student + StudentGradDTO currentStudent = new StudentGradDTO(); + // GraduationStudentRecord + currentStudent.setStudentID(studentID); + currentStudent.setProgram(program); + currentStudent.setStudentGrade("12"); + currentStudent.setStudentStatus("CUR"); + currentStudent.setCitizenship(null); + currentStudent.setSchoolOfRecord(mincode); + currentStudent.setSchoolAtGrad(mincode); + currentStudent.setGradDate(null); + // Optional Program Codes + currentStudent.getProgramCodes().add("XC"); + currentStudent.getProgramCodes().add("FI"); + // Courses + StudentCourse course1 = new StudentCourse(); + course1.setCourseCode("Test"); + course1.setCourseLevel("12"); + course1.setCourseName("Test Course"); + course1.setCreditsUsedForGrad(Integer.valueOf("4")); + course1.setCompletedCoursePercentage(Double.valueOf("92.00")); + course1.setCredits(Integer.valueOf("4")); + course1.setPen(pen); + currentStudent.getCourses().add(course1); + + when(this.studentProcess.loadStudentData(eq(pen), any())).thenReturn(currentStudent); + when(this.eventRepository.findByEventId(event.getEventId())).thenReturn(Optional.of(event)); + + studentGraduationUpdateEventService.processEvent(traxGraduationUpdate, event); + + assertThat(event).isNotNull(); + assertThat(event.getEventStatus()).isEqualTo(EventStatus.PROCESSED.name()); + } + + @Test + public void testProcessArchivedStudentForGrad2018ENProgram_givenUpdated_whenCitizenshipIsChanged_then_returnsAPICallSuccess() { + // ID + UUID studentID = UUID.randomUUID(); + String pen = "111222333"; + + // Program & School + String program = "2018-EN"; + String mincode = "222333"; + + String newCitizenship = "C"; + + String updateType = "UPD_GRAD"; + + // TraxGraduationUpdateDTO + TraxGraduationUpdateDTO traxGraduationUpdate = new TraxGraduationUpdateDTO(); + traxGraduationUpdate.setPen(pen); + traxGraduationUpdate.setGraduationRequirementYear("2018"); + traxGraduationUpdate.setStudentGrade("12"); + traxGraduationUpdate.setSchoolOfRecord(mincode); + traxGraduationUpdate.setCitizenship(newCitizenship); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("I"); + + // Event + Event event = new Event(); + event.setEventType(EventType.UPD_GRAD.name()); + event.setEventStatus(EventStatus.DB_COMMITTED.name()); + event.setActivityCode(updateType); + event.setEventId(UUID.randomUUID()); + + // current GRAD Student + StudentGradDTO currentStudent = new StudentGradDTO(); + // GraduationStudentRecord + currentStudent.setStudentID(studentID); + currentStudent.setProgram(program); + currentStudent.setStudentGrade("12"); + currentStudent.setStudentStatus("ARC"); + currentStudent.setCitizenship(null); + currentStudent.setSchoolOfRecord(mincode); + currentStudent.setSchoolAtGrad(mincode); + currentStudent.setGradDate(null); + // Optional Program Codes + currentStudent.getProgramCodes().add("XC"); + currentStudent.getProgramCodes().add("FI"); + // Courses + StudentCourse course1 = new StudentCourse(); + course1.setCourseCode("Test"); + course1.setCourseLevel("12"); + course1.setCourseName("Test Course"); + course1.setCreditsUsedForGrad(Integer.valueOf("4")); + course1.setCompletedCoursePercentage(Double.valueOf("92.00")); + course1.setCredits(Integer.valueOf("4")); + course1.setPen(pen); + currentStudent.getCourses().add(course1); + + when(this.studentProcess.loadStudentData(eq(pen), any())).thenReturn(currentStudent); + when(this.eventRepository.findByEventId(event.getEventId())).thenReturn(Optional.of(event)); + + studentGraduationUpdateEventService.processEvent(traxGraduationUpdate, event); + + assertThat(event).isNotNull(); + assertThat(event.getEventStatus()).isEqualTo(EventStatus.PROCESSED.name()); + } + + @Test + public void testProcessTerminatedStudentForGrad2018ENProgram_givenUpdated_whenCitizenshipIsChanged_then_returnsAPICallSuccess() { + // ID + UUID studentID = UUID.randomUUID(); + String pen = "111222333"; + + // Program & School + String program = "2018-EN"; + String mincode = "222333"; + + String newCitizenship = "C"; String updateType = "UPD_GRAD"; @@ -333,11 +786,11 @@ public void testProcessCurrentStudentForGrad2018ENProgram_givenUpdated_Archived_ TraxGraduationUpdateDTO traxGraduationUpdate = new TraxGraduationUpdateDTO(); traxGraduationUpdate.setPen(pen); traxGraduationUpdate.setGraduationRequirementYear("2018"); - traxGraduationUpdate.setCitizenship("C"); - traxGraduationUpdate.setStudentGrade("11"); - traxGraduationUpdate.setSchoolOfRecord(newMincode); - traxGraduationUpdate.setStudentStatus("A"); - traxGraduationUpdate.setArchiveFlag("I"); + traxGraduationUpdate.setStudentGrade("12"); + traxGraduationUpdate.setSchoolOfRecord(mincode); + traxGraduationUpdate.setCitizenship(newCitizenship); + traxGraduationUpdate.setStudentStatus("T"); + traxGraduationUpdate.setArchiveFlag("A"); // Event Event event = new Event(); @@ -352,10 +805,11 @@ public void testProcessCurrentStudentForGrad2018ENProgram_givenUpdated_Archived_ currentStudent.setStudentID(studentID); currentStudent.setProgram(program); currentStudent.setStudentGrade("12"); - currentStudent.setStudentStatus("CUR"); - currentStudent.setCitizenship("C"); + currentStudent.setStudentStatus("TER"); + currentStudent.setCitizenship(null); currentStudent.setSchoolOfRecord(mincode); currentStudent.setSchoolAtGrad(mincode); + currentStudent.setGradDate(null); // Optional Program Codes currentStudent.getProgramCodes().add("XC"); currentStudent.getProgramCodes().add("FI"); @@ -380,7 +834,7 @@ public void testProcessCurrentStudentForGrad2018ENProgram_givenUpdated_Archived_ } @Test - public void testProcessArchivedStudentForGrad2018ENProgram_givenUpdated_Current_STUDENT_whenGradeAndSchoolAreChangedAndStatusIsArchived_then_returnsAPICallSuccess() { + public void testProcessDeceasedStudentForGrad2018ENProgram_givenUpdated_whenCitizenshipIsChanged_then_returnsAPICallSuccess() { // ID UUID studentID = UUID.randomUUID(); String pen = "111222333"; @@ -389,7 +843,7 @@ public void testProcessArchivedStudentForGrad2018ENProgram_givenUpdated_Current_ String program = "2018-EN"; String mincode = "222333"; - String newMincode = "333444"; + String newCitizenship = "C"; String updateType = "UPD_GRAD"; @@ -397,11 +851,11 @@ public void testProcessArchivedStudentForGrad2018ENProgram_givenUpdated_Current_ TraxGraduationUpdateDTO traxGraduationUpdate = new TraxGraduationUpdateDTO(); traxGraduationUpdate.setPen(pen); traxGraduationUpdate.setGraduationRequirementYear("2018"); - traxGraduationUpdate.setCitizenship("C"); - traxGraduationUpdate.setStudentGrade("11"); - traxGraduationUpdate.setSchoolOfRecord(newMincode); - traxGraduationUpdate.setStudentStatus("A"); - traxGraduationUpdate.setArchiveFlag("A"); + traxGraduationUpdate.setStudentGrade("12"); + traxGraduationUpdate.setSchoolOfRecord(mincode); + traxGraduationUpdate.setCitizenship(newCitizenship); + traxGraduationUpdate.setStudentStatus("D"); + traxGraduationUpdate.setArchiveFlag("I"); // Event Event event = new Event(); @@ -416,10 +870,11 @@ public void testProcessArchivedStudentForGrad2018ENProgram_givenUpdated_Current_ currentStudent.setStudentID(studentID); currentStudent.setProgram(program); currentStudent.setStudentGrade("12"); - currentStudent.setStudentStatus("ARC"); - currentStudent.setCitizenship("C"); + currentStudent.setStudentStatus("DEC"); + currentStudent.setCitizenship(null); currentStudent.setSchoolOfRecord(mincode); currentStudent.setSchoolAtGrad(mincode); + currentStudent.setGradDate(null); // Optional Program Codes currentStudent.getProgramCodes().add("XC"); currentStudent.getProgramCodes().add("FI"); @@ -444,7 +899,7 @@ public void testProcessArchivedStudentForGrad2018ENProgram_givenUpdated_Current_ } @Test - public void testProcessStudentForGrad2018ENProgram_givenUpdated_STUDENT_whenSlpDateAndCitizenshipAreChanged_then_returnsAPICallSuccess() { + public void testProcessStudentForGrad2018ENProgram_givenUpdated_STUDENT_whenProgramIsChangedTo2018PF_then_returnsAPICallSuccess() { // ID UUID studentID = UUID.randomUUID(); String pen = "111222333"; @@ -453,7 +908,7 @@ public void testProcessStudentForGrad2018ENProgram_givenUpdated_STUDENT_whenSlpD String program = "2018-EN"; String mincode = "222333"; - String newCitizenship = "C"; + String newMincode = "093444"; String updateType = "UPD_GRAD"; @@ -462,8 +917,7 @@ public void testProcessStudentForGrad2018ENProgram_givenUpdated_STUDENT_whenSlpD traxGraduationUpdate.setPen(pen); traxGraduationUpdate.setGraduationRequirementYear("2018"); traxGraduationUpdate.setStudentGrade("12"); - traxGraduationUpdate.setSchoolOfRecord(mincode); - traxGraduationUpdate.setCitizenship(newCitizenship); + traxGraduationUpdate.setSchoolOfRecord(newMincode); traxGraduationUpdate.setStudentStatus("A"); traxGraduationUpdate.setArchiveFlag("A"); @@ -481,13 +935,11 @@ public void testProcessStudentForGrad2018ENProgram_givenUpdated_STUDENT_whenSlpD currentStudent.setProgram(program); currentStudent.setStudentGrade("12"); currentStudent.setStudentStatus("CUR"); - currentStudent.setCitizenship(null); currentStudent.setSchoolOfRecord(mincode); currentStudent.setSchoolAtGrad(mincode); - currentStudent.setGradDate(null); // Optional Program Codes currentStudent.getProgramCodes().add("XC"); - currentStudent.getProgramCodes().add("FI"); + currentStudent.getProgramCodes().add("DD"); // Courses StudentCourse course1 = new StudentCourse(); course1.setCourseCode("Test"); @@ -509,7 +961,7 @@ public void testProcessStudentForGrad2018ENProgram_givenUpdated_STUDENT_whenSlpD } @Test - public void testProcessStudentForGrad2018ENProgram_givenUpdated_STUDENT_whenProgramIsChangedTo2018PF_then_returnsAPICallSuccess() { + public void testProcessArchivedNonGradStudentForGrad2018ENProgram_givenUpdated_whenProgramIsChangedTo2018PF_then_returnsAPICallSuccess() { // ID UUID studentID = UUID.randomUUID(); String pen = "111222333"; @@ -529,7 +981,7 @@ public void testProcessStudentForGrad2018ENProgram_givenUpdated_STUDENT_whenProg traxGraduationUpdate.setStudentGrade("12"); traxGraduationUpdate.setSchoolOfRecord(newMincode); traxGraduationUpdate.setStudentStatus("A"); - traxGraduationUpdate.setArchiveFlag("A"); + traxGraduationUpdate.setArchiveFlag("I"); // Event Event event = new Event(); @@ -544,7 +996,69 @@ public void testProcessStudentForGrad2018ENProgram_givenUpdated_STUDENT_whenProg currentStudent.setStudentID(studentID); currentStudent.setProgram(program); currentStudent.setStudentGrade("12"); - currentStudent.setStudentStatus("CUR"); + currentStudent.setStudentStatus("ARC"); + currentStudent.setSchoolOfRecord(mincode); + currentStudent.setSchoolAtGrad(mincode); + // Optional Program Codes + currentStudent.getProgramCodes().add("XC"); + currentStudent.getProgramCodes().add("DD"); + // Courses + StudentCourse course1 = new StudentCourse(); + course1.setCourseCode("Test"); + course1.setCourseLevel("12"); + course1.setCourseName("Test Course"); + course1.setCreditsUsedForGrad(Integer.valueOf("4")); + course1.setCompletedCoursePercentage(Double.valueOf("92.00")); + course1.setCredits(Integer.valueOf("4")); + course1.setPen(pen); + currentStudent.getCourses().add(course1); + + when(this.studentProcess.loadStudentData(eq(pen), any())).thenReturn(currentStudent); + when(this.eventRepository.findByEventId(event.getEventId())).thenReturn(Optional.of(event)); + + studentGraduationUpdateEventService.processEvent(traxGraduationUpdate, event); + + assertThat(event).isNotNull(); + assertThat(event.getEventStatus()).isEqualTo(EventStatus.PROCESSED.name()); + } + + @Test + public void testProcessDeceasedNonGradStudentForGrad2018ENProgram_givenUpdated_whenProgramIsChangedTo2018PF_then_returnsAPICallSuccess() { + // ID + UUID studentID = UUID.randomUUID(); + String pen = "111222333"; + + // Program & School + String program = "2018-EN"; + String mincode = "222333"; + + String newMincode = "093444"; + + String updateType = "UPD_GRAD"; + + // TraxGraduationUpdateDTO + TraxGraduationUpdateDTO traxGraduationUpdate = new TraxGraduationUpdateDTO(); + traxGraduationUpdate.setPen(pen); + traxGraduationUpdate.setGraduationRequirementYear("2018"); + traxGraduationUpdate.setStudentGrade("12"); + traxGraduationUpdate.setSchoolOfRecord(newMincode); + traxGraduationUpdate.setStudentStatus("D"); + traxGraduationUpdate.setArchiveFlag("I"); + + // Event + Event event = new Event(); + event.setEventType(EventType.UPD_GRAD.name()); + event.setEventStatus(EventStatus.DB_COMMITTED.name()); + event.setActivityCode(updateType); + event.setEventId(UUID.randomUUID()); + + // current GRAD Student + StudentGradDTO currentStudent = new StudentGradDTO(); + // GraduationStudentRecord + currentStudent.setStudentID(studentID); + currentStudent.setProgram(program); + currentStudent.setStudentGrade("12"); + currentStudent.setStudentStatus("DEC"); currentStudent.setSchoolOfRecord(mincode); currentStudent.setSchoolAtGrad(mincode); // Optional Program Codes @@ -1115,6 +1629,136 @@ public void testProcessGraduatedStudentForSCCP_givenUpdated_STUDENT_whenSlpDateI assertThat(event.getEventStatus()).isEqualTo(EventStatus.PROCESSED.name()); } + @Test + public void testProcessArchivedNonGradStudentForSCCP_givenUpdated_whenSlpDateIsChanged_then_returnsAPICallSuccess() { + // ID + UUID studentID = UUID.randomUUID(); + String pen = "111222333"; + + // Program & School + String program = "SCCP"; + String mincode = "093333"; + + String newSlpDate = "208006"; + + String updateType = "UPD_GRAD"; + + // TraxGraduationUpdateDTO + TraxGraduationUpdateDTO traxGraduationUpdate = new TraxGraduationUpdateDTO(); + traxGraduationUpdate.setPen(pen); + traxGraduationUpdate.setGraduationRequirementYear("SCCP"); + traxGraduationUpdate.setStudentGrade("12"); + traxGraduationUpdate.setSchoolOfRecord(mincode); + traxGraduationUpdate.setSlpDate(newSlpDate); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("I"); + + // Event + Event event = new Event(); + event.setEventType(EventType.UPD_GRAD.name()); + event.setEventStatus(EventStatus.DB_COMMITTED.name()); + event.setActivityCode(updateType); + event.setEventId(UUID.randomUUID()); + + // current GRAD Student + StudentGradDTO currentStudent = new StudentGradDTO(); + currentStudent.setBirthday("2000-01-01"); + // GraduationStudentRecord + currentStudent.setStudentID(studentID); + currentStudent.setProgram(program); + currentStudent.setStudentGrade("12"); + currentStudent.setStudentStatus("ARC"); + currentStudent.setSchoolOfRecord(mincode); + currentStudent.setSchoolAtGrad(mincode); + // Optional Program Codes + currentStudent.getProgramCodes().add("XC"); + currentStudent.getProgramCodes().add("DD"); + + // Courses + StudentCourse course1 = new StudentCourse(); + course1.setCourseCode("Test"); + course1.setCourseLevel("12"); + course1.setCourseName("Test Course"); + course1.setCreditsUsedForGrad(Integer.valueOf("4")); + course1.setCompletedCoursePercentage(Double.valueOf("92.00")); + course1.setCredits(Integer.valueOf("4")); + course1.setPen(pen); + currentStudent.getCourses().add(course1); + + when(this.studentProcess.loadStudentData(eq(pen), any())).thenReturn(currentStudent); + when(this.eventRepository.findByEventId(event.getEventId())).thenReturn(Optional.of(event)); + + studentGraduationUpdateEventService.processEvent(traxGraduationUpdate, event); + + assertThat(event).isNotNull(); + assertThat(event.getEventStatus()).isEqualTo(EventStatus.PROCESSED.name()); + } + + @Test + public void testProcessDeceasedNonGradStudentForSCCP_givenUpdated_whenSlpDateIsChanged_then_returnsAPICallSuccess() { + // ID + UUID studentID = UUID.randomUUID(); + String pen = "111222333"; + + // Program & School + String program = "SCCP"; + String mincode = "093333"; + + String newSlpDate = "208006"; + + String updateType = "UPD_GRAD"; + + // TraxGraduationUpdateDTO + TraxGraduationUpdateDTO traxGraduationUpdate = new TraxGraduationUpdateDTO(); + traxGraduationUpdate.setPen(pen); + traxGraduationUpdate.setGraduationRequirementYear("SCCP"); + traxGraduationUpdate.setStudentGrade("12"); + traxGraduationUpdate.setSchoolOfRecord(mincode); + traxGraduationUpdate.setSlpDate(newSlpDate); + traxGraduationUpdate.setStudentStatus("D"); + traxGraduationUpdate.setArchiveFlag("I"); + + // Event + Event event = new Event(); + event.setEventType(EventType.UPD_GRAD.name()); + event.setEventStatus(EventStatus.DB_COMMITTED.name()); + event.setActivityCode(updateType); + event.setEventId(UUID.randomUUID()); + + // current GRAD Student + StudentGradDTO currentStudent = new StudentGradDTO(); + currentStudent.setBirthday("2000-01-01"); + // GraduationStudentRecord + currentStudent.setStudentID(studentID); + currentStudent.setProgram(program); + currentStudent.setStudentGrade("12"); + currentStudent.setStudentStatus("DEC"); + currentStudent.setSchoolOfRecord(mincode); + currentStudent.setSchoolAtGrad(mincode); + // Optional Program Codes + currentStudent.getProgramCodes().add("XC"); + currentStudent.getProgramCodes().add("DD"); + + // Courses + StudentCourse course1 = new StudentCourse(); + course1.setCourseCode("Test"); + course1.setCourseLevel("12"); + course1.setCourseName("Test Course"); + course1.setCreditsUsedForGrad(Integer.valueOf("4")); + course1.setCompletedCoursePercentage(Double.valueOf("92.00")); + course1.setCredits(Integer.valueOf("4")); + course1.setPen(pen); + currentStudent.getCourses().add(course1); + + when(this.studentProcess.loadStudentData(eq(pen), any())).thenReturn(currentStudent); + when(this.eventRepository.findByEventId(event.getEventId())).thenReturn(Optional.of(event)); + + studentGraduationUpdateEventService.processEvent(traxGraduationUpdate, event); + + assertThat(event).isNotNull(); + assertThat(event.getEventStatus()).isEqualTo(EventStatus.PROCESSED.name()); + } + @Test public void testProcessGraduatedStudentForGrad2018ENProgram_givenUpdated_STUDENT_whenGradeAndSchoolAreChanged_then_returnsAPICallSuccess() { // ID From 1b48b50a97d92f591da2a55b20fa8f69c43c2c4e Mon Sep 17 00:00:00 2001 From: Jinil Sung Date: Mon, 23 Sep 2024 15:05:17 -0700 Subject: [PATCH 2/2] Clean up the codes. Clean up the codes. --- .../service/student/StudentBaseService.java | 23 ------------------- .../StudentGraduationUpdateEventService.java | 5 ---- 2 files changed, 28 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentBaseService.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentBaseService.java index 7d4d6bf..87654c5 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentBaseService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentBaseService.java @@ -130,29 +130,6 @@ protected void populateNewBatchFlags(StudentGradDTO currentStudent) { } } - protected void validateAndAdjustNewBatchFlags(StudentGradDTO currentStudent) { - String currentStudentStatus = currentStudent.getStudentStatus(); - String newStudentStatus = currentStudent.getNewStudentStatus(); - // 1. If a student in GRAD is ARC/TER then do not set TVR flag - if (STUDENT_STATUS_ARCHIVED.equalsIgnoreCase(currentStudentStatus) || STUDENT_STATUS_TERMINATED.equalsIgnoreCase(currentStudentStatus)) { - currentStudent.setNewRecalculateProjectedGrad(null); - } - // 2. If a student in GRAD is MER then do not set Transcript & TVR flags - if (STUDENT_STATUS_MERGED.equalsIgnoreCase(currentStudentStatus)) { - currentStudent.setNewRecalculateGradStatus(null); - currentStudent.setNewRecalculateProjectedGrad(null); - } - // 3. If a student in GRAD is changed to ARC/TER then set TVR flag to NULL - if (STUDENT_STATUS_ARCHIVED.equalsIgnoreCase(newStudentStatus) || STUDENT_STATUS_TERMINATED.equalsIgnoreCase(newStudentStatus)) { - currentStudent.setNewRecalculateProjectedGrad(NULL_VALUE); - } - // 4. If a student in GRAD is changed to MER then set Transcript & TVR flags to NULL - if (STUDENT_STATUS_MERGED.equalsIgnoreCase(newStudentStatus)) { - currentStudent.setNewRecalculateGradStatus(NULL_VALUE); - currentStudent.setNewRecalculateProjectedGrad(NULL_VALUE); - } - } - private void updateProgramCountsInSummary(ConversionStudentSummaryDTO summary, String programCode, boolean isGraduated) { if (summary != null) { summary.increment(programCode, isGraduated); diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentGraduationUpdateEventService.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentGraduationUpdateEventService.java index 011901e..310c6b2 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentGraduationUpdateEventService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentGraduationUpdateEventService.java @@ -68,7 +68,6 @@ public void processEvent(T request, Event event) { public void processStudent(TraxGraduationUpdateDTO updateGrad, StudentGradDTO currentStudent, String accessToken) { boolean isChanged = false; - boolean isStudentStatusChanged = false; log.info(" Process Student : studentID = {}, pen = {}", currentStudent.getStudentID(), updateGrad.getPen()); // Processing order is important for the first 3 fields below. @@ -114,13 +113,9 @@ public void processStudent(TraxGraduationUpdateDTO updateGrad, StudentGradDTO cu processStudentStatus(currentStudent, newStudentStatus); log.info(" => student status : current = {}, request = {}", currentStudent.getStudentStatus(), currentStudent.getNewStudentStatus()); isChanged = true; - isStudentStatusChanged = true; } if (isChanged) { - if (isStudentStatusChanged) { - validateAndAdjustNewBatchFlags(currentStudent); - } log.info(" Save Student : studentID = {}, pen = {}", currentStudent.getStudentID(), updateGrad.getPen()); studentProcess.saveGraduationStudent(updateGrad.getPen(), currentStudent, UPD_GRAD, accessToken); }