user sys api

parent 64c71424
...@@ -10,6 +10,7 @@ import retrofit2.Call; ...@@ -10,6 +10,7 @@ import retrofit2.Call;
import retrofit2.http.Body; import retrofit2.http.Body;
import retrofit2.http.Field; import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded; import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Header; import retrofit2.http.Header;
import retrofit2.http.POST; import retrofit2.http.POST;
import retrofit2.http.PUT; import retrofit2.http.PUT;
...@@ -46,6 +47,8 @@ public interface LoginApi { ...@@ -46,6 +47,8 @@ public interface LoginApi {
Call<LiveAgentResultData> postChatHistory(@Query(Constants.USER_ID) String userID, Call<LiveAgentResultData> postChatHistory(@Query(Constants.USER_ID) String userID,
@Query(Constants.MESSAGE) String message, @Query(Constants.MESSAGE) String message,
@Body ChatHistoryPostData chatData); @Body ChatHistoryPostData chatData);
@GET(Constants.GET_USER_SYS_ID)
Call<LiveAgentResultData> getUserSysId(@Query(Constants.EMAIL) String userID);
......
...@@ -255,11 +255,49 @@ public class UserApiManager { ...@@ -255,11 +255,49 @@ public class UserApiManager {
CatalogueLog.d("refresh token failed, return FAIL"); CatalogueLog.d("refresh token failed, return FAIL");
} }
} }
}
public static void getUserSysId(Context context,String accToken,String email, final GetLiveAgentApiListener listener) {
if(accToken !=null){
final Retrofit retrofit = RestClient.getInitializedRestAdapterRestPWD(accToken);
Call<LiveAgentResultData> call = retrofit.create(LoginApi.class).getUserSysId(email);
try {
Response<LiveAgentResultData> response = call.execute();
if (response.isSuccessful()) {
listener.onDoneApiCall(response.body().getResult());
} else {
CatalogueLog.d("LoginApiManager: logout: response is not success");
if (response.code() == 401) {
Log.d(Constants.TAG, "-- is 401, try refresh token...");
Log.d(Constants.TAG, "refresh token: " + PrefManager.getSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN));
SyncStatus status = LoginApiManager.refreshLogin(context, PrefManager.getSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN));
if (status == SyncStatus.SUCCESS) {
CatalogueLog.d("refresh token success, retry same...");
String acc = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
}
} else {
listener.onFailApiCall();
}
}
} catch (IOException e) {
e.printStackTrace();
listener.onFailApiCall();
}
}else {
SyncStatus status = LoginApiManager.refreshLogin(context, PrefManager.getSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN));
if (status == SyncStatus.SUCCESS) {
String acc = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
CatalogueLog.d("refresh token success, retry same...");
} else {
CatalogueLog.d("refresh token failed, return FAIL");
}
}
} }
......
...@@ -47,16 +47,19 @@ import com.microsoft.aad.adal.PromptBehavior; ...@@ -47,16 +47,19 @@ import com.microsoft.aad.adal.PromptBehavior;
import com.microsoft.aad.adal.Telemetry; import com.microsoft.aad.adal.Telemetry;
import com.vsoft.vera.CatalogueApplication; import com.vsoft.vera.CatalogueApplication;
import com.vsoft.vera.R; import com.vsoft.vera.R;
import com.vsoft.vera.api.listeners.get.GetLiveAgentApiListener;
import com.vsoft.vera.api.listeners.get.GetUserDetailApiListener; import com.vsoft.vera.api.listeners.get.GetUserDetailApiListener;
import com.vsoft.vera.api.listeners.get.GetUserLoginApiListener; import com.vsoft.vera.api.listeners.get.GetUserLoginApiListener;
import com.vsoft.vera.api.listeners.put.PutDeviceRegistrationApiListener; import com.vsoft.vera.api.listeners.put.PutDeviceRegistrationApiListener;
import com.vsoft.vera.api.managers.LoginApiManager; import com.vsoft.vera.api.managers.LoginApiManager;
import com.vsoft.vera.api.managers.UserApiManager; import com.vsoft.vera.api.managers.UserApiManager;
import com.vsoft.vera.api.pojos.ChatHistoryPostData;
import com.vsoft.vera.api.pojos.LoginApiResponse; import com.vsoft.vera.api.pojos.LoginApiResponse;
import com.vsoft.vera.db.managers.ChatBotHistoryManager; import com.vsoft.vera.db.managers.ChatBotHistoryManager;
import com.vsoft.vera.db.managers.ChatBotUserManager; import com.vsoft.vera.db.managers.ChatBotUserManager;
import com.vsoft.vera.db.models.ChatBotUser; import com.vsoft.vera.db.models.ChatBotUser;
import com.vsoft.vera.db.models.UserApiValues; import com.vsoft.vera.db.models.UserApiValues;
import com.vsoft.vera.enums.SyncStatus;
import com.vsoft.vera.utils.Constants; import com.vsoft.vera.utils.Constants;
import com.vsoft.vera.utils.DialogUtils; import com.vsoft.vera.utils.DialogUtils;
import com.vsoft.vera.utils.GenerateRandomString; import com.vsoft.vera.utils.GenerateRandomString;
...@@ -327,7 +330,9 @@ public class ADALActivity extends AppCompatActivity { ...@@ -327,7 +330,9 @@ public class ADALActivity extends AppCompatActivity {
try { try {
root = new JSONObject(response.toString()); root = new JSONObject(response.toString());
String userLoginName = root.getString("givenName"); String userLoginName = root.getString("givenName");
String mail = root.getString("mail");
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_FULL_NAME, userLoginName); PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_FULL_NAME, userLoginName);
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_EMAIL_ID, mail);
/*Send broadcast to start SyncService*/ /*Send broadcast to start SyncService*/
if(!isLogin){ if(!isLogin){
...@@ -660,16 +665,97 @@ public class ADALActivity extends AppCompatActivity { ...@@ -660,16 +665,97 @@ public class ADALActivity extends AppCompatActivity {
PrefManager.setSharedPref(ADALActivity.this, PrefManager.SESSION_ID, generateRandoStrPharma); PrefManager.setSharedPref(ADALActivity.this, PrefManager.SESSION_ID, generateRandoStrPharma);
String firstName = mUserDetails.get(0).getFirstName(); String firstName = mUserDetails.get(0).getFirstName();
String lastName = mUserDetails.get(0).getLastName(); String lastName = mUserDetails.get(0).getLastName();
String sysid = mUserDetails.get(0).getSysId(); // String sysid = mUserDetails.get(0).getSysId();
String userFullName = mUserDetails.get(0).getFullName(); String userFullName = mUserDetails.get(0).getFullName();
String userId = mUserDetails.get(0).getUserId(); String userId = mUserDetails.get(0).getUserId();
String userEmailId = mUserDetails.get(0).getUserEmailId(); String userEmailId = mUserDetails.get(0).getUserEmailId();
/*End Chat Local DB Part*/
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_FIRST_NAME, firstName);
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_LAST_NAME, lastName);
/*For pre fill value in variable form*/
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_ID, userId);
new GetyUserSysIDAsync().execute();
//
//
} else {
Util.simpleAlert(ADALActivity.this,getResources().getString(R.string.user_detail_not_available));
}
} else if (syncStatus == API_FAIL_USER_LOGIN) {
Util.simpleAlert(ADALActivity.this,getResources().getString(R.string.login_screen_invalid_username_and_password_string));
} else if (syncStatus == API_FAIL_USER_DETAIL) {
Util.simpleAlert(ADALActivity.this,getResources().getString(R.string.failed_to_fetch_user_detail_string));
}
}
}
private class GetyUserSysIDAsync extends AsyncTask<Void, Void, SyncStatus> {
private ProgressDialog progressDialog;
private SyncStatus syncStatus = SyncStatus.FAIL;
String userSysId;
String accessToken;
String email,userFullName;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(ADALActivity.this);
progressDialog.setMessage(getString(R.string.login_screen_logging_in_loading_string));
progressDialog.show();
progressDialog.setCancelable(false);
accessToken = PrefManager.getSharedPref(ADALActivity.this, PrefManager.PREFERENCE_ACCESS_TOKEN);
email = PrefManager.getSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_EMAIL_ID);
userFullName = PrefManager.getSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_FULL_NAME);
}
@Override
protected SyncStatus doInBackground(Void... params) {
UserApiManager.getUserSysId(ADALActivity.this,accessToken,email,new GetLiveAgentApiListener() {
@Override
public void onDoneApiCall(String url) {
userSysId = url;
syncStatus = SyncStatus.SUCCESS;
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
}
@Override
protected void onPostExecute(SyncStatus syncStatus) {
super.onPostExecute(syncStatus);
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if (syncStatus == SyncStatus.SUCCESS) {
if(userSysId != null){
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_SYS_ID, userSysId);
if(Util.isChatItemEnabled()) { if(Util.isChatItemEnabled()) {
/*Start Chat Local DB Part*/ /*Start Chat Local DB Part*/
//Here we'll save logged in user detail in local DB for chat history. //Here we'll save logged in user detail in local DB for chat history.
ChatBotUser localChatBotUser = ChatBotUserManager.getChatBotUsersByUserSysId(sysid); ChatBotUser localChatBotUser = ChatBotUserManager.getChatBotUsersByUserSysId(userSysId);
if (localChatBotUser == null) { if (localChatBotUser == null) {
/*Clears all data from CHAT_BOT_HISTORY and CHAT_BOT_USER tables*/ /*Clears all data from CHAT_BOT_HISTORY and CHAT_BOT_USER tables*/
ChatBotHistoryManager.deleteAllRows(); ChatBotHistoryManager.deleteAllRows();
...@@ -677,27 +763,16 @@ public class ADALActivity extends AppCompatActivity { ...@@ -677,27 +763,16 @@ public class ADALActivity extends AppCompatActivity {
/*Save Logged in user in local db for chat screen*/ /*Save Logged in user in local db for chat screen*/
ChatBotUser chatBotUser = ChatBotUser.ChatBotUserBuilder.aChatBotUser() ChatBotUser chatBotUser = ChatBotUser.ChatBotUserBuilder.aChatBotUser()
.setUserSysId(sysid) .setUserSysId(userSysId)
.setName(firstName) .setName(userFullName)
.build(); .build();
ChatBotUserManager.save(chatBotUser); ChatBotUserManager.save(chatBotUser);
} else {//Update the name of user } else {//Update the name of user
localChatBotUser.setName(firstName); localChatBotUser.setName(userFullName);
ChatBotUserManager.update(localChatBotUser); ChatBotUserManager.update(localChatBotUser);
} }
} }
/*End Chat Local DB Part*/ /*Send broadcast to start SyncService*/
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_FIRST_NAME, firstName);
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_LAST_NAME, lastName);
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_SYS_ID, sysid);
/*For pre fill value in variable form*/
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_ID, userId);
PrefManager.setSharedPref(ADALActivity.this, PrefManager.PREFERENCE_USER_EMAIL_ID, userEmailId);
// /*Send broadcast to start SyncService*/
Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT); Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT);
intent.putExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION, Constants.ACTION_SYNC); intent.putExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION, Constants.ACTION_SYNC);
LocalBroadcastManager.getInstance(ADALActivity.this).sendBroadcast(intent); LocalBroadcastManager.getInstance(ADALActivity.this).sendBroadcast(intent);
...@@ -718,13 +793,13 @@ public class ADALActivity extends AppCompatActivity { ...@@ -718,13 +793,13 @@ public class ADALActivity extends AppCompatActivity {
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(homeIntent); startActivity(homeIntent);
} }
//
} else {
}else {
Util.simpleAlert(ADALActivity.this,getResources().getString(R.string.user_detail_not_available)); Util.simpleAlert(ADALActivity.this,getResources().getString(R.string.user_detail_not_available));
} }
} else if (syncStatus == API_FAIL_USER_LOGIN) {
Util.simpleAlert(ADALActivity.this,getResources().getString(R.string.login_screen_invalid_username_and_password_string)); } else if (syncStatus == SyncStatus.FAIL) {
} else if (syncStatus == API_FAIL_USER_DETAIL) {
Util.simpleAlert(ADALActivity.this,getResources().getString(R.string.failed_to_fetch_user_detail_string)); Util.simpleAlert(ADALActivity.this,getResources().getString(R.string.failed_to_fetch_user_detail_string));
} }
} }
......
...@@ -52,6 +52,7 @@ public class Constants { ...@@ -52,6 +52,7 @@ public class Constants {
public static final String PASSWORD = "password"; public static final String PASSWORD = "password";
public static final String USER_ID = "userID"; public static final String USER_ID = "userID";
public static final String MESSAGE = "Message"; public static final String MESSAGE = "Message";
public static final String EMAIL = "email";
public static final String PHONE_NUMBER = "phone_number"; public static final String PHONE_NUMBER = "phone_number";
...@@ -184,6 +185,7 @@ public class Constants { ...@@ -184,6 +185,7 @@ public class Constants {
public static final String URL_PUT_LOGOUT = "/api/x_vsng2_chatbot/uofl_mobile/logout"; public static final String URL_PUT_LOGOUT = "/api/x_vsng2_chatbot/uofl_mobile/logout";
public static final String URL_PUT_PASSWORD_RESET = "/api/vsng2/chatbot_api_services/passwordrest"; public static final String URL_PUT_PASSWORD_RESET = "/api/vsng2/chatbot_api_services/passwordrest";
public static final String LIVE_AGENT_API = "api/x_vsng2_chatbot/chatbot/chatapi"; public static final String LIVE_AGENT_API = "api/x_vsng2_chatbot/chatbot/chatapi";
public static final String GET_USER_SYS_ID = "api/x_vsng2_chatbot/chatbot/userSysiD";
/*Catalogue Category API */ /*Catalogue Category API */
public static final String URL_GET_CATALOGUE = DOMAIN + AppConfig.URL_GET_CATALOGUE; public static final String URL_GET_CATALOGUE = DOMAIN + AppConfig.URL_GET_CATALOGUE;
......
<vector android:height="30dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="30dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</vector>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment