Skip to content

Commit

Permalink
Merge pull request #668 from bcgov/develop/alex-GRAD2-2283
Browse files Browse the repository at this point in the history
GRAD2-2283
  • Loading branch information
arybakov-cgi authored Jul 17, 2024
2 parents abd09c7 + 66a027e commit cb07f88
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,22 @@ public ResponseEntity<Integer> 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<Long> getStudentsCount(@RequestParam(required = false) String studentStatus, @RequestBody List<String> 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<Integer> archiveStudents(@RequestParam long batchId, @RequestParam(required = false) String studentStatus, @RequestBody List<String> 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" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ public interface GraduationStudentRecordRepository extends JpaRepository<Graduat
@Query("select count(*) from GraduationStudentRecordEntity c where c.schoolOfRecord=:schoolOfRecord and c.studentStatus='CUR' and (c.studentGrade='AD' or c.studentGrade='12')")
Integer countBySchoolOfRecordAmalgamated(String schoolOfRecord);

@Query("select count(*) from GraduationStudentRecordEntity c where c.schoolOfRecord IN (:schoolOfRecords) and c.studentStatus=:studentStatus")
Long countBySchoolOfRecordsAndStudentStatus(List<String> 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<String> 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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1369,6 +1369,23 @@ public Integer countStudentsForAmalgamatedSchoolReport(String schoolOfRecord) {
return graduationStatusRepository.countBySchoolOfRecordAmalgamated(schoolOfRecord);
}

public Long countBySchoolOfRecordsAndStudentStatus(List<String> 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<String> 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<UUID> studentIDs) {
logger.debug("updateStudentFlagReadyForBatchJobByStudentIDs");
for(UUID uuid: studentIDs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand Down Expand Up @@ -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}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UUID> res = amalgamatedReports("TVRNONGRAD",false);
Expand Down

0 comments on commit cb07f88

Please sign in to comment.