Search in sources :

Example 1 with ORDER_CONFIG_MODULE_NAME

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));
}
Also used : Future.succeededFuture(io.vertx.core.Future.succeededFuture) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) Context(io.vertx.core.Context) OrdersOrderLines(org.folio.rest.jaxrs.resource.OrdersOrderLines) SpringContextUtil(org.folio.spring.SpringContextUtil) ArrayList(java.util.ArrayList) 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) AsyncResult(io.vertx.core.AsyncResult) ORDER_CONFIG_MODULE_NAME(org.folio.orders.utils.HelperUtils.ORDER_CONFIG_MODULE_NAME) Errors(org.folio.rest.jaxrs.model.Errors) OrderLinePatchOperationService(org.folio.service.orders.lines.update.OrderLinePatchOperationService) PO_LINES_BUSINESS(org.folio.orders.utils.ResourcePathResolver.PO_LINES_BUSINESS) Vertx(io.vertx.core.Vertx) ErrorCodes(org.folio.rest.core.exceptions.ErrorCodes) Validate(org.folio.rest.annotations.Validate) ConfigurationEntriesService(org.folio.service.configuration.ConfigurationEntriesService) Error(org.folio.rest.jaxrs.model.Error) List(java.util.List) ResourcePathResolver.resourceByIdPath(org.folio.orders.utils.ResourcePathResolver.resourceByIdPath) Logger(org.apache.logging.log4j.Logger) Response(javax.ws.rs.core.Response) CompositePoLineValidationService(org.folio.service.orders.CompositePoLineValidationService) PurchaseOrderLineHelper(org.folio.helper.PurchaseOrderLineHelper) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) PurchaseOrderLineService(org.folio.service.orders.PurchaseOrderLineService) PatchOrderLineRequest(org.folio.rest.jaxrs.model.PatchOrderLineRequest) Handler(io.vertx.core.Handler) LogManager(org.apache.logging.log4j.LogManager) Errors(org.folio.rest.jaxrs.model.Errors) ArrayList(java.util.ArrayList) Error(org.folio.rest.jaxrs.model.Error) RequestContext(org.folio.rest.core.models.RequestContext) Validate(org.folio.rest.annotations.Validate)

