use of org.folio.circulation.domain.Instance in project mod-circulation by folio-org.
the class InstanceRepository method findInstancesForRequests.
public CompletableFuture<Result<MultipleRecords<Request>>> findInstancesForRequests(MultipleRecords<Request> multipleRequests) {
Collection<Request> requests = multipleRequests.getRecords();
final List<String> instanceIdsToFetch = requests.stream().filter(Objects::nonNull).map(Request::getInstanceId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
if (instanceIdsToFetch.isEmpty()) {
log.info("No instance ids to query");
return completedFuture(succeeded(multipleRequests));
}
InstanceMapper mapper = new InstanceMapper();
return findWithMultipleCqlIndexValues(instancesClient, "instances", mapper::toDomain).findByIds(instanceIdsToFetch).thenApply(multipleInstancesResult -> multipleInstancesResult.next(multipleInstances -> {
List<Request> newRequestList = requests.stream().map(getRequestMapper(multipleInstances)).collect(Collectors.toList());
return succeeded(new MultipleRecords<>(newRequestList, multipleRequests.getTotalRecords()));
}));
}
Aggregations