Search in sources :

Example 1 with RequestQueueValidation

use of org.folio.circulation.domain.validation.RequestQueueValidation in project mod-circulation by folio-org.

the class RequestQueueResource method reorderQueue.

private void reorderQueue(RoutingContext routingContext, RequestQueueType requestQueueType) {
    String idParamValue = getIdParameterValueByQueueType(routingContext, requestQueueType);
    ReorderRequestContext reorderContext = new ReorderRequestContext(requestQueueType, idParamValue, routingContext.getBodyAsJson().mapTo(ReorderQueueRequest.class));
    final EventPublisher eventPublisher = new EventPublisher(routingContext);
    final var context = new WebContext(routingContext);
    final var 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 configurationRepository = new ConfigurationRepository(clients);
    final var requestQueueRepository = new RequestQueueRepository(requestRepository);
    final UpdateRequestQueue updateRequestQueue = new UpdateRequestQueue(requestQueueRepository, requestRepository, new ServicePointRepository(clients), configurationRepository);
    getRequestQueueByType(routingContext, requestQueueType, requestQueueRepository);
    validateTlrFeatureStatus(configurationRepository, requestQueueType, idParamValue).thenCompose(r -> r.after(tlrSettings -> getRequestQueueByType(routingContext, requestQueueType, requestQueueRepository))).thenApply(r -> r.map(reorderContext::withRequestQueue)).thenApply(RequestQueueValidation::queueIsFound).thenApply(RequestQueueValidation::positionsAreSequential).thenApply(RequestQueueValidation::queueIsConsistent).thenApply(RequestQueueValidation::pageRequestsPositioning).thenApply(RequestQueueValidation::fulfillingRequestsPositioning).thenCompose(updateRequestQueue::onReorder).thenApply(q -> publishReorderedQueue(eventPublisher, q)).thenCompose(r -> r.after(this::toRepresentation)).thenApply(r -> r.map(JsonHttpResponse::ok)).thenAccept(context::writeResultToHttpResponse);
}
Also used : FOR_INSTANCE(org.folio.circulation.resources.context.RequestQueueType.FOR_INSTANCE) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) 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) WebContext(org.folio.circulation.support.http.server.WebContext) Request(org.folio.circulation.domain.Request) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) 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) ReorderRequestContext(org.folio.circulation.resources.context.ReorderRequestContext) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) TlrSettingsConfiguration(org.folio.circulation.domain.configuration.TlrSettingsConfiguration) RequestUpdateLogEventMapper.mapToRequestLogEventJson(org.folio.circulation.domain.representations.logs.RequestUpdateLogEventMapper.mapToRequestLogEventJson) ServicePointRepository(org.folio.circulation.infrastructure.storage.ServicePointRepository) RequestQueueType(org.folio.circulation.resources.context.RequestQueueType) RequestQueueValidation(org.folio.circulation.domain.validation.RequestQueueValidation) JsonObject(io.vertx.core.json.JsonObject) RequestQueue(org.folio.circulation.domain.RequestQueue) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) RequestRepresentation(org.folio.circulation.domain.RequestRepresentation) LogEventType(org.folio.circulation.domain.representations.logs.LogEventType) MultipleRecords(org.folio.circulation.domain.MultipleRecords) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) Result(org.folio.circulation.support.results.Result) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) EventPublisher(org.folio.circulation.services.EventPublisher) FOR_ITEM(org.folio.circulation.resources.context.RequestQueueType.FOR_ITEM) RouteRegistration(org.folio.circulation.support.RouteRegistration) List(java.util.List) ReorderQueueRequest(org.folio.circulation.domain.reorder.ReorderQueueRequest) RequestRepository(org.folio.circulation.infrastructure.storage.requests.RequestRepository) HttpClient(io.vertx.core.http.HttpClient) WebContext(org.folio.circulation.support.http.server.WebContext) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) EventPublisher(org.folio.circulation.services.EventPublisher) RequestQueueValidation(org.folio.circulation.domain.validation.RequestQueueValidation) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) UpdateRequestQueue(org.folio.circulation.domain.UpdateRequestQueue) ServicePointRepository(org.folio.circulation.infrastructure.storage.ServicePointRepository) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) ReorderRequestContext(org.folio.circulation.resources.context.ReorderRequestContext) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) ReorderQueueRequest(org.folio.circulation.domain.reorder.ReorderQueueRequest)

Aggregations

HttpClient (io.vertx.core.http.HttpClient)1 JsonObject (io.vertx.core.json.JsonObject)1 Router (io.vertx.ext.web.Router)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 String.format (java.lang.String.format)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 Collectors (java.util.stream.Collectors)1 MultipleRecords (org.folio.circulation.domain.MultipleRecords)1 Request (org.folio.circulation.domain.Request)1 RequestQueue (org.folio.circulation.domain.RequestQueue)1 RequestRepresentation (org.folio.circulation.domain.RequestRepresentation)1 UpdateRequestQueue (org.folio.circulation.domain.UpdateRequestQueue)1 TlrSettingsConfiguration (org.folio.circulation.domain.configuration.TlrSettingsConfiguration)1 ReorderQueueRequest (org.folio.circulation.domain.reorder.ReorderQueueRequest)1 LogEventType (org.folio.circulation.domain.representations.logs.LogEventType)1 RequestUpdateLogEventMapper.mapToRequestLogEventJson (org.folio.circulation.domain.representations.logs.RequestUpdateLogEventMapper.mapToRequestLogEventJson)1 RequestQueueValidation (org.folio.circulation.domain.validation.RequestQueueValidation)1 ConfigurationRepository (org.folio.circulation.infrastructure.storage.ConfigurationRepository)1