use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.
the class ConfigurationService method getConfigurationsEntries.
/**
* Retrieve configuration by moduleName and configName from mod-configuration.
*
* @param searchCriteria name of the module for which the configuration is to be retrieved
* @return CompletableFuture with Configs
*/
public CompletableFuture<Configs> getConfigurationsEntries(RequestContext requestContext, String... searchCriteria) {
String query = buildSearchingQuery(searchCriteria);
RequestEntry requestEntry = new RequestEntry(CONFIGURATION_ENDPOINT).withQuery(query).withOffset(0).withLimit(Integer.MAX_VALUE);
return restClient.get(requestEntry, requestContext, Configs.class);
}
use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.
the class RestClient method post.
public <T> CompletableFuture<T> post(RequestEntry requestEntry, T entity, RequestContext requestContext, Class<T> responseType) {
CompletableFuture<T> future = new CompletableFuture<>();
String endpoint = requestEntry.buildEndpoint();
JsonObject recordData = JsonObject.mapFrom(entity);
if (logger.isDebugEnabled()) {
logger.debug("Sending 'POST {}' with body: {}", endpoint, Optional.ofNullable(recordData).map(JsonObject::encodePrettily).orElse(null));
}
HttpClientInterface client = getHttpClient(requestContext.getHeaders());
try {
client.request(HttpMethod.POST, Optional.ofNullable(recordData).map(JsonObject::toBuffer).orElse(null), endpoint, requestContext.getHeaders()).thenApply(HelperUtils::verifyAndExtractBody).thenAccept(body -> {
client.closeClient();
T responseEntity = Optional.ofNullable(body).map(json -> json.mapTo(responseType)).orElse(null);
if (logger.isDebugEnabled()) {
logger.debug("'POST {}' request successfully processed. Record with '{}' id has been created", endpoint, body);
}
future.complete(responseEntity);
}).exceptionally(t -> {
client.closeClient();
logger.error("'POST {}' request failed. Request body: {}", endpoint, Optional.ofNullable(recordData).map(JsonObject::encodePrettily).orElse(null), t.getCause());
future.completeExceptionally(t.getCause());
return null;
});
} catch (Exception e) {
logger.error("'POST {}' request failed. Request body: {}", endpoint, Optional.ofNullable(recordData).map(JsonObject::encodePrettily).orElse(null), e);
client.closeClient();
future.completeExceptionally(e);
}
return future;
}
use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.
the class RestClient method delete.
public CompletableFuture<Void> delete(RequestEntry requestEntry, RequestContext requestContext) {
CompletableFuture<Void> future = new CompletableFuture<>();
String endpoint = requestEntry.buildEndpoint();
if (logger.isDebugEnabled()) {
logger.debug(CALLING_ENDPOINT_MSG, HttpMethod.DELETE, endpoint);
}
HttpClientInterface client = getHttpClient(requestContext.getHeaders());
setDefaultHeaders(client);
try {
client.request(HttpMethod.DELETE, endpoint, requestContext.getHeaders()).thenAccept(HelperUtils::verifyResponse).thenAccept(aVoid -> {
client.closeClient();
future.complete(null);
}).exceptionally(t -> {
client.closeClient();
logger.error(String.format(EXCEPTION_CALLING_ENDPOINT_MSG, HttpMethod.DELETE, endpoint, requestContext), t);
future.completeExceptionally(t.getCause());
return null;
});
} catch (Exception e) {
client.closeClient();
logger.error(String.format(EXCEPTION_CALLING_ENDPOINT_MSG, HttpMethod.DELETE, endpoint, requestContext), e);
future.completeExceptionally(e);
}
return future;
}
use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.
the class RestClient method put.
public <T> CompletableFuture<Void> put(RequestEntry requestEntry, T entity, RequestContext requestContext) {
CompletableFuture<Void> future = new CompletableFuture<>();
String endpoint = requestEntry.buildEndpoint();
JsonObject recordData = JsonObject.mapFrom(entity);
if (logger.isDebugEnabled()) {
logger.debug("Sending 'PUT {}' with body: {}", endpoint, recordData.encodePrettily());
}
HttpClientInterface client = getHttpClient(requestContext.getHeaders());
setDefaultHeaders(client);
try {
client.request(HttpMethod.PUT, recordData.toBuffer(), endpoint, requestContext.getHeaders()).thenAccept(HelperUtils::verifyResponse).thenAccept(avoid -> {
client.closeClient();
future.complete(null);
}).exceptionally(t -> {
client.closeClient();
future.completeExceptionally(t.getCause());
logger.error("'PUT {}' request failed. Request body: {}", endpoint, recordData.encodePrettily(), t.getCause());
return null;
});
} catch (Exception e) {
logger.error("'PUT {}' request failed. Request body: {}", endpoint, recordData.encodePrettily(), e);
client.closeClient();
future.completeExceptionally(e);
}
return future;
}
use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.
the class InvoiceCancelServiceTest method setupEncumbrancePut.
private void setupEncumbrancePut(Transaction transaction) {
RequestEntry requestEntry = new RequestEntry("/finance/encumbrances/{id}").withPathParameter("id", transaction.getId());
Transaction updatedTransaction = JsonObject.mapFrom(transaction).mapTo(Transaction.class);
updatedTransaction.getEncumbrance().setStatus(UNRELEASED);
doReturn(completedFuture(null)).when(restClient).put(argThat(re -> sameRequestEntry(requestEntry, re)), eq(updatedTransaction), eq(requestContextMock));
}
Aggregations