Search in sources :

Example 16 with Clients

use of org.folio.circulation.support.Clients in project mod-circulation by folio-org.

the class ScheduledNoticeProcessingResource method process.

private void process(RoutingContext routingContext) {
    final WebContext context = new WebContext(routingContext);
    final Clients clients = Clients.create(context, client);
    final ScheduledNoticesRepository scheduledNoticesRepository = ScheduledNoticesRepository.using(clients);
    final ConfigurationRepository configurationRepository = new ConfigurationRepository(clients);
    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);
    safelyInitialise(configurationRepository::lookupSchedulerNoticesProcessingLimit).thenCompose(r -> r.after(limit -> findNoticesToSend(configurationRepository, scheduledNoticesRepository, limit))).thenCompose(r -> r.after(notices -> handleNotices(clients, requestRepository, loanRepository, notices))).thenApply(r -> r.map(toFixedValue(NoContentResponse::noContent))).exceptionally(CommonFailures::failedDueToServerError).thenAccept(context::writeResultToHttpResponse);
}
Also used : ScheduledNoticesRepository(org.folio.circulation.infrastructure.storage.notices.ScheduledNoticesRepository) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) CommonFailures(org.folio.circulation.support.results.CommonFailures) MultipleRecords(org.folio.circulation.domain.MultipleRecords) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) WebContext(org.folio.circulation.support.http.server.WebContext) Router(io.vertx.ext.web.Router) MappingFunctions.toFixedValue(org.folio.circulation.support.results.MappingFunctions.toFixedValue) CompletableFuture(java.util.concurrent.CompletableFuture) RoutingContext(io.vertx.ext.web.RoutingContext) Result(org.folio.circulation.support.results.Result) RouteRegistration(org.folio.circulation.support.RouteRegistration) PageLimit(org.folio.circulation.support.http.client.PageLimit) AsynchronousResultBindings.safelyInitialise(org.folio.circulation.support.results.AsynchronousResultBindings.safelyInitialise) ScheduledNotice(org.folio.circulation.domain.notice.schedule.ScheduledNotice) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) RequestRepository(org.folio.circulation.infrastructure.storage.requests.RequestRepository) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) HttpClient(io.vertx.core.http.HttpClient) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) WebContext(org.folio.circulation.support.http.server.WebContext) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) ScheduledNoticesRepository(org.folio.circulation.infrastructure.storage.notices.ScheduledNoticesRepository) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository)

Example 17 with Clients

use of org.folio.circulation.support.Clients in project mod-circulation by folio-org.

the class ScheduledAgeToLostResource method scheduledAgeToLost.

private void scheduledAgeToLost(RoutingContext routingContext) {
    final WebContext 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 MarkOverdueLoansAsAgedLostService ageToLostService = new MarkOverdueLoansAsAgedLostService(clients, itemRepository, loanRepository);
    ageToLostService.processAgeToLost().thenApply(r -> r.map(toFixedValue(NoContentResponse::noContent))).thenAccept(context::writeResultToHttpResponse);
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) WebContext(org.folio.circulation.support.http.server.WebContext) Router(io.vertx.ext.web.Router) MappingFunctions.toFixedValue(org.folio.circulation.support.results.MappingFunctions.toFixedValue) Resource(org.folio.circulation.resources.Resource) RoutingContext(io.vertx.ext.web.RoutingContext) RouteRegistration(org.folio.circulation.support.RouteRegistration) MarkOverdueLoansAsAgedLostService(org.folio.circulation.services.agedtolost.MarkOverdueLoansAsAgedLostService) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) HttpClient(io.vertx.core.http.HttpClient) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) WebContext(org.folio.circulation.support.http.server.WebContext) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) MarkOverdueLoansAsAgedLostService(org.folio.circulation.services.agedtolost.MarkOverdueLoansAsAgedLostService) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository)

Example 18 with Clients

use of org.folio.circulation.support.Clients in project mod-circulation by folio-org.

the class UpdateRequestQueueTest method createServerErrorMockBatchRequestClient.

private Clients createServerErrorMockBatchRequestClient() {
    Clients clients = mock(Clients.class);
    CollectionResourceClient requestBatchClient = mock(CollectionResourceClient.class);
    when(clients.requestsBatchStorage()).thenReturn(requestBatchClient);
    when(requestBatchClient.post(any(JsonObject.class))).thenAnswer(rq -> completedFuture(of(() -> serverErrorBatchResponse)));
    return clients;
}
Also used : CollectionResourceClient(org.folio.circulation.support.CollectionResourceClient) JsonObject(io.vertx.core.json.JsonObject) Clients(org.folio.circulation.support.Clients)

