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