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);
}
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);
}
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);
}
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));
}
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);
}
Aggregations