Skip to content

Commit

Permalink
[MODINVSTOR-1243] Add tenantId to items
Browse files Browse the repository at this point in the history
  • Loading branch information
Saba-Zedginidze-EPAM committed Aug 27, 2024
1 parent d135a4e commit a61fc63
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/main/java/org/folio/inventory/resources/TenantItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class TenantItems {
private static final String TENANT_ITEMS_PATH = "/inventory/tenant-items";
public static final String ITEMS_FIELD = "items";
public static final String TOTAL_RECORDS_FIELD = "totalRecords";
public static final String TENANT_ID_FIELD = "tenantId";

private final HttpClient client;

Expand Down Expand Up @@ -76,7 +77,7 @@ private void getItemsFromTenants(RoutingContext routingContext) {
}

private CompletableFuture<List<JsonObject>> getItemsWithTenantId(String tenantId, List<String> itemIds, RoutingContext routingContext) {
log.info("getItemsWithTenantId:: Fetching items - [{}] from tenant - {}", itemIds, tenantId);
log.info("getItemsWithTenantId:: Fetching items - {} from tenant - {}", itemIds, tenantId);
var context = new WebContext(routingContext);
CollectionResourceClient itemsStorageClient;
try {
Expand All @@ -93,9 +94,16 @@ private CompletableFuture<List<JsonObject>> getItemsWithTenantId(String tenantId
itemsStorageClient.getAll(getByIdsQuery, itemsFetched::complete);

return itemsFetched.thenApplyAsync(response ->
response.getStatusCode() == 200 && response.hasBody()
? JsonArrayHelper.toList(response.getJson(), ITEMS_FIELD)
: List.of());
getItemsWithTenantId(tenantId, response));
}

private List<JsonObject> getItemsWithTenantId(String tenantId, Response response) {
if (response.getStatusCode() == 200 && response.hasBody()) {
return List.of();
}
return JsonArrayHelper.toList(response.getJson(), ITEMS_FIELD).stream()
.map(item -> item.put(TENANT_ID_FIELD, tenantId))
.toList();
}

private JsonObject constructResponse(List<JsonObject> items) {
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/api/items/TenantItemApiTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static api.support.InstanceSamples.smallAngryPlanet;
import static org.assertj.core.api.Assertions.assertThat;
import static org.folio.inventory.resources.TenantItems.ITEMS_FIELD;
import static org.folio.inventory.resources.TenantItems.TENANT_ID_FIELD;
import static org.folio.inventory.resources.TenantItems.TOTAL_RECORDS_FIELD;
import static org.folio.inventory.support.ItemUtil.ID;

Expand Down Expand Up @@ -58,6 +59,8 @@ public void testTenantItemsGetFromDifferentTenants() throws MalformedURLExceptio
.toCompletableFuture().get(5, TimeUnit.SECONDS);
assertThat(response.getStatusCode()).isEqualTo(200);

consortiumItem.put(TENANT_ID_FIELD, CONSORTIA_TENANT_ID);
collegeItem.put(TENANT_ID_FIELD, COLLEGE_TENANT_ID);
var items = extractItems(response, 2);
assertThat(items).contains(consortiumItem, collegeItem);
}
Expand Down

0 comments on commit a61fc63

Please sign in to comment.