use of org.folio.rest.jaxrs.model.LoadStatusAttributes in project mod-kb-ebsco-java by folio-org.
the class HoldingsServiceImpl method hasLoadedLastPage.
private boolean hasLoadedLastPage(HoldingsLoadingStatus status) {
LoadStatusAttributes attributes = status.getData().getAttributes();
final Integer importedPages = attributes.getImportedPages();
final Integer totalPages = attributes.getTotalPages();
return isInProgress(status) && importedPages.equals(totalPages);
}
use of org.folio.rest.jaxrs.model.LoadStatusAttributes in project mod-kb-ebsco-java by folio-org.
the class HoldingsServiceImpl method processChanges.
@Override
public void processChanges(DeltaReportMessage holdings) {
final String tenantId = holdings.getTenantId();
final UUID credentialsId = toUUID(holdings.getCredentialsId());
processChanges(holdings.getHoldingList(), OffsetDateTime.now(), credentialsId, tenantId).thenCompose(o -> holdingsStatusRepository.increaseImportedCount(holdings.getHoldingList().size(), 1, credentialsId, tenantId)).thenCompose(status -> {
LoadStatusAttributes attributes = status.getData().getAttributes();
if (hasLoadedLastPage(status)) {
return holdingsStatusRepository.update(getStatusCompleted(attributes.getTotalCount()), credentialsId, tenantId).thenCompose(o -> transactionIdRepository.save(credentialsId, holdings.getTransactionId(), tenantId));
}
return CompletableFuture.completedFuture(null);
}).exceptionally(e -> {
logger.error(FAILED_PROCESS_CHANGES_MESSAGE, e);
return null;
});
}
use of org.folio.rest.jaxrs.model.LoadStatusAttributes in project mod-kb-ebsco-java by folio-org.
the class HoldingsServiceImpl method tryChangingStatusToInProgress.
private CompletableFuture<Void> tryChangingStatusToInProgress(HoldingsLoadingStatus newStatus, UUID credentialsId, String tenantId) {
return holdingsStatusRepository.findByCredentialsId(credentialsId, tenantId).thenCompose(status -> {
LoadStatusAttributes attributes = status.getData().getAttributes();
logger.info(CURRENT_STATUS_MESSAGE, credentialsId, attributes.getStatus().getName());
if (!isInProgress(status) || processTimedOut(status)) {
return holdingsStatusRepository.delete(credentialsId, tenantId).thenCompose(o -> holdingsStatusRepository.save(newStatus, credentialsId, tenantId));
}
return failedFuture(new ProcessInProgressException(LOADING_STATUS_IN_PROGRESS_MESSAGE));
});
}
use of org.folio.rest.jaxrs.model.LoadStatusAttributes in project mod-kb-ebsco-java by folio-org.
the class HoldingsServiceImpl method saveHolding.
@Override
public void saveHolding(HoldingsMessage holdings) {
final String tenantId = holdings.getTenantId();
final UUID credentialsId = toUUID(holdings.getCredentialsId());
saveHoldings(holdings.getHoldingList(), OffsetDateTime.now(), credentialsId, tenantId).thenCompose(o -> holdingsStatusRepository.increaseImportedCount(holdings.getHoldingList().size(), 1, credentialsId, tenantId)).thenCompose(status -> {
LoadStatusAttributes attributes = status.getData().getAttributes();
if (hasLoadedLastPage(status)) {
return holdingsRepository.deleteBeforeTimestamp(getZonedDateTime(attributes.getStarted()), credentialsId, tenantId).thenCompose(o -> holdingsStatusRepository.update(getStatusCompleted(attributes.getTotalCount()), credentialsId, tenantId)).thenCompose(o -> transactionIdRepository.save(credentialsId, holdings.getTransactionId(), tenantId));
}
return CompletableFuture.completedFuture(null);
}).exceptionally(e -> {
logger.error(FAILED_SAVE_HOLDINGS_MESSAGE, e);
return null;
});
}
Aggregations