use of org.folio.service.holdings.message.ConfigurationMessage in project mod-kb-ebsco-java by folio-org.
the class TransactionLoadServiceFacadeTest method shouldCreateSnapshotUsingExistingTransactionIfItIsInProgress.
@Test
public void shouldCreateSnapshotUsingExistingTransactionIfItIsInProgress(TestContext context) throws IOException, URISyntaxException {
Async async = context.async();
mockGetWithBody(new EqualToPattern(RMAPI_TRANSACTIONS_URL), readFile("responses/rmapi/holdings/status/get-transaction-list-in-progress.json"));
mockResponseList(new UrlPathPattern(new EqualToPattern(getStatusEndpoint(TRANSACTION_ID)), false), new ResponseDefinitionBuilder().withBody(readFile("responses/rmapi/holdings/status/get-transaction-status-completed.json")));
mockPostHoldings();
interceptor = interceptAndStop(HOLDINGS_SERVICE_ADDRESS, SNAPSHOT_CREATED_ACTION, message -> async.complete());
vertx.eventBus().addOutboundInterceptor(interceptor);
loadServiceFacade.createSnapshot(new ConfigurationMessage(stubConfiguration, STUB_CREDENTIALS_ID, STUB_TENANT));
async.await(TIMEOUT);
assertTrue(async.isSucceeded());
}
use of org.folio.service.holdings.message.ConfigurationMessage in project mod-kb-ebsco-java by folio-org.
the class TransactionLoadServiceFacadeTest method shouldNotCreateSnapshotIfItWasRecentlyCreated.
@Test
public void shouldNotCreateSnapshotIfItWasRecentlyCreated(TestContext context) throws IOException, URISyntaxException {
Async async = context.async();
String now = HOLDINGS_STATUS_TIME_FORMATTER.format(LocalDateTime.now(ZoneOffset.UTC));
HoldingsTransactionIdsList idList = readJsonFile("responses/rmapi/holdings/status/get-transaction-list.json", HoldingsTransactionIdsList.class);
HoldingsDownloadTransaction firstTransaction = idList.getHoldingsDownloadTransactionIds().get(0);
idList.getHoldingsDownloadTransactionIds().set(0, firstTransaction.toBuilder().creationDate(now).build());
HoldingsLoadTransactionStatus status = readJsonFile("responses/rmapi/holdings/status/get-transaction-status-completed.json", HoldingsLoadTransactionStatus.class).toBuilder().creationDate(now).build();
mockGetWithBody(new EqualToPattern(RMAPI_TRANSACTIONS_URL), Json.encode(idList));
mockGetWithBody(new EqualToPattern(getStatusEndpoint(TRANSACTION_ID)), Json.encode(status));
mockPostHoldings();
interceptor = interceptAndStop(HOLDINGS_SERVICE_ADDRESS, SNAPSHOT_CREATED_ACTION, message -> async.complete());
vertx.eventBus().addOutboundInterceptor(interceptor);
loadServiceFacade.createSnapshot(new ConfigurationMessage(stubConfiguration, STUB_CREDENTIALS_ID, STUB_TENANT));
async.await(TIMEOUT);
WireMock.verify(0, postRequestedFor(new UrlPathPattern(new EqualToPattern(RMAPI_POST_TRANSACTIONS_HOLDINGS_URL), false)));
}
use of org.folio.service.holdings.message.ConfigurationMessage in project mod-kb-ebsco-java by folio-org.
the class DefaultLoadServiceFacadeTest method shouldNotCreateSnapshotIfItWasRecentlyCreated.
@Test
public void shouldNotCreateSnapshotIfItWasRecentlyCreated(TestContext context) throws IOException, URISyntaxException {
Async async = context.async();
String now = HOLDINGS_STATUS_TIME_FORMATTER.format(LocalDateTime.now(ZoneOffset.UTC));
HoldingsLoadStatus status = readJsonFile("responses/rmapi/holdings/status/get-status-completed.json", HoldingsLoadStatus.class).toBuilder().created(now).build();
mockGetWithBody(new EqualToPattern(RMAPI_HOLDINGS_STATUS_URL), Json.encode(status));
mockPostHoldings();
interceptor = interceptAndStop(HOLDINGS_SERVICE_ADDRESS, SNAPSHOT_CREATED_ACTION, message -> async.complete());
vertx.eventBus().addOutboundInterceptor(interceptor);
loadServiceFacade.createSnapshot(new ConfigurationMessage(configuration, STUB_CREDENTIALS_ID, STUB_TENANT));
async.await(TIMEOUT);
WireMock.verify(0, postRequestedFor(new UrlPathPattern(new EqualToPattern(RMAPI_POST_HOLDINGS_URL), false)));
}
use of org.folio.service.holdings.message.ConfigurationMessage in project mod-kb-ebsco-java by folio-org.
the class HoldingsServiceImpl method loadSingleHoldings.
@Override
public CompletableFuture<Void> loadSingleHoldings(RMAPITemplateContext context) {
final String tenantId = context.getOkapiData().getTenant();
final String credentialsId = context.getCredentialsId();
Future<Void> executeFuture = executeWithLock(START_LOADING_LOCK, () -> tryChangingStatusToInProgress(getStatusPopulatingStagingArea(), toUUID(credentialsId), tenantId).thenCompose(o -> resetRetries(snapshotRetryCount - 1, toUUID(credentialsId), tenantId)).thenAccept(o -> {
ConfigurationMessage configuration = new ConfigurationMessage(context.getConfiguration(), credentialsId, tenantId);
loadServiceFacade.createSnapshot(configuration);
}));
return mapVertxFuture(executeFuture);
}
use of org.folio.service.holdings.message.ConfigurationMessage in project mod-kb-ebsco-java by folio-org.
the class AbstractLoadServiceFacade method createSnapshot.
@Override
public void createSnapshot(ConfigurationMessage message) {
LoadServiceImpl loadingService = new LoadServiceImpl(message.getConfiguration(), vertx);
populateHoldingsIfNecessary(loadingService).thenAccept(status -> holdingsService.snapshotCreated(getSnapshotCreatedMessage(message, status, getRequestCount(status.getTotalCount(), getMaxPageSize())))).whenComplete((o, throwable) -> {
if (throwable != null) {
logger.error("Failed to create snapshot", throwable);
holdingsService.snapshotFailed(getSnapshotFailedMessage(message, throwable));
}
});
}
Aggregations