use of org.folio.rest.acq.model.finance.FundCollection in project mod-orders by folio-org.
the class FundService method getAllFundsByIds.
private CompletableFuture<List<Fund>> getAllFundsByIds(Collection<String> ids, RequestContext requestContext) {
String query = convertIdsToCqlQuery(ids);
RequestEntry requestEntry = new RequestEntry(ENDPOINT).withQuery(query).withLimit(MAX_IDS_FOR_GET_RQ).withOffset(0);
return restClient.get(requestEntry, requestContext, FundCollection.class).thenApply(FundCollection::getFunds).thenApply(funds -> {
if (funds.size() == ids.size()) {
return funds;
}
List<Parameter> parameters = ids.stream().filter(id -> funds.stream().noneMatch(fund -> fund.getId().equals(id))).map(id -> new Parameter().withValue(id).withKey("funds")).collect(Collectors.toList());
throw new HttpException(404, FUNDS_NOT_FOUND.toError().withParameters(parameters));
});
}
use of org.folio.rest.acq.model.finance.FundCollection in project mod-orders by folio-org.
the class MockServer method handleGetFundById.
private void handleGetFundById(RoutingContext ctx) {
logger.info("got: " + ctx.request().path());
String id = ctx.request().getParam(ID);
logger.info("id: " + id);
FundCollection funds = getFundsByIds(Collections.singletonList(id)).mapTo(FundCollection.class);
if (funds.getTotalRecords() == 0) {
serverResponse(ctx, 404, APPLICATION_JSON, id);
} else {
JsonObject fund = new JsonObject().put("fund", JsonObject.mapFrom(funds.getFunds().get(0))).put("groupIds", new JsonArray());
addServerRqRsData(HttpMethod.GET, FUNDS, fund);
serverResponse(ctx, 200, APPLICATION_JSON, fund.encodePrettily());
}
}
use of org.folio.rest.acq.model.finance.FundCollection in project mod-orders by folio-org.
the class FundServiceTest method testShouldRetrieveFundsByFundIds.
@Test
void testShouldRetrieveFundsByFundIds() throws UnsupportedEncodingException {
// Given
String fundId1 = UUID.randomUUID().toString();
String fundId2 = UUID.randomUUID().toString();
List<String> fundIds = List.of(fundId1, fundId2);
List<Fund> funds = List.of(new Fund().withId(fundId1), new Fund().withId(fundId2));
FundCollection fundCollection = new FundCollection().withFunds(funds).withTotalRecords(1);
String query = URLEncoder.encode("id==(" + fundId1 + " or " + fundId2 + ")", StandardCharsets.UTF_8.toString());
doReturn(completedFuture(fundCollection)).when(restClient).get(any(), any(), any());
// When
List<Fund> actFund = fundService.getAllFunds(fundIds, requestContext).join();
// Then
ArgumentCaptor<RequestEntry> argumentCaptor = ArgumentCaptor.forClass(RequestEntry.class);
verify(restClient).get(argumentCaptor.capture(), any(), eq(FundCollection.class));
RequestEntry requestEntry = argumentCaptor.getValue();
assertEquals(query, requestEntry.getQueryParams().get("query"));
assertEquals(0, requestEntry.getQueryParams().get("offset"));
assertEquals(MAX_IDS_FOR_GET_RQ, requestEntry.getQueryParams().get("limit"));
assertThat(actFund, equalTo(fundCollection.getFunds()));
}
use of org.folio.rest.acq.model.finance.FundCollection in project mod-orders by folio-org.
the class FundService method getFundsByLedgerId.
public CompletableFuture<List<Fund>> getFundsByLedgerId(String ledgerId, RequestContext requestContext) {
String query = String.format(FUNDS_BY_LEDGER_ID_QUERY, ledgerId);
RequestEntry requestEntry = new RequestEntry(ENDPOINT).withQuery(query).withLimit(Integer.MAX_VALUE).withOffset(0);
return restClient.get(requestEntry, requestContext, FundCollection.class).thenApply(FundCollection::getFunds);
}
use of org.folio.rest.acq.model.finance.FundCollection in project mod-orders by folio-org.
the class FundService method getFundsByIds.
private CompletableFuture<List<Fund>> getFundsByIds(Collection<String> ids, RequestContext requestContext) {
String query = convertIdsToCqlQuery(ids);
RequestEntry requestEntry = new RequestEntry(ENDPOINT).withQuery(query).withLimit(MAX_IDS_FOR_GET_RQ).withOffset(0);
return restClient.get(requestEntry, requestContext, FundCollection.class).thenApply(FundCollection::getFunds);
}
Aggregations