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