org.apache.solr.schema

## Class OpenExchangeRatesOrgProvider

- java.lang.Object
- - org.apache.solr.schema.OpenExchangeRatesOrgProvider

- All Implemented Interfaces:
    ExchangeRateProvider

      public class OpenExchangeRatesOrgProvider
      extends Object
      implements ExchangeRateProvider

  Exchange Rates Provider for `CurrencyField` 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:
    openexchangerates.org JSON Data Format

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static String` | `DEFAULT_REFRESH_INTERVAL`
    `protected static String` | `PARAM_RATES_FILE_LOCATION`
    `protected static String` | `PARAM_REFRESH_INTERVAL`
    `protected org.apache.solr.schema.OpenExchangeRatesOrgProvider.OpenExchangeRates` | `rates`
    `protected String` | `ratesFileLocation`
    `protected int` | `refreshIntervalSeconds`
    `protected ResourceLoader` | `resourceLoader`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `OpenExchangeRatesOrgProvider()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(Object o)`
    `double` | `getExchangeRate(String sourceCurrencyCode, String targetCurrencyCode)` Returns the currently known exchange rate between two currencies.
    `int` | `hashCode()`
    `void` | `inform(ResourceLoader loader)` Passes a ResourceLoader, used to read config files from e.g.
    `void` | `init(Map<String,String> params)` Initializes the provider by passing in a set of key/value configs as a map.
    `Set<String>` | `listAvailableCurrencies()` List all configured currency codes which are valid as source/target for this Provider
    `boolean` | `reload()` Ask the currency provider to explicitly reload/refresh its configuration.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### PARAM_RATES_FILE_LOCATION

          protected static final String PARAM_RATES_FILE_LOCATION

      See Also:
        Constant Field Values

    - #### PARAM_REFRESH_INTERVAL

          protected static final String PARAM_REFRESH_INTERVAL

      See Also:
        Constant Field Values

    - #### DEFAULT_REFRESH_INTERVAL

          protected static final String DEFAULT_REFRESH_INTERVAL

      See Also:
        Constant Field Values

    - #### ratesFileLocation

          protected String ratesFileLocation

    - #### refreshIntervalSeconds

          protected int refreshIntervalSeconds

    - #### resourceLoader

          protected ResourceLoader resourceLoader

    - #### rates

          protected org.apache.solr.schema.OpenExchangeRatesOrgProvider.OpenExchangeRates rates

  - ### Constructor Detail

    - #### OpenExchangeRatesOrgProvider

          public OpenExchangeRatesOrgProvider()

  - ### Method Detail

    - #### getExchangeRate

          public double getExchangeRate(String sourceCurrencyCode,
                                        String targetCurrencyCode)

      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:
        `getExchangeRate` in interface `ExchangeRateProvider`
      Parameters:
        `sourceCurrencyCode` - The source currency being converted from.
        `targetCurrencyCode` - The target currency being converted to.
      Returns:
        The exchange rate.
      Throws:
        `SolrException` - if the requested currency pair cannot be found

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### listAvailableCurrencies

          public Set<String> listAvailableCurrencies()

      Description copied from interface: `ExchangeRateProvider`
      List all configured currency codes which are valid as source/target for this Provider
      Specified by:
        `listAvailableCurrencies` in interface `ExchangeRateProvider`
      Returns:
        a Set of ISO 4217 currency code strings

    - #### reload

          public boolean reload()
                         throws SolrException

      Description copied from interface: `ExchangeRateProvider`
      Ask the currency provider to explicitly reload/refresh its configuration. If this does not make sense for a particular provider, simply do nothing
      Specified by:
        `reload` in interface `ExchangeRateProvider`
      Returns:
        true if reload of rates succeeded, else false
      Throws:
        `SolrException` - if there is a problem reloading

    - #### init

          public void init(Map<String,String> params)
                    throws SolrException

      Description copied from interface: `ExchangeRateProvider`
      Initializes 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:
        `init` in interface `ExchangeRateProvider`
      Parameters:
        `params` - a @Map of key/value config params to initialize the provider
      Throws:
        `SolrException`

    - #### inform

          public void inform(ResourceLoader loader)
                      throws SolrException

      Description copied from interface: `ExchangeRateProvider`
      Passes 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:
        `inform` in interface `ExchangeRateProvider`
      Parameters:
        `loader` - a @ResourceLoader instance
      Throws:
        `SolrException`

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.