Search in sources :

Example 1 with RequestScheduledNoticeService

use of org.folio.circulation.domain.notice.schedule.RequestScheduledNoticeService in project mod-circulation by folio-org.

the class RequestCollectionResource method replace.

@Override
void replace(RoutingContext routingContext) {
    final var context = new WebContext(routingContext);
    final var clients = Clients.create(context, client);
    final var representation = routingContext.getBodyAsJson();
    write(representation, "id", getRequestId(routingContext));
    final var itemRepository = new ItemRepository(clients);
    final var userRepository = new UserRepository(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 var updateRequestQueue = UpdateRequestQueue.using(clients, requestRepository, requestQueueRepository);
    final var loanPolicyRepository = new LoanPolicyRepository(clients);
    final var eventPublisher = new EventPublisher(routingContext);
    final var requestNoticeSender = createRequestNoticeSender(clients, representation);
    final var configurationRepository = new ConfigurationRepository(clients);
    final var updateItem = new UpdateItem(itemRepository);
    final var updateUponRequest = new UpdateUponRequest(updateItem, new UpdateLoan(clients, loanRepository, loanPolicyRepository), updateRequestQueue);
    final var errorHandler = new FailFastErrorHandler();
    final var createRequestService = new CreateRequestService(new CreateRequestRepositories(requestRepository, new RequestPolicyRepository(clients), configurationRepository), updateUponRequest, new RequestLoanValidator(new ItemByInstanceIdFinder(clients.holdingsStorage(), itemRepository), loanRepository), requestNoticeSender, regularRequestBlockValidators(clients), eventPublisher, errorHandler);
    final var updateRequestService = new UpdateRequestService(requestRepository, updateRequestQueue, new ClosedRequestValidator(requestRepository), requestNoticeSender, updateItem, eventPublisher);
    final var requestFromRepresentationService = new RequestFromRepresentationService(new InstanceRepository(clients), itemRepository, new RequestQueueRepository(requestRepository), userRepository, loanRepository, new ServicePointRepository(clients), configurationRepository, createProxyRelationshipValidator(representation, clients), new ServicePointPickupLocationValidator(), errorHandler, new ItemByInstanceIdFinder(clients.holdingsStorage(), itemRepository));
    final var requestScheduledNoticeService = RequestScheduledNoticeService.using(clients);
    fromFutureResult(requestFromRepresentationService.getRequestFrom(Request.Operation.REPLACE, representation)).flatMapFuture(when(requestRepository::exists, updateRequestService::replaceRequest, createRequestService::createRequest)).flatMapFuture(records -> eventPublisher.publishDueDateChangedEvent(records, loanRepository)).map(requestScheduledNoticeService::rescheduleRequestNotices).map(toFixedValue(NoContentResponse::noContent)).onComplete(context::write, context::write);
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) UpdateRequestQueue(org.folio.circulation.domain.UpdateRequestQueue) RequestScheduledNoticeService(org.folio.circulation.domain.notice.schedule.RequestScheduledNoticeService) CreateRequestService(org.folio.circulation.domain.CreateRequestService) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) MappingFunctions.when(org.folio.circulation.support.results.MappingFunctions.when) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) LoanPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository) Router(io.vertx.ext.web.Router) ValidationErrorFailure.singleValidationError(org.folio.circulation.support.ValidationErrorFailure.singleValidationError) UpdateItem(org.folio.circulation.domain.UpdateItem) RoutingContext(io.vertx.ext.web.RoutingContext) JsonPropertyWriter.write(org.folio.circulation.support.json.JsonPropertyWriter.write) ServicePointRepository(org.folio.circulation.infrastructure.storage.ServicePointRepository) JsonObject(io.vertx.core.json.JsonObject) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) RequestRepresentation(org.folio.circulation.domain.RequestRepresentation) RequestBlockValidators.regularRequestBlockValidators(org.folio.circulation.resources.RequestBlockValidators.regularRequestBlockValidators) AsynchronousResult.fromFutureResult(org.folio.circulation.support.results.AsynchronousResult.fromFutureResult) RequestLoanValidator(org.folio.circulation.domain.validation.RequestLoanValidator) RequestPolicyRepository(org.folio.circulation.infrastructure.storage.requests.RequestPolicyRepository) UpdateRequestService(org.folio.circulation.domain.UpdateRequestService) BlockOverrides(org.folio.circulation.domain.override.BlockOverrides) EventPublisher(org.folio.circulation.services.EventPublisher) PROXY_USER_ID(org.folio.circulation.domain.representations.RequestProperties.PROXY_USER_ID) ServicePointPickupLocationValidator(org.folio.circulation.domain.validation.ServicePointPickupLocationValidator) TITLE(org.folio.circulation.domain.RequestLevel.TITLE) InstanceRepository(org.folio.circulation.infrastructure.storage.inventory.InstanceRepository) CreateRequestRepositories(org.folio.circulation.domain.CreateRequestRepositories) RequestRepository(org.folio.circulation.infrastructure.storage.requests.RequestRepository) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) HttpClient(io.vertx.core.http.HttpClient) Clients(org.folio.circulation.support.Clients) ClosedRequestValidator(org.folio.circulation.domain.validation.ClosedRequestValidator) WebContext(org.folio.circulation.support.http.server.WebContext) Request(org.folio.circulation.domain.Request) FailFastErrorHandler(org.folio.circulation.resources.handlers.error.FailFastErrorHandler) MoveRequestProcessAdapter(org.folio.circulation.domain.MoveRequestProcessAdapter) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) UpdateUponRequest(org.folio.circulation.domain.UpdateUponRequest) RequestAndRelatedRecords(org.folio.circulation.domain.RequestAndRelatedRecords) OkapiPermissions(org.folio.circulation.support.http.OkapiPermissions) MoveRequestService(org.folio.circulation.domain.MoveRequestService) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) RequestType(org.folio.circulation.domain.RequestType) MultipleRecords(org.folio.circulation.domain.MultipleRecords) ItemByInstanceIdFinder(org.folio.circulation.storage.ItemByInstanceIdFinder) MappingFunctions.toFixedValue(org.folio.circulation.support.results.MappingFunctions.toFixedValue) UpdateLoan(org.folio.circulation.domain.UpdateLoan) ProxyRelationshipValidator(org.folio.circulation.domain.validation.ProxyRelationshipValidator) WebContext(org.folio.circulation.support.http.server.WebContext) FailFastErrorHandler(org.folio.circulation.resources.handlers.error.FailFastErrorHandler) CreateRequestRepositories(org.folio.circulation.domain.CreateRequestRepositories) ItemByInstanceIdFinder(org.folio.circulation.storage.ItemByInstanceIdFinder) ServicePointRepository(org.folio.circulation.infrastructure.storage.ServicePointRepository) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) UpdateLoan(org.folio.circulation.domain.UpdateLoan) CreateRequestService(org.folio.circulation.domain.CreateRequestService) LoanPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository) ServicePointPickupLocationValidator(org.folio.circulation.domain.validation.ServicePointPickupLocationValidator) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) UpdateRequestService(org.folio.circulation.domain.UpdateRequestService) EventPublisher(org.folio.circulation.services.EventPublisher) RequestPolicyRepository(org.folio.circulation.infrastructure.storage.requests.RequestPolicyRepository) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) RequestLoanValidator(org.folio.circulation.domain.validation.RequestLoanValidator) ClosedRequestValidator(org.folio.circulation.domain.validation.ClosedRequestValidator) UpdateItem(org.folio.circulation.domain.UpdateItem) InstanceRepository(org.folio.circulation.infrastructure.storage.inventory.InstanceRepository) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) UpdateUponRequest(org.folio.circulation.domain.UpdateUponRequest)

