From 13fbc5b95e79ada1b05f403a6c97c66d9bd8a5dd Mon Sep 17 00:00:00 2001 From: Jinil Sung Date: Thu, 14 Nov 2024 09:57:29 -0800 Subject: [PATCH 01/14] GRAD2-3019: task is complete. GRAD2-3019: task is complete. --- .../gradstudent/constant/TraxEventType.java | 1 - .../model/dto/GradSearchStudent.java | 1 + .../model/dto/GraduationStudentRecord.java | 2 +- ...duationStudentRecordHistoryRepository.java | 56 +++++++++++++++ .../service/DataConversionService.java | 22 +++++- .../service/DataConversionServiceTest.java | 68 ++++++++++++++++++- 6 files changed, 143 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/TraxEventType.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/TraxEventType.java index 81724cc4..19334f90 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/TraxEventType.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/TraxEventType.java @@ -10,7 +10,6 @@ public enum TraxEventType { NEWSTUDENT, UPD_DEMOG, UPD_GRAD, - UPD_STD_STATUS, XPROGRAM, ASSESSMENT, COURSE, diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GradSearchStudent.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GradSearchStudent.java index 5a7a14fd..f88ca279 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GradSearchStudent.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GradSearchStudent.java @@ -42,6 +42,7 @@ public class GradSearchStudent { private String trueStudentID; private String program; private String schoolOfRecord; + private String schoolOfRecordId; private String schoolOfRecordName; private String schoolOfRecordindependentAffiliation; private String studentGrade; diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GraduationStudentRecord.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GraduationStudentRecord.java index f5061a06..6e6ed1cc 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GraduationStudentRecord.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GraduationStudentRecord.java @@ -26,7 +26,7 @@ public class GraduationStudentRecord extends BaseModel { private String recalculateGradStatus; private String schoolOfRecord; private String schoolName; - private String studentGrade; + private String studentGrade; private String studentStatus; private String studentStatusName; private UUID studentID; diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordHistoryRepository.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordHistoryRepository.java index 90816cbf..7a83c5c2 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordHistoryRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordHistoryRepository.java @@ -140,4 +140,60 @@ INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY ( @Query(value= INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_BATCH_ID_AND_STUDENT_ID_IN_SQL, nativeQuery=true) Integer insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(@Param(value = "batchId") Long batchId, @Param(value = "studentIDs") List studentIDs, @Param(value = "activityCode") String activityCode, @Param(value = "updateUser") String updateUser); + String INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_STUDENT_ID_IN_SQL = """ + INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY ( + GRADUATION_STUDENT_RECORD_HISTORY_ID, + HISTORY_ACTIVITY_CODE, + GRADUATION_STUDENT_RECORD_ID, + GRADUATION_PROGRAM_CODE, + GPA, + STUDENT_STATUS_CODE, + HONOURS_STANDING, + PROGRAM_COMPLETION_DATE, + RECALCULATE_GRAD_STATUS, + SCHOOL_OF_RECORD, + STUDENT_GRADE, + SCHOOL_AT_GRADUATION, + CREATE_USER, + CREATE_DATE, + UPDATE_USER, + UPDATE_DATE, + RECALCULATE_PROJECTED_GRAD, + BATCH_ID, + CONSUMER_EDUC_REQT_MET, + STUDENT_CITIZENSHIP_CODE, + ADULT_START_DATE, + SCHOOL_OF_RECORD_ID, + SCHOOL_AT_GRADUATION_ID + ) SELECT + SYS_GUID(), + :activityCode, + GRADUATION_STUDENT_RECORD_ID, + GRADUATION_PROGRAM_CODE, + GPA, + STUDENT_STATUS_CODE, + HONOURS_STANDING, + PROGRAM_COMPLETION_DATE, + RECALCULATE_GRAD_STATUS, + SCHOOL_OF_RECORD, + STUDENT_GRADE, + SCHOOL_AT_GRADUATION, + CREATE_USER, + CREATE_DATE, + UPDATE_USER, + SYSDATE, + RECALCULATE_PROJECTED_GRAD, + BATCH_ID, + CONSUMER_EDUC_REQT_MET, + STUDENT_CITIZENSHIP_CODE, + ADULT_START_DATE, + SCHOOL_OF_RECORD_ID, + SCHOOL_AT_GRADUATION_ID + FROM GRADUATION_STUDENT_RECORD + WHERE GRADUATION_STUDENT_RECORD_ID = :studentID + """; + @Modifying + @Query(value= INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_STUDENT_ID_IN_SQL, nativeQuery=true) + Integer insertGraduationStudentRecordHistoryByStudentId(@Param(value = "studentID") UUID studentID, @Param(value = "activityCode") String activityCode); + } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionService.java index 1d321e6f..d0734466 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionService.java @@ -120,8 +120,13 @@ public GraduationStudentRecord updateGraduationStatusByFields(OngoingUpdateReque gradEntity.setUpdateDate(null); gradEntity.setUpdateUser(null); validateStudentStatusAndResetBatchFlags(gradEntity); - gradEntity = graduationStatusRepository.saveAndFlush(gradEntity); - historyService.createStudentHistory(gradEntity, UPDATE_ONGOING_HISTORY_ACTIVITY_CODE); + if (isBatchFlagUpdatesOnly(eventType)) { + gradEntity = saveBatchFlagsWithAuditHistory(gradEntity.getStudentID(), gradEntity.getRecalculateGradStatus(), + gradEntity.getRecalculateProjectedGrad(), UPDATE_ONGOING_HISTORY_ACTIVITY_CODE); + } else { + gradEntity = graduationStatusRepository.saveAndFlush(gradEntity); + historyService.createStudentHistory(gradEntity, UPDATE_ONGOING_HISTORY_ACTIVITY_CODE); + } if (constants.isStudentGuidPenXrefEnabled() && StringUtils.isNotBlank(requestDTO.getPen())) { saveStudentGuidPenXref(gradEntity.getStudentID(), requestDTO.getPen()); } @@ -130,6 +135,10 @@ public GraduationStudentRecord updateGraduationStatusByFields(OngoingUpdateReque return null; } + private boolean isBatchFlagUpdatesOnly(TraxEventType eventType) { + return TraxEventType.NEWSTUDENT != eventType && TraxEventType.UPD_GRAD != eventType; + } + @Transactional @Retry(name = "generalpostcall") public StudentOptionalProgram saveStudentOptionalProgram(StudentOptionalProgramRequestDTO studentOptionalProgramReq, String accessToken) { @@ -214,6 +223,15 @@ private void saveStudentGuidPenXref(UUID studentId, String pen) { } } + /** + * Update Batch Flags in Graduation Status for Ongoing Updates + */ + private GraduationStudentRecordEntity saveBatchFlagsWithAuditHistory(UUID studentID, String recalculateGradStatus, String recalculateProjectedGrad, String historyActivityCode) { + graduationStatusRepository.updateGradStudentRecalculationAllFlags(studentID, recalculateGradStatus, recalculateProjectedGrad); + gradStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByStudentId(studentID, historyActivityCode); + return graduationStatusRepository.findByStudentID(studentID); + } + @Transactional public void deleteGraduationStatus(UUID studentID) { // graduation_student_record diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionServiceTest.java index 9e11bc9a..b06bf784 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionServiceTest.java @@ -289,7 +289,7 @@ public void testGraduationStudentRecordAsOngoingUpdateForStudentStatus() { OngoingUpdateRequestDTO requestDTO = new OngoingUpdateRequestDTO(); requestDTO.setPen(pen); requestDTO.setStudentID(studentID.toString()); - requestDTO.setEventType(TraxEventType.UPD_STD_STATUS); + requestDTO.setEventType(TraxEventType.UPD_GRAD); OngoingUpdateFieldDTO field = OngoingUpdateFieldDTO.builder() .type(FieldType.STRING).name(FieldName.STUDENT_STATUS).value(newStatus) @@ -322,6 +322,68 @@ public void testGraduationStudentRecordAsOngoingUpdateForStudentStatus() { assertThat(result.getRecalculateGradStatus()).isNull(); } + @Test + public void testGraduationStudentRecordAsOngoingUpdateForBatchFlags() { + // ID + UUID studentID = UUID.randomUUID(); + String pen = "123456789"; + String mincode = "12345678"; + + GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity(); + graduationStatusEntity.setStudentID(studentID); + graduationStatusEntity.setPen(pen); + graduationStatusEntity.setStudentStatus("CUR"); + graduationStatusEntity.setRecalculateGradStatus(null); + graduationStatusEntity.setRecalculateProjectedGrad("Y"); + graduationStatusEntity.setProgram("2018-EN"); + graduationStatusEntity.setSchoolOfRecord(mincode); + graduationStatusEntity.setSchoolAtGrad(mincode); + graduationStatusEntity.setGpa("4"); + graduationStatusEntity.setProgramCompletionDate(new Date(System.currentTimeMillis())); + + OngoingUpdateRequestDTO requestDTO = new OngoingUpdateRequestDTO(); + requestDTO.setPen(pen); + requestDTO.setStudentID(studentID.toString()); + requestDTO.setEventType(TraxEventType.COURSE); + + OngoingUpdateFieldDTO field1 = OngoingUpdateFieldDTO.builder() + .type(FieldType.STRING).name(FieldName.RECALC_GRAD_ALG).value("Y") + .build(); + requestDTO.getUpdateFields().add(field1); + + OngoingUpdateFieldDTO field2 = OngoingUpdateFieldDTO.builder() + .type(FieldType.STRING).name(FieldName.RECALC_TVR).value("NULL") + .build(); + requestDTO.getUpdateFields().add(field2); + + GraduationStudentRecordEntity savedGraduationStatus = new GraduationStudentRecordEntity(); + BeanUtils.copyProperties(graduationStatusEntity, savedGraduationStatus); + savedGraduationStatus.setRecalculateGradStatus("Y"); + savedGraduationStatus.setRecalculateProjectedGrad(null); + + when(graduationStatusRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity)); + when(graduationStatusRepository.findByStudentID(studentID)).thenReturn(savedGraduationStatus); + when(graduationStatusRepository.saveAndFlush(graduationStatusEntity)).thenReturn(savedGraduationStatus); + + when(this.webClient.delete()).thenReturn(this.requestHeadersUriMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getDeleteStudentAchievements(),studentID))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); + when(this.requestBodyMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(Integer.class)).thenReturn(Mono.just(0)); + + var result = dataConversionService.updateGraduationStatusByFields(requestDTO, "accessToken"); + + assertThat(result).isNotNull(); + assertThat(result.getStudentID()).isEqualTo(graduationStatusEntity.getStudentID()); + assertThat(result.getPen()).isEqualTo(graduationStatusEntity.getPen()); + + assertThat(result.getSchoolOfRecord()).isEqualTo(graduationStatusEntity.getSchoolOfRecord()); + assertThat(result.getGpa()).isEqualTo(graduationStatusEntity.getGpa()); + + assertThat(result.getRecalculateGradStatus()).isEqualTo("Y"); + assertThat(result.getRecalculateProjectedGrad()).isNull(); + } + @Test public void testGraduationStudentRecordAsOngoingUpdateForStudentMergedStatus() { // ID @@ -345,7 +407,7 @@ public void testGraduationStudentRecordAsOngoingUpdateForStudentMergedStatus() { OngoingUpdateRequestDTO requestDTO = new OngoingUpdateRequestDTO(); requestDTO.setPen(pen); requestDTO.setStudentID(studentID.toString()); - requestDTO.setEventType(TraxEventType.UPD_STD_STATUS); + requestDTO.setEventType(TraxEventType.UPD_GRAD); OngoingUpdateFieldDTO field = OngoingUpdateFieldDTO.builder() .type(FieldType.STRING).name(FieldName.STUDENT_STATUS).value(newStatus) @@ -407,7 +469,7 @@ public void testGraduationStudentRecordAsOngoingUpdateForStudentArchivedStatus() OngoingUpdateRequestDTO requestDTO = new OngoingUpdateRequestDTO(); requestDTO.setPen(pen); requestDTO.setStudentID(studentID.toString()); - requestDTO.setEventType(TraxEventType.UPD_STD_STATUS); + requestDTO.setEventType(TraxEventType.UPD_GRAD); OngoingUpdateFieldDTO field = OngoingUpdateFieldDTO.builder() .type(FieldType.STRING).name(FieldName.STUDENT_STATUS).value(newStatus) From f5a6c4e427311c6d8ac98716c3b61cd2992673c6 Mon Sep 17 00:00:00 2001 From: Jinil Sung Date: Fri, 22 Nov 2024 12:26:32 -0800 Subject: [PATCH 02/14] GRAD2-3012: task is complete. GRAD2-3012: task is complete. --- .../config/RequestInterceptor.java | 9 ++--- .../gradstudent/model/entity/BaseEntity.java | 3 ++ .../service/GraduationStatusService.java | 3 +- .../util/EducGradStudentApiConstants.java | 1 + .../educ/api/gradstudent/util/JwtUtil.java | 34 +++++++++++++++++++ 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/config/RequestInterceptor.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/config/RequestInterceptor.java index e2e2d238..9177a1c6 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/config/RequestInterceptor.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/config/RequestInterceptor.java @@ -42,13 +42,10 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons // username Authentication auth = SecurityContextHolder.getContext().getAuthentication(); - if (auth instanceof JwtAuthenticationToken) { - JwtAuthenticationToken authenticationToken = (JwtAuthenticationToken) auth; + if (auth instanceof JwtAuthenticationToken authenticationToken) { Jwt jwt = (Jwt) authenticationToken.getCredentials(); - String username = JwtUtil.getName(jwt); - if (username != null) { - ThreadLocalStateUtil.setCurrentUser(username); - } + String username = JwtUtil.getName(jwt, request); + ThreadLocalStateUtil.setCurrentUser(username); } return true; diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/BaseEntity.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/BaseEntity.java index ae1bfc7b..6c6d2b59 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/BaseEntity.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/BaseEntity.java @@ -70,5 +70,8 @@ protected void onPersist() { if (this.createDate == null) { this.createDate = LocalDateTime.now(); } + if(this.updateDate == null) { + this.updateDate = LocalDateTime.now(); + } } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java index 686df60d..e8a43bef 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java @@ -202,7 +202,7 @@ public Pair saveGraduationStatus(UUID if(batchId != null) { resetBatchFlags(gradEntity, false); } - + gradEntity.setUpdateUser(null); gradEntity = graduationStatusRepository.saveAndFlush(gradEntity); historyService.createStudentHistory(gradEntity, GRAD_ALG); final GradStatusEvent gradStatusEvent = createGradStatusEvent(gradEntity.getUpdateUser(), gradEntity, @@ -1112,6 +1112,7 @@ public Pair undoCompletionStudent(UUID gradEntity.setGpa(null); gradEntity.setSchoolAtGrad(null); gradEntity.setUpdateUser(null); + gradEntity.setUpdateDate(null); gradEntity = graduationStatusRepository.save(gradEntity); historyService.createStudentHistory(gradEntity, USER_UNDO_CMPL); final GradStatusEvent gradStatusEvent = createGradStatusEvent(gradEntity.getUpdateUser(), gradEntity, diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java index a930ac1f..2f16d23a 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java @@ -15,6 +15,7 @@ public class EducGradStudentApiConstants { public static final String API_NAME = "GRAD-STUDENT-API"; public static final String STREAM_NAME="GRAD_STATUS_EVENT_STREAM"; public static final String CORRELATION_ID = "correlationID"; + public static final String USERNAME = "username"; //API end-point Mapping constants public static final String API_ROOT_MAPPING = ""; diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/JwtUtil.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/JwtUtil.java index 49984fb2..c012d45d 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/JwtUtil.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/JwtUtil.java @@ -1,5 +1,7 @@ package ca.bc.gov.educ.api.gradstudent.util; +import jakarta.servlet.http.HttpServletRequest; +import lombok.val; import org.apache.commons.lang3.StringUtils; import org.springframework.security.oauth2.jwt.Jwt; @@ -54,6 +56,38 @@ public static String getName(Jwt jwt) { return sb.toString(); } + /** + * Gets name string + * => If it is service account, get it from request header. Otherwise, get it from jwt token + * + * @param jwt the JWT + * @param request the Request Header + * @return the username string from jwt + */ + public static String getName(Jwt jwt, HttpServletRequest request) { + StringBuilder sb = new StringBuilder(); + if (isServiceAccount(jwt.getClaims())) { + sb.append(getUserNameString(request)); + } else { + String givenName = (String) jwt.getClaims().get("given_name"); + if (StringUtils.isNotBlank(givenName)) { + sb.append(givenName.charAt(0)); + } + String familyName = (String) jwt.getClaims().get("family_name"); + sb.append(familyName); + } + return sb.toString(); + } + + private static String getUserNameString(HttpServletRequest request) { + val username = request.getHeader(EducGradStudentApiConstants.USERNAME); + if (StringUtils.isNotBlank(username)) { + return username; + } else { + return "Batch Process"; + } + } + private static boolean isServiceAccount(Map claims) { return !claims.containsKey("family_name"); } From 4c5f743b036b1d4ec9ff8ffa2092f5532b8fcbd3 Mon Sep 17 00:00:00 2001 From: Jinil Sung Date: Fri, 22 Nov 2024 12:49:49 -0800 Subject: [PATCH 03/14] Clean up comments. Clean up comments. --- .../java/ca/bc/gov/educ/api/gradstudent/util/JwtUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/JwtUtil.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/JwtUtil.java index c012d45d..dff3287d 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/JwtUtil.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/JwtUtil.java @@ -58,11 +58,11 @@ public static String getName(Jwt jwt) { /** * Gets name string - * => If it is service account, get it from request header. Otherwise, get it from jwt token + * => If it is service account, get it from request header. Otherwise, get it from jwt * * @param jwt the JWT * @param request the Request Header - * @return the username string from jwt + * @return the username string */ public static String getName(Jwt jwt, HttpServletRequest request) { StringBuilder sb = new StringBuilder(); From 800ebad7cf27b1cfd458a593afb7c4195527f08e Mon Sep 17 00:00:00 2001 From: Jinil Sung Date: Fri, 22 Nov 2024 13:56:53 -0800 Subject: [PATCH 04/14] Improved to fix some sonar complaints. Improved to fix some sonar complaints. --- .../gradstudent/service/GraduationStatusService.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java index e8a43bef..44718d77 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java @@ -82,16 +82,15 @@ public class GraduationStatusService extends GradBaseService { final HistoryService historyService; final GradValidation validation; final EducGradStudentApiConstants constants; + final GraduationStudentRecordSearchRepository graduationStudentRecordSearchRepository; @Autowired - GraduationStudentRecordSearchRepository graduationStudentRecordSearchRepository; - - @Autowired - public GraduationStatusService(WebClient webClient, GraduationStudentRecordRepository graduationStatusRepository, StudentStatusRepository studentStatusRepository, GradStatusEventRepository gradStatusEventRepository, StudentNonGradReasonRepository studentNonGradReasonRepository, GraduationStatusTransformer graduationStatusTransformer, StudentOptionalProgramRepository gradStudentOptionalProgramRepository, GradStudentOptionalProgramTransformer gradStudentOptionalProgramTransformer, StudentCareerProgramRepository gradStudentCareerProgramRepository, GradStudentCareerProgramTransformer gradStudentCareerProgramTransformer, StudentNonGradReasonTransformer studentNonGradReasonTransformer, GradStudentService gradStudentService, HistoryService historyService, GradValidation validation, EducGradStudentApiConstants constants) { + public GraduationStatusService(WebClient webClient, GraduationStudentRecordRepository graduationStatusRepository, StudentStatusRepository studentStatusRepository, GradStatusEventRepository gradStatusEventRepository, StudentNonGradReasonRepository studentNonGradReasonRepository, GraduationStatusTransformer graduationStatusTransformer, StudentOptionalProgramRepository gradStudentOptionalProgramRepository, GraduationStudentRecordSearchRepository graduationStudentRecordSearchRepository, GradStudentOptionalProgramTransformer gradStudentOptionalProgramTransformer, StudentCareerProgramRepository gradStudentCareerProgramRepository, GradStudentCareerProgramTransformer gradStudentCareerProgramTransformer, StudentNonGradReasonTransformer studentNonGradReasonTransformer, GradStudentService gradStudentService, HistoryService historyService, GradValidation validation, EducGradStudentApiConstants constants) { this.webClient = webClient; this.graduationStatusRepository = graduationStatusRepository; this.studentStatusRepository = studentStatusRepository; this.gradStatusEventRepository = gradStatusEventRepository; + this.graduationStudentRecordSearchRepository = graduationStudentRecordSearchRepository; this.graduationStatusTransformer = graduationStatusTransformer; this.gradStudentOptionalProgramRepository = gradStudentOptionalProgramRepository; this.gradStudentOptionalProgramTransformer = gradStudentOptionalProgramTransformer; @@ -403,8 +402,8 @@ public GraduationStudentRecordSearchResult searchGraduationStudentRecords(final Specification spec = new GraduationStudentRecordSearchSpecification(searchCriteria); List results = graduationStudentRecordSearchRepository.findAll(Specification.where(spec)); List students = new ArrayList<>(); - if (results != null && !results.isEmpty()) { - students = results.stream().map(GraduationStudentRecordSearchEntity::getStudentID).collect(Collectors.toList()); + if (!results.isEmpty()) { + students = results.stream().map(GraduationStudentRecordSearchEntity::getStudentID).toList(); } searchResult.setStudentIDs(students); return searchResult; From 85ea699ea25f6a4ae54d17b5584f884ae6cd69dc Mon Sep 17 00:00:00 2001 From: Jinil Sung Date: Fri, 22 Nov 2024 14:25:26 -0800 Subject: [PATCH 05/14] Clean up unused imports. Clean up unused imports. --- .../educ/api/gradstudent/service/GraduationStatusService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java index 44718d77..de56b812 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java @@ -41,7 +41,6 @@ import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.*; -import java.util.stream.Collectors; import static ca.bc.gov.educ.api.gradstudent.constant.EventStatus.DB_COMMITTED; From a459a8a23dc8b8c5991b18a49ccc527cd7a0b48e Mon Sep 17 00:00:00 2001 From: githubmamatha <106563495+githubmamatha@users.noreply.github.com> Date: Wed, 4 Dec 2024 13:43:24 -0800 Subject: [PATCH 06/14] ZAPscan version upgraded and added github actions to dependabot (#707) --- .github/dependabot.yml | 4 ++++ .../workflows/build.from.developer.branch.deploy.to.dev.yml | 2 +- .github/workflows/build.from.main.branch.deploy.to.dev.yml | 2 +- .github/workflows/build.from.release.branch.deploy.to.dev.yml | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0d28b300..56e573e7 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -10,3 +10,7 @@ updates: schedule: interval: "daily" target-branch: "grad-release" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" \ No newline at end of file diff --git a/.github/workflows/build.from.developer.branch.deploy.to.dev.yml b/.github/workflows/build.from.developer.branch.deploy.to.dev.yml index 22c39ee3..bb941421 100644 --- a/.github/workflows/build.from.developer.branch.deploy.to.dev.yml +++ b/.github/workflows/build.from.developer.branch.deploy.to.dev.yml @@ -155,6 +155,6 @@ jobs: # now hit it with a zap scan - name: ZAP Scan - uses: zaproxy/action-api-scan@v0.7.0 + uses: zaproxy/action-api-scan@v0.9.0 with: target: 'https://${{ env.REPO_NAME }}-${{ env.OPENSHIFT_NAMESPACE }}.apps.silver.devops.gov.bc.ca/api/v1/api-docs' diff --git a/.github/workflows/build.from.main.branch.deploy.to.dev.yml b/.github/workflows/build.from.main.branch.deploy.to.dev.yml index 6401fef0..af04a1ad 100644 --- a/.github/workflows/build.from.main.branch.deploy.to.dev.yml +++ b/.github/workflows/build.from.main.branch.deploy.to.dev.yml @@ -137,6 +137,6 @@ jobs: # now hit it with a zap scan - name: ZAP Scan - uses: zaproxy/action-api-scan@v0.7.0 + uses: zaproxy/action-api-scan@v0.9.0 with: target: 'https://${{ env.REPO_NAME }}-${{ env.OPENSHIFT_NAMESPACE }}.apps.silver.devops.gov.bc.ca/api/v1/api-docs' \ No newline at end of file diff --git a/.github/workflows/build.from.release.branch.deploy.to.dev.yml b/.github/workflows/build.from.release.branch.deploy.to.dev.yml index 2b49b449..2398ea31 100644 --- a/.github/workflows/build.from.release.branch.deploy.to.dev.yml +++ b/.github/workflows/build.from.release.branch.deploy.to.dev.yml @@ -144,6 +144,6 @@ jobs: # now hit it with a zap scan - name: ZAP Scan - uses: zaproxy/action-api-scan@v0.7.0 + uses: zaproxy/action-api-scan@v0.9.0 with: target: 'https://${{ env.REPO_NAME }}-${{ env.OPENSHIFT_NAMESPACE }}.apps.silver.devops.gov.bc.ca/api/v1/api-docs' \ No newline at end of file From 7283d63136c9e57494b030ab047b8c28234ae232 Mon Sep 17 00:00:00 2001 From: githubmamatha <106563495+githubmamatha@users.noreply.github.com> Date: Mon, 9 Dec 2024 13:15:22 -0800 Subject: [PATCH 07/14] Update pom.xml --- api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/pom.xml b/api/pom.xml index d2900d12..c2858170 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -6,7 +6,7 @@ ca.bc.gov.educ educ-grad-student-api - 1.8.67 + 1.8.68 educ-grad-student-api Student Demographics API for GRAD team From 9fb18d090cad3b885961180b3934df3ba17a6b2a Mon Sep 17 00:00:00 2001 From: Chris Ditcher Date: Tue, 10 Dec 2024 14:44:51 -0800 Subject: [PATCH 08/14] GRAD2-3060 (#721) * start of gdc messaging (cherry picked from commit 30eb4e12c2099ab1f2660d982d429f6b53df8a10) * gdc messaging (cherry picked from commit bd02fa6501867b44fe125c02d6bd5f56ac3fd591) * use grad student service (cherry picked from commit 1671dea2d6c96b49727531550087bde898749d13) * clean (cherry picked from commit 541dbb8b7641ab159d5a8fec60be337946b617c4) * extend base integration test (cherry picked from commit a4068716d9a2b5e970c2d3eb5fc6b61a2aaa1240) * required fields for grad student record payload (cherry picked from commit 61bec8a91bb1f02ff73cf83abb8b66d23e0f42ee) * clean (cherry picked from commit 1cbaddcc493972d194b40eda0149b056695c0026) * test (cherry picked from commit 6e49a5f70a01ccffc95fac36ebfb0f4ae628409e) * add studentStatusCode to grad student record messaging (cherry picked from commit 649c7baa6199ac3ed5655e4cc89629c4149ed557) * add student id and graduated status to grad stud messaging (#706) * add student id and graduated status to grad stud messaging * test parseGraduationStatus (cherry picked from commit 38f1f56d069c51f1ebd524359e3365f907b85a02) --------- Co-authored-by: alexmcdermid --- .../educ/api/gradstudent/constant/Topics.java | 3 +- .../FetchGradStudentRecordSubscriber.java | 91 ++++++++++++++ .../model/dc/GradStudentRecordPayload.java | 18 +++ .../dto/messaging/GradStudentRecord.java | 23 ++++ .../service/GradStudentService.java | 33 +++++ .../service/CommonServiceTest.java | 4 +- .../service/DataConversionServiceTest.java | 4 +- .../service/EdwSnapshotServiceTest.java | 4 +- .../service/GradStudentServiceTest.java | 115 +++++++++++++++++- .../service/GraduationStatusServiceTest.java | 4 +- .../service/HistoryServiceTest.java | 4 +- .../JetStreamEventHandlerServiceTest.java | 22 ++-- .../support/MockConfiguration.java | 6 + 13 files changed, 304 insertions(+), 27 deletions(-) create mode 100644 api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dc/GradStudentRecordPayload.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/messaging/GradStudentRecord.java diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/Topics.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/Topics.java index 7bc5019d..b7342b0d 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/Topics.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/Topics.java @@ -8,5 +8,6 @@ public enum Topics { * GradStatus events topic. */ GRAD_STATUS_EVENT_TOPIC, - GRAD_STUDENT_API_FETCH_GRAD_STATUS_TOPIC + GRAD_STUDENT_API_FETCH_GRAD_STATUS_TOPIC, + GRAD_STUDENT_API_FETCH_GRAD_STUDENT_TOPIC, } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java new file mode 100644 index 00000000..3d47f72a --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java @@ -0,0 +1,91 @@ +package ca.bc.gov.educ.api.gradstudent.messaging.jetstream; + +import ca.bc.gov.educ.api.gradstudent.constant.Topics; +import ca.bc.gov.educ.api.gradstudent.exception.EntityNotFoundException; +import ca.bc.gov.educ.api.gradstudent.model.dc.Event; +import ca.bc.gov.educ.api.gradstudent.model.dc.GradStudentRecordPayload; +import ca.bc.gov.educ.api.gradstudent.model.dto.messaging.GradStudentRecord; +import ca.bc.gov.educ.api.gradstudent.service.GradStudentService; +import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants; +import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiUtils; +import ca.bc.gov.educ.api.gradstudent.util.JsonUtil; +import com.fasterxml.jackson.core.JsonProcessingException; +import io.nats.client.*; +import lombok.val; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.UUID; + +@Component +public class FetchGradStudentRecordSubscriber implements MessageHandler { + + private final Connection natsConnection; + private Dispatcher dispatcher; + private final GradStudentService gradStudentService; + public static final String RESPONDING_BACK_TO_NATS_ON_CHANNEL = "responding back to NATS on {} channel "; + public static final String PAYLOAD_LOG = "payload is :: {}"; + private static final String TOPIC = Topics.GRAD_STUDENT_API_FETCH_GRAD_STUDENT_TOPIC.toString(); + private static final Logger log = LoggerFactory.getLogger(FetchGradStudentRecordSubscriber.class); + + @Autowired + public FetchGradStudentRecordSubscriber(final Connection natsConnection, GradStudentService gradStudentService, EducGradStudentApiConstants constants) { + this.natsConnection = natsConnection; + this.gradStudentService = gradStudentService; + } + + @PostConstruct + public void subscribe() { + this.dispatcher = this.natsConnection.createDispatcher(this); + this.dispatcher.subscribe(TOPIC); + } + + @Override + public void onMessage(Message message) { + val eventString = new String(message.getData()); + log.debug("Received message: {}", eventString); + String response; + + try { + Event event = JsonUtil.getJsonObjectFromString(Event.class, eventString); + log.info("received GET_STUDENT event :: {}", event.getSagaId()); + log.trace(PAYLOAD_LOG, event.getEventPayload()); + UUID studentId = JsonUtil.getJsonObjectFromString(UUID.class, event.getEventPayload()); + GradStudentRecord studentRecord = gradStudentService.getGraduationStudentRecord(studentId); + response = getResponse(studentRecord); + log.info(RESPONDING_BACK_TO_NATS_ON_CHANNEL, message.getReplyTo() != null ? message.getReplyTo() : event.getReplyTo()); + } catch (Exception e) { + response = getErrorResponse(e); + log.error("Error while processing GET_STUDENT event", e); + } + this.natsConnection.publish(message.getReplyTo(), response.getBytes()); + } + + private String getResponse(GradStudentRecord studentRecord) throws JsonProcessingException { + GradStudentRecordPayload gradStudentRecordPayload = GradStudentRecordPayload.builder() + .studentID(String.valueOf(studentRecord.getStudentID())) + .program(studentRecord.getProgram()) + .programCompletionDate(studentRecord.getProgramCompletionDate() != null ? EducGradStudentApiUtils.formatDate(studentRecord.getProgramCompletionDate()) : null) + .schoolOfRecord(studentRecord.getSchoolOfRecord()) + .studentStatusCode(studentRecord.getStudentStatusCode()) + .graduated(studentRecord.getGraduated().toString()) + .build(); + return JsonUtil.getJsonStringFromObject(gradStudentRecordPayload); + } + + private String getErrorResponse(Exception e) { + String ex = (e instanceof EntityNotFoundException) ? "not found" : "error"; + GradStudentRecordPayload gradStudentRecordPayload = GradStudentRecordPayload.builder() + .exception(ex) + .build(); + try { + return JsonUtil.getJsonStringFromObject(gradStudentRecordPayload); + } catch (JsonProcessingException exc) { + log.error("Error while serializing error response", exc); + return "{\"studentID\": \"\", \"program\": \"\", \"programCompletionDate\": \"\", \"schoolOfRecord\": \"\", \"studentStatusCode\": \"\", \"graduated\": \"\", \"exception\": \"JSON Parsing exception\"}"; + } + } +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dc/GradStudentRecordPayload.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dc/GradStudentRecordPayload.java new file mode 100644 index 00000000..256b477e --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dc/GradStudentRecordPayload.java @@ -0,0 +1,18 @@ +package ca.bc.gov.educ.api.gradstudent.model.dc; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class GradStudentRecordPayload { + + private String studentID; + private String exception; + private String program; + private String programCompletionDate; + private String schoolOfRecord; + private String studentStatusCode; + private String graduated; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/messaging/GradStudentRecord.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/messaging/GradStudentRecord.java new file mode 100644 index 00000000..30b8a805 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/messaging/GradStudentRecord.java @@ -0,0 +1,23 @@ +package ca.bc.gov.educ.api.gradstudent.model.dto.messaging; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; +import java.util.UUID; + +@Data +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class GradStudentRecord { + + private UUID studentID; + private String program; + private Date programCompletionDate; + private String schoolOfRecord; + private String studentStatusCode; + private String studentProjectedGradData; + private Boolean graduated; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentService.java index c7c15d17..a8f34386 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentService.java @@ -1,12 +1,16 @@ package ca.bc.gov.educ.api.gradstudent.service; +import ca.bc.gov.educ.api.gradstudent.exception.EntityNotFoundException; import ca.bc.gov.educ.api.gradstudent.model.dto.*; +import ca.bc.gov.educ.api.gradstudent.model.dto.messaging.GradStudentRecord; import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordEntity; import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordView; import ca.bc.gov.educ.api.gradstudent.model.transformer.GraduationStatusTransformer; import ca.bc.gov.educ.api.gradstudent.repository.GraduationStudentRecordRepository; import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants; import ca.bc.gov.educ.api.gradstudent.util.ThreadLocalStateUtil; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.resilience4j.retry.annotation.Retry; import jakarta.transaction.Transactional; @@ -50,6 +54,7 @@ public class GradStudentService { private static final String PAGE_NUMBER="pageNumber"; private static final String PAGE_SIZE="pageSize"; private static final String SEARCH_CRITERIA_LIST = "searchCriteriaList"; + private static final String STD_NOT_FOUND_MSG = "Student with ID: %s not found"; final EducGradStudentApiConstants constants; final WebClient webClient; @@ -419,4 +424,32 @@ public List getStudentIDsBySearchCriteriaOrAll(StudentSearchRequest search } return result; } + + /** + * Returns a condensed version of GraduationStudentRecord for GDC + * @param studentID + * @return + * @throws EntityNotFoundException + */ + public GradStudentRecord getGraduationStudentRecord(UUID studentID) { + GradStudentRecord response = graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class); + if (response != null) { + response.setGraduated(parseGraduationStatus(response.getStudentProjectedGradData())); + return response; + } + throw new EntityNotFoundException(String.format(STD_NOT_FOUND_MSG, studentID)); + } + + public Boolean parseGraduationStatus(String studentProjectedGradData) { + if (studentProjectedGradData == null || studentProjectedGradData.isEmpty()) { + return false; + } + try { + ObjectMapper mapper = new ObjectMapper(); + JsonNode jsonNode = mapper.readTree(studentProjectedGradData); + return jsonNode.get("graduated").asBoolean(); + } catch (JsonProcessingException e) { + return false; + } + } } diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/CommonServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/CommonServiceTest.java index 97bf0306..78036f17 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/CommonServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/CommonServiceTest.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.gradstudent.service; +import ca.bc.gov.educ.api.gradstudent.controller.BaseIntegrationTest; import ca.bc.gov.educ.api.gradstudent.messaging.NatsConnection; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStatusSubscriber; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Publisher; @@ -34,8 +35,7 @@ @RunWith(SpringRunner.class) @SpringBootTest -@ActiveProfiles("test") -public class CommonServiceTest { +public class CommonServiceTest extends BaseIntegrationTest { @Autowired EducGradStudentApiConstants constants; @Autowired CommonService commonService; diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionServiceTest.java index b06bf784..d99bdd39 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionServiceTest.java @@ -3,6 +3,7 @@ import ca.bc.gov.educ.api.gradstudent.constant.FieldName; import ca.bc.gov.educ.api.gradstudent.constant.FieldType; import ca.bc.gov.educ.api.gradstudent.constant.TraxEventType; +import ca.bc.gov.educ.api.gradstudent.controller.BaseIntegrationTest; import ca.bc.gov.educ.api.gradstudent.messaging.NatsConnection; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStatusSubscriber; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Publisher; @@ -39,8 +40,7 @@ @RunWith(SpringRunner.class) @SpringBootTest -@ActiveProfiles("test") -public class DataConversionServiceTest { +public class DataConversionServiceTest extends BaseIntegrationTest { @Autowired EducGradStudentApiConstants constants; @Autowired diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/EdwSnapshotServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/EdwSnapshotServiceTest.java index ea5adf7d..8fbb3655 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/EdwSnapshotServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/EdwSnapshotServiceTest.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.gradstudent.service; +import ca.bc.gov.educ.api.gradstudent.controller.BaseIntegrationTest; import ca.bc.gov.educ.api.gradstudent.messaging.NatsConnection; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStatusSubscriber; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Publisher; @@ -31,8 +32,7 @@ @RunWith(SpringRunner.class) @SpringBootTest -@ActiveProfiles("test") -public class EdwSnapshotServiceTest { +public class EdwSnapshotServiceTest extends BaseIntegrationTest { @Autowired EdwSnapshotService edwSnapshotService; diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java index 8ee2f046..df276d1a 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java @@ -1,10 +1,13 @@ package ca.bc.gov.educ.api.gradstudent.service; +import ca.bc.gov.educ.api.gradstudent.controller.BaseIntegrationTest; +import ca.bc.gov.educ.api.gradstudent.exception.EntityNotFoundException; import ca.bc.gov.educ.api.gradstudent.messaging.NatsConnection; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStatusSubscriber; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Publisher; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Subscriber; import ca.bc.gov.educ.api.gradstudent.model.dto.*; +import ca.bc.gov.educ.api.gradstudent.model.dto.messaging.GradStudentRecord; import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordEntity; import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordView; import ca.bc.gov.educ.api.gradstudent.model.transformer.GraduationStatusTransformer; @@ -41,6 +44,7 @@ import java.util.function.Function; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -48,8 +52,7 @@ @RunWith(SpringRunner.class) @SpringBootTest -@ActiveProfiles("test") -public class GradStudentServiceTest { +public class GradStudentServiceTest extends BaseIntegrationTest { @Autowired EducGradStudentApiConstants constants; @@ -847,6 +850,114 @@ public void testGetStudentIDsBySearchCriterias() { assertThat(results).isNotEmpty(); } + @Test + public void testGetGraduationStudentRecord_GivenValidProgramCompletionDate_ExpectTrue() throws EntityNotFoundException { + UUID studentID = UUID.randomUUID(); + GraduationStudentRecordEntity graduationStudentRecordEntity = new GraduationStudentRecordEntity(); + graduationStudentRecordEntity.setProgramCompletionDate(new java.util.Date()); + when(graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class)).thenReturn(new GradStudentRecord(studentID, "2018-EN", new java.util.Date(), "schoolOfRecord", "studentStatusCode", "{\"nonGradReasons\":null,\"graduated\":true}", Boolean.TRUE)); + GradStudentRecord result = gradStudentService.getGraduationStudentRecord(studentID); + assertNotNull(result); + } + + @Test + public void testGetGraduationStudentRecord_givenNotFound_ExpectEntityNotFoundExcetpion() { + UUID studentID = UUID.randomUUID(); + when(graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class)).thenReturn(null); + assertThrows(EntityNotFoundException.class, () -> { + gradStudentService.getGraduationStudentRecord(studentID); + }); + } + + @Test + public void testGetGraduationStudentRecord_GivenGraduatedTrue_ExpectGraduated() { + UUID studentID = UUID.randomUUID(); + GradStudentRecord mockRecord = new GradStudentRecord( + studentID, + "2018-EN", + new java.util.Date(), + "schoolOfRecord", + "studentStatusCode", + "{\"nonGradReasons\":null,\"graduated\":true}", + true + ); + when(graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class)).thenReturn(mockRecord); + + GradStudentRecord result = gradStudentService.getGraduationStudentRecord(studentID); + + assertNotNull(result); + assertTrue(result.getGraduated()); + } + + @Test + public void testGetGraduationStudentRecord_GivenGraduatedFalse_ExpectNotGraduated() { + UUID studentID = UUID.randomUUID(); + GradStudentRecord mockRecord = new GradStudentRecord( + studentID, + "2018-EN", + new java.util.Date(), + "schoolOfRecord", + "studentStatusCode", + "{\"nonGradReasons\":[],\"graduated\":false}", + false + ); + when(graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class)).thenReturn(mockRecord); + + GradStudentRecord result = gradStudentService.getGraduationStudentRecord(studentID); + + assertNotNull(result); + assertFalse(result.getGraduated()); + } + + @Test + public void testGetGraduationStudentRecord_GivenNullCLOBData_ExpectNotGraduated() { + UUID studentID = UUID.randomUUID(); + GradStudentRecord mockRecord = new GradStudentRecord( + studentID, + "2018-EN", + new java.util.Date(), + "schoolOfRecord", + "studentStatusCode", + null, + false + ); + when(graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class)).thenReturn(mockRecord); + + GradStudentRecord result = gradStudentService.getGraduationStudentRecord(studentID); + + assertNotNull(result); + assertFalse(result.getGraduated()); + } + + @Test + public void testGetGraduationStudentRecord_GivenRecordNotFound_ExpectEntityNotFoundException() { + UUID studentID = UUID.randomUUID(); + when(graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class)).thenReturn(null); + + assertThrows(EntityNotFoundException.class, () -> gradStudentService.getGraduationStudentRecord(studentID)); + } + + @Test + public void testParseGraduationStatus_GivenNullInput_ExpectFalse() { + String studentProjectedGradData = null; + Boolean result = gradStudentService.parseGraduationStatus(studentProjectedGradData); + assertFalse("Expected false for null input", result); + } + + @Test + public void testParseGraduationStatus_GivenEmptyInput_ExpectFalse() { + String studentProjectedGradData = ""; + Boolean result = gradStudentService.parseGraduationStatus(studentProjectedGradData); + assertFalse("Expected false for empty input", result); + } + + @Test + public void testParseGraduationStatus_GivenMalformedJson_ExpectFalse() { + String malformedJson = "{invalid-json}"; + Boolean result = gradStudentService.parseGraduationStatus(malformedJson); + assertFalse("Expected false for malformed JSON", result); + } + @SneakyThrows protected Object createDataObjectFromJson(String jsonPath, Class clazz) { String json = readFile(jsonPath); diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java index c70a33f2..57ec23ea 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.gradstudent.service; +import ca.bc.gov.educ.api.gradstudent.controller.BaseIntegrationTest; import ca.bc.gov.educ.api.gradstudent.exception.EntityNotFoundException; import ca.bc.gov.educ.api.gradstudent.messaging.NatsConnection; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStatusSubscriber; @@ -50,8 +51,7 @@ @RunWith(SpringRunner.class) @SpringBootTest -@ActiveProfiles("test") -public class GraduationStatusServiceTest { +public class GraduationStatusServiceTest extends BaseIntegrationTest { @Autowired EducGradStudentApiConstants constants; @Autowired GraduationStatusService graduationStatusService; diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java index 107bdd6e..5d8765b8 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.gradstudent.service; +import ca.bc.gov.educ.api.gradstudent.controller.BaseIntegrationTest; import ca.bc.gov.educ.api.gradstudent.messaging.NatsConnection; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStatusSubscriber; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Publisher; @@ -51,8 +52,7 @@ @RunWith(SpringRunner.class) @SpringBootTest -@ActiveProfiles("test") -public class HistoryServiceTest { +public class HistoryServiceTest extends BaseIntegrationTest { @Autowired EducGradStudentApiConstants constants; @Autowired HistoryService historyService; diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/JetStreamEventHandlerServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/JetStreamEventHandlerServiceTest.java index ba06130e..466cfb75 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/JetStreamEventHandlerServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/JetStreamEventHandlerServiceTest.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.gradstudent.service; +import ca.bc.gov.educ.api.gradstudent.controller.BaseIntegrationTest; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStatusSubscriber; import ca.bc.gov.educ.api.gradstudent.model.dto.ChoreographedEvent; import ca.bc.gov.educ.api.gradstudent.model.entity.GradStatusEvent; @@ -8,16 +9,12 @@ import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Subscriber; import ca.bc.gov.educ.api.gradstudent.repository.GradStatusEventRepository; import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; 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.Optional; @@ -27,10 +24,7 @@ import static ca.bc.gov.educ.api.gradstudent.constant.EventStatus.MESSAGE_PUBLISHED; import static org.mockito.MockitoAnnotations.openMocks; -@RunWith(SpringRunner.class) -@SpringBootTest -@ActiveProfiles("test") -public class JetStreamEventHandlerServiceTest { +class JetStreamEventHandlerServiceTest extends BaseIntegrationTest { @Autowired EducGradStudentApiConstants constants; @@ -59,18 +53,18 @@ public class JetStreamEventHandlerServiceTest { @MockBean private Subscriber subscriber; - @Before + @BeforeEach public void setUp() { openMocks(this); } - @After + @AfterEach public void tearDown() { } @Test - public void testUpdateEventStatus() { + void testUpdateEventStatus() { UUID eventId = UUID.randomUUID(); ChoreographedEvent choreographedEvent = new ChoreographedEvent(); diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/support/MockConfiguration.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/support/MockConfiguration.java index d48efe26..5836a491 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/support/MockConfiguration.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/support/MockConfiguration.java @@ -2,6 +2,7 @@ import ca.bc.gov.educ.api.gradstudent.messaging.NatsConnection; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStatusSubscriber; +import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStudentRecordSubscriber; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Publisher; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Subscriber; import io.nats.client.Connection; @@ -56,6 +57,11 @@ public FetchGradStatusSubscriber fetchGradStatusSubscriber() { return Mockito.mock(FetchGradStatusSubscriber.class); } + @Bean + @Primary + public FetchGradStudentRecordSubscriber fetchGradStudentRecordSubscriber() {return Mockito.mock(FetchGradStudentRecordSubscriber.class); + } + @Bean @Primary public Connection connection() { From c2316ac32936be3bf4372b8a5574ff825972358d Mon Sep 17 00:00:00 2001 From: alexmcdermid Date: Tue, 10 Dec 2024 15:28:25 -0800 Subject: [PATCH 09/14] GET_GRAD_STUDENT_RECORD --- .../ca/bc/gov/educ/api/gradstudent/model/dc/EventType.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dc/EventType.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dc/EventType.java index 94ef33ad..c9b14d16 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dc/EventType.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dc/EventType.java @@ -14,5 +14,6 @@ public enum EventType { MARK_SAGA_COMPLETE, GET_PAGINATED_SCHOOLS, WRITE_ENROLLED_PROGRAMS, - CALCULATE_ADDITIONAL_STUDENT_ATTRIBUTES + CALCULATE_ADDITIONAL_STUDENT_ATTRIBUTES, + GET_GRAD_STUDENT_RECORD } From e558c7bc47a8214050d1e1f2429a089abe69efcc Mon Sep 17 00:00:00 2001 From: cditcher Date: Tue, 10 Dec 2024 16:08:28 -0800 Subject: [PATCH 10/14] FromString --- .../messaging/jetstream/FetchGradStudentRecordSubscriber.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java index 3d47f72a..ab7bfdde 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java @@ -53,7 +53,7 @@ public void onMessage(Message message) { Event event = JsonUtil.getJsonObjectFromString(Event.class, eventString); log.info("received GET_STUDENT event :: {}", event.getSagaId()); log.trace(PAYLOAD_LOG, event.getEventPayload()); - UUID studentId = JsonUtil.getJsonObjectFromString(UUID.class, event.getEventPayload()); + UUID studentId = UUID.fromString(event.getEventPayload()); GradStudentRecord studentRecord = gradStudentService.getGraduationStudentRecord(studentId); response = getResponse(studentRecord); log.info(RESPONDING_BACK_TO_NATS_ON_CHANNEL, message.getReplyTo() != null ? message.getReplyTo() : event.getReplyTo()); From d0dabcafe94f2426c035fb14bafeb17cda50de4a Mon Sep 17 00:00:00 2001 From: alexmcdermid Date: Tue, 10 Dec 2024 16:27:23 -0800 Subject: [PATCH 11/14] student status code --- .../messaging/jetstream/FetchGradStudentRecordSubscriber.java | 2 +- .../api/gradstudent/model/dto/messaging/GradStudentRecord.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java index ab7bfdde..529277ef 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java @@ -70,7 +70,7 @@ private String getResponse(GradStudentRecord studentRecord) throws JsonProcessin .program(studentRecord.getProgram()) .programCompletionDate(studentRecord.getProgramCompletionDate() != null ? EducGradStudentApiUtils.formatDate(studentRecord.getProgramCompletionDate()) : null) .schoolOfRecord(studentRecord.getSchoolOfRecord()) - .studentStatusCode(studentRecord.getStudentStatusCode()) + .studentStatusCode(studentRecord.getStudentStatus()) .graduated(studentRecord.getGraduated().toString()) .build(); return JsonUtil.getJsonStringFromObject(gradStudentRecordPayload); diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/messaging/GradStudentRecord.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/messaging/GradStudentRecord.java index 30b8a805..868fdc95 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/messaging/GradStudentRecord.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/messaging/GradStudentRecord.java @@ -16,7 +16,7 @@ public class GradStudentRecord { private String program; private Date programCompletionDate; private String schoolOfRecord; - private String studentStatusCode; + private String studentStatus; private String studentProjectedGradData; private Boolean graduated; From b7713b5eab65a2886caca81110e67b0d9c445b90 Mon Sep 17 00:00:00 2001 From: alexmcdermid Date: Tue, 10 Dec 2024 16:43:44 -0800 Subject: [PATCH 12/14] remove graduated from dto --- .../messaging/jetstream/FetchGradStudentRecordSubscriber.java | 2 +- .../api/gradstudent/model/dto/messaging/GradStudentRecord.java | 1 - .../bc/gov/educ/api/gradstudent/service/GradStudentService.java | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java index 529277ef..db1e354d 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java @@ -71,7 +71,7 @@ private String getResponse(GradStudentRecord studentRecord) throws JsonProcessin .programCompletionDate(studentRecord.getProgramCompletionDate() != null ? EducGradStudentApiUtils.formatDate(studentRecord.getProgramCompletionDate()) : null) .schoolOfRecord(studentRecord.getSchoolOfRecord()) .studentStatusCode(studentRecord.getStudentStatus()) - .graduated(studentRecord.getGraduated().toString()) + .graduated(gradStudentService.parseGraduationStatus(studentRecord.getStudentProjectedGradData()).toString()) .build(); return JsonUtil.getJsonStringFromObject(gradStudentRecordPayload); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/messaging/GradStudentRecord.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/messaging/GradStudentRecord.java index 868fdc95..33516001 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/messaging/GradStudentRecord.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/messaging/GradStudentRecord.java @@ -18,6 +18,5 @@ public class GradStudentRecord { private String schoolOfRecord; private String studentStatus; private String studentProjectedGradData; - private Boolean graduated; } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentService.java index a8f34386..9e77e1ca 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentService.java @@ -434,7 +434,6 @@ public List getStudentIDsBySearchCriteriaOrAll(StudentSearchRequest search public GradStudentRecord getGraduationStudentRecord(UUID studentID) { GradStudentRecord response = graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class); if (response != null) { - response.setGraduated(parseGraduationStatus(response.getStudentProjectedGradData())); return response; } throw new EntityNotFoundException(String.format(STD_NOT_FOUND_MSG, studentID)); From c19698d2d2693c77368ef3f3cda29cbca392c890 Mon Sep 17 00:00:00 2001 From: alexmcdermid Date: Tue, 10 Dec 2024 16:51:23 -0800 Subject: [PATCH 13/14] remove tests --- .../service/GradStudentServiceTest.java | 62 +------------------ 1 file changed, 1 insertion(+), 61 deletions(-) diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java index df276d1a..e9275fbe 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java @@ -855,7 +855,7 @@ public void testGetGraduationStudentRecord_GivenValidProgramCompletionDate_Expec UUID studentID = UUID.randomUUID(); GraduationStudentRecordEntity graduationStudentRecordEntity = new GraduationStudentRecordEntity(); graduationStudentRecordEntity.setProgramCompletionDate(new java.util.Date()); - when(graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class)).thenReturn(new GradStudentRecord(studentID, "2018-EN", new java.util.Date(), "schoolOfRecord", "studentStatusCode", "{\"nonGradReasons\":null,\"graduated\":true}", Boolean.TRUE)); + when(graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class)).thenReturn(new GradStudentRecord(studentID, "2018-EN", new java.util.Date(), "schoolOfRecord", "studentStatusCode", "{\"nonGradReasons\":null,\"graduated\":true}")); GradStudentRecord result = gradStudentService.getGraduationStudentRecord(studentID); assertNotNull(result); } @@ -869,66 +869,6 @@ public void testGetGraduationStudentRecord_givenNotFound_ExpectEntityNotFoundExc }); } - @Test - public void testGetGraduationStudentRecord_GivenGraduatedTrue_ExpectGraduated() { - UUID studentID = UUID.randomUUID(); - GradStudentRecord mockRecord = new GradStudentRecord( - studentID, - "2018-EN", - new java.util.Date(), - "schoolOfRecord", - "studentStatusCode", - "{\"nonGradReasons\":null,\"graduated\":true}", - true - ); - when(graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class)).thenReturn(mockRecord); - - GradStudentRecord result = gradStudentService.getGraduationStudentRecord(studentID); - - assertNotNull(result); - assertTrue(result.getGraduated()); - } - - @Test - public void testGetGraduationStudentRecord_GivenGraduatedFalse_ExpectNotGraduated() { - UUID studentID = UUID.randomUUID(); - GradStudentRecord mockRecord = new GradStudentRecord( - studentID, - "2018-EN", - new java.util.Date(), - "schoolOfRecord", - "studentStatusCode", - "{\"nonGradReasons\":[],\"graduated\":false}", - false - ); - when(graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class)).thenReturn(mockRecord); - - GradStudentRecord result = gradStudentService.getGraduationStudentRecord(studentID); - - assertNotNull(result); - assertFalse(result.getGraduated()); - } - - @Test - public void testGetGraduationStudentRecord_GivenNullCLOBData_ExpectNotGraduated() { - UUID studentID = UUID.randomUUID(); - GradStudentRecord mockRecord = new GradStudentRecord( - studentID, - "2018-EN", - new java.util.Date(), - "schoolOfRecord", - "studentStatusCode", - null, - false - ); - when(graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class)).thenReturn(mockRecord); - - GradStudentRecord result = gradStudentService.getGraduationStudentRecord(studentID); - - assertNotNull(result); - assertFalse(result.getGraduated()); - } - @Test public void testGetGraduationStudentRecord_GivenRecordNotFound_ExpectEntityNotFoundException() { UUID studentID = UUID.randomUUID(); From 81a8e7ab471462fe734a63a18208379e168d9b2a Mon Sep 17 00:00:00 2001 From: githubmamatha <106563495+githubmamatha@users.noreply.github.com> Date: Wed, 11 Dec 2024 08:21:02 -0800 Subject: [PATCH 14/14] Update pom.xml --- api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/pom.xml b/api/pom.xml index c2858170..0e9215c7 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -6,7 +6,7 @@ ca.bc.gov.educ educ-grad-student-api - 1.8.68 + 1.8.69 educ-grad-student-api Student Demographics API for GRAD team