Commit ecb0b032 by Kunj Gupta

UOFLMA-124 : Fixed - Make sure all API failures are handled and user is shown failure message.

parent 2d66699b
Showing with 283 additions and 162 deletions
......@@ -11,4 +11,5 @@ import java.util.List;
*/
public interface GetCatalogueApiListener {
void onDoneApiCall(List<Catalogue> catalogueList);
void onFailApiCall();
}
......@@ -11,4 +11,5 @@ import java.util.List;
*/
public interface GetCatalogueItemApiListener {
void onDoneApiCall(List<CatalogueItem> catalogueItemList);
void onFailApiCall();
}
......@@ -11,4 +11,5 @@ import java.util.List;
*/
public interface GetCatalogueOrderApiListener {
void onDoneApiCall(List<CatalogueOrder> catalogueOrderList);
void onFailApiCall();
}
......@@ -12,4 +12,5 @@ import java.util.List;
*/
public interface GetCatalogueVariableApiListener {
void onDoneApiCall(List<CatalogueVariableSet> variableSetList, List<CatalogueVariable> variableList);
void onFailApiCall();
}
......@@ -11,4 +11,5 @@ import java.util.List;
*/
public interface GetIncidentApiListener {
void onDoneApiCall(List<Incident> incidentList);
void onFailApiCall();
}
......@@ -11,4 +11,5 @@ import java.util.List;
*/
public interface GetMyRequestApiListener {
void onDoneApiCall(List<MyRequest> catalogueList);
void onFailApiCall();
}
......@@ -11,4 +11,5 @@ import java.util.List;
*/
public interface GetReferenceApiListener {
void onDoneApiCall(List<Reference> referenceList);
void onFailApiCall();
}
......@@ -11,4 +11,5 @@ import java.util.List;
*/
public interface GetUiPolicyApiListener {
void onDoneApiCall(List<UiPolicyItem> uiPolicyItemList);
void onFailApiCall();
}
......@@ -9,6 +9,7 @@ import java.util.List;
* @author Kunj on 11/8/16
*
*/
public interface GetUserApiListener {
public interface GetUserDetailApiListener {
void onDoneApiCall(List<UserApiValues> userValues);
void onFailApiCall();
}
package com.vsoft.uoflservicenow.api.listeners.get;
/**
* @since 1.0
* @author Kunj on 11/8/16
*
*/
public interface GetUserLoginApiListener {
void onDoneApiCall();
void onFailApiCall();
}
......@@ -11,4 +11,5 @@ import java.util.List;
*/
public interface GetVariableChoiceApiListener {
void onDoneApiCall(List<VariableChoice> variableChoiceList);
void onFailApiCall();
}
package com.vsoft.uoflservicenow.api.listeners.post;
/**
* @since 1.0
* @author Kunj on 11/8/16
*
*/
public interface PostAttachmentApiListener {
void onDoneApiCall();
void onFailApiCall();
}
......@@ -7,4 +7,5 @@ package com.vsoft.uoflservicenow.api.listeners.post;
*/
public interface PostIncidentApiListener {
void onDoneApiCall(String incidentNumber);
void onFailApiCall();
}
......@@ -7,4 +7,5 @@ package com.vsoft.uoflservicenow.api.listeners.post;
*/
public interface PostVariableFormApiListener {
void onDoneApiCall(String variableFromSysId);
void onFailApiCall();
}
......@@ -12,7 +12,6 @@ import com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueOrderApiListener;
import com.vsoft.uoflservicenow.db.models.Catalogue;
import com.vsoft.uoflservicenow.db.models.CatalogueOrder;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants;
......@@ -38,7 +37,7 @@ import retrofit2.Retrofit;
*/
public class CatalogueApiManager {
public static SyncStatus getCatalogues(GetCatalogueApiListener listener) {
public static void getCatalogues(final GetCatalogueApiListener listener) {
CatalogueLog.d("CatalogueApiManager: getCatalogues: ");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(Catalogue.Json.URL_PARAM_CATALOGUE_SYSPRM_QUERY_VALUE);
......@@ -119,38 +118,42 @@ public class CatalogueApiManager {
}
}
}
listener.onDoneApiCall(finalCatalogueList);
}
@Override
public void onFailApiCall() {
listener.onFailApiCall();
}
});
listener.onDoneApiCall(finalCatalogueList);
} else {
listener.onDoneApiCall(new ArrayList<Catalogue>(0));
}
} else {
listener.onDoneApiCall(new ArrayList<Catalogue>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogues: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogues: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogues: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogues: NullPointerException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
public static SyncStatus getCatalogueOrder(GetCatalogueOrderApiListener listener) {
public static void getCatalogueOrder(GetCatalogueOrderApiListener listener) {
CatalogueLog.d("CatalogueApiManager: getCatalogueOrder: ");
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
......@@ -225,25 +228,24 @@ public class CatalogueApiManager {
} else {
listener.onDoneApiCall(new ArrayList<CatalogueOrder>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogueOrder: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogueOrder: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogueOrder: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogueOrder: NullPointerException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
}
\ No newline at end of file
......@@ -10,7 +10,6 @@ import com.vsoft.uoflservicenow.api.RestClient;
import com.vsoft.uoflservicenow.api.interfaces.CatalogueCategoryItemApi;
import com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueItemApiListener;
import com.vsoft.uoflservicenow.db.models.CatalogueItem;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants;
......@@ -34,7 +33,7 @@ import retrofit2.Retrofit;
*/
public class CatalogueItemApiManager {
public static SyncStatus getCatalogueItems(String catalogueSysId, GetCatalogueItemApiListener listener) {
public static void getCatalogueItems(String catalogueSysId, GetCatalogueItemApiListener listener) {
CatalogueLog.d("CatalogueItemApiManager: getCatalogueItems: ");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(CatalogueItem.Json.URL_PARAM_CATALOGUE_SYSPRM_QUERY_VALUE);
......@@ -105,25 +104,24 @@ public class CatalogueItemApiManager {
} else {
listener.onDoneApiCall(new ArrayList<CatalogueItem>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("CatalogueItemApiManager: getCatalogueItems: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("CatalogueItemApiManager: getCatalogueItems: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("CatalogueItemApiManager: getCatalogueItems: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueItemApiManager: getCatalogueItems: NullPointerException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
}
\ No newline at end of file
......@@ -10,12 +10,12 @@ import com.vsoft.uoflservicenow.api.RestClient;
import com.vsoft.uoflservicenow.api.interfaces.CatalogueVariableApi;
import com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueVariableApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetUiPolicyApiListener;
import com.vsoft.uoflservicenow.api.listeners.post.PostAttachmentApiListener;
import com.vsoft.uoflservicenow.api.listeners.post.PostVariableFormApiListener;
import com.vsoft.uoflservicenow.db.models.CatalogueVariable;
import com.vsoft.uoflservicenow.db.models.CatalogueVariableSet;
import com.vsoft.uoflservicenow.db.models.UiPolicyAction;
import com.vsoft.uoflservicenow.db.models.UiPolicyItem;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants;
......@@ -42,7 +42,7 @@ import retrofit2.Retrofit;
*/
public class CatalogueVariableApiManager {
public static SyncStatus getCatalogueVariable(String catalogueItemSysId, GetCatalogueVariableApiListener listener) {
public static void getCatalogueVariable(String catalogueItemSysId, GetCatalogueVariableApiListener listener) {
CatalogueLog.d("CatalogueVariableApiManager: getCatalogueVariable: ");
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).getVariable(catalogueItemSysId);
......@@ -149,29 +149,28 @@ public class CatalogueVariableApiManager {
} else {
listener.onDoneApiCall(new ArrayList<CatalogueVariableSet>(0), new ArrayList<CatalogueVariable>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("CatalogueVariableApiManager: getCatalogueVariable: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: getCatalogueVariable: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: getCatalogueVariable: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueVariableApiManager: getCatalogueVariable: NullPointerException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
public static SyncStatus getUiPolicy(String catalogueItemSysId, GetUiPolicyApiListener listener) {
public static void getUiPolicy(String catalogueItemSysId, GetUiPolicyApiListener listener) {
CatalogueLog.d("CatalogueVariableApiManager: getUiPolicy: ");
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).getUiPolicy(catalogueItemSysId);
......@@ -245,29 +244,28 @@ public class CatalogueVariableApiManager {
} else {
listener.onDoneApiCall(new ArrayList<UiPolicyItem>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: NullPointerException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
public static SyncStatus submitVariableForm(String catalogueItemSysId, String catalogueJsonString, PostVariableFormApiListener listener) {
public static void submitVariableForm(String catalogueItemSysId, String catalogueJsonString, PostVariableFormApiListener listener) {
CatalogueLog.d("submitVariableForm: " + catalogueJsonString);
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).postCatalogueItem(catalogueItemSysId, catalogueJsonString);
......@@ -284,21 +282,21 @@ public class CatalogueVariableApiManager {
}
} catch (JSONException e) {
e.printStackTrace();
listener.onFailApiCall();
}
return SyncStatus.SUCCESS;
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: submitVariableForm: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueVariableApiManager: submitVariableForm: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
public static SyncStatus postAttachment(String contentType, String tableSysId, String attachmentName, RequestBody requestBody/*String attachmentJsonString*/) {
public static void postAttachment(String contentType, String tableSysId, String attachmentName, RequestBody requestBody, PostAttachmentApiListener listener) {
CatalogueLog.d("postAttachment: tableSysId: " + tableSysId);
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).postAttachment(contentType, tableSysId, CatalogueVariable.Json.TABLE_NAME_VALUE, attachmentName, requestBody);
......@@ -306,16 +304,16 @@ public class CatalogueVariableApiManager {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) {
return SyncStatus.SUCCESS;
listener.onDoneApiCall();
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: postAttachment: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueVariableApiManager: postAttachment: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
}
\ No newline at end of file
......@@ -11,7 +11,6 @@ import com.vsoft.uoflservicenow.api.interfaces.IncidentApi;
import com.vsoft.uoflservicenow.api.listeners.get.GetIncidentApiListener;
import com.vsoft.uoflservicenow.api.listeners.post.PostIncidentApiListener;
import com.vsoft.uoflservicenow.db.models.Incident;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants;
......@@ -35,7 +34,7 @@ import retrofit2.Retrofit;
*/
public class IncidentApiManager {
public static SyncStatus getIncident(GetIncidentApiListener listener) {
public static void getIncident(GetIncidentApiListener listener) {
CatalogueLog.d("IncidentApiManager: getIncident: ");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("caller_id=javascript:gs.getUserID()");
......@@ -104,30 +103,28 @@ public class IncidentApiManager {
} else {
listener.onDoneApiCall(new ArrayList<Incident>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("IncidentApiManager: getIncident: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("IncidentApiManager: getIncident: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("IncidentApiManager: getIncident: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("IncidentApiManager: getIncident: NullPointerException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
public static SyncStatus submitIncidentForm(String incidentJsonString, PostIncidentApiListener listener) {
public static void submitIncidentForm(String incidentJsonString, PostIncidentApiListener listener) {
CatalogueLog.d("submitIncidentForm: incidentJson" + incidentJsonString);
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(IncidentApi.class).submitIncident(incidentJsonString);
......@@ -146,16 +143,15 @@ public class IncidentApiManager {
} catch (JSONException e) {
e.printStackTrace();
}
return SyncStatus.SUCCESS;
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("IncidentApiManager: submitIncidentForm: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e){
CatalogueLog.e("IncidentApiManager: submitIncidentForm: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@ package com.vsoft.uoflservicenow.api.managers;
import com.vsoft.uoflservicenow.api.RestClient;
import com.vsoft.uoflservicenow.api.interfaces.LoginApi;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.api.listeners.get.GetUserLoginApiListener;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import java.io.IOException;
......@@ -17,7 +17,7 @@ import retrofit2.Retrofit;
*/
public class LoginApiManger {
public static SyncStatus submitLoginValues(String garntType, String clientId, String clientSecret, String userName, String password) {
public static void submitLoginValues(String garntType, String clientId, String clientSecret, String userName, String password, GetUserLoginApiListener listener) {
final Retrofit retrofit = RestClient.getInitializedRestAdapterWithOutAuthorizationHeader();
Call<ResponseBody> call = retrofit.create(LoginApi.class).postLoginValues(garntType, clientId, clientSecret, userName, password);
try {
......@@ -27,20 +27,20 @@ public class LoginApiManger {
if (body != null) {
if (body.contentLength() != -1) {
return SyncStatus.SUCCESS;
listener.onDoneApiCall();
} else {
return SyncStatus.SERVICEDOWN;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("LoginApiManger: submitLoginValues: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("LoginApiManger: submitLoginValues: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
}
......@@ -8,9 +8,8 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.vsoft.uoflservicenow.api.RestClient;
import com.vsoft.uoflservicenow.api.interfaces.UserApi;
import com.vsoft.uoflservicenow.api.listeners.get.GetUserApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetUserDetailApiListener;
import com.vsoft.uoflservicenow.db.models.UserApiValues;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants;
......@@ -32,7 +31,7 @@ import retrofit2.Retrofit;
* Created by kvemulavada on 8/31/2016.
*/
public class UserApiManager {
public static SyncStatus getUserDetailResponse(String userName, GetUserApiListener listener) {
public static void getUserDetailResponse(String userName, GetUserDetailApiListener listener) {
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(UserApi.class).getuserDetails(userName);
......@@ -96,21 +95,20 @@ public class UserApiManager {
} else {
listener.onDoneApiCall(new ArrayList<UserApiValues>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (JSONException e) {
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (IOException e) {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
......
......@@ -12,7 +12,6 @@ import com.vsoft.uoflservicenow.api.listeners.get.GetReferenceApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetVariableChoiceApiListener;
import com.vsoft.uoflservicenow.db.models.Reference;
import com.vsoft.uoflservicenow.db.models.VariableChoice;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants;
......@@ -37,7 +36,7 @@ import retrofit2.Retrofit;
*/
public class VariableChoiceApiManager {
public static SyncStatus getVariableChoice(String variableSysId, GetVariableChoiceApiListener listener) {
public static void getVariableChoice(String variableSysId, GetVariableChoiceApiListener listener) {
CatalogueLog.d("VariableChoiceApiManager: getVariableChoice: ");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(VariableChoice.Json.URL_PARAM_VARIABLE_CHOICE_SYSPRM_QUERY_VALUE);
......@@ -107,29 +106,28 @@ public class VariableChoiceApiManager {
} else {
listener.onDoneApiCall(new ArrayList<VariableChoice>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("VariableChoiceApiManager: getVariableChoice: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("VariableChoiceApiManager: getVariableChoice: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("VariableChoiceApiManager: getVariableChoice: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("VariableChoiceApiManager: getVariableChoice: NullPointerException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
public static SyncStatus getReference(String tableName, Map<String,String> queryMap, GetReferenceApiListener listener) {
public static void getReference(String tableName, Map<String,String> queryMap, GetReferenceApiListener listener) {
CatalogueLog.d("VariableChoiceApiManager: getReference: tableName: "+tableName);
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
......@@ -194,25 +192,24 @@ public class VariableChoiceApiManager {
} else {
listener.onDoneApiCall(new ArrayList<Reference>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("VariableChoiceApiManager: getReference: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("VariableChoiceApiManager: getReference: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("VariableChoiceApiManager: getReference: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("VariableChoiceApiManager: getReference: NullPointerException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
}
\ No newline at end of file
......@@ -168,6 +168,7 @@ public class SelectReferenceDialog extends DialogFragment {
class FetchReference extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
private SyncStatus syncStatus;
@Override
protected void onPreExecute() {
......@@ -183,12 +184,19 @@ public class SelectReferenceDialog extends DialogFragment {
Map<String, String> stringMap = new HashMap<>(1);
stringMap.put(Constants.URL_PARAM_SYSPRM_FIELDS, "sys_id,"+mReferenceColumnName);
stringMap.put(Constants.URL_PARAM_SYSPRM_QUERY, mReferenceColumnName+"LIKE"+params[0]);
return VariableChoiceApiManager.getReference(mReferenceTableName, stringMap, new GetReferenceApiListener() {
VariableChoiceApiManager.getReference(mReferenceTableName, stringMap, new GetReferenceApiListener() {
@Override
public void onDoneApiCall(List<Reference> referenceList) {
syncStatus = SyncStatus.SUCCESS;
mReferenceList = referenceList;
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
}
@Override
......
......@@ -7,8 +7,7 @@ package com.vsoft.uoflservicenow.enums;
*/
public enum SyncStatus {
SUCCESS (1),
FAIL (2),
SERVICEDOWN (3);
FAIL (2);
int id;
......
......@@ -86,6 +86,7 @@ public class CatalogueItemScreen extends AppCompatActivity {
class FetchCatalogueItem extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
private SyncStatus syncStatus;
@Override
protected void onPreExecute() {
......@@ -98,13 +99,20 @@ public class CatalogueItemScreen extends AppCompatActivity {
@Override
protected SyncStatus doInBackground(String... params) {
return CatalogueItemApiManager.getCatalogueItems(mCatalogueSysId, new GetCatalogueItemApiListener() {
CatalogueItemApiManager.getCatalogueItems(mCatalogueSysId, new GetCatalogueItemApiListener() {
@Override
public void onDoneApiCall(List<CatalogueItem> catalogueItemList) {
syncStatus = SyncStatus.SUCCESS;
CatalogueLog.e("Data: catalogueItemList: "+catalogueItemList);
mCatalogueItemList = catalogueItemList;
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
}
@Override
......
......@@ -77,6 +77,7 @@ public class CatalogueScreen extends AppCompatActivity {
class FetchCatalogue extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
private SyncStatus syncStatus = SyncStatus.FAIL;
@Override
protected void onPreExecute() {
......@@ -89,13 +90,20 @@ public class CatalogueScreen extends AppCompatActivity {
@Override
protected SyncStatus doInBackground(String... params) {
return CatalogueApiManager.getCatalogues(new GetCatalogueApiListener() {
CatalogueApiManager.getCatalogues(new GetCatalogueApiListener() {
@Override
public void onDoneApiCall(List<Catalogue> catalogueList) {
syncStatus = SyncStatus.SUCCESS;
CatalogueLog.e("Data: catalogueList: "+catalogueList);
mCatalogueList = catalogueList;
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
}
@Override
......
......@@ -55,6 +55,7 @@ import com.vsoft.uoflservicenow.R;
import com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueVariableApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetUiPolicyApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetVariableChoiceApiListener;
import com.vsoft.uoflservicenow.api.listeners.post.PostAttachmentApiListener;
import com.vsoft.uoflservicenow.api.listeners.post.PostVariableFormApiListener;
import com.vsoft.uoflservicenow.api.managers.CatalogueVariableApiManager;
import com.vsoft.uoflservicenow.api.managers.VariableChoiceApiManager;
......@@ -123,6 +124,8 @@ public class CatalogueVariableScreen extends AppCompatActivity {
private static final int FILE_SELECT_CODE = 0;
private TextView mAttachmentTextView;
private SyncStatus mSyncStatus;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
......@@ -167,7 +170,6 @@ public class CatalogueVariableScreen extends AppCompatActivity {
class FetchCatalogueVariable extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
SyncStatus syncStatus;
@Override
protected void onPreExecute() {
......@@ -180,25 +182,31 @@ public class CatalogueVariableScreen extends AppCompatActivity {
@Override
protected SyncStatus doInBackground(final String... params) {
syncStatus = CatalogueVariableApiManager.getCatalogueVariable(mCatalogueItemSysId, new GetCatalogueVariableApiListener() {
CatalogueVariableApiManager.getCatalogueVariable(mCatalogueItemSysId, new GetCatalogueVariableApiListener() {
@Override
public void onDoneApiCall(List<CatalogueVariableSet> variableSetList, List<CatalogueVariable> variableList) {
mSyncStatus = SyncStatus.SUCCESS;
/*For variableset */
for (int i = 0; i <variableSetList.size(); i++) {
CatalogueVariableSet catalogueVariableSet = variableSetList.get(i);
setVariableChoiceData(catalogueVariableSet.getVariables());
mSyncStatus = setVariableChoiceData(catalogueVariableSet.getVariables());
if(mSyncStatus == SyncStatus.FAIL)
break;
}
if(mSyncStatus != SyncStatus.FAIL) {
/*For variable list*/
setVariableChoiceData(variableList);
syncStatus = CatalogueVariableApiManager.getUiPolicy(mCatalogueItemSysId, new GetUiPolicyApiListener() {
mSyncStatus = setVariableChoiceData(variableList);
if(mSyncStatus != SyncStatus.FAIL) {
CatalogueVariableApiManager.getUiPolicy(mCatalogueItemSysId, new GetUiPolicyApiListener() {
@Override
public void onDoneApiCall(List<UiPolicyItem> uiPolicyItemList) {
mSyncStatus = SyncStatus.SUCCESS;
mUiPolicyItemList = uiPolicyItemList;
for (int i = 0; i < mUiPolicyItemList.size(); i++) {
UiPolicyItem uiPolicyItem = mUiPolicyItemList.get(i);
String condition = uiPolicyItem.getCondition();
if(condition!=null) {
if (condition != null) {
String[] splitStrings = uiPolicyItem.getCondition().split("\\^");
List<PartialCondition> partialConditionList = new ArrayList<>(splitStrings.length - 1);
for (int j = 0; j < splitStrings.length - 1; j++) {
......@@ -215,7 +223,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
partialCondition.setOperator(Operator.EQUAL);
/*Below condition is use for condition=empty,
*we need to handle empty condition in else statement*/
if(strings.length >= 2) {
if (strings.length >= 2) {
partialCondition.setOperatorValue(strings[1]);
} else {
partialCondition.setOperatorValue("");
......@@ -227,10 +235,22 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
}
}
@Override
public void onFailApiCall() {
mSyncStatus = SyncStatus.FAIL;
}
});
}
}
}
@Override
public void onFailApiCall() {
mSyncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
return mSyncStatus;
}
@Override
......@@ -250,7 +270,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
}
private void setVariableChoiceData(List<CatalogueVariable> variableList) {
private SyncStatus setVariableChoiceData(List<CatalogueVariable> variableList) {
if(!variableList.isEmpty()) {
for (int i = 0; i < variableList.size(); i++) {
final CatalogueVariable catalogueVariable = variableList.get(i);
......@@ -260,6 +280,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
VariableChoiceApiManager.getVariableChoice(catalogueVariable.getSysId(), new GetVariableChoiceApiListener() {
@Override
public void onDoneApiCall(List<VariableChoice> variableChoiceList) {
mSyncStatus = SyncStatus.SUCCESS;
/*Sort List of CatalogueOrder*/
Collections.sort(variableChoiceList, new Comparator<VariableChoice>() {
@Override
......@@ -269,11 +290,19 @@ public class CatalogueVariableScreen extends AppCompatActivity {
});
catalogueVariable.setVariableChoiceList(variableChoiceList);
}
@Override
public void onFailApiCall() {
mSyncStatus = SyncStatus.FAIL;
}
});
if(mSyncStatus == SyncStatus.FAIL)
break;
}
}
mCatalogueVariableList.addAll(variableList);
}
return mSyncStatus;
}
private void createView() {
......@@ -673,6 +702,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
class SubmitForm extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
private SyncStatus syncStatus = SyncStatus.FAIL;
@Override
protected void onPreExecute() {
......@@ -685,9 +715,10 @@ public class CatalogueVariableScreen extends AppCompatActivity {
@Override
protected SyncStatus doInBackground(String... params) {
return CatalogueVariableApiManager.submitVariableForm(mCatalogueItemSysId, params[0], new PostVariableFormApiListener() {
CatalogueVariableApiManager.submitVariableForm(mCatalogueItemSysId, params[0], new PostVariableFormApiListener() {
@Override
public void onDoneApiCall(String variableFromSysId) {
syncStatus = SyncStatus.SUCCESS;
if(mAttachmentFile !=null) {
String uriContentType = getMimeType(mAttachmentUri);
if(uriContentType != null) {
......@@ -705,11 +736,29 @@ public class CatalogueVariableScreen extends AppCompatActivity {
e.printStackTrace();
}
RequestBody requestBody = RequestBody.create(MediaType.parse(uriContentType), buf);
CatalogueVariableApiManager.postAttachment(uriContentType, variableFromSysId, mAttachmentFile.getName(), requestBody);
CatalogueVariableApiManager.postAttachment(uriContentType, variableFromSysId,
mAttachmentFile.getName(), requestBody, new PostAttachmentApiListener() {
@Override
public void onDoneApiCall() {
syncStatus = SyncStatus.SUCCESS;
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
}
});
}
}
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
}
@Override
......@@ -1019,6 +1068,8 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
private void runUIPolicyActions(String sysId) {
if(mUiPolicyItemList == null)
return;
for(int i=0; i<mUiPolicyItemList.size(); i++) {
UiPolicyItem item = mUiPolicyItemList.get(i);
/*UIPolicy condition is null then skip iterator*/
......
......@@ -16,12 +16,11 @@ import android.widget.Toast;
import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.R;
import com.vsoft.uoflservicenow.api.listeners.get.GetUserApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetUserDetailApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetUserLoginApiListener;
import com.vsoft.uoflservicenow.api.managers.LoginApiManger;
import com.vsoft.uoflservicenow.api.managers.UserApiManager;
import com.vsoft.uoflservicenow.db.models.UserApiValues;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.KeyboardUtil;
......@@ -39,14 +38,18 @@ import butterknife.OnClick;
*/
public class LoginScreen extends Activity {
@BindView(R.id.login_screen_username_edit_text)
EditText mUserNameEditText;
@BindView(R.id.login_screen_password_edit_text)
EditText mPasswordEditText;
@BindView(R.id.login_screen_username_edit_text) EditText mUserNameEditText;
@BindView(R.id.login_screen_password_edit_text) EditText mPasswordEditText;
private List<UserApiValues> mUserDetails;
private CatalogueApplication mApplication;
private static final int API_SUCCESS_USER_LOGIN = 1;
private static final int API_FAIL_USER_LOGIN = 2;
private static final int API_SUCCESS_USER_DETAIL = 3;
private static final int API_FAIL_USER_DETAIL = 4;
private int apiStatus;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
......@@ -115,10 +118,9 @@ public class LoginScreen extends Activity {
callLoginAPI();
}
private class LoginDetailsSendToServer extends AsyncTask<String, Integer, SyncStatus> {
private class LoginDetailsSendToServer extends AsyncTask<String, Integer, Integer> {
private ProgressDialog progressDialog;
private static final int USER_DETAIL = 1;
private String userName;
@Override
......@@ -131,46 +133,34 @@ public class LoginScreen extends Activity {
}
@Override
protected SyncStatus doInBackground(String... params) {
SyncStatus syncStatus = null;
protected Integer doInBackground(String... params) {
userName = params[0];//"a0kuma18";
String password = params[1];//"v$0ftA$win";
try {
syncStatus = LoginApiManger.submitLoginValues(Constants.GRANT_TYPE, Constants.CLIENT_ID, Constants
.CLIENT_SECRET, userName, password);
if (syncStatus != null) {
if (syncStatus == SyncStatus.SUCCESS) {
LoginApiManger.submitLoginValues(Constants.GRANT_TYPE, Constants.CLIENT_ID, Constants
.CLIENT_SECRET, userName, password, new GetUserLoginApiListener() {
@Override
public void onDoneApiCall() {
apiStatus = API_SUCCESS_USER_LOGIN;
publishProgress(USER_DETAIL);
return UserApiManager.getUserDetailResponse(userName, new GetUserApiListener() {
UserApiManager.getUserDetailResponse(userName, new GetUserDetailApiListener() {
@Override
public void onDoneApiCall(List<UserApiValues> userValues) {
apiStatus = API_SUCCESS_USER_DETAIL;
mUserDetails = userValues;
}
});
} else if (syncStatus == SyncStatus.SERVICEDOWN) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(LoginScreen.this, R.string.server_not_reachable, Toast.LENGTH_LONG).show();
}
});
} else if (syncStatus == SyncStatus.FAIL) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(LoginScreen.this, R.string.login_screen_invalid_username_and_password_string, Toast.LENGTH_LONG).show();
public void onFailApiCall() {
apiStatus = API_FAIL_USER_DETAIL;
}
});
}
@Override
public void onFailApiCall() {
apiStatus = API_FAIL_USER_LOGIN;
}
} catch (Exception e) {
CatalogueLog.e("LoginScreen: LoginDetailsSendToServer: doInBackground: Exception: "+e);
}
return syncStatus;
});
return apiStatus;
}
@Override
......@@ -182,12 +172,12 @@ public class LoginScreen extends Activity {
}
@Override
protected void onPostExecute(SyncStatus syncStatus) {
protected void onPostExecute(Integer syncStatus) {
super.onPostExecute(syncStatus);
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if (syncStatus != null && syncStatus == SyncStatus.SUCCESS) {
if (syncStatus == API_SUCCESS_USER_DETAIL) {
if (mUserDetails != null) {
String firstName = mUserDetails.get(0).getFirstName();
String lastName = mUserDetails.get(0).getLastName();
......@@ -198,6 +188,10 @@ public class LoginScreen extends Activity {
} else {
Toast.makeText(LoginScreen.this, R.string.user_detail_not_available, Toast.LENGTH_LONG).show();
}
} else if (syncStatus == API_FAIL_USER_LOGIN) {
Toast.makeText(LoginScreen.this, R.string.login_screen_invalid_username_and_password_string, Toast.LENGTH_LONG).show();
} else if (syncStatus == API_FAIL_USER_DETAIL) {
Toast.makeText(LoginScreen.this, R.string.failed_to_fetch_user_detail_string, Toast.LENGTH_LONG).show();
}
}
}
......
......@@ -93,6 +93,7 @@ public class MyIncidentScreen extends AppCompatActivity {
class FetchIncident extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
private SyncStatus syncStatus = SyncStatus.FAIL;
@Override
protected void onPreExecute() {
......@@ -105,13 +106,20 @@ public class MyIncidentScreen extends AppCompatActivity {
@Override
protected SyncStatus doInBackground(String... params) {
return IncidentApiManager.getIncident(new GetIncidentApiListener() {
IncidentApiManager.getIncident(new GetIncidentApiListener() {
@Override
public void onDoneApiCall(List<Incident> incidentList) {
syncStatus = SyncStatus.SUCCESS;
CatalogueLog.e("Data: incidentList: "+incidentList);
mIncidentList = incidentList;
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
}
@Override
......
......@@ -72,6 +72,7 @@ public class MyRequestActivity extends AppCompatActivity {
class FetchMyRequestData extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
private SyncStatus syncStatus = SyncStatus.FAIL;
@Override
protected void onPreExecute() {
......@@ -84,12 +85,19 @@ public class MyRequestActivity extends AppCompatActivity {
@Override
protected SyncStatus doInBackground(String... params) {
return MyRequestApiManager.getMyrequests(new GetMyRequestApiListener() {
MyRequestApiManager.getMyrequests(new GetMyRequestApiListener() {
@Override
public void onDoneApiCall(List<MyRequest> requestList) {
syncStatus = SyncStatus.SUCCESS;
mMyRequestList = requestList;
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
}
@Override
......
......@@ -151,6 +151,7 @@ public class ReportIncidentScreen extends AppCompatActivity {
class submitIncident extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
private String number;
private SyncStatus syncStatus;
@Override
protected void onPreExecute() {
......@@ -174,12 +175,20 @@ public class ReportIncidentScreen extends AppCompatActivity {
e.printStackTrace();
}
return IncidentApiManager.submitIncidentForm(incidentJsonObject.toString(), new PostIncidentApiListener() {
IncidentApiManager.submitIncidentForm(incidentJsonObject.toString(), new PostIncidentApiListener() {
@Override
public void onDoneApiCall(String incidentNumber) {
syncStatus = SyncStatus.SUCCESS;
number = incidentNumber;
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
}
@Override
......
......@@ -35,13 +35,13 @@
<string name="failed_to_fetch_reference_string">Failed to fetch References.</string>
<string name="failed_to_submit_form_string">Failed to submit form.</string>
<string name="failed_to_fetch_incident_string">Failed to fetch incidents.</string>
<string name="failed_to_fetch_user_detail_string">Failed to fetch User Details.</string>
<!--Login Screen-->
<string name="login_screen_login_string">Login</string>
<string name="login_screen_logging_in_loading_string">Logging in&#8230;</string>
<string name="login_screen_getting_user_detail_loading_string">Getting user details&#8230;</string>
<string name="login_screen_invalid_username_and_password_string">Invalid username and password</string>
<string name="server_not_reachable">Unable to connect to server. Please try again later.</string>
<string name="user_detail_not_available">Unable to fetch user details.</string>
<string name="user_error">Please enter username</string>
......
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