use of org.folio.holdingsiq.model.HoldingsDownloadTransaction 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.holdingsiq.model.HoldingsDownloadTransaction in project mod-kb-ebsco-java by folio-org.
the class TransactionLoadServiceFacade method getLastLoadingStatus.
@Override
protected CompletableFuture<HoldingsStatus> getLastLoadingStatus(LoadService loadingService) {
return loadingService.getTransactions().thenCompose(transactions -> {
if (transactions.getHoldingsDownloadTransactionIds().isEmpty()) {
return CompletableFuture.completedFuture(createNoneStatus());
}
List<HoldingsDownloadTransaction> sortedTransactions = sortByDate(transactions);
HoldingsDownloadTransaction lastTransaction = sortedTransactions.get(sortedTransactions.size() - 1);
return getLoadingStatus(loadingService, lastTransaction.getTransactionId());
});
}
use of org.folio.holdingsiq.model.HoldingsDownloadTransaction in project mod-kb-ebsco-java by folio-org.
the class TransactionLoadHoldingsImplTest method shouldUpdateHoldingsWithDeltas.
@Test
public void shouldUpdateHoldingsWithDeltas(TestContext context) throws IOException, URISyntaxException {
HoldingsTestUtil.saveHolding(STUB_CREDENTIALS_ID, Json.decodeValue(readFile("responses/kb-ebsco/holdings/custom-holding.json"), DbHoldingInfo.class), OffsetDateTime.now(), vertx);
HoldingsTestUtil.saveHolding(STUB_CREDENTIALS_ID, Json.decodeValue(readFile("responses/kb-ebsco/holdings/custom-holding2.json"), DbHoldingInfo.class), OffsetDateTime.now(), vertx);
TransactionIdTestUtil.addTransactionId(STUB_CREDENTIALS_ID, PREVIOUS_TRANSACTION_ID, vertx);
HoldingsDownloadTransaction previousTransaction = HoldingsDownloadTransaction.builder().creationDate(OffsetDateTime.now().minus(500, ChronoUnit.HOURS).toString()).transactionId(PREVIOUS_TRANSACTION_ID).build();
mockTransactionList(Collections.singletonList(previousTransaction));
mockPostHoldings();
mockGet(new EqualToPattern(getStatusEndpoint(PREVIOUS_TRANSACTION_ID)), RMAPI_RESPONSE_TRANSACTION_STATUS_COMPLETED);
mockGet(new EqualToPattern(getStatusEndpoint(TRANSACTION_ID)), RMAPI_RESPONSE_TRANSACTION_STATUS_COMPLETED);
mockPostDeltaReport();
mockGet(new EqualToPattern(getDeltaReportStatusEndpoint()), "responses/rmapi/holdings/status/get-delta-report-status-completed.json");
mockGet(new EqualToPattern(getDeltaEndpoint()), "responses/rmapi/holdings/delta/get-delta.json");
Async async = context.async();
handleStatusChange(COMPLETED, holdingsStatusRepository, o -> async.complete());
postWithStatus(HOLDINGS_LOAD_BY_ID_URL, "", SC_NO_CONTENT, STUB_TOKEN_HEADER);
async.await(TIMEOUT);
Map<String, DbHoldingInfo> holdings = HoldingsTestUtil.getHoldings(vertx).stream().collect(Collectors.toMap(this::getHoldingsId, Function.identity()));
assertFalse(holdings.containsKey(DELETED_HOLDING_ID));
DbHoldingInfo updatedHolding = holdings.get(UPDATED_HOLDING_ID);
assertEquals("Test Title Updated", updatedHolding.getPublicationTitle());
assertEquals("Test one Press Updated", updatedHolding.getPublisherName());
assertEquals("Book", updatedHolding.getResourceType());
DbHoldingInfo addedHolding = holdings.get(ADDED_HOLDING_ID);
assertEquals("Added test title", addedHolding.getPublicationTitle());
assertEquals("Added test publisher", addedHolding.getPublisherName());
assertEquals("Book", addedHolding.getResourceType());
}
Aggregations