diff --git a/.gitignore b/.gitignore index 07c41426..1ca7b04e 100644 --- a/.gitignore +++ b/.gitignore @@ -52,4 +52,7 @@ target/ build/ ### VS Code ### -.vscode/ \ No newline at end of file +.vscode/ + +### Local dev ### +**/application-local.yaml \ No newline at end of file diff --git a/api/.gitignore b/api/.gitignore deleted file mode 100644 index 07c41426..00000000 --- a/api/.gitignore +++ /dev/null @@ -1,55 +0,0 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -HELP.md -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/** -!**/src/test/** - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ - -### VS Code ### -.vscode/ \ No newline at end of file diff --git a/api/pom.xml b/api/pom.xml index 97eee1f9..12af4f40 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -6,7 +6,7 @@ ca.bc.gov.educ educ-grad-graduation-report-api - 1.8.49 + 1.8.50 educ-grad-graduation-report-api Grad Graduation Report API for GRAD team diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/controller/CommonController.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/controller/CommonController.java index dd2f48c8..6e2e4ac2 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/controller/CommonController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/controller/CommonController.java @@ -65,7 +65,7 @@ public ResponseEntity getStudentReport(@PathVariable String reportTypeC public ResponseEntity> 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) @@ -80,6 +80,28 @@ public ResponseEntity getStudentReportByType( return commonService.getStudentReportByType(UUID.fromString(studentID),reportType,documentStatusCode); } + @DeleteMapping(EducGradReportApiConstants.STUDENT_REPORT_BY_STUDENTID) + @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 deleteStudentReportByType( + @RequestParam(value = "reportType") String reportType, + @PathVariable UUID studentID) { + logger.debug("deleteStudentReportByType"); + return response.GET(commonService.deleteStudentReports(studentID, 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 processStudentReports( + @RequestParam(value = "reportTypeCode") String reportTypeCode, + @RequestBody List studentIDs) { + logger.debug("processStudentReports : "); + return response.GET(commonService.processStudentReports(studentIDs, reportTypeCode)); + } + @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" }) @@ -374,5 +396,41 @@ public ResponseEntity getStudentCredentialByType(@PathVaria return commonService.getStudentCredentialByType(UUID.fromString(studentID),type); } + @PostMapping (EducGradReportApiConstants.REPORT_COUNT) + @PreAuthorize(PermissionsConstants.READ_GRADUATION_STUDENT_REPORTS) + @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 getReportsCount(@RequestParam String reportType, @RequestBody List reportContainerIds) { + if(StringUtils.containsAnyIgnoreCase(reportType, "ACHV")) { + return response.GET(commonService.countByStudentGuidsAndReportType(reportContainerIds, reportType)); + } else { + return response.GET(commonService.countBySchoolOfRecordsAndReportType(reportContainerIds, reportType)); + } + } + + @PostMapping (EducGradReportApiConstants.STUDENT_REPORTS_BY_GUIDS) + @PreAuthorize(PermissionsConstants.READ_GRADUATION_STUDENT_REPORTS) + @Operation(summary = "Get Report Students Guids by mincode and type", description = "Get Report Students Guids by mincode and type", tags = { "Business" }) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) + public ResponseEntity> getStudentIDsByIdentityAndReportType(@RequestParam String reportType, @RequestParam Integer rowCount, @RequestBody List reportContainerIds) { + return response.GET(commonService.getStudentIDsByStudentGuidsAndReportType(reportContainerIds, reportType, rowCount)); + } + + @PostMapping (EducGradReportApiConstants.REPORT_ARCHIVE) + @PreAuthorize(PermissionsConstants.ARCHIVE_SCHOOL_REPORT) + @Operation(summary = "Archive Reports", description = "Archive Reports", tags = { "Business" }) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) + public ResponseEntity archiveReports(@RequestParam long batchId, @RequestParam String reportType, @RequestBody List schoolOfRecords) { + logger.debug("Archive Reports for batch {}", batchId); + return response.GET(commonService.archiveSchoolReports(batchId, schoolOfRecords, reportType)); + } + @PostMapping (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 deleteReports(@RequestParam long batchId, @RequestParam String reportType, @RequestBody List studentGuids) { + logger.debug("Delete Reports for batch {}", batchId); + return response.GET(commonService.deleteStudentReports(studentGuids, reportType)); + } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/Address.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/Address.java new file mode 100644 index 00000000..95050202 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/Address.java @@ -0,0 +1,72 @@ +package ca.bc.gov.educ.api.grad.report.model.dto; + +import java.io.Serializable; + +public class Address implements Serializable { + + private static final long serialVersionUID = 2L; + + private String streetLine1; + private String streetLine2; + private String streetLine3; + private String city; + private String region; + private String country; + private String code; + + public String getStreetLine1() { + return streetLine1; + } + + public void setStreetLine1(String value) { + this.streetLine1 = value; + } + + public String getStreetLine2() { + return streetLine2; + } + + public void setStreetLine2(String value) { + this.streetLine2 = value; + } + + public String getStreetLine3() { + return streetLine3; + } + + public void setStreetLine3(String streetLine3) { + this.streetLine3 = streetLine3; + } + + public String getCity() { + return city; + } + + public void setCity(String value) { + this.city = value; + } + + public String getRegion() { + return region; + } + + public void setRegion(String value) { + this.region = value; + } + + public String getCountry() { + return country; + } + + public void setCountry(String value) { + this.country = value; + } + + public String getCode() { + return code; + } + + public void setCode(String value) { + this.code = value; + } +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/StudentSearchRequest.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/StudentSearchRequest.java index 2ba36785..2cebfa83 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/StudentSearchRequest.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/StudentSearchRequest.java @@ -10,6 +10,7 @@ import java.io.Serializable; import java.time.LocalDate; +import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -19,12 +20,17 @@ @AllArgsConstructor @Builder public class StudentSearchRequest implements Serializable { - private List schoolOfRecords; - private List districts; - private List schoolCategoryCodes; - private List pens; - private List programs; - private List studentIDs; + private List schoolOfRecords = new ArrayList<>(); + private List districts = new ArrayList<>(); + private List schoolCategoryCodes = new ArrayList<>(); + private List pens = new ArrayList<>(); + private List programs = new ArrayList<>(); + private List studentIDs = new ArrayList<>(); + private List statuses = new ArrayList<>(); + private List reportTypes = new ArrayList(); + + private String user; + private Address address; @JsonFormat(pattern= EducGradReportApiConstants.DEFAULT_DATE_FORMAT) LocalDate gradDateFrom; @@ -33,5 +39,15 @@ public class StudentSearchRequest implements Serializable { Boolean validateInput; String activityCode; + String localDownload; + + public boolean isEmpty() { + return schoolOfRecords.isEmpty() && + districts.isEmpty() && + schoolCategoryCodes.isEmpty() && + pens.isEmpty() && + studentIDs.isEmpty() && + programs.isEmpty(); + } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/GradStudentReportsRepository.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/GradStudentReportsRepository.java index 7a5e1402..08ebad8f 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/GradStudentReportsRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/GradStudentReportsRepository.java @@ -2,7 +2,10 @@ import ca.bc.gov.educ.api.grad.report.model.dto.SchoolStudentCredentialDistribution; import ca.bc.gov.educ.api.grad.report.model.entity.GradStudentReportsEntity; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; 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; @@ -17,8 +20,18 @@ public interface GradStudentReportsRepository extends JpaRepository existsByReportTypeCode(String reportType); - - long deleteByStudentID(UUID studentID); + + @Modifying + @Query(value="DELETE from STUDENT_REPORT where GRADUATION_STUDENT_RECORD_ID in (:studentIDs) and REPORT_TYPE_CODE = :gradReportTypeCode", nativeQuery = true) + Integer deleteByStudentIDInAndGradReportTypeCode(List studentIDs, String gradReportTypeCode); + + @Modifying + @Query(value="DELETE from STUDENT_REPORT where REPORT_TYPE_CODE = :gradReportTypeCode", nativeQuery = true) + Integer deleteByGradReportTypeCode(String gradReportTypeCode); + + @Modifying + @Query(value="DELETE from STUDENT_REPORT where GRADUATION_STUDENT_RECORD_ID = :studentID and REPORT_TYPE_CODE = :gradReportTypeCode", nativeQuery = true) + Integer deleteByStudentIDAndGradReportTypeCode(UUID studentID, String gradReportTypeCode); List findByStudentID(UUID studentID); @@ -30,4 +43,16 @@ public interface GradStudentReportsRepository extends JpaRepository findByReportUpdateDate(); + + @Query("select count(*) from GradStudentReportsEntity c where c.studentID IN (:studentGuids) and c.gradReportTypeCode=:reportType") + Integer countByStudentGuidsAndReportType(List studentGuids, String reportType); + + @Query("select c.studentID from GradStudentReportsEntity c where c.studentID IN (:studentGuids) and c.gradReportTypeCode=:reportType") + Page getReportStudentIDsByStudentIDsAndReportType(List studentGuids, String reportType, Pageable page); + + @Query("select count(*) from GradStudentReportsEntity c where c.gradReportTypeCode=:reportType") + Integer countByReportType(String reportType); + + @Query("select c.studentID from GradStudentReportsEntity c where c.gradReportTypeCode=:reportType") + Page findStudentIDByGradReportTypeCode(String reportType, Pageable page); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/SchoolReportsRepository.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/SchoolReportsRepository.java index 886cc975..ea20c0ea 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/SchoolReportsRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/SchoolReportsRepository.java @@ -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; @@ -23,4 +24,35 @@ public interface SchoolReportsRepository extends JpaRepository findBySchoolOfRecordAndReportTypeCodeOrderBySchoolOfRecord(String schoolOfRecord, String reportTypeCode); + @Query("select count(*) from SchoolReportsLightEntity c where c.schoolOfRecord IN (:schoolOfRecords) and c.reportTypeCode=:reportType") + Integer countBySchoolOfRecordsAndReportType(List schoolOfRecords, String reportType); + + @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 getReportGuidsBySchoolOfRecordsAndReportType(List schoolOfRecords, String reportType); + + @Query("select c.id from SchoolReportsLightEntity c where c.reportTypeCode=:reportType") + List getReportGuidsByReportType(String reportType); + + @Query("select c.schoolOfRecord from SchoolReportsLightEntity c where c.reportTypeCode=:reportType") + List 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 schoolOfRecords, String reportTypeFrom, String reportTypeTo, long batchId); + + @Modifying + @Query(value="update SCHOOL_REPORT set REPORT_TYPE_CODE = :reportTypeTo, update_date = SYSDATE, update_user = 'Batch ' || :batchId || ' Archive Process' where REPORT_TYPE_CODE = :reportTypeFrom", nativeQuery=true) + Integer archiveSchoolReports(String reportTypeFrom, String reportTypeTo, long batchId); + + @Modifying + @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 schoolReportGuids, List schoolOfRecords, String archivedReportType); + + @Modifying + @Query(value="delete from SCHOOL_REPORT where SCHOOL_REPORT_ID not in (:schoolReportGuids) and REPORT_TYPE_CODE = :archivedReportType", nativeQuery=true) + Integer deleteAllNotMatchingSchoolReports(List schoolReportGuids, String archivedReportType); + } diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/CommonService.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/CommonService.java index 1064aaca..abbc76ac 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/CommonService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/CommonService.java @@ -20,6 +20,7 @@ import org.springframework.core.io.InputStreamResource; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -88,7 +89,7 @@ public class CommonService extends BaseService { private static final List 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 existingEntity = gradStudentReportsRepository.findByStudentIDAndGradReportTypeCodeAndDocumentStatusCodeNot(gradStudentReports.getStudentID(), gradStudentReports.getGradReportTypeCode(), "ARCH"); if (existingEntity.isPresent()) { @@ -319,6 +320,37 @@ public int deleteAllStudentAchievement(UUID studentID) { } + @Transactional + public long processStudentReports(List studentIDs, String reportType) { + long reportsCount = 0L; + for(UUID uuid: studentIDs) { + Optional existingEntity = gradStudentReportsRepository.findByStudentIDAndGradReportTypeCode(uuid, reportType); + if(existingEntity.isPresent()) { + GradStudentReportsEntity reportsEntity = existingEntity.get(); + reportsEntity.setReportUpdateDate(new Date()); + gradStudentReportsRepository.save(reportsEntity); + reportsCount ++; + } + } + return reportsCount; + } + + @Transactional + public Integer deleteStudentReports(List studentIDs, String reportType) { + Integer result; + if(studentIDs != null && !studentIDs.isEmpty()) { + result = gradStudentReportsRepository.deleteByStudentIDInAndGradReportTypeCode(studentIDs, StringUtils.upperCase(reportType)); + } else { + result = gradStudentReportsRepository.deleteByGradReportTypeCode(StringUtils.upperCase(reportType)); + } + return result; + } + + @Transactional + public Integer deleteStudentReports(UUID studentID, String reportType) { + return gradStudentReportsRepository.deleteByStudentIDAndGradReportTypeCode(studentID, StringUtils.upperCase(reportType)); + } + public List getAllStudentReportList(UUID studentID) { List reportList = gradStudentReportsTransformer.transformToDTO(gradStudentReportsRepository.findByStudentID(studentID)); reportList.forEach(rep -> { @@ -815,6 +847,73 @@ private synchronized List getReportGradStudentData(String .block(); } + public Integer countBySchoolOfRecordsAndReportType(List schoolOfRecords, String reportType) { + Integer reportsCount = 0; + if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) { + reportsCount += schoolReportsRepository.countBySchoolOfRecordsAndReportType(schoolOfRecords, reportType); + } else { + reportsCount += schoolReportsRepository.countByReportType(reportType); + } + return reportsCount; + } + + public Integer countByStudentGuidsAndReportType(List studentGuidsString, String reportType) { + Integer reportsCount = 0; + if(studentGuidsString != null && !studentGuidsString.isEmpty()) { + List studentGuids = new ArrayList<>(); + for(String guid: studentGuidsString) { + studentGuids.add(UUID.fromString(guid)); + } + reportsCount += gradStudentReportsRepository.countByStudentGuidsAndReportType(studentGuids, reportType); + } else { + reportsCount += gradStudentReportsRepository.countByReportType(reportType); + } + return reportsCount; + } + + public List getStudentIDsByStudentGuidsAndReportType(List studentGuidsString, String reportType, Integer rowCount) { + List result = new ArrayList<>(); + rowCount = (rowCount) == 0 ? Integer.MAX_VALUE : rowCount; + Pageable paging = PageRequest.of(0, rowCount); + if(studentGuidsString != null && !studentGuidsString.isEmpty()) { + List studentGuids = new ArrayList<>(); + for(String guid: studentGuidsString) { + studentGuids.add(UUID.fromString(guid)); + } + result.addAll(gradStudentReportsRepository.getReportStudentIDsByStudentIDsAndReportType(studentGuids, reportType, paging).getContent()); + } else { + result.addAll(gradStudentReportsRepository.findStudentIDByGradReportTypeCode(reportType, paging).getContent()); + } + return result; + } + + @Transactional + public Integer archiveSchoolReports(long batchId, List 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 schoolOfRecords, String reportType) { + Integer updatedReportsCount = 0; + Integer deletedReportsCount = 0; + Integer originalReportsCount = 0; + String archivedReportType = StringUtils.appendIfMissing(reportType, "ARC", "ARC"); + if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) { + List 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.deleteSchoolOfRecordsNotMatchingSchoolReports(reportGuids, schoolOfRecords, archivedReportType); + logger.debug("{} School Reports deleted", deletedReportsCount); + } + } + return updatedReportsCount; + } + class UUIDPageTask implements Callable { private final PageRequest pageRequest; diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/util/EducGradReportApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/util/EducGradReportApiConstants.java index 468d4237..fe68b709 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/util/EducGradReportApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/util/EducGradReportApiConstants.java @@ -23,6 +23,10 @@ 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 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}"; @@ -42,6 +46,9 @@ 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 STUDENT_REPORTS_BY_GUIDS = "/studentreportsbystudentid"; public static final String SCHOOL_REPORT = "/schoolreport"; public static final String STUDENT_CERTIFICATE = "/studentcertificate"; public static final String STUDENT_CERTIFICATES = "/studentcertificates"; diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/util/PermissionsConstants.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/util/PermissionsConstants.java index 57a6ee55..b6ea0152 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/util/PermissionsConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/util/PermissionsConstants.java @@ -22,6 +22,9 @@ 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_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; diff --git a/api/src/main/resources/application.yaml b/api/src/main/resources/application.yaml index 2ee0fb4d..4cfd1a28 100644 --- a/api/src/main/resources/application.yaml +++ b/api/src/main/resources/application.yaml @@ -61,6 +61,9 @@ logging: boot: autoconfigure: logging: ${SPRING_BOOT_AUTOCONFIG_LOG_LEVEL} + com: + zaxxer: + hikari: ERROR #Local properties server: @@ -69,6 +72,7 @@ server: worker: 128 io: 16 #port: ${HTTP_PORT} + max-http-request-header-size: 20000 #API Documentation springdoc: diff --git a/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/CommonControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/CommonControllerTest.java index c98cc1ea..5c241d8f 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/CommonControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/CommonControllerTest.java @@ -52,6 +52,59 @@ public void testGetStudentCertificate() { Mockito.verify(commonService).getStudentCertificate(certificateTypeCode); } + @Test + 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.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), "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, "REPORT_TYPE")).thenReturn(1); + commonController.deleteStudentReportByType("REPORT_TYPE", studentGuid); + Mockito.verify(commonService).deleteStudentReports(studentGuid, "REPORT_TYPE"); + } + @Test public void testGetStudentCertificateByGuid() { final UUID studentGuid = UUID.randomUUID(); @@ -107,9 +160,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 @@ -484,6 +537,28 @@ public void testGetAllStudentCredentialDistributionList() { Mockito.verify(commonService).getStudentCredentialsForUserRequestDisRun(credentialType,req,false,"accessToken"); } + @Test + public void testUpdateStudentCredentialPosting() { + // UUID + final UUID studentID = UUID.randomUUID(); + final String credentialType = "E"; + + Mockito.when(commonService.updateStudentCredentialPosting(studentID, credentialType)).thenReturn(true); + commonController.updateStudentCredentialPosting(studentID.toString(), credentialType); + Mockito.verify(commonService).updateStudentCredentialPosting(studentID, credentialType); + } + + @Test + public void testGetStudentIDsByIdentityAndReportType() { + // UUID + final UUID studentID = UUID.randomUUID(); + final String reportType = "ACHV"; + + Mockito.when(commonService.getStudentIDsByStudentGuidsAndReportType(List.of(studentID.toString()), reportType, 1)).thenReturn(List.of(studentID)); + commonController.getStudentIDsByIdentityAndReportType(reportType, 1, List.of(studentID.toString())); + Mockito.verify(commonService).getStudentIDsByStudentGuidsAndReportType(List.of(studentID.toString()), reportType, 1); + } + @Test public void testGetAllStudentCredentialDistributionListWithNullDistributionDate() { // UUID diff --git a/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java index 93f923fc..d5cd7006 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/CommonServiceTest.java @@ -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); @@ -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); @@ -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); @@ -330,6 +330,48 @@ public void testGetStudentReportByType() { } + @Test + public void testDeleteStudentReports() { + // ID + final UUID studentID = UUID.randomUUID(); + final String reportTypeCode = "TEST".toUpperCase(); + + 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(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); + + } + + @Test + public void testProcessStudentReports() { + // ID + final UUID studentID = UUID.randomUUID(); + final String reportTypeCode = "TVRRUN"; + final UUID reportID = UUID.randomUUID(); + final String pen = "123456789"; + + final GradStudentReportsEntity gradStudentReport = new GradStudentReportsEntity(); + gradStudentReport.setId(reportID); + gradStudentReport.setGradReportTypeCode(reportTypeCode); + gradStudentReport.setPen(pen); + gradStudentReport.setStudentID(studentID); + gradStudentReport.setReport("TEST Report Body"); + + when(gradStudentReportsRepository.findByStudentIDAndGradReportTypeCode(studentID, reportTypeCode)).thenReturn(Optional.of(gradStudentReport)); + when(gradStudentReportsRepository.save(gradStudentReport)).thenReturn(gradStudentReport); + var result = commonService.processStudentReports(List.of(studentID), reportTypeCode); + assertThat(result).isEqualTo(1); + + } + @Test public void testGetStudentCertificateByType() { // UUID @@ -1635,6 +1677,179 @@ 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); + + Mockito.when(schoolReportsRepository.countByReportType("reportType")).thenReturn(1); + count = commonService.countBySchoolOfRecordsAndReportType(List.of(), "reportType"); + 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 testGetStudentIDsByStudentGuidsAndReportType() { + + UUID uuid = UUID.randomUUID(); + Pageable paging = PageRequest.of(0, 1); + Mockito.when(gradStudentReportsRepository.getReportStudentIDsByStudentIDsAndReportType(List.of(uuid), "reportType", paging)).thenReturn(new Page() { + @Override + public Iterator iterator() { + return getContent().listIterator(); + } + + @Override + public int getNumber() { + return 1; + } + + @Override + public int getSize() { + return 1; + } + + @Override + public int getNumberOfElements() { + return 1; + } + + @Override + public List getContent() { + return List.of(uuid); + } + + @Override + public boolean hasContent() { + return !getContent().isEmpty(); + } + + @Override + public Sort getSort() { + return null; + } + + @Override + public boolean isFirst() { + return false; + } + + @Override + public boolean isLast() { + return false; + } + + @Override + public boolean hasNext() { + return false; + } + + @Override + public boolean hasPrevious() { + return false; + } + + @Override + public Pageable nextPageable() { + return null; + } + + @Override + public Pageable previousPageable() { + return null; + } + + @Override + public int getTotalPages() { + return getContent().size(); + } + + @Override + public long getTotalElements() { + return getContent().size(); + } + + @Override + public Page map(Function converter) { + return null; + } + }); + List result = commonService.getStudentIDsByStudentGuidsAndReportType(List.of(uuid.toString()), "reportType", 1); + assertThat(result).isNotNull().isNotEmpty(); + + Mockito.when(gradStudentReportsRepository.findStudentIDByGradReportTypeCode("reportType", paging)).thenReturn(Page.empty()); + result = commonService.getStudentIDsByStudentGuidsAndReportType(List.of(), "reportType", 1); + assertThat(result).isNotNull().isEmpty(); + } + + + @Test + 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(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()); + assertThat(count).isNotNull().isEqualTo(0); + } + + @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); + } + + @Test + 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); + Integer count = commonService.archiveSchoolReports(1L, List.of("12345678"), "reportType".toUpperCase()); + assertThat(count).isNotNull().isEqualTo(1); + } + @Test @SneakyThrows public void testGetSchoolReportGradStudentData() { diff --git a/api/src/test/resources/application.yaml b/api/src/test/resources/application.yaml index a1e44920..b4af2fa7 100644 --- a/api/src/test/resources/application.yaml +++ b/api/src/test/resources/application.yaml @@ -55,7 +55,9 @@ logging: boot: autoconfigure: logging: INFO - + com: + zaxxer: + hikari: ERROR #API Documentation springdoc: api-docs: diff --git a/tools/config/update-configmap.sh b/tools/config/update-configmap.sh index bde28e8b..8f9b93fa 100644 --- a/tools/config/update-configmap.sh +++ b/tools/config/update-configmap.sh @@ -23,6 +23,7 @@ FLB_CONFIG="[SERVICE] Exclude_Path *.gz,*.zip Parser docker Mem_Buf_Limit 20MB + Buffer_Max_Size 1MB [FILTER] Name record_modifier Match *