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);
}
Aggregations