use of org.folio.circulation.support.results.Result in project mod-circulation by folio-org.
the class VertxWebClientOkapiHttpClientTests method canGetJsonUsingQueryParameters.
@Test
public void canGetJsonUsingQueryParameters() throws InterruptedException, ExecutionException, TimeoutException {
fakeWebServer.stubFor(matchingFolioHeaders(get(urlPathEqualTo("/record"))).withQueryParam("first-parameter", equalTo("foo")).withQueryParam("second-parameter", equalTo("bar")).willReturn(okJson(dummyJsonResponseBody())));
OkapiHttpClient client = createClient();
CompletableFuture<Result<Response>> getCompleted = client.get(fakeWebServer.url("/record"), namedParameter("first-parameter", "foo"), namedParameter("second-parameter", "bar"));
final Response response = getCompleted.get(2, SECONDS).value();
assertThat(response, hasStatus(HTTP_OK));
assertThat(response.getJson().getString("message"), is("hello"));
assertThat(response.getContentType(), is("application/json"));
}
use of org.folio.circulation.support.results.Result in project mod-circulation by folio-org.
the class VertxWebClientOkapiHttpClientTests method canDeleteAResource.
@Test
public void canDeleteAResource() throws InterruptedException, ExecutionException, TimeoutException {
fakeWebServer.stubFor(matchingFolioHeaders(delete(urlPathEqualTo("/record"))).willReturn(noContent()));
OkapiHttpClient client = createClient();
CompletableFuture<Result<Response>> getCompleted = client.delete(fakeWebServer.url("/record"));
final Response response = getCompleted.get(2, SECONDS).value();
assertThat(response, hasStatus(HTTP_NO_CONTENT));
}
use of org.folio.circulation.support.results.Result in project mod-circulation by folio-org.
the class VertxWebClientOkapiHttpClientTests method failsWhenGetTimesOut.
@Test
public void failsWhenGetTimesOut() throws InterruptedException, ExecutionException, TimeoutException {
fakeWebServer.stubFor(matchingFolioHeaders(get(urlPathEqualTo("/record"))).willReturn(aResponse().withFixedDelay(1000)));
OkapiHttpClient client = createClient();
CompletableFuture<Result<Response>> getCompleted = client.get(fakeWebServer.url("/record"), Duration.of(500, MILLIS));
final Result<Response> responseResult = getCompleted.get(1, SECONDS);
assertThat(responseResult.failed(), is(true));
assertThat(responseResult.cause(), is(instanceOf(ServerErrorFailure.class)));
final ServerErrorFailure cause = (ServerErrorFailure) responseResult.cause();
assertThat(cause.getReason(), containsString("The timeout period of 500ms has been exceeded while executing " + "GET /record for server localhost"));
}
use of org.folio.circulation.support.results.Result in project mod-circulation by folio-org.
the class OverduePeriodCalculatorService method minutesOverdueExcludingClosedPeriods.
private CompletableFuture<Result<Integer>> minutesOverdueExcludingClosedPeriods(Loan loan, ZonedDateTime returnDate) {
ZonedDateTime dueDate = loan.getDueDate();
String itemLocationPrimaryServicePoint = getItemLocationPrimaryServicePoint(loan).toString();
return calendarRepository.fetchOpeningDaysBetweenDates(itemLocationPrimaryServicePoint, dueDate, returnDate, false).thenApply(r -> r.next(openingDays -> getOpeningDaysDurationMinutes(openingDays, dueDate, returnDate)));
}
use of org.folio.circulation.support.results.Result in project mod-circulation by folio-org.
the class RequestByInstanceIdResource method validateRequester.
private Result<Collection<Item>> validateRequester(Map<Item, RequestQueue> itemRequestQueueMap, InstanceRequestRelatedRecords requestPackage) {
if (!itemRequestQueueMap.isEmpty()) {
Collection<RequestQueue> requestQueues = itemRequestQueueMap.values();
String requesterId = requestPackage.getInstanceLevelRequest().getRequesterId().toString();
for (RequestQueue queue : requestQueues) {
final Optional<Request> matchingRequest = queue.getRequests().stream().filter(request -> request.isOpen() && Objects.equals(request.getUserId(), requesterId)).findFirst();
if (matchingRequest.isPresent()) {
Map<String, String> parameters = new HashMap<>();
parameters.put(REQUESTER_ID, requesterId);
parameters.put(ITEM_ID, matchingRequest.get().getItemId());
parameters.put("instanceId", requestPackage.getInstanceLevelRequest().getInstanceId().toString());
String message = "This requester already has an open request for an item of this instance";
return failedValidation(new ValidationError(message, parameters));
}
}
}
return of(itemRequestQueueMap::keySet);
}
Aggregations