Search in sources :

Example 1 with ItemByInstanceIdFinder

use of org.folio.circulation.storage.ItemByInstanceIdFinder in project mod-circulation by folio-org.

the class RequestCollectionResource method create.

@Override
void create(RoutingContext routingContext) {
    final var context = new WebContext(routingContext);
    final var clients = Clients.create(context, client);
    final var representation = routingContext.getBodyAsJson();
    final var eventPublisher = new EventPublisher(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 loanPolicyRepository = new LoanPolicyRepository(clients);
    final var requestNoticeSender = createRequestNoticeSender(clients, representation);
    final var configurationRepository = new ConfigurationRepository(clients);
    final var updateUponRequest = new UpdateUponRequest(new UpdateItem(itemRepository), new UpdateLoan(clients, loanRepository, loanPolicyRepository), UpdateRequestQueue.using(clients, requestRepository, new RequestQueueRepository(requestRepository)));
    final var okapiPermissions = OkapiPermissions.from(context.getHeaders());
    final var blockOverrides = BlockOverrides.fromRequest(representation);
    final var errorHandler = new OverridingErrorHandler(okapiPermissions);
    final var requestBlocksValidators = new RequestBlockValidators(blockOverrides, okapiPermissions, clients);
    final var requestLoanValidator = new RequestLoanValidator(new ItemByInstanceIdFinder(clients.holdingsStorage(), itemRepository), loanRepository);
    final var createRequestService = new CreateRequestService(new CreateRequestRepositories(requestRepository, new RequestPolicyRepository(clients), configurationRepository), updateUponRequest, requestLoanValidator, requestNoticeSender, requestBlocksValidators, eventPublisher, errorHandler);
    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 scheduledNoticeService = RequestScheduledNoticeService.using(clients);
    fromFutureResult(requestFromRepresentationService.getRequestFrom(Request.Operation.CREATE, representation)).flatMapFuture(createRequestService::createRequest).onSuccess(scheduledNoticeService::scheduleRequestNotices).onSuccess(records -> eventPublisher.publishDueDateChangedEvent(records, loanRepository)).map(RequestAndRelatedRecords::getRequest).map(new RequestRepresentation()::extendedRepresentation).map(JsonHttpResponse::created).onComplete(context::write, context::write);
}
Also used : WebContext(org.folio.circulation.support.http.server.WebContext) 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) EventPublisher(org.folio.circulation.services.EventPublisher) RequestRepresentation(org.folio.circulation.domain.RequestRepresentation) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) 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) UpdateItem(org.folio.circulation.domain.UpdateItem) RequestBlockValidators.regularRequestBlockValidators(org.folio.circulation.resources.RequestBlockValidators.regularRequestBlockValidators) InstanceRepository(org.folio.circulation.infrastructure.storage.inventory.InstanceRepository) UpdateUponRequest(org.folio.circulation.domain.UpdateUponRequest) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository)

Example 2 with ItemByInstanceIdFinder

use of org.folio.circulation.storage.ItemByInstanceIdFinder 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 3 with ItemByInstanceIdFinder

use of org.folio.circulation.storage.ItemByInstanceIdFinder in project mod-circulation by folio-org.

the class RequestCollectionResource method move.

