/*
   * Service interface implementation
   */
  @Override
  public void start() throws CantStartPluginException {
    System.out.println("PROVIDERELCRONISTA - PluginRoot START");

    supportedCurrencyPairs.add(
        new CurrencyPairImpl(FiatCurrency.ARGENTINE_PESO, FiatCurrency.US_DOLLAR));
    supportedCurrencyPairs.add(
        new CurrencyPairImpl(FiatCurrency.US_DOLLAR, FiatCurrency.ARGENTINE_PESO));

    try {
      dao = new ElCronistaProviderDao(pluginDatabaseSystem, pluginId, errorManager);
      dao.initialize();
      dao.initializeProvider("ElCronista");
    } catch (Exception e) {
      errorManager.reportUnexpectedPluginException(
          Plugins.ELCRONISTA, UnexpectedPluginExceptionSeverity.DISABLES_THIS_PLUGIN, e);
      throw new CantStartPluginException(
          CantStartPluginException.DEFAULT_MESSAGE, FermatException.wrapException(e), null, null);
    }
    serviceStatus = ServiceStatus.STARTED;
  }
 @Override
 public Collection<ExchangeRate> getQueriedExchangeRates(CurrencyPair currencyPair)
     throws UnsupportedCurrencyPairException, CantGetExchangeRateException {
   return dao.getQueriedExchangeRateHistory(currencyPair);
 }
 @Override
 public UUID getProviderId() throws CantGetProviderInfoException {
   return dao.getProviderId();
 }
  @Override
  public ExchangeRate getCurrentExchangeRate(CurrencyPair currencyPair)
      throws UnsupportedCurrencyPairException, CantGetExchangeRateException {

    if (!isCurrencyPairSupported(currencyPair)) throw new UnsupportedCurrencyPairException();

    String content, aux;
    JSONObject json;
    JSONArray jsonArr;
    double purchasePrice = 0;
    double salePrice = 0;
    try {
      content = HttpReader.getHTTPContent("http://api.bluelytics.com.ar/json/last_price");
      json = new JSONObject("{\"indexes\": " + content + "}");
      jsonArr = json.getJSONArray("indexes");

      for (int i = 0; i < jsonArr.length(); ++i) {
        JSONObject jsonIndex = jsonArr.getJSONObject(i);
        if (jsonIndex.getString("source").equals("elcronista")) {
          aux = jsonIndex.get("value_buy").toString();
          purchasePrice = Double.valueOf(aux);
          aux = jsonIndex.get("value_sell").toString();
          salePrice = Double.valueOf(aux);
          break;
        }
      }
    } catch (JSONException e) {
      errorManager.reportUnexpectedPluginException(
          Plugins.ELCRONISTA, UnexpectedPluginExceptionSeverity.DISABLES_THIS_PLUGIN, e);
      throw new CantGetExchangeRateException(
          CantGetExchangeRateException.DEFAULT_MESSAGE,
          e,
          "ElCronista CER Provider",
          "Cant Get exchange rate for"
              + currencyPair.getFrom().getCode()
              + "-"
              + currencyPair.getTo().getCode());
    }

    if (currencyPair.getTo() == FiatCurrency.US_DOLLAR) {
      purchasePrice = 1 / purchasePrice;
      salePrice = 1 / salePrice;
    }

    ExchangeRateImpl exchangeRate =
        new ExchangeRateImpl(
            currencyPair.getFrom(),
            currencyPair.getTo(),
            purchasePrice,
            salePrice,
            (new Date().getTime() / 1000));
    try {
      dao.saveExchangeRate(exchangeRate);
    } catch (CantSaveExchangeRateException e) {
      errorManager.reportUnexpectedPluginException(
          Plugins.ELCRONISTA,
          UnexpectedPluginExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_PLUGIN,
          e);
    }
    return exchangeRate;
  }
 @Override
 public String getProviderName() throws CantGetProviderInfoException {
   return dao.getProviderName();
 }