Commit 00a21c21 by Kunj

In Catalogue Variable - Combined multiple calls in single calls.

parent 9085c295
package com.vsoft.servicenow.api.listeners.get; package com.vsoft.servicenow.api.listeners.get;
import com.vsoft.servicenow.db.models.CatalogueVariable; import com.vsoft.servicenow.db.models.CatalogueVariableResponse;
import com.vsoft.servicenow.db.models.CatalogueVariableSet;
import java.util.List;
/** /**
* @since 1.0 * @since 1.0
...@@ -11,6 +8,6 @@ import java.util.List; ...@@ -11,6 +8,6 @@ import java.util.List;
* *
*/ */
public interface GetCatalogueVariableApiListener { public interface GetCatalogueVariableApiListener {
void onDoneApiCall(List<CatalogueVariableSet> variableSetList, List<CatalogueVariable> variableList); void onDoneApiCall(CatalogueVariableResponse catalogueVariableResponse);
void onFailApiCall(); void onFailApiCall();
} }
...@@ -9,16 +9,15 @@ import com.google.gson.JsonDeserializationContext; ...@@ -9,16 +9,15 @@ import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer; import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.vsoft.servicenow.db.models.UiPolicyAction;
import com.vsoft.servicenow.api.RestClient; import com.vsoft.servicenow.api.RestClient;
import com.vsoft.servicenow.api.interfaces.CatalogueVariableApi; import com.vsoft.servicenow.api.interfaces.CatalogueVariableApi;
import com.vsoft.servicenow.api.listeners.get.GetCatalogueVariableApiListener; import com.vsoft.servicenow.api.listeners.get.GetCatalogueVariableApiListener;
import com.vsoft.servicenow.api.listeners.get.GetUiPolicyApiListener;
import com.vsoft.servicenow.api.listeners.post.PostAttachmentApiListener; import com.vsoft.servicenow.api.listeners.post.PostAttachmentApiListener;
import com.vsoft.servicenow.api.listeners.post.PostVariableFormApiListener; import com.vsoft.servicenow.api.listeners.post.PostVariableFormApiListener;
import com.vsoft.servicenow.db.models.CatalogueVariable; import com.vsoft.servicenow.db.models.CatalogueVariable;
import com.vsoft.servicenow.db.models.CatalogueVariableResponse;
import com.vsoft.servicenow.db.models.CatalogueVariableSet; import com.vsoft.servicenow.db.models.CatalogueVariableSet;
import com.vsoft.servicenow.db.models.UiPolicyItem; import com.vsoft.servicenow.db.models.VariableChoice;
import com.vsoft.servicenow.enums.SyncStatus; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.servicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
...@@ -30,10 +29,8 @@ import org.json.JSONObject; ...@@ -30,10 +29,8 @@ import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
...@@ -109,57 +106,78 @@ public class CatalogueVariableApiManager { ...@@ -109,57 +106,78 @@ public class CatalogueVariableApiManager {
.create(); .create();
JSONObject catalogueJsonObject = jsonArray.getJSONObject(0); JSONObject catalogueJsonObject = jsonArray.getJSONObject(0);
JSONArray variableSetJsonArray = catalogueJsonObject.getJSONArray(Constants.RESPONSE_VARIABLE_SET_OBJECT_NAME); JSONArray catalogueVariableJsonArray = catalogueJsonObject.getJSONArray(Constants
List<CatalogueVariableSet> variableSetList = new ArrayList<>(variableSetJsonArray.length()); .RESPONSE_VARIABLES_OBJECT_NAME);
for (int i = 0; i < variableSetJsonArray.length(); i++) { JSONArray catalogueVariableSetJsonArray = catalogueJsonObject.getJSONArray(Constants
JSONObject variableSetJsonObject = variableSetJsonArray.getJSONObject(i); .RESPONSE_VARIABLE_SET_OBJECT_NAME);
CatalogueVariableSet catalogueVariableSet = gson.fromJson(variableSetJsonObject.toString(), CatalogueVariableSet.class); CatalogueVariableResponse catalogueVariableResponse = gson.fromJson(catalogueJsonObject.toString(),
CatalogueVariableResponse.class);
for (int i = 0; i < catalogueVariableJsonArray.length(); i++) {
CatalogueVariable catalogueVariable = catalogueVariableResponse.getVariables().get(i);
JSONObject catalogueVariableJsonObject = catalogueVariableJsonArray.getJSONObject(i);
catalogueVariable.parseJson(catalogueVariableJsonObject);
if(!catalogueVariable.getVariableChoiceList().isEmpty()) {
Collections.sort(catalogueVariable.getVariableChoiceList(), new Comparator<VariableChoice>() {
@Override
public int compare(VariableChoice lhs, VariableChoice rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
}
}
JSONArray variableJsonArray = variableSetJsonObject.getJSONArray(Constants.RESPONSE_VARIABLES_OBJECT_NAME); for (int i = 0; i < catalogueVariableSetJsonArray.length(); i++) {
List<CatalogueVariable> variableList = new ArrayList<>(variableJsonArray.length()); CatalogueVariableSet catalogueVariableSet = catalogueVariableResponse.getVariablesets
().get(i);
JSONObject variableSetJsonObject = catalogueVariableSetJsonArray.getJSONObject(i);
JSONArray variableJsonArray = variableSetJsonObject.getJSONArray(Constants
.RESPONSE_VARIABLES_OBJECT_NAME);
for (int j = 0; j < variableJsonArray.length(); j++) { for (int j = 0; j < variableJsonArray.length(); j++) {
JSONObject variableJsonObject = variableJsonArray.getJSONObject(j); JSONObject variableJsonObject = variableJsonArray.getJSONObject(j);
CatalogueVariable catalogueVariable = gson.fromJson(variableJsonObject.toString(), CatalogueVariable.class); CatalogueVariable catalogueVariable = catalogueVariableSet.getVariables().get(j);
catalogueVariable.parseJson(variableJsonObject); catalogueVariable.parseJson(variableJsonObject);
variableList.add(catalogueVariable); if(!catalogueVariable.getVariableChoiceList().isEmpty()) {
} Collections.sort(catalogueVariable.getVariableChoiceList(), new Comparator<VariableChoice>() {
@Override
Collections.sort(variableList, new Comparator<CatalogueVariable>() { public int compare(VariableChoice lhs, VariableChoice rhs) {
@Override return (lhs.getOrder() - rhs.getOrder());
public int compare(CatalogueVariable lhs, CatalogueVariable rhs) { }
return (lhs.getOrder() - rhs.getOrder()); });
} }
}); }
catalogueVariableSet.setVariables(variableList);
variableSetList.add(catalogueVariableSet);
} }
Collections.sort(variableSetList, new Comparator<CatalogueVariableSet>() { /*Sort Variable set*/
Collections.sort(catalogueVariableResponse.getVariablesets(), new Comparator<CatalogueVariableSet>() {
@Override @Override
public int compare(CatalogueVariableSet lhs, CatalogueVariableSet rhs) { public int compare(CatalogueVariableSet lhs, CatalogueVariableSet rhs) {
return (lhs.getOrder() - rhs.getOrder()); return (lhs.getOrder() - rhs.getOrder());
} }
}); });
JSONArray variableJsonArray = catalogueJsonObject.getJSONArray(Constants.RESPONSE_VARIABLES_OBJECT_NAME); /*Sort Variables*/
List<CatalogueVariable> variableList = new ArrayList<>(variableJsonArray.length()); Collections.sort(catalogueVariableResponse.getVariables(), new Comparator<CatalogueVariable>() {
for (int i = 0; i < variableJsonArray.length(); i++) {
JSONObject variableJsonObject = variableJsonArray.getJSONObject(i);
CatalogueVariable catalogueVariable = gson.fromJson(variableJsonObject.toString(), CatalogueVariable.class);
catalogueVariable.parseJson(variableJsonObject);
variableList.add(catalogueVariable);
}
Collections.sort(variableList, new Comparator<CatalogueVariable>() {
@Override @Override
public int compare(CatalogueVariable lhs, CatalogueVariable rhs) { public int compare(CatalogueVariable lhs, CatalogueVariable rhs) {
return (lhs.getOrder() - rhs.getOrder()); return (lhs.getOrder() - rhs.getOrder());
} }
}); });
listener.onDoneApiCall(variableSetList, variableList);
/*Sort Variables of Variable sets*/
for (int i = 0; i < catalogueVariableResponse.getVariablesets().size() ; i++) {
CatalogueVariableSet catalogueVariableSet = catalogueVariableResponse.getVariablesets
().get(i);
Collections.sort(catalogueVariableSet.getVariables(), new Comparator<CatalogueVariable>() {
@Override
public int compare(CatalogueVariable lhs, CatalogueVariable rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
}
listener.onDoneApiCall(catalogueVariableResponse);
} else { } else {
listener.onDoneApiCall(new ArrayList<CatalogueVariableSet>(0), new ArrayList<CatalogueVariable>(0)); listener.onDoneApiCall(null);
} }
} else } else
listener.onFailApiCall(); listener.onFailApiCall();
...@@ -195,120 +213,6 @@ public class CatalogueVariableApiManager { ...@@ -195,120 +213,6 @@ public class CatalogueVariableApiManager {
} }
} }
public static void getUiPolicy(Context context, String catalogueItemSysId, GetUiPolicyApiListener listener) {
CatalogueLog.d("CatalogueVariableApiManager: getUiPolicy: ");
String accessToken = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
if(accessToken.isEmpty()) {
listener.onFailApiCall();
return;
}
final Retrofit retrofit = RestClient.getInitializedRestAdapter(accessToken);
Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).getUiPolicy(catalogueItemSysId);
try {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) {
try {
JSONObject jsonObject = new JSONObject(response.body().string());
JSONObject error = jsonObject.optJSONObject(Constants.RESPONSE_ERROR_OBJECT_NAME);
if (error == null) {
JSONArray resultJsonArray = jsonObject.getJSONArray(Constants.RESPONSE_RESULT_OBJECT_NAME);
if(resultJsonArray.length() > 0) {
Gson gson = new GsonBuilder()
.excludeFieldsWithoutExposeAnnotation()
.registerTypeAdapter(long.class, new JsonDeserializer<Long>() {
@Override
public Long deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
long value = 0;
try {
value = json.getAsLong();
} catch (NumberFormatException e) {
CatalogueLog.d("CatalogueVariableApiManager: getUiPolicy: deserialize: long.class: NumberFormatException: ");
}
return value;
}
})
.registerTypeAdapter(int.class, new JsonDeserializer<Integer>() {
@Override
public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
int value = 0;
try {
value = json.getAsInt();
} catch (NumberFormatException e) {
CatalogueLog.d("CatalogueVariableApiManager: getUiPolicy: deserialize: int.class: NumberFormatException: ");
}
return value;
}
})
.registerTypeAdapter(float.class, new JsonDeserializer<Float>() {
@Override
public Float deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
float value = 0;
try {
value = json.getAsFloat();
} catch (NumberFormatException e) {
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: deserialize: float.class: NumberFormatException: ", e);
}
return value;
}
})
.create();
JSONArray uiPolicyJsonArray = resultJsonArray.getJSONArray(0);
List<UiPolicyItem> uiPolicyItemList = new ArrayList<>(uiPolicyJsonArray.length());
for (int i = 0; i < uiPolicyJsonArray.length(); i++) {
JSONObject UiPolicyResponseJsonObject = uiPolicyJsonArray.getJSONObject(i);
UiPolicyItem uiPolicyItem = gson.fromJson(UiPolicyResponseJsonObject.toString(), UiPolicyItem.class);
JSONArray UiPolicyActionJsonArray = UiPolicyResponseJsonObject.getJSONArray(Constants.RESPONSE_VARIABLES_UI_POLICY_ACTIONS);
List<UiPolicyAction> uiPolicyActionList = new ArrayList<>(UiPolicyActionJsonArray.length());
for (int j = 0; j < UiPolicyActionJsonArray.length(); j++) {
JSONObject UiPolicyActionJsonObject = UiPolicyActionJsonArray.getJSONObject(j);
UiPolicyAction uiPolicyAction = gson.fromJson(UiPolicyActionJsonObject.toString(), UiPolicyAction.class);
uiPolicyActionList.add(uiPolicyAction);
}
uiPolicyItem.setUiPolicyActions(uiPolicyActionList);
uiPolicyItemList.add(uiPolicyItem);
}
listener.onDoneApiCall(uiPolicyItemList);
} else {
listener.onDoneApiCall(new ArrayList<UiPolicyItem>(0));
}
} else
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: onResponse: ", e);
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: onResponse: ", e);
listener.onFailApiCall();
}
} else {
CatalogueLog.d("CatalogueVariableApiManager: getUiPolicy: 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...");
getUiPolicy(context, catalogueItemSysId, listener);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
}
} else {
listener.onFailApiCall();
}
}
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: IOException: ", e);
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: NullPointerException: ", e);
listener.onFailApiCall();
}
}
public static void submitVariableForm(Context context, String catalogueItemSysId, String catalogueJsonString, PostVariableFormApiListener listener) { public static void submitVariableForm(Context context, String catalogueItemSysId, String catalogueJsonString, PostVariableFormApiListener listener) {
CatalogueLog.d("submitVariableForm: " + catalogueJsonString); CatalogueLog.d("submitVariableForm: " + catalogueJsonString);
......
...@@ -48,14 +48,14 @@ public class CatalogueVariable { ...@@ -48,14 +48,14 @@ public class CatalogueVariable {
@SerializedName("default_value") @SerializedName("default_value")
@Expose @Expose
private String defaultValue; private String defaultValue;
@SerializedName("question_choice")
@Expose
private List<VariableChoice> questionChoice = null;
// @SerializedName("type") // @SerializedName("type")
// @Expose // @Expose
private ViewType type; private ViewType type;
private List<VariableChoice> mVariableChoiceList;
/** /**
* *
* @return * @return
...@@ -185,20 +185,20 @@ public class CatalogueVariable { ...@@ -185,20 +185,20 @@ public class CatalogueVariable {
} }
public List<VariableChoice> getVariableChoiceList() { public List<VariableChoice> getVariableChoiceList() {
return mVariableChoiceList; return questionChoice;
} }
public void setVariableChoiceList(List<VariableChoice> mVariableChoiceList) { public void setVariableChoiceList(List<VariableChoice> mVariableChoiceList) {
this.mVariableChoiceList = mVariableChoiceList; this.questionChoice = mVariableChoiceList;
} }
public String[] getDisplayChoiceText(Context context) { public String[] getDisplayChoiceText(Context context) {
String[] choiceText; String[] choiceText;
if(defaultValue!=null) { if(defaultValue!=null) {
choiceText = new String[mVariableChoiceList.size() + 1]; choiceText = new String[questionChoice.size() + 1];
choiceText[0] = defaultValue; choiceText[0] = defaultValue;
for (int i = 0; i < mVariableChoiceList.size(); i++) { for (int i = 0; i < questionChoice.size(); i++) {
VariableChoice variableChoice = mVariableChoiceList.get(i); VariableChoice variableChoice = questionChoice.get(i);
/*(i+1) for add None text as a first Element*/ /*(i+1) for add None text as a first Element*/
if(variableChoice.getMisc() > 0) { if(variableChoice.getMisc() > 0) {
choiceText[i + 1] = String.format(context.getString(R.string.variable_form_misc_info_string), choiceText[i + 1] = String.format(context.getString(R.string.variable_form_misc_info_string),
...@@ -209,10 +209,10 @@ public class CatalogueVariable { ...@@ -209,10 +209,10 @@ public class CatalogueVariable {
} }
} }
} else if(isNoneRequired) { } else if(isNoneRequired) {
choiceText = new String[mVariableChoiceList.size() + 1]; choiceText = new String[questionChoice.size() + 1];
choiceText[0] = context.getString(R.string.none_string); choiceText[0] = context.getString(R.string.none_string);
for (int i = 0; i < mVariableChoiceList.size(); i++) { for (int i = 0; i < questionChoice.size(); i++) {
VariableChoice variableChoice = mVariableChoiceList.get(i); VariableChoice variableChoice = questionChoice.get(i);
/*(i+1) for add None text as a first Element*/ /*(i+1) for add None text as a first Element*/
if(variableChoice.getMisc() > 0) { if(variableChoice.getMisc() > 0) {
choiceText[i + 1] = String.format(context.getString(R.string.variable_form_misc_info_string), choiceText[i + 1] = String.format(context.getString(R.string.variable_form_misc_info_string),
...@@ -223,9 +223,9 @@ public class CatalogueVariable { ...@@ -223,9 +223,9 @@ public class CatalogueVariable {
} }
} }
} else { } else {
choiceText = new String[mVariableChoiceList.size()]; choiceText = new String[questionChoice.size()];
for (int i = 0; i < mVariableChoiceList.size(); i++) { for (int i = 0; i < questionChoice.size(); i++) {
VariableChoice variableChoice = mVariableChoiceList.get(i); VariableChoice variableChoice = questionChoice.get(i);
if(variableChoice.getMisc() > 0) { if(variableChoice.getMisc() > 0) {
choiceText[i] = String.format(context.getString(R.string.variable_form_misc_info_string), choiceText[i] = String.format(context.getString(R.string.variable_form_misc_info_string),
variableChoice.getText(), variableChoice.getText(),
...@@ -239,8 +239,8 @@ public class CatalogueVariable { ...@@ -239,8 +239,8 @@ public class CatalogueVariable {
} }
public String getDisplayChoiceText(String text) { public String getDisplayChoiceText(String text) {
for (int i = 0; i < mVariableChoiceList.size(); i++) { for (int i = 0; i < questionChoice.size(); i++) {
VariableChoice variableChoice = mVariableChoiceList.get(i); VariableChoice variableChoice = questionChoice.get(i);
if(variableChoice.getText().equals(text)) { if(variableChoice.getText().equals(text)) {
return variableChoice.getValue(); return variableChoice.getValue();
} }
...@@ -280,7 +280,7 @@ public class CatalogueVariable { ...@@ -280,7 +280,7 @@ public class CatalogueVariable {
", active=" + active + ", active=" + active +
", defaultValue='" + defaultValue + '\'' + ", defaultValue='" + defaultValue + '\'' +
", type=" + type + ", type=" + type +
", mVariableChoiceList=" + mVariableChoiceList + ", mVariableChoiceList=" + questionChoice +
'}'; '}';
} }
} }
package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.List;
/**
* Created by kunj on 16/02/17.
*/
public class CatalogueVariableResponse {
@SerializedName("variables")
@Expose
private List<CatalogueVariable> variables = null;
@SerializedName("ui_policy")
@Expose
private List<UiPolicyItem> uiPolicy = null;
@SerializedName("variablesets")
@Expose
private List<CatalogueVariableSet> variablesets = null;
public List<CatalogueVariable> getVariables() {
return variables;
}
public void setVariables(List<CatalogueVariable> variables) {
this.variables = variables;
}
public List<UiPolicyItem> getUiPolicy() {
return uiPolicy;
}
public void setUiPolicy(List<UiPolicyItem> uiPolicy) {
this.uiPolicy = uiPolicy;
}
public List<CatalogueVariableSet> getVariablesets() {
return variablesets;
}
public void setVariablesets(List<CatalogueVariableSet> variablesets) {
this.variablesets = variablesets;
}
}
...@@ -12,12 +12,15 @@ import java.util.List; ...@@ -12,12 +12,15 @@ import java.util.List;
public class UiPolicyItem { public class UiPolicyItem {
private List<UiPolicyAction> uiPolicyActions;
private List<PartialCondition> partialConditions; private List<PartialCondition> partialConditions;
@SerializedName("condition") @SerializedName("condition")
@Expose @Expose
private String condition; private String condition;
@SerializedName("sys_id") @SerializedName("sys_id")
private String sysId;
@SerializedName("ui_policy_actions")
@Expose
private List<UiPolicyAction> uiPolicyActions;
public List<UiPolicyAction> getUiPolicyActions() { public List<UiPolicyAction> getUiPolicyActions() {
return uiPolicyActions; return uiPolicyActions;
...@@ -52,4 +55,22 @@ public class UiPolicyItem { ...@@ -52,4 +55,22 @@ public class UiPolicyItem {
public void setCondition(String condition) { public void setCondition(String condition) {
this.condition = condition; this.condition = condition;
} }
/**
*
* @return
* The sys_id
*/
public String getSysId() {
return sysId;
}
/**
*
* @param sysId
* The sys_id
*/
public void setSysId(String sysId) {
this.sysId = sysId;
}
} }
...@@ -57,6 +57,7 @@ import com.vsoft.servicenow.api.listeners.post.PostVariableFormApiListener; ...@@ -57,6 +57,7 @@ import com.vsoft.servicenow.api.listeners.post.PostVariableFormApiListener;
import com.vsoft.servicenow.api.managers.CatalogueVariableApiManager; import com.vsoft.servicenow.api.managers.CatalogueVariableApiManager;
import com.vsoft.servicenow.api.managers.VariableChoiceApiManager; import com.vsoft.servicenow.api.managers.VariableChoiceApiManager;
import com.vsoft.servicenow.db.models.CatalogueVariable; import com.vsoft.servicenow.db.models.CatalogueVariable;
import com.vsoft.servicenow.db.models.CatalogueVariableResponse;
import com.vsoft.servicenow.db.models.CatalogueVariableSet; import com.vsoft.servicenow.db.models.CatalogueVariableSet;
import com.vsoft.servicenow.db.models.Reference; import com.vsoft.servicenow.db.models.Reference;
import com.vsoft.servicenow.db.models.UiPolicyAction; import com.vsoft.servicenow.db.models.UiPolicyAction;
...@@ -101,6 +102,8 @@ import butterknife.OnClick; ...@@ -101,6 +102,8 @@ import butterknife.OnClick;
import okhttp3.MediaType; import okhttp3.MediaType;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import static com.google.android.gms.analytics.internal.zzy.i;
/** /**
* Created by Kunj on 11/8/16. * Created by Kunj on 11/8/16.
*/ */
...@@ -184,63 +187,48 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -184,63 +187,48 @@ public class CatalogueVariableScreen extends AppCompatActivity {
protected SyncStatus doInBackground(final String... params) { protected SyncStatus doInBackground(final String... params) {
CatalogueVariableApiManager.getCatalogueVariable(CatalogueVariableScreen.this, mCatalogueItemSysId, new GetCatalogueVariableApiListener() { CatalogueVariableApiManager.getCatalogueVariable(CatalogueVariableScreen.this, mCatalogueItemSysId, new GetCatalogueVariableApiListener() {
@Override @Override
public void onDoneApiCall(List<CatalogueVariableSet> variableSetList, List<CatalogueVariable> variableList) { public void onDoneApiCall(CatalogueVariableResponse catalogueVariableResponse/*List<CatalogueVariableSet> variableSetList,
List<CatalogueVariable>
variableList*/) {
mSyncStatus = SyncStatus.SUCCESS; mSyncStatus = SyncStatus.SUCCESS;
/*For variableset */ /*For variableset */
for (int i = 0; i <variableSetList.size(); i++) { for (int i = 0; i <catalogueVariableResponse.getVariablesets().size(); i++) {
CatalogueVariableSet catalogueVariableSet = variableSetList.get(i); CatalogueVariableSet catalogueVariableSet = catalogueVariableResponse.getVariablesets().get(i);
mSyncStatus = setVariableChoiceData(catalogueVariableSet.getVariables()); mCatalogueVariableList.addAll(catalogueVariableSet.getVariables());
if(mSyncStatus == SyncStatus.FAIL)
break;
} }
if(mSyncStatus != SyncStatus.FAIL) { /*For variable list*/
/*For variable list*/ mCatalogueVariableList.addAll(catalogueVariableResponse.getVariables());
mSyncStatus = setVariableChoiceData(variableList); mUiPolicyItemList = catalogueVariableResponse.getUiPolicy();
if(mSyncStatus != SyncStatus.FAIL) { for (int i = 0; i < mUiPolicyItemList.size(); i++) {
CatalogueVariableApiManager.getUiPolicy(CatalogueVariableScreen.this, mCatalogueItemSysId, new GetUiPolicyApiListener() { UiPolicyItem uiPolicyItem = mUiPolicyItemList.get(i);
@Override String condition = uiPolicyItem.getCondition();
public void onDoneApiCall(List<UiPolicyItem> uiPolicyItemList) { if (condition != null) {
mSyncStatus = SyncStatus.SUCCESS; String[] splitStrings = uiPolicyItem.getCondition().split("\\^");
mUiPolicyItemList = uiPolicyItemList; List<PartialCondition> partialConditionList = new ArrayList<>(splitStrings.length - 1);
for (int i = 0; i < mUiPolicyItemList.size(); i++) { for (int j = 0; j < splitStrings.length - 1; j++) {
UiPolicyItem uiPolicyItem = mUiPolicyItemList.get(i); PartialCondition partialCondition = new PartialCondition();
String condition = uiPolicyItem.getCondition(); String value = splitStrings[j].replace("IO:", "");
if (condition != null) { String sysId = value.substring(0, 32);
String[] splitStrings = uiPolicyItem.getCondition().split("\\^"); String operatorAndValue = value.substring(32);
List<PartialCondition> partialConditionList = new ArrayList<>(splitStrings.length - 1); partialCondition.setViewSysId(sysId);
for (int j = 0; j < splitStrings.length - 1; j++) {
PartialCondition partialCondition = new PartialCondition(); if (!operatorAndValue.contains("=")) {
String value = splitStrings[j].replace("IO:", ""); partialCondition.setOperator(Operator.from(operatorAndValue));
String sysId = value.substring(0, 32); } else {
String operatorAndValue = value.substring(32); String[] strings = operatorAndValue.split("=");
partialCondition.setViewSysId(sysId); partialCondition.setOperator(Operator.EQUAL);
/*Below condition is use for condition=empty,
if (!operatorAndValue.contains("=")) { *we need to handle empty condition in else statement*/
partialCondition.setOperator(Operator.from(operatorAndValue)); if (strings.length >= 2) {
} else { partialCondition.setOperatorValue(strings[1]);
String[] strings = operatorAndValue.split("="); } else {
partialCondition.setOperator(Operator.EQUAL); partialCondition.setOperatorValue("");
/*Below condition is use for condition=empty,
*we need to handle empty condition in else statement*/
if (strings.length >= 2) {
partialCondition.setOperatorValue(strings[1]);
} else {
partialCondition.setOperatorValue("");
}
}
partialConditionList.add(partialCondition);
}
uiPolicyItem.setPartialConditions(partialConditionList);
}
} }
} }
partialConditionList.add(partialCondition);
@Override }
public void onFailApiCall() { uiPolicyItem.setPartialConditions(partialConditionList);
mSyncStatus = SyncStatus.FAIL;
}
});
} }
} }
} }
...@@ -270,41 +258,6 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -270,41 +258,6 @@ public class CatalogueVariableScreen extends AppCompatActivity {
} }
} }
private SyncStatus setVariableChoiceData(List<CatalogueVariable> variableList) {
if(!variableList.isEmpty()) {
for (int i = 0; i < variableList.size(); i++) {
final CatalogueVariable catalogueVariable = variableList.get(i);
if (catalogueVariable.getType() == ViewType.MULTIPLE_CHOICE
|| catalogueVariable.getType() == ViewType.SELECT_BOX) {
/*Fetch multi choice variable values*/
VariableChoiceApiManager.getVariableChoice(CatalogueVariableScreen.this, 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
public int compare(VariableChoice lhs, VariableChoice rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
catalogueVariable.setVariableChoiceList(variableChoiceList);
}
@Override
public void onFailApiCall() {
mSyncStatus = SyncStatus.FAIL;
}
});
if(mSyncStatus == SyncStatus.FAIL)
break;
}
}
mCatalogueVariableList.addAll(variableList);
}
return mSyncStatus;
}
private void createView() { private void createView() {
/*For variable list */ /*For variable list */
getCustomLayout(); getCustomLayout();
......
...@@ -26,7 +26,7 @@ public class AppConfig { ...@@ -26,7 +26,7 @@ public class AppConfig {
public static final String URL_GET_CATALOGUE_ITEM = "api/uno33/uofl_mobile/catalog_item"; public static final String URL_GET_CATALOGUE_ITEM = "api/uno33/uofl_mobile/catalog_item";
/*Variable form API */ /*Variable form API */
public static final String URL_GET_VARIABLE = "/api/uno33/uofl_mobile/variables"; public static final String URL_GET_VARIABLE = "api/uno33/uofl_mobile/catalogue_variable_screen";
public static final String URL_GET_UI_POLICY = "/api/uno33/uofl_mobile/uipolicy"; public static final String URL_GET_UI_POLICY = "/api/uno33/uofl_mobile/uipolicy";
public static final String URL_GET_VARIABLE_CHOICE = "/api/uno33/uofl_mobile/question_choice"; public static final String URL_GET_VARIABLE_CHOICE = "/api/uno33/uofl_mobile/question_choice";
public static final String URL_POST_CATALOGUE_ITEM = "api/uno33/uofl_mobile"; public static final String URL_POST_CATALOGUE_ITEM = "api/uno33/uofl_mobile";
......
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