From 0604721935af3233ae6ec21bb3e82a4bddf7b9c9 Mon Sep 17 00:00:00 2001 From: saba_zedginidze Date: Fri, 13 Sep 2024 18:14:01 +0400 Subject: [PATCH] [MODORDERS-1174] Fix incorrect url and unnecessary filtering --- src/main/java/org/folio/helper/BindHelper.java | 2 +- .../folio/helper/CheckinReceivePiecesHelper.java | 2 +- .../folio/orders/utils/ResourcePathResolver.java | 4 +++- .../ConsortiumUserTenantsRetriever.java | 5 +++-- .../service/orders/HoldingsSummaryService.java | 2 +- .../folio/service/pieces/PieceStorageService.java | 15 ++++++++++----- .../inventory/HoldingsSummaryServiceTest.java | 2 +- .../service/pieces/PieceStorageServiceTest.java | 6 +++--- 8 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/folio/helper/BindHelper.java b/src/main/java/org/folio/helper/BindHelper.java index 332da4ad8..14b2076ff 100644 --- a/src/main/java/org/folio/helper/BindHelper.java +++ b/src/main/java/org/folio/helper/BindHelper.java @@ -93,7 +93,7 @@ private Future removeForbiddenEntities(Piece piece, RequestContext request private Future clearTitleBindItemsIfNeeded(String titleId, String bindItemId, RequestContext requestContext) { String query = String.format("titleId==%s and bindItemId==%s and isBound==true", titleId, bindItemId); - return pieceStorageService.getPieces(0, 0, query, requestContext) + return pieceStorageService.getAllPieces(query, requestContext) .compose(pieceCollection -> { var totalRecords = pieceCollection.getTotalRecords(); if (totalRecords != 0) { diff --git a/src/main/java/org/folio/helper/CheckinReceivePiecesHelper.java b/src/main/java/org/folio/helper/CheckinReceivePiecesHelper.java index 40da3a97d..0429f3f9d 100644 --- a/src/main/java/org/folio/helper/CheckinReceivePiecesHelper.java +++ b/src/main/java/org/folio/helper/CheckinReceivePiecesHelper.java @@ -377,7 +377,7 @@ private List getSuccessfullyProcessedPieces(String poLineId, Map> getPiecesByPoLine(String poLineId, RequestContext requestContext) { String query = String.format("poLineId==%s", poLineId); - return pieceStorageService.getPieces(Integer.MAX_VALUE, 0, query, requestContext) + return pieceStorageService.getAllPieces(query, requestContext) .map(PieceCollection::getPieces); } diff --git a/src/main/java/org/folio/orders/utils/ResourcePathResolver.java b/src/main/java/org/folio/orders/utils/ResourcePathResolver.java index 520b8d846..376049038 100644 --- a/src/main/java/org/folio/orders/utils/ResourcePathResolver.java +++ b/src/main/java/org/folio/orders/utils/ResourcePathResolver.java @@ -5,6 +5,8 @@ import java.util.Map; import java.util.stream.Collectors; +import static org.folio.rest.RestConstants.PATH_PARAM_PLACE_HOLDER; + public class ResourcePathResolver { private ResourcePathResolver() { @@ -98,7 +100,7 @@ private ResourcePathResolver() { apis.put(EXPORT_HISTORY, "/orders-storage/export-history"); apis.put(TAGS, "/tags"); apis.put(USERS, "/users"); - apis.put(CONSORTIA_USER_TENANTS, "/consortia/:id/user-tenants"); + apis.put(CONSORTIA_USER_TENANTS, "/consortia/" + PATH_PARAM_PLACE_HOLDER + "/user-tenants"); apis.put(ORDER_SETTINGS, "/orders-storage/settings"); apis.put(ROUTING_LISTS, "/orders-storage/routing-lists"); diff --git a/src/main/java/org/folio/service/consortium/ConsortiumUserTenantsRetriever.java b/src/main/java/org/folio/service/consortium/ConsortiumUserTenantsRetriever.java index b69b98fda..292b8c0e4 100644 --- a/src/main/java/org/folio/service/consortium/ConsortiumUserTenantsRetriever.java +++ b/src/main/java/org/folio/service/consortium/ConsortiumUserTenantsRetriever.java @@ -12,6 +12,7 @@ import static org.folio.orders.utils.RequestContextUtil.getUserIdFromContext; import static org.folio.orders.utils.ResourcePathResolver.CONSORTIA_USER_TENANTS; import static org.folio.orders.utils.ResourcePathResolver.resourcesPath; +import static org.folio.rest.RestConstants.PATH_PARAM_PLACE_HOLDER; import static org.folio.service.pieces.util.UserTenantFields.COLLECTION_USER_TENANTS; import static org.folio.service.pieces.util.UserTenantFields.TENANT_ID; import static org.folio.service.pieces.util.UserTenantFields.USER_ID; @@ -28,10 +29,10 @@ public ConsortiumUserTenantsRetriever(RestClient restClient) { public Future> getUserTenants(String consortiumId, RequestContext requestContext) { var userId = getUserIdFromContext(requestContext); - var requestEntry = new RequestEntry(CONSORTIA_USER_TENANTS_ENDPOINT) + var url = CONSORTIA_USER_TENANTS_ENDPOINT.replace(PATH_PARAM_PLACE_HOLDER, consortiumId); + var requestEntry = new RequestEntry(url) .withOffset(0) .withLimit(Integer.MAX_VALUE) - .withId(consortiumId) .withQueryParameter(USER_ID.getValue(), userId); return restClient.getAsJsonObject(requestEntry, requestContext) .map(this::extractTenantIds); diff --git a/src/main/java/org/folio/service/orders/HoldingsSummaryService.java b/src/main/java/org/folio/service/orders/HoldingsSummaryService.java index 19b999c95..225e62367 100644 --- a/src/main/java/org/folio/service/orders/HoldingsSummaryService.java +++ b/src/main/java/org/folio/service/orders/HoldingsSummaryService.java @@ -37,7 +37,7 @@ public Future getHoldingsSummary(String holdingId, Req var queryForPiece = String.format("?query=holdingId==%s", holdingId); var queryForLines = String.format("?query=locations=\"holdingId\" : \"%s\"", holdingId); - return pieceStorageService.getPieces(Integer.MAX_VALUE, 0, queryForPiece, requestContext) + return pieceStorageService.getAllPieces(queryForPiece, requestContext) .map(piecesCollection -> { Set lineIds = piecesCollection.getPieces().stream() .map(Piece::getPoLineId) diff --git a/src/main/java/org/folio/service/pieces/PieceStorageService.java b/src/main/java/org/folio/service/pieces/PieceStorageService.java index c67194e0f..b815d337d 100644 --- a/src/main/java/org/folio/service/pieces/PieceStorageService.java +++ b/src/main/java/org/folio/service/pieces/PieceStorageService.java @@ -107,22 +107,27 @@ public Future deletePiecesByIds(List pieceIds, RequestContext requ public Future getExpectedPiecesByLineId(String poLineId, RequestContext requestContext) { String query = String.format(PIECES_BY_POL_ID_AND_STATUS_QUERY, poLineId, Piece.ReceivingStatus.EXPECTED.value()); - return getPieces(Integer.MAX_VALUE, 0, query, requestContext); + return getAllPieces(query, requestContext); } public Future> getPiecesByHoldingId(String holdingId, RequestContext requestContext) { if (holdingId != null) { String query = String.format(PIECES_BY_HOLDING_ID_QUERY, holdingId); - return getPieces(Integer.MAX_VALUE, 0, query, requestContext).map(PieceCollection::getPieces); + return getAllPieces(query, requestContext).map(PieceCollection::getPieces); } return Future.succeededFuture(Collections.emptyList()); } + public Future getAllPieces(String query, RequestContext requestContext) { + var requestEntry = new RequestEntry(PIECE_STORAGE_ENDPOINT).withQuery(query).withOffset(0).withLimit(Integer.MAX_VALUE); + return restClient.get(requestEntry, PieceCollection.class, requestContext); + } + public Future getPieces(int limit, int offset, String query, RequestContext requestContext) { var requestEntry = new RequestEntry(PIECE_STORAGE_ENDPOINT).withQuery(query).withOffset(offset).withLimit(limit); return restClient.get(requestEntry, PieceCollection.class, requestContext) - .compose(piecesCollection -> filterPiecesByUserTenantsIfNecessary(piecesCollection.getPieces(), requestContext)) - .map(pieces -> new PieceCollection().withPieces(pieces).withTotalRecords(pieces.size())); + .compose(piecesCollection -> filterPiecesByUserTenantsIfNecessary(piecesCollection.getPieces(), requestContext) + .map(piecesCollection::withPieces)); } private Future> filterPiecesByUserTenantsIfNecessary(List pieces, RequestContext requestContext) { @@ -145,7 +150,7 @@ public Future> getPiecesByIds(List pieceIds, RequestContext logger.debug("getPiecesByIds:: start to retrieving pieces by ids: {}", pieceIds); var futures = ofSubLists(new ArrayList<>(pieceIds), MAX_IDS_FOR_GET_RQ_15) .map(HelperUtils::convertIdsToCqlQuery) - .map(query -> getPieces(Integer.MAX_VALUE, 0, query, requestContext)) + .map(query -> getAllPieces(query, requestContext)) .toList(); return collectResultsOnSuccess(futures) .map(lists -> lists.stream() diff --git a/src/test/java/org/folio/service/inventory/HoldingsSummaryServiceTest.java b/src/test/java/org/folio/service/inventory/HoldingsSummaryServiceTest.java index dbd65e531..9eef67bbc 100644 --- a/src/test/java/org/folio/service/inventory/HoldingsSummaryServiceTest.java +++ b/src/test/java/org/folio/service/inventory/HoldingsSummaryServiceTest.java @@ -69,7 +69,7 @@ void testGetHoldingSummaryById() throws IOException { when(purchaseOrderLineService.getOrderLines(anyString(), anyInt(), anyInt(), any())) .thenReturn(Future.succeededFuture(polines)); - when(pieceStorageService.getPieces(anyInt(), anyInt(), anyString(), any())) + when(pieceStorageService.getAllPieces(anyString(), any())) .thenReturn(Future.succeededFuture(pieces)); var hs = holdingsSummaryService.getHoldingsSummary(UUID.randomUUID().toString(), requestContext) diff --git a/src/test/java/org/folio/service/pieces/PieceStorageServiceTest.java b/src/test/java/org/folio/service/pieces/PieceStorageServiceTest.java index 233710a5f..f9e3673a5 100644 --- a/src/test/java/org/folio/service/pieces/PieceStorageServiceTest.java +++ b/src/test/java/org/folio/service/pieces/PieceStorageServiceTest.java @@ -126,7 +126,7 @@ void testPiecesShouldBeReturnedByQuery(VertxTestContext vertxTestContext) { when(consortiumConfigurationService.getConsortiumConfiguration(any(RequestContext.class))).thenReturn(Future.succeededFuture(Optional.empty())); String expectedQuery = String.format("id==%s", pieceId); - var future = pieceStorageService.getPieces(Integer.MAX_VALUE, 0, expectedQuery, requestContext); + var future = pieceStorageService.getAllPieces(expectedQuery, requestContext); verify(restClientMock).get(any(RequestEntry.class), eq(PieceCollection.class), eq(requestContext)); vertxTestContext.assertComplete(future) @@ -156,7 +156,7 @@ void testGetPiecesFilterByUserTenants(VertxTestContext vertxTestContext) { doReturn(Future.succeededFuture(piecesMockData)).when(restClientMock).get(any(RequestEntry.class), eq(PieceCollection.class), any(RequestContext.class)); doReturn(Future.succeededFuture(userTenantsMockData)).when(restClientMock).getAsJsonObject(any(), any(RequestContext.class)); - var future = pieceStorageService.getPieces(Integer.MAX_VALUE, 0, null, requestContext); + var future = pieceStorageService.getAllPieces(null, requestContext); verify(restClientMock, times(1)).get(any(RequestEntry.class), eq(PieceCollection.class), eq(requestContext)); verify(restClientMock, times(1)).getAsJsonObject(any(), any(RequestContext.class)); @@ -179,7 +179,7 @@ void testGetPiecesFilterByUserTenantsNonECS(VertxTestContext vertxTestContext) { doReturn(Future.succeededFuture(Optional.empty())).when(consortiumConfigurationService).getConsortiumConfiguration(any(RequestContext.class)); doReturn(Future.succeededFuture(piecesMockData)).when(restClientMock).get(any(RequestEntry.class), eq(PieceCollection.class), any(RequestContext.class)); - var future = pieceStorageService.getPieces(Integer.MAX_VALUE, 0, null, requestContext); + var future = pieceStorageService.getAllPieces(null, requestContext); verify(restClientMock, times(1)).get(any(RequestEntry.class), eq(PieceCollection.class), eq(requestContext)); verify(restClientMock, times(0)).getAsJsonObject(any(), any(RequestContext.class));