Skip to content

Commit

Permalink
MODINV-943 Retrieve at least 500 item records
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrokrutii authored Jun 5, 2024
1 parent c3699f8 commit 39bc88a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* 422 Unprocessable Content Error while updating Instances and Items with electronic access without URI field populated. [MODINV-1024](https://folio-org.atlassian.net/browse/MODINV-1024)
* Error appears when edit via quickMARC MARC Instance shared from Member tenant [MODDATAIMP-1052](https://folio-org.atlassian.net/browse/MODDATAIMP-1052)
* Fix mod-inventory OOM issue [MODINV-1023](https://folio-org.atlassian.net/browse/MODINV-1023)
* Replace GET with POST request for fetching instances and holdings on /items endpoint to omit 414 error [MODINV-943](https://folio-org.atlassian.net/browse/MODINV-943)

## 20.2.0 2023-03-20
* Inventory cannot process Holdings with virtual fields ([MODINV-941](https://issues.folio.org/browse/MODINV-941))
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/folio/inventory/resources/Items.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ protected void respondWithManyItems(

String holdingsQuery = multipleRecordsCqlQuery(holdingsIds);

holdingsClient.getMany(holdingsQuery, holdingsIds.size(), 0,
holdingsClient.retrieveMany(holdingsQuery, holdingsIds.size(), 0,
holdingsFetched::complete);

holdingsFetched.thenAccept(holdingsResponse -> {
Expand All @@ -366,7 +366,7 @@ protected void respondWithManyItems(

String instancesQuery = multipleRecordsCqlQuery(instanceIds);

instancesClient.getMany(instancesQuery, instanceIds.size(), 0,
instancesClient.retrieveMany(instancesQuery, instanceIds.size(), 0,
instancesFetched::complete);

instancesFetched.thenAccept(instancesResponse -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ public void getMany(
.thenAccept(responseHandler);
}

/**
* Run the query using some limit and offset.
*
* @param cqlQuery the query without percent (url) encoding
*/
public void retrieveMany(
String cqlQuery,
Integer pageLimit,
Integer pageOffset,
Consumer<Response> responseHandler) {
var body = new JsonObject()
.put("query", cqlQuery)
.put("limit", pageLimit)
.put("offset", pageOffset);
var url = collectionRoot + "/retrieve";
client.post(url, body)
.thenAccept(responseHandler);
}

/**
* Runs the query while setting limit to maximum and offset to zero to get all records.
*
Expand Down
32 changes: 32 additions & 0 deletions src/test/java/support/fakes/FakeStorageModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void register(Router router) {
router.route(pathTree).handler(this::emulateFailureIfNeeded);
router.route(pathTree).handler(this::checkTokenHeader);

router.post(rootPath + "/retrieve").handler(this::retrieveMany);
router.post(rootPath).handler(this::checkRequiredProperties);
router.post(rootPath).handler(this::checkUniqueProperties);
router.post(rootPath + "/emulate-failure").handler(this::emulateFailure);
Expand Down Expand Up @@ -266,6 +267,37 @@ private void getMany(RoutingContext routingContext) {
JsonResponse.success(routingContext.response(), result);
}

private void retrieveMany(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);
var requestBody = routingContext.getBodyAsJson();

var limit = requestBody.getInteger("limit");
var offset = requestBody.getInteger("offset");
var query = requestBody.getString("query");;

System.out.printf("Handling %s%n", routingContext.request().uri());

Map<String, JsonObject> resourcesForTenant = getResourcesForTenant(context);

List<JsonObject> filteredItems = new FakeCQLToJSONInterpreter(false)
.execute(resourcesForTenant.values(), query);

List<JsonObject> pagedItems = filteredItems.stream()
.skip(offset)
.limit(limit)
.collect(Collectors.toList());

JsonObject result = new JsonObject();

result.put(collectionPropertyName, new JsonArray(pagedItems));
result.put("totalRecords", filteredItems.size());

System.out.printf("Found %s resources: %s%n", recordTypeName,
result.encodePrettily());

JsonResponse.success(routingContext.response(), result);
}

private void empty(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);

Expand Down

0 comments on commit 39bc88a

Please sign in to comment.