Search in sources :

Example 1 with JsonHttpResponse

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);
}
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 2 with JsonHttpResponse

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

Example 3 with JsonHttpResponse

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);
}
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) RequestRepresentation(org.folio.circulation.domain.RequestRepresentation) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) Result(org.folio.circulation.support.results.Result) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository)

Example 4 with JsonHttpResponse

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);
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) UpdateRequestQueue(org.folio.circulation.domain.UpdateRequestQueue) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) LoanPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository) ValidationErrorFailure.singleValidationError(org.folio.circulation.support.ValidationErrorFailure.singleValidationError) UpdateItem(org.folio.circulation.domain.UpdateItem) RoutingContext(io.vertx.ext.web.RoutingContext) Item(org.folio.circulation.domain.Item) LoanAndRelatedRecords(org.folio.circulation.domain.LoanAndRelatedRecords) ServicePointRepository(org.folio.circulation.infrastructure.storage.ServicePointRepository) AccountRepository(org.folio.circulation.infrastructure.storage.feesandfines.AccountRepository) LostItemPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LostItemPolicyRepository) JsonObject(io.vertx.core.json.JsonObject) LoanScheduledNoticeService(org.folio.circulation.domain.notice.schedule.LoanScheduledNoticeService) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) ChangeDueDateValidator(org.folio.circulation.domain.validation.ChangeDueDateValidator) Result.of(org.folio.circulation.support.results.Result.of) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) MethodHandles(java.lang.invoke.MethodHandles) Loan(org.folio.circulation.domain.Loan) RequestedByAnotherPatronValidator(org.folio.circulation.domain.validation.RequestedByAnotherPatronValidator) ITEM_ID(org.folio.circulation.domain.representations.LoanProperties.ITEM_ID) ServicePointLoanLocationValidator(org.folio.circulation.domain.validation.ServicePointLoanLocationValidator) Result(org.folio.circulation.support.results.Result) EventPublisher(org.folio.circulation.services.EventPublisher) LoanRepresentation(org.folio.circulation.domain.LoanRepresentation) Logger(org.apache.logging.log4j.Logger) ItemStatusValidator(org.folio.circulation.domain.validation.ItemStatusValidator) LoanService(org.folio.circulation.domain.LoanService) 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) OverdueFinePolicyRepository(org.folio.circulation.infrastructure.storage.loans.OverdueFinePolicyRepository) WebContext(org.folio.circulation.support.http.server.WebContext) CompletableFuture(java.util.concurrent.CompletableFuture) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) ItemNotFoundValidator(org.folio.circulation.domain.validation.ItemNotFoundValidator) RequestQueue(org.folio.circulation.domain.RequestQueue) DateTimeUtil.isSameMillis(org.folio.circulation.support.utils.DateTimeUtil.isSameMillis) ValidationErrorFailure(org.folio.circulation.support.ValidationErrorFailure) MappingFunctions.toFixedValue(org.folio.circulation.support.results.MappingFunctions.toFixedValue) User(org.folio.circulation.domain.User) AlreadyCheckedOutValidator(org.folio.circulation.domain.validation.AlreadyCheckedOutValidator) ProxyRelationshipValidator(org.folio.circulation.domain.validation.ProxyRelationshipValidator) PatronGroupRepository(org.folio.circulation.infrastructure.storage.users.PatronGroupRepository) LogManager(org.apache.logging.log4j.LogManager) WebContext(org.folio.circulation.support.http.server.WebContext) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) AccountRepository(org.folio.circulation.infrastructure.storage.feesandfines.AccountRepository) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ServicePointRepository(org.folio.circulation.infrastructure.storage.ServicePointRepository) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) LostItemPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LostItemPolicyRepository) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) LoanRepresentation(org.folio.circulation.domain.LoanRepresentation) LoanPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository) OverdueFinePolicyRepository(org.folio.circulation.infrastructure.storage.loans.OverdueFinePolicyRepository) PatronGroupRepository(org.folio.circulation.infrastructure.storage.users.PatronGroupRepository)

