diff --git a/src/main/java/org/folio/circulation/infrastructure/storage/PrintEventsRepository.java b/src/main/java/org/folio/circulation/infrastructure/storage/PrintEventsRepository.java index 360fcc4552..10ef85e8c3 100644 --- a/src/main/java/org/folio/circulation/infrastructure/storage/PrintEventsRepository.java +++ b/src/main/java/org/folio/circulation/infrastructure/storage/PrintEventsRepository.java @@ -59,6 +59,8 @@ public CompletableFuture>> findPrintEventDetails private CompletableFuture>> fetchAndMapPrintEventDetails( MultipleRecords multipleRequests) { + log.debug("fetchAndMapPrintEventDetails:: parameters multipleRequests: {}", + () -> multipleRecordsAsString(multipleRequests)); var requestIds = multipleRequests.toKeys(Request::getId); if (requestIds.isEmpty()) { return completedFuture(succeeded(multipleRequests)); @@ -88,10 +90,12 @@ private CompletableFuture validatePrintEventFeatureFlag() { private Result> mapPrintEventDetailsToRequest( MultipleRecords printEventDetails, MultipleRecords requests) { - log.info("mapPrintEventDetailsToRequest:: Mapping print event details {} with requests {}", + log.debug("mapPrintEventDetailsToRequest:: Mapping print event details {} with requests {}", () -> multipleRecordsAsString(printEventDetails), () -> multipleRecordsAsString(requests)); Map printEventDetailMap = printEventDetails.toMap(PrintEventDetail::getRequestId); - return of(() -> requests.mapRecords(request -> request.withPrintEventDetail(printEventDetailMap.getOrDefault(request.getId(), null)))); + return of(() -> + requests.mapRecords(request -> request + .withPrintEventDetail(printEventDetailMap.getOrDefault(request.getId(), null)))); } } diff --git a/src/main/java/org/folio/circulation/infrastructure/storage/requests/RequestRepository.java b/src/main/java/org/folio/circulation/infrastructure/storage/requests/RequestRepository.java index 9f85a9fb53..c17aa06dc5 100644 --- a/src/main/java/org/folio/circulation/infrastructure/storage/requests/RequestRepository.java +++ b/src/main/java/org/folio/circulation/infrastructure/storage/requests/RequestRepository.java @@ -125,8 +125,8 @@ public static RequestRepository using( public CompletableFuture>> findBy(String query) { return requestsStorageClient.getManyWithRawQueryStringParameters(query) .thenApply(flatMapResult(this::mapResponseToRequests)) - .thenCompose(r -> r.after(this::fetchAdditionalFields)) - .thenCompose(r -> r.after(this::fetchPrintEventDetails)); + .thenCompose(r -> r.after(this::fetchPrintEventDetails)) + .thenCompose(r -> r.after(this::fetchAdditionalFields)); } CompletableFuture>> findBy(CqlQuery query, PageLimit pageLimit) { @@ -151,9 +151,10 @@ private CompletableFuture>> fetchAdditionalField private CompletableFuture>> fetchPrintEventDetails( MultipleRecords requestRecords) { + log.debug("fetchPrintEventDetails:: Fetching print event details for requestRecords: {}", + ()-> multipleRecordsAsString(requestRecords)); return ofAsync(() -> requestRecords) - .thenComposeAsync(result -> result.after(printEventsRepository::findPrintEventDetails)) - .thenComposeAsync(result -> result.after(userRepository::findUsersForPrintEvents)); + .thenComposeAsync(result -> result.after(printEventsRepository::findPrintEventDetails)); } CompletableFuture>> findByWithoutItems( diff --git a/src/main/java/org/folio/circulation/infrastructure/storage/users/UserRepository.java b/src/main/java/org/folio/circulation/infrastructure/storage/users/UserRepository.java index cae35c4471..8e8256f990 100644 --- a/src/main/java/org/folio/circulation/infrastructure/storage/users/UserRepository.java +++ b/src/main/java/org/folio/circulation/infrastructure/storage/users/UserRepository.java @@ -239,18 +239,6 @@ public CompletableFuture>> findUsersForRequests( matchUsersToRequests(request, multipleUsers))))); } - public CompletableFuture>> findUsersForPrintEvents( - MultipleRecords multipleRequests) { - - log.debug("findUsersForRequests:: parameters multipleRequests: {}", - () -> multipleRecordsAsString(multipleRequests)); - return findUsersForPrintEvents(multipleRequests.getRecords()) - .thenApply(multipleUsersResult -> multipleUsersResult.next( - multipleUsers -> of(() -> - multipleRequests.mapRecords(request -> - matchUsersToPrintEvents(request, multipleUsers))))); - } - public CompletableFuture>> findUsersByRequests( Collection requests) { @@ -261,22 +249,6 @@ public CompletableFuture>> findUsersByRequests( .distinct() .collect(Collectors.toList()); - return fetchUsers(usersToFetch); - } - - public CompletableFuture>> findUsersForPrintEvents( - Collection requests) { - log.debug("findUsersForPrintEvents:: parameters requests: {}", () -> collectionAsString(requests)); - final List usersToFetch = requests.stream() - .filter(request -> request.getPrintEventDetail() != null && request.getPrintEventDetail().getUserId() != null) - .map(request -> request.getPrintEventDetail().getUserId()) - .distinct() - .collect(Collectors.toList()); - - return fetchUsers(usersToFetch); - } - - private CompletableFuture>> fetchUsers(List usersToFetch) { if (usersToFetch.isEmpty()) { log.info("findUsersByRequests:: no users to fetch"); return completedFuture(succeeded(MultipleRecords.empty())); @@ -300,6 +272,10 @@ private ArrayList getUsersFromRequest(Request request) { usersToFetch.add(request.getProxyUserId()); } + if (request.getPrintEventDetail() != null && request.getPrintEventDetail().getUserId() != null) { + usersToFetch.add(request.getPrintEventDetail().getUserId()); + } + return usersToFetch; } @@ -311,16 +287,7 @@ private Request matchUsersToRequests( return request .withRequester(userMap.getOrDefault(request.getUserId(), null)) - .withProxy(userMap.getOrDefault(request.getProxyUserId(), null)); - } - - private Request matchUsersToPrintEvents( - Request request, - MultipleRecords users) { - - final Map userMap = users.toMap(User::getId); - - return request + .withProxy(userMap.getOrDefault(request.getProxyUserId(), null)) .withPrintEventDetail(mapUserToPrintEventDetails(request, userMap)); }