package com.github.vedenin.codingchallenge.restclient;

import com.github.vedenin.codingchallenge.common.CurrencyEnum;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.List;

/**
 * Created by slava on 10.02.17.
 */
@Service("FaultTolerant")
public class FaultTolerantRestClient implements RestClient {
    @Inject
    private List<RestClient> list;

    public BigDecimal getCurrentExchangeRates(CurrencyEnum currencyFrom, CurrencyEnum currencyTo) {
        for (RestClient client : list) {
            if (!(client instanceof FaultTolerantRestClient)) {
                try {
                    return client.getCurrentExchangeRates(currencyFrom, currencyTo);
                } catch (Exception ignore) {
                }
            }
        }
        return null;
    }

    public BigDecimal getHistoricalExchangeRates(CurrencyEnum currencyFrom, CurrencyEnum currencyTo, Calendar calendar) {
        for (RestClient client : list) {
            if (!(client instanceof FaultTolerantRestClient)) {
                try {
                    return client.getHistoricalExchangeRates(currencyFrom, currencyTo, calendar);
                } catch (Exception ignore) {
                }
            }
        }
        return null;
    }

}

@@ -272,16 +272,110 @@
 t;%0A%0A/**%0A
+ * Rest client that used all services before one of services not returns%0A * correct result%0A *%0A
  * Creat
@@ -683,76 +683,8 @@
 ) %7B%0A
-            if (!(client instanceof FaultTolerantRestClient)) %7B%0A    
     
@@ -689,36 +689,32 @@
           try %7B%0A
-    
                 
@@ -782,36 +782,32 @@
 o);%0A            
-    
 %7D catch (Excepti
@@ -819,34 +819,16 @@
 nore) %7B%0A
-                %7D%0A
         
@@ -1038,76 +1038,8 @@
 ) %7B%0A
-            if (!(client instanceof FaultTolerantRestClient)) %7B%0A    
     
@@ -1044,36 +1044,32 @@
           try %7B%0A
-    
                 
@@ -1150,36 +1150,32 @@
 r);%0A            
-    
 %7D catch (Excepti
@@ -1191,26 +1191,8 @@
 ) %7B%0A
-                %7D%0A
     

Add FaultTolerantRestClient