Skip to content

Commit

Permalink
Merge pull request #272 from bcgov/develop/alex-GRAD2-2322
Browse files Browse the repository at this point in the history
Develop/alex grad2 2322
  • Loading branch information
arybakov-cgi committed Jul 23, 2024
2 parents 4cf8297 + 7b3ef2d commit a56369d
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,5 +397,19 @@ public ResponseEntity<InputStreamResource> getStudentCredentialByType(@PathVaria
return commonService.getStudentCredentialByType(UUID.fromString(studentID),type);
}

@PostMapping (EducGradReportApiConstants.REPORT_COUNT)
@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<Integer> getReportsCount(@RequestParam String reportType, @RequestBody List<String> schoolOfRecords) {
return response.GET(commonService.countBySchoolOfRecordsAndReportType(schoolOfRecords, reportType));
}

@PostMapping (EducGradReportApiConstants.REPORT_ARCHIVE)
@PreAuthorize(PermissionsConstants.ARCHIVE_SCHOOL_REPORT)
@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> archiveSchoolReports(@RequestParam long batchId, @RequestParam String reportType, @RequestBody List<String> schoolOfRecords) {
return response.GET(commonService.archiveSchoolReports(batchId, schoolOfRecords, reportType));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.bc.gov.educ.api.grad.report.model.entity.SchoolReportsEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

Expand All @@ -23,4 +24,18 @@ 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")
Integer countBySchoolOfRecordsAndReportType(List<String> schoolOfRecords, String reportType);

@Query("select count(*) from SchoolReportsLightEntity c where c.reportTypeCode=: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 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);

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

public Integer countBySchoolOfRecordsAndReportType(List<String> schoolOfRecords, String reportType) {
Integer reportsCount = 0;
if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) {
reportsCount += schoolReportsRepository.countBySchoolOfRecordsAndReportType(schoolOfRecords, reportType);
}
return reportsCount;
}

@Transactional
public Integer archiveSchoolReports(long batchId, List<String> schoolOfRecords, String reportType) {
Integer updatedReportsCount = 0;
Integer deletedReportsCount = 0;
Integer originalReportsCount = 0;
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);
}
}
return updatedReportsCount;
}

class UUIDPageTask implements Callable<Object> {

private final PageRequest pageRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ private EducGradReportApiConstants(){}
public static final String API_VERSION = "v1";
public static final String GRAD_REPORT_API_ROOT_MAPPING = "/api/" + API_VERSION + "/graduationreports";

public static final String REPORT_COUNT = "/count";
public static final String REPORT_ARCHIVE = "/archive";

public static final String GET_ALL_CERTIFICATE_TYPE_MAPPING = "/certificatetype";
public static final String GET_ALL_CERTIFICATE_TYPE_BY_CODE_MAPPING = "/certificatetype/{certTypeCode}";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ private PermissionsConstants() {
public static final String UPDATE_CERTIFICATE_TYPE = _PREFIX + "SCOPE_UPDATE_GRAD_CERTIFICATE_CODE_DATA" + _SUFFIX;
public static final String CREATE_CERTIFICATE_TYPE = _PREFIX + "SCOPE_CREATE_GRAD_CERTIFICATE_CODE_DATA" + _SUFFIX;
public static final String READ_GRAD_REPORT = _PREFIX + "SCOPE_READ_GRAD_REPORT_CODE_DATA" + _SUFFIX;

public static final String ARCHIVE_SCHOOL_REPORT = _PREFIX + "SCOPE_ARCHIVE_SCHOOL_REPORT" + _SUFFIX;
public static final String DELETE_REPORT_TYPE = _PREFIX + "SCOPE_DELETE_GRAD_REPORT_CODE_DATA" + _SUFFIX;
public static final String UPDATE_REPORT_TYPE = _PREFIX + "SCOPE_UPDATE_GRAD_REPORT_CODE_DATA" + _SUFFIX;
public static final String CREATE_REPORT_TYPE = _PREFIX + "SCOPE_CREATE_GRAD_REPORT_CODE_DATA" + _SUFFIX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ public void testGetStudentCertificate() {
Mockito.verify(commonService).getStudentCertificate(certificateTypeCode);
}

@Test
public void testGetReportsCount() {
// ID
String mincode = "123456789";
Mockito.when(commonService.countBySchoolOfRecordsAndReportType(List.of(mincode), "reportType")).thenReturn(1);
commonController.getReportsCount("reportType", List.of(mincode));
Mockito.verify(commonService).countBySchoolOfRecordsAndReportType(List.of(mincode), "reportType");
}

@Test
public void testArchiveSchoolReports() {
// ID
String mincode = "123456789";
Mockito.when(commonService.archiveSchoolReports(1L, List.of(mincode), "reportType")).thenReturn(1);
commonController.archiveSchoolReports(1L, "reportType", List.of(mincode));
Mockito.verify(commonService).archiveSchoolReports(1L, List.of(mincode), "reportType");
}

@Test
public void testProcessStudentReports() {
final UUID studentGuid = UUID.randomUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1680,6 +1680,41 @@ public void testCheckStudentCertificateExistsForSCCP_with_SCCP_Certificate() {
assertThat(result).isTrue();
}

@Test
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);
}

@Test
public void testArchiveSchoolReports() {
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".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".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);
}

@Test
@SneakyThrows
public void testGetSchoolReportGradStudentData() {
Expand Down

0 comments on commit a56369d

Please sign in to comment.