use of org.folio.inventory.storage.external.CollectionResourceClient in project mod-inventory by folio-org.
the class PrecedingSucceedingTitlesHelper method getExistingPrecedingSucceedingTitles.
public Future<List<JsonObject>> getExistingPrecedingSucceedingTitles(Instance instance, Context context) {
CollectionResourceClient precedingSucceedingTitlesClient = createPrecedingSucceedingTitlesClient(context);
Promise<List<JsonObject>> promise = Promise.promise();
String instanceId = instance.getId();
String queryForPrecedingSucceedingInstances = String.format("succeedingInstanceId==(%s) or precedingInstanceId==(%s)", instanceId, instanceId);
precedingSucceedingTitlesClient.getAll(queryForPrecedingSucceedingInstances, response -> {
if (response.getStatusCode() == 200) {
JsonObject json = response.getJson();
List<JsonObject> precedingSucceedingTitles = JsonArrayHelper.toList(json.getJsonArray("precedingSucceedingTitles"));
promise.complete(precedingSucceedingTitles);
} else {
String msg = format("Error retrieving existing preceding and succeeding titles. Response status code: %s", response.getStatusCode());
LOGGER.error(msg);
promise.fail(msg);
}
});
return promise.future();
}
use of org.folio.inventory.storage.external.CollectionResourceClient in project mod-inventory by folio-org.
the class ItemsByHoldingsRecordId method getCollectionResourceRepository.
private CollectionResourceClient getCollectionResourceRepository(RoutingContext routingContext, WebContext context, String path) {
CollectionResourceClient collectionResourceClient = null;
try {
OkapiHttpClient okapiClient = createHttpClient(routingContext, context);
collectionResourceClient = new CollectionResourceClient(okapiClient, new URL(context.getOkapiLocation() + path));
} catch (MalformedURLException mfue) {
log.error(mfue);
}
return collectionResourceClient;
}
use of org.folio.inventory.storage.external.CollectionResourceClient in project mod-inventory by folio-org.
the class MoveApi method moveItems.
private void moveItems(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);
JsonObject itemsMoveJsonRequest = routingContext.getBodyAsJson();
Optional<ValidationError> validationError = itemsMoveHasRequiredFields(itemsMoveJsonRequest);
if (validationError.isPresent()) {
unprocessableEntity(routingContext.response(), validationError.get());
return;
}
String toHoldingsRecordId = itemsMoveJsonRequest.getString(TO_HOLDINGS_RECORD_ID);
List<String> itemIdsToUpdate = toListOfStrings(itemsMoveJsonRequest.getJsonArray(ITEM_IDS));
storage.getHoldingCollection(context).findById(toHoldingsRecordId).thenAccept(holding -> {
if (Objects.nonNull(holding)) {
try {
CollectionResourceClient itemsStorageClient = createItemStorageClient(createHttpClient(routingContext, context), context);
MultipleRecordsFetchClient itemsFetchClient = createItemsFetchClient(itemsStorageClient);
itemsFetchClient.find(itemIdsToUpdate, this::fetchByIdCql).thenAccept(jsons -> {
List<Item> itemsToUpdate = updateHoldingsRecordIdForItems(toHoldingsRecordId, jsons);
updateItems(routingContext, context, itemIdsToUpdate, itemsToUpdate);
}).exceptionally(e -> {
ServerErrorResponse.internalError(routingContext.response(), e);
return null;
});
} catch (Exception e) {
ServerErrorResponse.internalError(routingContext.response(), e);
}
} else {
JsonResponse.unprocessableEntity(routingContext.response(), String.format("Holding with id=%s not found", toHoldingsRecordId));
}
}).exceptionally(e -> {
ServerErrorResponse.internalError(routingContext.response(), e);
return null;
});
}
use of org.folio.inventory.storage.external.CollectionResourceClient in project mod-inventory by folio-org.
the class AbstractInstances method updatePrecedingSucceedingTitles.
protected CompletableFuture<List<Response>> updatePrecedingSucceedingTitles(Instance instance, RoutingContext routingContext, WebContext context) {
CollectionResourceClient precedingSucceedingTitlesClient = createPrecedingSucceedingTitlesClient(routingContext, context);
CollectionResourceRepository precedingSucceedingTitlesRepository = new CollectionResourceRepository(precedingSucceedingTitlesClient);
List<String> instanceId = List.of(instance.getId());
String query = createQueryForPrecedingSucceedingInstances(instanceId);
CompletableFuture<Response> future = new CompletableFuture<>();
precedingSucceedingTitlesClient.getAll(query, future::complete);
return future.thenCompose(result -> updatePrecedingSucceedingTitles(instance, precedingSucceedingTitlesRepository, result));
}
use of org.folio.inventory.storage.external.CollectionResourceClient in project mod-inventory by folio-org.
the class Instances method fetchPrecedingSucceedingTitles.
private CompletableFuture<Instance> fetchPrecedingSucceedingTitles(Success<Instance> success, RoutingContext routingContext, WebContext context) {
Instance instance = success.getResult();
List<String> instanceIds = getInstanceIdsFromInstanceResult(success);
String queryForPrecedingSucceedingInstances = createQueryForPrecedingSucceedingInstances(instanceIds);
CollectionResourceClient precedingSucceedingTitlesClient = createPrecedingSucceedingTitlesClient(routingContext, context);
CompletableFuture<Response> precedingSucceedingTitlesFetched = new CompletableFuture<>();
precedingSucceedingTitlesClient.getAll(queryForPrecedingSucceedingInstances, precedingSucceedingTitlesFetched::complete);
return precedingSucceedingTitlesFetched.thenCompose(response -> withPrecedingSucceedingTitles(routingContext, context, instance, response));
}
Aggregations