Panagiotis Triantafyllou

new login implementation with JWT, new logout, optimizations

......@@ -36,9 +36,10 @@ public class SplashActivity extends BaseActivity {
@Override
public void onWarplyReady() {
if (!WarplyDBHelper.getInstance(SplashActivity.this).isTableNotEmpty("auth")) {
WarplyManager.getCosmoteUser(new WarplyCosmoteUserRequest()
.setGuid("7000023717"), //6012049321, 6012049322, 6012049323, 7000000831 history, 7000000826, 7000000831 shared coupons, prod 6006552990, prod 6005892749, live 3000184910,prod 7000070282
mLoginReceiver);
//6012049321, 6012049322, 6012049323, 7000000831 history, 7000000826, 7000000831 shared coupons
//prod 6006552990, prod 6005892749, live 3000184910,prod 7000070282
WarplyManager.getCosmoteUser("7000000833", mLoginReceiver);
// WarplyManager.verifyTicket("", "7000000833", mLoginReceiver);
} else {
startNextActivity();
}
......
......@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'ly.warp'
PUBLISH_VERSION = '4.5.5.4r18'
PUBLISH_VERSION = '4.5.5.4r19'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......@@ -112,6 +112,9 @@ dependencies {
//------------------------------ Lifecycle -----------------------------//
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
//------------------------------ Retrofit Logs -----------------------------//
// implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0'
}
// In every export please update the version number
......
......@@ -18,6 +18,8 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import org.json.JSONObject;
import java.util.ArrayList;
import ly.warp.sdk.R;
......@@ -120,6 +122,10 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip
if (view.getId() == R.id.rl_driving_history) {
Intent intent = new Intent(getContext(), TelematicsHistoryActivity.class);
startActivity(intent);
return;
}
if (view.getId() == R.id.iv_settings) {
WarplyManager.logout(mLogoutReceiver);
}
}
......@@ -152,4 +158,16 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip
Toast.makeText(getActivity(), "Coupons Error", Toast.LENGTH_SHORT).show();
}
};
private final CallbackReceiver<JSONObject> mLogoutReceiver = new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
Toast.makeText(getActivity(), "LOGOUT SUCCESS", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(int errorCode) {
Toast.makeText(getActivity(), "LOGOUT ERROR", Toast.LENGTH_SHORT).show();
}
};
}
\ No newline at end of file
......
......@@ -47,7 +47,12 @@ public class ApiClient {
}
private static OkHttpClient getClient() {
/* Logs Enabled */
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
return new OkHttpClient.Builder()
// .addInterceptor(interceptor) // Logs Enabled
.connectTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
......
......@@ -44,6 +44,39 @@ public interface ApiService {
@Header(WarpConstants.HEADER_SIGNATURE) String signature);
@Headers("Content-Type: application/json")
@POST("/partners/oauth/{appUuid}/token")
Call<ResponseBody> cosmoteUser(@Path("appUuid") String appUuid,
@Body RequestBody request,
@Header(WarpConstants.HEADER_DATE) String timeStamp,
@Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId,
@Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId,
@Header(WarpConstants.HEADER_CHANNEL) String channel,
@Header(WarpConstants.HEADER_WEB_ID) String webId,
@Header(WarpConstants.HEADER_SIGNATURE) String signature,
@Header(WarpConstants.HEADER_AUTHORIZATION) String basic);
@Headers("Content-Type: application/json")
@POST("/partners/cosmote/verify")
Call<ResponseBody> verifyUser(@Body RequestBody request,
@Header(WarpConstants.HEADER_DATE) String timeStamp,
@Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId,
@Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId,
@Header(WarpConstants.HEADER_CHANNEL) String channel,
@Header(WarpConstants.HEADER_WEB_ID) String webId,
@Header(WarpConstants.HEADER_SIGNATURE) String signature);
@Headers("Content-Type: application/json")
@POST("/oauth/{appUuid}/logout")
Call<ResponseBody> logoutUser(@Path("appUuid") String appUuid,
@Body RequestBody request,
@Header(WarpConstants.HEADER_DATE) String timeStamp,
@Header(WarpConstants.HEADER_LOYALTY_BUNDLE_ID) String bundleId,
@Header(WarpConstants.HEADER_UNIQUE_DEVICE_ID) String deviceId,
@Header(WarpConstants.HEADER_CHANNEL) String channel,
@Header(WarpConstants.HEADER_WEB_ID) String webId,
@Header(WarpConstants.HEADER_SIGNATURE) String signature);
@Headers("Content-Type: application/json")
@POST("/oauth/{appUuid}/context")
Call<ResponseBody> getCouponsets(@Path("appUuid") String appUuid,
@Body RequestBody request,
......
......@@ -596,6 +596,33 @@ public class WarplyManager {
WarpUtils.log("[WARP Trace] WARPLY Logout is active");
WarpUtils.log("**************************************************");
ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
String webId = WarpUtils.getWebId(Warply.getWarplyContext());
Map<String, Object> jsonParams = new ArrayMap<>();
jsonParams.put("access_token", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token"));
jsonParams.put("refresh_token", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("refresh_token"));
RequestBody loginRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParams)).toString());
Call<ResponseBody> logoutCall = service.logoutUser(
WarplyProperty.getAppUuid(Warply.getWarplyContext()),
loginRequest,
timeStamp,
"android:" + Warply.getWarplyContext().getPackageName(),
new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(),
"mobile",
webId,
WarpUtils.produceSignature(apiKey + timeStamp)
);
logoutCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
if (response.code() == 200 && response.body() != null) {
WarpUtils.setUserNonTelco(Warply.getWarplyContext(), false);
WarpUtils.setUserTag(Warply.getWarplyContext(), "");
WarplyManagerHelper.clearCCMSLoyaltyCampaigns();
......@@ -618,6 +645,22 @@ public class WarplyManager {
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(2);
}
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_logout_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(response.code());
}
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_logout_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(2);
}
});
}
public static void changePassword(WarplyChangePasswordRequest request, final CallbackReceiver<JSONObject> receiver) {
......@@ -856,6 +899,284 @@ public class WarplyManager {
});
}
public static void getCosmoteUser(String guid, final CallbackReceiver<JSONObject> receiver) {
WarpUtils.log("************* WARPLY Cosmote User Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Cosmote User Request is active");
WarpUtils.log("**************************************************");
ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
String webId = WarpUtils.getWebId(Warply.getWarplyContext());
Map<String, Object> jsonParams = new ArrayMap<>();
jsonParams.put("user_identifier", guid);
RequestBody loginRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParams)).toString());
Call<ResponseBody> loginCall = service.cosmoteUser(
WarplyProperty.getAppUuid(Warply.getWarplyContext()),
loginRequest,
timeStamp,
"android:" + Warply.getWarplyContext().getPackageName(),
new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(),
"mobile",
webId,
WarpUtils.produceSignature(apiKey + timeStamp),
"Basic MVBQNFhCQzhFYTJBaUdCNkJWZGFGUERlTTNLQ3kzMjU6YzViMzAyZDY5N2FiNGY3NzhiNThhMTg0YzBkZWRmNGU="
);
loginCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
if (response.code() == 200 && response.body() != null) {
JSONObject jobjLoginResponse = null;
try {
jobjLoginResponse = new JSONObject(response.body().string());
} catch (Exception e) {
e.printStackTrace();
}
if (jobjLoginResponse != null && jobjLoginResponse.has("status") && jobjLoginResponse.optString("status", "2").equals("1")) {
JSONObject tokens = jobjLoginResponse.optJSONObject("result");
if (tokens != null) {
WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveClientAccess(
tokens.optString("client_id", ""),
tokens.optString("client_secret", "")
);
WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveAuthAccess(
tokens.optString("access_token", ""),
tokens.optString("refresh_token", "")
);
JSONObject newResult = new JSONObject();
try {
newResult.putOpt("status", 1);
newResult.putOpt("message", "Success");
receiver.onSuccess(newResult);
} catch (JSONException e) {
e.printStackTrace();
receiver.onFailure(2);
}
getConsumer(new WarplyConsumerRequest(), new CallbackReceiver<Consumer>() {
@Override
public void onSuccess(Consumer result) {
WarplyManagerHelper.setConsumerInternal(result);
if (result != null) {
JSONObject profMetadata = WarpJSONParser.getJSONFromString(result.getProfileMetadata());
if (profMetadata != null && profMetadata.has("nonTelco")) {
WarpUtils.setUserNonTelco(Warply.getWarplyContext(), profMetadata.optBoolean("nonTelco"));
} else {
WarpUtils.setUserNonTelco(Warply.getWarplyContext(), false);
}
}
if (result != null) {
JSONObject profMetadata = WarpJSONParser.getJSONFromString(result.getProfileMetadata());
if (profMetadata != null) {
if (profMetadata.has("badge")) {
WarpUtils.setUserTag(Warply.getWarplyContext(), profMetadata.optString("badge"));
}
if (profMetadata.has("steps_enabled") && profMetadata.optBoolean("steps_enabled")) {
if (!isMyServiceRunning(WarplyHealthService.class)) {
Intent stepsServiceIntent = new Intent(Warply.getWarplyContext(), WarplyHealthService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
AlarmManager mgr = (AlarmManager) Warply.getWarplyContext().getSystemService(Context.ALARM_SERVICE);
PendingIntent pi = PendingIntent.getService(Warply.getWarplyContext(), 2002, stepsServiceIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_MUTABLE);
mgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1000, pi);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Warply.getWarplyContext().startForegroundService(stepsServiceIntent);
} else {
Warply.getWarplyContext().startService(stepsServiceIntent);
}
WarplyPacingEventModel pacingVisible = new WarplyPacingEventModel();
pacingVisible.setVisible(true);
EventBus.getDefault().post(new WarplyEventBusManager(pacingVisible));
}
}
}
}
}
@Override
public void onFailure(int errorCode) {
}
});
} else
receiver.onFailure(2);
} else {
receiver.onFailure(2);
}
} else {
receiver.onFailure(response.code());
}
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
receiver.onFailure(2);
}
});
}
public static void verifyTicket(String ticket, String guid, final CallbackReceiver<JSONObject> receiver) {
WarpUtils.log("************* WARPLY Verify Ticket Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Verify Ticket Request is active");
WarpUtils.log("**************************************************");
WarpUtils.setUserNonTelco(Warply.getWarplyContext(), false);
WarpUtils.setUserTag(Warply.getWarplyContext(), "");
WarplyManagerHelper.clearCCMSLoyaltyCampaigns();
ApiService service = ApiClient.getRetrofitInstance().create(ApiService.class);
String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
String webId = WarpUtils.getWebId(Warply.getWarplyContext());
Map<String, Object> jsonParams = new ArrayMap<>();
jsonParams.put("app_uuid", WarplyProperty.getAppUuid(Warply.getWarplyContext()));
jsonParams.put("guid", guid);
jsonParams.put("ticket", ticket);
RequestBody loginRequest = RequestBody.create(MediaType.get("application/json; charset=utf-8"), (new JSONObject(jsonParams)).toString());
Call<ResponseBody> loginCall = service.verifyUser(
loginRequest,
timeStamp,
"android:" + Warply.getWarplyContext().getPackageName(),
new WarplyDeviceInfoCollector(Warply.getWarplyContext()).getUniqueDeviceId(),
"mobile",
webId,
WarpUtils.produceSignature(apiKey + timeStamp)
);
loginCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
if (response.code() == 200 && response.body() != null) {
JSONObject jobjLoginResponse = null;
try {
jobjLoginResponse = new JSONObject(response.body().string());
} catch (Exception e) {
e.printStackTrace();
}
if (jobjLoginResponse != null && jobjLoginResponse.has("status") && jobjLoginResponse.optString("status", "2").equals("1")) {
JSONObject tokens = jobjLoginResponse.optJSONObject("result");
if (tokens != null) {
WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveClientAccess(
tokens.optString("client_id", ""),
tokens.optString("client_secret", "")
);
WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveAuthAccess(
tokens.optString("access_token", ""),
tokens.optString("refresh_token", "")
);
JSONObject newResult = new JSONObject();
try {
newResult.putOpt("status", 1);
newResult.putOpt("message", "Success");
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_success_login_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onSuccess(newResult);
} catch (JSONException e) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_login_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
e.printStackTrace();
receiver.onFailure(2);
}
getConsumer(new WarplyConsumerRequest(), new CallbackReceiver<Consumer>() {
@Override
public void onSuccess(Consumer result) {
WarplyManagerHelper.setConsumerInternal(result);
if (result != null) {
JSONObject profMetadata = WarpJSONParser.getJSONFromString(result.getProfileMetadata());
if (profMetadata != null && profMetadata.has("nonTelco")) {
WarpUtils.setUserNonTelco(Warply.getWarplyContext(), profMetadata.optBoolean("nonTelco"));
} else {
WarpUtils.setUserNonTelco(Warply.getWarplyContext(), false);
}
}
if (result != null) {
JSONObject profMetadata = WarpJSONParser.getJSONFromString(result.getProfileMetadata());
if (profMetadata != null) {
if (profMetadata.has("badge")) {
WarpUtils.setUserTag(Warply.getWarplyContext(), profMetadata.optString("badge"));
}
if (profMetadata.has("steps_enabled") && profMetadata.optBoolean("steps_enabled")) {
if (!isMyServiceRunning(WarplyHealthService.class)) {
Intent stepsServiceIntent = new Intent(Warply.getWarplyContext(), WarplyHealthService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
AlarmManager mgr = (AlarmManager) Warply.getWarplyContext().getSystemService(Context.ALARM_SERVICE);
PendingIntent pi = PendingIntent.getService(Warply.getWarplyContext(), 2002, stepsServiceIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
mgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1000, pi);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Warply.getWarplyContext().startForegroundService(stepsServiceIntent);
} else {
Warply.getWarplyContext().startService(stepsServiceIntent);
}
WarplyPacingEventModel pacingVisible = new WarplyPacingEventModel();
pacingVisible.setVisible(true);
EventBus.getDefault().post(new WarplyEventBusManager(pacingVisible));
}
}
}
}
}
@Override
public void onFailure(int errorCode) {
}
});
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_login_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(2);
}
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_login_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(2);
}
} else {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_login_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(response.code());
}
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_login_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
receiver.onFailure(2);
}
});
}
public static void verifyTicket(WarplyVerifyTicketRequest request, final CallbackReceiver<JSONObject> receiver) {
WarpUtils.log("************* WARPLY Verify Ticket Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Verify Ticket Request is active");
......@@ -1573,7 +1894,8 @@ public class WarplyManager {
//TODO: check to see if we need merchants global else delete request
ListenableFuture<MerchantList> futureMerchants = getMerchantsRetro(service);
ListenableFuture<CouponsetsList> futureCouponsets = getCouponsetsRetro(service);
ListenableFuture<CouponList> futureCoupons = getCouponsUniversalRetro(service, 0);
SettableFuture<CouponList> futureUniversal = SettableFuture.create();
ListenableFuture<CouponList> futureCoupons = getCouponsUniversalRetro(service, 0, futureUniversal);
ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureMerchants, futureCouponsets, futureCoupons);
ListenableFuture<CouponList> mergedResultFuture = Futures.transformAsync(
......@@ -1609,7 +1931,8 @@ public class WarplyManager {
ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(3));
ListenableFuture<ArrayList<Campaign>> futureCampaigns = getCampaignsRetro(service);
ListenableFuture<ArrayList<Campaign>> futurePersonalizedCampaigns = getCampaignsPersonalizedRetro(service, 0);
SettableFuture<ArrayList<Campaign>> futurePersonalized = SettableFuture.create();
ListenableFuture<ArrayList<Campaign>> futurePersonalizedCampaigns = getCampaignsPersonalizedRetro(service, 0, futurePersonalized);
ListenableFuture<JSONObject> futureCampaignAvailability = getCampaignAvailability(service);
ListenableFuture<List<Object>> allResultsFuture = Futures.allAsList(futureCampaigns, futurePersonalizedCampaigns, futureCampaignAvailability);
......@@ -1830,7 +2153,8 @@ public class WarplyManager {
dynatraceEvent.setEventName("custom_error_campaigns_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(response.code());
future.set(new ArrayList<Campaign>());
// future.set(new ArrayList<Campaign>());
future.setException(new Throwable());
}
}
......@@ -1840,16 +2164,15 @@ public class WarplyManager {
dynatraceEvent.setEventName("custom_error_campaigns_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(2);
future.set(new ArrayList<Campaign>());
// future.set(new ArrayList<Campaign>());
future.setException(new Throwable());
}
});
return future;
}
private static /*void*/ ListenableFuture<ArrayList<Campaign>> getCampaignsPersonalizedRetro(ApiService service, int tries/*, final CallbackReceiver<ArrayList<Campaign>> receiver*/) {
SettableFuture<ArrayList<Campaign>> future = SettableFuture.create();
private static /*void*/ ListenableFuture<ArrayList<Campaign>> getCampaignsPersonalizedRetro(ApiService service, int tries/*, final CallbackReceiver<ArrayList<Campaign>> receiver*/, SettableFuture<ArrayList<Campaign>> future) {
String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
String webId = WarpUtils.getWebId(Warply.getWarplyContext());
......@@ -1980,13 +2303,14 @@ public class WarplyManager {
public void onSuccess(JSONObject result) {
int status = result.optInt("status", 2);
if (status == 1)
getCampaignsPersonalizedRetro(service, tries/*, receiver*/);
getCampaignsPersonalizedRetro(service, tries/*, receiver*/, future);
else {
// receiver.onFailure(status);
if (tries < MAX_RETRIES) {
getCampaignsPersonalizedRetro(service, (tries + 1));
getCampaignsPersonalizedRetro(service, (tries + 1), future);
} else {
future.set(new ArrayList<Campaign>());
// future.set(new ArrayList<Campaign>());
future.setException(new Throwable());
}
}
}
......@@ -1995,9 +2319,10 @@ public class WarplyManager {
public void onFailure(int errorCode) {
// receiver.onFailure(errorCode);
if (tries < MAX_RETRIES) {
getCampaignsPersonalizedRetro(service, (tries + 1));
getCampaignsPersonalizedRetro(service, (tries + 1), future);
} else {
future.set(new ArrayList<Campaign>());
// future.set(new ArrayList<Campaign>());
future.setException(new Throwable());
}
}
});
......@@ -2006,7 +2331,8 @@ public class WarplyManager {
dynatraceEvent.setEventName("custom_error_campaigns_personalized_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(response.code());
future.set(new ArrayList<Campaign>());
// future.set(new ArrayList<Campaign>());
future.setException(new Throwable());
}
}
......@@ -2016,7 +2342,8 @@ public class WarplyManager {
dynatraceEvent.setEventName("custom_error_campaigns_personalized_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
// receiver.onFailure(2);
future.set(new ArrayList<Campaign>());
// future.set(new ArrayList<Campaign>());
future.setException(new Throwable());
}
});
......@@ -2093,7 +2420,8 @@ public class WarplyManager {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_available_coupons");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
future.set(new JSONObject());
// future.set(new JSONObject());
future.setException(new Throwable());
}
}
......@@ -2102,7 +2430,8 @@ public class WarplyManager {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_available_coupons");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
future.set(new JSONObject());
// future.set(new JSONObject());
future.setException(new Throwable());
}
});
......@@ -3630,7 +3959,8 @@ public class WarplyManager {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_couponsets_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
future.set(new CouponsetsList());
// future.set(new CouponsetsList());
future.setException(new Throwable());
}
}
......@@ -3639,7 +3969,8 @@ public class WarplyManager {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_couponsets_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
future.set(new CouponsetsList());
// future.set(new CouponsetsList());
future.setException(new Throwable());
}
});
......@@ -4149,7 +4480,8 @@ public class WarplyManager {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_shops_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
future.set(new MerchantList());
// future.set(new MerchantList());
future.setException(new Throwable());
}
}
......@@ -4158,7 +4490,8 @@ public class WarplyManager {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_shops_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
future.set(new MerchantList());
// future.set(new MerchantList());
future.setException(new Throwable());
}
});
......@@ -4310,9 +4643,7 @@ public class WarplyManager {
});
}
private static ListenableFuture<CouponList> getCouponsUniversalRetro(ApiService service, int tries) {
SettableFuture<CouponList> future = SettableFuture.create();
private static ListenableFuture<CouponList> getCouponsUniversalRetro(ApiService service, int tries, SettableFuture<CouponList> future) {
String timeStamp = DateFormat.format("yyyy-MM-dd hh:mm:ss", System.currentTimeMillis()).toString();
String apiKey = WarpUtils.getApiKey(Warply.getWarplyContext());
String webId = WarpUtils.getWebId(Warply.getWarplyContext());
......@@ -4422,13 +4753,14 @@ public class WarplyManager {
public void onSuccess(JSONObject result) {
int status = result.optInt("status", 2);
if (status == 1)
getCouponsUniversalRetro(service, tries/*, receiver*/);
getCouponsUniversalRetro(service, tries/*, receiver*/, future);
else {
// receiver.onFailure(status);
if (tries < MAX_RETRIES) {
getCouponsUniversalRetro(service, (tries + 1));
getCouponsUniversalRetro(service, (tries + 1), future);
} else {
future.set(new CouponList());
// future.set(new CouponList());
future.setException(new Throwable());
}
}
}
......@@ -4437,9 +4769,10 @@ public class WarplyManager {
public void onFailure(int errorCode) {
// receiver.onFailure(errorCode);
if (tries < MAX_RETRIES) {
getCouponsUniversalRetro(service, (tries + 1));
getCouponsUniversalRetro(service, (tries + 1), future);
} else {
future.set(new CouponList());
// future.set(new CouponList());
future.setException(new Throwable());
}
}
});
......@@ -4447,7 +4780,8 @@ public class WarplyManager {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_user_coupons_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
future.set(new CouponList());
// future.set(new CouponList());
future.setException(new Throwable());
}
}
......@@ -4456,7 +4790,8 @@ public class WarplyManager {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_error_user_coupons_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
future.set(new CouponList());
// future.set(new CouponList());
future.setException(new Throwable());
}
});
......