From 8b5981a778cdcab8246a19b1f2f55e91439594af Mon Sep 17 00:00:00 2001 From: Jinil Sung Date: Thu, 10 Oct 2024 15:27:36 -0700 Subject: [PATCH] GRAD2-3000: NEWSTUDENT event is retried when it is failed. GRAD2-3000: NEWSTUDENT event is retried when it is failed. --- .../service/student/NewStudentEventService.java | 8 +++++++- .../service/NewStudentEventServiceTest.java | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/NewStudentEventService.java b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/NewStudentEventService.java index dc1a108c..7c8b9ffe 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/NewStudentEventService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/dataconversion/service/student/NewStudentEventService.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.dataconversion.service.student; +import ca.bc.gov.educ.api.dataconversion.constant.ConversionResultType; import ca.bc.gov.educ.api.dataconversion.entity.Event; import ca.bc.gov.educ.api.dataconversion.model.*; import ca.bc.gov.educ.api.dataconversion.process.StudentProcess; @@ -41,6 +42,7 @@ public NewStudentEventService(EventRepository eventRepository, @Override public void processEvent(T request, Event event) { ConvGradStudent convStudent = (ConvGradStudent) request; + ConvGradStudent result = null; if (convStudent != null && constants.isGradUpdateEnabled()) { // Get Access Token ResponseObj res = restUtils.getTokenResponseObject(); @@ -51,13 +53,17 @@ public void processEvent(T request, Event event) { ConversionStudentSummaryDTO summary = new ConversionStudentSummaryDTO(); summary.setAccessToken(accessToken); try { - studentProcess.convertStudent(convStudent, summary, false, true); + result = studentProcess.convertStudent(convStudent, summary, false, true); } catch (Exception e) { ConversionAlert error = new ConversionAlert(); error.setItem(convStudent.getPen()); error.setReason("Unexpected Exception is occurred: " + e.getLocalizedMessage()); summary.getErrors().add(error); log.error("unknown exception: " + e.getLocalizedMessage()); + return; + } + if (result == null || ConversionResultType.FAILURE.equals(result.getResult())) { + return; } } diff --git a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/NewStudentEventServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/NewStudentEventServiceTest.java index 08363b3f..b086dd5d 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/NewStudentEventServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/dataconversion/service/NewStudentEventServiceTest.java @@ -59,7 +59,7 @@ public class NewStudentEventServiceTest { private EducGradDataConversionApiConstants constants; @Test - public void testProcessStudentForGrad2018ENProgram_givenNew_STUDENT_returnsAPICallSuccess() { + public void testProcessStudentForGrad2018ENProgram_givenNew_STUDENT_returnsAPICallSuccess() throws Exception { // ID UUID studentID = UUID.randomUUID(); String pen = "111222333"; @@ -91,6 +91,7 @@ public void testProcessStudentForGrad2018ENProgram_givenNew_STUDENT_returnsAPICa event.setEventId(UUID.randomUUID()); when(this.eventRepository.findByEventId(event.getEventId())).thenReturn(Optional.of(event)); + when(this.studentProcess.convertStudent(any(), any(), eq(false), eq(true))).thenReturn(traxNewStudent); newStudentEventService.processEvent(traxNewStudent, event); @@ -132,6 +133,6 @@ public void testProcessStudent_whenException_isThrown_returnsAPICallError() thro newStudentEventService.processEvent(traxNewStudent, event); assertThat(event).isNotNull(); - assertThat(event.getEventStatus()).isEqualTo(EventStatus.PROCESSED.name()); + assertThat(event.getEventStatus()).isNotEqualTo(EventStatus.PROCESSED.name()); } }