diff --git a/NEWS.md b/NEWS.md index 4ba4ba6f5..99a4158a5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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)) diff --git a/src/main/java/org/folio/inventory/resources/Items.java b/src/main/java/org/folio/inventory/resources/Items.java index 977dcec8b..17c1ac4a4 100644 --- a/src/main/java/org/folio/inventory/resources/Items.java +++ b/src/main/java/org/folio/inventory/resources/Items.java @@ -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 -> { @@ -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 -> { diff --git a/src/main/java/org/folio/inventory/storage/external/CollectionResourceClient.java b/src/main/java/org/folio/inventory/storage/external/CollectionResourceClient.java index 39d748917..d57ad77ab 100644 --- a/src/main/java/org/folio/inventory/storage/external/CollectionResourceClient.java +++ b/src/main/java/org/folio/inventory/storage/external/CollectionResourceClient.java @@ -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 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. * diff --git a/src/test/java/support/fakes/FakeStorageModule.java b/src/test/java/support/fakes/FakeStorageModule.java index 84e20583b..c60495492 100644 --- a/src/test/java/support/fakes/FakeStorageModule.java +++ b/src/test/java/support/fakes/FakeStorageModule.java @@ -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); @@ -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 resourcesForTenant = getResourcesForTenant(context); + + List filteredItems = new FakeCQLToJSONInterpreter(false) + .execute(resourcesForTenant.values(), query); + + List 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);