Commit 67ff5765 by Kunj Gupta

UOFLMA-118: implemented API to modify Dynamic Form according to UI Policies.

parent 44225f97
Showing with 1127 additions and 216 deletions
......@@ -30,7 +30,7 @@ public class HomeScreenAdapter extends BaseAdapter {
@Override
public int getCount() {
// Number of times getView method call depends upon mGridValues.length
// Number of times getVariableViewContainer method call depends upon mGridValues.length
return mGridValues.length;
}
......@@ -44,7 +44,7 @@ public class HomeScreenAdapter extends BaseAdapter {
return position;
}
// Number of times getView method call depends upon mGridValues.length
// Number of times getVariableViewContainer method call depends upon mGridValues.length
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
......
package com.vsoft.uoflservicenow.api;
import android.text.TextUtils;
import android.util.Base64;
import com.vsoft.uoflservicenow.utils.Constants;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
......@@ -18,53 +21,16 @@ import retrofit2.converter.gson.GsonConverterFactory;
*/
public class RestClient {
public static Retrofit getInitializedRestAdapter(final String accessToken) {
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
Interceptor interceptor = new Interceptor() {
@Override
public Response intercept(Chain chain) {
Request original = chain.request();
Request.Builder requestBuilder = original.newBuilder();
if(!TextUtils.isEmpty(accessToken)) {
final String bearer = "Bearer " + accessToken;
requestBuilder.header(Constants.API_HEADER_PARAM_AUTHORIZATION, bearer);
}
requestBuilder.header("Accept", "application/json");
requestBuilder.header("Content-Type", "application/json");
requestBuilder.method(original.method(), original.body());
Request request = requestBuilder.build();
try {
return chain.proceed(request);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
};
httpClient.interceptors().add(interceptor);
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
httpClient.interceptors().add(logging);
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl(Constants.DOMAIN)
.client(httpClient.build())
.addConverterFactory(new GsonStringConverterFactory())
.addConverterFactory(GsonConverterFactory.create());
return builder.build();
}
public static Retrofit getInitializedRestAdapter(String username, String password) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
// set your desired log level
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
OkHttpClient.Builder httpClient = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS);
String credentials = username + ":" + password;
final String basic =
"Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
......@@ -101,51 +67,15 @@ public class RestClient {
return builder.build();
}
public static Retrofit getInitializedRestAdapterWithOutHeader(String username, String password) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
// set your desired log level
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
String credentials = username + ":" + password;
final String basic =
"Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
// add your other interceptors
Interceptor interceptor = new Interceptor() {
@Override
public Response intercept(Chain chain) {
Request original = chain.request();
Request.Builder requestBuilder = original.newBuilder()
.header(Constants.API_HEADER_PARAM_AUTHORIZATION, basic);
requestBuilder.method(original.method(), original.body());
Request request = requestBuilder.build();
try {
return chain.proceed(request);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
};
httpClient.interceptors().add(interceptor);
// add logging as last interceptor
httpClient.interceptors().add(logging); // <-- this is the important line!
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl(Constants.DOMAIN)
.client(httpClient.build())
.addConverterFactory(new GsonStringConverterFactory())
.addConverterFactory(GsonConverterFactory.create());
return builder.build();
}
public static Retrofit getInitializedRestAdapterWithOutAuthorizationHeader() {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
// set your desired log level
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
OkHttpClient.Builder httpClient = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS);
// add your other interceptors
Interceptor interceptor = new Interceptor() {
@Override
......
......@@ -49,6 +49,10 @@ public interface CatalogueVariableApi {
@Query(Constants.URL_PARAM_TABLE_NAME) String tableName,
@Query(Constants.URL_PARAM_FILE_NAME) String fileName,
@Body RequestBody attachmentRequestBody);
// Get Variable API
@GET(Constants.URL_GET_UI_POLICY)
Call<ResponseBody> getUiPolicy(@Query(CatalogueVariable.Json.SYS_ID) String sysId);
}
package com.vsoft.uoflservicenow.api.listeners.get;
import com.vsoft.uoflservicenow.db.models.UiPolicyItem;
import java.util.List;
/**
* @since 1.0
* @author Kunj on 11/8/16
*
*/
public interface GetUiPolicyApiListener {
void onDoneApiCall(List<UiPolicyItem> uiPolicyItemList);
}
......@@ -101,8 +101,8 @@ public class CatalogueApiManager {
final List<Catalogue> catalogueList = new ArrayList<>(catalogueJsonArray.length());
final List<Catalogue> finalCatalogueList = new ArrayList<>(catalogueJsonArray.length());
for (int i = 0; i < catalogueJsonArray.length(); i++) {
JSONObject expenseJsonObject = catalogueJsonArray.getJSONObject(i);
Catalogue catalogue = gson.fromJson(expenseJsonObject.toString(), Catalogue.class);
JSONObject catalogueJsonObject = catalogueJsonArray.getJSONObject(i);
Catalogue catalogue = gson.fromJson(catalogueJsonObject.toString(), Catalogue.class);
catalogueList.add(catalogue);
}
if(!catalogueList.isEmpty()) {
......@@ -208,8 +208,8 @@ public class CatalogueApiManager {
List<CatalogueOrder> catalogueOrderList = new ArrayList<>(catalogueOrderJsonArray.length());
for (int i = 0; i < catalogueOrderJsonArray.length(); i++) {
JSONObject expenseJsonObject = catalogueOrderJsonArray.getJSONObject(i);
CatalogueOrder catalogueOrder = gson.fromJson(expenseJsonObject.toString(), CatalogueOrder.class);
JSONObject orderJsonObject = catalogueOrderJsonArray.getJSONObject(i);
CatalogueOrder catalogueOrder = gson.fromJson(orderJsonObject.toString(), CatalogueOrder.class);
catalogueOrderList.add(catalogueOrder);
}
......
......@@ -97,8 +97,8 @@ public class CatalogueItemApiManager {
List<CatalogueItem> catalogueItemList = new ArrayList<>(catalogueItemJsonArray.length());
for (int i = 0; i < catalogueItemJsonArray.length(); i++) {
JSONObject expenseJsonObject = catalogueItemJsonArray.getJSONObject(i);
CatalogueItem catalogueItem = gson.fromJson(expenseJsonObject.toString(), CatalogueItem.class);
JSONObject catalogueItemJsonObject = catalogueItemJsonArray.getJSONObject(i);
CatalogueItem catalogueItem = gson.fromJson(catalogueItemJsonObject.toString(), CatalogueItem.class);
catalogueItemList.add(catalogueItem);
}
listener.onDoneApiCall(catalogueItemList);
......
......@@ -9,9 +9,12 @@ import com.google.gson.JsonParseException;
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.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;
......@@ -168,11 +171,106 @@ public class CatalogueVariableApiManager {
}
}
public static SyncStatus submitVariableForm(String catalogueItemSysId, JSONArray catalogueJsonArray, PostVariableFormApiListener listener) {
CatalogueLog.d("submitVariableForm: " + catalogueJsonArray);
String expenseJsonString = catalogueJsonArray.toString();
public static SyncStatus 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).postCatalogueItem(catalogueItemSysId, expenseJsonString);
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));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
} catch (JSONException e) {
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: onResponse: ", e);
return SyncStatus.FAIL;
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: onResponse: ", e);
return SyncStatus.FAIL;
}
} else {
return SyncStatus.FAIL;
}
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: IOException: ", e);
return SyncStatus.FAIL;
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: NullPointerException: ", e);
return SyncStatus.FAIL;
}
}
public static SyncStatus 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);
try {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
......@@ -194,7 +292,7 @@ public class CatalogueVariableApiManager {
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: submitVariableForm: IOException: ", e);
return SyncStatus.FAIL;
} catch (NullPointerException e){
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueVariableApiManager: submitVariableForm: IOException: ", e);
return SyncStatus.FAIL;
}
......@@ -215,7 +313,7 @@ public class CatalogueVariableApiManager {
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: postAttachment: IOException: ", e);
return SyncStatus.FAIL;
} catch (NullPointerException e){
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueVariableApiManager: postAttachment: IOException: ", e);
return SyncStatus.FAIL;
}
......
......@@ -95,9 +95,9 @@ public class IncidentApiManager {
List<Incident> incidentList = new ArrayList<>(incidentJsonArray.length());
for (int i = 0; i < incidentJsonArray.length(); i++) {
JSONObject expenseJsonObject = incidentJsonArray.getJSONObject(i);
Incident incident = gson.fromJson(expenseJsonObject.toString(), Incident.class);
incident.parseJson(expenseJsonObject);
JSONObject incidentJsonObject = incidentJsonArray.getJSONObject(i);
Incident incident = gson.fromJson(incidentJsonObject.toString(), Incident.class);
incident.parseJson(incidentJsonObject);
incidentList.add(incident);
}
listener.onDoneApiCall(incidentList);
......
......@@ -88,8 +88,8 @@ public class UserApiManager {
List<UserApiValues> userList = new ArrayList<>(catalogueJsonArray.length());
for (int i = 0; i < catalogueJsonArray.length(); i++) {
JSONObject expenseJsonObject = catalogueJsonArray.getJSONObject(i);
UserApiValues catalogue = gson.fromJson(expenseJsonObject.toString(), UserApiValues.class);
JSONObject catalogueJsonObject = catalogueJsonArray.getJSONObject(i);
UserApiValues catalogue = gson.fromJson(catalogueJsonObject.toString(), UserApiValues.class);
userList.add(catalogue);
}
listener.onDoneApiCall(userList);
......
......@@ -46,11 +46,11 @@ public class CatalogueVariable {
@Expose
private boolean active;
// @SerializedName("type")
// @Expose
private ViewType type;
private List<VariableChoice> mVariableChoiceList;
/**
......@@ -213,6 +213,16 @@ public class CatalogueVariable {
return choiceText;
}
public String getDisplayChoiceText(String text) {
for (int i = 0; i < mVariableChoiceList.size(); i++) {
VariableChoice variableChoice = mVariableChoiceList.get(i);
if(variableChoice.getText().equals(text)) {
return variableChoice.getValue();
}
}
return null;
}
public void parseJson(JSONObject jsonObject) {
String viewType = null;
try {
......
package com.vsoft.uoflservicenow.db.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class UiPolicyAction {
@SerializedName("visible")
@Expose
private String visible;
@SerializedName("mandatory")
@Expose
private String mandatory;
@SerializedName("variable")
@Expose
private String variableName;
@SerializedName("disabled")
@Expose
private String disabled;
/**
*
* @return
* The visible
*/
public String getVisible() {
return visible;
}
/**
*
* @param visible
* The visible
*/
public void setVisible(String visible) {
this.visible = visible;
}
/**
*
* @return
* The mandatory
*/
public String getMandatory() {
return mandatory;
}
/**
*
* @param mandatory
* The mandatory
*/
public void setMandatory(String mandatory) {
this.mandatory = mandatory;
}
/**
*
* @return
* The variableName
*/
public String getVariableName() {
return variableName;
}
/**
*
* @param variableName
* The variableName
*/
public void setVariableName(String variableName) {
this.variableName = variableName;
}
/**
*
* @return
* The disabled
*/
public String getDisabled() {
return disabled;
}
/**
*
* @param disabled
* The disabled
*/
public void setDisabled(String disabled) {
this.disabled = disabled;
}
}
package com.vsoft.uoflservicenow.db.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.vsoft.uoflservicenow.utils.PartialCondition;
import java.util.List;
/**
* Created by chaukadev on 6/10/16.
*/
public class UiPolicyItem {
private List<UiPolicyAction> uiPolicyActions;
private List<PartialCondition> partialConditions;
@SerializedName("condition")
@Expose
private String condition;
@SerializedName("sys_id")
public List<UiPolicyAction> getUiPolicyActions() {
return uiPolicyActions;
}
public void setUiPolicyActions(List<UiPolicyAction> uiPolicyActions) {
this.uiPolicyActions = uiPolicyActions;
}
public List<PartialCondition> getPartialConditions() {
return partialConditions;
}
public void setPartialConditions(List<PartialCondition> partialConditions) {
this.partialConditions = partialConditions;
}
/**
*
* @return
* The condition
*/
public String getCondition() {
return condition;
}
/**
*
* @param condition
* The condition
*/
public void setCondition(String condition) {
this.condition = condition;
}
}
package com.vsoft.uoflservicenow.db.models;
import android.view.View;
import android.view.ViewGroup;
/**
* Created by chaukadev on 7/10/16.
*/
public class VariableViewContainer {
private CatalogueVariable variable;
private View labelView;
private View inputView;
private View errorView;
private ViewGroup containerView;
public View getLabelView() {
return labelView;
}
public void setLabelView(View labelView) {
this.labelView = labelView;
}
public View getInputView() {
return inputView;
}
public void setInputView(View inputView) {
this.inputView = inputView;
}
public View getErrorView() {
return errorView;
}
public void setErrorView(View errorView) {
this.errorView = errorView;
}
public ViewGroup getContainerView() {
return containerView;
}
public void setContainerView(ViewGroup containerView) {
this.containerView = containerView;
}
}
package com.vsoft.uoflservicenow.enums;
/**
* @since 1.0
* @author Kunj on 06/10/16.
*
*/
public enum Operator {
UNKNOWN (-1, ""),
EQUAL (1, "="),
IS_NOT_EMPTY (2, "ISNOTEMPTY");
private int id;
private String operatorString;
Operator(int id, String operatorString) {
this.id = id;
this.operatorString = operatorString;
}
public String getOperatorString() {
return operatorString;
}
public void setOperatorString(String operatorString) {
this.operatorString = operatorString;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public static Operator from(int id) {
for(int i = 0; i < Operator.values().length; i++) {
Operator operator = Operator.values()[i];
if(operator.id == id)
return Operator.values()[i];
}
return UNKNOWN;
}
public static Operator from(String operatorString) {
for(int i = 0; i < Operator.values().length; i++) {
Operator operator = Operator.values()[i];
if(operator.operatorString.equals(operatorString))
return Operator.values()[i];
}
return UNKNOWN;
}
}
......@@ -30,17 +30,21 @@ import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.StringBuilderPrinter;
import android.util.TypedValue;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
......@@ -49,6 +53,7 @@ import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.CatalogueApplication;
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.PostVariableFormApiListener;
import com.vsoft.uoflservicenow.api.managers.CatalogueVariableApiManager;
......@@ -56,8 +61,12 @@ import com.vsoft.uoflservicenow.api.managers.VariableChoiceApiManager;
import com.vsoft.uoflservicenow.db.models.CatalogueVariable;
import com.vsoft.uoflservicenow.db.models.CatalogueVariableSet;
import com.vsoft.uoflservicenow.db.models.Reference;
import com.vsoft.uoflservicenow.db.models.UiPolicyAction;
import com.vsoft.uoflservicenow.db.models.UiPolicyItem;
import com.vsoft.uoflservicenow.db.models.VariableChoice;
import com.vsoft.uoflservicenow.db.models.VariableViewContainer;
import com.vsoft.uoflservicenow.dialog.SelectReferenceDialog;
import com.vsoft.uoflservicenow.enums.Operator;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.enums.ViewType;
import com.vsoft.uoflservicenow.listeners.ReferenceListener;
......@@ -65,7 +74,7 @@ import com.vsoft.uoflservicenow.ui.supportviews.DateAndTimePickerFragment;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.TagObject;
import com.vsoft.uoflservicenow.utils.PartialCondition;
import com.vsoft.uoflservicenow.utils.Util;
import org.json.JSONArray;
......@@ -80,7 +89,9 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Stack;
import butterknife.BindView;
import butterknife.ButterKnife;
......@@ -88,6 +99,11 @@ import butterknife.OnClick;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import static com.google.android.gms.analytics.internal.zzy.C;
import static com.google.android.gms.analytics.internal.zzy.c;
import static com.google.android.gms.analytics.internal.zzy.n;
import static com.google.android.gms.analytics.internal.zzy.s;
/**
* Created by Kunj on 11/8/16.
*/
......@@ -100,11 +116,13 @@ public class CatalogueVariableScreen extends AppCompatActivity {
@BindView(R.id.variable_screen_bottom_layout) RelativeLayout mBottomLayout;
private List<CatalogueVariable> mCatalogueVariableList = new ArrayList<>();
private JSONArray mJsonArray;
private List<UiPolicyItem> mUiPolicyItemList;
private CatalogueApplication mApplication;
private String mCatalogueItemSysId, mCatalogueItemDescription, mCatalogueItemShortDescription, mCatalogueItemTitle;
private File mAttachmentFile;
private Uri mAttachmentUri;
private HashMap<CatalogueVariable, VariableViewContainer> mVariableViewMap;
private HashMap<String, ArrayList<CatalogueVariable>> mContainerViewMap;
private static final int WRITE_EXTERNAL_STORAGE = 1;
private static final int FILE_SELECT_CODE = 0;
......@@ -166,12 +184,11 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
@Override
protected SyncStatus doInBackground(String... params) {
protected SyncStatus doInBackground(final String... params) {
syncStatus = CatalogueVariableApiManager.getCatalogueVariable(mCatalogueItemSysId, new GetCatalogueVariableApiListener() {
@Override
public void onDoneApiCall(List<CatalogueVariableSet> variableSetList, List<CatalogueVariable> variableList) {
/*For variableset */
/*For variableset */
for (int i = 0; i <variableSetList.size(); i++) {
CatalogueVariableSet catalogueVariableSet = variableSetList.get(i);
setVariableChoiceData(catalogueVariableSet.getVariables());
......@@ -179,7 +196,43 @@ public class CatalogueVariableScreen extends AppCompatActivity {
/*For variable list*/
setVariableChoiceData(variableList);
syncStatus = CatalogueVariableApiManager.getUiPolicy(mCatalogueItemSysId, new GetUiPolicyApiListener() {
@Override
public void onDoneApiCall(List<UiPolicyItem> uiPolicyItemList) {
mUiPolicyItemList = uiPolicyItemList;
for (int i = 0; i < mUiPolicyItemList.size(); i++) {
UiPolicyItem uiPolicyItem = mUiPolicyItemList.get(i);
String condition = uiPolicyItem.getCondition();
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++) {
PartialCondition partialCondition = new PartialCondition();
String value = splitStrings[j].replace("IO:", "");
String sysId = value.substring(0, 32);
String operatorAndValue = value.substring(32);
partialCondition.setViewSysId(sysId);
if (!operatorAndValue.contains("=")) {
partialCondition.setOperator(Operator.from(operatorAndValue));
} else {
String[] strings = operatorAndValue.split("=");
partialCondition.setOperator(Operator.EQUAL);
/*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);
}
}
}
});
}
});
return syncStatus;
......@@ -194,6 +247,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
if(syncStatus == SyncStatus.SUCCESS) {
if (mCatalogueVariableList != null) {
createView();
runUIPolicyActions(null);
}
} else {
showFetchVariableErrorDialog(R.string.failed_to_fetch_catalogue_form_string);
......@@ -211,7 +265,6 @@ public class CatalogueVariableScreen extends AppCompatActivity {
VariableChoiceApiManager.getVariableChoice(catalogueVariable.getSysId(), new GetVariableChoiceApiListener() {
@Override
public void onDoneApiCall(List<VariableChoice> variableChoiceList) {
CatalogueLog.e("Data: variableChoiceList: " + variableChoiceList);
/*Sort List of CatalogueOrder*/
Collections.sort(variableChoiceList, new Comparator<VariableChoice>() {
@Override
......@@ -239,6 +292,9 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
private void getCustomLayout() {
mVariableViewMap = new HashMap<>(mCatalogueVariableList.size());
Stack<LinearLayout> stack = null;
/*Child view of scroll view*/
LinearLayout.LayoutParams childControlViewLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
......@@ -283,6 +339,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
if(!mCatalogueVariableList.isEmpty()) {
VariableViewContainer container;
for (int i = 0; i < mCatalogueVariableList.size(); i++) {
CatalogueVariable catalogueVariable = mCatalogueVariableList.get(i);
/*If API return active false for a variable, there is no need show that variable*/
......@@ -299,35 +356,22 @@ public class CatalogueVariableScreen extends AppCompatActivity {
(int) getResources().getDimension(R.dimen.small_margin),
(int) getResources().getDimension(R.dimen.small_margin));
mContainerLayout.addView(nameNullView, childLabelViewLayoutParams);
} else if (viewType != ViewType.MACRO && viewType != ViewType.CONTAINER_START && viewType != ViewType.CONTAINER_END && viewType != ViewType.CONTAINER_SPLIT) {
/*For MACRO, CONTAINER_START, CONTAINER_END and CONTAINER_SPLIT, there is no need to render any view*/
if (viewType != ViewType.LABEL && viewType != ViewType.CHECK_BOX && viewType != ViewType.BREAK) {
/*Create label for every type*/
if (!catalogueVariable.isMandatory()) {
TextView label = new TextView(CatalogueVariableScreen.this);
label.setText(catalogueVariable.getQuestionText());
childLabelViewLayoutParams.topMargin = (int) getResources().getDimension(R.dimen.small_margin);
mContainerLayout.addView(label, childLabelViewLayoutParams);
} else {
/*Create labelWithMandatory with mandatory value*/
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(catalogueVariable.getQuestionText());
stringBuilder.append(getString(R.string.variable_form_view_mandatory_sign_string));
TextView labelWithMandatory = new TextView(CatalogueVariableScreen.this);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
labelWithMandatory.setText(Html.fromHtml(stringBuilder.toString(), Html.FROM_HTML_MODE_LEGACY));
} else {
labelWithMandatory.setText(Html.fromHtml(stringBuilder.toString()));
}
mContainerLayout.addView(labelWithMandatory, childLabelViewLayoutParams);
} else if(viewType == ViewType.CONTAINER_END) {
/*In Container End, we need to add view for rendering*/
LinearLayout containerLinearLayout;
if(stack!=null && !stack.isEmpty()) {
containerLinearLayout = stack.pop();
if (containerLinearLayout != null) {
mContainerLayout.addView(containerLinearLayout);
}
}
} else if (viewType != ViewType.MACRO && viewType != ViewType.CONTAINER_SPLIT) {
container = Util.getVariableViewContainer(CatalogueVariableScreen.this,
catalogueVariable, childLabelViewLayoutParams);
mVariableViewMap.put(catalogueVariable, container);
View controlView = Util.getView(CatalogueVariableScreen.this, viewType, catalogueVariable);
View controlView = container.getInputView();
if (controlView != null) {
controlView.setTag(new TagObject(i, null));
if (viewType == ViewType.DATE) {
controlView.setOnClickListener(dateListener);
} else if (viewType == ViewType.DATE_AND_TIME) {
......@@ -337,21 +381,45 @@ public class CatalogueVariableScreen extends AppCompatActivity {
} else if (viewType == ViewType.UI_PAGE) {
((LinearLayout)controlView).getChildAt(0).setOnClickListener(attachmentListener);
mAttachmentTextView = (TextView)((LinearLayout)controlView).getChildAt(1);
} else if (viewType == ViewType.CHECK_BOX) {
((CheckBox)controlView).setOnCheckedChangeListener(checkedChangeListener);
// if this checkbox is a trigger of UI action, set a listener for change, and send a broadcast event
} else if (viewType == ViewType.MULTIPLE_CHOICE) {
((RadioGroup)controlView).setOnCheckedChangeListener(radioGroupCheckedChangeListener);
// if this checkbox is a trigger of UI action, set a listener for change, and send a broadcast event
} else if (viewType == ViewType.SELECT_BOX) {
((Spinner)controlView).setOnItemSelectedListener(spinnerItemSelectedListener);
// if this checkbox is a trigger of UI action, set a listener for change, and send a broadcast event
}
/*Set bottom margin for custom view*/
if (viewType != ViewType.BREAK) {
mContainerLayout.addView(controlView, childControlViewLayoutParams);
} else
mContainerLayout.addView(controlView);
/*Mandatory variable contain error view*/
if (catalogueVariable.isMandatory()) {
/*Add error view for validation*/
View errorView = getErrorView();
errorView.setTag("error_" + i);
mContainerLayout.addView(errorView);
LinearLayout containerLinearLayout = null;
if(stack!=null && !stack.isEmpty()) {
containerLinearLayout = stack.peek();
}
if(containerLinearLayout!=null) {
/*That mean, we need to add only in container view*/
if (container.getContainerView() != null)
containerLinearLayout.addView(container.getContainerView());
else
containerLinearLayout.addView(container.getInputView());
} else if (viewType != ViewType.BREAK) { /*Set bottom margin for custom view*/
if(container.getContainerView()!=null)
mContainerLayout.addView(container.getContainerView(), childControlViewLayoutParams);
else
mContainerLayout.addView(container.getInputView(), childControlViewLayoutParams);
} else {
if (container.getContainerView() != null)
mContainerLayout.addView(container.getContainerView());
else
mContainerLayout.addView(container.getInputView());
}
} else if(viewType == ViewType.CONTAINER_START) {
/*For Container start, we need to create a layout, it contain all views until we reach Container End*/
LinearLayout containerLinearLayout = (LinearLayout) container.getContainerView();
if(stack == null)
stack = new Stack();
stack.push(containerLinearLayout);
} else {
TextView viewNotImplemented = new TextView(CatalogueVariableScreen.this);
viewNotImplemented.setText(String.format(getString(R.string.view_not_implemented_string), viewType.getDisplayString()));
......@@ -362,15 +430,21 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
}
}
}
}
private View getErrorView() {
TextView textView = new TextView(CatalogueVariableScreen.this);
textView.setTextColor(ContextCompat.getColor(CatalogueVariableScreen.this, R.color.error_color));
textView.setText(R.string.error_string);
textView.setVisibility(View.GONE);
return textView;
/*This condition is use for where u do not have Container End at the end of loop, then we need to render*/
if(stack != null) {
while (!stack.isEmpty()) {
LinearLayout popLinearLayout = stack.pop();
if(!stack.isEmpty()) {
LinearLayout peekLinearLayout = stack.peek();
peekLinearLayout.addView(popLinearLayout);
} else {
if(popLinearLayout != null)
mContainerLayout.addView(popLinearLayout);
}
}
}
}
}
@OnClick(R.id.variable_screen_submit_text_view)
......@@ -385,36 +459,48 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
private void saveFormData() {
/*For Local DB column and value*/
List<String> columnList = new ArrayList<>(mCatalogueVariableList.size());
List<String> valueList = new ArrayList<>(mCatalogueVariableList.size());
mJsonArray = new JSONArray();
TagObject tempTagObj = new TagObject(0, null);
JSONArray jsonArray;
JSONObject jsonObject = null;
boolean hasErrors = false;
boolean skipInvisibleItem = false;
for (int i = 0; i < mCatalogueVariableList.size(); i++) {
tempTagObj.setIndex(i);
CatalogueVariable catalogueVariable = mCatalogueVariableList.get(i);
ViewType viewType = catalogueVariable.getType();
if(viewType != ViewType.LABEL && viewType != ViewType.BREAK) {
VariableViewContainer container = mVariableViewMap.get(catalogueVariable);
if(catalogueVariable.getType() == ViewType.CONTAINER_START
&& container != null
&& container.getContainerView() != null
&& container.getContainerView().getVisibility() == View.GONE) {
skipInvisibleItem = true;
}
if(skipInvisibleItem && catalogueVariable.getType() != ViewType.CONTAINER_END) {
continue;
}
View view = mContainerLayout.findViewWithTag(tempTagObj);
if(catalogueVariable.getType() == ViewType.CONTAINER_END) {
skipInvisibleItem = false;
}
if(jsonObject == null) {
jsonObject = new JSONObject();
}
ViewType viewType = catalogueVariable.getType();
if (container != null && viewType != ViewType.LABEL && viewType != ViewType.BREAK) {
View view = container.getInputView();
if (view != null) {
String value = Util.getVariableViewValue(view, viewType);
View errorView = mContainerLayout.findViewWithTag("error_"+i);
View errorView = container.getErrorView();
columnList.add(catalogueVariable.getName());
JSONObject jsonObject = new JSONObject();
String jsonColumnValue = value;
/*Convert date and time long value to string for server communication*/
if(viewType == ViewType.DATE) {
if (viewType == ViewType.DATE) {
jsonColumnValue = Util.getDateFromLong(Util.getDateFromString(value));
} else if(viewType == ViewType.DATE_AND_TIME) {
} else if (viewType == ViewType.DATE_AND_TIME) {
jsonColumnValue = Util.getDateTime(Util.getDateTimeFromString(value));
}
if(catalogueVariable.isMandatory()) {
if (catalogueVariable.isMandatory()) {
if (viewType != ViewType.SELECT_BOX && viewType != ViewType.UI_PAGE) {
if (TextUtils.isEmpty(jsonColumnValue)) {
hasErrors = true;
......@@ -439,14 +525,11 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
}
}
try {
jsonObject.put(catalogueVariable.getName(), jsonColumnValue);
} catch (JSONException e) {
e.printStackTrace();
}
mJsonArray.put(jsonObject);
valueList.add(value);
}
}
}
......@@ -455,7 +538,9 @@ public class CatalogueVariableScreen extends AppCompatActivity {
return;
if(mApplication.isNetConnected()) {
new SubmitForm().execute();
jsonArray = new JSONArray();
jsonArray.put(jsonObject);
new SubmitForm().execute(jsonArray.toString());
} else {
DialogUtils.showNoConnectionDialogWithCloseActivity(CatalogueVariableScreen.this);
}
......@@ -520,8 +605,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
@Override
public void positiveButtonClick(Reference reference) {
editText.setText(reference.getName());
TagObject tagObject = (TagObject)v.getTag();
tagObject.setTagObject(reference);
v.setTag(reference);
}
@Override
......@@ -530,8 +614,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
};
FragmentManager fm = getSupportFragmentManager();
TagObject tagObject = (TagObject)v.getTag();
CatalogueVariable catalogueVariable = mCatalogueVariableList.get(tagObject.getIndex());
CatalogueVariable catalogueVariable = getVariableForView(v);
String tableName = catalogueVariable.getReferenceTable();
String columnName = catalogueVariable.getReferenceColumnName();
String title = catalogueVariable.getQuestionText();
......@@ -558,6 +641,35 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
};
CompoundButton.OnCheckedChangeListener checkedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
CatalogueVariable catalogueVariable = getVariableForView(compoundButton);
runUIPolicyActions(catalogueVariable.getSysId());
}
};
RadioGroup.OnCheckedChangeListener radioGroupCheckedChangeListener = new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
CatalogueVariable catalogueVariable = getVariableForView(radioGroup);
runUIPolicyActions(catalogueVariable.getSysId());
}
};
AdapterView.OnItemSelectedListener spinnerItemSelectedListener = new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
CatalogueVariable catalogueVariable = getVariableForView(adapterView);
runUIPolicyActions(catalogueVariable.getSysId());
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
};
class SubmitForm extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
......@@ -572,7 +684,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
@Override
protected SyncStatus doInBackground(String... params) {
return CatalogueVariableApiManager.submitVariableForm(mCatalogueItemSysId, mJsonArray, new PostVariableFormApiListener() {
return CatalogueVariableApiManager.submitVariableForm(mCatalogueItemSysId, params[0], new PostVariableFormApiListener() {
@Override
public void onDoneApiCall(String variableFromSysId) {
if(mAttachmentFile !=null) {
......@@ -904,4 +1016,167 @@ public class CatalogueVariableScreen extends AppCompatActivity {
AlertDialog alert = builder.create();
alert.show();
}
private void runUIPolicyActions(String sysId) {
for(int i=0; i<mUiPolicyItemList.size(); i++) {
UiPolicyItem item = mUiPolicyItemList.get(i);
/*UIPolicy condition is null then skip iterator*/
if(item.getPartialConditions()==null)
continue;
boolean needToExecuteUIPolicy = false;
if(sysId != null) {
for (int j = 0; j < item.getPartialConditions().size(); j++) {
if (item.getPartialConditions().get(j).getViewSysId().equals(sysId)) {
needToExecuteUIPolicy = true;
break;
}
}
if (!needToExecuteUIPolicy)
continue;
}
boolean conditionsSatisfied = true;
for(int j=0; j<item.getPartialConditions().size(); j++) {
PartialCondition condition = item.getPartialConditions().get(j);
CatalogueVariable variable = getVariableForSysId(condition.getViewSysId());
VariableViewContainer variableViewContainer = mVariableViewMap.get(variable);
if(variableViewContainer == null || variableViewContainer.getInputView() == null) {
continue;
}
String value = Util.getVariableViewValueForUIPolicy(variableViewContainer.getInputView(), variable);
switch(condition.getOperator()) {
case EQUAL:
conditionsSatisfied = conditionsSatisfied && value.equals(condition.getOperatorValue());
break;
case IS_NOT_EMPTY:
conditionsSatisfied = conditionsSatisfied && !TextUtils.isEmpty(value);
break;
}
}
if(conditionsSatisfied) {
for(int j=0; j<item.getUiPolicyActions().size(); j++) {
UiPolicyAction action = item.getUiPolicyActions().get(j);
CatalogueVariable variable = getVariableForName(action.getVariableName());
VariableViewContainer container = mVariableViewMap.get(variable);
if(container!=null) {
if (action.getMandatory().equals(Boolean.toString(true))) {
variable.setMandatory(true);
/*For first time, by default there is no error view
*but after call UIPolicy api we need to create an error view and set it to container.*/
if(container.getErrorView()==null) {
TextView errorView = Util.getErrorView(CatalogueVariableScreen.this);
container.setErrorView(errorView);
container.getContainerView().addView(errorView);
}
setMandatoryView(container, variable.getQuestionText(), true);
} else if (action.getMandatory().equals(Boolean.toString(false))) {
variable.setMandatory(false);
setMandatoryView(container, variable.getQuestionText(), false);
}
if (action.getVisible().equals(Boolean.toString(true))) {
container.getContainerView().setVisibility(View.VISIBLE);
runUIPolicyActions(variable.getSysId());
} else if (action.getVisible().equals(Boolean.toString(false))) {
container.getContainerView().setVisibility(View.GONE);
}
if (action.getDisabled().equals(Boolean.toString(true))) {
container.getContainerView().setEnabled(true);
} else if (action.getDisabled().equals(Boolean.toString(false))) {
container.getContainerView().setEnabled(false);
}
}
}
} else {
for(int j=0; j<item.getUiPolicyActions().size(); j++) {
UiPolicyAction action = item.getUiPolicyActions().get(j);
CatalogueVariable variable = getVariableForName(action.getVariableName());
VariableViewContainer container = mVariableViewMap.get(variable);
if(container!=null) {
if (action.getMandatory().equals(Boolean.toString(true))) {
variable.setMandatory(false);
setMandatoryView(container, variable.getQuestionText(), false);
} else if (action.getMandatory().equals(Boolean.toString(false))) {
/*For first time, by default there is no error view
*but after call UIPolicy api we need to create an error view and set it to container.*/
if(container.getErrorView()==null) {
TextView errorView = Util.getErrorView(CatalogueVariableScreen.this);
container.setErrorView(errorView);
container.getContainerView().addView(errorView);
}
variable.setMandatory(true);
setMandatoryView(container, variable.getQuestionText(), true);
}
if (action.getVisible().equals(Boolean.toString(true))) {
container.getContainerView().setVisibility(View.GONE);
} else if (action.getVisible().equals(Boolean.toString(false))) {
container.getContainerView().setVisibility(View.VISIBLE);
runUIPolicyActions(variable.getSysId());
}
if (action.getDisabled().equals(Boolean.toString(true))) {
container.getContainerView().setEnabled(false);
} else if (action.getDisabled().equals(Boolean.toString(false))) {
container.getContainerView().setEnabled(true);
}
}
}
}
}
}
private CatalogueVariable getVariableForSysId(String sysId) {
for(int i=0; i<mCatalogueVariableList.size(); i++) {
if(mCatalogueVariableList.get(i).getSysId().equals(sysId))
return mCatalogueVariableList.get(i);
}
return null;
}
private CatalogueVariable getVariableForName(String name) {
for(int i=0; i<mCatalogueVariableList.size(); i++) {
if(mCatalogueVariableList.get(i).getName().equals(name))
return mCatalogueVariableList.get(i);
}
return null;
}
private CatalogueVariable getVariableForView(View view) {
for(int i=0; i<mCatalogueVariableList.size(); i++) {
VariableViewContainer container = mVariableViewMap.get(mCatalogueVariableList.get(i));
if(container == null) {
continue;
}
if(container.getInputView() != null) {
if (container.getInputView() == view)
return mCatalogueVariableList.get(i);
} else if(container.getContainerView() != null) {
if (container.getContainerView() == view)
return mCatalogueVariableList.get(i);
}
}
return null;
}
private void setMandatoryView(VariableViewContainer container, String displayString, boolean isMandatory) {
TextView label = (TextView) container.getLabelView();
if(label!=null) {
if (!isMandatory) {
label.setText(displayString);
} else {
/*Create label with mandatory value*/
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(displayString);
stringBuilder.append(getString(R.string.variable_form_view_mandatory_sign_string));
label = (TextView) container.getLabelView();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
label.setText(Html.fromHtml(stringBuilder.toString(), Html.FROM_HTML_MODE_LEGACY));
} else {
label.setText(Html.fromHtml(stringBuilder.toString()));
}
}
}
}
}
\ No newline at end of file
package com.vsoft.uoflservicenow.utils;
import com.vsoft.uoflservicenow.db.models.UiPolicyAction;
/**
* Created by kunj on 6/10/16.
*/
public class ActionCondition {
private int[] childViewTagIndex;
private UiPolicyAction uiPolicyAction;
private String operatorValue;
public int[] getChildViewTagIndex() {
return childViewTagIndex;
}
public void setChildViewTagIndex(int[] childViewTagIndex) {
this.childViewTagIndex = childViewTagIndex;
}
public UiPolicyAction getUiPolicyAction() {
return uiPolicyAction;
}
public void setUiPolicyAction(UiPolicyAction uiPolicyAction) {
this.uiPolicyAction = uiPolicyAction;
}
public String getOperatorValue() {
return operatorValue;
}
public void setOperatorValue(String operatorValue) {
this.operatorValue = operatorValue;
}
}
......@@ -117,6 +117,7 @@ public class Constants {
public static final String RESPONSE_VARIABLE_SET_OBJECT_NAME = "variablesets";
public static final String RESPONSE_VARIABLES_OBJECT_NAME = "variables";
public static final String RESPONSE_CATEGORY_OBJECT_NAME = "Category";
public static final String RESPONSE_VARIABLES_UI_POLICY_ACTIONS = "ui_policy_actions";
/**
* Catalogue web services urls
......@@ -133,6 +134,7 @@ public class Constants {
/*Variable form API */
public static final String URL_GET_VARIABLE = "/api/uno33/uofl_mobile/variables";
public static final String URL_GET_UI_POLICY = "/api/uno33/uofl_mobile/uipolicy";
public static final String URL_GET_VARIABLE_CHOICE = API_PATH + "question_choice";
public static final String URL_POST_CATALOGUE_ITEM = "api/uno33/uofl_mobile";
public static final String URL_GET_REFERENCE = API_PATH;
......
package com.vsoft.uoflservicenow.utils;
import com.vsoft.uoflservicenow.enums.Operator;
/**
* Created by kunj on 6/10/16.
*/
public class PartialCondition {
private String viewSysId;
private Operator operator;
private String operatorValue;
public String getOperatorValue() {
return operatorValue;
}
public void setOperatorValue(String operatorValue) {
this.operatorValue = operatorValue;
}
public String getViewSysId() {
return viewSysId;
}
public void setViewSysId(String viewSysId) {
this.viewSysId = viewSysId;
}
public Operator getOperator() {
return operator;
}
public void setOperator(Operator operator) {
this.operator = operator;
}
@Override
public String toString() {
return "PartialCondition{" +
"viewSysId='" + viewSysId + '\'' +
", operator=" + operator +
", operatorValue='" + operatorValue + '\'' +
'}';
}
}
......@@ -3,6 +3,7 @@ package com.vsoft.uoflservicenow.utils;
import android.content.Context;
import android.graphics.Typeface;
import android.support.v4.content.ContextCompat;
import android.text.Html;
import android.text.InputType;
import android.text.TextUtils;
import android.text.method.PasswordTransformationMethod;
......@@ -26,6 +27,7 @@ import com.vsoft.uoflservicenow.R;
import com.vsoft.uoflservicenow.db.models.CatalogueVariable;
import com.vsoft.uoflservicenow.db.models.Reference;
import com.vsoft.uoflservicenow.db.models.VariableChoice;
import com.vsoft.uoflservicenow.db.models.VariableViewContainer;
import com.vsoft.uoflservicenow.enums.ViewType;
import java.text.ParseException;
......@@ -33,11 +35,60 @@ import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import static com.vsoft.uoflservicenow.enums.ViewType.BREAK;
import static com.vsoft.uoflservicenow.enums.ViewType.CHECK_BOX;
/**
* Created by Kunj on 12/8/16.
*/
public class Util {
public static View getView(Context context, ViewType viewType, CatalogueVariable catalogueVariable) {
private static TextView getLabelView(Context context, CatalogueVariable catalogueVariable, LinearLayout.LayoutParams childLabelViewLayoutParams) {
ViewType viewType = catalogueVariable.getType();
if (catalogueVariable.getQuestionText() != null && viewType != ViewType.MACRO /*&& viewType != ViewType.CONTAINER_START*/
&& viewType != ViewType.CONTAINER_END && viewType != ViewType.CONTAINER_SPLIT
&& viewType != ViewType.LABEL && viewType != CHECK_BOX && viewType != BREAK) {
/*For MACRO, CONTAINER_START, CONTAINER_END and CONTAINER_SPLIT, there is no need to render any view*/
/*Create label for every type*/
if (!catalogueVariable.isMandatory()) {
TextView label = new TextView(context);
label.setText(catalogueVariable.getQuestionText());
childLabelViewLayoutParams.topMargin = (int) context.getResources().getDimension(R.dimen.small_margin);
return label;
} else {
/*Create label with mandatory value*/
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(catalogueVariable.getQuestionText());
stringBuilder.append(context.getString(R.string.variable_form_view_mandatory_sign_string));
TextView label = new TextView(context);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
label.setText(Html.fromHtml(stringBuilder.toString(), Html.FROM_HTML_MODE_LEGACY));
} else {
label.setText(Html.fromHtml(stringBuilder.toString()));
}
return label;
}
} else {
return null;
}
}
public static VariableViewContainer getVariableViewContainer(Context context, CatalogueVariable catalogueVariable, LinearLayout.LayoutParams childLabelViewLayoutParams) {
VariableViewContainer container = new VariableViewContainer();
/*Label View*/
TextView label = getLabelView(context, catalogueVariable, childLabelViewLayoutParams);
container.setLabelView(label);
/*Error View*/
TextView errorView = null;
if (catalogueVariable.isMandatory()) {
errorView = getErrorView(context);
}
container.setErrorView(errorView);
ViewType viewType = catalogueVariable.getType();
LinearLayout linearLayout;
switch (viewType) {
case YES_NO:
Spinner spinner = new Spinner(context);
......@@ -48,7 +99,19 @@ public class Util {
context.getResources().getString(R.string.no_string)});
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spinnerArrayAdapter);
return spinner;
container.setInputView(spinner);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(spinner);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case MULTI_LINE_TEXT:
EditText multiLineEditText = new EditText(context);
multiLineEditText.setSingleLine(false);
......@@ -57,7 +120,19 @@ public class Util {
multiLineEditText.setLines(3);
multiLineEditText.setVerticalScrollBarEnabled(true);
multiLineEditText.setGravity(Gravity.START);
return multiLineEditText;
container.setInputView(multiLineEditText);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(multiLineEditText);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case HTML:
EditText htmlEditText = new EditText(context);
htmlEditText.setSingleLine(false);
......@@ -66,45 +141,119 @@ public class Util {
htmlEditText.setLines(3);
htmlEditText.setVerticalScrollBarEnabled(true);
htmlEditText.setGravity(Gravity.START);
return htmlEditText;
container.setInputView(htmlEditText);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(htmlEditText);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case NUMERIC_SCALE:
LinearLayout linearLayout = new LinearLayout(context);
LinearLayout numericScaleLayout = new LinearLayout(context);
numericScaleLayout.setOrientation(LinearLayout.VERTICAL);
RadioButton[] radioButtons = new RadioButton[5];
RadioGroup rg = new RadioGroup(context); //create the RadioGroup
rg.setOrientation(RadioGroup.HORIZONTAL);//or RadioGroup.VERTICAL
for(int i = 0; i < 5; i++){
radioButtons[i] = new RadioButton(context);
radioButtons[i].setText(String.format(context.getString(R.string.variable_form_radio_text_string), (i+1)));
rg.addView(radioButtons[i]);
}
linearLayout.addView(rg);
return linearLayout;
container.setInputView(rg);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(numericScaleLayout);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case CHECK_BOX:
CheckBox checkBox = new CheckBox(context);
checkBox.setText(catalogueVariable.getQuestionText());
return checkBox;
container.setInputView(checkBox);
break;
case SINGLE_LINE_TEXT:
EditText singleLineEditText = new EditText(context);
singleLineEditText.setSingleLine(true);
singleLineEditText.setLines(1);
singleLineEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
return singleLineEditText;
container.setInputView(singleLineEditText);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(singleLineEditText);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case WIDE_SINGLE_LINE_TEXT:
EditText wideSingleLineEditText = new EditText(context);
wideSingleLineEditText.setSingleLine(true);
wideSingleLineEditText.setLines(1);
wideSingleLineEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
return wideSingleLineEditText;
container.setInputView(wideSingleLineEditText);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(wideSingleLineEditText);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case DATE:
Button dateTextButton = new Button(context);
dateTextButton.setText(getDefaultDate());
dateTextButton.setGravity(Gravity.CENTER_VERTICAL);
return dateTextButton;
container.setInputView(dateTextButton);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(dateTextButton);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case DATE_AND_TIME:
Button dateTimeButton = new Button(context);
dateTimeButton.setText(getDefaultDateTime()/* + " " + getDefaultTime()*/);
dateTimeButton.setGravity(Gravity.CENTER_VERTICAL);
return dateTimeButton;
container.setInputView(dateTimeButton);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(dateTimeButton);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case REFERENCE:
EditText referenceEditText = new EditText(context);
referenceEditText.setLines(1);
......@@ -114,7 +263,19 @@ public class Util {
referenceEditText.setFocusableInTouchMode(false);
referenceEditText.setClickable(false);
referenceEditText.setCompoundDrawablesWithIntrinsicBounds(0, 0, android.R.drawable.ic_menu_search, 0);
return referenceEditText;
container.setInputView(referenceEditText);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(referenceEditText);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case LABEL:
LinearLayout labelLayout = new LinearLayout(context);
labelLayout.setOrientation(LinearLayout.VERTICAL);
......@@ -123,6 +284,7 @@ public class Util {
labelTextView.setText(catalogueVariable.getQuestionText());
labelTextView.setTypeface(null, Typeface.BOLD);
labelLayout.addView(labelTextView);
container.setInputView(labelTextView);
View view = new View(context);
view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1));
......@@ -130,7 +292,8 @@ public class Util {
labelLayout.addView(view);
labelLayout.setPadding(0, 0, 0, (int)context.getResources().getDimension(R.dimen.small_margin));
return labelLayout;
container.setContainerView(labelLayout);
break;
case MASKED:
EditText maskedEditText = new EditText(context);
maskedEditText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
......@@ -138,7 +301,19 @@ public class Util {
maskedEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
maskedEditText.setSingleLine(true);
maskedEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
return maskedEditText;
container.setInputView(maskedEditText);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(maskedEditText);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case MULTIPLE_CHOICE:
LinearLayout multiChoiceLinearLayout = new LinearLayout(context);
multiChoiceLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
......@@ -161,7 +336,19 @@ public class Util {
radioGroup.addView(multiChoiceRadioButtons[i]);
}
multiChoiceLinearLayout.addView(radioGroup);
return multiChoiceLinearLayout;
container.setInputView(radioGroup);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(multiChoiceLinearLayout);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case SELECT_BOX:
Spinner selectBoxSpinner = new Spinner(context);
selectBoxSpinner.setPadding(0, (int) context.getResources().getDimension(R.dimen.normal_margin),
......@@ -170,12 +357,25 @@ public class Util {
new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, catalogueVariable.getDisplayChoiceText(context, catalogueVariable.isNoneRequired()));
selectBoxSpinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
selectBoxSpinner.setAdapter(selectBoxSpinnerArrayAdapter);
return selectBoxSpinner;
container.setInputView(selectBoxSpinner);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(selectBoxSpinner);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case BREAK:
View breakView = new View(context);
breakView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1));
breakView.setBackgroundColor(ContextCompat.getColor(context, android.R.color.black));
return breakView;
container.setInputView(breakView);
break;
case UI_PAGE:
LinearLayout uiPageLayout = new LinearLayout(context);
uiPageLayout.setOrientation(LinearLayout.HORIZONTAL);
......@@ -195,10 +395,36 @@ public class Util {
attachmentTextView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
attachmentTextView.setText(R.string.variable_form_ui_page_no_selected_attachment_string);
uiPageLayout.addView(attachmentTextView, layoutParams);
container.setInputView(uiPageLayout);
return uiPageLayout;
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(uiPageLayout);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case CONTAINER_START:
LinearLayout containerLinearLayout = new LinearLayout(context);
containerLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(containerLinearLayout);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
}
return null;
return container;
}
public static String getVariableViewValue(View view, ViewType viewType) {
......@@ -224,7 +450,7 @@ public class Util {
}
case CHECK_BOX:
CheckBox checkBox = (CheckBox) view;
return checkBox.isChecked() ? "1" : "0";
return checkBox.isChecked() ? "true" : "false";
case SINGLE_LINE_TEXT:
EditText singleLineEditText = (EditText) view;
return singleLineEditText.getText().toString();
......@@ -238,8 +464,7 @@ public class Util {
Button dateTimeButton = (Button) view;
return dateTimeButton.getText().toString();
case REFERENCE:
TagObject tagObject = (TagObject) view.getTag();
Reference reference = (Reference)tagObject.getTagObject();
Reference reference = (Reference)view.getTag();
if(reference!=null) {
return reference.getSysId();
} else {
......@@ -249,15 +474,12 @@ public class Util {
EditText maskedEditText = (EditText) view;
return maskedEditText.getText().toString();
case MULTIPLE_CHOICE:
LinearLayout multipleChoiceLinearLayout = (LinearLayout) view;
for(int i = 0; i < multipleChoiceLinearLayout.getChildCount(); i++) {
RadioGroup radioGroup = (RadioGroup) multipleChoiceLinearLayout.getChildAt(i);
int radioButtonID = radioGroup.getCheckedRadioButtonId();
RadioButton radioButton = (RadioButton)radioGroup.findViewById(radioButtonID);
RadioGroup multipleChoiceRadioGroup = (RadioGroup) view;
int radioButtonID = multipleChoiceRadioGroup.getCheckedRadioButtonId();
RadioButton radioButton = (RadioButton)multipleChoiceRadioGroup.findViewById(radioButtonID);
if(radioButton != null) {
return radioButton.getTag().toString();
}
}
return "";
case SELECT_BOX:
Spinner selectBoxSpinner = (Spinner) view;
......@@ -267,6 +489,25 @@ public class Util {
}
}
public static String getVariableViewValueForUIPolicy(View view, CatalogueVariable catalogueVariable) {
switch (catalogueVariable.getType()) {
case SELECT_BOX:
Spinner selectBoxSpinner = (Spinner) view;
String value = catalogueVariable.getDisplayChoiceText(selectBoxSpinner.getSelectedItem().toString());
return value;
default:
return getVariableViewValue(view, catalogueVariable.getType());
}
}
public static TextView getErrorView(Context context) {
TextView textView = new TextView(context);
textView.setTextColor(ContextCompat.getColor(context, R.color.error_color));
textView.setText(R.string.error_string);
textView.setVisibility(View.GONE);
return textView;
}
public static String getDefaultDate() {
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("dd MMM, yyyy");
......
......@@ -50,7 +50,7 @@
<string name="password_string">Password</string>
<!--Variable Screen-->
<string name="variable_form_misc_info_string">%1$s [add %2$s]</string>
<string name="variable_form_misc_info_string">%1$s [add %2$.2f]</string>
<string name="variable_form_header_string">Submit Order</string>
<string name="variable_form_view_mandatory_sign_string">&lt;font color="#FF0000"&gt;*&lt;/font&gt;</string>
<string name="variable_form_reference_dialog_title_string">Search \'%s\'</string>
......
......@@ -73,14 +73,14 @@ if [ -n "$JAVA_HOME" ] ; then
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
Please set the JAVA_HOME variableName in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
Please set the JAVA_HOME variableName in your environment to match the
location of your Java installation."
fi
......
......@@ -26,7 +26,7 @@ if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo Please set the JAVA_HOME variableName in your environment to match the
echo location of your Java installation.
goto fail
......@@ -40,7 +40,7 @@ if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo Please set the JAVA_HOME variableName in your environment to match the
echo location of your Java installation.
goto fail
......@@ -79,7 +79,7 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem Set variableName GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
......
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