Search in sources :

Example 1 with MultipleRecords

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));
}
Also used : ServerErrorFailure(org.folio.circulation.support.ServerErrorFailure) MultipleRecords(org.folio.circulation.domain.MultipleRecords) Test(org.junit.jupiter.api.Test)

Example 2 with MultipleRecords

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"));
}
Also used : ServerErrorFailure(org.folio.circulation.support.ServerErrorFailure) MultipleRecords(org.folio.circulation.domain.MultipleRecords) Test(org.junit.jupiter.api.Test)

Example 3 with MultipleRecords

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);
}
Also used : FOR_INSTANCE(org.folio.circulation.resources.context.RequestQueueType.FOR_INSTANCE) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) UpdateRequestQueue(org.folio.circulation.domain.UpdateRequestQueue) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) WebContext(org.folio.circulation.support.http.server.WebContext) Request(org.folio.circulation.domain.Request) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) Router(io.vertx.ext.web.Router) CompletableFuture(java.util.concurrent.CompletableFuture) ValidationErrorFailure.singleValidationError(org.folio.circulation.support.ValidationErrorFailure.singleValidationError) RoutingContext(io.vertx.ext.web.RoutingContext) ReorderRequestContext(org.folio.circulation.resources.context.ReorderRequestContext) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) TlrSettingsConfiguration(org.folio.circulation.domain.configuration.TlrSettingsConfiguration) RequestUpdateLogEventMapper.mapToRequestLogEventJson(org.folio.circulation.domain.representations.logs.RequestUpdateLogEventMapper.mapToRequestLogEventJson) ServicePointRepository(org.folio.circulation.infrastructure.storage.ServicePointRepository) RequestQueueType(org.folio.circulation.resources.context.RequestQueueType) RequestQueueValidation(org.folio.circulation.domain.validation.RequestQueueValidation) JsonObject(io.vertx.core.json.JsonObject) RequestQueue(org.folio.circulation.domain.RequestQueue) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) RequestRepresentation(org.folio.circulation.domain.RequestRepresentation) LogEventType(org.folio.circulation.domain.representations.logs.LogEventType) MultipleRecords(org.folio.circulation.domain.MultipleRecords) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) Result(org.folio.circulation.support.results.Result) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) EventPublisher(org.folio.circulation.services.EventPublisher) FOR_ITEM(org.folio.circulation.resources.context.RequestQueueType.FOR_ITEM) RouteRegistration(org.folio.circulation.support.RouteRegistration) List(java.util.List) ReorderQueueRequest(org.folio.circulation.domain.reorder.ReorderQueueRequest) RequestRepository(org.folio.circulation.infrastructure.storage.requests.RequestRepository) HttpClient(io.vertx.core.http.HttpClient) WebContext(org.folio.circulation.support.http.server.WebContext) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) RequestRepresentation(org.folio.circulation.domain.RequestRepresentation) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) Result(org.folio.circulation.support.results.Result) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository)

Example 4 with MultipleRecords

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()));
    }));
}
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)

Example 5 with MultipleRecords

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));
    });
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) HttpURLConnection(java.net.HttpURLConnection) Response(org.folio.circulation.support.http.client.Response) MultipleRecords(org.folio.circulation.domain.MultipleRecords) ZonedDateTime(java.time.ZonedDateTime) APITests(api.support.APITests) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) IndividualResource(api.support.http.IndividualResource) Matchers.contains(org.hamcrest.Matchers.contains) UTC(java.time.ZoneOffset.UTC) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

MultipleRecords (org.folio.circulation.domain.MultipleRecords)9 Test (org.junit.jupiter.api.Test)7 JsonObject (io.vertx.core.json.JsonObject)5 APITests (api.support.APITests)4 IndividualResource (api.support.http.IndividualResource)4 UTC (java.time.ZoneOffset.UTC)4 ZonedDateTime (java.time.ZonedDateTime)4 Collection (java.util.Collection)4 UUID (java.util.UUID)4 MultipleJsonRecords (api.support.MultipleJsonRecords)3 TlrFeatureStatus (api.support.TlrFeatureStatus)3 NoticeConfigurationBuilder (api.support.builders.NoticeConfigurationBuilder)3 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)3 RequestBuilder (api.support.builders.RequestBuilder)3 OPEN_NOT_YET_FILLED (api.support.builders.RequestBuilder.OPEN_NOT_YET_FILLED)3 FakeModNotify (api.support.fakes.FakeModNotify)3 ItemResource (api.support.http.ItemResource)3 ItemStatusCodeMatcher.hasItemStatus (api.support.matchers.ItemStatusCodeMatcher.hasItemStatus)3 ValidationErrorMatchers.hasErrorWith (api.support.matchers.ValidationErrorMatchers.hasErrorWith)3 ValidationErrorMatchers.hasMessage (api.support.matchers.ValidationErrorMatchers.hasMessage)3