From ee4c49fd2266285b795c13fa6df0fbd01bdfc438 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 20 Aug 2024 15:52:44 -0600 Subject: [PATCH] Fix username for student history --- .../controller/GradStudentController.java | 28 +++++++---- .../GraduationStatusController.java | 4 +- .../GraduationStudentRecordRepository.java | 13 ++++- .../service/GradStudentService.java | 17 ++++++- .../service/GraduationStatusService.java | 16 ++++-- .../gradstudent/service/HistoryService.java | 30 ++++++++++-- .../util/EducGradStudentApiConstants.java | 1 + .../controller/GradStudentControllerTest.java | 14 +++++- .../GraduationStatusControllerTest.java | 19 +++++++ .../service/GradStudentServiceTest.java | 7 +++ .../service/GraduationStatusServiceTest.java | 17 ++++++- .../service/HistoryServiceTest.java | 49 +++++++++++++++++++ 12 files changed, 190 insertions(+), 25 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GradStudentController.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GradStudentController.java index dfcebcbb..6bd88e72 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GradStudentController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/controller/GradStudentController.java @@ -1,22 +1,23 @@ package ca.bc.gov.educ.api.gradstudent.controller; -import java.util.List; - import ca.bc.gov.educ.api.gradstudent.model.dto.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - 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.PermissionsConstants; import io.swagger.v3.oas.annotations.OpenAPIDefinition; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.info.Info; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.UUID; @RestController @CrossOrigin @@ -26,7 +27,8 @@ public class GradStudentController { @SuppressWarnings("unused") private static final Logger logger = LoggerFactory.getLogger(GradStudentController.class); - + private static final String BEARER = "Bearer "; + private final GradStudentService gradStudentService; public GradStudentController(GradStudentService gradStudentService) { @@ -116,4 +118,12 @@ public GraduationStudentRecordDistribution getGradStudentByStudentIDFromGRAD(@Pa public Student addNewPenFromStudentAPI(@Validated @RequestBody StudentCreate student, @RequestHeader(name="Authorization") String accessToken) { return gradStudentService.addNewPenFromStudentAPI(student, accessToken.replaceAll("Bearer ", "")); } + + @PostMapping (EducGradStudentApiConstants.GRAD_STUDENT_BY_SEARCH_CRITERIAS) + @PreAuthorize(PermissionsConstants.READ_GRADUATION_STUDENT) + @Operation(summary = "Find Students by StudentSearchRequest criteria", description = "Find Students by StudentSearchRequest criteria", tags = { "Search Student Records" }) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) + public List searchGraduationStudentRecords(@RequestBody StudentSearchRequest searchRequest) { + return gradStudentService.getStudentIDsBySearchCriteriaOrAll(searchRequest); + } } 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 adb6ca5e..603c2264 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 @@ -359,9 +359,9 @@ public ResponseEntity saveStudentGradStatusDistribution @PreAuthorize(PermissionsConstants.UPDATE_GRADUATION_STUDENT) @Operation(summary = "Save Student Grad Status by Student ID for projected run", description = "Save Student Grad Status by Student ID for projected run", tags = { "Student Graduation Status" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) - public ResponseEntity> updateStudentGradHistoryStatusDistributionRun(@PathVariable Long batchID, @RequestParam(required = false) String userName, @RequestParam(required = false) String activityCode) { + public ResponseEntity> updateStudentGradHistoryStatusDistributionRun(@PathVariable Long batchID, @RequestParam(required = false) String userName, @RequestParam(required = false) String activityCode, @RequestBody List studentGuids) { logger.debug("Save Distribution student Grad history for Student ID"); - return response.UPDATED(historyService.updateStudentRecordHistoryDistributionRun(batchID, userName, activityCode)); + return response.UPDATED(historyService.updateStudentRecordHistoryDistributionRun(batchID, userName, activityCode, studentGuids)); } @GetMapping (EducGradStudentApiConstants.STUDENT_LIST_FOR_SCHOOL_REPORT) 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 64b1b8a1..69f97703 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 @@ -50,9 +50,15 @@ public interface GraduationStudentRecordRepository extends JpaRepository findBySchoolOfRecordInAndStudentStatus(List schoolOfRecords, String studentStatus); + @Query("select c.studentID from GraduationStudentRecordEntity c where c.schoolOfRecord IN (:schoolOfRecords)") + List findBySchoolOfRecordIn(List schoolOfRecords); + @Query("select c.studentID from GraduationStudentRecordEntity c where c.studentStatus=:studentStatus") List findByStudentStatus(String studentStatus); + @Query("select c.studentID from GraduationStudentRecordEntity c") + List findAllStudentGuids(); + List findBySchoolOfRecordAndStudentStatusAndStudentGradeIn(String schoolOfRecord, String studentStatus, List studentGrade); @Query("select count(*) from GraduationStudentRecordEntity c where c.schoolOfRecord=:schoolOfRecord and c.studentStatus='CUR' and (c.studentGrade='AD' or c.studentGrade='12')") @@ -61,6 +67,9 @@ public interface GraduationStudentRecordRepository extends JpaRepository schoolOfRecords, String studentStatus); + @Query("select count(*) from GraduationStudentRecordEntity c where c.schoolOfRecord IN (:schoolOfRecords)") + Long countBySchoolOfRecords(List schoolOfRecords); + @Query("select count(*) from GraduationStudentRecordEntity c where c.studentStatus=:studentStatus") Long countByStudentStatus(String studentStatus); @@ -96,8 +105,8 @@ void updateStudentGuidPenXrefRecord( long countStudentGuidPenXrefRecord(@Param("studentGuid") UUID studentGuid); @Query(value="select STUDENT_GUID from STUDENT_GUID_PEN_XREF \n" - + "where STUDENT_PEN = :pen", nativeQuery = true) - byte[] findStudentID(@Param("pen") String pen); + + "where STUDENT_PEN in (:pens)", nativeQuery = true) + List findStudentIDsByPenIn(@Param("pens") List pens); @Query("select c.studentID from GraduationStudentRecordEntity c where c.studentStatus = :statusCode and c.studentID in :studentIDList") List filterGivenStudentsByStatusCode(@Param("studentIDList") List studentIDs, @Param("statusCode") String statusCode); 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 9472a754..db672025 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 @@ -143,7 +143,7 @@ public GradOnlyStudentSearch getGRADStudents(StudentSearchRequest studentSearchR h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID()); }) .retrieve().bodyToMono(new ParameterizedTypeReference>() {}).block(); - List studentList = response != null ?response.getContent():new ArrayList<>(); + List studentList = response != null ? response.getContent() : new ArrayList<>(); if (!studentList.isEmpty()) { studentList.forEach(st -> { GradSearchStudent gradStu = populateGradSearchStudent(st, accessToken); @@ -405,4 +405,19 @@ public List getStudentIDsByStatusCode(List studentIDs, String status } return results; } + + public List getStudentIDsBySearchCriteriaOrAll(StudentSearchRequest searchRequest) { + ArrayList result = new ArrayList<>(); + result.addAll(searchRequest.getStudentIDs()); + if(searchRequest.getPens() != null && !searchRequest.getPens().isEmpty()) { + result.addAll(graduationStatusRepository.findStudentIDsByPenIn(searchRequest.getPens())); + } + if(searchRequest.getSchoolOfRecords() != null && !searchRequest.getSchoolOfRecords().isEmpty()) { + result.addAll(graduationStatusRepository.findBySchoolOfRecordIn(searchRequest.getSchoolOfRecords())); + } + if(result.isEmpty()) { + result.addAll(graduationStatusRepository.findAllStudentGuids()); + } + return result; + } } 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 10a8b237..b1cae25b 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 @@ -1385,10 +1385,12 @@ public Integer countStudentsForAmalgamatedSchoolReport(String schoolOfRecord) { } public Long countBySchoolOfRecordsAndStudentStatus(List schoolOfRecords, String studentStatus) { - if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) { - return graduationStatusRepository.countBySchoolOfRecordsAndStudentStatus(schoolOfRecords, StringUtils.defaultString(studentStatus, "CUR")); + if(schoolOfRecords != null && !schoolOfRecords.isEmpty() && StringUtils.isNotBlank(studentStatus) && !StringUtils.equalsAnyIgnoreCase(studentStatus, "null")) { + return graduationStatusRepository.countBySchoolOfRecordsAndStudentStatus(schoolOfRecords, StringUtils.upperCase(studentStatus)); + } else if(StringUtils.isNotBlank(studentStatus) && !StringUtils.equalsAnyIgnoreCase(studentStatus, "null")) { + return graduationStatusRepository.countByStudentStatus(StringUtils.upperCase(studentStatus)); } else { - return graduationStatusRepository.countByStudentStatus(StringUtils.defaultString(studentStatus, "CUR")); + return countBySchoolOfRecords(schoolOfRecords); } } @@ -1448,6 +1450,14 @@ private void saveBatchFlagsOfGraduationStudentRecord(GraduationStudentRecordEnti } } + private Long countBySchoolOfRecords(List schoolOfRecords) { + if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) { + return graduationStatusRepository.countBySchoolOfRecords(schoolOfRecords); + } else { + return graduationStatusRepository.count(); + } + } + private void resetBatchFlags(GraduationStudentRecordEntity gradEntity, boolean projectedRun) { String flag = null; if (gradEntity.getProgram().equalsIgnoreCase("SCCP") && EducGradStudentApiUtils.isDateInFuture(gradEntity.getProgramCompletionDate())) { diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/HistoryService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/HistoryService.java index 7c8db130..98f6ee56 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/HistoryService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/HistoryService.java @@ -9,6 +9,7 @@ import ca.bc.gov.educ.api.gradstudent.model.transformer.GraduationStudentRecordHistoryTransformer; import ca.bc.gov.educ.api.gradstudent.model.transformer.StudentOptionalProgramHistoryTransformer; import ca.bc.gov.educ.api.gradstudent.repository.GraduationStudentRecordHistoryRepository; +import ca.bc.gov.educ.api.gradstudent.repository.GraduationStudentRecordRepository; import ca.bc.gov.educ.api.gradstudent.repository.HistoryActivityRepository; import ca.bc.gov.educ.api.gradstudent.repository.StudentOptionalProgramHistoryRepository; import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants; @@ -38,6 +39,7 @@ public class HistoryService { final WebClient webClient; + final GraduationStudentRecordRepository graduationStatusRepository; final GraduationStudentRecordHistoryRepository graduationStudentRecordHistoryRepository; final GraduationStudentRecordHistoryTransformer graduationStudentRecordHistoryTransformer; final StudentOptionalProgramHistoryRepository studentOptionalProgramHistoryRepository; @@ -46,13 +48,14 @@ public class HistoryService { final EducGradStudentApiConstants constants; @Autowired - public HistoryService(WebClient webClient, GraduationStudentRecordHistoryRepository graduationStudentRecordHistoryRepository, GraduationStudentRecordHistoryTransformer graduationStudentRecordHistoryTransformer, StudentOptionalProgramHistoryRepository studentOptionalProgramHistoryRepository, StudentOptionalProgramHistoryTransformer studentOptionalProgramHistoryTransformer, EducGradStudentApiConstants constants, HistoryActivityRepository historyActivityRepository) { + public HistoryService(WebClient webClient, GraduationStudentRecordHistoryRepository graduationStudentRecordHistoryRepository, GraduationStudentRecordHistoryTransformer graduationStudentRecordHistoryTransformer, StudentOptionalProgramHistoryRepository studentOptionalProgramHistoryRepository, StudentOptionalProgramHistoryTransformer studentOptionalProgramHistoryTransformer, EducGradStudentApiConstants constants, HistoryActivityRepository historyActivityRepository, GraduationStudentRecordRepository graduationStatusRepository) { this.webClient = webClient; this.graduationStudentRecordHistoryRepository = graduationStudentRecordHistoryRepository; this.graduationStudentRecordHistoryTransformer = graduationStudentRecordHistoryTransformer; this.studentOptionalProgramHistoryRepository = studentOptionalProgramHistoryRepository; this.studentOptionalProgramHistoryTransformer = studentOptionalProgramHistoryTransformer; this.historyActivityRepository = historyActivityRepository; + this.graduationStatusRepository = graduationStatusRepository; this.constants = constants; } @@ -160,13 +163,30 @@ public Page getStudentHistoryByBatchID(Lon } @Transactional - public Integer updateStudentRecordHistoryDistributionRun(Long batchId, String updateUser, String activityCode) { + public Integer updateStudentRecordHistoryDistributionRun(Long batchId, String updateUser, String activityCode, List studentGuids) { + Integer result = 0; LocalDateTime updateDate = LocalDateTime.now(); - if(StringUtils.isBlank(activityCode) || StringUtils.equalsIgnoreCase(activityCode, "null")) { - return graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, updateUser, updateDate); + if(studentGuids != null && !studentGuids.isEmpty()) { + Page recordHistoryEntityPage = graduationStudentRecordHistoryRepository.findByBatchId(batchId, PageRequest.of(0, Integer.SIZE)); + if(recordHistoryEntityPage == null || recordHistoryEntityPage.isEmpty()) { + for (UUID studentGuid : studentGuids) { + GraduationStudentRecordEntity entity = graduationStatusRepository.findByStudentID(studentGuid); + if(entity != null) { + GraduationStudentRecordEntity toBeSaved = new GraduationStudentRecordEntity(); + BeanUtils.copyProperties(entity, toBeSaved); + toBeSaved.setUpdateDate(updateDate); + toBeSaved.setUpdateUser(updateUser); + createStudentHistory(toBeSaved, activityCode); + result ++; + } + } + } + } else if(StringUtils.isBlank(activityCode) || StringUtils.equalsIgnoreCase(activityCode, "null")) { + result = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, updateUser, updateDate); } else { - return graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, activityCode, updateUser, updateDate); + result = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, activityCode, updateUser, updateDate); } + return result; } } 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 a28611e2..dad2e2f3 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 @@ -27,6 +27,7 @@ public class EducGradStudentApiConstants { public static final String GRAD_STUDENT_DEMOG_BY_PEN = "/demog/pen/{pen}"; public static final String GRAD_STUDENT_BY_STUDENT_ID_STUDENT_API = "/stdid/{studentID}"; public static final String GRAD_STUDENT_BY_STUDENT_ID_GRAD="/grad/{studentID}"; + public static final String GRAD_STUDENT_BY_SEARCH_CRITERIAS = "/gradstudentbysearchcriteria"; public static final String GRAD_STUDENT_BY_LAST_NAME = "/gradstudent"; public static final String GRAD_STUDENT_BY_FIRST_NAME = "/studentsearchfirstname"; public static final String GRAD_STUDENT_BY_MULTIPLE_STUDENTIDS = "/multistudentids"; diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GradStudentControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GradStudentControllerTest.java index 9c18bea9..48c82f6d 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GradStudentControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/controller/GradStudentControllerTest.java @@ -1,6 +1,9 @@ package ca.bc.gov.educ.api.gradstudent.controller; -import ca.bc.gov.educ.api.gradstudent.model.dto.*; +import ca.bc.gov.educ.api.gradstudent.model.dto.GradSearchStudent; +import ca.bc.gov.educ.api.gradstudent.model.dto.StudentCreate; +import ca.bc.gov.educ.api.gradstudent.model.dto.StudentSearch; +import ca.bc.gov.educ.api.gradstudent.model.dto.StudentSearchRequest; import ca.bc.gov.educ.api.gradstudent.service.GradStudentService; import org.junit.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -12,6 +15,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.util.Arrays; +import java.util.List; import java.util.UUID; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -134,4 +138,12 @@ public void testAddNewPenFromStudentAPI() { Mockito.verify(gradStudentService).addNewPenFromStudentAPI(student, "accessToken"); } + @Test + public void testSearchGraduationStudentRecords() { + StudentSearchRequest searchRequest = StudentSearchRequest.builder().schoolOfRecords(List.of("12345678")).build(); + Mockito.when(gradStudentService.getStudentIDsBySearchCriteriaOrAll(searchRequest)).thenReturn(List.of(UUID.randomUUID())); + gradStudentController.searchGraduationStudentRecords(searchRequest); + Mockito.verify(gradStudentService).getStudentIDsBySearchCriteriaOrAll(searchRequest); + } + } 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 8ab3af82..601f5b72 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 @@ -558,6 +558,13 @@ public void testGetStudentsForYearlyRun() { Mockito.verify(graduationStatusService).getStudentsForYearlyDistribution(); } + @Test + public void testUpdateStudentGradHistoryStatusDistributionRun() { + Mockito.when(historyService.updateStudentRecordHistoryDistributionRun(1L, "USER", "activityCode", List.of())).thenReturn(1); + graduationStatusController.updateStudentGradHistoryStatusDistributionRun(1L, "USER", "activityCode", List.of()); + Mockito.verify(historyService).updateStudentRecordHistoryDistributionRun(1L, "USER", "activityCode", List.of()); + } + @Test public void testGetStudentsForSchoolReport() { // ID @@ -610,6 +617,18 @@ public void testGetStudentsCount() { Mockito.when(graduationStatusService.countBySchoolOfRecordsAndStudentStatus(List.of(mincode), "CUR")).thenReturn(1L); graduationStatusController.getStudentsCount("CUR", List.of(mincode)); Mockito.verify(graduationStatusService).countBySchoolOfRecordsAndStudentStatus(List.of(mincode), "CUR"); + + Mockito.when(graduationStatusService.countBySchoolOfRecordsAndStudentStatus(List.of(), "CUR")).thenReturn(1L); + graduationStatusController.getStudentsCount("CUR", List.of()); + Mockito.verify(graduationStatusService).countBySchoolOfRecordsAndStudentStatus(List.of(), "CUR"); + + Mockito.when(graduationStatusService.countBySchoolOfRecordsAndStudentStatus(List.of(mincode), null)).thenReturn(1L); + graduationStatusController.getStudentsCount(null, List.of(mincode)); + Mockito.verify(graduationStatusService).countBySchoolOfRecordsAndStudentStatus(List.of(mincode), null); + + Mockito.when(graduationStatusService.countBySchoolOfRecordsAndStudentStatus(List.of(), null)).thenReturn(1L); + graduationStatusController.getStudentsCount(null, List.of()); + Mockito.verify(graduationStatusService).countBySchoolOfRecordsAndStudentStatus(List.of(), null); } @Test 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 fc78eb7e..beb254f0 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 @@ -829,7 +829,14 @@ public void testGetStudentIDsByStatusCode() { assertThat(result.get(0)).isEqualTo(studentID1); } + @Test + public void testGetStudentIDsBySearchCriterias() { + StudentSearchRequest searchRequest = StudentSearchRequest.builder().schoolOfRecords(List.of("12345678")).build(); + when(graduationStatusRepository.findBySchoolOfRecordIn(List.of("12345678"))).thenReturn(List.of(UUID.randomUUID())); + List results = gradStudentService.getStudentIDsBySearchCriteriaOrAll(searchRequest); + assertThat(results).isNotEmpty(); + } @SneakyThrows protected Object createDataObjectFromJson(String jsonPath, Class clazz) { 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 e45fb6b0..438a84d6 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 @@ -3035,8 +3035,21 @@ 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"); + + Mockito.when(graduationStatusRepository.countByStudentStatus("CUR")).thenReturn(1L); + count = graduationStatusService.countBySchoolOfRecordsAndStudentStatus(List.of(), "CUR"); + assertThat(count).isNotNull().isEqualTo(1L); + + Mockito.when(graduationStatusRepository.countBySchoolOfRecords(List.of("12345678"))).thenReturn(1L); + count = graduationStatusService.countBySchoolOfRecordsAndStudentStatus(List.of("12345678"), null); + assertThat(count).isNotNull().isEqualTo(1L); + + Mockito.when(graduationStatusRepository.countBySchoolOfRecords(List.of("12345678"))).thenReturn(1L); + count = graduationStatusService.countBySchoolOfRecordsAndStudentStatus(List.of("12345678"), "null"); + assertThat(count).isNotNull().isEqualTo(1L); + + Mockito.when(graduationStatusRepository.count()).thenReturn(2L); + count = graduationStatusService.countBySchoolOfRecordsAndStudentStatus(List.of(), null); assertThat(count).isNotNull().isEqualTo(2L); } 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 d4038b90..bfd61902 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 @@ -37,6 +37,7 @@ import reactor.core.publisher.Mono; import java.sql.Date; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -268,4 +269,52 @@ public void testGetStudentHistoryByBatchID() { assertThat(list).isNotEmpty(); assertThat(list.getContent()).hasSize(1); } + + @Test + public void testUpdateStudentRecordHistoryDistributionRun() { + // ID + UUID studentID = UUID.randomUUID(); + UUID historyID = UUID.randomUUID(); + List histList = new ArrayList<>(); + + Student std = new Student(); + std.setPen("123123"); + std.setLegalFirstName("Asdad"); + std.setLegalMiddleNames("Adad"); + std.setLegalLastName("sadad"); + + GradSearchStudent serObj = new GradSearchStudent(); + serObj.setPen("123123"); + serObj.setLegalFirstName("Asdad"); + serObj.setLegalMiddleNames("Adad"); + serObj.setLegalLastName("sadad"); + GraduationData gd = new GraduationData(); + gd.setGradStudent(serObj); + + GraduationStudentRecordHistoryEntity graduationStudentRecordHistoryEntity = new GraduationStudentRecordHistoryEntity(); + graduationStudentRecordHistoryEntity.setStudentID(studentID); + graduationStudentRecordHistoryEntity.setStudentStatus("A"); + graduationStudentRecordHistoryEntity.setRecalculateGradStatus("Y"); + graduationStudentRecordHistoryEntity.setProgram("2018-EN"); + graduationStudentRecordHistoryEntity.setSchoolOfRecord("223333"); + graduationStudentRecordHistoryEntity.setGpa("4"); + graduationStudentRecordHistoryEntity.setHistoryID(new UUID(1,1)); + graduationStudentRecordHistoryEntity.setActivityCode("GRADALG"); + graduationStudentRecordHistoryEntity.setBatchId(4000L); + graduationStudentRecordHistoryEntity.setPen("123123"); + graduationStudentRecordHistoryEntity.setLegalFirstName("Asdad"); + graduationStudentRecordHistoryEntity.setLegalMiddleNames("Adad"); + graduationStudentRecordHistoryEntity.setLegalLastName("sadad"); + histList.add(graduationStudentRecordHistoryEntity); + Pageable paging = PageRequest.of(0, 10); + Page hPage = new PageImpl(histList); + + when(graduationStudentRecordHistoryRepository.findByBatchId(4000L, PageRequest.of(0, Integer.SIZE))).thenReturn(hPage); + when(graduationStudentRecordHistoryRepository.findByStudentID(studentID)).thenReturn(List.of(graduationStudentRecordHistoryEntity)); + when(graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(4000L, "USER", LocalDateTime.now())).thenReturn(1); + + var result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", "activityCode", List.of(studentID)); + assertThat(result).isNotNull(); + assertThat(result).isEqualTo(0); + } }