use of gov.cms.ab2d.common.model.Contract in project ab2d by CMSgov.
the class CoverageDriverImpl method isCoverageAvailable.
/**
* Determine whether database contains all necessary enrollment for a contract and that no updates to that
* enrollment are currently occurring.
*
* Steps
* - Lock coverage so no other workers can modify coverage while this check is occurring
* - Create any {@link CoveragePeriod}s that are currently missing
* - Check the following to determine whether a job can run (return false if any are not met)
* - Look for whether months have failed to update during earlier attempts
* - Look for coverage periods that have never been successfully searched and queue them
* - Look for coverage periods currently being updated
*
* @param job job to check for coverage
* @throws CoverageDriverException if enrollment state violates assumed preconditions or database lock cannot be retrieved
* @throws InterruptedException if trying to lock the table is interrupted
*/
@Trace(metricName = "EnrollmentIsAvailable", dispatcher = true)
@Override
public boolean isCoverageAvailable(Job job, ContractDTO contract) throws InterruptedException {
String contractNumber = job.getContractNumber();
assert contractNumber.equals(contract.getContractNumber());
Lock coverageLock = coverageLockWrapper.getCoverageLock();
// Track whether locked or not to prevent an illegal monitor exception
boolean locked = false;
try {
locked = coverageLock.tryLock(MINUTE, TimeUnit.MINUTES);
if (!locked) {
log.warn("Could not retrieve lock after timeout of {} minute(s)." + " Cannot confirm coverage metadata is available", MINUTE);
return false;
}
// Check whether a coverage period is missing for this contract.
// If so then create those coverage periods.
discoverCoveragePeriods(mapping.map(contract));
log.info("queueing never searched coverage metadata periods for {}", contractNumber);
/*
* If any relevant coverage period has never been pulled from BFD successfully then automatically fail the
* search
*/
List<CoveragePeriod> neverSearched = coverageService.coveragePeriodNeverSearchedSuccessfully().stream().filter(period -> Objects.equals(contract.getContractNumber(), period.getContractNumber())).toList();
if (!neverSearched.isEmpty()) {
// Check that we've not submitted and failed these jobs
neverSearched.forEach(period -> checkCoveragePeriodValidity(job, period));
// Add all never searched coverage periods to the queue for processing
neverSearched.forEach(period -> coverageProcessor.queueCoveragePeriod(period, false));
return false;
}
log.info("checking whether any coverage metadata is currently being updated for {}", contractNumber);
/*
* If coverage periods are submitted, in progress or null then ignore for the moment.
*
* There will always be at least one coverage period returned.
*/
List<CoveragePeriod> periods = coverageService.findAssociatedCoveragePeriods(contract.getContractNumber());
if (periods.isEmpty()) {
log.error("There are no existing coverage periods for this job so no metadata exists");
throw new CoverageDriverException("There are no existing coverage periods for this job so no ");
}
return periods.stream().map(CoveragePeriod::getStatus).noneMatch(status -> status == null || status == CoverageJobStatus.IN_PROGRESS || status == CoverageJobStatus.SUBMITTED);
} catch (InterruptedException interruptedException) {
log.error("Interrupted attempting to retrieve lock. Cannot confirm coverage metadata is available");
throw interruptedException;
} finally {
if (locked) {
coverageLock.unlock();
}
}
}
use of gov.cms.ab2d.common.model.Contract in project ab2d by CMSgov.
the class HPMSManualModeTest method buildContract.
@NotNull
private Contract buildContract(Contract.UpdateMode updateMode) {
Contract contract = new Contract();
contract.setContractNumber(TEST_CONTRACT_NUMBER);
contract.setContractName("Manual Mode Test");
contract.setAttestedOn(OffsetDateTime.now());
contract.setUpdateMode(updateMode);
return contract;
}
use of gov.cms.ab2d.common.model.Contract in project ab2d by CMSgov.
the class AttestationUpdaterServiceImpl method updateContract.
private Optional<Contract> updateContract(HPMSOrganizationInfo hpmsInfo) {
Optional<Contract> contractHolder = contractRepository.findContractByContractNumber(hpmsInfo.getContractId());
if (contractHolder.isEmpty())
return contractHolder;
Contract contract = contractHolder.get();
return contract.isAutoUpdatable() && hpmsInfo.hasChanges(contract) ? Optional.of(hpmsInfo.updateContract(contract)) : Optional.empty();
}
use of gov.cms.ab2d.common.model.Contract in project ab2d by CMSgov.
the class AttestationUpdaterServiceTest method updateCoverage.
@Test
void updateCoverage() {
HPMSOrganizationInfo info = new HPMSOrganizationInfo();
info.setParentOrgId(2);
Contract contract = new Contract();
contract.setHpmsParentOrgId(1L);
info.updateContract(contract);
assertEquals(2L, (long) contract.getHpmsParentOrgId());
}
use of gov.cms.ab2d.common.model.Contract in project ab2d by CMSgov.
the class AttestationUpdaterServiceTest method hasChanges.
@Test
void hasChanges() {
HPMSOrganizationInfo info = new HPMSOrganizationInfo();
info.setParentOrgId(2);
Contract contract = new Contract();
contract.setHpmsParentOrgId(1L);
assertTrue(info.hasChanges(contract));
}
Aggregations