use of org.folio.circulation.domain.representations.CheckInByBarcodeRequest in project mod-circulation by folio-org.
the class LoanCheckInServiceTest method isInHouseUseWhenNonPrimaryServicePointServesHomeLocation.
@Test
void isInHouseUseWhenNonPrimaryServicePointServesHomeLocation() {
final UUID checkInServicePoint = UUID.randomUUID();
JsonObject itemRepresentation = new ItemBuilder().available().create();
JsonObject locationRepresentation = new LocationBuilder().withPrimaryServicePoint(UUID.randomUUID()).servedBy(checkInServicePoint).create();
CheckInByBarcodeRequest checkInRequest = getCheckInRequest(checkInServicePoint);
Item item = Item.from(itemRepresentation).withLocation(Location.from(locationRepresentation));
assertTrue(loanCheckInService.isInHouseUse(item, createEmptyQueue(), checkInRequest));
}
use of org.folio.circulation.domain.representations.CheckInByBarcodeRequest in project mod-circulation by folio-org.
the class LoanCheckInServiceTest method isNotInHouseUseWhenItemIsUnavailable.
@Test
void isNotInHouseUseWhenItemIsUnavailable() {
final UUID checkInServicePoint = UUID.randomUUID();
JsonObject itemRepresentation = new ItemBuilder().checkOut().create();
JsonObject locationRepresentation = new LocationBuilder().withPrimaryServicePoint(checkInServicePoint).create();
CheckInByBarcodeRequest checkInRequest = getCheckInRequest(checkInServicePoint);
Item item = Item.from(itemRepresentation).withLocation(Location.from(locationRepresentation));
assertFalse(loanCheckInService.isInHouseUse(item, createEmptyQueue(), checkInRequest));
}
use of org.folio.circulation.domain.representations.CheckInByBarcodeRequest 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);
}
use of org.folio.circulation.domain.representations.CheckInByBarcodeRequest in project mod-circulation by folio-org.
the class LoanCheckInServiceTest method isInHouseUseWhenServicePointIsPrimaryForHomeLocation.
@Test
void isInHouseUseWhenServicePointIsPrimaryForHomeLocation() {
final UUID checkInServicePoint = UUID.randomUUID();
JsonObject itemRepresentation = new ItemBuilder().available().create();
JsonObject locationRepresentation = new LocationBuilder().withPrimaryServicePoint(checkInServicePoint).create();
CheckInByBarcodeRequest checkInRequest = getCheckInRequest(checkInServicePoint);
Item item = Item.from(itemRepresentation).withLocation(Location.from(locationRepresentation));
assertTrue(loanCheckInService.isInHouseUse(item, createEmptyQueue(), checkInRequest));
}
use of org.folio.circulation.domain.representations.CheckInByBarcodeRequest in project mod-circulation by folio-org.
the class LoanCheckInServiceTest method isNotInHouseUseWhenServicePointDoesNotServeHomeLocation.
@Test
void isNotInHouseUseWhenServicePointDoesNotServeHomeLocation() {
JsonObject itemRepresentation = new ItemBuilder().available().create();
JsonObject locationRepresentation = new LocationBuilder().withPrimaryServicePoint(UUID.randomUUID()).servedBy(UUID.randomUUID()).create();
CheckInByBarcodeRequest checkInRequest = getCheckInRequest(UUID.randomUUID());
Item item = Item.from(itemRepresentation).withLocation(Location.from(locationRepresentation));
assertFalse(loanCheckInService.isInHouseUse(item, createEmptyQueue(), checkInRequest));
}
Aggregations