use of org.folio.circulation.domain.CheckInContext in project mod-circulation by folio-org.
the class LogCheckInServiceTest method logCheckInOperationPropagatesException.
@Test
void logCheckInOperationPropagatesException() {
final CheckInContext context = checkInProcessRecords();
final ServerErrorFailure postError = new ServerErrorFailure("ServerError");
when(checkInStorageClient.post(any(JsonObject.class))).thenReturn(CompletableFuture.completedFuture(Result.failed(postError)));
final CompletableFuture<Result<CheckInContext>> logCheckInOperation = logCheckInService.logCheckInOperation(context);
final Result<CheckInContext> logResult = logCheckInOperation.getNow(Result.failed(new ServerErrorFailure("Uncompleted")));
assertThat(logResult.failed(), is(true));
assertThat(logResult.cause(), is(postError));
}
use of org.folio.circulation.domain.CheckInContext in project mod-circulation by folio-org.
the class LogCheckInServiceTest method checkInProcessRecords.
private CheckInContext checkInProcessRecords() {
JsonObject requestRepresentation = new JsonObject().put("servicePointId", UUID.randomUUID().toString()).put("itemBarcode", "barcode").put("checkInDate", ClockUtil.getZonedDateTime().toString());
JsonObject itemRepresentation = new JsonObject().put("id", UUID.randomUUID().toString()).put("status", new JsonObject().put("name", "Available"));
return new CheckInContext(CheckInByBarcodeRequest.from(requestRepresentation).value()).withItem(Item.from(itemRepresentation)).withRequestQueue(new RequestQueue(Collections.emptyList())).withLoggedInUserId(UUID.randomUUID().toString());
}
use of org.folio.circulation.domain.CheckInContext in project mod-circulation by folio-org.
the class PatronActionSessionService method saveCheckInSessionRecord.
public CompletableFuture<Result<CheckInContext>> saveCheckInSessionRecord(CheckInContext context) {
Loan loan = context.getLoan();
if (loan == null) {
log.info("CheckInSessionRecord is not saved, context doesn't have a valid loan.");
return completedFuture(of(() -> context));
}
UUID patronId = UUID.fromString(loan.getUserId());
UUID loanId = UUID.fromString(loan.getId());
PatronSessionRecord patronSessionRecord = new PatronSessionRecord(UUID.randomUUID(), patronId, loanId, PatronActionType.CHECK_IN);
return patronActionSessionRepository.create(patronSessionRecord).thenApply(mapResult(v -> context));
}
use of org.folio.circulation.domain.CheckInContext in project mod-circulation by folio-org.
the class EventPublisher method publishItemCheckedInEvents.
public CompletableFuture<Result<CheckInContext>> publishItemCheckedInEvents(CheckInContext checkInContext, UserRepository userRepository) {
runAsync(() -> userRepository.getUser(checkInContext.getLoggedInUserId()).thenApplyAsync(r -> r.after(loggedInUser -> CompletableFuture.completedFuture(Result.succeeded(pubSubPublishingService.publishEvent(LOG_RECORD.name(), mapToCheckInLogEventContent(checkInContext, loggedInUser)))))));
if (checkInContext.getLoan() != null) {
Loan loan = checkInContext.getLoan();
JsonObject payloadJsonObject = new JsonObject();
write(payloadJsonObject, USER_ID_FIELD, loan.getUserId());
write(payloadJsonObject, LOAN_ID_FIELD, loan.getId());
write(payloadJsonObject, RETURN_DATE_FIELD, loan.getReturnDate());
return pubSubPublishingService.publishEvent(ITEM_CHECKED_IN.name(), payloadJsonObject.encode()).handle((result, error) -> handlePublishEventError(error, checkInContext));
} else {
logger.error(FAILED_TO_PUBLISH_LOG_TEMPLATE, ITEM_CHECKED_IN.name());
}
return completedFuture(succeeded(checkInContext));
}
use of org.folio.circulation.domain.CheckInContext in project mod-circulation by folio-org.
the class CheckInByBarcodeResource method checkIn.
private void checkIn(RoutingContext routingContext) {
final WebContext context = new WebContext(routingContext);
final Clients clients = Clients.create(context, client);
final var userRepository = new UserRepository(clients);
final var itemRepository = new ItemRepository(clients);
final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
final var requestRepository = RequestRepository.using(clients, itemRepository, userRepository, loanRepository);
final Result<CheckInByBarcodeRequest> checkInRequestResult = CheckInByBarcodeRequest.from(routingContext.getBodyAsJson());
final EventPublisher eventPublisher = new EventPublisher(routingContext);
final var checkInValidators = new CheckInValidators(this::errorWhenInIncorrectStatus);
final CheckInProcessAdapter processAdapter = CheckInProcessAdapter.newInstance(clients, itemRepository, userRepository, loanRepository, requestRepository, new RequestQueueRepository(requestRepository));
final RequestScheduledNoticeService requestScheduledNoticeService = RequestScheduledNoticeService.using(clients);
final PatronActionSessionService patronActionSessionService = PatronActionSessionService.using(clients, PatronActionSessionRepository.using(clients, loanRepository, userRepository));
final RequestNoticeSender requestNoticeSender = RequestNoticeSender.using(clients);
final ConfigurationRepository configurationRepository = new ConfigurationRepository(clients);
refuseWhenLoggedInUserNotPresent(context).next(notUsed -> checkInRequestResult).map(CheckInContext::new).combineAfter(processAdapter::findItem, (records, item) -> records.withItem(item).withItemStatusBeforeCheckIn(item.getStatus())).thenApply(checkInValidators::refuseWhenItemIsNotAllowedForCheckIn).thenApply(checkInValidators::refuseWhenClaimedReturnedIsNotResolved).thenComposeAsync(r -> r.combineAfter(configurationRepository::lookupTlrSettings, CheckInContext::withTlrSettings)).thenComposeAsync(findItemResult -> findItemResult.combineAfter(processAdapter::getRequestQueue, CheckInContext::withRequestQueue)).thenApply(findRequestQueueResult -> findRequestQueueResult.map(processAdapter::setInHouseUse)).thenApplyAsync(r -> r.map(records -> records.withLoggedInUserId(context.getUserId()))).thenComposeAsync(setUserResult -> setUserResult.after(processAdapter::logCheckInOperation)).thenComposeAsync(logCheckInResult -> logCheckInResult.combineAfter(processAdapter::findSingleOpenLoan, CheckInContext::withLoan)).thenComposeAsync(findLoanResult -> findLoanResult.combineAfter(processAdapter::checkInLoan, CheckInContext::withLoan)).thenComposeAsync(checkInLoan -> checkInLoan.combineAfter(processAdapter::updateRequestQueue, CheckInContext::withRequestQueue)).thenComposeAsync(updateRequestQueueResult -> updateRequestQueueResult.combineAfter(processAdapter::updateItem, CheckInContext::withItem)).thenApply(handleItemStatus -> handleItemStatus.next(requestNoticeSender::sendNoticeOnRequestAwaitingPickup)).thenComposeAsync(updateItemResult -> updateItemResult.combineAfter(processAdapter::getDestinationServicePoint, CheckInContext::withItem)).thenComposeAsync(updateItemResult -> updateItemResult.combineAfter(processAdapter::getCheckInServicePoint, CheckInContext::withCheckInServicePoint)).thenComposeAsync(updateItemResult -> updateItemResult.combineAfter(processAdapter::getPickupServicePoint, CheckInContext::withHighestPriorityFulfillableRequest)).thenComposeAsync(updateItemResult -> updateItemResult.combineAfter(processAdapter::getRequester, CheckInContext::withHighestPriorityFulfillableRequest)).thenComposeAsync(updateItemResult -> updateItemResult.combineAfter(processAdapter::getAddressType, CheckInContext::withHighestPriorityFulfillableRequest)).thenComposeAsync(updateItemResult -> updateItemResult.combineAfter(processAdapter::updateLoan, CheckInContext::withLoan)).thenComposeAsync(updateItemResult -> updateItemResult.after(patronActionSessionService::saveCheckInSessionRecord)).thenComposeAsync(r -> r.after(processAdapter::refundLostItemFees)).thenComposeAsync(r -> r.after(records -> processAdapter.createOverdueFineIfNecessary(records, context))).thenComposeAsync(r -> r.after(v -> eventPublisher.publishItemCheckedInEvents(v, userRepository))).thenApply(r -> r.next(requestScheduledNoticeService::rescheduleRequestNotices)).thenApply(r -> r.map(CheckInByBarcodeResponse::fromRecords)).thenApply(r -> r.map(CheckInByBarcodeResponse::toHttpResponse)).thenAccept(context::writeResultToHttpResponse);
}
Aggregations