void move(RoutingContext routingContext) {
    final var context = new WebContext(routingContext);
    final var clients = Clients.create(context, client);
    final var representation = routingContext.getBodyAsJson();
    final var 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 loanPolicyRepository = new LoanPolicyRepository(clients);
    final var configurationRepository = new ConfigurationRepository(clients);
    final var updateUponRequest = new UpdateUponRequest(new UpdateItem(itemRepository), new UpdateLoan(clients, loanRepository, loanPolicyRepository), UpdateRequestQueue.using(clients, requestRepository, requestQueueRepository));
    final var moveRequestProcessAdapter = new MoveRequestProcessAdapter(itemRepository, loanRepository, requestRepository);
    final var eventPublisher = new EventPublisher(routingContext);
    final var moveRequestService = new MoveRequestService(requestRepository, new RequestPolicyRepository(clients), updateUponRequest, moveRequestProcessAdapter, new RequestLoanValidator(new ItemByInstanceIdFinder(clients.holdingsStorage(), itemRepository), loanRepository), RequestNoticeSender.using(clients), configurationRepository, eventPublisher, requestQueueRepository);
    fromFutureResult(requestRepository.getById(id)).map(RequestAndRelatedRecords::new).map(request -> asMove(request, representation)).flatMapFuture(move -> moveRequestService.moveRequest(move, move.getOriginalRequest())).onSuccess(records -> eventPublisher.publishDueDateChangedEvent(records, loanRepository)).map(RequestAndRelatedRecords::getRequest).map(new RequestRepresentation()::extendedRepresentation).map(JsonHttpResponse::ok).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) EventPublisher(org.folio.circulation.services.EventPublisher) RequestRepresentation(org.folio.circulation.domain.RequestRepresentation) MoveRequestService(org.folio.circulation.domain.MoveRequestService) ItemByInstanceIdFinder(org.folio.circulation.storage.ItemByInstanceIdFinder) 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) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) UpdateLoan(org.folio.circulation.domain.UpdateLoan) UpdateItem(org.folio.circulation.domain.UpdateItem) MoveRequestProcessAdapter(org.folio.circulation.domain.MoveRequestProcessAdapter) LoanPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) UpdateUponRequest(org.folio.circulation.domain.UpdateUponRequest)

Example 4 with ItemByInstanceIdFinder

use of org.folio.circulation.storage.ItemByInstanceIdFinder in project mod-circulation by folio-org.

the class RequestByInstanceIdResource method createInstanceLevelRequests.

