use of ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchHistoryAPIController method findAll.
/**
* Find all completable future.
*
* @param pageNumber the page number
* @param pageSize the page size
* @param sortCriteriaJson the sort criteria json
* @param searchList the search list
* @return the completable future
*/
@Override
public CompletableFuture<Page<PenRequestBatchHistorySearch>> findAll(final Integer pageNumber, final Integer pageSize, final String sortCriteriaJson, final String searchList) {
final ObjectMapper objectMapper = new ObjectMapper();
final List<Sort.Order> sorts = new ArrayList<>();
Specification<PenRequestBatchHistoryEntity> penRegBatchSpecs = null;
final Associations associationNames;
try {
associationNames = this.getSortCriteria(sortCriteriaJson, objectMapper, sorts);
if (StringUtils.isNotBlank(searchList)) {
final List<Search> searches = objectMapper.readValue(searchList, new TypeReference<>() {
});
this.getAssociationNamesFromSearchCriterias(associationNames, searches);
int i = 0;
for (final var search : searches) {
penRegBatchSpecs = this.getSpecifications(penRegBatchSpecs, i, search, associationNames, this.getPenRegBatchFilterSpecs());
i++;
}
}
} catch (final JsonProcessingException e) {
throw new InvalidParameterException(e.getMessage());
}
return this.getService().findAll(penRegBatchSpecs, pageNumber, pageSize, sorts).thenApplyAsync(page -> page.map(mapper::toSearchStructure));
}
use of ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRegBatchProcessorTest method testProcessPenRegBatchFileFromTSW_BatchToBeHeldBackForSFAS_ShouldCreateRecordLOADHELDSIZEInDB.
@Test
@Transactional
public void testProcessPenRegBatchFileFromTSW_BatchToBeHeldBackForSFAS_ShouldCreateRecordLOADHELDSIZEInDB() throws IOException {
when(this.restUtils.getSchoolByMincode(anyString())).thenReturn(Optional.of(this.createMockSchool()));
final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("sample_5_PSI_OK.txt")).getFile());
final byte[] bFile = Files.readAllBytes(file.toPath());
final var randomNum = (new Random().nextLong() * (MAX - MIN + 1) + MIN);
var tsw = PENWebBlobEntity.builder().penWebBlobId(1L).mincode("10200030").sourceApplication("MYED").tswAccount((randomNum + "").substring(0, 8)).fileName("sample_5_PSI_OK").fileType("PEN").fileContents(bFile).insertDateTime(LocalDateTime.now()).submissionNumber(("T" + randomNum).substring(0, 8)).build();
tsw = this.penRequestBatchTestUtils.savePenWebBlob(tsw);
this.penRegBatchProcessor.processPenRegBatchFileFromPenWebBlob(tsw);
final var result = this.repository.findAll();
assertThat(result.size()).isEqualTo(1);
final var entity = result.get(0);
assertThat(entity.getPenRequestBatchID()).isNotNull();
assertThat(entity.getSchoolGroupCode()).isEqualTo(PSI.getCode());
assertThat(entity.getPenRequestBatchStatusCode()).isEqualTo(HOLD_FOR_REVIEW.getCode());
assertThat(entity.getPenRequestBatchHistoryEntities().size()).isEqualTo(1);
final Optional<PenRequestBatchHistoryEntity> penRequestBatchHistoryEntityOptional = entity.getPenRequestBatchHistoryEntities().stream().min(new PenRequestBatchHistoryComparator());
assertThat(penRequestBatchHistoryEntityOptional).isPresent();
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchEventCode()).isEqualTo(STATUS_CHANGED.getCode());
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchStatusCode()).isEqualTo(HOLD_FOR_REVIEW.getCode());
}
use of ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRegBatchProcessorTest method testProcessPenRegBatchFileFromTSW_Given8RowInvalidFileWithHeaderAndRecordLengthShort_ShouldCreateLOADFAILRecordsInDB.
/**
* Test process pen reg batch file from tsw given 30 row valid file should create records in db.
*
* @throws IOException the io exception
*/
@Test
@Transactional
public void testProcessPenRegBatchFileFromTSW_Given8RowInvalidFileWithHeaderAndRecordLengthShort_ShouldCreateLOADFAILRecordsInDB() throws IOException {
final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("sample_8_records_Header_Short_Length.txt")).getFile());
final byte[] bFile = Files.readAllBytes(file.toPath());
final var randomNum = (new Random().nextLong() * (MAX - MIN + 1) + MIN);
var tsw = PENWebBlobEntity.builder().penWebBlobId(1L).mincode("66510518").sourceApplication("MYED").tswAccount((randomNum + "").substring(0, 8)).fileName("sample_8_records_Header_Short_Length").fileType("PEN").fileContents(bFile).insertDateTime(LocalDateTime.now()).submissionNumber(("T" + randomNum).substring(0, 8)).build();
System.out.println(JsonUtil.getJsonStringFromObject(tsw));
System.out.println(JsonUtil.getJsonObjectFromString(PENWebBlobEntity.class, JsonUtil.getJsonStringFromObject(tsw)));
tsw = this.penRequestBatchTestUtils.savePenWebBlob(tsw);
this.penRegBatchProcessor.processPenRegBatchFileFromPenWebBlob(tsw);
final var result = this.repository.findAll();
assertThat(result.size()).isEqualTo(1);
final var entity = result.get(0);
assertThat(entity.getPenRequestBatchID()).isNotNull();
assertThat(entity.getPenRequestBatchStatusCode()).isEqualTo(LOAD_FAIL.getCode());
assertThat(entity.getPenRequestBatchStatusReason()).containsIgnoringCase("Detail record 1 is missing characters");
assertThat(entity.getPenRequestBatchHistoryEntities().size()).isEqualTo(1);
final Optional<PenRequestBatchHistoryEntity> penRequestBatchHistoryEntityOptional = entity.getPenRequestBatchHistoryEntities().stream().min(new PenRequestBatchHistoryComparator());
assertThat(penRequestBatchHistoryEntityOptional).isPresent();
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchEventCode()).isEqualTo(STATUS_CHANGED.getCode());
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchStatusCode()).isEqualTo(LOAD_FAIL.getCode());
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchStatusReason()).containsIgnoringCase("Detail record 1 is missing characters");
final var students = this.studentRepository.findAllByPenRequestBatchEntity(result.get(0));
assertThat(students.size()).isZero();
}
use of ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRegBatchProcessorTest method testProcessPenRegBatchFileFromTSW_GivenRecordCountDoesNotMatchActualCount_ShouldCreateRecordLOADFAILInDB.
/**
* Test process pen reg batch file from tsw given record count does not match actual count should create record loadfail in db.
*
* @throws IOException the io exception
*/
@Test
@Transactional
public void testProcessPenRegBatchFileFromTSW_GivenRecordCountDoesNotMatchActualCount_ShouldCreateRecordLOADFAILInDB() throws IOException {
when(this.restUtils.getSchoolByMincode(anyString())).thenReturn(Optional.of(this.createMockSchool()));
final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("sample_10_records_student_count_mismatch.txt")).getFile());
final byte[] bFile = Files.readAllBytes(file.toPath());
final var randomNum = (new Random().nextLong() * (MAX - MIN + 1) + MIN);
var tsw = PENWebBlobEntity.builder().penWebBlobId(1L).mincode("66510518").sourceApplication("MYED").tswAccount((randomNum + "").substring(0, 8)).fileName("sample_10_records_student_count_mismatch").fileType("PEN").fileContents(bFile).insertDateTime(LocalDateTime.now()).submissionNumber(("T" + randomNum).substring(0, 8)).build();
tsw = this.penRequestBatchTestUtils.savePenWebBlob(tsw);
this.penRegBatchProcessor.processPenRegBatchFileFromPenWebBlob(tsw);
final var result = this.repository.findAll();
assertThat(result.size()).isEqualTo(1);
final var entity = result.get(0);
assertThat(entity.getPenRequestBatchID()).isNotNull();
assertThat(entity.getPenRequestBatchStatusCode()).isEqualTo(LOAD_FAIL.getCode());
assertThat(entity.getPenRequestBatchStatusReason()).containsIgnoringCase("Invalid count in trailer record. Stated was 30, Actual was 10");
assertThat(entity.getPenRequestBatchHistoryEntities().size()).isEqualTo(1);
final Optional<PenRequestBatchHistoryEntity> penRequestBatchHistoryEntityOptional = entity.getPenRequestBatchHistoryEntities().stream().min(new PenRequestBatchHistoryComparator());
assertThat(penRequestBatchHistoryEntityOptional).isPresent();
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchEventCode()).isEqualTo(STATUS_CHANGED.getCode());
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchStatusCode()).isEqualTo(LOAD_FAIL.getCode());
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchStatusReason()).containsIgnoringCase("Invalid count in trailer record. Stated was 30, Actual was 10");
final var students = this.studentRepository.findAllByPenRequestBatchEntity(result.get(0));
assertThat(students.size()).isZero();
}
use of ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRegBatchProcessorTest method testProcessPenRegBatchFileFromTSW_BatchToBeHeldBackForSize_ShouldCreateRecordLOADHELDSIZEInDB.
/**
* Test process pen reg batch file from tsw given record count does not match actual count should create record loadfail in db.
*
* @throws IOException the io exception
*/
@Test
@Transactional
public void testProcessPenRegBatchFileFromTSW_BatchToBeHeldBackForSize_ShouldCreateRecordLOADHELDSIZEInDB() throws IOException {
when(this.restUtils.getSchoolByMincode(anyString())).thenReturn(Optional.of(this.createMockSchool()));
final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("sample_5000_records_OK.txt")).getFile());
final byte[] bFile = Files.readAllBytes(file.toPath());
final var randomNum = (new Random().nextLong() * (MAX - MIN + 1) + MIN);
var tsw = PENWebBlobEntity.builder().penWebBlobId(1L).mincode("10210518").sourceApplication("MYED").tswAccount((randomNum + "").substring(0, 8)).fileName("sample_5000_records_OK").fileType("PEN").fileContents(bFile).insertDateTime(LocalDateTime.now()).submissionNumber(("T" + randomNum).substring(0, 8)).build();
tsw = this.penRequestBatchTestUtils.savePenWebBlob(tsw);
this.penRegBatchProcessor.processPenRegBatchFileFromPenWebBlob(tsw);
final var result = this.repository.findAll();
assertThat(result.size()).isEqualTo(1);
final var entity = result.get(0);
assertThat(entity.getPenRequestBatchID()).isNotNull();
assertThat(entity.getSchoolGroupCode()).isEqualTo(PSI.getCode());
assertThat(entity.getPenRequestBatchStatusCode()).isEqualTo(HOLD_FOR_REVIEW.getCode());
assertThat(entity.getPenRequestBatchHistoryEntities().size()).isEqualTo(1);
final Optional<PenRequestBatchHistoryEntity> penRequestBatchHistoryEntityOptional = entity.getPenRequestBatchHistoryEntities().stream().min(new PenRequestBatchHistoryComparator());
assertThat(penRequestBatchHistoryEntityOptional).isPresent();
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchEventCode()).isEqualTo(STATUS_CHANGED.getCode());
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchStatusCode()).isEqualTo(HOLD_FOR_REVIEW.getCode());
}
Aggregations