Skip to content

Commit

Permalink
Merge pull request #278 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 28, 2024
2 parents 57be853 + d96374f commit 8287313
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@ public ResponseEntity<Integer> getReportsCount(@RequestParam String reportType,
@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<List<UUID>> getStudentIDsByIdentityAndReportType(@RequestParam String reportType, @RequestBody List<String> reportContainerIds) {
return response.GET(commonService.getStudentIDsByStudentGuidsAndReportType(reportContainerIds, reportType));
public ResponseEntity<List<UUID>> getStudentIDsByIdentityAndReportType(@RequestParam String reportType, @RequestParam Integer rowCount, @RequestBody List<String> reportContainerIds) {
return response.GET(commonService.getStudentIDsByStudentGuidsAndReportType(reportContainerIds, reportType, rowCount));
}

@PostMapping (EducGradReportApiConstants.REPORT_ARCHIVE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -17,11 +20,17 @@ public interface GradStudentReportsRepository extends JpaRepository<GradStudentR

@Query("select c from GradStudentReportsEntity c where c.gradReportTypeCode=:reportType")
List<GradStudentReportsEntity> existsByReportTypeCode(String reportType);


@Modifying
@Query(value="DELETE from STUDENT_REPORT where GRADUATION_STUDENT_RECORD_ID in (:studentIDs) and REPORT_TYPE_CODE = :gradReportTypeCode", nativeQuery = true)
Integer deleteByStudentIDInAndGradReportTypeCode(List<UUID> 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<GradStudentReportsEntity> findByStudentID(UUID studentID);
Expand All @@ -39,11 +48,11 @@ public interface GradStudentReportsRepository extends JpaRepository<GradStudentR
Integer countByStudentGuidsAndReportType(List<UUID> studentGuids, String reportType);

@Query("select c.studentID from GradStudentReportsEntity c where c.studentID IN (:studentGuids) and c.gradReportTypeCode=:reportType")
List<UUID> getReportStudentIDsByStudentIDsAndReportType(List<UUID> studentGuids, String reportType);
Page<UUID> getReportStudentIDsByStudentIDsAndReportType(List<UUID> 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")
List<UUID> getReportStudentIDsByReportType(String reportType);
Page<UUID> findStudentIDByGradReportTypeCode(String reportType, Pageable page);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -870,16 +871,18 @@ public Integer countByStudentGuidsAndReportType(List<String> studentGuidsString,
return reportsCount;
}

public List<UUID> getStudentIDsByStudentGuidsAndReportType(List<String> studentGuidsString, String reportType) {
List<UUID> result;
public List<UUID> getStudentIDsByStudentGuidsAndReportType(List<String> studentGuidsString, String reportType, Integer rowCount) {
List<UUID> result = new ArrayList<>();
rowCount = (rowCount) == 0 ? Integer.MAX_VALUE : rowCount;
Pageable paging = PageRequest.of(0, rowCount);
if(studentGuidsString != null && !studentGuidsString.isEmpty()) {
List<UUID> studentGuids = new ArrayList<>();
for(String guid: studentGuidsString) {
studentGuids.add(UUID.fromString(guid));
}
result = gradStudentReportsRepository.getReportStudentIDsByStudentIDsAndReportType(studentGuids, reportType);
result.addAll(gradStudentReportsRepository.getReportStudentIDsByStudentIDsAndReportType(studentGuids, reportType, paging).getContent());
} else {
result = gradStudentReportsRepository.getReportStudentIDsByReportType(reportType);
result.addAll(gradStudentReportsRepository.findStudentIDByGradReportTypeCode(reportType, paging).getContent());
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,9 @@ public void testGetStudentIDsByIdentityAndReportType() {
final UUID studentID = UUID.randomUUID();
final String reportType = "ACHV";

Mockito.when(commonService.getStudentIDsByStudentGuidsAndReportType(List.of(studentID.toString()), reportType)).thenReturn(List.of(studentID));
commonController.getStudentIDsByIdentityAndReportType(reportType, List.of(studentID.toString()));
Mockito.verify(commonService).getStudentIDsByStudentGuidsAndReportType(List.of(studentID.toString()), reportType);
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1705,13 +1705,94 @@ public void testCountByStudentGuidsAndReportType() {
public void testGetStudentIDsByStudentGuidsAndReportType() {

UUID uuid = UUID.randomUUID();
Mockito.when(gradStudentReportsRepository.getReportStudentIDsByStudentIDsAndReportType(List.of(uuid), "reportType")).thenReturn(List.of(uuid));
List<UUID> result = commonService.getStudentIDsByStudentGuidsAndReportType(List.of(uuid.toString()), "reportType");
assertThat(result).isNotNull().isNotEmpty();
Pageable paging = PageRequest.of(0, 1);
Mockito.when(gradStudentReportsRepository.getReportStudentIDsByStudentIDsAndReportType(List.of(uuid), "reportType", paging)).thenReturn(new Page() {
@Override
public Iterator<UUID> 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<UUID> getContent() {
return List.of(uuid);
}

@Override
public boolean hasContent() {
return !getContent().isEmpty();
}

@Override
public Sort getSort() {
return null;
}

@Override
public boolean isFirst() {
return false;
}

Mockito.when(gradStudentReportsRepository.getReportStudentIDsByReportType("reportType")).thenReturn(List.of(uuid));
result = commonService.getStudentIDsByStudentGuidsAndReportType(List.of(), "reportType");
@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<UUID> 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();
}


Expand Down

0 comments on commit 8287313

Please sign in to comment.