use of org.folio.service.orders.OrderWorkflowType in project mod-orders by folio-org.
the class PurchaseOrderLineHelper method processPoLineEncumbrances.
private CompletableFuture<Void> processPoLineEncumbrances(CompositePurchaseOrder compOrder, CompositePoLine compositePoLine, JsonObject lineFromStorage, RequestContext requestContext) {
PoLine storagePoLine = lineFromStorage.mapTo(PoLine.class);
List<String> storageFundIds = storagePoLine.getFundDistribution().stream().map(FundDistribution::getFundId).collect(Collectors.toList());
compositePoLine.getFundDistribution().stream().filter(fundDistribution -> storageFundIds.contains(fundDistribution.getFundId()) && fundDistribution.getEncumbrance() == null).forEach(fundDistribution -> storagePoLine.getFundDistribution().stream().filter(storageFundDistribution -> storageFundDistribution.getFundId().equals(fundDistribution.getFundId())).findFirst().ifPresent(storageFundDistribution -> fundDistribution.setEncumbrance(storageFundDistribution.getEncumbrance())));
if (isEncumbranceUpdateNeeded(compOrder, compositePoLine, storagePoLine)) {
OrderWorkflowType workflowType = compOrder.getWorkflowStatus() == PENDING ? OrderWorkflowType.PENDING_TO_PENDING : OrderWorkflowType.PENDING_TO_OPEN;
EncumbranceWorkflowStrategy strategy = encumbranceWorkflowStrategyFactory.getStrategy(workflowType);
CompositePurchaseOrder poFromStorage = JsonObject.mapFrom(compOrder).mapTo(CompositePurchaseOrder.class);
return strategy.processEncumbrances(compOrder.withCompositePoLines(Collections.singletonList(compositePoLine)), poFromStorage, requestContext);
}
return completedFuture(null);
}
Aggregations