Search in sources :

Example 6 with VoucherLine

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;
}
Also used : AddressConverter(org.folio.converters.AddressConverter) BatchVoucherGenerationException(org.folio.exceptions.BatchVoucherGenerationException) VoucherService(org.folio.rest.impl.VoucherService) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) CompletableFuture(java.util.concurrent.CompletableFuture) Context(io.vertx.core.Context) SpringContextUtil(org.folio.spring.SpringContextUtil) ArrayList(java.util.ArrayList) VoucherLine(org.folio.rest.acq.model.VoucherLine) InvoiceRetrieveService(org.folio.services.InvoiceRetrieveService) CompletableFuture.allOf(java.util.concurrent.CompletableFuture.allOf) BatchGroupHelper(org.folio.rest.impl.BatchGroupHelper) VoucherLinesRetrieveService(org.folio.services.VoucherLinesRetrieveService) Map(java.util.Map) RequestContext(org.folio.rest.core.models.RequestContext) JsonObject(io.vertx.core.json.JsonObject) VendorRetrieveService(org.folio.services.VendorRetrieveService) Vertx(io.vertx.core.Vertx) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) org.folio.rest.jaxrs.model(org.folio.rest.jaxrs.model) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) FundDistribution(org.folio.rest.acq.model.FundDistribution) Address(org.folio.rest.acq.model.Address) Organization(org.folio.rest.acq.model.Organization) InvoiceLinesRetrieveService(org.folio.services.InvoiceLinesRetrieveService) Optional(java.util.Optional) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) BatchVoucherGenerationException(org.folio.exceptions.BatchVoucherGenerationException)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)6 VoucherLine (org.folio.rest.acq.model.VoucherLine)6 List (java.util.List)5 Collectors.toList (java.util.stream.Collectors.toList)5 Context (io.vertx.core.Context)4 Vertx (io.vertx.core.Vertx)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 IOException (java.io.IOException)3 Date (java.util.Date)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 CompletableFuture.allOf (java.util.concurrent.CompletableFuture.allOf)3 Collectors (java.util.stream.Collectors)3 AddressConverter (org.folio.converters.AddressConverter)3 BatchVoucherGenerationException (org.folio.exceptions.BatchVoucherGenerationException)3 Address (org.folio.rest.acq.model.Address)3 FundDistribution (org.folio.rest.acq.model.FundDistribution)3 Organization (org.folio.rest.acq.model.Organization)3