use of org.folio.inventory.common.WebContext in project mod-inventory by folio-org.
the class ItemsByHoldingsRecordId method joinAndRespondWithManyItems.
private void joinAndRespondWithManyItems(RoutingContext routingContext, WebContext webContext, Response boundWithParts, String holdingsRecordId, String relationsParam) {
String itemQuery = "id==(NOOP)";
List<String> itemIds = new ArrayList<>();
boolean onlyBoundWiths = relationsParam != null && (relationsParam.equals(RELATION_PARAM_ONLY_BOUND_WITHS) || relationsParam.equals(RELATION_PARAM_ONLY_BOUND_WITHS_SKIP_DIRECTLY_LINKED_ITEM));
boolean skipDirectlyLinkedItem = relationsParam != null && relationsParam.equals(RELATION_PARAM_ONLY_BOUND_WITHS_SKIP_DIRECTLY_LINKED_ITEM);
JsonObject boundWithPartsJson = boundWithParts.getJson();
JsonArray boundWithPartRecords = boundWithPartsJson.getJsonArray(BOUND_WITH_PARTS_JSON_ARRAY);
itemIds = boundWithPartRecords.stream().map(o -> (JsonObject) o).map(part -> part.getString("itemId")).collect(Collectors.toList());
boolean boundWithsFound = itemIds.size() > 0;
if (boundWithsFound) {
itemQuery = buildQueryByIds(itemIds);
if (skipDirectlyLinkedItem) {
itemQuery += " and holdingsRecordId <>" + holdingsRecordId;
} else if (!onlyBoundWiths) {
itemQuery += " or holdingsRecordId==" + holdingsRecordId;
}
} else {
if (onlyBoundWiths) {
itemQuery = "id==(NOOP)";
} else {
itemQuery = "holdingsRecordId==" + holdingsRecordId;
}
}
try {
storage.getItemCollection(webContext).findByCql(itemQuery, new PagingParameters(1000, 0), success -> respondWithManyItems(routingContext, webContext, success.getResult()), FailureResponseConsumer.serverError(routingContext.response()));
} catch (UnsupportedEncodingException e) {
ServerErrorResponse.internalError(routingContext.response(), e.toString());
}
}
use of org.folio.inventory.common.WebContext in project mod-inventory by folio-org.
the class MoveApi method updateItems.
private void updateItems(RoutingContext routingContext, WebContext context, List<String> idsToUpdate, List<Item> itemsToUpdate) {
ItemCollection storageItemCollection = storage.getItemCollection(context);
List<CompletableFuture<Item>> updates = itemsToUpdate.stream().map(storageItemCollection::update).collect(Collectors.toList());
CompletableFuture.allOf(updates.toArray(new CompletableFuture[0])).handle((vVoid, throwable) -> updates.stream().filter(future -> !future.isCompletedExceptionally()).map(CompletableFuture::join).map(Item::getId).collect(toList())).thenAccept(updatedIds -> respond(routingContext, idsToUpdate, updatedIds));
}
use of org.folio.inventory.common.WebContext in project mod-inventory by folio-org.
the class MoveApi method updateHoldings.
private void updateHoldings(RoutingContext routingContext, WebContext context, List<String> idsToUpdate, List<HoldingsRecord> holdingsToUpdate) {
HoldingsRecordCollection storageHoldingsRecordsCollection = storage.getHoldingsRecordCollection(context);
List<CompletableFuture<HoldingsRecord>> updateFutures = holdingsToUpdate.stream().map(storageHoldingsRecordsCollection::update).collect(Collectors.toList());
CompletableFuture.allOf(updateFutures.toArray(new CompletableFuture[0])).handle((vVoid, throwable) -> updateFutures.stream().filter(future -> !future.isCompletedExceptionally()).map(CompletableFuture::join).map(HoldingsRecord::getId).collect(toList())).thenAccept(updatedIds -> respond(routingContext, idsToUpdate, updatedIds));
}
use of org.folio.inventory.common.WebContext 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.common.WebContext in project mod-inventory by folio-org.
the class ModsIngestion method status.
private void status(RoutingContext routingContext) {
Context context = new WebContext(routingContext);
storage.getIngestJobCollection(context).findById(routingContext.request().getParam("id"), it -> JsonResponse.success(routingContext.response(), new JsonObject().put("status", it.getResult().state.toString())), FailureResponseConsumer.serverError(routingContext.response()));
}
Aggregations