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-2817 #280

Merged
merged 3 commits into from
Sep 6, 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 @@ -30,6 +30,12 @@ public interface SchoolReportsRepository extends JpaRepository<SchoolReportsEnti
@Query("select count(*) from SchoolReportsLightEntity c where c.reportTypeCode=:reportType")
Integer countByReportType(String reportType);

@Query("select c.id from SchoolReportsLightEntity c where c.schoolOfRecord IN (:schoolOfRecords) and c.reportTypeCode=:reportType")
List<UUID> getReportGuidsBySchoolOfRecordsAndReportType(List<String> schoolOfRecords, String reportType);

@Query("select c.id from SchoolReportsLightEntity c where c.reportTypeCode=:reportType")
List<UUID> getReportGuidsByReportType(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);
Expand All @@ -39,11 +45,11 @@ public interface SchoolReportsRepository extends JpaRepository<SchoolReportsEnti
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);
@Query(value="delete from SCHOOL_REPORT where SCHOOL_REPORT_ID not in (:schoolReportGuids) and school_of_record in (:schoolOfRecords) and REPORT_TYPE_CODE = :archivedReportType", nativeQuery=true)
Integer deleteSchoolOfRecordsNotMatchingSchoolReports(List<UUID> schoolReportGuids, List<String> schoolOfRecords, String archivedReportType);

@Modifying
@Query(value="delete from SCHOOL_REPORT where REPORT_TYPE_CODE = :reportType and UPDATE_DATE <= SYSDATE - 1", nativeQuery=true)
Integer deleteSchoolReports(String reportType);
@Query(value="delete from SCHOOL_REPORT where SCHOOL_REPORT_ID not in (:schoolReportGuids) and REPORT_TYPE_CODE = :archivedReportType", nativeQuery=true)
Integer deleteAllNotMatchingSchoolReports(List<UUID> schoolReportGuids, String archivedReportType);

}
Original file line number Diff line number Diff line change
Expand Up @@ -894,17 +894,19 @@ public Integer archiveSchoolReports(long batchId, List<String> schoolOfRecords,
Integer originalReportsCount = 0;
String archivedReportType = StringUtils.appendIfMissing(reportType, "ARC", "ARC");
if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) {
List<UUID> reportGuids = schoolReportsRepository.getReportGuidsBySchoolOfRecordsAndReportType(schoolOfRecords, reportType);
originalReportsCount += schoolReportsRepository.countBySchoolOfRecordsAndReportType(schoolOfRecords, reportType);
updatedReportsCount += schoolReportsRepository.archiveSchoolReports(schoolOfRecords, reportType, archivedReportType, batchId);
if(updatedReportsCount > 0 && originalReportsCount.equals(updatedReportsCount)) {
deletedReportsCount += schoolReportsRepository.deleteSchoolReports(schoolOfRecords, archivedReportType);
deletedReportsCount += schoolReportsRepository.deleteSchoolOfRecordsNotMatchingSchoolReports(reportGuids, schoolOfRecords, archivedReportType);
logger.debug("{} School Reports deleted", deletedReportsCount);
}
} else {
List<UUID> reportGuids = schoolReportsRepository.getReportGuidsByReportType(reportType);
originalReportsCount += schoolReportsRepository.countByReportType(reportType);
updatedReportsCount += schoolReportsRepository.archiveSchoolReports(reportType, archivedReportType, batchId);
if(updatedReportsCount > 0 && originalReportsCount.equals(updatedReportsCount)) {
deletedReportsCount += schoolReportsRepository.deleteSchoolReports(archivedReportType);
deletedReportsCount += schoolReportsRepository.deleteAllNotMatchingSchoolReports(reportGuids, archivedReportType);
logger.debug("{} School Reports deleted", deletedReportsCount);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1798,26 +1798,28 @@ public Page map(Function converter) {

@Test
public void testArchiveSchoolReports() {
UUID schoolReportGuid = UUID.randomUUID();
Mockito.when(schoolReportsRepository.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType".toUpperCase())).thenReturn(1);
Mockito.when(schoolReportsRepository.deleteSchoolReports(List.of("12345678"), "reportTypeARC".toUpperCase())).thenReturn(1);
Mockito.when(schoolReportsRepository.deleteSchoolOfRecordsNotMatchingSchoolReports(List.of(schoolReportGuid), List.of("12345678"), "reportTypeARC".toUpperCase())).thenReturn(1);
Mockito.when(schoolReportsRepository.deleteAllNotMatchingSchoolReports(List.of(schoolReportGuid), "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".toUpperCase());
assertThat(count).isNotNull().isEqualTo(1);

Mockito.when(schoolReportsRepository.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType".toUpperCase())).thenReturn(0);
Mockito.when(schoolReportsRepository.deleteSchoolReports(List.of("12345678"), "reportTypeARC".toUpperCase())).thenReturn(0);
Mockito.when(schoolReportsRepository.deleteAllNotMatchingSchoolReports(List.of(schoolReportGuid), "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".toUpperCase());
assertThat(count).isNotNull().isEqualTo(0);

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

Mockito.when(schoolReportsRepository.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType".toUpperCase())).thenReturn(0);
Mockito.when(schoolReportsRepository.deleteSchoolReports("reportTypeARC".toUpperCase())).thenReturn(0);
Mockito.when(schoolReportsRepository.deleteAllNotMatchingSchoolReports(List.of(schoolReportGuid), "reportTypeARC".toUpperCase())).thenReturn(0);
Mockito.when(schoolReportsRepository.archiveSchoolReports("reportType".toUpperCase(), "reportTypeARC".toUpperCase(), 1L)).thenReturn(0);
count = commonService.archiveSchoolReports(1L, List.of(), "reportType".toUpperCase());
assertThat(count).isNotNull().isEqualTo(0);
Expand All @@ -1833,8 +1835,10 @@ public void testArchiveSchoolReportsEmpty() {

@Test
public void testDeleteSchoolReports() {
UUID schoolReportGuid = UUID.randomUUID();
Mockito.when(schoolReportsRepository.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType".toUpperCase())).thenReturn(1);
Mockito.when(schoolReportsRepository.deleteSchoolReports(List.of("12345678"), "reportTypeARC".toUpperCase())).thenReturn(1);
Mockito.when(schoolReportsRepository.deleteSchoolOfRecordsNotMatchingSchoolReports(List.of(schoolReportGuid), List.of("12345678"), "reportTypeARC".toUpperCase())).thenReturn(1);
Mockito.when(schoolReportsRepository.deleteAllNotMatchingSchoolReports(List.of(schoolReportGuid), "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".toUpperCase());
assertThat(count).isNotNull().isEqualTo(1);
Expand Down
Loading