use of org.folio.rest.acq.model.orders.PoLine in project mod-invoice by folio-org.
the class CreateInvoiceEventHandler method prepareInvoiceLinesToSave.
private List<InvoiceLine> prepareInvoiceLinesToSave(String invoiceId, DataImportEventPayload dataImportEventPayload, Map<Integer, PoLine> associatedPoLines) {
List<InvoiceLine> invoiceLines = new JsonArray(dataImportEventPayload.getContext().get(INVOICE_LINES_KEY)).stream().map(JsonObject.class::cast).map(json -> json.mapTo(InvoiceLine.class)).map(invoiceLine -> invoiceLine.withInvoiceId(invoiceId).withInvoiceLineStatus(OPEN)).collect(Collectors.toList());
linkInvoiceLinesToPoLines(invoiceLines, associatedPoLines);
return invoiceLines;
}
use of org.folio.rest.acq.model.orders.PoLine in project mod-invoice by folio-org.
the class CreateInvoiceEventHandler method getAssociatedPoLinesByPoLineNumber.
private CompletableFuture<Map<Integer, PoLine>> getAssociatedPoLinesByPoLineNumber(Map<Integer, String> invoiceLineNoToPoLineNo, Map<String, String> okapiHeaders) {
Map<Integer, PoLine> invoiceLineNoToPoLine = new HashMap<>();
if (invoiceLineNoToPoLineNo.isEmpty()) {
return completedFuture(invoiceLineNoToPoLine);
}
List<CompletableFuture<PoLineCollection>> polineCollectionsFuture = ofSubLists(List.copyOf(invoiceLineNoToPoLineNo.values()), MAX_CHUNK_SIZE).map(this::prepareQueryGetPoLinesByNumber).map(cqlQuery -> new RequestEntry(resourcesPath(ORDER_LINES)).withQuery(cqlQuery).withOffset(0).withLimit(Integer.MAX_VALUE)).map(requestEntry -> restClient.get(requestEntry, new RequestContext(Vertx.currentContext(), okapiHeaders), PoLineCollection.class)).collect(Collectors.toList());
return collectResultsOnSuccess(polineCollectionsFuture).thenApply(lists -> lists.stream().flatMap(polCollection -> polCollection.getPoLines().stream()).distinct().collect(Collectors.toList())).thenApply(poLines -> poLines.stream().collect(Collectors.toMap(PoLine::getPoLineNumber, poLine -> poLine))).thenAccept(poLineNumberToPoLine -> invoiceLineNoToPoLineNo.forEach((key, value) -> poLineNumberToPoLine.computeIfPresent(value, (polNo, poLine) -> invoiceLineNoToPoLine.put(key, poLine)))).thenApply(v -> invoiceLineNoToPoLine);
}
use of org.folio.rest.acq.model.orders.PoLine in project mod-invoice by folio-org.
the class CreateInvoiceEventHandler method ensureAdditionalData.
private void ensureAdditionalData(DataImportEventPayload dataImportEventPayload, Map<Integer, PoLine> invoiceLineNoToPoLine) {
for (Map.Entry<Integer, PoLine> pair : invoiceLineNoToPoLine.entrySet()) {
PoLine poLine = pair.getValue();
// put poLine id because invoice line schema expects "poLineId" instead of poLine number
// https://github.com/folio-org/acq-models/blob/master/mod-invoice-storage/schemas/invoice_line.json
dataImportEventPayload.getContext().put(format(POL_NUMBER_KEY, pair.getKey() - 1), poLine.getId());
dataImportEventPayload.getContext().put(format(POL_TITLE_KEY, pair.getKey() - 1), poLine.getTitleOrPackage());
if (poLine.getFundDistribution() != null) {
dataImportEventPayload.getContext().put(format(POL_FUND_DISTRIBUTIONS_KEY, pair.getKey() - 1), Json.encode(poLine.getFundDistribution()));
}
if (isNotEmpty(poLine.getFundDistribution()) && verifyAllFundsHaveSameExpenseClass(poLine.getFundDistribution())) {
dataImportEventPayload.getContext().put(format(POL_EXPENSE_CLASS_KEY, pair.getKey() - 1), poLine.getFundDistribution().get(0).getExpenseClassId());
}
}
}
Aggregations