diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusController.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusController.java index 546b6a01..adb6ca5e 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusController.java @@ -391,6 +391,22 @@ public ResponseEntity getStudentsCountForAmalgamatedSchoolReport(@PathV return response.GET(gradStatusService.countStudentsForAmalgamatedSchoolReport(schoolOfRecord)); } + @PostMapping (EducGradStudentApiConstants.STUDENT_COUNT) + @PreAuthorize(PermissionsConstants.READ_GRADUATION_STUDENT) + @Operation(summary = "Get Students Count by mincode and status", description = "Get Students Count by mincode and status", tags = { "Business" }) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) + public ResponseEntity getStudentsCount(@RequestParam(required = false) String studentStatus, @RequestBody List schoolOfRecords) { + return response.GET(gradStatusService.countBySchoolOfRecordsAndStudentStatus(schoolOfRecords, studentStatus)); + } + + @PostMapping (EducGradStudentApiConstants.STUDENT_ARCHIVE) + @PreAuthorize(PermissionsConstants.ARCHIVE_GRADUATION_STUDENT) + @Operation(summary = "Get Students Count by mincode and status", description = "Get Students Count by mincode and status", tags = { "Business" }) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) + public ResponseEntity archiveStudents(@RequestParam long batchId, @RequestParam(required = false) String studentStatus, @RequestBody List schoolOfRecords) { + return response.GET(gradStatusService.archiveStudents(batchId, schoolOfRecords, studentStatus)); + } + @PostMapping (EducGradStudentApiConstants.UPDATE_GRAD_STUDENT_FLAG_BY_BATCH_JOB_TYPE_AND_MULTIPLE_STUDENTIDS) @PreAuthorize(PermissionsConstants.UPDATE_GRADUATION_STUDENT) @Operation(summary = "Update Student Flag ready for batch by Batch Job Type and Student IDs", description = "Update Student Flag ready for batch by Batch Job Type and Student IDs", tags = { "Batch Algorithm" }) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordRepository.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordRepository.java index 99d81b24..ba98aee0 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/repository/GraduationStudentRecordRepository.java @@ -52,6 +52,20 @@ public interface GraduationStudentRecordRepository extends JpaRepository schoolOfRecords, String studentStatus); + + @Query("select count(*) from GraduationStudentRecordEntity c where c.studentStatus=:studentStatus") + Long countByStudentStatus(String studentStatus); + + @Modifying + @Query(value="update graduation_student_record set student_status_code = :inStudStatTo, batch_id = :batchId, student_grad_data = json_transform(student_grad_data, SET '$.gradStatus.studentStatus' = :inStudStatTo IGNORE ON MISSING), update_date = SYSDATE, update_user = 'Batch Archive Process' where school_of_record in (:inSor) and student_status_code = :inStudStatFrom", nativeQuery=true) + Integer archiveStudents(List inSor, String inStudStatFrom, String inStudStatTo, long batchId); + + @Modifying + @Query(value="update graduation_student_record set student_status_code = :inStudStatTo, batch_id = :batchId, student_grad_data = json_transform(student_grad_data, SET '$.gradStatus.studentStatus' = :inStudStatTo IGNORE ON MISSING), update_date = SYSDATE, update_user = 'Batch Archive Process' where student_status_code = :inStudStatFrom", nativeQuery=true) + Integer archiveStudents(String inStudStatFrom, String inStudStatTo, long batchId); + // Data Conversion @Modifying @Query(value="insert into STUDENT_GUID_PEN_XREF(STUDENT_GUID, STUDENT_PEN, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE)\n" 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 3b499f7b..9f975634 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 @@ -1338,7 +1338,7 @@ private GraduationStudentRecord processReceivedStudent(GraduationStudentRecord e ent.setLegalFirstName(existingData.getGradStudent().getLegalFirstName()); ent.setLegalMiddleNames(existingData.getGradStudent().getLegalMiddleNames()); ent.setLegalLastName(existingData.getGradStudent().getLegalLastName()); - }else { + } else { Student stuData = webClient.get().uri(String.format(constants.getPenStudentApiByStudentIdUrl(), ent.getStudentID())) .headers(h -> { h.setBearerAuth(accessToken); @@ -1369,6 +1369,23 @@ public Integer countStudentsForAmalgamatedSchoolReport(String schoolOfRecord) { return graduationStatusRepository.countBySchoolOfRecordAmalgamated(schoolOfRecord); } + public Long countBySchoolOfRecordsAndStudentStatus(List schoolOfRecords, String studentStatus) { + if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) { + return graduationStatusRepository.countBySchoolOfRecordsAndStudentStatus(schoolOfRecords, StringUtils.defaultString(studentStatus, "CUR")); + } else { + return graduationStatusRepository.countByStudentStatus(StringUtils.defaultString(studentStatus, "CUR")); + } + } + + @Transactional + public Integer archiveStudents(long batchId, List schoolOfRecords, String studentStatus) { + if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) { + return graduationStatusRepository.archiveStudents(schoolOfRecords, StringUtils.defaultString(studentStatus, "CUR"), "ARC", batchId); + } else { + return graduationStatusRepository.archiveStudents(StringUtils.defaultString(studentStatus, "CUR"), "ARC", batchId); + } + } + public void updateStudentFlagReadyForBatchJobByStudentIDs(String batchJobType, List studentIDs) { logger.debug("updateStudentFlagReadyForBatchJobByStudentIDs"); for(UUID uuid: studentIDs) { 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 89bbc849..a28611e2 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 @@ -20,6 +20,8 @@ public class EducGradStudentApiConstants { public static final String API_ROOT_MAPPING = ""; public static final String API_VERSION = "v1"; public static final String GRAD_STUDENT_API_ROOT_MAPPING = "/api/" + API_VERSION + "/student" ; + public static final String STUDENT_COUNT = "/count"; + public static final String STUDENT_ARCHIVE = "/archive"; public static final String GRAD_STUDENT_BY_PEN = "/{pen}"; public static final String GRAD_STUDENT_BY_PEN_STUDENT_API = "/pen/{pen}"; public static final String GRAD_STUDENT_DEMOG_BY_PEN = "/demog/pen/{pen}"; @@ -54,7 +56,7 @@ public class EducGradStudentApiConstants { public static final String GRAD_STUDENT_BY_STUDENT_ID_FOR_BATCH_RUN = "/batch/gradstudent/studentid/{studentID}"; public static final String STUDENT_LIST_FOR_SCHOOL_REPORT = "/batch/schoolreport/{schoolOfRecord}"; public static final String STUDENT_LIST_FOR_AMALGAMATED_SCHOOL_REPORT = "/amalgamated/schoolreport/{schoolOfRecord}/type/{type}"; - public static final String STUDENT_COUNT_FOR_AMALGAMATED_SCHOOL_REPORT = "/amalgamated/schoolreport/{schoolOfRecord}/count"; + public static final String STUDENT_COUNT_FOR_AMALGAMATED_SCHOOL_REPORT = "/amalgamated/schoolreport/{schoolOfRecord}" + STUDENT_COUNT; public static final String STUDENT_RECORD_STUDENT_ID_BATCH_RUN = "/batch/{studentID}"; public static final String GET_STUDENT_STATUS_BY_STATUS_CODE_MAPPING = "/checkstudentstatus/{statusCode}"; public static final String UNGRAD_STUDENT = "/undocompletionstudent/studentid/{studentID}"; diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/PermissionsConstants.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/PermissionsConstants.java index a3d06c3e..1a7a70c9 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/PermissionsConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/PermissionsConstants.java @@ -8,6 +8,7 @@ private PermissionsConstants() {} public static final String UPDATE_GRADUATION_STUDENT = PREFIX + "SCOPE_UPDATE_GRAD_GRADUATION_STATUS" + SUFFIX; public static final String READ_GRADUATION_STUDENT = PREFIX + "SCOPE_READ_GRAD_GRADUATION_STATUS" + SUFFIX; + public static final String ARCHIVE_GRADUATION_STUDENT = PREFIX + "SCOPE_ARCHIVE_GRADUATION_STUDENT_RECORD" + SUFFIX; public static final String UPDATE_GRADUATION_STUDENT_OPTIONAL_PROGRAM = PREFIX + "SCOPE_UPDATE_GRAD_STUDENT_SPECIAL_DATA" + SUFFIX; public static final String READ_GRADUATION_STUDENT_OPTIONAL_PROGRAM = PREFIX + "SCOPE_READ_GRAD_STUDENT_SPECIAL_DATA" + SUFFIX; diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusControllerTest.java index e8905fe6..8ab3af82 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GraduationStatusControllerTest.java @@ -603,6 +603,24 @@ public void testGetStudentsCountForAmalgamatedSchoolReport() { Mockito.verify(graduationStatusService).countStudentsForAmalgamatedSchoolReport(mincode); } + @Test + public void testGetStudentsCount() { + // ID + String mincode = "123456789"; + Mockito.when(graduationStatusService.countBySchoolOfRecordsAndStudentStatus(List.of(mincode), "CUR")).thenReturn(1L); + graduationStatusController.getStudentsCount("CUR", List.of(mincode)); + Mockito.verify(graduationStatusService).countBySchoolOfRecordsAndStudentStatus(List.of(mincode), "CUR"); + } + + @Test + public void testArchiveStudents() { + // ID + String mincode = "123456789"; + Mockito.when(graduationStatusService.archiveStudents(1L, List.of(mincode), "CUR")).thenReturn(1); + graduationStatusController.archiveStudents(1L, "CUR", List.of(mincode)); + Mockito.verify(graduationStatusService).archiveStudents(1L, List.of(mincode), "CUR"); + } + @Test public void testGetStudentForBatch() { String mincode = "123456789"; 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 41ba286b..c65d2271 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 @@ -2891,6 +2891,31 @@ public void testGetStudentsCountForAmalgamatedSchoolReport() { } + @Test + public void testCountBySchoolOfRecordsAndStudentStatus() { + Mockito.when(graduationStatusRepository.countBySchoolOfRecordsAndStudentStatus(List.of("12345678"), "CUR")).thenReturn(1L); + Long count = graduationStatusService.countBySchoolOfRecordsAndStudentStatus(List.of("12345678"), "CUR"); + assertThat(count).isNotNull().isEqualTo(1L); + Mockito.when(graduationStatusRepository.countByStudentStatus("CUR")).thenReturn(2L); + count = graduationStatusService.countBySchoolOfRecordsAndStudentStatus(null, "CUR"); + assertThat(count).isNotNull().isEqualTo(2L); + + } + + @Test + public void testArchiveStudents() { + Mockito.when(graduationStatusRepository.archiveStudents(List.of("12345678"), "CUR", "ARC", 1L)).thenReturn(1); + Integer count = graduationStatusService.archiveStudents(1L, List.of("12345678"), "CUR"); + assertThat(count).isNotNull().isEqualTo(1); + } + + @Test + public void testArchiveStudentEmpty() { + Mockito.when(graduationStatusRepository.archiveStudents("CUR", "ARC", 1L)).thenReturn(1); + Integer count = graduationStatusService.archiveStudents(1L, new ArrayList<>(), "CUR"); + assertThat(count).isNotNull().isEqualTo(1); + } + @Test public void testGetStudentsForAmalgamatedSchoolReport() { List res = amalgamatedReports("TVRNONGRAD",false);