Skip to content

Commit

Permalink
GRAD2-2817 (#281)
Browse files Browse the repository at this point in the history
* GRAD2-2817
Fix archive all when other schools being deleted

* GRAD2-2817
Fix archive all when other schools being deleted

* GRAD2-2817
Fix archive all when other schools being deleted
  • Loading branch information
arybakov-cgi authored Sep 10, 2024
1 parent 0a25c31 commit 9c802ed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public interface SchoolReportsRepository extends JpaRepository<SchoolReportsEnti
@Query("select c.id from SchoolReportsLightEntity c where c.reportTypeCode=:reportType")
List<UUID> getReportGuidsByReportType(String reportType);

@Query("select c.schoolOfRecord from SchoolReportsLightEntity c where c.reportTypeCode=:reportType")
List<String> getReportSchoolOfRecordsByReportType(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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,15 @@ public List<UUID> getStudentIDsByStudentGuidsAndReportType(List<String> studentG

@Transactional
public Integer archiveSchoolReports(long batchId, List<String> schoolOfRecords, String reportType) {
if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) {
return archiveSchoolReportsBySchoolOfRecordAndReportType(batchId, schoolOfRecords, reportType);
} else {
schoolOfRecords = schoolReportsRepository.getReportSchoolOfRecordsByReportType(reportType);
return archiveSchoolReportsBySchoolOfRecordAndReportType(batchId, schoolOfRecords, reportType);
}
}

private Integer archiveSchoolReportsBySchoolOfRecordAndReportType(long batchId, List<String> schoolOfRecords, String reportType) {
Integer updatedReportsCount = 0;
Integer deletedReportsCount = 0;
Integer originalReportsCount = 0;
Expand All @@ -901,14 +910,6 @@ public Integer archiveSchoolReports(long batchId, List<String> schoolOfRecords,
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.deleteAllNotMatchingSchoolReports(reportGuids, archivedReportType);
logger.debug("{} School Reports deleted", deletedReportsCount);
}
}
return updatedReportsCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1800,25 +1800,29 @@ public Page map(Function converter) {
public void testArchiveSchoolReports() {
UUID schoolReportGuid = UUID.randomUUID();
Mockito.when(schoolReportsRepository.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType".toUpperCase())).thenReturn(1);
Mockito.when(schoolReportsRepository.getReportSchoolOfRecordsByReportType("reportType".toUpperCase())).thenReturn(List.of("12345678"));
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.getReportSchoolOfRecordsByReportType("reportType".toUpperCase())).thenReturn(List.of("12345678"));
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.getReportSchoolOfRecordsByReportType("reportType".toUpperCase())).thenReturn(List.of("12345678"));
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);
assertThat(count).isNotNull().isEqualTo(0);

Mockito.when(schoolReportsRepository.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType".toUpperCase())).thenReturn(0);
Mockito.when(schoolReportsRepository.getReportSchoolOfRecordsByReportType("reportType".toUpperCase())).thenReturn(List.of("12345678"));
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());
Expand All @@ -1828,6 +1832,7 @@ public void testArchiveSchoolReports() {
@Test
public void testArchiveSchoolReportsEmpty() {
Mockito.when(schoolReportsRepository.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType".toUpperCase())).thenReturn(0);
Mockito.when(schoolReportsRepository.getReportSchoolOfRecordsByReportType("reportType".toUpperCase())).thenReturn(List.of("12345678"));
Mockito.when(schoolReportsRepository.archiveSchoolReports(new ArrayList<>(), "reportType".toUpperCase(), "reportTypeARC".toUpperCase(), 1L)).thenReturn(0);
Integer count = commonService.archiveSchoolReports(1L, new ArrayList<>(), "reportType".toUpperCase());
assertThat(count).isNotNull().isEqualTo(0);
Expand All @@ -1837,6 +1842,7 @@ public void testArchiveSchoolReportsEmpty() {
public void testDeleteSchoolReports() {
UUID schoolReportGuid = UUID.randomUUID();
Mockito.when(schoolReportsRepository.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType".toUpperCase())).thenReturn(1);
Mockito.when(schoolReportsRepository.getReportSchoolOfRecordsByReportType("reportType".toUpperCase())).thenReturn(List.of("12345678"));
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);
Expand Down

0 comments on commit 9c802ed

Please sign in to comment.