Search in sources :

Example 1 with PenRequestBatchStat

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

the class PenRequestBatchService method getStats.

/**
 * Gets stats.
 *
 * @return the stats
 */
@Transactional(propagation = Propagation.SUPPORTS)
public PenRequestBatchStats getStats() {
    final List<PenRequestBatchStat> penRequestBatchStats = new ArrayList<>();
    for (final SchoolGroupCodes schoolGroupCode : SchoolGroupCodes.values()) {
        val results = this.getRepository().findByPenRequestBatchStatusCodeAndSchoolGroupCode(PenRequestBatchStatusCodes.ACTIVE.getCode(), schoolGroupCode.getCode());
        final PenRequestBatchStat stats = this.calculateFixableAndRepeats(results);
        stats.setSchoolGroupCode(schoolGroupCode.getCode());
        List<String> penReqBatchStatusCodes = Arrays.asList(PenRequestBatchStatusCodes.UNARCHIVED.getCode(), PenRequestBatchStatusCodes.UNARCHIVED_CHANGED.getCode());
        stats.setUnarchivedCount(this.getRepository().countAllByPenRequestBatchStatusCodeInAndSchoolGroupCode(penReqBatchStatusCodes, schoolGroupCode.getCode()));
        if (schoolGroupCode == SchoolGroupCodes.PSI) {
            penReqBatchStatusCodes = Arrays.asList(PenRequestBatchStatusCodes.HOLD_FOR_REVIEW.getCode(), PenRequestBatchStatusCodes.DUPLICATE.getCode());
            stats.setHeldForReviewCount(this.getRepository().countAllByPenRequestBatchStatusCodeInAndSchoolGroupCode(penReqBatchStatusCodes, schoolGroupCode.getCode()));
        } else {
            stats.setHeldForReviewCount(0L);
        }
        penRequestBatchStats.add(stats);
    }
    // this is irrespective of school group code.
    val loadFailedCount = this.getRepository().countPenRequestBatchEntitiesByPenRequestBatchStatusCode(PenRequestBatchStatusCodes.LOAD_FAIL.getCode());
    return PenRequestBatchStats.builder().penRequestBatchStatList(penRequestBatchStats).loadFailCount(loadFailedCount).build();
}
Also used : lombok.val(lombok.val) PenRequestBatchStat(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStat) SchoolGroupCodes(ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with PenRequestBatchStat

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

the class PenRequestBatchService method calculateFixableAndRepeats.

/**
 * Calculate fixable and repeats pen request batch stat.
 *
 * @param results the results
 * @return the pen request batch stat
 */
private PenRequestBatchStat calculateFixableAndRepeats(final List<PenRequestBatchEntity> results) {
    final PenRequestBatchStat.PenRequestBatchStatBuilder builder = PenRequestBatchStat.builder();
    long fixableCount = 0;
    long repeatCount = 0;
    for (val result : results) {
        if (result != null) {
            if (result.getFixableCount() != null) {
                fixableCount += result.getFixableCount();
            }
            if (result.getRepeatCount() != null) {
                repeatCount += result.getRepeatCount();
            }
        }
    }
    builder.fixableCount(fixableCount);
    builder.repeatCount(repeatCount);
    builder.pendingCount((long) results.size());
    return builder.build();
}
Also used : lombok.val(lombok.val) PenRequestBatchStat(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStat)

Aggregations

PenRequestBatchStat (ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStat)2 lombok.val (lombok.val)2 SchoolGroupCodes (ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes)1 Transactional (org.springframework.transaction.annotation.Transactional)1