Search in sources :

Example 6 with EventPublisher

use of org.folio.circulation.services.EventPublisher in project mod-circulation by folio-org.

the class DeclareLostResource method declareLost.

private void declareLost(RoutingContext routingContext) {
    final WebContext context = new WebContext(routingContext);
    final Clients clients = Clients.create(context, client);
    final EventPublisher eventPublisher = new EventPublisher(routingContext);
    validateDeclaredLostRequest(routingContext).after(request -> declareItemLost(request, clients, context)).thenComposeAsync(r -> r.after(loan -> publishEvent(loan, eventPublisher))).thenApply(r -> r.map(toFixedValue(NoContentResponse::noContent))).thenAccept(context::writeResultToHttpResponse);
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) DeclareItemLostRequest(org.folio.circulation.domain.representations.DeclareItemLostRequest) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) WebContext(org.folio.circulation.support.http.server.WebContext) MappingFunctions.when(org.folio.circulation.support.results.MappingFunctions.when) Router(io.vertx.ext.web.Router) CompletableFuture(java.util.concurrent.CompletableFuture) ValidationErrorFailure.singleValidationError(org.folio.circulation.support.ValidationErrorFailure.singleValidationError) LostItemFeeChargingService(org.folio.circulation.services.LostItemFeeChargingService) RoutingContext(io.vertx.ext.web.RoutingContext) Function(java.util.function.Function) NotesRepository(org.folio.circulation.infrastructure.storage.notes.NotesRepository) LoanValidator(org.folio.circulation.domain.validation.LoanValidator) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) LostItemFeeRefundService(org.folio.circulation.services.LostItemFeeRefundService) NoteCreator(org.folio.circulation.domain.notes.NoteCreator) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) Loan(org.folio.circulation.domain.Loan) MappingFunctions.toFixedValue(org.folio.circulation.support.results.MappingFunctions.toFixedValue) Result(org.folio.circulation.support.results.Result) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) EventPublisher(org.folio.circulation.services.EventPublisher) StringUtils.defaultIfBlank(org.apache.commons.lang.StringUtils.defaultIfBlank) CompletionStage(java.util.concurrent.CompletionStage) StoreLoanAndItem(org.folio.circulation.StoreLoanAndItem) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) HttpClient(io.vertx.core.http.HttpClient) WebContext(org.folio.circulation.support.http.server.WebContext) EventPublisher(org.folio.circulation.services.EventPublisher) Clients(org.folio.circulation.support.Clients)

Example 7 with EventPublisher

use of org.folio.circulation.services.EventPublisher in project mod-circulation by folio-org.

the class ScheduledAnonymizationProcessingResource method scheduledAnonymizeLoans.