private void createInstanceLevelRequests(RoutingContext routingContext) {
    final WebContext context = new WebContext(routingContext);
    final Clients clients = Clients.create(context, client);
    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 itemFinder = new ItemByInstanceIdFinder(clients.holdingsStorage(), itemRepository);
    final var eventPublisher = new EventPublisher(routingContext);
    final var requestBody = routingContext.getBodyAsJson();
    new ConfigurationRepository(clients).lookupTlrSettings().thenCompose(r -> r.after(config -> buildAndPlaceRequests(clients, eventPublisher, itemRepository, loanRepository, requestRepository, requestQueueRepository, userRepository, itemFinder, config, requestBody))).thenApply(r -> r.map(RequestAndRelatedRecords::getRequest)).thenApply(r -> r.map(new RequestRepresentation()::extendedRepresentation)).thenApply(r -> r.map(JsonHttpResponse::created)).thenAccept(context::writeResultToHttpResponse).exceptionally(err -> {
        String reason = "Error processing instance-level request";
        log.error(reason, err);
        ServerErrorResponse.internalError(routingContext.response(), reason);
        return null;
    });
}
Also used : HOLD(org.folio.circulation.domain.RequestType.HOLD) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) UpdateRequestQueue(org.folio.circulation.domain.UpdateRequestQueue) CreateRequestService(org.folio.circulation.domain.CreateRequestService) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) InstanceRequestRelatedRecords(org.folio.circulation.domain.InstanceRequestRelatedRecords) ZonedDateTime(java.time.ZonedDateTime) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) LoanPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository) ServerErrorResponse(org.folio.circulation.support.http.server.ServerErrorResponse) 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) Item(org.folio.circulation.domain.Item) REQUEST_LEVEL(org.folio.circulation.domain.representations.RequestProperties.REQUEST_LEVEL) ServicePointRepository(org.folio.circulation.infrastructure.storage.ServicePointRepository) HttpFailure(org.folio.circulation.support.HttpFailure) Map(java.util.Map) CommonFailures.failedDueToServerError(org.folio.circulation.support.results.CommonFailures.failedDueToServerError) 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) Result.of(org.folio.circulation.support.results.Result.of) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) Loan(org.folio.circulation.domain.Loan) RequestLoanValidator(org.folio.circulation.domain.validation.RequestLoanValidator) RequestPolicyRepository(org.folio.circulation.infrastructure.storage.requests.RequestPolicyRepository) UUID(java.util.UUID) ValidationError(org.folio.circulation.support.http.server.ValidationError) Result(org.folio.circulation.support.results.Result) Collectors(java.util.stream.Collectors) EventPublisher(org.folio.circulation.services.EventPublisher) Objects(java.util.Objects) PROXY_USER_ID(org.folio.circulation.domain.representations.RequestProperties.PROXY_USER_ID) ServicePointPickupLocationValidator(org.folio.circulation.domain.validation.ServicePointPickupLocationValidator) RouteRegistration(org.folio.circulation.support.RouteRegistration) List(java.util.List) PAGE(org.folio.circulation.domain.RequestType.PAGE) Logger(org.apache.logging.log4j.Logger) RECALL(org.folio.circulation.domain.RequestType.RECALL) HOLD_SHELF(org.folio.circulation.domain.RequestFulfilmentPreference.HOLD_SHELF) InstanceRepository(org.folio.circulation.infrastructure.storage.inventory.InstanceRepository) REQUEST_TYPE(org.folio.circulation.domain.representations.RequestProperties.REQUEST_TYPE) Optional(java.util.Optional) BadRequestFailure(org.folio.circulation.support.BadRequestFailure) FULFILMENT_PREFERENCE(org.folio.circulation.domain.representations.RequestProperties.FULFILMENT_PREFERENCE) CreateRequestRepositories(org.folio.circulation.domain.CreateRequestRepositories) RequestRepository(org.folio.circulation.infrastructure.storage.requests.RequestRepository) HttpClient(io.vertx.core.http.HttpClient) Clients(org.folio.circulation.support.Clients) WebContext(org.folio.circulation.support.http.server.WebContext) Request(org.folio.circulation.domain.Request) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) FailFastErrorHandler(org.folio.circulation.resources.handlers.error.FailFastErrorHandler) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) UpdateUponRequest(org.folio.circulation.domain.UpdateUponRequest) ArrayList(java.util.ArrayList) TlrSettingsConfiguration(org.folio.circulation.domain.configuration.TlrSettingsConfiguration) ForwardOnFailure(org.folio.circulation.support.ForwardOnFailure) RequestAndRelatedRecords(org.folio.circulation.domain.RequestAndRelatedRecords) RequestQueue(org.folio.circulation.domain.RequestQueue) REQUESTER_ID(org.folio.circulation.domain.representations.RequestProperties.REQUESTER_ID) LinkedList(java.util.LinkedList) RequestType(org.folio.circulation.domain.RequestType) RequestFulfilmentPreference(org.folio.circulation.domain.RequestFulfilmentPreference) ItemByInstanceIdFinder(org.folio.circulation.storage.ItemByInstanceIdFinder) ValidationErrorFailure(org.folio.circulation.support.ValidationErrorFailure) ServerErrorFailure(org.folio.circulation.support.ServerErrorFailure) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) ITEM_ID(org.folio.circulation.domain.representations.RequestProperties.ITEM_ID) ValidationErrorFailure.failedValidation(org.folio.circulation.support.ValidationErrorFailure.failedValidation) InstanceRequestItemsComparer.sortRequestQueues(org.folio.circulation.domain.InstanceRequestItemsComparer.sortRequestQueues) UpdateLoan(org.folio.circulation.domain.UpdateLoan) Collectors.toList(java.util.stream.Collectors.toList) RequestLevel(org.folio.circulation.domain.RequestLevel) ProxyRelationshipValidator(org.folio.circulation.domain.validation.ProxyRelationshipValidator) RequestByInstanceIdRequest(org.folio.circulation.domain.representations.RequestByInstanceIdRequest) LogManager(org.apache.logging.log4j.LogManager) WebContext(org.folio.circulation.support.http.server.WebContext) EventPublisher(org.folio.circulation.services.EventPublisher) RequestRepresentation(org.folio.circulation.domain.RequestRepresentation) ItemByInstanceIdFinder(org.folio.circulation.storage.ItemByInstanceIdFinder) 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) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository)

Example 5 with ItemByInstanceIdFinder

use of org.folio.circulation.storage.ItemByInstanceIdFinder in project mod-circulation by folio-org.

the class RequestByInstanceIdResource method placeRequest.

