Search in sources :

Example 1 with PenRequestBatchHistoryEntity

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));
}
Also used : PenRequestBatchHistoryEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity) ArrayList(java.util.ArrayList) Associations(ca.bc.gov.educ.penreg.api.filter.Associations) PenRequestBatchHistoryAPIEndpoint(ca.bc.gov.educ.penreg.api.endpoint.v1.PenRequestBatchHistoryAPIEndpoint) InvalidParameterException(ca.bc.gov.educ.penreg.api.exception.InvalidParameterException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with PenRequestBatchHistoryEntity

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());
}
Also used : PenRequestBatchHistoryEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity) PenRequestBatchHistoryComparator(ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator) Random(java.util.Random) File(java.io.File) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with PenRequestBatchHistoryEntity

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();
}
Also used : PenRequestBatchHistoryEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity) PenRequestBatchHistoryComparator(ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator) Random(java.util.Random) PENWebBlobEntity(ca.bc.gov.educ.penreg.api.model.v1.PENWebBlobEntity) File(java.io.File) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with PenRequestBatchHistoryEntity

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();
}
Also used : PenRequestBatchHistoryEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity) PenRequestBatchHistoryComparator(ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator) Random(java.util.Random) File(java.io.File) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with PenRequestBatchHistoryEntity

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());
}
Also used : PenRequestBatchHistoryEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity) PenRequestBatchHistoryComparator(ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator) Random(java.util.Random) File(java.io.File) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PenRequestBatchHistoryEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity)20 Transactional (org.springframework.transaction.annotation.Transactional)18 BasePenRegAPITest (ca.bc.gov.educ.penreg.api.BasePenRegAPITest)17 PenRequestBatchHistoryComparator (ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator)17 File (java.io.File)17 Random (java.util.Random)17 Test (org.junit.Test)17 PenRequestBatchStudentEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity)6 School (ca.bc.gov.educ.penreg.api.struct.School)5 PENWebBlobEntity (ca.bc.gov.educ.penreg.api.model.v1.PENWebBlobEntity)3 STATUS_CHANGED (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchEventCodes.STATUS_CHANGED)2 PenRequestBatchStatusCodes (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStatusCodes)2 PenRequestBatchStudentStatusCodes (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes)2 DUPLICATE (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes.DUPLICATE)2 SchoolGroupCodes (ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes)2 K12 (ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes.K12)2 PSI (ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes.PSI)2 MessagePublisher (ca.bc.gov.educ.penreg.api.messaging.MessagePublisher)2 PenRequestBatchRepository (ca.bc.gov.educ.penreg.api.repository.PenRequestBatchRepository)2 PenRequestBatchStudentRepository (ca.bc.gov.educ.penreg.api.repository.PenRequestBatchStudentRepository)2