Package org.apache.solr.schema
Class OpenExchangeRatesOrgProvider
java.lang.Object
org.apache.solr.schema.OpenExchangeRatesOrgProvider
- All Implemented Interfaces:
ExchangeRateProvider
Exchange Rates Provider for
CurrencyFieldType capable of fetching & parsing the
freely available exchange rates from openexchangerates.org
Configuration Options:
ratesFileLocation- A file path or absolute URL specifying the JSON data to load (mandatory)refreshInterval- How frequently (in minutes) to reload the exchange rate data (default: 1440)
Disclaimer: This data is collected from various providers and provided free of charge for informational purposes only, with no guarantee whatsoever of accuracy, validity, availability or fitness for any purpose; use at your own risk. Other than that - have fun, and please share/watch/fork if you think data like this should be free!
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleandoublegetExchangeRate(String sourceCurrencyCode, String targetCurrencyCode) Returns the currently known exchange rate between two currencies.inthashCode()voidinform(org.apache.lucene.util.ResourceLoader loader) Passes a ResourceLoader, used to read config files from e.g.voidInitializes the provider by passing in a set of key/value configs as a map.List all configured currency codes which are valid as source/target for this Providerbooleanreload()Ask the currency provider to explicitly reload/refresh its configuration.toString()
-
Field Details
-
PARAM_RATES_FILE_LOCATION
- See Also:
-
PARAM_REFRESH_INTERVAL
- See Also:
-
DEFAULT_REFRESH_INTERVAL
- See Also:
-
ratesFileLocation
-
refreshIntervalSeconds
protected int refreshIntervalSeconds -
resourceLoader
protected org.apache.lucene.util.ResourceLoader resourceLoader -
rates
protected org.apache.solr.schema.OpenExchangeRatesOrgProvider.OpenExchangeRates rates
-
-
Constructor Details
-
OpenExchangeRatesOrgProvider
public OpenExchangeRatesOrgProvider()
-
-
Method Details
-
getExchangeRate
Returns the currently known exchange rate between two currencies. The rates are fetched from the freely available OpenExchangeRates.org JSON, hourly updated. All rates are symmetrical with base currency being USD by default.- Specified by:
getExchangeRatein interfaceExchangeRateProvider- Parameters:
sourceCurrencyCode- The source currency being converted from.targetCurrencyCode- The target currency being converted to.- Returns:
- The exchange rate.
- Throws:
org.apache.solr.common.SolrException- if the requested currency pair cannot be found
-
equals
-
hashCode
public int hashCode() -
toString
-
listAvailableCurrencies
Description copied from interface:ExchangeRateProviderList all configured currency codes which are valid as source/target for this Provider- Specified by:
listAvailableCurrenciesin interfaceExchangeRateProvider- Returns:
- a Set of ISO 4217 currency code strings
-
reload
public boolean reload() throws org.apache.solr.common.SolrExceptionDescription copied from interface:ExchangeRateProviderAsk the currency provider to explicitly reload/refresh its configuration. If this does not make sense for a particular provider, simply do nothing- Specified by:
reloadin interfaceExchangeRateProvider- Returns:
- true if reload of rates succeeded, else false
- Throws:
org.apache.solr.common.SolrException- if there is a problem reloading
-
init
Description copied from interface:ExchangeRateProviderInitializes the provider by passing in a set of key/value configs as a map. Note that the map also contains other fieldType parameters, so make sure to avoid name clashes.Important: Custom config params must be removed from the map before returning
- Specified by:
initin interfaceExchangeRateProvider- Parameters:
params- a @Map of key/value config params to initialize the provider- Throws:
org.apache.solr.common.SolrException
-
inform
public void inform(org.apache.lucene.util.ResourceLoader loader) throws org.apache.solr.common.SolrException Description copied from interface:ExchangeRateProviderPasses a ResourceLoader, used to read config files from e.g. ZooKeeper. Implementations not needing resource loader can implement this as NOOP.Typically called after init
- Specified by:
informin interfaceExchangeRateProvider- Parameters:
loader- a @ResourceLoader instance- Throws:
org.apache.solr.common.SolrException
-