private CompletableFuture<Result<RequestAndRelatedRecords>> placeRequest(List<JsonObject> itemRequests, int startIndex, CreateRequestService createRequestService, Clients clients, LoanRepository loanRepository, List<String> errors, ItemRepository itemRepository, UserRepository userRepository, RequestQueueRepository requestQueueRepository) {
    log.debug("RequestByInstanceIdResource.placeRequest, startIndex={}, itemRequestSize={}", startIndex, itemRequests.size());
    if (startIndex >= itemRequests.size()) {
        String aggregateFailures = String.format("%n%s", String.join("%n", errors));
        return CompletableFuture.completedFuture(failedDueToServerError("Failed to place a request for the instance. Reasons: " + aggregateFailures));
    }
    JsonObject currentItemRequest = itemRequests.get(startIndex);
    final RequestFromRepresentationService requestFromRepresentationService = new RequestFromRepresentationService(new InstanceRepository(clients), itemRepository, requestQueueRepository, userRepository, loanRepository, new ServicePointRepository(clients), new ConfigurationRepository(clients), createProxyRelationshipValidator(currentItemRequest, clients), new ServicePointPickupLocationValidator(), new FailFastErrorHandler(), new ItemByInstanceIdFinder(clients.holdingsStorage(), itemRepository));
    return requestFromRepresentationService.getRequestFrom(Request.Operation.CREATE, currentItemRequest).thenCompose(r -> r.after(createRequestService::createRequest)).thenCompose(r -> {
        if (r.succeeded()) {
            log.debug("RequestByInstanceIdResource.placeRequest: succeeded creating request for item {}", currentItemRequest.getString(ITEM_ID));
            return CompletableFuture.completedFuture(r);
        } else {
            String reason = getErrorMessage(r.cause());
            errors.add(reason);
            log.debug("Failed to create request for item {} with reason: {}", currentItemRequest.getString(ITEM_ID), reason);
            return placeRequest(itemRequests, startIndex + 1, createRequestService, clients, loanRepository, errors, itemRepository, userRepository, requestQueueRepository);
        }
    });
}
Also used : HOLD(org.folio.circulation.domain.RequestType.HOLD) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) UpdateRequestQueue(org.folio.circulation.domain.UpdateRequestQueue) CreateRequestService(org.folio.circulation.domain.CreateRequestService) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) InstanceRequestRelatedRecords(org.folio.circulation.domain.InstanceRequestRelatedRecords) ZonedDateTime(java.time.ZonedDateTime) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) LoanPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository) ServerErrorResponse(org.folio.circulation.support.http.server.ServerErrorResponse) 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) Item(org.folio.circulation.domain.Item) REQUEST_LEVEL(org.folio.circulation.domain.representations.RequestProperties.REQUEST_LEVEL) ServicePointRepository(org.folio.circulation.infrastructure.storage.ServicePointRepository) HttpFailure(org.folio.circulation.support.HttpFailure) Map(java.util.Map) CommonFailures.failedDueToServerError(org.folio.circulation.support.results.CommonFailures.failedDueToServerError) 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) Result.of(org.folio.circulation.support.results.Result.of) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) Loan(org.folio.circulation.domain.Loan) RequestLoanValidator(org.folio.circulation.domain.validation.RequestLoanValidator) RequestPolicyRepository(org.folio.circulation.infrastructure.storage.requests.RequestPolicyRepository) UUID(java.util.UUID) ValidationError(org.folio.circulation.support.http.server.ValidationError) Result(org.folio.circulation.support.results.Result) Collectors(java.util.stream.Collectors) EventPublisher(org.folio.circulation.services.EventPublisher) Objects(java.util.Objects) PROXY_USER_ID(org.folio.circulation.domain.representations.RequestProperties.PROXY_USER_ID) ServicePointPickupLocationValidator(org.folio.circulation.domain.validation.ServicePointPickupLocationValidator) RouteRegistration(org.folio.circulation.support.RouteRegistration) List(java.util.List) PAGE(org.folio.circulation.domain.RequestType.PAGE) Logger(org.apache.logging.log4j.Logger) RECALL(org.folio.circulation.domain.RequestType.RECALL) HOLD_SHELF(org.folio.circulation.domain.RequestFulfilmentPreference.HOLD_SHELF) InstanceRepository(org.folio.circulation.infrastructure.storage.inventory.InstanceRepository) REQUEST_TYPE(org.folio.circulation.domain.representations.RequestProperties.REQUEST_TYPE) Optional(java.util.Optional) BadRequestFailure(org.folio.circulation.support.BadRequestFailure) FULFILMENT_PREFERENCE(org.folio.circulation.domain.representations.RequestProperties.FULFILMENT_PREFERENCE) CreateRequestRepositories(org.folio.circulation.domain.CreateRequestRepositories) RequestRepository(org.folio.circulation.infrastructure.storage.requests.RequestRepository) HttpClient(io.vertx.core.http.HttpClient) Clients(org.folio.circulation.support.Clients) WebContext(org.folio.circulation.support.http.server.WebContext) Request(org.folio.circulation.domain.Request) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) FailFastErrorHandler(org.folio.circulation.resources.handlers.error.FailFastErrorHandler) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) UpdateUponRequest(org.folio.circulation.domain.UpdateUponRequest) ArrayList(java.util.ArrayList) TlrSettingsConfiguration(org.folio.circulation.domain.configuration.TlrSettingsConfiguration) ForwardOnFailure(org.folio.circulation.support.ForwardOnFailure) RequestAndRelatedRecords(org.folio.circulation.domain.RequestAndRelatedRecords) RequestQueue(org.folio.circulation.domain.RequestQueue) REQUESTER_ID(org.folio.circulation.domain.representations.RequestProperties.REQUESTER_ID) LinkedList(java.util.LinkedList) RequestType(org.folio.circulation.domain.RequestType) RequestFulfilmentPreference(org.folio.circulation.domain.RequestFulfilmentPreference) ItemByInstanceIdFinder(org.folio.circulation.storage.ItemByInstanceIdFinder) ValidationErrorFailure(org.folio.circulation.support.ValidationErrorFailure) ServerErrorFailure(org.folio.circulation.support.ServerErrorFailure) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) ITEM_ID(org.folio.circulation.domain.representations.RequestProperties.ITEM_ID) ValidationErrorFailure.failedValidation(org.folio.circulation.support.ValidationErrorFailure.failedValidation) InstanceRequestItemsComparer.sortRequestQueues(org.folio.circulation.domain.InstanceRequestItemsComparer.sortRequestQueues) UpdateLoan(org.folio.circulation.domain.UpdateLoan) Collectors.toList(java.util.stream.Collectors.toList) RequestLevel(org.folio.circulation.domain.RequestLevel) ProxyRelationshipValidator(org.folio.circulation.domain.validation.ProxyRelationshipValidator) RequestByInstanceIdRequest(org.folio.circulation.domain.representations.RequestByInstanceIdRequest) LogManager(org.apache.logging.log4j.LogManager) FailFastErrorHandler(org.folio.circulation.resources.handlers.error.FailFastErrorHandler) JsonObject(io.vertx.core.json.JsonObject) InstanceRepository(org.folio.circulation.infrastructure.storage.inventory.InstanceRepository) ServicePointPickupLocationValidator(org.folio.circulation.domain.validation.ServicePointPickupLocationValidator) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) ItemByInstanceIdFinder(org.folio.circulation.storage.ItemByInstanceIdFinder) ServicePointRepository(org.folio.circulation.infrastructure.storage.ServicePointRepository)

