use of io.vertx.core.json.JsonObject.mapFrom in project mod-orders by folio-org.
the class PurchaseOrderLineHelper method createPoLine.
/**
* Creates PO Line if its content is valid and all restriction checks passed
* @param compPOL {@link CompositePoLine} to be created
* @return completable future which might hold {@link CompositePoLine} on success, {@code null} if validation fails or an exception if any issue happens
*/
public CompletableFuture<CompositePoLine> createPoLine(CompositePoLine compPOL, RequestContext requestContext) {
// Validate PO Line content and retrieve order only if this operation is allowed
JsonObject cachedTenantConfiguration = new JsonObject();
return configurationEntriesService.loadConfiguration(ORDER_CONFIG_MODULE_NAME, requestContext).thenApply(tenantConfiguration -> cachedTenantConfiguration.mergeIn(tenantConfiguration, true)).thenCompose(tenantConfiguration -> setTenantDefaultCreateInventoryValues(compPOL, tenantConfiguration)).thenCompose(v -> validateNewPoLine(compPOL, cachedTenantConfiguration, requestContext)).thenCompose(validationErrors -> {
if (CollectionUtils.isEmpty(validationErrors)) {
return getCompositePurchaseOrder(compPOL.getPurchaseOrderId(), requestContext).thenApply(this::validateOrderState).thenCompose(po -> protectionService.isOperationRestricted(po.getAcqUnitIds(), ProtectedOperationType.CREATE, requestContext).thenApply(vVoid -> po)).thenCompose(po -> createPoLine(compPOL, po, requestContext));
} else {
Errors errors = new Errors().withErrors(validationErrors).withTotalRecords(validationErrors.size());
logger.error("Create POL validation error : " + JsonObject.mapFrom(errors).encodePrettily());
throw new HttpException(RestConstants.VALIDATION_ERROR, errors);
}
});
}
use of io.vertx.core.json.JsonObject.mapFrom 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