Example 2 with RequestScheduledNoticeService

use of org.folio.circulation.domain.notice.schedule.RequestScheduledNoticeService 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)

Aggregations

HttpClient (io.vertx.core.http.HttpClient)2 Router (io.vertx.ext.web.Router)2 RoutingContext (io.vertx.ext.web.RoutingContext)2 RequestScheduledNoticeService (org.folio.circulation.domain.notice.schedule.RequestScheduledNoticeService)2 ConfigurationRepository (org.folio.circulation.infrastructure.storage.ConfigurationRepository)2 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)2 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)2 RequestQueueRepository (org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository)2 RequestRepository (org.folio.circulation.infrastructure.storage.requests.RequestRepository)2 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)2 EventPublisher (org.folio.circulation.services.EventPublisher)2 Clients (org.folio.circulation.support.Clients)2 ValidationErrorFailure.singleValidationError (org.folio.circulation.support.ValidationErrorFailure.singleValidationError)2 WebContext (org.folio.circulation.support.http.server.WebContext)2 JsonObject (io.vertx.core.json.JsonObject)1 CheckInContext (org.folio.circulation.domain.CheckInContext)1 CreateRequestRepositories (org.folio.circulation.domain.CreateRequestRepositories)1 CreateRequestService (org.folio.circulation.domain.CreateRequestService)1 Item (org.folio.circulation.domain.Item)1 MoveRequestProcessAdapter (org.folio.circulation.domain.MoveRequestProcessAdapter)1