Search in sources :

Example 1 with LoadStatusAttributes

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);
}
Also used : LoadStatusAttributes(org.folio.rest.jaxrs.model.LoadStatusAttributes)

Example 2 with LoadStatusAttributes

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;
    });
}
Also used : HoldingsLoadingStatusFactory.getStatusLoadingHoldings(org.folio.repository.holdings.status.HoldingsLoadingStatusFactory.getStatusLoadingHoldings) Arrays(java.util.Arrays) HoldingsMessage(org.folio.service.holdings.message.HoldingsMessage) DeltaReportCreatedMessage(org.folio.service.holdings.message.DeltaReportCreatedMessage) Autowired(org.springframework.beans.factory.annotation.Autowired) HoldingChangeType(org.folio.holdingsiq.model.HoldingChangeType) LoadStatusNameEnum(org.folio.rest.jaxrs.model.LoadStatusNameEnum) HOLDING_UPDATED_ADDED_COVERAGE(org.folio.holdingsiq.model.HoldingChangeType.HOLDING_UPDATED_ADDED_COVERAGE) HoldingsStatusRepository(org.folio.repository.holdings.status.HoldingsStatusRepository) RetryStatus(org.folio.repository.holdings.status.retry.RetryStatus) HoldingsLoadingStatusFactory.getLoadStatusFailed(org.folio.repository.holdings.status.HoldingsLoadingStatusFactory.getLoadStatusFailed) HoldingsLoadingStatusFactory.getStatusPopulatingStagingArea(org.folio.repository.holdings.status.HoldingsLoadingStatusFactory.getStatusPopulatingStagingArea) StringUtils(org.apache.commons.lang3.StringUtils) SnapshotCreatedMessage(org.folio.service.holdings.message.SnapshotCreatedMessage) HoldingsLoadingStatusFactory.getStatusCompleted(org.folio.repository.holdings.status.HoldingsLoadingStatusFactory.getStatusCompleted) Holding(org.folio.holdingsiq.model.Holding) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) RowSetUtils.toUUID(org.folio.db.RowSetUtils.toUUID) UUID(java.util.UUID) HOLDING_ADDED(org.folio.holdingsiq.model.HoldingChangeType.HOLDING_ADDED) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) LoadStatusAttributes(org.folio.rest.jaxrs.model.LoadStatusAttributes) RMAPITemplateContext(org.folio.rest.util.template.RMAPITemplateContext) HOLDING_UPDATED(org.folio.holdingsiq.model.HoldingChangeType.HOLDING_UPDATED) HoldingsServiceMessagesFactory.getLoadHoldingsMessage(org.folio.repository.holdings.HoldingsServiceMessagesFactory.getLoadHoldingsMessage) Producer(org.glassfish.jersey.internal.util.Producer) CompletableFuture(java.util.concurrent.CompletableFuture) HoldingsLoadingStatusFactory.getStatusNotStarted(org.folio.repository.holdings.status.HoldingsLoadingStatusFactory.getStatusNotStarted) Function(java.util.function.Function) ProcessInProgressException(org.folio.service.holdings.exception.ProcessInProgressException) ErrorUtil.createError(org.folio.rest.util.ErrorUtil.createError) Value(org.springframework.beans.factory.annotation.Value) HoldingInReport(org.folio.holdingsiq.model.HoldingInReport) HoldingsRepository(org.folio.repository.holdings.HoldingsRepository) DbHoldingInfo(org.folio.repository.holdings.DbHoldingInfo) SnapshotFailedMessage(org.folio.service.holdings.message.SnapshotFailedMessage) AsyncResult(io.vertx.core.AsyncResult) HOLDING_UPDATED_DELETED_COVERAGE(org.folio.holdingsiq.model.HoldingChangeType.HOLDING_UPDATED_DELETED_COVERAGE) FutureUtils.mapVertxFuture(org.folio.util.FutureUtils.mapVertxFuture) FutureUtils.failedFuture(org.folio.util.FutureUtils.failedFuture) LoadFailedMessage(org.folio.service.holdings.message.LoadFailedMessage) Promise(io.vertx.core.Promise) DeltaReportMessage(org.folio.service.holdings.message.DeltaReportMessage) Vertx(io.vertx.core.Vertx) HoldingsLoadingStatus(org.folio.rest.jaxrs.model.HoldingsLoadingStatus) Integer.parseInt(java.lang.Integer.parseInt) Component(org.springframework.stereotype.Component) HoldingsId(org.folio.repository.holdings.HoldingsId) ChronoUnit(java.time.temporal.ChronoUnit) Lock(io.vertx.core.shareddata.Lock) LoadStatusInformation(org.folio.rest.jaxrs.model.LoadStatusInformation) RetryStatusRepository(org.folio.repository.holdings.status.retry.RetryStatusRepository) DateTimeFormatter(java.time.format.DateTimeFormatter) ConfigurationMessage(org.folio.service.holdings.message.ConfigurationMessage) TransactionIdRepository(org.folio.repository.holdings.transaction.TransactionIdRepository) HOLDING_DELETED(org.folio.holdingsiq.model.HoldingChangeType.HOLDING_DELETED) Handler(io.vertx.core.Handler) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) LoadStatusAttributes(org.folio.rest.jaxrs.model.LoadStatusAttributes) RowSetUtils.toUUID(org.folio.db.RowSetUtils.toUUID) UUID(java.util.UUID)

Example 3 with LoadStatusAttributes

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));
    });
}
Also used : ProcessInProgressException(org.folio.service.holdings.exception.ProcessInProgressException) LoadStatusAttributes(org.folio.rest.jaxrs.model.LoadStatusAttributes)

