use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.
the class InvoiceHelper method getInvoices.
/**
* Gets list of invoice
*
* @param limit Limit the number of elements returned in the response
* @param offset Skip over a number of elements by specifying an offset value for the query
* @param query A query expressed as a CQL string using valid searchable fields
* @return completable future with {@link InvoiceCollection} on success or an exception if processing fails
*/
public CompletableFuture<InvoiceCollection> getInvoices(int limit, int offset, String query) {
CompletableFuture<InvoiceCollection> future = new FolioVertxCompletableFuture<>(ctx);
RequestContext requestContext = new RequestContext(ctx, okapiHeaders);
try {
buildGetInvoicesQuery(query).thenCompose(getInvoicesQuery -> invoiceService.getInvoices(getInvoicesQuery, offset, limit, requestContext)).thenCompose(invoiceCollection -> invoiceService.updateInvoicesTotals(invoiceCollection, requestContext).thenAccept(v -> {
logger.info("Successfully retrieved invoices: {}", invoiceCollection);
future.complete(invoiceCollection);
})).exceptionally(t -> {
logger.error("Error getting invoices", t);
future.completeExceptionally(t);
return null;
});
} catch (Exception e) {
future.completeExceptionally(e);
}
return future;
}
use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.
the class CreateInvoiceEventHandler method saveInvoice.
private CompletableFuture<Invoice> saveInvoice(DataImportEventPayload dataImportEventPayload, Map<String, String> okapiHeaders) {
Invoice invoiceToSave = Json.decodeValue(dataImportEventPayload.getContext().get(INVOICE.value()), Invoice.class);
invoiceToSave.setSource(Invoice.Source.EDI);
InvoiceHelper invoiceHelper = new InvoiceHelper(okapiHeaders, Vertx.currentContext(), DEFAULT_LANG);
return invoiceHelper.createInvoice(invoiceToSave).whenComplete((invoice, throwable) -> {
if (throwable == null) {
dataImportEventPayload.getContext().put(INVOICE.value(), Json.encode(invoice));
return;
}
logger.error("Error during creation invoice in the storage", throwable);
});
}
use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.
the class InvoiceCancelServiceTest method setupGetTransactions.
private void setupGetTransactions(Invoice invoice) throws IOException {
TransactionCollection creditCollection = getMockAs(MOCK_CREDITS_LIST, TransactionCollection.class);
TransactionCollection encumbranceCollection = getMockAs(MOCK_ENCUMBRANCES_LIST, TransactionCollection.class);
TransactionCollection paymentCollection = getMockAs(MOCK_PAYMENTS_LIST, TransactionCollection.class);
TransactionCollection pendingPaymentCollection = getMockAs(MOCK_PENDING_PAYMENTS_LIST, TransactionCollection.class);
TransactionCollection trCollection = mergeCollections(List.of(creditCollection, encumbranceCollection, paymentCollection, pendingPaymentCollection));
String query = String.format("sourceInvoiceId==%s", invoice.getId());
RequestEntry requestEntry = new RequestEntry(TRANSACTIONS_ENDPOINT).withQuery(query).withLimit(Integer.MAX_VALUE).withOffset(0);
doReturn(completedFuture(trCollection)).when(restClient).get(argThat(re -> sameRequestEntry(requestEntry, re)), eq(requestContextMock), eq(TransactionCollection.class));
}
use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.
the class InvoiceCancelServiceTest method setupUpdateVoucher.
private void setupUpdateVoucher(Invoice invoice) throws IOException {
// GET Voucher
Voucher voucher = getMockAs(VOUCHER_SAMPLE_PATH, Voucher.class);
VoucherCollection voucherCollection = new VoucherCollection().withVouchers(singletonList(voucher)).withTotalRecords(1);
RequestEntry getRequestEntry = new RequestEntry(VOUCHER_ENDPOINT).withQuery(String.format("invoiceId==%s", invoice.getId())).withLimit(1).withOffset(0);
doReturn(completedFuture(voucherCollection)).when(restClient).get(argThat(re -> sameRequestEntry(getRequestEntry, re)), eq(requestContextMock), eq(VoucherCollection.class));
// PUT Voucher
RequestEntry putRequestEntry = new RequestEntry(VOUCHER_BY_ID_ENDPOINT).withId(voucher.getId());
doReturn(completedFuture(null)).when(restClient).put(argThat(re -> sameRequestEntry(putRequestEntry, re)), any(Voucher.class), eq(requestContextMock));
}
use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.
the class InvoiceCancelServiceTest method setupUpdateTransactionSummary.
private void setupUpdateTransactionSummary(Invoice invoice) {
RequestEntry requestEntry = new RequestEntry(INVOICE_TRANSACTION_SUMMARIES_BY_ID_ENDPOINT).withPathParameter("id", invoice.getId());
InvoiceTransactionSummary summary = new InvoiceTransactionSummary().withId(invoice.getId()).withNumPaymentsCredits(3).withNumPendingPayments(1);
doReturn(completedFuture(null)).when(restClient).put(argThat(re -> sameRequestEntry(requestEntry, re)), eq(summary), eq(requestContextMock));
}
Aggregations