Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODINV-943 Retrieve at least 500 item records #728

Merged
merged 7 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Remove null values from electronicAccess object before returning item and instance [MODINV-1006](https://folio-org.atlassian.net/browse/MODINV-1006)
* 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)
* 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