Example 19 with Clients

use of org.folio.circulation.support.Clients in project mod-circulation by folio-org.

the class UpdateRequestQueueTest method setUp.

@BeforeEach
public void setUp() {
    Clients clients = createServerErrorMockBatchRequestClient();
    final ItemRepository itemRepository = new ItemRepository(clients);
    final UserRepository userRepository = new UserRepository(clients);
    final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
    requestRepository = mock(RequestRepository.class);
    requestQueueRepository = spy(new RequestQueueRepository(RequestRepository.using(clients, itemRepository, userRepository, loanRepository)));
    updateRequestQueue = new UpdateRequestQueue(requestQueueRepository, requestRepository, null, null);
}
Also used : ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) RequestRepository(org.folio.circulation.infrastructure.storage.requests.RequestRepository) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 20 with Clients

use of org.folio.circulation.support.Clients in project mod-circulation by folio-org.

the class AbstractCirculationRulesEngineResource method applyRules.

private <T> void applyRules(RoutingContext routingContext, BiFunction<CirculationRulesProcessor, RulesExecutionParameters, CompletableFuture<Result<T>>> triggerFunction, Function<T, CompletableFuture<Result<JsonObject>>> mapToJson) {
    val request = routingContext.request();
    if (invalidApplyParameters(request)) {
        return;
    }
    final WebContext context = new WebContext(routingContext);
    final Clients clients = Clients.create(context, client);
    triggerFunction.apply(clients.circulationRulesProcessor(), forRequest(context)).thenCompose(r -> r.after(mapToJson)).thenApply(r -> r.map(JsonHttpResponse::ok)).thenAccept(context::writeResultToHttpResponse);
}
Also used : lombok.val(lombok.val) Clients(org.folio.circulation.support.Clients) ClientErrorResponse(org.folio.circulation.support.http.server.ClientErrorResponse) HttpServerRequest(io.vertx.core.http.HttpServerRequest) CirculationRulesProcessor(org.folio.circulation.rules.CirculationRulesProcessor) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) MethodHandles(java.lang.invoke.MethodHandles) BiFunction(java.util.function.BiFunction) WebContext(org.folio.circulation.support.http.server.WebContext) lombok.val(lombok.val) Router(io.vertx.ext.web.Router) CompletableFuture(java.util.concurrent.CompletableFuture) RoutingContext(io.vertx.ext.web.RoutingContext) Result(org.folio.circulation.support.results.Result) Function(java.util.function.Function) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) JsonArray(io.vertx.core.json.JsonArray) RulesExecutionParameters.forRequest(org.folio.circulation.rules.RulesExecutionParameters.forRequest) Logger(org.apache.logging.log4j.Logger) CirculationRuleMatch(org.folio.circulation.rules.CirculationRuleMatch) RulesExecutionParameters(org.folio.circulation.rules.RulesExecutionParameters) JsonObject(io.vertx.core.json.JsonObject) LogManager(org.apache.logging.log4j.LogManager) 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)

Aggregations

Clients (org.folio.circulation.support.Clients)41 WebContext (org.folio.circulation.support.http.server.WebContext)38 HttpClient (io.vertx.core.http.HttpClient)36 RoutingContext (io.vertx.ext.web.RoutingContext)36 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)33 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)32 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)31 Result (org.folio.circulation.support.results.Result)31 Router (io.vertx.ext.web.Router)30 CompletableFuture (java.util.concurrent.CompletableFuture)29 JsonObject (io.vertx.core.json.JsonObject)26 EventPublisher (org.folio.circulation.services.EventPublisher)26 Result.succeeded (org.folio.circulation.support.results.Result.succeeded)23 RouteRegistration (org.folio.circulation.support.RouteRegistration)21 ValidationErrorFailure.singleValidationError (org.folio.circulation.support.ValidationErrorFailure.singleValidationError)21 Loan (org.folio.circulation.domain.Loan)19 RequestRepository (org.folio.circulation.infrastructure.storage.requests.RequestRepository)19 JsonHttpResponse (org.folio.circulation.support.http.server.JsonHttpResponse)19 NoContentResponse (org.folio.circulation.support.http.server.NoContentResponse)19 MappingFunctions.toFixedValue (org.folio.circulation.support.results.MappingFunctions.toFixedValue)19