From 8aa13c5b063821bed5a812aef69b10da73775349 Mon Sep 17 00:00:00 2001 From: Roman_Chernetskyi Date: Tue, 18 Jun 2024 14:59:04 +0300 Subject: [PATCH] Add logs on failures --- .../inventory/resources/UpdateOwnershipApi.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/folio/inventory/resources/UpdateOwnershipApi.java b/src/main/java/org/folio/inventory/resources/UpdateOwnershipApi.java index 0bca384a7..0c7286f3a 100644 --- a/src/main/java/org/folio/inventory/resources/UpdateOwnershipApi.java +++ b/src/main/java/org/folio/inventory/resources/UpdateOwnershipApi.java @@ -185,6 +185,7 @@ private CompletableFuture> createItems(List jsons, List itemCollection.add(item) .exceptionally(e -> { + LOGGER.warn("createHoldings:: Error during creating item with id: {} for holdingsRecord with id: {}", item.getId(), item.getHoldingId(), e); notUpdatedEntities.add(new NotUpdatedEntity().withEntityId(item.getHoldingId()).withErrorMessage(e.getMessage())); throw new CompletionException(e); })) @@ -209,6 +210,7 @@ private CompletableFuture> createHoldings(List .map(holdingRecord -> holdingsRecordCollection.add(holdingRecord) .exceptionally(e -> { + LOGGER.warn("createHoldings:: Error during creating holdingsRecord with id: {}", holdingRecord.getId(), e); notUpdatedEntities.add(new NotUpdatedEntity().withEntityId(holdingRecord.getId()).withErrorMessage(e.getMessage())); throw new CompletionException(e); })) @@ -228,6 +230,9 @@ private CompletableFuture> deleteHoldings(List hold Promise promise = Promise.promise(); holdingsRecordCollection.delete(holdingsRecord.getId(), success -> promise.complete(holdingsRecord.getId()), failure -> { + LOGGER.warn("deleteHoldings:: Error during deleting holdingsRecord with id: {}, status code: {}, reason: {}", + holdingsRecord.getId(), failure.getStatusCode(), failure.getReason()); + notUpdatedEntities.add(new NotUpdatedEntity().withEntityId(holdingsRecord.getId()).withErrorMessage(failure.getReason())); promise.fail(failure.getReason()); }); @@ -247,6 +252,9 @@ private CompletableFuture> deleteItems(List itemIds, List promise = Promise.promise(); itemCollection.delete(item.getId(), success -> promise.complete(item.getId()), failure -> { + LOGGER.warn("deleteItems:: Error during deleting item with id: {} for holdingsRecord with id {}, status code: {}, reason: {}", + item.getId(), item.getHoldingId(), failure.getStatusCode(), failure.getReason()); + notUpdatedEntities.add(new NotUpdatedEntity().withEntityId(item.getHoldingId()).withErrorMessage(failure.getReason())); promise.fail(failure.getReason()); }); @@ -263,8 +271,11 @@ private CompletableFuture> deleteItems(List itemIds, List holdingsRecordIds, List notUpdatedEntities, WebContext context, List jsons) { List foundedIds = jsons.stream().map(json -> json.getString("id")).toList(); List notFoundedIds = ListUtils.subtract(holdingsRecordIds, foundedIds); - notFoundedIds.forEach(id -> - notUpdatedEntities.add(new NotUpdatedEntity().withEntityId(id).withErrorMessage(String.format(INSTANCE_NOT_FOUND, id, context.getTenantId())))); + notFoundedIds.forEach(id -> { + String errorMessage = String.format(INSTANCE_NOT_FOUND, id, context.getTenantId()); + LOGGER.warn("processNotFoundedInstances:: " + errorMessage); + notUpdatedEntities.add(new NotUpdatedEntity().withEntityId(id).withErrorMessage(errorMessage)); + }); } private List getHoldingsToDelete(List notUpdatedEntities, List createdHoldings) {