Aggregations

CreateRequestRepositories (org.folio.circulation.domain.CreateRequestRepositories)5 CreateRequestService (org.folio.circulation.domain.CreateRequestService)5 RequestRepresentation (org.folio.circulation.domain.RequestRepresentation)5 UpdateItem (org.folio.circulation.domain.UpdateItem)5 UpdateLoan (org.folio.circulation.domain.UpdateLoan)5 HttpClient (io.vertx.core.http.HttpClient)4 JsonObject (io.vertx.core.json.JsonObject)4 Router (io.vertx.ext.web.Router)4 RoutingContext (io.vertx.ext.web.RoutingContext)4 Request (org.folio.circulation.domain.Request)4 RequestAndRelatedRecords (org.folio.circulation.domain.RequestAndRelatedRecords)4 RequestType (org.folio.circulation.domain.RequestType)4 UpdateRequestQueue (org.folio.circulation.domain.UpdateRequestQueue)4 UpdateUponRequest (org.folio.circulation.domain.UpdateUponRequest)3 RequestLoanValidator (org.folio.circulation.domain.validation.RequestLoanValidator)3 ServicePointPickupLocationValidator (org.folio.circulation.domain.validation.ServicePointPickupLocationValidator)3 ConfigurationRepository (org.folio.circulation.infrastructure.storage.ConfigurationRepository)3 ServicePointRepository (org.folio.circulation.infrastructure.storage.ServicePointRepository)3 InstanceRepository (org.folio.circulation.infrastructure.storage.inventory.InstanceRepository)3 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)3