private void scheduledAnonymizeLoans(RoutingContext routingContext) {
    final WebContext context = new WebContext(routingContext);
    final Clients clients = Clients.create(context, client);
    ConfigurationRepository configurationRepository = new ConfigurationRepository(clients);
    final var itemRepository = new ItemRepository(clients);
    final var userRepository = new UserRepository(clients);
    final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
    final var accountRepository = new AccountRepository(clients);
    final var anonymizeStorageLoansRepository = new AnonymizeStorageLoansRepository(clients);
    final var eventPublisher = new EventPublisher(clients.pubSubPublishingService());
    final var loansFinder = new LoansForTenantFinder(loanRepository, accountRepository, Environment.getScheduledAnonymizationNumberOfLoansToCheck());
    log.info("Initializing loan anonymization for current tenant");
    safelyInitialise(configurationRepository::loanHistoryConfiguration).thenApply(r -> r.map(config -> new DefaultLoanAnonymizationService(new AnonymizationCheckersService(config, ClockUtil::getZonedDateTime), anonymizeStorageLoansRepository, eventPublisher))).thenCompose(r -> r.after(service -> service.anonymizeLoans(loansFinder::findLoansToAnonymize))).thenApply(AnonymizeLoansRepresentation::from).thenApply(r -> r.map(JsonHttpResponse::ok)).exceptionally(CommonFailures::failedDueToServerError).thenAccept(context::writeResultToHttpResponse);
}
Also used : Environment(org.folio.Environment) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) WebContext(org.folio.circulation.support.http.server.WebContext) Router(io.vertx.ext.web.Router) RoutingContext(io.vertx.ext.web.RoutingContext) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) AccountRepository(org.folio.circulation.infrastructure.storage.feesandfines.AccountRepository) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) AnonymizeStorageLoansRepository(org.folio.circulation.infrastructure.storage.loans.AnonymizeStorageLoansRepository) CommonFailures(org.folio.circulation.support.results.CommonFailures) MethodHandles(java.lang.invoke.MethodHandles) AnonymizeLoansRepresentation(org.folio.circulation.domain.representations.anonymization.AnonymizeLoansRepresentation) EventPublisher(org.folio.circulation.services.EventPublisher) RouteRegistration(org.folio.circulation.support.RouteRegistration) LoansForTenantFinder(org.folio.circulation.domain.anonymization.service.LoansForTenantFinder) Logger(org.apache.logging.log4j.Logger) DefaultLoanAnonymizationService(org.folio.circulation.domain.anonymization.DefaultLoanAnonymizationService) ClockUtil(org.folio.circulation.support.utils.ClockUtil) AsynchronousResultBindings.safelyInitialise(org.folio.circulation.support.results.AsynchronousResultBindings.safelyInitialise) LogManager(org.apache.logging.log4j.LogManager) AnonymizationCheckersService(org.folio.circulation.domain.anonymization.service.AnonymizationCheckersService) HttpClient(io.vertx.core.http.HttpClient) WebContext(org.folio.circulation.support.http.server.WebContext) EventPublisher(org.folio.circulation.services.EventPublisher) DefaultLoanAnonymizationService(org.folio.circulation.domain.anonymization.DefaultLoanAnonymizationService) ClockUtil(org.folio.circulation.support.utils.ClockUtil) AccountRepository(org.folio.circulation.infrastructure.storage.feesandfines.AccountRepository) LoansForTenantFinder(org.folio.circulation.domain.anonymization.service.LoansForTenantFinder) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) AnonymizationCheckersService(org.folio.circulation.domain.anonymization.service.AnonymizationCheckersService) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) AnonymizeStorageLoansRepository(org.folio.circulation.infrastructure.storage.loans.AnonymizeStorageLoansRepository)

Example 8 with EventPublisher

use of org.folio.circulation.services.EventPublisher 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);
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) RequestScheduledNoticeService(org.folio.circulation.domain.notice.schedule.RequestScheduledNoticeService) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) WebContext(org.folio.circulation.support.http.server.WebContext) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) CheckInByBarcodeResponse(org.folio.circulation.domain.representations.CheckInByBarcodeResponse) Router(io.vertx.ext.web.Router) ValidationErrorFailure.singleValidationError(org.folio.circulation.support.ValidationErrorFailure.singleValidationError) RoutingContext(io.vertx.ext.web.RoutingContext) CheckInContext(org.folio.circulation.domain.CheckInContext) Item(org.folio.circulation.domain.Item) UserNotFoundValidator.refuseWhenLoggedInUserNotPresent(org.folio.circulation.domain.validation.UserNotFoundValidator.refuseWhenLoggedInUserNotPresent) CheckInValidators(org.folio.circulation.domain.validation.CheckInValidators) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) ITEM_BARCODE(org.folio.circulation.domain.representations.CheckOutByBarcodeRequest.ITEM_BARCODE) ValidationErrorFailure(org.folio.circulation.support.ValidationErrorFailure) PatronActionSessionRepository(org.folio.circulation.infrastructure.storage.sessions.PatronActionSessionRepository) Result(org.folio.circulation.support.results.Result) EventPublisher(org.folio.circulation.services.EventPublisher) RouteRegistration(org.folio.circulation.support.RouteRegistration) CheckInByBarcodeRequest(org.folio.circulation.domain.representations.CheckInByBarcodeRequest) PatronActionSessionService(org.folio.circulation.domain.notice.session.PatronActionSessionService) RequestRepository(org.folio.circulation.infrastructure.storage.requests.RequestRepository) HttpClient(io.vertx.core.http.HttpClient) WebContext(org.folio.circulation.support.http.server.WebContext) PatronActionSessionService(org.folio.circulation.domain.notice.session.PatronActionSessionService) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) CheckInValidators(org.folio.circulation.domain.validation.CheckInValidators) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) CheckInByBarcodeRequest(org.folio.circulation.domain.representations.CheckInByBarcodeRequest) EventPublisher(org.folio.circulation.services.EventPublisher) RequestScheduledNoticeService(org.folio.circulation.domain.notice.schedule.RequestScheduledNoticeService) Clients(org.folio.circulation.support.Clients) CheckInByBarcodeResponse(org.folio.circulation.domain.representations.CheckInByBarcodeResponse) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) CheckInContext(org.folio.circulation.domain.CheckInContext) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository)

