Search in sources :

Example 1 with ErrorCodes

use of org.folio.rest.core.exceptions.ErrorCodes in project mod-orders by folio-org.

the class VendorHelper method createErrorWithId.

/**
 * Creates {@link Error} with id of corresponding vendor/access provider and poLines ids
 *
 * @param id vendor's/access provider's identifier
 * @param errorCodes error code
 * @param poLines list of composite PoLines
 * @return {@link Error} with id of failed vendor/access provider
 */
private Error createErrorWithId(ErrorCodes errorCodes, String id, List<CompositePoLine> poLines) {
    Error error = createErrorWithId(errorCodes, id);
    poLines.stream().filter(p -> p.getPoLineNumber() != null).forEach(p -> error.getParameters().add(new Parameter().withKey(PO_LINE_NUMBER).withValue(p.getPoLineNumber())));
    return error;
}
Also used : ORGANIZATION_NOT_A_VENDOR(org.folio.rest.core.exceptions.ErrorCodes.ORGANIZATION_NOT_A_VENDOR) HttpException(org.folio.rest.core.exceptions.HttpException) POL_ACCESS_PROVIDER_NOT_FOUND(org.folio.rest.core.exceptions.ErrorCodes.POL_ACCESS_PROVIDER_NOT_FOUND) CompletableFuture(java.util.concurrent.CompletableFuture) Context(io.vertx.core.Context) ArrayList(java.util.ArrayList) HelperUtils.convertIdsToCqlQuery(org.folio.orders.utils.HelperUtils.convertIdsToCqlQuery) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) ORDER_VENDOR_NOT_FOUND(org.folio.rest.core.exceptions.ErrorCodes.ORDER_VENDOR_NOT_FOUND) Errors(org.folio.rest.jaxrs.model.Errors) ORDER_VENDOR_IS_INACTIVE(org.folio.rest.core.exceptions.ErrorCodes.ORDER_VENDOR_IS_INACTIVE) VENDOR_ISSUE(org.folio.rest.core.exceptions.ErrorCodes.VENDOR_ISSUE) Set(java.util.Set) ErrorCodes(org.folio.rest.core.exceptions.ErrorCodes) HelperUtils.handleGetRequest(org.folio.orders.utils.HelperUtils.handleGetRequest) Collectors(java.util.stream.Collectors) Error(org.folio.rest.jaxrs.model.Error) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) Organization(org.folio.rest.acq.model.Organization) HttpStatus(org.folio.HttpStatus) HelperUtils.encodeQuery(org.folio.orders.utils.HelperUtils.encodeQuery) Parameter(org.folio.rest.jaxrs.model.Parameter) POL_ACCESS_PROVIDER_IS_INACTIVE(org.folio.rest.core.exceptions.ErrorCodes.POL_ACCESS_PROVIDER_IS_INACTIVE) Error(org.folio.rest.jaxrs.model.Error) Parameter(org.folio.rest.jaxrs.model.Parameter)

Example 2 with ErrorCodes

use of org.folio.rest.core.exceptions.ErrorCodes in project mod-orders by folio-org.

the class CompositePoLineValidationService method validateCostPrices.

private List<Error> validateCostPrices(CompositePoLine compLine) {
    List<ErrorCodes> errors = new ArrayList<>();
    Cost cost = compLine.getCost();
    CompositePoLine.OrderFormat orderFormat = compLine.getOrderFormat();
    // Using default value as -1 to avoid null checks
    double unitPrice = defaultIfNull(cost.getListUnitPrice(), -1d);
    if (orderFormat == ELECTRONIC_RESOURCE) {
        if (unitPrice > 0d) {
            errors.add(ErrorCodes.COST_UNIT_PRICE_INVALID);
        }
    } else if (unitPrice < 0d) {
        errors.add(ErrorCodes.COST_UNIT_PRICE_INVALID);
    }
    double unitPriceElectronic = defaultIfNull(cost.getListUnitPriceElectronic(), -1d);
    if (orderFormat == ELECTRONIC_RESOURCE || orderFormat == P_E_MIX) {
        if (unitPriceElectronic < 0d) {
            errors.add(ErrorCodes.COST_UNIT_PRICE_ELECTRONIC_INVALID);
        }
    } else if (unitPriceElectronic > 0d) {
        errors.add(ErrorCodes.COST_UNIT_PRICE_ELECTRONIC_INVALID);
    }
    double additionalCost = defaultIfNull(cost.getAdditionalCost(), 0d);
    if (additionalCost < 0d) {
        errors.add(ErrorCodes.COST_ADDITIONAL_COST_INVALID);
    }
    if (isDiscountNotValid(cost)) {
        errors.add(ErrorCodes.COST_DISCOUNT_INVALID);
    }
    return convertErrorCodesToErrors(compLine, errors);
}
Also used : ErrorCodes(org.folio.rest.core.exceptions.ErrorCodes) ArrayList(java.util.ArrayList) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Cost(org.folio.rest.jaxrs.model.Cost)

