use of org.folio.circulation.resources.context.ReorderRequestContext 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);
}
use of org.folio.circulation.resources.context.ReorderRequestContext in project mod-circulation by folio-org.
the class UpdateRequestQueueTest method reorderShouldFailWhenBatchUpdateFails.
@Test
void reorderShouldFailWhenBatchUpdateFails() throws Exception {
ReorderRequestContext reorderContext = createReorderContext();
CompletableFuture<Result<ReorderRequestContext>> completableFutureResult = updateRequestQueue.onReorder(succeeded(reorderContext));
assertFailedOnFailureResponse(completableFutureResult);
}
use of org.folio.circulation.resources.context.ReorderRequestContext in project mod-circulation by folio-org.
the class UpdateRequestQueueTest method createReorderContext.
private ReorderRequestContext createReorderContext() {
UUID itemId = UUID.randomUUID();
RequestQueue requestQueue = createRequestQueue(itemId, 4);
ReorderQueueRequest reorderQueueRequest = new ReorderQueueRequest();
reorderQueueRequest.setReorderedQueue(new ArrayList<>());
final int requestCount = requestQueue.getRequests().size();
for (Request request : requestQueue.getRequests()) {
ReorderRequest reorderRequest = new ReorderRequest();
reorderQueueRequest.getReorderedQueue().add(reorderRequest);
reorderRequest.setId(request.getId());
// i.e. reverse positions
reorderRequest.setNewPosition(requestCount - request.getPosition());
}
return new ReorderRequestContext(null, itemId.toString(), reorderQueueRequest).withRequestQueue(requestQueue);
}
Aggregations