Skip to content

Commit

Permalink
GRAD2-2817
Browse files Browse the repository at this point in the history
TVR Delete Process - Backend Changes Endpoints
  • Loading branch information
arybakov-cgi committed Jun 27, 2024
1 parent 350feca commit 1d02aa0
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ResponseEntity<Boolean> getStudentReport(@PathVariable String reportTypeC
public ResponseEntity<ApiResponseModel<GradStudentReports>> saveStudentReport(@RequestBody GradStudentReports gradStudentReports,@RequestParam(value = "isGraduated", required = false, defaultValue = "false") boolean isGraduated) {
logger.debug("Save student Grad Report for Student ID: {}",gradStudentReports.getStudentID());
validation.requiredField(gradStudentReports.getStudentID(), "Student ID");
return response.UPDATED(commonService.saveGradReports(gradStudentReports,isGraduated));
return response.UPDATED(commonService.saveGradStudentReports(gradStudentReports,isGraduated));
}

@GetMapping(EducGradReportApiConstants.STUDENT_REPORT)
Expand All @@ -80,6 +80,29 @@ public ResponseEntity<InputStreamResource> getStudentReportByType(
return commonService.getStudentReportByType(UUID.fromString(studentID),reportType,documentStatusCode);
}

@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" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<Long> deleteStudentReportByType(
@RequestParam(value = "reportType") String reportType,
@PathVariable UUID uuid) {
logger.debug("getStudentReportByType : ");
return response.GET(commonService.deleteStudentReports(uuid, reportType));
}

@PostMapping(EducGradReportApiConstants.STUDENT_REPORTS)
@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" })
@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));
}