Example 5 with JsonHttpResponse

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);
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) RecordFetching.findWithMultipleCqlIndexValues(org.folio.circulation.support.fetching.RecordFetching.findWithMultipleCqlIndexValues) Location(org.folio.circulation.domain.Location) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) WebContext(org.folio.circulation.support.http.server.WebContext) Request(org.folio.circulation.domain.Request) Router(io.vertx.ext.web.Router) CompletableFuture(java.util.concurrent.CompletableFuture) RoutingContext(io.vertx.ext.web.RoutingContext) ItemStatus(org.folio.circulation.domain.ItemStatus) StringUtils(org.apache.commons.lang3.StringUtils) Item(org.folio.circulation.domain.Item) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) LocationRepository(org.folio.circulation.infrastructure.storage.inventory.LocationRepository) CqlQuery.exactMatch(org.folio.circulation.support.http.client.CqlQuery.exactMatch) Collectors.toMap(java.util.stream.Collectors.toMap) ServicePointRepository(org.folio.circulation.infrastructure.storage.ServicePointRepository) MultipleCqlIndexValuesCriteria.byIndex(org.folio.circulation.support.fetching.MultipleCqlIndexValuesCriteria.byIndex) Map(java.util.Map) PageLimit(org.folio.circulation.support.http.client.PageLimit) TemplateContextUtil(org.folio.circulation.domain.notice.TemplateContextUtil) JsonObject(io.vertx.core.json.JsonObject) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) Collectors.toSet(java.util.stream.Collectors.toSet) RecordFetching.findWithCqlQuery(org.folio.circulation.support.fetching.RecordFetching.findWithCqlQuery) RequestType(org.folio.circulation.domain.RequestType) MultipleRecords(org.folio.circulation.domain.MultipleRecords) Collections.emptyList(java.util.Collections.emptyList) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) Collection(java.util.Collection) Set(java.util.Set) UUID(java.util.UUID) Result(org.folio.circulation.support.results.Result) Collectors(java.util.stream.Collectors) ResultBinding.flatMapResult(org.folio.circulation.support.results.ResultBinding.flatMapResult) RouteRegistration(org.folio.circulation.support.RouteRegistration) List(java.util.List) AddressTypeRepository(org.folio.circulation.infrastructure.storage.users.AddressTypeRepository) RequestStatus(org.folio.circulation.domain.RequestStatus) Function.identity(java.util.function.Function.identity) CqlQuery(org.folio.circulation.support.http.client.CqlQuery) HttpClient(io.vertx.core.http.HttpClient) WebContext(org.folio.circulation.support.http.server.WebContext) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) Clients(org.folio.circulation.support.Clients) ServicePointRepository(org.folio.circulation.infrastructure.storage.ServicePointRepository) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) AddressTypeRepository(org.folio.circulation.infrastructure.storage.users.AddressTypeRepository) UUID(java.util.UUID)

Aggregations

HttpClient (io.vertx.core.http.HttpClient)13 RoutingContext (io.vertx.ext.web.RoutingContext)13 Clients (org.folio.circulation.support.Clients)13 JsonHttpResponse (org.folio.circulation.support.http.server.JsonHttpResponse)13 WebContext (org.folio.circulation.support.http.server.WebContext)13 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)11 JsonObject (io.vertx.core.json.JsonObject)10 Router (io.vertx.ext.web.Router)10 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)10 CompletableFuture (java.util.concurrent.CompletableFuture)9 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)9 EventPublisher (org.folio.circulation.services.EventPublisher)9 Result (org.folio.circulation.support.results.Result)9 ServicePointRepository (org.folio.circulation.infrastructure.storage.ServicePointRepository)8 RouteRegistration (org.folio.circulation.support.RouteRegistration)8 Result.succeeded (org.folio.circulation.support.results.Result.succeeded)8 MethodHandles (java.lang.invoke.MethodHandles)7 LogManager (org.apache.logging.log4j.LogManager)7 Logger (org.apache.logging.log4j.Logger)7 UpdateRequestQueue (org.folio.circulation.domain.UpdateRequestQueue)7