@Override public BigDecimal getPrice(final Currency currency) throws CatalogApiException { for (final Price p : prices) { if (p.getCurrency() == currency) { return p.getValue(); } } throw new CatalogApiException(ErrorCode.CAT_NO_PRICE_FOR_CURRENCY, currency); }
public PriceJson(final Price price) throws CurrencyValueNull { this(price.getCurrency().toString(), price.getValue()); }
@Override public PriceJson apply(final Price price) { try { return new PriceJson(price); } catch (CurrencyValueNull e) { return new PriceJson(price.getCurrency().toString(), BigDecimal.ZERO); } } });
@Override public ValidationErrors validate(final StandaloneCatalog catalog, final ValidationErrors errors) { final Currency[] supportedCurrencies = catalog.getCurrentSupportedCurrencies(); for (final Price p : prices) { final Currency currency = p.getCurrency(); if (!currencyIsSupported(currency, supportedCurrencies)) { errors.add("Unsupported currency: " + currency, catalog.getCatalogURI(), this.getClass(), ""); } try { if (p.getValue().doubleValue() < 0.0) { errors.add("Negative value for price in currency: " + currency, catalog.getCatalogURI(), this.getClass(), ""); } } catch (CurrencyValueNull e) { // No currency => nothing to check, ignore exception } } return errors; }