Showing
1 changed file
with
43 additions
and
22 deletions
... | @@ -186,6 +186,8 @@ import retrofit2.Response; | ... | @@ -186,6 +186,8 @@ import retrofit2.Response; |
186 | */ | 186 | */ |
187 | 187 | ||
188 | public class WarplyManager { | 188 | public class WarplyManager { |
189 | + private static final int MAX_RETRIES = 3; | ||
190 | + | ||
189 | public static void getProducts(WarplyProductsRequest request, final CallbackReceiver<ProductList> receiver) { | 191 | public static void getProducts(WarplyProductsRequest request, final CallbackReceiver<ProductList> receiver) { |
190 | // String productCategory = ""; | 192 | // String productCategory = ""; |
191 | // int resStringId = getWarplyContext().getResources().getIdentifier("products_category", "string", getWarplyContext().getPackageName()); | 193 | // int resStringId = getWarplyContext().getResources().getIdentifier("products_category", "string", getWarplyContext().getPackageName()); |
... | @@ -1568,7 +1570,7 @@ public class WarplyManager { | ... | @@ -1568,7 +1570,7 @@ public class WarplyManager { |
1568 | //TODO: check to see if we need merchants global else delete request | 1570 | //TODO: check to see if we need merchants global else delete request |
1569 | ListenableFuture<MerchantList> futureMerchants = getMerchantsRetro(service); | 1571 | ListenableFuture<MerchantList> futureMerchants = getMerchantsRetro(service); |
1570 | ListenableFuture<CouponsetsList> futureCouponsets = getCouponsetsRetro(service); | 1572 | ListenableFuture<CouponsetsList> futureCouponsets = getCouponsetsRetro(service); |
1571 | - ListenableFuture<CouponList> futureCoupons = getCouponsUniversalRetro(service); | 1573 | + ListenableFuture<CouponList> futureCoupons = getCouponsUniversalRetro(service, 0); |
1572 | 1574 | ||
1573 | ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureMerchants, futureCouponsets, futureCoupons); | 1575 | ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureMerchants, futureCouponsets, futureCoupons); |
1574 | ListenableFuture<CouponList> mergedResultFuture = Futures.transformAsync( | 1576 | ListenableFuture<CouponList> mergedResultFuture = Futures.transformAsync( |
... | @@ -1603,7 +1605,7 @@ public class WarplyManager { | ... | @@ -1603,7 +1605,7 @@ public class WarplyManager { |
1603 | ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(3)); | 1605 | ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(3)); |
1604 | 1606 | ||
1605 | ListenableFuture<ArrayList<Campaign>> futureCampaigns = getCampaignsRetro(service); | 1607 | ListenableFuture<ArrayList<Campaign>> futureCampaigns = getCampaignsRetro(service); |
1606 | - ListenableFuture<ArrayList<Campaign>> futurePersonalizedCampaigns = getCampaignsPersonalizedRetro(service); | 1608 | + ListenableFuture<ArrayList<Campaign>> futurePersonalizedCampaigns = getCampaignsPersonalizedRetro(service, 0); |
1607 | ListenableFuture<JSONObject> futureCampaignAvailability = getCampaignAvailability(service); | 1609 | ListenableFuture<JSONObject> futureCampaignAvailability = getCampaignAvailability(service); |
1608 | 1610 | ||
1609 | ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCampaigns, futurePersonalizedCampaigns, futureCampaignAvailability); | 1611 | ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCampaigns, futurePersonalizedCampaigns, futureCampaignAvailability); |
... | @@ -1835,7 +1837,7 @@ public class WarplyManager { | ... | @@ -1835,7 +1837,7 @@ public class WarplyManager { |
1835 | return future; | 1837 | return future; |
1836 | } | 1838 | } |
1837 | 1839 | ||
1838 | - private static /*void*/ ListenableFuture<ArrayList<Campaign>> getCampaignsPersonalizedRetro(ApiService service/*, final CallbackReceiver<ArrayList<Campaign>> receiver*/) { | 1840 | + private static /*void*/ ListenableFuture<ArrayList<Campaign>> getCampaignsPersonalizedRetro(ApiService service, int tries/*, final CallbackReceiver<ArrayList<Campaign>> receiver*/) { |
1839 | SettableFuture<ArrayList<Campaign>> future = SettableFuture.create(); | 1841 | SettableFuture<ArrayList<Campaign>> future = SettableFuture.create(); |
1840 | 1842 | ||
1841 | String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); | 1843 | String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); |
... | @@ -1963,17 +1965,25 @@ public class WarplyManager { | ... | @@ -1963,17 +1965,25 @@ public class WarplyManager { |
1963 | public void onSuccess(JSONObject result) { | 1965 | public void onSuccess(JSONObject result) { |
1964 | int status = result.optInt("status", 2); | 1966 | int status = result.optInt("status", 2); |
1965 | if (status == 1) | 1967 | if (status == 1) |
1966 | - getCampaignsPersonalizedRetro(service/*, receiver*/); | 1968 | + getCampaignsPersonalizedRetro(service, tries/*, receiver*/); |
1967 | else { | 1969 | else { |
1968 | // receiver.onFailure(status); | 1970 | // receiver.onFailure(status); |
1969 | - future.set(new ArrayList<Campaign>()); | 1971 | + if (tries < MAX_RETRIES) { |
1972 | + getCampaignsPersonalizedRetro(service, (tries + 1)); | ||
1973 | + } else { | ||
1974 | + future.set(new ArrayList<Campaign>()); | ||
1975 | + } | ||
1970 | } | 1976 | } |
1971 | } | 1977 | } |
1972 | 1978 | ||
1973 | @Override | 1979 | @Override |
1974 | public void onFailure(int errorCode) { | 1980 | public void onFailure(int errorCode) { |
1975 | // receiver.onFailure(errorCode); | 1981 | // receiver.onFailure(errorCode); |
1976 | - future.set(new ArrayList<Campaign>()); | 1982 | + if (tries < MAX_RETRIES) { |
1983 | + getCampaignsPersonalizedRetro(service, (tries + 1)); | ||
1984 | + } else { | ||
1985 | + future.set(new ArrayList<Campaign>()); | ||
1986 | + } | ||
1977 | } | 1987 | } |
1978 | }); | 1988 | }); |
1979 | } else { | 1989 | } else { |
... | @@ -4285,7 +4295,7 @@ public class WarplyManager { | ... | @@ -4285,7 +4295,7 @@ public class WarplyManager { |
4285 | }); | 4295 | }); |
4286 | } | 4296 | } |
4287 | 4297 | ||
4288 | - private static ListenableFuture<CouponList> getCouponsUniversalRetro(ApiService service) { | 4298 | + private static ListenableFuture<CouponList> getCouponsUniversalRetro(ApiService service, int tries) { |
4289 | SettableFuture<CouponList> future = SettableFuture.create(); | 4299 | SettableFuture<CouponList> future = SettableFuture.create(); |
4290 | 4300 | ||
4291 | String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); | 4301 | String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString(); |
... | @@ -4392,21 +4402,32 @@ public class WarplyManager { | ... | @@ -4392,21 +4402,32 @@ public class WarplyManager { |
4392 | future.set(new CouponList()); | 4402 | future.set(new CouponList()); |
4393 | } | 4403 | } |
4394 | } else if (response.code() == 401) { | 4404 | } else if (response.code() == 401) { |
4395 | -// refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() { | 4405 | + refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() { |
4396 | -// @Override | 4406 | + @Override |
4397 | -// public void onSuccess(JSONObject result) { | 4407 | + public void onSuccess(JSONObject result) { |
4398 | -// int status = result.optInt("status", 2); | 4408 | + int status = result.optInt("status", 2); |
4399 | -// if (status == 1) | 4409 | + if (status == 1) |
4400 | -// getCouponsUniversalRetro(service, callback); | 4410 | + getCouponsUniversalRetro(service, tries/*, receiver*/); |
4401 | -// else | 4411 | + else { |
4402 | -// callback.onFailure(call, new Throwable()); | 4412 | +// receiver.onFailure(status); |
4403 | -// } | 4413 | + if (tries < MAX_RETRIES) { |
4404 | -// | 4414 | + getCouponsUniversalRetro(service, (tries + 1)); |
4405 | -// @Override | 4415 | + } else { |
4406 | -// public void onFailure(int errorCode) { | 4416 | + future.set(new CouponList()); |
4407 | -// callback.onFailure(call, new Throwable()); | 4417 | + } |
4408 | -// } | 4418 | + } |
4409 | -// }); | 4419 | + } |
4420 | + | ||
4421 | + @Override | ||
4422 | + public void onFailure(int errorCode) { | ||
4423 | +// receiver.onFailure(errorCode); | ||
4424 | + if (tries < MAX_RETRIES) { | ||
4425 | + getCouponsUniversalRetro(service, (tries + 1)); | ||
4426 | + } else { | ||
4427 | + future.set(new CouponList()); | ||
4428 | + } | ||
4429 | + } | ||
4430 | + }); | ||
4410 | } else { | 4431 | } else { |
4411 | LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); | 4432 | LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel(); |
4412 | dynatraceEvent.setEventName("custom_error_user_coupons_loyalty"); | 4433 | dynatraceEvent.setEventName("custom_error_user_coupons_loyalty"); | ... | ... |
-
Please register or login to post a comment