Example 9 with EventPublisher

use of org.folio.circulation.services.EventPublisher in project mod-circulation by folio-org.

the class CheckOutByBarcodeResource method checkOut.

private void checkOut(RoutingContext routingContext) {
    final WebContext context = new WebContext(routingContext);
    CheckOutByBarcodeRequest request = CheckOutByBarcodeRequest.fromJson(routingContext.getBodyAsJson());
    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 var requestQueueRepository = new RequestQueueRepository(requestRepository);
    final LoanService loanService = new LoanService(clients);
    final LoanPolicyRepository loanPolicyRepository = new LoanPolicyRepository(clients);
    final OverdueFinePolicyRepository overdueFinePolicyRepository = new OverdueFinePolicyRepository(clients);
    final LostItemPolicyRepository lostItemPolicyRepository = new LostItemPolicyRepository(clients);
    final PatronNoticePolicyRepository patronNoticePolicyRepository = new PatronNoticePolicyRepository(clients);
    final PatronGroupRepository patronGroupRepository = new PatronGroupRepository(clients);
    final ConfigurationRepository configurationRepository = new ConfigurationRepository(clients);
    final ScheduledNoticesRepository scheduledNoticesRepository = ScheduledNoticesRepository.using(clients);
    final LoanScheduledNoticeService scheduledNoticeService = new LoanScheduledNoticeService(scheduledNoticesRepository, patronNoticePolicyRepository);
    OkapiPermissions permissions = OkapiPermissions.from(new WebContext(routingContext).getHeaders());
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(permissions);
    CheckOutValidators validators = new CheckOutValidators(request, clients, errorHandler, permissions, loanRepository);
    final var requestQueueUpdate = UpdateRequestQueue.using(clients, requestRepository, requestQueueRepository);
    final LoanRepresentation loanRepresentation = new LoanRepresentation();
    final EventPublisher eventPublisher = new EventPublisher(routingContext);
    final PatronActionSessionService patronActionSessionService = PatronActionSessionService.using(clients, PatronActionSessionRepository.using(clients, loanRepository, userRepository));
    ofAsync(() -> new LoanAndRelatedRecords(request.toLoan())).thenApply(validators::refuseCheckOutWhenServicePointIsNotPresent).thenComposeAsync(r -> lookupUser(request.getUserBarcode(), userRepository, r, errorHandler)).thenComposeAsync(validators::refuseWhenCheckOutActionIsBlockedManuallyForPatron).thenComposeAsync(validators::refuseWhenCheckOutActionIsBlockedAutomaticallyForPatron).thenComposeAsync(r -> lookupProxyUser(request.getProxyUserBarcode(), userRepository, r, errorHandler)).thenApply(validators::refuseWhenUserIsInactive).thenApply(validators::refuseWhenProxyUserIsInactive).thenComposeAsync(validators::refuseWhenInvalidProxyRelationship).thenComposeAsync(r -> lookupItem(request.getItemBarcode(), itemRepository, r)).thenApply(validators::refuseWhenItemNotFound).thenApply(validators::refuseWhenItemIsAlreadyCheckedOut).thenApply(validators::refuseWhenItemIsNotAllowedForCheckOut).thenComposeAsync(validators::refuseWhenItemHasOpenLoans).thenComposeAsync(r -> r.combineAfter(configurationRepository::lookupTlrSettings, LoanAndRelatedRecords::withTlrSettings)).thenComposeAsync(r -> r.after(requestQueueRepository::get)).thenApply(validators::refuseWhenRequestedByAnotherPatron).thenComposeAsync(r -> r.after(l -> lookupLoanPolicy(l, loanPolicyRepository, errorHandler))).thenComposeAsync(validators::refuseWhenItemLimitIsReached).thenCompose(validators::refuseWhenItemIsNotLoanable).thenApply(r -> r.next(errorHandler::failWithValidationErrors)).thenCompose(r -> r.combineAfter(configurationRepository::findTimeZoneConfiguration, LoanAndRelatedRecords::withTimeZone)).thenComposeAsync(r -> r.after(overdueFinePolicyRepository::lookupOverdueFinePolicy)).thenComposeAsync(r -> r.after(lostItemPolicyRepository::lookupLostItemPolicy)).thenApply(r -> r.next(this::setItemLocationIdAtCheckout)).thenComposeAsync(r -> r.after(relatedRecords -> checkOut(relatedRecords, routingContext.getBodyAsJson(), clients))).thenApply(r -> r.map(this::checkOutItem)).thenComposeAsync(r -> r.after(requestQueueUpdate::onCheckOut)).thenComposeAsync(r -> r.after(loanService::truncateLoanWhenItemRecalled)).thenComposeAsync(r -> r.after(patronGroupRepository::findPatronGroupForLoanAndRelatedRecords)).thenComposeAsync(r -> r.after(l -> updateItem(l, itemRepository))).thenComposeAsync(r -> r.after(loanRepository::createLoan)).thenComposeAsync(r -> r.after(l -> saveCheckOutSessionRecord(l, patronActionSessionService, errorHandler))).thenApplyAsync(r -> r.map(records -> records.withLoggedInUserId(context.getUserId()))).thenComposeAsync(r -> r.after(l -> publishItemCheckedOutEvent(l, eventPublisher, userRepository, errorHandler))).thenApply(r -> r.next(scheduledNoticeService::scheduleNoticesForLoanDueDate)).thenApply(r -> r.map(LoanAndRelatedRecords::getLoan)).thenApply(r -> r.map(loanRepresentation::extendedLoan)).thenApply(r -> createdLoanFrom(r, errorHandler)).thenAccept(context::writeResultToHttpResponse);
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) 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) ZonedDateTime(java.time.ZonedDateTime) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) LoanPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository) Router(io.vertx.ext.web.Router) RoutingContext(io.vertx.ext.web.RoutingContext) ClosedLibraryStrategyService(org.folio.circulation.domain.policy.library.ClosedLibraryStrategyService) CheckOutByBarcodeRequest(org.folio.circulation.domain.representations.CheckOutByBarcodeRequest) FAILED_TO_FETCH_PROXY_USER(org.folio.circulation.resources.handlers.error.CirculationErrorType.FAILED_TO_FETCH_PROXY_USER) LoanAndRelatedRecords(org.folio.circulation.domain.LoanAndRelatedRecords) LostItemPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LostItemPolicyRepository) PatronNoticePolicyRepository(org.folio.circulation.infrastructure.storage.notices.PatronNoticePolicyRepository) FAILED_TO_FETCH_ITEM(org.folio.circulation.resources.handlers.error.CirculationErrorType.FAILED_TO_FETCH_ITEM) JsonObject(io.vertx.core.json.JsonObject) LoanScheduledNoticeService(org.folio.circulation.domain.notice.schedule.LoanScheduledNoticeService) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) Loan(org.folio.circulation.domain.Loan) FAILED_TO_PUBLISH_CHECKOUT_EVENT(org.folio.circulation.resources.handlers.error.CirculationErrorType.FAILED_TO_PUBLISH_CHECKOUT_EVENT) Result(org.folio.circulation.support.results.Result) LoanPolicy(org.folio.circulation.domain.policy.LoanPolicy) EventPublisher(org.folio.circulation.services.EventPublisher) RouteRegistration(org.folio.circulation.support.RouteRegistration) LoanRepresentation(org.folio.circulation.domain.LoanRepresentation) PatronActionSessionService(org.folio.circulation.domain.notice.session.PatronActionSessionService) LoanService(org.folio.circulation.domain.LoanService) CirculationErrorType(org.folio.circulation.resources.handlers.error.CirculationErrorType) CHECKED_OUT_THROUGH_OVERRIDE(org.folio.circulation.domain.LoanAction.CHECKED_OUT_THROUGH_OVERRIDE) CheckOutValidators(org.folio.circulation.domain.validation.CheckOutValidators) RequestRepository(org.folio.circulation.infrastructure.storage.requests.RequestRepository) HttpClient(io.vertx.core.http.HttpClient) Clients(org.folio.circulation.support.Clients) OverdueFinePolicyRepository(org.folio.circulation.infrastructure.storage.loans.OverdueFinePolicyRepository) WebContext(org.folio.circulation.support.http.server.WebContext) CompletableFuture(java.util.concurrent.CompletableFuture) FAILED_TO_SAVE_SESSION_RECORD(org.folio.circulation.resources.handlers.error.CirculationErrorType.FAILED_TO_SAVE_SESSION_RECORD) HttpResponse(org.folio.circulation.support.http.server.HttpResponse) JsonHttpResponse.ok(org.folio.circulation.support.http.server.JsonHttpResponse.ok) OkapiPermissions(org.folio.circulation.support.http.OkapiPermissions) RequestQueue(org.folio.circulation.domain.RequestQueue) ScheduledNoticesRepository(org.folio.circulation.infrastructure.storage.notices.ScheduledNoticesRepository) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) FAILED_TO_FETCH_USER(org.folio.circulation.resources.handlers.error.CirculationErrorType.FAILED_TO_FETCH_USER) PatronActionSessionRepository(org.folio.circulation.infrastructure.storage.sessions.PatronActionSessionRepository) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) JsonHttpResponse.created(org.folio.circulation.support.http.server.JsonHttpResponse.created) CHECKED_OUT(org.folio.circulation.domain.ItemStatus.CHECKED_OUT) PatronGroupRepository(org.folio.circulation.infrastructure.storage.users.PatronGroupRepository) WebContext(org.folio.circulation.support.http.server.WebContext) CheckOutValidators(org.folio.circulation.domain.validation.CheckOutValidators) PatronNoticePolicyRepository(org.folio.circulation.infrastructure.storage.notices.PatronNoticePolicyRepository) ScheduledNoticesRepository(org.folio.circulation.infrastructure.storage.notices.ScheduledNoticesRepository) PatronActionSessionService(org.folio.circulation.domain.notice.session.PatronActionSessionService) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) LoanPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) OverdueFinePolicyRepository(org.folio.circulation.infrastructure.storage.loans.OverdueFinePolicyRepository) EventPublisher(org.folio.circulation.services.EventPublisher) OkapiPermissions(org.folio.circulation.support.http.OkapiPermissions) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) Clients(org.folio.circulation.support.Clients) LoanService(org.folio.circulation.domain.LoanService) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) LoanScheduledNoticeService(org.folio.circulation.domain.notice.schedule.LoanScheduledNoticeService) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) LostItemPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LostItemPolicyRepository) CheckOutByBarcodeRequest(org.folio.circulation.domain.representations.CheckOutByBarcodeRequest) LoanRepresentation(org.folio.circulation.domain.LoanRepresentation) LoanAndRelatedRecords(org.folio.circulation.domain.LoanAndRelatedRecords) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) PatronGroupRepository(org.folio.circulation.infrastructure.storage.users.PatronGroupRepository)

