Search in sources :

Example 1 with BatchVoucherGenerationException

use of org.folio.exceptions.BatchVoucherGenerationException 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

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