use of org.folio.rest.acq.model.VoucherLine in project mod-invoice by folio-org.
the class BatchVoucherGenerateService method generateBatchVoucher.
public CompletableFuture<BatchVoucher> generateBatchVoucher(BatchVoucherExport batchVoucherExport, RequestContext requestContext) {
CompletableFuture<BatchVoucher> future = new CompletableFuture<>();
String voucherCQL = buildBatchVoucherQuery(batchVoucherExport);
voucherService.getVouchers(voucherCQL, 0, Integer.MAX_VALUE, requestContext).thenCompose(vouchers -> {
if (!vouchers.getVouchers().isEmpty()) {
CompletableFuture<Map<String, List<VoucherLine>>> voucherLines = voucherLinesRetrieveService.getVoucherLinesMap(vouchers);
CompletableFuture<Map<String, Invoice>> invoices = invoiceRetrieveService.getInvoiceMap(vouchers, requestContext);
CompletableFuture<Map<String, List<InvoiceLine>>> invoiceLines = invoiceLinesRetrieveService.getInvoiceLineMap(vouchers, requestContext);
return allOf(voucherLines, invoices, invoiceLines).thenCompose(v -> buildBatchVoucher(batchVoucherExport, vouchers, voucherLines.join(), invoices.join(), invoiceLines.join(), requestContext)).thenAccept(batchVoucher -> {
future.complete(batchVoucher);
closeHttpConnections();
});
}
throw new BatchVoucherGenerationException("Vouchers for batch voucher export were not found");
}).exceptionally(t -> {
future.completeExceptionally(t);
closeHttpConnections();
return null;
});
return future;
}
Aggregations