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