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 f3afbcfa..d96b951d 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 @@ -73,9 +73,6 @@ public void processStudent(TraxGraduationUpdateDTO updateGrad, StudentGradDTO cu boolean isChanged = false; log.info(" Process Student : studentID = {}, pen = {}", currentStudent.getStudentID(), updateGrad.getPen()); - if (currentStudent.isArchived() && currentStudent.isGraduated()) { - return; - } // Processing order is important for the first 3 fields below. String newStudentStatus = getGradStudentStatus(updateGrad.getStudentStatus(), updateGrad.getArchiveFlag()); // 0. Student Status @@ -92,87 +89,89 @@ public void processStudent(TraxGraduationUpdateDTO updateGrad, StudentGradDTO cu log.info(" => student status : current = {}, request = {}", currentStudent.getStudentStatus(), currentStudent.getNewStudentStatus()); isChanged = true; } - // 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())) { + 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(" => grad program : current = {}, request = {}", currentStudent.getProgram(), currentStudent.getNewProgram()); + log.info(" => school of record : current = {}, request = {}", currentStudent.getSchoolOfRecord(), currentStudent.getNewSchoolOfRecord()); 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"); + // 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); } - 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()) { + // 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"); } - } else { - // TVR - currentStudent.setNewRecalculateProjectedGrad("Y"); + log.info(" => student grade : current = {}, request = {}", currentStudent.getStudentGrade(), currentStudent.getNewStudentGrade()); + isChanged = true; } - 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()) { + // 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"); } - } else { - // TVR - currentStudent.setNewRecalculateProjectedGrad("Y"); + log.info(" => student citizenship : current = {}, request = {}", currentStudent.getCitizenship(), currentStudent.getNewCitizenship()); + isChanged = true; } - log.info(" => student citizenship : current = {}, request = {}", currentStudent.getCitizenship(), currentStudent.getNewCitizenship()); - isChanged = true; } if (isChanged) { 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 20a38f27..afa2c8b3 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 @@ -75,6 +75,8 @@ public void testProcessStudentForGrad2018ENProgram_givenUpdated_STUDENT_returnsA traxGraduationUpdate.setGraduationRequirementYear("2018"); traxGraduationUpdate.setStudentGrade("12"); traxGraduationUpdate.setSchoolOfRecord(mincode); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("A"); // Event Event event = new Event(); @@ -141,6 +143,8 @@ public void testProcessStudentForGrad2018ENProgram_givenUpdated_STUDENT_whenGrad traxGraduationUpdate.setCitizenship("C"); traxGraduationUpdate.setStudentGrade("11"); traxGraduationUpdate.setSchoolOfRecord(newMincode); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("A"); // Event Event event = new Event(); @@ -183,7 +187,7 @@ public void testProcessStudentForGrad2018ENProgram_givenUpdated_STUDENT_whenGrad } @Test - public void testProcessStudentForGrad2018ENProgram_givenUpdated_Archived_STUDENT_whenGradeAndSchoolAreChanged_then_returnsAPICallSuccess() { + public void testProcessArchivedStudentForGrad2018ENProgram_givenUpdated_Archived_STUDENT_whenGradeAndSchoolAreChanged_then_returnsAPICallSuccess() { // ID UUID studentID = UUID.randomUUID(); String pen = "111222333"; @@ -203,6 +207,201 @@ public void testProcessStudentForGrad2018ENProgram_givenUpdated_Archived_STUDENT 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("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 testProcessCurrentGraduatedStudentForGrad2018ENProgram_givenUpdated_Archived_STUDENT_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("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); + 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 + 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("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_whenGradeAndSchoolAreChangedAndStatusIsArchived_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(); @@ -265,6 +464,8 @@ public void testProcessStudentForGrad2018ENProgram_givenUpdated_STUDENT_whenSlpD traxGraduationUpdate.setStudentGrade("12"); traxGraduationUpdate.setSchoolOfRecord(mincode); traxGraduationUpdate.setCitizenship(newCitizenship); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("A"); // Event Event event = new Event(); @@ -327,6 +528,8 @@ public void testProcessStudentForGrad2018ENProgram_givenUpdated_STUDENT_whenProg traxGraduationUpdate.setGraduationRequirementYear("2018"); traxGraduationUpdate.setStudentGrade("12"); traxGraduationUpdate.setSchoolOfRecord(newMincode); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("A"); // Event Event event = new Event(); @@ -387,6 +590,8 @@ public void testProcessStudentForGrad2018PFProgram_givenUpdated_STUDENT_whenProg traxGraduationUpdate.setGraduationRequirementYear("2018"); traxGraduationUpdate.setStudentGrade("12"); traxGraduationUpdate.setSchoolOfRecord(newMincode); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("A"); // Event Event event = new Event(); @@ -447,6 +652,8 @@ public void testProcessStudentFor1950AdultProgram_givenUpdated_STUDENT_whenProgr traxGraduationUpdate.setGraduationRequirementYear("2018"); traxGraduationUpdate.setStudentGrade("12"); traxGraduationUpdate.setSchoolOfRecord(newMincode); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("A"); // Event Event event = new Event(); @@ -508,6 +715,8 @@ public void testProcessStudentFor2018EN_givenUpdated_STUDENT_whenProgramIsChange traxGraduationUpdate.setGraduationRequirementYear("1950"); traxGraduationUpdate.setStudentGrade("AD"); traxGraduationUpdate.setSchoolOfRecord(newMincode); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("A"); // Event Event event = new Event(); @@ -572,6 +781,8 @@ public void testProcessStudentFor2018ENProgram_givenUpdated_STUDENT_whenProgramI traxGraduationUpdate.setStudentGrade("12"); traxGraduationUpdate.setSchoolOfRecord(newMincode); traxGraduationUpdate.setSlpDate(newSlpDate); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("A"); // Event Event event = new Event(); @@ -636,6 +847,8 @@ public void testProcessStudentFor2018PFProgram_givenUpdated_STUDENT_whenProgramI traxGraduationUpdate.setStudentGrade("12"); traxGraduationUpdate.setSchoolOfRecord(newMincode); traxGraduationUpdate.setSlpDate(newSlpDate); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("A"); // Event Event event = new Event(); @@ -698,6 +911,8 @@ public void testProcessStudentForSCCPProgram_givenUpdated_STUDENT_whenProgramIsC traxGraduationUpdate.setGraduationRequirementYear("2018"); traxGraduationUpdate.setStudentGrade("12"); traxGraduationUpdate.setSchoolOfRecord(newMincode); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("A"); // Event Event event = new Event(); @@ -791,6 +1006,8 @@ public void testProcessGraduatedStudentForGrad2018ENProgram_givenUpdated_STUDENT traxGraduationUpdate.setGraduationRequirementYear("2018"); traxGraduationUpdate.setStudentGrade("12"); traxGraduationUpdate.setSchoolOfRecord(newMincode); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("A"); // Event Event event = new Event(); @@ -853,6 +1070,8 @@ public void testProcessGraduatedStudentForSCCP_givenUpdated_STUDENT_whenSlpDateI traxGraduationUpdate.setStudentGrade("12"); traxGraduationUpdate.setSchoolOfRecord(mincode); traxGraduationUpdate.setSlpDate(newSlpDate); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("A"); // Event Event event = new Event(); @@ -917,6 +1136,8 @@ public void testProcessGraduatedStudentForGrad2018ENProgram_givenUpdated_STUDENT traxGraduationUpdate.setCitizenship("C"); traxGraduationUpdate.setStudentGrade("11"); traxGraduationUpdate.setSchoolOfRecord(newMincode); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("A"); // Event Event event = new Event(); @@ -980,6 +1201,8 @@ public void testProcessGraduatedStudentForGrad2018ENProgram_givenUpdated_STUDENT traxGraduationUpdate.setStudentGrade("12"); traxGraduationUpdate.setSchoolOfRecord(mincode); traxGraduationUpdate.setCitizenship(newCitizenship); + traxGraduationUpdate.setStudentStatus("A"); + traxGraduationUpdate.setArchiveFlag("A"); // Event Event event = new Event();