Skip to content

Commit

Permalink
[MODORDERS-1209]. Fix handleGetPieces
Browse files Browse the repository at this point in the history
  • Loading branch information
BKadirkhodjaev committed Dec 4, 2024
1 parent da0fe05 commit e304b31
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private Future<Map<String, List<String>>> groupPieceIdsByVendorId(List<String> p
logger.info("groupPieceIdsByVendorId:: No pieces are grouped by vendor, pieceIds is empty");
return Future.succeededFuture();
}
logger.info("groupPieceIdsByVendorId:: Grouping pieces by vendor");
return pieceStorageService.getPiecesByIds(pieceIds, requestContext)
.compose(pieces -> {
var uniquePiecePoLinePairs = pieces.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public Future<PieceCollection> getAllPieces(String query, RequestContext request
}

public Future<PieceCollection> getAllPieces(int limit, int offset, String query, RequestContext requestContext) {
log.info("getAllPieces:: limit: {}, offset: {}, query: {}", limit, offset, query);
var requestEntry = new RequestEntry(PIECE_STORAGE_ENDPOINT).withQuery(query).withOffset(offset).withLimit(limit);
return restClient.get(requestEntry, PieceCollection.class, requestContext);
}
Expand All @@ -155,7 +156,7 @@ private Future<List<String>> getUserTenantsIfNeeded(RequestContext requestContex
}

public Future<List<Piece>> getPiecesByIds(List<String> pieceIds, RequestContext requestContext) {
log.debug("getPiecesByIds:: start to retrieving pieces by ids: {}", pieceIds);
log.info("getPiecesByIds:: start to retrieving pieces by ids: {}", pieceIds);
var futures = ofSubLists(new ArrayList<>(pieceIds), MAX_IDS_FOR_GET_RQ_15)
.map(QueryUtils::convertIdsToCqlQuery)
.map(query -> getAllPieces(query, requestContext))
Expand Down
9 changes: 7 additions & 2 deletions src/test/java/org/folio/rest/impl/MockServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ private Optional<JsonObject> getMockEntry(String objName, String id) {
}

private <T> Optional<List<T>> getMockEntries(String objName, Class<T> tClass) {
List<T> entryList = getRqRsEntries(HttpMethod.SEARCH, objName).stream()
List<T> entryList = getRqRsEntries(HttpMethod.SEARCH, objName).stream()
.map(entries -> entries.mapTo(tClass))
.collect(toList());
return Optional.ofNullable(entryList.isEmpty() ? null : entryList);
Expand Down Expand Up @@ -1937,7 +1937,12 @@ private void handleGetPieces(RoutingContext ctx) {
String requestQuery = ctx.request().getParam("query");
MultiMap requestHeaders = ctx.request().headers();
logger.info("handleGetPieces requestPath: {}, requestQuery: {}, requestHeaders: {}", requestPath, requestQuery, requestHeaders);
if (Objects.nonNull(requestQuery) && requestQuery.contains(ID_FOR_PIECES_INTERNAL_SERVER_ERROR)) {
if (Objects.isNull(requestQuery)) {
logger.info("handleGetPieces (empty requestQuery) requestPath: {}, requestHeaders: {}", requestPath, requestHeaders);
PieceCollection pieces = new PieceCollection().withPieces(new ArrayList<>());
pieces.setTotalRecords(pieces.getPieces().size());
} else
if (requestQuery.contains(ID_FOR_PIECES_INTERNAL_SERVER_ERROR)) {
logger.info("handleGetPieces (with internal server error)");
addServerRqRsData(HttpMethod.GET, PIECES_STORAGE, new JsonObject());
serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
Expand Down

0 comments on commit e304b31

Please sign in to comment.