use of org.folio.orders.utils.ResourcePathResolver.PO_LINE_NUMBER in project mod-orders by folio-org.
the class PurchaseOrderLineHelper method createPoLine.
/**
* Creates PO Line assuming its content is valid and all restriction checks have been already passed
* @param compPoLine {@link CompositePoLine} to be created
* @param compOrder associated {@link CompositePurchaseOrder} object
* @return completable future which might hold {@link CompositePoLine} on success or an exception if any issue happens
*/
public CompletableFuture<CompositePoLine> createPoLine(CompositePoLine compPoLine, CompositePurchaseOrder compOrder, RequestContext requestContext) {
// The id is required because sub-objects are being created first
if (isEmpty(compPoLine.getId())) {
compPoLine.setId(UUID.randomUUID().toString());
}
compPoLine.setPurchaseOrderId(compOrder.getId());
updateEstimatedPrice(compPoLine);
PoLineCommonUtil.updateLocationsQuantity(compPoLine.getLocations());
JsonObject line = mapFrom(compPoLine);
List<CompletableFuture<Void>> subObjFuts = new ArrayList<>();
subObjFuts.add(createAlerts(compPoLine, line, requestContext));
subObjFuts.add(createReportingCodes(compPoLine, line, requestContext));
return allOf(subObjFuts.toArray(new CompletableFuture[0])).thenCompose(v -> generateLineNumber(compOrder, requestContext)).thenAccept(lineNumber -> line.put(PO_LINE_NUMBER, lineNumber)).thenCompose(v -> createPoLineSummary(compPoLine, line, requestContext));
}
Aggregations