Example 3 with ErrorCodes

use of org.folio.rest.core.exceptions.ErrorCodes in project mod-orders by folio-org.

the class CompositePoLineValidationUtil method validateCostPrices.

private static List<Error> validateCostPrices(CompositePoLine compLine) {
    List<ErrorCodes> errors = new ArrayList<>();
    Cost cost = compLine.getCost();
    CompositePoLine.OrderFormat orderFormat = compLine.getOrderFormat();
    // Using default value as -1 to avoid null checks
    double unitPrice = defaultIfNull(cost.getListUnitPrice(), -1d);
    if (orderFormat == ELECTRONIC_RESOURCE) {
        if (unitPrice > 0d) {
            errors.add(ErrorCodes.COST_UNIT_PRICE_INVALID);
        }
    } else if (unitPrice < 0d) {
        errors.add(ErrorCodes.COST_UNIT_PRICE_INVALID);
    }
    double unitPriceElectronic = defaultIfNull(cost.getListUnitPriceElectronic(), -1d);
    if (orderFormat == ELECTRONIC_RESOURCE || orderFormat == P_E_MIX) {
        if (unitPriceElectronic < 0d) {
            errors.add(ErrorCodes.COST_UNIT_PRICE_ELECTRONIC_INVALID);
        }
    } else if (unitPriceElectronic > 0d) {
        errors.add(ErrorCodes.COST_UNIT_PRICE_ELECTRONIC_INVALID);
    }
    double additionalCost = defaultIfNull(cost.getAdditionalCost(), 0d);
    if (additionalCost < 0d) {
        errors.add(ErrorCodes.COST_ADDITIONAL_COST_INVALID);
    }
    if (isDiscountNotValid(cost)) {
        errors.add(ErrorCodes.COST_DISCOUNT_INVALID);
    }
    return convertErrorCodesToErrors(compLine, errors);
}
Also used : ErrorCodes(org.folio.rest.core.exceptions.ErrorCodes) ArrayList(java.util.ArrayList) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Cost(org.folio.rest.jaxrs.model.Cost)

Aggregations

ArrayList (java.util.ArrayList)3 ErrorCodes (org.folio.rest.core.exceptions.ErrorCodes)3 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)3 Cost (org.folio.rest.jaxrs.model.Cost)2 Context (io.vertx.core.Context)1 JsonObject (io.vertx.core.json.JsonObject)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 HttpStatus (org.folio.HttpStatus)1 HelperUtils.convertIdsToCqlQuery (org.folio.orders.utils.HelperUtils.convertIdsToCqlQuery)1 HelperUtils.encodeQuery (org.folio.orders.utils.HelperUtils.encodeQuery)1 HelperUtils.handleGetRequest (org.folio.orders.utils.HelperUtils.handleGetRequest)1 Organization (org.folio.rest.acq.model.Organization)1 ORDER_VENDOR_IS_INACTIVE (org.folio.rest.core.exceptions.ErrorCodes.ORDER_VENDOR_IS_INACTIVE)1 ORDER_VENDOR_NOT_FOUND (org.folio.rest.core.exceptions.ErrorCodes.ORDER_VENDOR_NOT_FOUND)1 ORGANIZATION_NOT_A_VENDOR (org.folio.rest.core.exceptions.ErrorCodes.ORGANIZATION_NOT_A_VENDOR)1