Search in sources :

Example 1 with CollectionResourceClient

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

the class CalendarRepositoryTest method shouldCreateCorrectRawQueryStringParameters.

@Test
void shouldCreateCorrectRawQueryStringParameters() {
    Clients clients = mock(Clients.class);
    CollectionResourceClient collectionResourceClient = mock(CollectionResourceClient.class);
    when(clients.calendarStorageClient()).thenReturn(collectionResourceClient);
    when(collectionResourceClient.getManyWithRawQueryStringParameters(any(String.class))).thenReturn(CompletableFuture.completedFuture(Result.succeeded(null)));
    String servicePointId = UUID.randomUUID().toString();
    ZonedDateTime startDate = ZonedDateTime.of(2020, 10, 12, 18, 0, 0, 0, UTC);
    ZonedDateTime endDate = ZonedDateTime.of(2020, 10, 22, 15, 30, 0, 0, UTC);
    CalendarRepository calendarRepository = new CalendarRepository(clients);
    calendarRepository.fetchOpeningDaysBetweenDates(servicePointId, startDate, endDate, false);
    ArgumentCaptor<String> paramsArgumentCaptor = ArgumentCaptor.forClass(String.class);
    verify(collectionResourceClient).getManyWithRawQueryStringParameters(paramsArgumentCaptor.capture());
    String actualParams = paramsArgumentCaptor.getValue();
    String expectedParams = String.format(QUERY_PARAMETERS, servicePointId, startDate.toLocalDate(), endDate.toLocalDate().plusDays(1));
    assertEquals(expectedParams, actualParams);
}
Also used : CollectionResourceClient(org.folio.circulation.support.CollectionResourceClient) ZonedDateTime(java.time.ZonedDateTime) Clients(org.folio.circulation.support.Clients) Test(org.junit.jupiter.api.Test)

Example 2 with CollectionResourceClient

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

the class CirculationRulesResource method getPolicyIdsByType.

private CompletableFuture<Result<Map<String, Set<String>>>> getPolicyIdsByType(Clients clients) {
    CollectionResourceClient loanPolicyClient = clients.loanPoliciesStorage();
    CollectionResourceClient noticePolicyClient = clients.patronNoticePolicesStorageClient();
    CollectionResourceClient requestPolicyClient = clients.requestPoliciesStorage();
    CollectionResourceClient overdueFinePolicyClient = clients.overdueFinesPoliciesStorage();
    CollectionResourceClient lostItemFeePolicyClient = clients.lostItemPoliciesStorage();
    Map<String, Set<String>> ids = new HashMap<>();
    return Result.ofAsync(() -> ids).thenCombineAsync(getPolicyIdsByType(loanPolicyClient, "loanPolicies", "l"), (resultTotalIds, resultNewIds) -> resultTotalIds.combine(resultNewIds, this::getTotalMap)).thenCombineAsync(getPolicyIdsByType(noticePolicyClient, "patronNoticePolicies", "n"), (resultTotalIds, resultNewIds) -> resultTotalIds.combine(resultNewIds, this::getTotalMap)).thenCombineAsync(getPolicyIdsByType(requestPolicyClient, "requestPolicies", "r"), (resultTotalIds, resultNewIds) -> resultTotalIds.combine(resultNewIds, this::getTotalMap)).thenCombineAsync(getPolicyIdsByType(overdueFinePolicyClient, "overdueFinePolicies", "o"), (resultTotalIds, resultNewIds) -> resultTotalIds.combine(resultNewIds, this::getTotalMap)).thenCombineAsync(getPolicyIdsByType(lostItemFeePolicyClient, "lostItemFeePolicies", "i"), (resultTotalIds, resultNewIds) -> resultTotalIds.combine(resultNewIds, this::getTotalMap));
}
Also used : Clients(org.folio.circulation.support.Clients) Response(org.folio.circulation.support.http.client.Response) DecodeException(io.vertx.core.json.DecodeException) WebContext(org.folio.circulation.support.http.server.WebContext) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Token(org.antlr.v4.runtime.Token) Router(io.vertx.ext.web.Router) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) CollectionResourceClient(org.folio.circulation.support.CollectionResourceClient) RoutingContext(io.vertx.ext.web.RoutingContext) BodyHandler(io.vertx.ext.web.handler.BodyHandler) Function(java.util.function.Function) JsonHttpResponse.ok(org.folio.circulation.support.http.server.JsonHttpResponse.ok) ForwardOnFailure(org.folio.circulation.support.ForwardOnFailure) CirculationRulesParser(org.folio.circulation.rules.CirculationRulesParser) Text2Drools(org.folio.circulation.rules.Text2Drools) Collectors.mapping(java.util.stream.Collectors.mapping) Map(java.util.Map) PageLimit(org.folio.circulation.support.http.client.PageLimit) JsonObject(io.vertx.core.json.JsonObject) Collectors.toSet(java.util.stream.Collectors.toSet) MapUtils(org.apache.commons.collections4.MapUtils) CirculationRulesCache(org.folio.circulation.rules.cache.CirculationRulesCache) MultipleRecords(org.folio.circulation.domain.MultipleRecords) Result.of(org.folio.circulation.support.results.Result.of) MethodHandles(java.lang.invoke.MethodHandles) ExceptionUtils.getStackTrace(org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace) Set(java.util.Set) Result(org.folio.circulation.support.results.Result) ForwardResponse(org.folio.circulation.support.http.server.ForwardResponse) NoContentResponse.noContent(org.folio.circulation.support.http.server.NoContentResponse.noContent) List(java.util.List) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) Logger(org.apache.logging.log4j.Logger) CirculationRulesException(org.folio.circulation.rules.CirculationRulesException) HttpServerResponse(io.vertx.core.http.HttpServerResponse) JsonHttpResponse.unprocessableEntity(org.folio.circulation.support.http.server.JsonHttpResponse.unprocessableEntity) LogManager(org.apache.logging.log4j.LogManager) JsonPropertyFetcher.getProperty(org.folio.circulation.support.json.JsonPropertyFetcher.getProperty) ServerErrorResponse.internalError(org.folio.circulation.support.http.server.ServerErrorResponse.internalError) HttpClient(io.vertx.core.http.HttpClient) CollectionResourceClient(org.folio.circulation.support.CollectionResourceClient) Collectors.toSet(java.util.stream.Collectors.toSet) Set(java.util.Set) HashMap(java.util.HashMap)

