use of org.folio.circulation.domain.MultipleRecords in project mod-circulation by folio-org.
the class MoreThanOneLoanValidatorTests method allowSingleLoan.
@Test
void allowSingleLoan() {
final MoreThanOneLoanValidator validator = new MoreThanOneLoanValidator(() -> new ServerErrorFailure("More than one loan"));
final Result<MultipleRecords<Loan>> multipleLoans = multipleLoansResult(generateLoan());
final Result<MultipleRecords<Loan>> result = validator.failWhenMoreThanOneLoan(multipleLoans);
assertThat(result.succeeded(), is(true));
}
use of org.folio.circulation.domain.MultipleRecords in project mod-circulation by folio-org.
the class MoreThanOneLoanValidatorTests method failWhenMoreThanOneLoan.
@Test
void failWhenMoreThanOneLoan() {
final MoreThanOneLoanValidator validator = new MoreThanOneLoanValidator(() -> new ServerErrorFailure("More than one loan"));
final Result<MultipleRecords<Loan>> multipleLoans = multipleLoansResult(generateLoan(), generateLoan());
final Result<MultipleRecords<Loan>> result = validator.failWhenMoreThanOneLoan(multipleLoans);
assertThat(result, isErrorFailureContaining("More than one loan"));
}
use of org.folio.circulation.domain.MultipleRecords in project mod-circulation by folio-org.
the class RequestQueueResource method getQueue.
private void getQueue(RoutingContext routingContext, RequestQueueType requestQueueType) {
final var context = new WebContext(routingContext);
final var clients = Clients.create(context, client);
final var itemRepository = new ItemRepository(clients);
final var userRepository = new UserRepository(clients);
final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
final var requestQueueRepository = new RequestQueueRepository(RequestRepository.using(clients, itemRepository, userRepository, loanRepository));
final RequestRepresentation requestRepresentation = new RequestRepresentation();
CompletableFuture<Result<RequestQueue>> requestQueue = getRequestQueueByType(routingContext, requestQueueType, requestQueueRepository);
requestQueue.thenApply(r -> r.map(queue -> new MultipleRecords<>(queue.getRequests(), queue.size()))).thenApply(r -> r.map(requests -> requests.asJson(requestRepresentation::extendedRepresentation, "requests"))).thenApply(r -> r.map(JsonHttpResponse::ok)).thenAccept(context::writeResultToHttpResponse);
}
use of org.folio.circulation.domain.MultipleRecords 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()));
}));
}
use of org.folio.circulation.domain.MultipleRecords in project mod-circulation by folio-org.
the class RequestQueueTests method canFetchTheRequestQueueForAnItem.
@Test
void canFetchTheRequestQueueForAnItem() {
IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
IndividualResource james = usersFixture.james();
IndividualResource jessica = usersFixture.jessica();
IndividualResource steve = usersFixture.steve();
IndividualResource charlotte = usersFixture.charlotte();
IndividualResource rebecca = usersFixture.rebecca();
checkOutFixture.checkOutByBarcode(smallAngryPlanet, james);
IndividualResource requestByJessica = requestsFixture.placeItemLevelHoldShelfRequest(smallAngryPlanet, jessica, ZonedDateTime.of(2017, 7, 22, 10, 22, 54, 0, UTC));
IndividualResource requestBySteve = requestsFixture.placeItemLevelHoldShelfRequest(smallAngryPlanet, steve, ZonedDateTime.of(2017, 10, 27, 11, 54, 37, 0, UTC));
IndividualResource requestByCharlotte = requestsFixture.placeItemLevelHoldShelfRequest(smallAngryPlanet, charlotte, ZonedDateTime.of(2018, 1, 10, 15, 34, 21, 0, UTC));
IndividualResource requestByRebecca = requestsFixture.placeItemLevelHoldShelfRequest(smallAngryPlanet, rebecca, ZonedDateTime.of(2018, 2, 4, 7, 4, 53, 0, UTC));
MultipleRecords<JsonObject> queue = requestsFixture.getQueueFor(smallAngryPlanet);
// Correct size
assertThat(queue.getTotalRecords(), is(4));
assertThat(queue.getRecords().size(), is(4));
final List<Integer> positions = queue.getRecords().stream().map(request -> request.getInteger("position")).collect(Collectors.toList());
// In position order
assertThat(positions, contains(1, 2, 3, 4));
// Correct requests
final List<UUID> ids = queue.getRecords().stream().map(request -> request.getString("id")).map(UUID::fromString).collect(Collectors.toList());
// In position order
assertThat(ids, contains(requestByJessica.getId(), requestBySteve.getId(), requestByCharlotte.getId(), requestByRebecca.getId()));
// Has extended item properties
queue.getRecords().forEach(request -> {
assertThat(String.format("request has an item summary: %s", request.encodePrettily()), request.containsKey("item"), is(true));
JsonObject item = request.getJsonObject("item");
assertThat(String.format("item summary has not a holdings record ID: %s", request.encodePrettily()), item.containsKey("holdingsRecordId"), is(false));
assertThat(String.format("item summary has an instance ID: %s", request.encodePrettily()), request.containsKey("instanceId"), is(true));
assertThat(String.format("item summary has a location: %s", request.encodePrettily()), item.containsKey("location"), is(true));
JsonObject location = item.getJsonObject("location");
assertThat(String.format("location has a name: %s", request.encodePrettily()), location.containsKey("name"), is(true));
});
}
Aggregations