use of org.folio.inventory.storage.external.MultipleRecordsFetchClient 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.MultipleRecordsFetchClient in project mod-inventory by folio-org.
the class Instances method fetchHoldingsRecordsForInstanceRecordSet.
private CompletableFuture<List<JsonObject>> fetchHoldingsRecordsForInstanceRecordSet(InstancesResponse instancesResponse, RoutingContext routingContext, WebContext context) {
List<String> instanceIds = getInstanceIdsFromInstanceResult(instancesResponse.getSuccess());
MultipleRecordsFetchClient holdingsFetcher = MultipleRecordsFetchClient.builder().withCollectionPropertyName("holdingsRecords").withExpectedStatus(200).withCollectionResourceClient(createHoldingsStorageClient(routingContext, context)).build();
return holdingsFetcher.find(instanceIds, this::cqlMatchAnyByInstanceIds);
}
use of org.folio.inventory.storage.external.MultipleRecordsFetchClient in project mod-inventory by folio-org.
the class MoveApi method moveHoldings.
private void moveHoldings(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);
JsonObject holdingsMoveJsonRequest = routingContext.getBodyAsJson();
Optional<ValidationError> validationError = holdingsMoveHasRequiredFields(holdingsMoveJsonRequest);
if (validationError.isPresent()) {
unprocessableEntity(routingContext.response(), validationError.get());
return;
}
String toInstanceId = holdingsMoveJsonRequest.getString(TO_INSTANCE_ID);
List<String> holdingsRecordsIdsToUpdate = toListOfStrings(holdingsMoveJsonRequest.getJsonArray(HOLDINGS_RECORD_IDS));
storage.getInstanceCollection(context).findById(toInstanceId).thenAccept(instance -> {
if (instance == null) {
JsonResponse.unprocessableEntity(routingContext.response(), String.format("Instance with id=%s not found", toInstanceId));
return;
}
try {
CollectionResourceClient holdingsStorageClient = createHoldingsStorageClient(createHttpClient(routingContext, context), context);
MultipleRecordsFetchClient holdingsRecordFetchClient = createHoldingsRecordsFetchClient(holdingsStorageClient);
holdingsRecordFetchClient.find(holdingsRecordsIdsToUpdate, this::fetchByIdCql).thenAccept(jsons -> {
List<HoldingsRecord> holdingsRecordsToUpdate = updateInstanceIdForHoldings(toInstanceId, jsons);
updateHoldings(routingContext, context, holdingsRecordsIdsToUpdate, holdingsRecordsToUpdate);
}).exceptionally(e -> {
ServerErrorResponse.internalError(routingContext.response(), e);
return null;
});
} catch (Exception e) {
ServerErrorResponse.internalError(routingContext.response(), e);
}
}).exceptionally(e -> {
ServerErrorResponse.internalError(routingContext.response(), e);
return null;
});
}
Aggregations