Search in sources :

Example 1 with PenRequestBatchMultiplePen

use of ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchMultiplePen in project EDUC-PEN-REG-BATCH-API by bcgov.

the class EventTaskSchedulerAsyncService method checkAndUpdateStatusToActiveOrArchived.

/**
 * Check and update status to active.
 *
 * @param penReqBatchEntities   the pen req batch entities
 * @param penRequestBatchEntity the pen request batch entity
 * @param redisKey              the redis key
 */
private void checkAndUpdateStatusToActiveOrArchived(final List<PenRequestBatchEntity> penReqBatchEntities, final PenRequestBatchEntity penRequestBatchEntity, final String redisKey) {
    long loadedCount = this.penRequestBatchStudentRepository.countAllByPenRequestBatchEntityAndPenRequestBatchStudentStatusCodeIn(penRequestBatchEntity, List.of(LOADED.getCode()));
    if (loadedCount > 0) {
        // all the records are not processed yet.
        return;
    }
    val studentSagaRecordsCount = this.getSagaRepository().countAllByPenRequestBatchIDAndSagaName(penRequestBatchEntity.getPenRequestBatchID(), PEN_REQUEST_BATCH_STUDENT_PROCESSING_SAGA.toString());
    long dupCount = this.penRequestBatchStudentRepository.countAllByPenRequestBatchEntityAndPenRequestBatchStudentStatusCodeIn(penRequestBatchEntity, List.of(DUPLICATE.getCode()));
    long rptCount = this.penRequestBatchStudentRepository.countAllByPenRequestBatchEntityAndPenRequestBatchStudentStatusCodeIn(penRequestBatchEntity, List.of(REPEAT.getCode()));
    long newPenAndMatchCount = this.penRequestBatchStudentRepository.countAllByPenRequestBatchEntityAndPenRequestBatchStudentStatusCodeIn(penRequestBatchEntity, List.of(PenRequestBatchStudentStatusCodes.SYS_NEW_PEN.getCode(), PenRequestBatchStudentStatusCodes.SYS_MATCHED.getCode()));
    final List<PenRequestBatchMultiplePen> recordWithMultiples = this.penRequestBatchStudentRepository.findBatchFilesWithMultipleAssignedPens(List.of(penRequestBatchEntity.getPenRequestBatchID()));
    boolean isSamePenAssignedToMultiplePRForSameBatch = !recordWithMultiples.isEmpty();
    if (penRequestBatchEntity.getStudentCount() == (rptCount + dupCount)) {
        // all records are either repeat or
        this.handleAllDuplicateOrRepeat(penReqBatchEntities, penRequestBatchEntity, redisKey);
    } else if (studentSagaRecordsCount > 0) {
        this.updateBasedOnCompletedSagas(penReqBatchEntities, penRequestBatchEntity, redisKey, studentSagaRecordsCount, newPenAndMatchCount, isSamePenAssignedToMultiplePRForSameBatch);
    }
}
Also used : lombok.val(lombok.val) PenRequestBatchMultiplePen(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchMultiplePen)

Aggregations

PenRequestBatchMultiplePen (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchMultiplePen)1 lombok.val (lombok.val)1