use of org.folio.orders.utils.HelperUtils.ORDER_CONFIG_MODULE_NAME in project mod-orders by folio-org.
the class CompositePoLineAPI method putOrdersOrderLinesById.
@Override
@Validate
public void putOrdersOrderLinesById(String lineId, String lang, CompositePoLine poLine, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
logger.info("Handling PUT Order Line operation...");
// Set id if this is available only in path
RequestContext requestContext = new RequestContext(vertxContext, okapiHeaders);
if (StringUtils.isEmpty(poLine.getId())) {
poLine.setId(lineId);
}
// First validate content of the PO Line and proceed only if all is okay
List<Error> errors = new ArrayList<>();
if (!lineId.equals(poLine.getId())) {
errors.add(ErrorCodes.MISMATCH_BETWEEN_ID_IN_PATH_AND_BODY.toError());
}
configurationEntriesService.loadConfiguration(ORDER_CONFIG_MODULE_NAME, requestContext).thenCompose(tenantConfig -> helper.setTenantDefaultCreateInventoryValues(poLine, tenantConfig)).thenCompose(v -> compositePoLineValidationService.validatePoLine(poLine, requestContext)).thenAccept(errors::addAll).thenAccept(empty -> {
if (!errors.isEmpty()) {
PutOrdersOrderLinesByIdResponse response = PutOrdersOrderLinesByIdResponse.respond422WithApplicationJson(new Errors().withErrors(errors));
asyncResultHandler.handle(succeededFuture(response));
return;
}
helper.updateOrderLine(poLine, requestContext).thenAccept(v -> asyncResultHandler.handle(succeededFuture(buildNoContentResponse()))).exceptionally(t -> handleErrorResponse(asyncResultHandler, t));
}).exceptionally(t -> handleErrorResponse(asyncResultHandler, t));
}
use of org.folio.orders.utils.HelperUtils.ORDER_CONFIG_MODULE_NAME 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 org.folio.orders.utils.HelperUtils.ORDER_CONFIG_MODULE_NAME in project mod-orders by folio-org.
the class OrdersApi method postOrdersCompositeOrders.
@Override
@Validate
public void postOrdersCompositeOrders(String lang, CompositePurchaseOrder compPO, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
RequestContext requestContext = new RequestContext(vertxContext, okapiHeaders);
// First validate content of the PO and proceed only if all is okay
configurationEntriesService.loadConfiguration(ORDER_CONFIG_MODULE_NAME, requestContext).thenCompose(tenantConfig -> purchaseOrderHelper.validateOrder(compPO, tenantConfig, requestContext)).thenCompose(errors -> {
if (CollectionUtils.isEmpty(errors)) {
logger.info("Creating PO and POLines...");
return purchaseOrderHelper.createPurchaseOrder(compPO, new RequestContext(vertxContext, okapiHeaders)).thenAccept(withIds -> {
logger.info("Successfully Placed Order: {}", JsonObject.mapFrom(withIds).encodePrettily());
String okapiUrl = okapiHeaders.get(OKAPI_URL);
String url = resourceByIdPath(PO_LINES_BUSINESS, compPO.getId());
asyncResultHandler.handle(succeededFuture(buildResponseWithLocation(okapiUrl, url, compPO)));
});
} else {
throw new HttpException(422, new Errors().withErrors(errors).withTotalRecords(errors.size()));
}
}).exceptionally(t -> handleErrorResponse(asyncResultHandler, t));
}
Aggregations