use of org.folio.rest.core.exceptions.HttpException in project mod-orders by folio-org.
the class ManualExchangeRateProvider method getExchangeRate.
@Override
public ExchangeRate getExchangeRate(ConversionQuery conversionQuery) {
ExchangeRateBuilder builder = new ExchangeRateBuilder(ConversionContext.of());
builder.setBase(conversionQuery.getBaseCurrency());
builder.setTerm(conversionQuery.getCurrency());
if (conversionQuery.get(RATE_KEY, Double.class) == null) {
throw new HttpException(500, "Rate must be provided in provider : " + this.getClass().getSimpleName());
}
builder.setFactor(DefaultNumberValue.of(conversionQuery.get(RATE_KEY, Double.class)));
return builder.build();
}
use of org.folio.rest.core.exceptions.HttpException 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.core.exceptions.HttpException in project mod-orders by folio-org.
the class PurchaseOrderHelperTest method testDeleteOrderLinkedToInvoiceWithError.
@Test
void testDeleteOrderLinkedToInvoiceWithError() {
// given
InvoiceLineService invoiceLineService = new InvoiceLineService(restClient);
RestClient restClient = mock(RestClient.class, CALLS_REAL_METHODS);
OrderInvoiceRelationService orderInvoiceRelationService = spy(new OrderInvoiceRelationService(restClient, invoiceLineService));
// for returning non empty collection
OrderInvoiceRelationshipCollection oirCollection = new OrderInvoiceRelationshipCollection().withOrderInvoiceRelationships(Collections.singletonList(new OrderInvoiceRelationship())).withTotalRecords(1);
doReturn(completedFuture(oirCollection)).when(restClient).get(any(), any(), any());
CompletableFuture<Void> future = orderInvoiceRelationService.checkOrderInvoiceRelationship(ORDER_ID, new RequestContext(ctxMock, okapiHeadersMock));
CompletionException exception = assertThrows(CompletionException.class, future::join);
HttpException httpException = (HttpException) exception.getCause();
assertEquals(ErrorCodes.ORDER_RELATES_TO_INVOICE.getDescription(), httpException.getMessage());
}
use of org.folio.rest.core.exceptions.HttpException in project mod-orders by folio-org.
the class InventoryManagerTest method shouldThrowExceptionIfHoldingIsNotAlreadyExist.
@Test
void shouldThrowExceptionIfHoldingIsNotAlreadyExist() {
String instanceId = UUID.randomUUID().toString();
String holdingId = UUID.randomUUID().toString();
Location location = new Location().withHoldingId(holdingId).withQuantity(1).withQuantityPhysical(1);
String msg = String.format(HOLDINGS_BY_ID_NOT_FOUND.getDescription(), holdingId);
Error error = new Error().withCode(HOLDINGS_BY_ID_NOT_FOUND.getCode()).withMessage(msg);
when(restClient.getAsJsonObject(any(RequestEntry.class), eq(requestContext))).thenThrow(new CompletionException(new HttpException(NOT_FOUND, error)));
CompletionException exception = assertThrows(CompletionException.class, () -> inventoryManager.getOrCreateHoldingsRecord(instanceId, location, requestContext).join());
assertThat(exception.getCause(), IsInstanceOf.instanceOf(HttpException.class));
HttpException cause = (HttpException) exception.getCause();
assertEquals(NOT_FOUND, cause.getCode());
assertEquals(error, cause.getError());
}
use of org.folio.rest.core.exceptions.HttpException in project mod-orders by folio-org.
the class ReasonForClosureServiceTest method testUpdateReasonForClosureWithIdMismatchFails.
@Test
void testUpdateReasonForClosureWithIdMismatchFails() {
ReasonForClosure suffix = new ReasonForClosure().withId(UUID.randomUUID().toString());
CompletableFuture<Void> result = reasonForClosureService.updateReasonForClosure(UUID.randomUUID().toString(), suffix, requestContext);
CompletionException expectedException = assertThrows(CompletionException.class, result::join);
HttpException httpException = (HttpException) expectedException.getCause();
assertEquals(422, httpException.getCode());
assertEquals(MISMATCH_BETWEEN_ID_IN_PATH_AND_BODY.toError(), httpException.getError());
}
Aggregations