Example 4 with LoadStatusAttributes

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;
    });
}
Also used : HoldingsLoadingStatusFactory.getStatusLoadingHoldings(org.folio.repository.holdings.status.HoldingsLoadingStatusFactory.getStatusLoadingHoldings) Arrays(java.util.Arrays) HoldingsMessage(org.folio.service.holdings.message.HoldingsMessage) DeltaReportCreatedMessage(org.folio.service.holdings.message.DeltaReportCreatedMessage) Autowired(org.springframework.beans.factory.annotation.Autowired) HoldingChangeType(org.folio.holdingsiq.model.HoldingChangeType) LoadStatusNameEnum(org.folio.rest.jaxrs.model.LoadStatusNameEnum) HOLDING_UPDATED_ADDED_COVERAGE(org.folio.holdingsiq.model.HoldingChangeType.HOLDING_UPDATED_ADDED_COVERAGE) HoldingsStatusRepository(org.folio.repository.holdings.status.HoldingsStatusRepository) RetryStatus(org.folio.repository.holdings.status.retry.RetryStatus) HoldingsLoadingStatusFactory.getLoadStatusFailed(org.folio.repository.holdings.status.HoldingsLoadingStatusFactory.getLoadStatusFailed) HoldingsLoadingStatusFactory.getStatusPopulatingStagingArea(org.folio.repository.holdings.status.HoldingsLoadingStatusFactory.getStatusPopulatingStagingArea) StringUtils(org.apache.commons.lang3.StringUtils) SnapshotCreatedMessage(org.folio.service.holdings.message.SnapshotCreatedMessage) HoldingsLoadingStatusFactory.getStatusCompleted(org.folio.repository.holdings.status.HoldingsLoadingStatusFactory.getStatusCompleted) Holding(org.folio.holdingsiq.model.Holding) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) RowSetUtils.toUUID(org.folio.db.RowSetUtils.toUUID) UUID(java.util.UUID) HOLDING_ADDED(org.folio.holdingsiq.model.HoldingChangeType.HOLDING_ADDED) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) LoadStatusAttributes(org.folio.rest.jaxrs.model.LoadStatusAttributes) RMAPITemplateContext(org.folio.rest.util.template.RMAPITemplateContext) HOLDING_UPDATED(org.folio.holdingsiq.model.HoldingChangeType.HOLDING_UPDATED) HoldingsServiceMessagesFactory.getLoadHoldingsMessage(org.folio.repository.holdings.HoldingsServiceMessagesFactory.getLoadHoldingsMessage) Producer(org.glassfish.jersey.internal.util.Producer) CompletableFuture(java.util.concurrent.CompletableFuture) HoldingsLoadingStatusFactory.getStatusNotStarted(org.folio.repository.holdings.status.HoldingsLoadingStatusFactory.getStatusNotStarted) Function(java.util.function.Function) ProcessInProgressException(org.folio.service.holdings.exception.ProcessInProgressException) ErrorUtil.createError(org.folio.rest.util.ErrorUtil.createError) Value(org.springframework.beans.factory.annotation.Value) HoldingInReport(org.folio.holdingsiq.model.HoldingInReport) HoldingsRepository(org.folio.repository.holdings.HoldingsRepository) DbHoldingInfo(org.folio.repository.holdings.DbHoldingInfo) SnapshotFailedMessage(org.folio.service.holdings.message.SnapshotFailedMessage) AsyncResult(io.vertx.core.AsyncResult) HOLDING_UPDATED_DELETED_COVERAGE(org.folio.holdingsiq.model.HoldingChangeType.HOLDING_UPDATED_DELETED_COVERAGE) FutureUtils.mapVertxFuture(org.folio.util.FutureUtils.mapVertxFuture) FutureUtils.failedFuture(org.folio.util.FutureUtils.failedFuture) LoadFailedMessage(org.folio.service.holdings.message.LoadFailedMessage) Promise(io.vertx.core.Promise) DeltaReportMessage(org.folio.service.holdings.message.DeltaReportMessage) Vertx(io.vertx.core.Vertx) HoldingsLoadingStatus(org.folio.rest.jaxrs.model.HoldingsLoadingStatus) Integer.parseInt(java.lang.Integer.parseInt) Component(org.springframework.stereotype.Component) HoldingsId(org.folio.repository.holdings.HoldingsId) ChronoUnit(java.time.temporal.ChronoUnit) Lock(io.vertx.core.shareddata.Lock) LoadStatusInformation(org.folio.rest.jaxrs.model.LoadStatusInformation) RetryStatusRepository(org.folio.repository.holdings.status.retry.RetryStatusRepository) DateTimeFormatter(java.time.format.DateTimeFormatter) ConfigurationMessage(org.folio.service.holdings.message.ConfigurationMessage) TransactionIdRepository(org.folio.repository.holdings.transaction.TransactionIdRepository) HOLDING_DELETED(org.folio.holdingsiq.model.HoldingChangeType.HOLDING_DELETED) Handler(io.vertx.core.Handler) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) LoadStatusAttributes(org.folio.rest.jaxrs.model.LoadStatusAttributes) RowSetUtils.toUUID(org.folio.db.RowSetUtils.toUUID) UUID(java.util.UUID)

Aggregations

LoadStatusAttributes (org.folio.rest.jaxrs.model.LoadStatusAttributes)4 AsyncResult (io.vertx.core.AsyncResult)2 Future (io.vertx.core.Future)2 Handler (io.vertx.core.Handler)2 Promise (io.vertx.core.Promise)2 Vertx (io.vertx.core.Vertx)2 Lock (io.vertx.core.shareddata.Lock)2 Integer.parseInt (java.lang.Integer.parseInt)2 OffsetDateTime (java.time.OffsetDateTime)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 ChronoUnit (java.time.temporal.ChronoUnit)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Set (java.util.Set)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Function (java.util.function.Function)2