Search in sources :

Example 21 with CoveragePeriod

use of gov.cms.ab2d.coverage.model.CoveragePeriod in project ab2d by CMSgov.

the class CoverageServiceImpl method cancelSearch.

@Override
public CoverageSearchEvent cancelSearch(int periodId, String description) {
    CoveragePeriod period = findCoveragePeriod(periodId);
    CoverageJobStatus coverageJobStatus = period.getStatus();
    if (coverageJobStatus != CoverageJobStatus.SUBMITTED) {
        throw new InvalidJobStateTransition("cannot change from " + coverageJobStatus + " to " + CoverageJobStatus.CANCELLED);
    }
    coverageSearchRepo.deleteCoverageSearchByPeriod(period);
    return updateStatus(period, description, CoverageJobStatus.CANCELLED);
}
Also used : CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) CoverageJobStatus(gov.cms.ab2d.coverage.model.CoverageJobStatus)

Example 22 with CoveragePeriod

use of gov.cms.ab2d.coverage.model.CoveragePeriod in project ab2d by CMSgov.

the class CoverageServiceImpl method getCreateIfAbsentCoveragePeriod.

@Override
public CoveragePeriod getCreateIfAbsentCoveragePeriod(ContractForCoverageDTO contract, int month, int year) {
    checkMonthAndYear(month, year);
    Optional<CoveragePeriod> existing = coveragePeriodRepo.findByContractNumberAndMonthAndYear(contract.getContractNumber(), month, year);
    if (existing.isPresent()) {
        return existing.get();
    }
    CoveragePeriod period = new CoveragePeriod();
    period.setContractNumber(contract.getContractNumber());
    period.setMonth(month);
    period.setYear(year);
    return coveragePeriodRepo.save(period);
}
Also used : CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod)

Example 23 with CoveragePeriod

use of gov.cms.ab2d.coverage.model.CoveragePeriod in project ab2d by CMSgov.

the class CoverageServiceImpl method resubmitSearch.

@Override
public CoverageSearchEvent resubmitSearch(int periodId, int attempts, String failedDescription, String restartDescription, boolean prioritize) {
    CoveragePeriod period = findCoveragePeriod(periodId);
    updateStatus(period, failedDescription, CoverageJobStatus.FAILED, false);
    // Add to queue of jobs to do
    CoverageSearch search = new CoverageSearch();
    search.setPeriod(period);
    search.setAttempts(attempts);
    // Force to front of the queue if necessary
    if (prioritize) {
        search.setCreated(OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC));
    }
    coverageSearchRepo.saveAndFlush(search);
    return updateStatus(period, restartDescription, CoverageJobStatus.SUBMITTED);
}
Also used : CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) CoverageSearch(gov.cms.ab2d.coverage.model.CoverageSearch)

Example 24 with CoveragePeriod

use of gov.cms.ab2d.coverage.model.CoveragePeriod in project ab2d by CMSgov.

the class CoverageServiceImpl method submitSearch.

@Override
public Optional<CoverageSearchEvent> submitSearch(int periodId, int attempts, String description) {
    CoveragePeriod period = findCoveragePeriod(periodId);
    CoverageJobStatus coverageJobStatus = period.getStatus();
    if (coverageJobStatus == CoverageJobStatus.IN_PROGRESS || coverageJobStatus == CoverageJobStatus.SUBMITTED) {
        return Optional.empty();
    }
    // Add to queue of jobs to do
    CoverageSearch search = new CoverageSearch();
    search.setPeriod(period);
    search.setAttempts(attempts);
    coverageSearchRepo.saveAndFlush(search);
    return Optional.of(updateStatus(period, description, CoverageJobStatus.SUBMITTED));
}
Also used : CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) CoverageSearch(gov.cms.ab2d.coverage.model.CoverageSearch) CoverageJobStatus(gov.cms.ab2d.coverage.model.CoverageJobStatus)

Example 25 with CoveragePeriod

use of gov.cms.ab2d.coverage.model.CoveragePeriod in project ab2d by CMSgov.

the class CoverageServiceImpl method searchDiff.

// todo: consider removing now that the CoverageDeltaRepository functionality exists
// We can write alarms using that delta table if we need to.
@Override
@Trace(metricName = "SearchDiff", dispatcher = true)
public CoverageSearchDiff searchDiff(int periodId) {
    CoveragePeriod period = findCoveragePeriod(periodId);
    if (period.getStatus() != CoverageJobStatus.IN_PROGRESS) {
        throw new InvalidJobStateTransition("Cannot diff a currently running search against previous search because results may be added");
    }
    Optional<CoverageSearchEvent> previousSearch = findEventWithSuccessfulOffset(periodId, 1);
    Optional<CoverageSearchEvent> currentSearch = findEventWithSuccessfulOffset(periodId, 0);
    CoverageSearchEvent current = currentSearch.orElseThrow(() -> new RuntimeException("could not find latest in progress search event"));
    int previousCount = 0;
    if (previousSearch.isPresent()) {
        previousCount = coverageServiceRepo.countBySearchEvent(previousSearch.get());
    }
    int currentCount = coverageServiceRepo.countBySearchEvent(current);
    int unchanged = 0;
    if (previousCount > 0) {
        log.info("Calculating the deltas for the search period {}-{}-{}", period.getContractNumber(), period.getMonth(), period.getYear());
        coverageDeltaRepository.trackDeltas(previousSearch.get(), current);
        unchanged = coverageServiceRepo.countIntersection(previousSearch.get(), current);
    }
    return new CoverageSearchDiff(period, previousCount, currentCount, unchanged);
}
Also used : CoverageSearchDiff(gov.cms.ab2d.coverage.model.CoverageSearchDiff) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) CoverageSearchEvent(gov.cms.ab2d.coverage.model.CoverageSearchEvent) Trace(com.newrelic.api.agent.Trace)

Aggregations

CoveragePeriod (gov.cms.ab2d.coverage.model.CoveragePeriod)62 Test (org.junit.jupiter.api.Test)40 DisplayName (org.junit.jupiter.api.DisplayName)38 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)25 CoverageSearchEvent (gov.cms.ab2d.coverage.model.CoverageSearchEvent)22 ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)20 CoverageSearch (gov.cms.ab2d.coverage.model.CoverageSearch)19 OffsetDateTime (java.time.OffsetDateTime)18 CoverageJobStatus (gov.cms.ab2d.coverage.model.CoverageJobStatus)15 CoverageMapping (gov.cms.ab2d.coverage.model.CoverageMapping)15 ContractToContractCoverageMapping (gov.cms.ab2d.worker.config.ContractToContractCoverageMapping)14 ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)12 Identifiers (gov.cms.ab2d.coverage.model.Identifiers)11 ZonedDateTime (java.time.ZonedDateTime)11 ArrayList (java.util.ArrayList)11 LinkedHashSet (java.util.LinkedHashSet)11 Job (gov.cms.ab2d.common.model.Job)10 AB2D_EPOCH (gov.cms.ab2d.common.util.DateUtil.AB2D_EPOCH)9 CoveragePagingRequest (gov.cms.ab2d.coverage.model.CoveragePagingRequest)9 CoveragePagingResult (gov.cms.ab2d.coverage.model.CoveragePagingResult)9