Search in sources :

Example 16 with Request

use of org.folio.circulation.domain.Request in project mod-circulation by folio-org.

the class RequestUpdateLogEventMapper method mapReorderedRequestsToJsonArray.

private static JsonObject mapReorderedRequestsToJsonArray(List<Request> requests) {
    JsonObject requestPayload = new JsonObject();
    requestPayload.put("reordered", new JsonArray(requests.stream().map(r -> r.asJson().put("previousPosition", r.getPreviousPosition())).collect(Collectors.toList())));
    return requestPayload;
}
Also used : JsonArray(io.vertx.core.json.JsonArray) UpdatedRequestPair(org.folio.circulation.domain.UpdatedRequestPair) ITEM_STATUS_NAME(org.folio.circulation.domain.representations.logs.LogEventPayloadField.ITEM_STATUS_NAME) Optional.ofNullable(java.util.Optional.ofNullable) DESTINATION_SERVICE_POINT(org.folio.circulation.domain.representations.logs.LogEventPayloadField.DESTINATION_SERVICE_POINT) Request(org.folio.circulation.domain.Request) ITEM_ID(org.folio.circulation.domain.representations.logs.LogEventPayloadField.ITEM_ID) JsonPropertyWriter.write(org.folio.circulation.support.json.JsonPropertyWriter.write) Collectors(java.util.stream.Collectors) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) ITEM_BARCODE(org.folio.circulation.domain.representations.logs.LogEventPayloadField.ITEM_BARCODE) SERVICE_POINT_ID(org.folio.circulation.domain.representations.logs.LogEventPayloadField.SERVICE_POINT_ID) SOURCE(org.folio.circulation.domain.representations.logs.LogEventPayloadField.SOURCE) REQUESTS(org.folio.circulation.domain.representations.logs.LogEventPayloadField.REQUESTS) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject)

Example 17 with Request

use of org.folio.circulation.domain.Request 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 18 with Request

use of org.folio.circulation.domain.Request in project mod-circulation by folio-org.

the class RequestsAPIUpdatingTests method eventsShouldBePublished.

@Test
void eventsShouldBePublished() {
    final ItemResource temeraire = itemsFixture.basedUponTemeraire();
    IndividualResource loan = checkOutFixture.checkOutByBarcode(temeraire);
    final IndividualResource steve = usersFixture.steve();
    ZonedDateTime requestDate = ZonedDateTime.of(2017, 7, 22, 10, 22, 54, 0, UTC);
    final IndividualResource exampleServicePoint = servicePointsFixture.cd1();
    IndividualResource createdRequest = requestsClient.create(new RequestBuilder().recall().withRequestDate(requestDate).forItem(temeraire).by(steve).fulfilToHoldShelf().withPickupServicePointId(exampleServicePoint.getId()).withRequestExpiration(LocalDate.of(2017, 7, 30)).withHoldShelfExpiration(LocalDate.of(2017, 8, 31)));
    final IndividualResource charlotte = usersFixture.charlotte();
    requestsClient.replace(createdRequest.getId(), RequestBuilder.from(createdRequest).hold().by(charlotte).withTags(new RequestBuilder.Tags(Arrays.asList("new", "important"))));
    Response response = loansClient.getById(loan.getId());
    JsonObject updatedLoan = response.getJson();
    // There should be seven events published - for "check out", for "log event: check out",
    // for "log event: request created", for "log event: request updated" for "recall" and for "replace"
    // and one log events for loans
    final var publishedEvents = Awaitility.await().atMost(1, SECONDS).until(FakePubSub::getPublishedEvents, hasSize(9));
    final var requestCreatedLogEvent = publishedEvents.findFirst(byLogEventType(REQUEST_CREATED.value()));
    final var requestUpdatedLogEvent = publishedEvents.findFirst(byLogEventType(REQUEST_UPDATED.value()));
    final var dueDateChangedEvent = publishedEvents.findFirst(byEventType(LOAN_DUE_DATE_CHANGED.name()));
    Request requestCreatedFromEventPayload = getRequestFromPayload(requestCreatedLogEvent, "created");
    assertThat(requestCreatedFromEventPayload, notNullValue());
    Request originalCreatedFromEventPayload = getRequestFromPayload(requestUpdatedLogEvent, "original");
    Request updatedCreatedFromEventPayload = getRequestFromPayload(requestUpdatedLogEvent, "updated");
    assertThat(requestCreatedFromEventPayload.getRequestType(), equalTo(originalCreatedFromEventPayload.getRequestType()));
    assertThat(originalCreatedFromEventPayload.getRequestType(), not(equalTo(updatedCreatedFromEventPayload.getRequestType())));
    assertThat(dueDateChangedEvent, isValidLoanDueDateChangedEvent(updatedLoan));
}
Also used : Response(org.folio.circulation.support.http.client.Response) FakePubSub(api.support.fakes.FakePubSub) RequestBuilder(api.support.builders.RequestBuilder) ZonedDateTime(java.time.ZonedDateTime) Request(org.folio.circulation.domain.Request) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Example 19 with Request