Example 3 with CollectionResourceClient

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

the class CirculationRulesResource method put.

// Cannot combine exception catching as cannot resolve overloaded method for error
@SuppressWarnings("squid:S2147")
private void put(RoutingContext routingContext) {
    final Clients clients = Clients.create(new WebContext(routingContext), client);
    CollectionResourceClient loansRulesClient = clients.circulationRulesStorage();
    if (loansRulesClient == null) {
        internalError(routingContext.response(), "Cannot initialise client to storage interface");
        return;
    }
    getPolicyIdsByType(clients).thenAccept(result -> proceedWithUpdate(result.value(), routingContext, clients));
}
Also used : CollectionResourceClient(org.folio.circulation.support.CollectionResourceClient) WebContext(org.folio.circulation.support.http.server.WebContext) Clients(org.folio.circulation.support.Clients)

Example 4 with CollectionResourceClient

use of org.folio.circulation.support.CollectionResourceClient 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 5 with CollectionResourceClient

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

the class CirculationRulesCache method getDrools.

public CompletableFuture<Result<Drools>> getDrools(String tenantId, CollectionResourceClient circulationRulesClient) {
    final CompletableFuture<Result<Drools>> cfDrools = new CompletableFuture<>();
    Rules rules = rulesMap.get(tenantId);
    if (isCurrent(rules)) {
        cfDrools.complete(succeeded(rules.drools));
        if (reloadNeeded(rules)) {
            rules.reloadInitiated = true;
            reloadRules(rules, circulationRulesClient).thenCompose(r -> r.after(updatedRules -> ofAsync(() -> updatedRules.drools)));
        }
        return cfDrools;
    }
    if (rules == null) {
        rules = new Rules();
        rulesMap.put(tenantId, rules);
    }
    return reloadRules(rules, circulationRulesClient).thenCompose(r -> r.after(updatedRules -> ofAsync(() -> updatedRules.drools)));
}
Also used : CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) MethodHandles(java.lang.invoke.MethodHandles) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CompletableFuture(java.util.concurrent.CompletableFuture) CollectionResourceClient(org.folio.circulation.support.CollectionResourceClient) ExecutableRules(org.folio.circulation.rules.ExecutableRules) Result(org.folio.circulation.support.results.Result) ServerErrorFailure(org.folio.circulation.support.ServerErrorFailure) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) Logger(org.apache.logging.log4j.Logger) Drools(org.folio.circulation.rules.Drools) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) Text2Drools(org.folio.circulation.rules.Text2Drools) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) Result.failed(org.folio.circulation.support.results.Result.failed) LogManager(org.apache.logging.log4j.LogManager) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutableRules(org.folio.circulation.rules.ExecutableRules) Result(org.folio.circulation.support.results.Result)

Aggregations

CollectionResourceClient (org.folio.circulation.support.CollectionResourceClient)6 Clients (org.folio.circulation.support.Clients)5 JsonObject (io.vertx.core.json.JsonObject)4 MethodHandles (java.lang.invoke.MethodHandles)3 Map (java.util.Map)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 Text2Drools (org.folio.circulation.rules.Text2Drools)3 WebContext (org.folio.circulation.support.http.server.WebContext)3 HttpClient (io.vertx.core.http.HttpClient)2 HttpServerResponse (io.vertx.core.http.HttpServerResponse)2 DecodeException (io.vertx.core.json.DecodeException)2 Router (io.vertx.ext.web.Router)2 RoutingContext (io.vertx.ext.web.RoutingContext)2 BodyHandler (io.vertx.ext.web.handler.BodyHandler)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Set (java.util.Set)2 Function (java.util.function.Function)2