Class DefaultCurrencyConversionService
- java.lang.Object
-
- com.broadleafcommerce.pricing.service.DefaultCurrencyConversionService
-
- All Implemented Interfaces:
CurrencyConversionService
public class DefaultCurrencyConversionService extends Object implements CurrencyConversionService
Implementation ofCurrencyConversionService
that relies on an implementation of ExchangeRateService and provides a mapping from and to for each item included in the ExchangeRateService- Author:
- Brian Polster (bpolster)
-
-
Constructor Summary
Constructors Constructor Description DefaultCurrencyConversionService(ExchangeRateInfoProvider provider)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Map<javax.money.CurrencyUnit,javax.money.convert.ExchangeRate>
buildExchangeRatesFromMap(javax.money.CurrencyUnit targetCurrency, Map<javax.money.CurrencyUnit,javax.money.convert.ExchangeRate> baseExchangeRates)
boolean
canCovert(javax.money.CurrencyUnit from, javax.money.CurrencyUnit to)
Determine if conversion support is available based on a currencyCode from and to.protected boolean
canEqual(Object other)
javax.money.MonetaryAmount
convert(javax.money.MonetaryAmount fromAmount, javax.money.CurrencyUnit toCurrency)
Converts the passed in MonetaryAmount to the requested currency.protected javax.money.convert.ExchangeRate
convertExchangeRate(javax.money.convert.ExchangeRate fromBaseToSrc, javax.money.convert.ExchangeRate fromBaseToTarget, javax.money.NumberValue newFactor)
boolean
equals(Object o)
List<String>
getBaseCurrencies()
protected javax.money.convert.ConversionContext
getDefaultContext()
javax.money.CurrencyUnit
getDefaultCurrency()
protected RoundingMode
getDefaultRoundingMode()
protected int
getDefaultScale()
Map<javax.money.CurrencyUnit,Map<javax.money.CurrencyUnit,javax.money.convert.ExchangeRate>>
getExchangeMap()
ExchangeRateInfoProvider
getExchangeRateInfoProvider()
int
hashCode()
void
init()
protected javax.money.convert.ExchangeRate
invertExchangeRate(javax.money.convert.ExchangeRate origRate, javax.money.NumberValue newFactor)
boolean
isAllowMappingThroughBaseCurrency()
protected void
populateBaseExchangeRates(ExchangeRateInfo exchangeRateInfo, Map<javax.money.CurrencyUnit,javax.money.convert.ExchangeRate> rates)
protected void
populateOtherExchangeRatesFromBase(javax.money.CurrencyUnit baseCurrency, Map<javax.money.CurrencyUnit,Map<javax.money.CurrencyUnit,javax.money.convert.ExchangeRate>> ratesMap)
void
refreshExchangeRateData()
protected void
refreshExchangeRateDataByCurrency(Optional<String> baseCurrency)
void
setAllowMappingThroughBaseCurrency(boolean allowMappingThroughBaseCurrency)
void
setBaseCurrencies(List<String> baseCurrencies)
void
setDefaultCurrency(javax.money.CurrencyUnit defaultCurrency)
void
setExchangeMap(Map<javax.money.CurrencyUnit,Map<javax.money.CurrencyUnit,javax.money.convert.ExchangeRate>> exchangeMap)
void
setExchangeRateInfoProvider(ExchangeRateInfoProvider exchangeRateInfoProvider)
String
toString()
-
-
-
Constructor Detail
-
DefaultCurrencyConversionService
public DefaultCurrencyConversionService(ExchangeRateInfoProvider provider)
-
-
Method Detail
-
init
@PostConstruct public void init()
-
canCovert
public boolean canCovert(javax.money.CurrencyUnit from, javax.money.CurrencyUnit to)
Determine if conversion support is available based on a currencyCode from and to. By default, if both currencies are found in the- Specified by:
canCovert
in interfaceCurrencyConversionService
- Parameters:
from
- The currency to convert from.to
- The currency to convert to.- Returns:
-
convert
public javax.money.MonetaryAmount convert(javax.money.MonetaryAmount fromAmount, javax.money.CurrencyUnit toCurrency)
Converts the passed in MonetaryAmount to the requested currency. The value will be rounded to the scale appropriate for the currency and as such, this method should not be used in intermediary calculations. Throws NullPointerException if the currencies cannot be converted. Call canConvert(from,to) before calling to insure support for the convert operation.- Specified by:
convert
in interfaceCurrencyConversionService
- Parameters:
fromAmount
-toCurrency
-- Returns:
-
refreshExchangeRateData
@Scheduled(fixedDelayString="${exchange.refresh.rate.in.milliseconds:86400000}") public void refreshExchangeRateData()
-
refreshExchangeRateDataByCurrency
protected void refreshExchangeRateDataByCurrency(Optional<String> baseCurrency)
-
populateBaseExchangeRates
protected void populateBaseExchangeRates(ExchangeRateInfo exchangeRateInfo, Map<javax.money.CurrencyUnit,javax.money.convert.ExchangeRate> rates)
-
populateOtherExchangeRatesFromBase
protected void populateOtherExchangeRatesFromBase(javax.money.CurrencyUnit baseCurrency, Map<javax.money.CurrencyUnit,Map<javax.money.CurrencyUnit,javax.money.convert.ExchangeRate>> ratesMap)
-
buildExchangeRatesFromMap
protected Map<javax.money.CurrencyUnit,javax.money.convert.ExchangeRate> buildExchangeRatesFromMap(javax.money.CurrencyUnit targetCurrency, Map<javax.money.CurrencyUnit,javax.money.convert.ExchangeRate> baseExchangeRates)
-
invertExchangeRate
protected javax.money.convert.ExchangeRate invertExchangeRate(javax.money.convert.ExchangeRate origRate, javax.money.NumberValue newFactor)
-
getDefaultContext
protected javax.money.convert.ConversionContext getDefaultContext()
-
convertExchangeRate
protected javax.money.convert.ExchangeRate convertExchangeRate(javax.money.convert.ExchangeRate fromBaseToSrc, javax.money.convert.ExchangeRate fromBaseToTarget, javax.money.NumberValue newFactor)
-
getDefaultRoundingMode
protected RoundingMode getDefaultRoundingMode()
-
getDefaultScale
protected int getDefaultScale()
-
getDefaultCurrency
public javax.money.CurrencyUnit getDefaultCurrency()
-
getExchangeRateInfoProvider
public ExchangeRateInfoProvider getExchangeRateInfoProvider()
-
getExchangeMap
public Map<javax.money.CurrencyUnit,Map<javax.money.CurrencyUnit,javax.money.convert.ExchangeRate>> getExchangeMap()
-
isAllowMappingThroughBaseCurrency
public boolean isAllowMappingThroughBaseCurrency()
-
setDefaultCurrency
public void setDefaultCurrency(javax.money.CurrencyUnit defaultCurrency)
-
setExchangeRateInfoProvider
public void setExchangeRateInfoProvider(ExchangeRateInfoProvider exchangeRateInfoProvider)
-
setExchangeMap
public void setExchangeMap(Map<javax.money.CurrencyUnit,Map<javax.money.CurrencyUnit,javax.money.convert.ExchangeRate>> exchangeMap)
-
setAllowMappingThroughBaseCurrency
public void setAllowMappingThroughBaseCurrency(boolean allowMappingThroughBaseCurrency)
-
canEqual
protected boolean canEqual(Object other)
-
-