From 294e1813e3405dbdfaa8ac5857e76231393a78dc Mon Sep 17 00:00:00 2001 From: Jinil Sung Date: Tue, 25 Jun 2024 15:05:33 -0700 Subject: [PATCH] GRAD2-2673: task is complete. GRAD2-2673: task is complete. --- .../ChoreographEventHandler.java | 5 - .../dataconversion/constant/EventType.java | 1 - .../model/TraxStudentStatusUpdateDTO.java | 22 --- .../process/StudentProcess.java | 8 - .../StudentStatusUpdateEventService.java | 102 ------------ .../process/StudentProcessTest.java | 2 +- .../StudentStatusUpdateEventServiceTest.java | 150 ------------------ 7 files changed, 1 insertion(+), 289 deletions(-) delete mode 100644 api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/TraxStudentStatusUpdateDTO.java delete mode 100644 api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentStatusUpdateEventService.java delete mode 100644 api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentStatusUpdateEventServiceTest.java diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/choreographer/ChoreographEventHandler.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/choreographer/ChoreographEventHandler.java index 59c75eb5..d76d6121 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/choreographer/ChoreographEventHandler.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/choreographer/ChoreographEventHandler.java @@ -56,11 +56,6 @@ public void handleEvent(@NonNull final Event event) { final TraxGraduationUpdateDTO updateGrad = JsonUtil.getJsonObjectFromString(TraxGraduationUpdateDTO.class, event.getEventPayload()); this.eventServiceMap.get(UPD_GRAD.toString()).processEvent(updateGrad, event); break; - case "UPD_STD_STATUS": // UPD_STD_STATUS will be deprecated - log.debug("Processing UPD_STD_STATUS event record :: {} ", event); - final TraxStudentStatusUpdateDTO updateStudentStatus = JsonUtil.getJsonObjectFromString(TraxStudentStatusUpdateDTO.class, event.getEventPayload()); - this.eventServiceMap.get(UPD_STD_STATUS.toString()).processEvent(updateStudentStatus, event); - break; case "XPROGRAM": log.debug("Processing XPROGRAM event record :: {} ", event); final TraxXProgramDTO xprogram = JsonUtil.getJsonObjectFromString(TraxXProgramDTO.class, event.getEventPayload()); diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/constant/EventType.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/constant/EventType.java index 07ab2513..0f99fa0e 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/constant/EventType.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/constant/EventType.java @@ -13,7 +13,6 @@ public enum EventType { NEWSTUDENT, UPD_DEMOG, UPD_GRAD, - UPD_STD_STATUS, // UPD_STD_STATUS will be deprecated XPROGRAM, ASSESSMENT, COURSE, diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/TraxStudentStatusUpdateDTO.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/TraxStudentStatusUpdateDTO.java deleted file mode 100644 index 047e1c66..00000000 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/model/TraxStudentStatusUpdateDTO.java +++ /dev/null @@ -1,22 +0,0 @@ -package ca.bc.gov.educ.api.dataconversion.model; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@Builder -@AllArgsConstructor -@NoArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -// UPD_STD_STATUS will be deprecated -public class TraxStudentStatusUpdateDTO extends TraxStudentUpdateDTO { - - // STUD_STATUS - private String studentStatus; - // ARCHIVE_FLAG - private String archiveFlag; - -} 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 8846fc94..70f59889 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 @@ -490,14 +490,6 @@ public void saveGraduationStudent(String pen, StudentGradDTO gradStudent, EventT requestDTO.getUpdateFields().add(field); } } - // UPD_STD_STATUS will be deprecated - // Student Status - if (eventType == EventType.UPD_STD_STATUS && StringUtils.isNotBlank(gradStudent.getNewStudentStatus())) { - OngoingUpdateFieldDTO field = OngoingUpdateFieldDTO.builder() - .type(FieldType.STRING).name(FieldName.STUDENT_STATUS).value(gradStudent.getNewStudentStatus()) - .build(); - requestDTO.getUpdateFields().add(field); - } // Others ====================================================== // Batch Flags diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentStatusUpdateEventService.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentStatusUpdateEventService.java deleted file mode 100644 index 202b7116..00000000 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/StudentStatusUpdateEventService.java +++ /dev/null @@ -1,102 +0,0 @@ -package ca.bc.gov.educ.api.dataconversion.service.student; - -import ca.bc.gov.educ.api.dataconversion.entity.Event; -import ca.bc.gov.educ.api.dataconversion.model.ResponseObj; -import ca.bc.gov.educ.api.dataconversion.model.StudentGradDTO; -import ca.bc.gov.educ.api.dataconversion.model.TraxStudentStatusUpdateDTO; -import ca.bc.gov.educ.api.dataconversion.process.StudentProcess; -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.RestUtils; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.time.LocalDateTime; - -import static ca.bc.gov.educ.api.dataconversion.constant.EventStatus.PROCESSED; -import static ca.bc.gov.educ.api.dataconversion.constant.EventType.UPD_STD_STATUS; - -@Service -@Slf4j -// UPD_STD_STATUS will be deprecated -public class StudentStatusUpdateEventService extends StudentBaseService implements EventService { - - private final EventRepository eventRepository; - - private final StudentProcess studentProcess; - private final RestUtils restUtils; - - private final EducGradDataConversionApiConstants constants; - - @Autowired - public StudentStatusUpdateEventService(EventRepository eventRepository, - StudentProcess studentProcess, - RestUtils restUtils, - EducGradDataConversionApiConstants constants) { - this.eventRepository = eventRepository; - this.studentProcess = studentProcess; - this.restUtils = restUtils; - this.constants = constants; - } - - @Override - public void processEvent(T request, Event event) { - TraxStudentStatusUpdateDTO studentStatusUpdate = (TraxStudentStatusUpdateDTO) request; - if (studentStatusUpdate != null && constants.isGradUpdateEnabled()) { - // Get Access Token - ResponseObj res = restUtils.getTokenResponseObject(); - String accessToken = null; - if (res != null) { - accessToken = res.getAccess_token(); - } - // Load grad student - StudentGradDTO currentStudent = studentProcess.loadStudentData(studentStatusUpdate.getPen(), accessToken); - if (currentStudent != null) { - processStudent(studentStatusUpdate, currentStudent, accessToken); - } else { - return; - } - } - - var existingEvent = eventRepository.findByEventId(event.getEventId()); - existingEvent.ifPresent(eventRecord -> { - eventRecord.setEventStatus(PROCESSED.toString()); - eventRecord.setUpdateDate(LocalDateTime.now()); - eventRepository.save(eventRecord); - }); - } - - public void processStudent(TraxStudentStatusUpdateDTO studentStatusUpdate, StudentGradDTO currentStudent, String accessToken) { - boolean isChanged = false; - - log.info(" Process Student Status : studentID = {}, pen = {}", currentStudent.getStudentID(), studentStatusUpdate.getPen()); - String newStudentStatus = getGradStudentStatus(studentStatusUpdate.getStudentStatus(), studentStatusUpdate.getArchiveFlag()); - // 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"); - } - log.info(" => student status : current = {}, request = {}", currentStudent.getStudentStatus(), currentStudent.getNewStudentStatus()); - isChanged = true; - } - - if (isChanged) { - log.info(" Save Student : studentID = {}, pen = {}", currentStudent.getStudentID(), studentStatusUpdate.getPen()); - studentProcess.saveGraduationStudent(studentStatusUpdate.getPen(), currentStudent, UPD_STD_STATUS, accessToken); - } - } - - @Override - public String getEventType() { - return UPD_STD_STATUS.toString(); - } -} diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/process/StudentProcessTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/process/StudentProcessTest.java index e0121bb3..fce7d4e4 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/process/StudentProcessTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/process/StudentProcessTest.java @@ -916,7 +916,7 @@ public void testSaveGraduationStudent_whenStudentStatus_isChanged_then_returnAPI boolean exceptionIsThrown = false; try { - studentProcess.saveGraduationStudent(pen, requestStudent, EventType.UPD_STD_STATUS, "123"); + studentProcess.saveGraduationStudent(pen, requestStudent, EventType.UPD_GRAD, "123"); } catch (Exception e) { exceptionIsThrown = true; } diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentStatusUpdateEventServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentStatusUpdateEventServiceTest.java deleted file mode 100644 index 8c944ab5..00000000 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/StudentStatusUpdateEventServiceTest.java +++ /dev/null @@ -1,150 +0,0 @@ -package ca.bc.gov.educ.api.dataconversion.service; - -import ca.bc.gov.educ.api.dataconversion.constant.EventStatus; -import ca.bc.gov.educ.api.dataconversion.constant.EventType; -import ca.bc.gov.educ.api.dataconversion.entity.Event; -import ca.bc.gov.educ.api.dataconversion.messaging.NatsConnection; -import ca.bc.gov.educ.api.dataconversion.messaging.jetstream.Subscriber; -import ca.bc.gov.educ.api.dataconversion.model.*; -import ca.bc.gov.educ.api.dataconversion.repository.EventRepository; -import ca.bc.gov.educ.api.dataconversion.process.StudentProcess; -import ca.bc.gov.educ.api.dataconversion.service.student.StudentStatusUpdateEventService; -import ca.bc.gov.educ.api.dataconversion.util.EducGradDataConversionApiConstants; -import ca.bc.gov.educ.api.dataconversion.util.RestUtils; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.reactive.function.client.WebClient; - -import java.util.Arrays; -import java.util.Optional; -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.when; - -@RunWith(SpringRunner.class) -@SpringBootTest -@ActiveProfiles("test") -public class StudentStatusUpdateEventServiceTest { - - @Autowired - StudentStatusUpdateEventService studentStatusUpdateEventService; - - @MockBean - EventRepository eventRepository; - - @MockBean - StudentProcess studentProcess; - - @MockBean - RestUtils restUtils; - - @MockBean - WebClient webClient; - - // NATS - @MockBean - private NatsConnection natsConnection; - @MockBean - private Subscriber subscriber; - - @Autowired - private EducGradDataConversionApiConstants constants; - - @Test - public void testProcessStudentStatusForGrad2018ENProgram_givenUpdated_UPD_STD_STATUS_then_returnsAPICallSuccess() { - // ID - UUID studentID = UUID.randomUUID(); - String pen = "111222333"; - - // Program & School - String program = "2018-EN"; - String mincode = "222333"; - - String updateType = "UPD_STD_STATUS"; - - // TraxStudentStatusUpdateDTO - TraxStudentStatusUpdateDTO traxStudentStatusUpdate = new TraxStudentStatusUpdateDTO(); - traxStudentStatusUpdate.setPen(pen); - traxStudentStatusUpdate.setStudentStatus("T"); - traxStudentStatusUpdate.setArchiveFlag("I"); - - // Event - Event event = new Event(); - event.setEventType(EventType.UPD_STD_STATUS.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.setSchoolOfRecord(mincode); - currentStudent.setSchoolAtGrad(mincode); - - when(this.studentProcess.loadStudentData(eq(pen), any())).thenReturn(currentStudent); - - // ConvGradStudent = traxStudent with the recent updated info - ConvGradStudent traxStudent = ConvGradStudent.builder().pen(pen) - .program(program) - .studentGrade("12") - .studentStatus("A") - .archiveFlag("A") - .schoolOfRecord(mincode) - .graduationRequirementYear("2018").build(); - ConversionStudentSummaryDTO summary = new ConversionStudentSummaryDTO(); - summary.setAccessToken("123"); - - when(this.restUtils.getTraxStudentMasterDataByPen(eq(pen), any())).thenReturn(Arrays.asList(traxStudent)); - when(this.eventRepository.findByEventId(event.getEventId())).thenReturn(Optional.of(event)); - - studentStatusUpdateEventService.processEvent(traxStudentStatusUpdate, event); - - assertThat(event).isNotNull(); - assertThat(event.getEventStatus()).isEqualTo(EventStatus.PROCESSED.name()); - } - - @Test - public void testProcessStudentStatus_whenException_isThrown_returnsAPICallError() throws Exception { - // ID - String pen = "111222333"; - - // Program & School - String program = "2018-EN"; - String mincode = "222333"; - - String updateType = "UPD_STD_STATUS"; - - TraxStudentStatusUpdateDTO traxStudentUpdate = TraxStudentStatusUpdateDTO.builder() - .studentStatus("A") - .archiveFlag("I") - .build(); - traxStudentUpdate.setPen(pen); - - // Event - Event event = new Event(); - event.setEventType(EventType.UPD_STD_STATUS.name()); - event.setEventStatus(EventStatus.DB_COMMITTED.name()); - event.setActivityCode(updateType); - event.setEventId(UUID.randomUUID()); - - when(this.eventRepository.findByEventId(event.getEventId())).thenReturn(Optional.of(event)); - when(this.studentProcess.convertStudent(any(), any(), eq(false), eq(true))).thenThrow(new RuntimeException("Test Exception is thrown!")); - - studentStatusUpdateEventService.processEvent(traxStudentUpdate, event); - - assertThat(event).isNotNull(); - assertThat(event.getEventStatus()).isEqualTo(EventStatus.DB_COMMITTED.name()); - } -}