use of org.folio.circulation.domain.Request in project mod-circulation by folio-org.

the class ItemLevelRequestNoticeSender method sendNoticeOnRequestCancelled.

@Override
protected Result<Void> sendNoticeOnRequestCancelled(RequestAndRelatedRecords relatedRecords) {
    Request request = relatedRecords.getRequest();
    PatronNoticeEvent requestCancelledEvent = createPatronNoticeEvent(request, NoticeEventType.REQUEST_CANCELLATION).withItem(request.getItem());
    patronNoticeService.acceptNoticeEvent(requestCancelledEvent);
    return Result.succeeded(null);
}
Also used : Request(org.folio.circulation.domain.Request) PatronNoticeEvent(org.folio.circulation.domain.notice.PatronNoticeEvent)

Example 20 with Request

use of org.folio.circulation.domain.Request in project mod-circulation by folio-org.

the class RequestLoanValidator method refuseWhenUserHasAlreadyBeenLoanedItem.

public CompletableFuture<Result<RequestAndRelatedRecords>> refuseWhenUserHasAlreadyBeenLoanedItem(RequestAndRelatedRecords requestAndRelatedRecords) {
    final Request request = requestAndRelatedRecords.getRequest();
    return loanRepository.findOpenLoanForRequest(request).thenApply(loanResult -> loanResult.failWhen(loan -> of(() -> loan != null && loan.getUserId().equals(request.getUserId())), loan -> {
        Map<String, String> parameters = new HashMap<>();
        parameters.put("itemId", request.getItemId());
        parameters.put("userId", request.getUserId());
        parameters.put("loanId", loan.getId());
        String message = "This requester currently has this item on loan.";
        return singleValidationError(new ValidationError(message, parameters));
    }).map(loan -> requestAndRelatedRecords));
}
Also used : MultipleRecords(org.folio.circulation.domain.MultipleRecords) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) Result.of(org.folio.circulation.support.results.Result.of) ItemByInstanceIdFinder(org.folio.circulation.storage.ItemByInstanceIdFinder) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) Collection(java.util.Collection) Loan(org.folio.circulation.domain.Loan) Request(org.folio.circulation.domain.Request) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PageLimit.limit(org.folio.circulation.support.http.client.PageLimit.limit) ValidationErrorFailure.singleValidationError(org.folio.circulation.support.ValidationErrorFailure.singleValidationError) UUID(java.util.UUID) Result(org.folio.circulation.support.results.Result) ValidationError(org.folio.circulation.support.http.server.ValidationError) Collectors(java.util.stream.Collectors) Item(org.folio.circulation.domain.Item) ValidationErrorFailure.failedValidation(org.folio.circulation.support.ValidationErrorFailure.failedValidation) List(java.util.List) RequestAndRelatedRecords(org.folio.circulation.domain.RequestAndRelatedRecords) Map(java.util.Map) PageLimit(org.folio.circulation.support.http.client.PageLimit) HashMap(java.util.HashMap) Request(org.folio.circulation.domain.Request) ValidationErrorFailure.singleValidationError(org.folio.circulation.support.ValidationErrorFailure.singleValidationError) ValidationError(org.folio.circulation.support.http.server.ValidationError)

Aggregations

Request (org.folio.circulation.domain.Request)35 JsonObject (io.vertx.core.json.JsonObject)17 Loan (org.folio.circulation.domain.Loan)12 Result (org.folio.circulation.support.results.Result)11 Item (org.folio.circulation.domain.Item)10 ZonedDateTime (java.time.ZonedDateTime)9 List (java.util.List)9 Map (java.util.Map)9 ValidationError (org.folio.circulation.support.http.server.ValidationError)9 Result.succeeded (org.folio.circulation.support.results.Result.succeeded)9 HashMap (java.util.HashMap)8 UUID (java.util.UUID)8 CompletableFuture (java.util.concurrent.CompletableFuture)8 RequestAndRelatedRecords (org.folio.circulation.domain.RequestAndRelatedRecords)8 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)8 Clients (org.folio.circulation.support.Clients)8 Collection (java.util.Collection)7 Collectors (java.util.stream.Collectors)7 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)7 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)7