@GetMapping(EducGradReportApiConstants.STUDENT_CERTIFICATES)
@PreAuthorize(PermissionsConstants.READ_GRADUATION_STUDENT_CERTIFICATES)
@Operation(summary = "Read Student Certificates by Student ID", description = "Read Student Certificates by Student ID", tags = { "Reports" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public interface GradStudentReportsRepository extends JpaRepository<GradStudentR
@Query("select c from GradStudentReportsEntity c where c.gradReportTypeCode=:reportType")
List<GradStudentReportsEntity> existsByReportTypeCode(String reportType);

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

long deleteByStudentIDAndGradReportTypeCode(UUID studentID, String gradReportTypeCode);

List<GradStudentReportsEntity> findByStudentID(UUID studentID);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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 @@ -88,7 +89,7 @@ public class CommonService extends BaseService {
private static final List<String> SCCP_CERT_TYPES = Arrays.asList("SC", "SCF", "SCI");

@Transactional
public GradStudentReports saveGradReports(GradStudentReports gradStudentReports, boolean isGraduated) {
public GradStudentReports saveGradStudentReports(GradStudentReports gradStudentReports, boolean isGraduated) {
GradStudentReportsEntity toBeSaved = gradStudentReportsTransformer.transformToEntity(gradStudentReports);
Optional<GradStudentReportsEntity> existingEntity = gradStudentReportsRepository.findByStudentIDAndGradReportTypeCodeAndDocumentStatusCodeNot(gradStudentReports.getStudentID(), gradStudentReports.getGradReportTypeCode(), "ARCH");
if (existingEntity.isPresent()) {
Expand Down Expand Up @@ -319,6 +320,35 @@ 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);
}
long reportsCount = 0L;
for(UUID uuid: studentIDs) {
Optional<GradStudentReportsEntity> existingEntity = gradStudentReportsRepository.findByStudentIDAndGradReportTypeCode(uuid, reportType);
if(existingEntity.isPresent()) {
GradStudentReportsEntity reportsEntity = existingEntity.get();
reportsEntity.setReportUpdateDate(new Date());
gradStudentReportsRepository.save(reportsEntity);
reportsCount ++;
}
}
return reportsCount;
}

@Transactional
public long deleteStudentReports(List<UUID> studentIDs, String reportType) {
return gradStudentReportsRepository.deleteByStudentIDInAndGradReportTypeCode(studentIDs, ObjectUtils.defaultIfNull(reportType, "ACHV").toUpperCase());
}

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

public List<GradStudentReports> getAllStudentReportList(UUID studentID) {
List<GradStudentReports> reportList = gradStudentReportsTransformer.transformToDTO(gradStudentReportsRepository.findByStudentID(studentID));
reportList.forEach(rep -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ private EducGradReportApiConstants(){}
public static final String UPDATE_SCHOOL_REPORTS = "/updateschoolreport";

public static final String STUDENT_REPORT = "/studentreport";
public static final String STUDENT_REPORT_BY_STUDENTID = "/studentreport/{studentID}";
public static final String STUDENT_REPORTS = "/studentreports";
public static final String SCHOOL_REPORT = "/schoolreport";
public static final String STUDENT_CERTIFICATE = "/studentcertificate";
public static final String STUDENT_CERTIFICATES = "/studentcertificates";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ public void testSaveStudentReport() {
gradStudentReport.setReport("TEST Report Body");
gradStudentReport.setDocumentStatusCode("IP");

Mockito.when(commonService.saveGradReports(gradStudentReport,isGraduated)).thenReturn(gradStudentReport);
Mockito.when(commonService.saveGradStudentReports(gradStudentReport,isGraduated)).thenReturn(gradStudentReport);
commonController.saveStudentReport(gradStudentReport,isGraduated);
Mockito.verify(commonService).saveGradReports(gradStudentReport,isGraduated);
Mockito.verify(commonService).saveGradStudentReports(gradStudentReport,isGraduated);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void testSaveGradReports_thenReturnCreateSuccess() {
when(this.gradStudentReportsRepository.findByStudentIDAndGradReportTypeCodeAndDocumentStatusCodeNot(studentID, reportTypeCode,documentStatusCode)).thenReturn(optionalEmpty);
when(this.gradStudentReportsRepository.save(any(GradStudentReportsEntity.class))).thenReturn(gradStudentReportEntity);

var result = commonService.saveGradReports(gradStudentReport,isGraduated);
var result = commonService.saveGradStudentReports(gradStudentReport,isGraduated);

assertThat(result).isNotNull();
assertThat(result.getStudentID()).isEqualTo(studentID);
Expand Down Expand Up @@ -258,7 +258,7 @@ public void testSaveGradReportsWithExistingOne_thenReturnUpdateSuccess() {
when(this.gradStudentReportsRepository.findByStudentIDAndGradReportTypeCodeAndDocumentStatusCodeNot(studentID, reportTypeCode,"ARCH")).thenReturn(optional);
when(this.gradStudentReportsRepository.save(any(GradStudentReportsEntity.class))).thenReturn(gradStudentReportEntity);

var result = commonService.saveGradReports(gradStudentReport,isGraduated);
var result = commonService.saveGradStudentReports(gradStudentReport,isGraduated);

assertThat(result).isNotNull();
assertThat(result.getStudentID()).isEqualTo(studentID);
Expand Down Expand Up @@ -294,7 +294,7 @@ public void testSaveGradReportsWithExistingOne_whenReportClobIsChanged_thenRetur
when(this.gradStudentReportsRepository.findByStudentIDAndGradReportTypeCodeAndDocumentStatusCodeNot(studentID, reportTypeCode,"ARCH")).thenReturn(optional);
when(this.gradStudentReportsRepository.save(any(GradStudentReportsEntity.class))).thenReturn(gradStudentReportEntity);

var result = commonService.saveGradReports(gradStudentReport,isGraduated);
var result = commonService.saveGradStudentReports(gradStudentReport,isGraduated);

assertThat(result).isNotNull();
assertThat(result.getStudentID()).isEqualTo(studentID);
Expand Down

0 comments on commit 1d02aa0

Please sign in to comment.