Example 2 with ORDER_CONFIG_MODULE_NAME

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);
        }
    });
}
Also used : OrderInvoiceRelationService(org.folio.service.orders.OrderInvoiceRelationService) EN(org.folio.rest.RestConstants.EN) URL_WITH_LANG_PARAM(org.folio.orders.utils.HelperUtils.URL_WITH_LANG_PARAM) StringUtils(org.apache.commons.lang3.StringUtils) PoLineCommonUtil(org.folio.orders.utils.PoLineCommonUtil) Matcher(java.util.regex.Matcher) HelperUtils.verifyProtectedFieldsChanged(org.folio.orders.utils.HelperUtils.verifyProtectedFieldsChanged) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) ORDER_CONFIG_MODULE_NAME(org.folio.orders.utils.HelperUtils.ORDER_CONFIG_MODULE_NAME) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) Errors(org.folio.rest.jaxrs.model.Errors) Alert(org.folio.rest.jaxrs.model.Alert) ErrorCodes(org.folio.rest.core.exceptions.ErrorCodes) ConfigurationEntriesService(org.folio.service.configuration.ConfigurationEntriesService) REPORTING_CODES(org.folio.orders.utils.ResourcePathResolver.REPORTING_CODES) OPEN(org.folio.rest.jaxrs.model.CompositePurchaseOrder.WorkflowStatus.OPEN) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) Eresource(org.folio.rest.jaxrs.model.Eresource) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) PO_LINES_STORAGE(org.folio.orders.utils.ResourcePathResolver.PO_LINES_STORAGE) ExpenseClassValidationService(org.folio.service.finance.expenceclass.ExpenseClassValidationService) RestClient(org.folio.rest.core.RestClient) UPDATE(org.folio.orders.utils.ProtectedOperationType.UPDATE) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) FolioVertxCompletableFuture(org.folio.completablefuture.FolioVertxCompletableFuture) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) OrderFormat(org.folio.rest.jaxrs.model.CompositePoLine.OrderFormat) ResourcePathResolver.resourcesPath(org.folio.orders.utils.ResourcePathResolver.resourcesPath) SequenceNumbers(org.folio.rest.acq.model.SequenceNumbers) Physical(org.folio.rest.jaxrs.model.Physical) ALERTS(org.folio.orders.utils.ResourcePathResolver.ALERTS) PO_LINE_NUMBER(org.folio.orders.utils.ResourcePathResolver.PO_LINE_NUMBER) HelperUtils(org.folio.orders.utils.HelperUtils) RequestEntry(org.folio.rest.core.models.RequestEntry) PostResponseType(org.folio.rest.core.PostResponseType) HelperUtils.combineCqlExpressions(org.folio.orders.utils.HelperUtils.combineCqlExpressions) JsonArray(io.vertx.core.json.JsonArray) ResourcePathResolver.resourceByIdPath(org.folio.orders.utils.ResourcePathResolver.resourceByIdPath) PoLineCollection(org.folio.rest.jaxrs.model.PoLineCollection) OrderWorkflowType(org.folio.service.orders.OrderWorkflowType) EVENT_PAYLOAD(org.folio.helper.AbstractHelper.EVENT_PAYLOAD) Cost(org.folio.rest.jaxrs.model.Cost) JsonObject.mapFrom(io.vertx.core.json.JsonObject.mapFrom) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) PurchaseOrderStorageService(org.folio.service.orders.PurchaseOrderStorageService) PoNumberHelper.buildPoLineNumber(org.folio.helper.PoNumberHelper.buildPoLineNumber) HelperUtils.collectResultsOnSuccess(org.folio.orders.utils.HelperUtils.collectResultsOnSuccess) PoLine(org.folio.rest.jaxrs.model.PoLine) ProtectionService(org.folio.service.ProtectionService) CollectionUtils.isEqualCollection(org.apache.commons.collections4.CollectionUtils.isEqualCollection) LOCATION_CAN_NOT_BE_MODIFIER_AFTER_OPEN(org.folio.rest.core.exceptions.ErrorCodes.LOCATION_CAN_NOT_BE_MODIFIER_AFTER_OPEN) HelperUtils.operateOnObject(org.folio.orders.utils.HelperUtils.operateOnObject) HelperUtils.deletePoLine(org.folio.orders.utils.HelperUtils.deletePoLine) Predicate(java.util.function.Predicate) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ID(org.folio.helper.AbstractHelper.ID) List(java.util.List) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) Response(javax.ws.rs.core.Response) CompositePoLineValidationService(org.folio.service.orders.CompositePoLineValidationService) ReportingCode(org.folio.rest.jaxrs.model.ReportingCode) EncumbranceService(org.folio.service.finance.transaction.EncumbranceService) Optional(java.util.Optional) Parameter(org.folio.rest.jaxrs.model.Parameter) ORDER_ID(org.folio.helper.AbstractHelper.ORDER_ID) Pattern(java.util.regex.Pattern) AcquisitionsUnitsService(org.folio.service.AcquisitionsUnitsService) ProtectedOperationType(org.folio.orders.utils.ProtectedOperationType) HttpException(org.folio.rest.core.exceptions.HttpException) ProductId(org.folio.rest.jaxrs.model.ProductId) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PENDING(org.folio.rest.jaxrs.model.CompositePurchaseOrder.WorkflowStatus.PENDING) POLineProtectedFieldsUtil(org.folio.orders.utils.POLineProtectedFieldsUtil) Title(org.folio.rest.jaxrs.model.Title) TitlesService(org.folio.service.titles.TitlesService) CompletableFuture.allOf(java.util.concurrent.CompletableFuture.allOf) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) RequestContext(org.folio.rest.core.models.RequestContext) HelperUtils.getPoLineLimit(org.folio.orders.utils.HelperUtils.getPoLineLimit) DELETE(org.folio.orders.utils.ProtectedOperationType.DELETE) EncumbranceWorkflowStrategyFactory(org.folio.service.finance.transaction.EncumbranceWorkflowStrategyFactory) InventoryManager(org.folio.service.inventory.InventoryManager) RestConstants(org.folio.rest.RestConstants) EncumbranceWorkflowStrategy(org.folio.service.finance.transaction.EncumbranceWorkflowStrategy) Iterator(java.util.Iterator) MessageAddress(org.folio.orders.events.handlers.MessageAddress) CLOSED(org.folio.rest.jaxrs.model.CompositePurchaseOrder.WorkflowStatus.CLOSED) Error(org.folio.rest.jaxrs.model.Error) Collectors.toList(java.util.stream.Collectors.toList) HelperUtils.calculateEstimatedPrice(org.folio.orders.utils.HelperUtils.calculateEstimatedPrice) HttpMethod(io.vertx.core.http.HttpMethod) PurchaseOrderLineService(org.folio.service.orders.PurchaseOrderLineService) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) Errors(org.folio.rest.jaxrs.model.Errors) JsonObject(io.vertx.core.json.JsonObject) HttpException(org.folio.rest.core.exceptions.HttpException)

Example 3 with ORDER_CONFIG_MODULE_NAME

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));
}
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

JsonObject (io.vertx.core.json.JsonObject)3 Map (java.util.Map)3 Response (javax.ws.rs.core.Response)3 StringUtils (org.apache.commons.lang3.StringUtils)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 ORDER_CONFIG_MODULE_NAME (org.folio.orders.utils.HelperUtils.ORDER_CONFIG_MODULE_NAME)3 ResourcePathResolver.resourceByIdPath (org.folio.orders.utils.ResourcePathResolver.resourceByIdPath)3 RequestContext (org.folio.rest.core.models.RequestContext)3 Errors (org.folio.rest.jaxrs.model.Errors)3 ConfigurationEntriesService (org.folio.service.configuration.ConfigurationEntriesService)3 AsyncResult (io.vertx.core.AsyncResult)2 Context (io.vertx.core.Context)2 Future.succeededFuture (io.vertx.core.Future.succeededFuture)2 Handler (io.vertx.core.Handler)2 Vertx (io.vertx.core.Vertx)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ErrorCodes (org.folio.rest.core.exceptions.ErrorCodes)2 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)2