use of org.folio.circulation.support.http.server.JsonHttpResponse 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);
}
use of org.folio.circulation.support.http.server.JsonHttpResponse 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.support.http.server.JsonHttpResponse in project mod-circulation by folio-org.
the class RequestQueueResource method getQueue.
private void getQueue(RoutingContext routingContext, RequestQueueType requestQueueType) {
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 requestQueueRepository = new RequestQueueRepository(RequestRepository.using(clients, itemRepository, userRepository, loanRepository));
final RequestRepresentation requestRepresentation = new RequestRepresentation();
CompletableFuture<Result<RequestQueue>> requestQueue = getRequestQueueByType(routingContext, requestQueueType, requestQueueRepository);
requestQueue.thenApply(r -> r.map(queue -> new MultipleRecords<>(queue.getRequests(), queue.size()))).thenApply(r -> r.map(requests -> requests.asJson(requestRepresentation::extendedRepresentation, "requests"))).thenApply(r -> r.map(JsonHttpResponse::ok)).thenAccept(context::writeResultToHttpResponse);
}
use of org.folio.circulation.support.http.server.JsonHttpResponse in project mod-circulation by folio-org.
the class LoanCollectionResource method get.
@Override
void get(RoutingContext routingContext) {
final WebContext context = new WebContext(routingContext);
final Clients clients = Clients.create(context, client);
final var userRepository = new UserRepository(clients);
final var loanRepository = new LoanRepository(clients, new ItemRepository(clients), userRepository);
final ServicePointRepository servicePointRepository = new ServicePointRepository(clients);
final LoanRepresentation loanRepresentation = new LoanRepresentation();
final LoanPolicyRepository loanPolicyRepository = new LoanPolicyRepository(clients);
final OverdueFinePolicyRepository overdueFinePolicyRepository = new OverdueFinePolicyRepository(clients);
final LostItemPolicyRepository lostItemPolicyRepository = new LostItemPolicyRepository(clients);
final AccountRepository accountRepository = new AccountRepository(clients);
final PatronGroupRepository patronGroupRepository = new PatronGroupRepository(clients);
String id = routingContext.request().getParam("id");
loanRepository.getById(id).thenComposeAsync(accountRepository::findAccountsAndActionsForLoan).thenComposeAsync(servicePointRepository::findServicePointsForLoan).thenComposeAsync(userRepository::findUserForLoan).thenComposeAsync(loanPolicyRepository::findPolicyForLoan).thenComposeAsync(overdueFinePolicyRepository::findOverdueFinePolicyForLoan).thenComposeAsync(lostItemPolicyRepository::findLostItemPolicyForLoan).thenComposeAsync(patronGroupRepository::findGroupForLoan).thenApply(loanResult -> loanResult.map(loanRepresentation::extendedLoan)).thenApply(r -> r.map(JsonHttpResponse::ok)).thenAccept(context::writeResultToHttpResponse);
}
use of org.folio.circulation.support.http.server.JsonHttpResponse in project mod-circulation by folio-org.
the class PickSlipsResource method getMany.
private void getMany(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 AddressTypeRepository addressTypeRepository = new AddressTypeRepository(clients);
final ServicePointRepository servicePointRepository = new ServicePointRepository(clients);
final UUID servicePointId = UUID.fromString(routingContext.request().getParam(SERVICE_POINT_ID_PARAM));
fetchLocationsForServicePoint(servicePointId, clients).thenComposeAsync(r -> r.after(locations -> fetchPagedItemsForLocations(locations, itemRepository, LocationRepository.using(clients, servicePointRepository)))).thenComposeAsync(r -> r.after(items -> fetchOpenPageRequestsForItems(items, clients))).thenComposeAsync(r -> r.after(userRepository::findUsersForRequests)).thenComposeAsync(r -> r.after(addressTypeRepository::findAddressTypesForRequests)).thenComposeAsync(r -> r.after(servicePointRepository::findServicePointsForRequests)).thenApply(flatMapResult(this::mapResultToJson)).thenApply(r -> r.map(JsonHttpResponse::ok)).thenAccept(context::writeResultToHttpResponse);
}
Aggregations