Search in sources :

Example 1 with OKAPI_URL

use of org.folio.rest.RestConstants.OKAPI_URL 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));
}
Also used : Future.succeededFuture(io.vertx.core.Future.succeededFuture) OrderReEncumberService(org.folio.service.orders.OrderReEncumberService) HttpException(org.folio.rest.core.exceptions.HttpException) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) Context(io.vertx.core.Context) CollectionUtils(org.apache.commons.collections4.CollectionUtils) SpringContextUtil(org.folio.spring.SpringContextUtil) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) OrdersCompositeOrders(org.folio.rest.jaxrs.resource.OrdersCompositeOrders) Map(java.util.Map) RequestContext(org.folio.rest.core.models.RequestContext) JsonObject(io.vertx.core.json.JsonObject) OKAPI_URL(org.folio.rest.RestConstants.OKAPI_URL) PurchaseOrderHelper(org.folio.helper.PurchaseOrderHelper) AsyncResult(io.vertx.core.AsyncResult) ORDER_CONFIG_MODULE_NAME(org.folio.orders.utils.HelperUtils.ORDER_CONFIG_MODULE_NAME) RestConstants(org.folio.rest.RestConstants) Errors(org.folio.rest.jaxrs.model.Errors) OrdersRollover(org.folio.rest.jaxrs.resource.OrdersRollover) PO_LINES_BUSINESS(org.folio.orders.utils.ResourcePathResolver.PO_LINES_BUSINESS) Vertx(io.vertx.core.Vertx) Validate(org.folio.rest.annotations.Validate) ConfigurationEntriesService(org.folio.service.configuration.ConfigurationEntriesService) OrderRolloverService(org.folio.service.orders.OrderRolloverService) ResourcePathResolver.resourceByIdPath(org.folio.orders.utils.ResourcePathResolver.resourceByIdPath) Logger(org.apache.logging.log4j.Logger) Response(javax.ws.rs.core.Response) Handler(io.vertx.core.Handler) LogManager(org.apache.logging.log4j.LogManager) LedgerFiscalYearRollover(org.folio.rest.jaxrs.model.LedgerFiscalYearRollover) Errors(org.folio.rest.jaxrs.model.Errors) HttpException(org.folio.rest.core.exceptions.HttpException) RequestContext(org.folio.rest.core.models.RequestContext) Validate(org.folio.rest.annotations.Validate)

Aggregations

AsyncResult (io.vertx.core.AsyncResult)1 Context (io.vertx.core.Context)1 Future.succeededFuture (io.vertx.core.Future.succeededFuture)1 Handler (io.vertx.core.Handler)1 Vertx (io.vertx.core.Vertx)1 JsonObject (io.vertx.core.json.JsonObject)1 Map (java.util.Map)1 Response (javax.ws.rs.core.Response)1 CollectionUtils (org.apache.commons.collections4.CollectionUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 PurchaseOrderHelper (org.folio.helper.PurchaseOrderHelper)1 ORDER_CONFIG_MODULE_NAME (org.folio.orders.utils.HelperUtils.ORDER_CONFIG_MODULE_NAME)1 PO_LINES_BUSINESS (org.folio.orders.utils.ResourcePathResolver.PO_LINES_BUSINESS)1 ResourcePathResolver.resourceByIdPath (org.folio.orders.utils.ResourcePathResolver.resourceByIdPath)1 RestConstants (org.folio.rest.RestConstants)1 OKAPI_URL (org.folio.rest.RestConstants.OKAPI_URL)1 Validate (org.folio.rest.annotations.Validate)1 HttpException (org.folio.rest.core.exceptions.HttpException)1