Example 10 with EventPublisher

use of org.folio.circulation.services.EventPublisher in project mod-circulation by folio-org.

the class DeclareClaimedReturnedItemAsMissingResource method declareClaimedReturnedItemAsMissing.

private void declareClaimedReturnedItemAsMissing(RoutingContext routingContext) {
    final WebContext context = new WebContext(routingContext);
    final EventPublisher eventPublisher = new EventPublisher(new PubSubPublishingService(context));
    createRequest(routingContext).after(request -> processDeclareClaimedReturnedItemAsMissing(routingContext, request)).thenCompose(r -> r.after(eventPublisher::publishMarkedAsMissingLoanEvent)).thenApply(r -> r.map(toFixedValue(NoContentResponse::noContent))).thenAccept(context::writeResultToHttpResponse);
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) WebContext(org.folio.circulation.support.http.server.WebContext) 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) NotesRepository(org.folio.circulation.infrastructure.storage.notes.NotesRepository) ChangeItemStatusRequest(org.folio.circulation.domain.representations.ChangeItemStatusRequest) PubSubPublishingService(org.folio.circulation.services.PubSubPublishingService) JsonObject(io.vertx.core.json.JsonObject) ChangeItemStatusService(org.folio.circulation.services.ChangeItemStatusService) Result.failed(org.folio.circulation.support.results.Result.failed) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) NoteCreator(org.folio.circulation.domain.notes.NoteCreator) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) Loan(org.folio.circulation.domain.Loan) MappingFunctions.toFixedValue(org.folio.circulation.support.results.MappingFunctions.toFixedValue) NotInItemStatusValidator(org.folio.circulation.domain.validation.NotInItemStatusValidator) Result(org.folio.circulation.support.results.Result) EventPublisher(org.folio.circulation.services.EventPublisher) RouteRegistration(org.folio.circulation.support.RouteRegistration) StoreLoanAndItem(org.folio.circulation.StoreLoanAndItem) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) HttpClient(io.vertx.core.http.HttpClient) WebContext(org.folio.circulation.support.http.server.WebContext) EventPublisher(org.folio.circulation.services.EventPublisher) PubSubPublishingService(org.folio.circulation.services.PubSubPublishingService)

Aggregations

EventPublisher (org.folio.circulation.services.EventPublisher)19 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)18 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)18 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)18 WebContext (org.folio.circulation.support.http.server.WebContext)18 HttpClient (io.vertx.core.http.HttpClient)17 RoutingContext (io.vertx.ext.web.RoutingContext)17 Clients (org.folio.circulation.support.Clients)17 Router (io.vertx.ext.web.Router)15 ValidationErrorFailure.singleValidationError (org.folio.circulation.support.ValidationErrorFailure.singleValidationError)13 Result (org.folio.circulation.support.results.Result)13 CompletableFuture (java.util.concurrent.CompletableFuture)12 RouteRegistration (org.folio.circulation.support.RouteRegistration)12 Result.succeeded (org.folio.circulation.support.results.Result.succeeded)12 JsonObject (io.vertx.core.json.JsonObject)11 Loan (org.folio.circulation.domain.Loan)11 RequestQueueRepository (org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository)11 RequestRepository (org.folio.circulation.infrastructure.storage.requests.RequestRepository)10 NoContentResponse (org.folio.circulation.support.http.server.NoContentResponse)10 MappingFunctions.toFixedValue (org.folio.circulation.support.results.MappingFunctions.toFixedValue)10