Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRAD2-2322 #274

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@ public interface SchoolReportsRepository extends JpaRepository<SchoolReportsEnti
@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="update SCHOOL_REPORT set REPORT_TYPE_CODE = :reportTypeTo, update_date = SYSDATE, update_user = 'Batch ' || :batchId || ' Archive Process' where REPORT_TYPE_CODE = :reportTypeFrom", nativeQuery=true)
Integer archiveSchoolReports(String reportTypeFrom, String reportTypeTo, long batchId);

@Modifying
@Query(value="delete from 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);

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ public Integer countBySchoolOfRecordsAndReportType(List<String> schoolOfRecords,
Integer reportsCount = 0;
if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) {
reportsCount += schoolReportsRepository.countBySchoolOfRecordsAndReportType(schoolOfRecords, reportType);
} else {
reportsCount += schoolReportsRepository.countByReportType(reportType);
}
return reportsCount;
}
Expand All @@ -858,15 +860,22 @@ public Integer archiveSchoolReports(long batchId, List<String> schoolOfRecords,
Integer updatedReportsCount = 0;
Integer deletedReportsCount = 0;
Integer originalReportsCount = 0;
reportType = StringUtils.upperCase(StringUtils.endsWithIgnoreCase(reportType, "ARC") ? StringUtils.removeEndIgnoreCase(reportType, "ARC") : reportType);
String archivedReportType = StringUtils.upperCase(StringUtils.endsWith(reportType, "ARC") ? reportType : reportType + "ARC");
if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) {
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);
}
} else {
originalReportsCount += schoolReportsRepository.countByReportType(reportType);
updatedReportsCount += schoolReportsRepository.archiveSchoolReports(reportType, archivedReportType, batchId);
if(originalReportsCount.equals(updatedReportsCount)) {
deletedReportsCount += schoolReportsRepository.deleteSchoolReports(archivedReportType);
logger.debug("{} School Reports deleted", deletedReportsCount);
}
}
return updatedReportsCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,10 @@ public void testCountBySchoolOfRecordsAndReportType() {
Mockito.when(schoolReportsRepository.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType")).thenReturn(1);
Integer count = commonService.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType");
assertThat(count).isNotNull().isEqualTo(1);

Mockito.when(schoolReportsRepository.countByReportType("reportType")).thenReturn(1);
count = commonService.countBySchoolOfRecordsAndReportType(List.of(), "reportType");
assertThat(count).isNotNull().isEqualTo(1);
}

@Test
Expand All @@ -1698,6 +1702,16 @@ public void testArchiveSchoolReports() {
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);

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

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

@Test
Expand Down
Loading