Search in sources :

Example 1 with Instance

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()));
    }));
}
Also used : Clients(org.folio.circulation.support.Clients) RecordFetching.findWithMultipleCqlIndexValues(org.folio.circulation.support.fetching.RecordFetching.findWithMultipleCqlIndexValues) MultipleRecords(org.folio.circulation.domain.MultipleRecords) InstanceMapper(org.folio.circulation.storage.mappers.InstanceMapper) SingleRecordFetcher(org.folio.circulation.support.SingleRecordFetcher) Predicate(java.util.function.Predicate) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) Request(org.folio.circulation.domain.Request) CompletableFuture(java.util.concurrent.CompletableFuture) CollectionResourceClient(org.folio.circulation.support.CollectionResourceClient) Result(org.folio.circulation.support.results.Result) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Instance(org.folio.circulation.domain.Instance) LogManager(org.apache.logging.log4j.LogManager) MultipleRecords(org.folio.circulation.domain.MultipleRecords) Request(org.folio.circulation.domain.Request) Objects(java.util.Objects) InstanceMapper(org.folio.circulation.storage.mappers.InstanceMapper) List(java.util.List)

Aggregations

MethodHandles (java.lang.invoke.MethodHandles)1 Collection (java.util.Collection)1 List (java.util.List)1 Objects (java.util.Objects)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Instance (org.folio.circulation.domain.Instance)1 MultipleRecords (org.folio.circulation.domain.MultipleRecords)1 Request (org.folio.circulation.domain.Request)1 InstanceMapper (org.folio.circulation.storage.mappers.InstanceMapper)1 Clients (org.folio.circulation.support.Clients)1 CollectionResourceClient (org.folio.circulation.support.CollectionResourceClient)1 SingleRecordFetcher (org.folio.circulation.support.SingleRecordFetcher)1 RecordFetching.findWithMultipleCqlIndexValues (org.folio.circulation.support.fetching.RecordFetching.findWithMultipleCqlIndexValues)1 Result (org.folio.circulation.support.results.Result)1