use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.
the class BudgetExpenseClassService method checkExpenseClass.
private CompletableFuture<Void> checkExpenseClass(InvoiceWorkflowDataHolder holder, RequestContext requestContext) {
Budget budget = holder.getBudget();
FundDistribution fundDistribution = holder.getFundDistribution();
String query = String.format("budgetId==%s and expenseClassId==%s", budget.getId(), fundDistribution.getExpenseClassId());
RequestEntry requestEntry = new RequestEntry(BUDGET_EXPENSE_CLASS_ENDPOINT).withQuery(query).withOffset(0).withLimit(1);
return restClient.get(requestEntry, requestContext, BudgetExpenseClassCollection.class).thenAccept(budgetExpenseClasses -> {
checkExpenseClassAssignedToBudget(holder, budgetExpenseClasses);
checkExpenseClassActive(holder, budgetExpenseClasses);
});
}
use of org.folio.rest.core.models.RequestEntry in project mod-invoice by folio-org.
the class ExpenseClassRetrieveService method getExpenseClassById.
public CompletableFuture<ExpenseClass> getExpenseClassById(String id, RequestContext requestContext) {
RequestEntry requestEntry = new RequestEntry(EXPENSE_CLASS_BY_ID_ENDPOINT).withId(id);
return restClient.get(requestEntry, requestContext, ExpenseClass.class).exceptionally(t -> {
Throwable cause = t.getCause() == null ? t : t.getCause();
if (HelperUtils.isNotFound(cause)) {
List<Parameter> parameters = Collections.singletonList(new Parameter().withValue(id).withKey("expenseClass"));
cause = new HttpException(404, EXPENSE_CLASS_NOT_FOUND.toError().withParameters(parameters));
}
throw new CompletionException(cause);
});
}
use of org.folio.rest.core.models.RequestEntry in project mod-orders by folio-org.
the class InvoiceLineServiceTest method shouldRemoveEncumbranceLinks.
@Test
void shouldRemoveEncumbranceLinks() {
// Given
String poLineId1 = UUID.randomUUID().toString();
String poLineId2 = UUID.randomUUID().toString();
String encumbrance1Id = UUID.randomUUID().toString();
String encumbrance2Id = UUID.randomUUID().toString();
String encumbrance3Id = UUID.randomUUID().toString();
List<String> transactionIds = List.of(encumbrance1Id, encumbrance2Id, encumbrance3Id);
String invoiceLineId1 = UUID.randomUUID().toString();
InvoiceLine invoiceLine1 = new InvoiceLine().withId(invoiceLineId1).withPoLineId(poLineId1).withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance1Id))).withAdjustments(List.of(new Adjustment().withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance2Id)))));
String invoiceLineId2 = UUID.randomUUID().toString();
InvoiceLine invoiceLine2 = new InvoiceLine().withId(invoiceLineId2).withPoLineId(poLineId2).withAdjustments(List.of(new Adjustment().withFundDistributions(List.of(new org.folio.rest.acq.model.invoice.FundDistribution().withEncumbrance(encumbrance3Id)))));
List<InvoiceLine> invoiceLines = List.of(invoiceLine1, invoiceLine2);
InvoiceLine expectedInvoiceLine1 = JsonObject.mapFrom(invoiceLine1).mapTo(InvoiceLine.class);
expectedInvoiceLine1.getFundDistributions().get(0).setEncumbrance(null);
expectedInvoiceLine1.getAdjustments().get(0).getFundDistributions().get(0).setEncumbrance(null);
InvoiceLine expectedInvoiceLine2 = JsonObject.mapFrom(invoiceLine2).mapTo(InvoiceLine.class);
expectedInvoiceLine2.getAdjustments().get(0).getFundDistributions().get(0).setEncumbrance(null);
when(restClient.put(any(RequestEntry.class), any(InvoiceLine.class), eq(requestContextMock))).thenReturn(CompletableFuture.completedFuture(null));
when(requestContextMock.getContext()).thenReturn(Vertx.vertx().getOrCreateContext());
// When
CompletableFuture<Void> result = invoiceLineService.removeEncumbranceLinks(invoiceLines, transactionIds, requestContextMock);
assertFalse(result.isCompletedExceptionally());
result.join();
// Then
verify(restClient, times(1)).put(argThat(requestEntry -> invoiceLineId1.equals(requestEntry.getPathParams().get("id"))), eq(expectedInvoiceLine1), eq(requestContextMock));
verify(restClient, times(1)).put(argThat(requestEntry -> invoiceLineId2.equals(requestEntry.getPathParams().get("id"))), eq(expectedInvoiceLine2), eq(requestContextMock));
}
use of org.folio.rest.core.models.RequestEntry in project mod-orders by folio-org.
the class TransactionSummariesService method createOrderTransactionSummary.
public CompletableFuture<OrderTransactionSummary> createOrderTransactionSummary(String id, int number, RequestContext requestContext) {
OrderTransactionSummary summary = new OrderTransactionSummary().withId(id).withNumTransactions(number);
RequestEntry requestEntry = new RequestEntry(ENDPOINT);
return restClient.post(requestEntry, summary, requestContext, OrderTransactionSummary.class);
}
use of org.folio.rest.core.models.RequestEntry in project mod-orders by folio-org.
the class InventoryManager method getOrCreateHoldingsRecord.
public CompletableFuture<String> getOrCreateHoldingsRecord(String instanceId, Location location, RequestContext requestContext) {
if (location.getHoldingId() != null) {
Context ctx = requestContext.getContext();
String tenantId = TenantTool.tenantId(requestContext.getHeaders());
String holdingId = location.getHoldingId();
RequestEntry requestEntry = new RequestEntry(INVENTORY_LOOKUP_ENDPOINTS.get(HOLDINGS_RECORDS_BY_ID_ENDPOINT)).withId(holdingId);
CompletableFuture<String> holdingIdFuture;
var holdingIdKey = String.format(TENANT_SPECIFIC_KEY_FORMAT, tenantId, "getOrCreateHoldingsRecord", holdingId);
String holdingIdCached = ctx.get(holdingIdKey);
if (holdingIdCached != null) {
holdingIdFuture = CompletableFuture.completedFuture(holdingIdCached);
} else {
holdingIdFuture = restClient.getAsJsonObject(requestEntry, requestContext).whenComplete((id, err) -> ctx.put(holdingIdKey, id)).thenApply(holdingJson -> {
var id = HelperUtils.extractId(holdingJson);
ctx.put(holdingIdKey, id);
return id;
});
}
return holdingIdFuture.exceptionally(throwable -> {
if (throwable.getCause() instanceof HttpException && ((HttpException) throwable.getCause()).getCode() == 404) {
String msg = String.format(HOLDINGS_BY_ID_NOT_FOUND.getDescription(), holdingId);
Error error = new Error().withCode(HOLDINGS_BY_ID_NOT_FOUND.getCode()).withMessage(msg);
throw new CompletionException(new HttpException(NOT_FOUND, error));
} else {
throw new CompletionException(throwable.getCause());
}
});
} else {
return createHoldingsRecord(instanceId, location.getLocationId(), PostResponseType.UUID, String.class, requestContext);
}
}
Aggregations