use of org.folio.inventory.common.api.request.PagingParameters 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.api.request.PagingParameters in project mod-inventory by folio-org.
the class ExternalItemCollectionExamples method allItemsCanBePaged.
@Test
public void allItemsCanBePaged() throws InterruptedException, ExecutionException, TimeoutException {
WaitForAllFutures<Item> allAdded = new WaitForAllFutures<>();
collection.add(smallAngryPlanet, allAdded.notifySuccess(), v -> {
});
collection.add(nod, allAdded.notifySuccess(), v -> {
});
collection.add(uprooted, allAdded.notifySuccess(), v -> {
});
collection.add(temeraire, allAdded.notifySuccess(), v -> {
});
collection.add(interestingTimes, allAdded.notifySuccess(), v -> {
});
allAdded.waitForCompletion();
CompletableFuture<MultipleRecords<Item>> firstPageFuture = new CompletableFuture<>();
CompletableFuture<MultipleRecords<Item>> secondPageFuture = new CompletableFuture<>();
collection.findAll(new PagingParameters(3, 0), succeed(firstPageFuture), fail(secondPageFuture));
collection.findAll(new PagingParameters(3, 3), succeed(secondPageFuture), fail(secondPageFuture));
MultipleRecords<Item> firstPage = getOnCompletion(firstPageFuture);
MultipleRecords<Item> secondPage = getOnCompletion(secondPageFuture);
assertThat(firstPage.records.size(), is(3));
assertThat(secondPage.records.size(), is(2));
assertThat(firstPage.totalRecords, is(5));
assertThat(secondPage.totalRecords, is(5));
}
use of org.folio.inventory.common.api.request.PagingParameters in project mod-inventory by folio-org.
the class ExternalItemCollectionExamples method itemsCanBeFoundByBarcode.
@Test
public void itemsCanBeFoundByBarcode() throws InterruptedException, ExecutionException, TimeoutException, UnsupportedEncodingException {
CompletableFuture<Item> firstAddFuture = new CompletableFuture<>();
CompletableFuture<Item> secondAddFuture = new CompletableFuture<>();
CompletableFuture<Item> thirdAddFuture = new CompletableFuture<>();
collection.add(smallAngryPlanet, succeed(firstAddFuture), fail(firstAddFuture));
collection.add(nod, succeed(secondAddFuture), fail(secondAddFuture));
collection.add(uprooted, succeed(thirdAddFuture), fail(thirdAddFuture));
CompletableFuture<Void> allAddsFuture = CompletableFuture.allOf(firstAddFuture, secondAddFuture, thirdAddFuture);
getOnCompletion(allAddsFuture);
Item addedSmallAngryPlanet = getOnCompletion(firstAddFuture);
CompletableFuture<MultipleRecords<Item>> findFuture = new CompletableFuture<>();
collection.findByCql("barcode==036000291452", new PagingParameters(10, 0), succeed(findFuture), fail(findFuture));
MultipleRecords<Item> wrappedItems = getOnCompletion(findFuture);
assertThat(wrappedItems.records.size(), is(1));
assertThat(wrappedItems.totalRecords, is(1));
assertThat(wrappedItems.records.stream().findFirst().get().id, is(addedSmallAngryPlanet.id));
}
use of org.folio.inventory.common.api.request.PagingParameters in project mod-inventory by folio-org.
the class ExternalInstanceCollectionFailureExamples method serverErrorWhenFindingItemsTriggersFailureCallback.
@Test
public void serverErrorWhenFindingItemsTriggersFailureCallback() throws InterruptedException, ExecutionException, TimeoutException, UnsupportedEncodingException {
InstanceCollection collection = createCollection();
CompletableFuture<Failure> failureCalled = new CompletableFuture<>();
collection.findByCql("title=\"*Small Angry*\"", new PagingParameters(10, 0), success -> fail("Completion callback should not be called"), failureCalled::complete);
Failure failure = failureCalled.get(1000, TimeUnit.MILLISECONDS);
check(failure);
}
use of org.folio.inventory.common.api.request.PagingParameters in project mod-inventory by folio-org.
the class Instances method getAll.
private void getAll(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);
String search = context.getStringParameter("query", null);
PagingParameters pagingParameters = PagingParameters.from(context);
if (pagingParameters == null) {
ClientErrorResponse.badRequest(routingContext.response(), "limit and offset must be numeric when supplied");
return;
}
if (search == null) {
storage.getInstanceCollection(context).findAll(pagingParameters, (Success<MultipleRecords<Instance>> success) -> makeInstancesResponse(success, routingContext, context), FailureResponseConsumer.serverError(routingContext.response()));
} else {
try {
storage.getInstanceCollection(context).findByCql(search, pagingParameters, success -> makeInstancesResponse(success, routingContext, context), FailureResponseConsumer.serverError(routingContext.response()));
} catch (UnsupportedEncodingException e) {
ServerErrorResponse.internalError(routingContext.response(), e.toString());
}
}
}
Aggregations