Skip to content

Commit

Permalink
Merge pull request #275 from bcgov/develop/alex-GRAD2-2817
Browse files Browse the repository at this point in the history
Develop/alex grad2 2817
  • Loading branch information
arybakov-cgi authored Aug 19, 2024
2 parents 0d93da4 + 9b81086 commit 88c7770
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ public ResponseEntity<InputStreamResource> getStudentReportByType(
}

@DeleteMapping(EducGradReportApiConstants.STUDENT_REPORT_BY_STUDENTID)
@PreAuthorize(PermissionsConstants.READ_GRADUATION_STUDENT_REPORTS)
@Operation(summary = "Read Student Reports by Student ID and Report Type", description = "Read Student Reports by Student ID and Report Type", tags = { "Reports" })
@PreAuthorize(PermissionsConstants.DELETE_STUDENT_REPORT)
@Operation(summary = "Delete Student Reports by Student ID and Report Type", description = "Delete Student Reports by Student ID and Report Type", tags = { "Reports" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<Long> deleteStudentReportByType(
public ResponseEntity<Integer> deleteStudentReportByType(
@RequestParam(value = "reportType") String reportType,
@PathVariable UUID studentID) {
logger.debug("getStudentReportByType : ");
logger.debug("deleteStudentReportByType");
return response.GET(commonService.deleteStudentReports(studentID, reportType));
}

Expand All @@ -97,10 +97,9 @@ public ResponseEntity<Long> deleteStudentReportByType(
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<Long> processStudentReports(
@RequestParam(value = "reportTypeCode") String reportTypeCode,
@RequestParam(value = "actionType") String actionType,
@RequestBody List<UUID> studentIDs) {
logger.debug("processStudentReports : ");
return response.GET(commonService.processStudentReports(studentIDs, reportTypeCode, actionType));
return response.GET(commonService.processStudentReports(studentIDs, reportTypeCode));
}

@GetMapping(EducGradReportApiConstants.STUDENT_CERTIFICATES)
Expand Down Expand Up @@ -399,17 +398,31 @@ public ResponseEntity<InputStreamResource> getStudentCredentialByType(@PathVaria

@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" })
@Operation(summary = "Get Reports 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));
public ResponseEntity<Integer> getReportsCount(@RequestParam String reportType, @RequestBody List<String> reportContainerIds) {
if(StringUtils.containsAnyIgnoreCase(reportType, "ACHV")) {
return response.GET(commonService.countByStudentGuidsAndReportType(reportContainerIds, reportType));
} else {
return response.GET(commonService.countBySchoolOfRecordsAndReportType(reportContainerIds, 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" })
@Operation(summary = "Archive Reports", description = "Archive Reports", tags = { "Business" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<Integer> archiveSchoolReports(@RequestParam long batchId, @RequestParam String reportType, @RequestBody List<String> schoolOfRecords) {
public ResponseEntity<Integer> archiveReports(@RequestParam long batchId, @RequestParam String reportType, @RequestBody List<String> schoolOfRecords) {
logger.debug("Archive Reports for batch {}", batchId);
return response.GET(commonService.archiveSchoolReports(batchId, schoolOfRecords, reportType));
}

@DeleteMapping (EducGradReportApiConstants.REPORT_DELETE)
@PreAuthorize(PermissionsConstants.DELETE_STUDENT_REPORT)
@Operation(summary = "Delete Reports", description = "Delete Reports", tags = { "Business" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<Integer> deleteReports(@RequestParam long batchId, @RequestParam String reportType, @RequestBody List<UUID> studentGuids) {
logger.debug("Delete Reports for batch {}", batchId);
return response.GET(commonService.deleteStudentReports(studentGuids, reportType));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ public interface GradStudentReportsRepository extends JpaRepository<GradStudentR
@Query("select c from GradStudentReportsEntity c where c.gradReportTypeCode=:reportType")
List<GradStudentReportsEntity> existsByReportTypeCode(String reportType);

long deleteByStudentIDInAndGradReportTypeCode(List<UUID> studentIDs, String gradReportTypeCode);
Integer deleteByStudentIDInAndGradReportTypeCode(List<UUID> studentIDs, String gradReportTypeCode);

long deleteByStudentIDAndGradReportTypeCode(UUID studentID, String gradReportTypeCode);
Integer deleteByGradReportTypeCode(String gradReportTypeCode);

Integer deleteByStudentIDAndGradReportTypeCode(UUID studentID, String gradReportTypeCode);

List<GradStudentReportsEntity> findByStudentID(UUID studentID);

Expand All @@ -32,4 +34,10 @@ public interface GradStudentReportsRepository extends JpaRepository<GradStudentR

@Query("select new ca.bc.gov.educ.api.grad.report.model.dto.SchoolStudentCredentialDistribution(c.id,c.gradReportTypeCode,c.studentID,c.documentStatusCode) from GradStudentReportsEntity c where c.reportUpdateDate is null or c.reportUpdateDate < c.updateDate")
List<SchoolStudentCredentialDistribution> findByReportUpdateDate();

@Query("select count(*) from GradStudentReportsEntity c where c.studentID IN (:studentGuids) and c.gradReportTypeCode=:reportType")
Integer countByStudentGuidsAndReportType(List<UUID> studentGuids, String reportType);

@Query("select count(*) from GradStudentReportsEntity c where c.gradReportTypeCode=:reportType")
Integer countByReportType(String reportType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import ca.bc.gov.educ.api.grad.report.util.ThreadLocalStateUtil;
import jakarta.transaction.Transactional;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.SerializationUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -321,11 +320,7 @@ public int deleteAllStudentAchievement(UUID studentID) {
}

@Transactional
public long processStudentReports(List<UUID> studentIDs, String reportType, String actionType) {
String reportCode = StringUtils.replace(reportType, "TVRRUN", "ACHV");
if(StringUtils.containsIgnoreCase(actionType, "DELETE")) {
return deleteStudentReports(studentIDs, reportCode);
}
public long processStudentReports(List<UUID> studentIDs, String reportType) {
long reportsCount = 0L;
for(UUID uuid: studentIDs) {
Optional<GradStudentReportsEntity> existingEntity = gradStudentReportsRepository.findByStudentIDAndGradReportTypeCode(uuid, reportType);
Expand All @@ -340,13 +335,17 @@ public long processStudentReports(List<UUID> studentIDs, String reportType, Stri
}

@Transactional
public long deleteStudentReports(List<UUID> studentIDs, String reportType) {
return gradStudentReportsRepository.deleteByStudentIDInAndGradReportTypeCode(studentIDs, ObjectUtils.defaultIfNull(reportType, "ACHV").toUpperCase());
public Integer deleteStudentReports(List<UUID> studentIDs, String reportType) {
if(studentIDs != null && !studentIDs.isEmpty()) {
return gradStudentReportsRepository.deleteByStudentIDInAndGradReportTypeCode(studentIDs, StringUtils.upperCase(reportType));
} else {
return gradStudentReportsRepository.deleteByGradReportTypeCode(StringUtils.upperCase(reportType));
}
}

@Transactional
public long deleteStudentReports(UUID studentID, String reportType) {
return gradStudentReportsRepository.deleteByStudentIDAndGradReportTypeCode(studentID, ObjectUtils.defaultIfNull(reportType, "ACHV").toUpperCase());
public Integer deleteStudentReports(UUID studentID, String reportType) {
return gradStudentReportsRepository.deleteByStudentIDAndGradReportTypeCode(studentID, StringUtils.upperCase(reportType));
}

public List<GradStudentReports> getAllStudentReportList(UUID studentID) {
Expand Down Expand Up @@ -855,6 +854,20 @@ public Integer countBySchoolOfRecordsAndReportType(List<String> schoolOfRecords,
return reportsCount;
}

public Integer countByStudentGuidsAndReportType(List<String> studentGuidsString, String reportType) {
Integer reportsCount = 0;
if(studentGuidsString != null && !studentGuidsString.isEmpty()) {
List<UUID> studentGuids = new ArrayList<>();
for(String guid: studentGuidsString) {
studentGuids.add(UUID.fromString(guid));
}
reportsCount += gradStudentReportsRepository.countByStudentGuidsAndReportType(studentGuids, reportType);
} else {
reportsCount += gradStudentReportsRepository.countByReportType(reportType);
}
return reportsCount;
}

@Transactional
public Integer archiveSchoolReports(long batchId, List<String> schoolOfRecords, String reportType) {
Integer updatedReportsCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private EducGradReportApiConstants(){}

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

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 @@ -24,6 +24,7 @@ private PermissionsConstants() {
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_STUDENT_REPORT = _PREFIX + "SCOPE_DELETE_STUDENT_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 @@ -56,34 +56,53 @@ public void testGetStudentCertificate() {
public void testGetReportsCount() {
// ID
String mincode = "123456789";
String guid = UUID.randomUUID().toString();

Mockito.when(commonService.countBySchoolOfRecordsAndReportType(List.of(mincode), "reportType")).thenReturn(1);
commonController.getReportsCount("reportType", List.of(mincode));
Mockito.verify(commonService).countBySchoolOfRecordsAndReportType(List.of(mincode), "reportType");

Mockito.when(commonService.countByStudentGuidsAndReportType(List.of(guid), "ACHV")).thenReturn(1);
commonController.getReportsCount("ACHV", List.of(guid));
Mockito.verify(commonService).countByStudentGuidsAndReportType(List.of(guid), "ACHV");
}

@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));
commonController.archiveReports(1L, "reportType", List.of(mincode));
Mockito.verify(commonService).archiveSchoolReports(1L, List.of(mincode), "reportType");
}

@Test
public void testDeleteStudentReports() {
// ID
UUID guid = UUID.randomUUID();
Mockito.when(commonService.deleteStudentReports(List.of(guid), "reportType")).thenReturn(1);
commonController.deleteReports(1L, "reportType", List.of(guid));
Mockito.verify(commonService).deleteStudentReports(List.of(guid), "reportType");

Mockito.when(commonService.deleteStudentReports(List.of(), "reportType")).thenReturn(1);
commonController.deleteReports(1L, "reportType", List.of());
Mockito.verify(commonService).deleteStudentReports(List.of(), "reportType");
}

@Test
public void testProcessStudentReports() {
final UUID studentGuid = UUID.randomUUID();
Mockito.when(commonService.processStudentReports(List.of(studentGuid), "TVRRUN", "TVRDELETE")).thenReturn(1L);
commonController.processStudentReports("TVRRUN", "TVRDELETE", List.of(studentGuid));
Mockito.verify(commonService).processStudentReports(List.of(studentGuid), "TVRRUN", "TVRDELETE");
Mockito.when(commonService.processStudentReports(List.of(studentGuid), "ARCH")).thenReturn(1L);
commonController.processStudentReports("ARCH", List.of(studentGuid));
Mockito.verify(commonService).processStudentReports(List.of(studentGuid), "ARCH");
}

@Test
public void testDeleteStudentReportByType() {
final UUID studentGuid = UUID.randomUUID();
Mockito.when(commonService.deleteStudentReports(studentGuid, "TVRRUN")).thenReturn(1L);
commonController.deleteStudentReportByType("TVRRUN", studentGuid);
Mockito.verify(commonService).deleteStudentReports(studentGuid, "TVRRUN");
Mockito.when(commonService.deleteStudentReports(studentGuid, "REPORT_TYPE")).thenReturn(1);
commonController.deleteStudentReportByType("REPORT_TYPE", studentGuid);
Mockito.verify(commonService).deleteStudentReports(studentGuid, "REPORT_TYPE");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,18 @@ public void testGetStudentReportByType() {
public void testDeleteStudentReports() {
// ID
final UUID studentID = UUID.randomUUID();
final String reportTypeCode = "TEST";
final String reportTypeCode = "TEST".toUpperCase();

when(gradStudentReportsRepository.deleteByStudentIDAndGradReportTypeCode(studentID, reportTypeCode)).thenReturn(1L);
when(gradStudentReportsRepository.deleteByStudentIDAndGradReportTypeCode(studentID, reportTypeCode)).thenReturn(1);
var result = commonService.deleteStudentReports(studentID, reportTypeCode);
assertThat(result).isEqualTo(1);

when(gradStudentReportsRepository.deleteByStudentIDInAndGradReportTypeCode(List.of(studentID), reportTypeCode)).thenReturn(1L);
result = commonService.deleteStudentReports(studentID, reportTypeCode);
when(gradStudentReportsRepository.deleteByStudentIDInAndGradReportTypeCode(List.of(studentID), reportTypeCode)).thenReturn(1);
result = commonService.deleteStudentReports(List.of(studentID), reportTypeCode);
assertThat(result).isEqualTo(1);

when(gradStudentReportsRepository.deleteByGradReportTypeCode(reportTypeCode)).thenReturn(1);
result = commonService.deleteStudentReports(List.of(), reportTypeCode);
assertThat(result).isEqualTo(1);

}
Expand All @@ -351,12 +355,6 @@ public void testProcessStudentReports() {
// ID
final UUID studentID = UUID.randomUUID();
final String reportTypeCode = "TVRRUN";
String actionType = "TVRDELETE";

when(gradStudentReportsRepository.deleteByStudentIDInAndGradReportTypeCode(List.of(studentID), reportTypeCode)).thenReturn(0L);
var result = commonService.processStudentReports(List.of(studentID), reportTypeCode, actionType);
assertThat(result).isZero();

final UUID reportID = UUID.randomUUID();
final String pen = "123456789";

Expand All @@ -366,11 +364,10 @@ public void testProcessStudentReports() {
gradStudentReport.setPen(pen);
gradStudentReport.setStudentID(studentID);
gradStudentReport.setReport("TEST Report Body");
actionType = "TVRCREATE";

when(gradStudentReportsRepository.findByStudentIDAndGradReportTypeCode(studentID, reportTypeCode)).thenReturn(Optional.of(gradStudentReport));
when(gradStudentReportsRepository.save(gradStudentReport)).thenReturn(gradStudentReport);
result = commonService.processStudentReports(List.of(studentID), reportTypeCode, actionType);
var result = commonService.processStudentReports(List.of(studentID), reportTypeCode);
assertThat(result).isEqualTo(1);

}
Expand Down Expand Up @@ -1691,6 +1688,19 @@ public void testCountBySchoolOfRecordsAndReportType() {
assertThat(count).isNotNull().isEqualTo(1);
}

@Test
public void testCountByStudentGuidsAndReportType() {

UUID uuid = UUID.randomUUID();
Mockito.when(gradStudentReportsRepository.countByStudentGuidsAndReportType(List.of(uuid), "reportType")).thenReturn(1);
Integer count = commonService.countByStudentGuidsAndReportType(List.of(uuid.toString()), "reportType");
assertThat(count).isNotNull().isEqualTo(1);

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

@Test
public void testArchiveSchoolReports() {
Mockito.when(schoolReportsRepository.deleteSchoolReports(List.of("12345678"), "reportTypeARC".toUpperCase())).thenReturn(1);
Expand Down

0 comments on commit 88c7770

Please sign in to comment.