Skip to content

Commit

Permalink
GRAD2-2322
Browse files Browse the repository at this point in the history
School Reports Archive Process: Backend endpoints and Processing To Complete
  • Loading branch information
arybakov-cgi committed Jul 18, 2024
1 parent 2d10faf commit 35a2869
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public ResponseEntity<InputStreamResource> getStudentCredentialByType(@PathVaria
@PreAuthorize(PermissionsConstants.READ_GRADUATION_STUDENT_REPORTS)
@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> getReportsCount(@RequestParam String reportType, @RequestBody List<String> schoolOfRecords) {
public ResponseEntity<Integer> getReportsCount(@RequestParam String reportType, @RequestBody List<String> schoolOfRecords) {
return response.GET(commonService.countBySchoolOfRecordsAndReportType(schoolOfRecords, reportType));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ public interface SchoolReportsRepository extends JpaRepository<SchoolReportsEnti
Optional<SchoolReportsEntity> findBySchoolOfRecordAndReportTypeCodeOrderBySchoolOfRecord(String schoolOfRecord, String reportTypeCode);

@Query("select count(*) from SchoolReportsLightEntity c where c.schoolOfRecord IN (:schoolOfRecords) and c.reportTypeCode=:reportType")
Long countBySchoolOfRecordsAndReportType(List<String> schoolOfRecords, String reportType);
Integer countBySchoolOfRecordsAndReportType(List<String> schoolOfRecords, String reportType);

@Query("select count(*) from SchoolReportsLightEntity c where c.reportTypeCode=:reportType")
Long countByReportType(String reportType);
Integer countByReportType(String reportType);

@Modifying
@Query(value="update SCHOOL_REPORT set REPORT_TYPE_CODE = :reportTypeTo, update_date = SYSDATE, update_user = 'Batch ' || :batchId || ' Archive Process' where school_of_record in (:schoolOfRecords) and REPORT_TYPE_CODE = :reportTypeFrom", nativeQuery=true)
Integer archiveSchoolReports(List<String> schoolOfRecords, String reportTypeFrom, String reportTypeTo, long batchId);

@Modifying
@Query(value="delete SCHOOL_REPORT where school_of_record in (:schoolOfRecords) and REPORT_TYPE_CODE = :reportType", nativeQuery=true)
@Query(value="delete SCHOOL_REPORT where school_of_record in (:schoolOfRecords) and REPORT_TYPE_CODE = :reportType and UPDATE_DATE <= SYSDATE - 1", nativeQuery=true)
Integer deleteSchoolReports(List<String> schoolOfRecords, String reportType);

}
Original file line number Diff line number Diff line change
Expand Up @@ -845,8 +845,8 @@ private synchronized List<ReportGradStudentData> getReportGradStudentData(String
.block();
}

public Long countBySchoolOfRecordsAndReportType(List<String> schoolOfRecords, String reportType) {
Long reportsCount = 0L;
public Integer countBySchoolOfRecordsAndReportType(List<String> schoolOfRecords, String reportType) {
Integer reportsCount = 0;
if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) {
reportsCount += schoolReportsRepository.countBySchoolOfRecordsAndReportType(schoolOfRecords, reportType);
}
Expand All @@ -855,12 +855,20 @@ public Long countBySchoolOfRecordsAndReportType(List<String> schoolOfRecords, St

@Transactional
public Integer archiveSchoolReports(long batchId, List<String> schoolOfRecords, String reportType) {
Integer reportsCount = 0;
Integer updatedReportsCount = 0;
Integer deletedReportsCount = 0;
Integer originalReportsCount = 0;
if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) {
schoolReportsRepository.deleteSchoolReports(schoolOfRecords, reportType + "ARC");
reportsCount += schoolReportsRepository.archiveSchoolReports(schoolOfRecords, reportType, reportType + "ARC", batchId);
reportType = StringUtils.upperCase(StringUtils.endsWithIgnoreCase(reportType, "ARC") ? StringUtils.removeEndIgnoreCase(reportType, "ARC") : reportType);
String archivedReportType = StringUtils.upperCase(StringUtils.endsWith(reportType, "ARC") ? reportType : reportType + "ARC");
originalReportsCount += schoolReportsRepository.countBySchoolOfRecordsAndReportType(schoolOfRecords, reportType);
updatedReportsCount += schoolReportsRepository.archiveSchoolReports(schoolOfRecords, reportType, archivedReportType, batchId);
if(originalReportsCount.equals(updatedReportsCount)) {
deletedReportsCount += schoolReportsRepository.deleteSchoolReports(schoolOfRecords, archivedReportType);
logger.debug("{} School Reports deleted", deletedReportsCount);
}
}
return reportsCount;
return updatedReportsCount;
}

class UUIDPageTask implements Callable<Object> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testGetStudentCertificate() {
public void testGetReportsCount() {
// ID
String mincode = "123456789";
Mockito.when(commonService.countBySchoolOfRecordsAndReportType(List.of(mincode), "reportType")).thenReturn(1L);
Mockito.when(commonService.countBySchoolOfRecordsAndReportType(List.of(mincode), "reportType")).thenReturn(1);
commonController.getReportsCount("reportType", List.of(mincode));
Mockito.verify(commonService).countBySchoolOfRecordsAndReportType(List.of(mincode), "reportType");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1682,30 +1682,35 @@ public void testCheckStudentCertificateExistsForSCCP_with_SCCP_Certificate() {

@Test
public void testCountBySchoolOfRecordsAndReportType() {
Mockito.when(schoolReportsRepository.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType")).thenReturn(1L);
Long count = commonService.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType");
Mockito.when(schoolReportsRepository.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType")).thenReturn(1);
Integer count = commonService.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType");
assertThat(count).isNotNull().isEqualTo(1L);
}

@Test
public void testArchiveSchoolReports() {
Mockito.when(schoolReportsRepository.deleteSchoolReports(List.of("12345678"), "reportTypeARC")).thenReturn(1);
Mockito.when(schoolReportsRepository.archiveSchoolReports(List.of("12345678"), "reportType", "reportTypeARC", 1L)).thenReturn(1);
Mockito.when(schoolReportsRepository.deleteSchoolReports(List.of("12345678"), "reportTypeARC".toUpperCase())).thenReturn(1);
Mockito.when(schoolReportsRepository.archiveSchoolReports(List.of("12345678"), "reportType".toUpperCase(), "reportTypeARC".toUpperCase(), 1L)).thenReturn(1);
Integer count = commonService.archiveSchoolReports(1L, List.of("12345678"), "reportType");
assertThat(count).isNotNull().isEqualTo(1);

Mockito.when(schoolReportsRepository.deleteSchoolReports(List.of("12345678"), "reportTypeARC".toUpperCase())).thenReturn(0);
Mockito.when(schoolReportsRepository.archiveSchoolReports(List.of("12345678"), "reportType".toUpperCase(), "reportTypeARC".toUpperCase(), 1L)).thenReturn(0);
count = commonService.archiveSchoolReports(1L, List.of("12345678"), "reportType");
assertThat(count).isNotNull().isEqualTo(0);
}

@Test
public void testArchiveSchoolReportsEmpty() {
Mockito.when(schoolReportsRepository.archiveSchoolReports(new ArrayList<>(), "reportType", "ARC", 1L)).thenReturn(0);
Mockito.when(schoolReportsRepository.archiveSchoolReports(new ArrayList<>(), "reportType".toUpperCase(), "reportTypeARC".toUpperCase(), 1L)).thenReturn(0);
Integer count = commonService.archiveSchoolReports(1L, new ArrayList<>(), "reportType");
assertThat(count).isNotNull().isEqualTo(0);
}

@Test
public void testDeleteSchoolReports() {
Mockito.when(schoolReportsRepository.deleteSchoolReports(List.of("12345678"), "reportTypeARC")).thenReturn(1);
Mockito.when(schoolReportsRepository.archiveSchoolReports(List.of("12345678"), "reportType", "reportTypeARC", 1L)).thenReturn(1);
Mockito.when(schoolReportsRepository.deleteSchoolReports(List.of("12345678"), "reportTypeARC".toUpperCase())).thenReturn(1);
Mockito.when(schoolReportsRepository.archiveSchoolReports(List.of("12345678"), "reportType".toUpperCase(), "reportTypeARC".toUpperCase(), 1L)).thenReturn(1);
Integer count = commonService.archiveSchoolReports(1L, List.of("12345678"), "reportType");
assertThat(count).isNotNull().isEqualTo(1);
}
Expand Down

0 comments on commit 35a2869

Please sign in to comment.