Commit 37ce0acf by Kunj Gupta

Local database configuration with existing code.

parents 3141cb84 df26a011
Showing with 4188 additions and 837 deletions
......@@ -34,7 +34,7 @@ android {
minSdkVersion 9
targetSdkVersion 24
versionCode 1
versionName "0.0.11"
versionName "0.0.20"
multiDexEnabled true
}
buildTypes {
......
......@@ -3,6 +3,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
......@@ -81,6 +82,9 @@
<activity
android:name="com.vsoft.uoflservicenow.ui.MyIncidentScreen"
android:screenOrientation="portrait"/>
<service android:name=".service.SyncService" />
<meta-data
android:name="io.fabric.ApiKey"
android:value="2b0a6e9db28d607fbcf71b8b25f1a0795e3f5b22" />
......
package com.vsoft.uoflservicenow;
import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.sqlite.SQLiteDatabase;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import com.crashlytics.android.Crashlytics;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.db.DBManager;
import com.vsoft.uoflservicenow.service.SyncService;
import com.vsoft.uoflservicenow.utils.Constants;
import io.fabric.sdk.android.Fabric;
......@@ -20,17 +27,38 @@ public class CatalogueApplication extends Application {
private static Context mContext;
private Tracker mTracker;
private BroadcastReceiver mSyncBroadCastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getStringExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION);
Log.d(Constants.TAG, "CatalogueApplication: onReceive: action: "+action);
if(Constants.ACTION_SYNC.equals(action)) {
Intent syncMatchSummaryIntentIntent = new Intent(context, SyncService.class);
if (Constants.DEBUG) Log.d(Constants.TAG, "CatalogueApplication: Start SyncService");
context.startService(syncMatchSummaryIntentIntent);
}
}
};
@Override
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics());
mContext = getApplicationContext();
LocalBroadcastManager.getInstance(this).registerReceiver(mSyncBroadCastReceiver,
new IntentFilter(Constants.APPLICATION_BROADCAST_INTENT));
/*Database is created*/
initializeDatabase();
}
@Override
public void onTerminate() {
super.onTerminate();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadCastReceiver);
}
public static Context getContext() {
return mContext;
}
......
......@@ -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;
......
......@@ -74,7 +74,7 @@ public class MyRequestAdapter extends BaseAdapter {
MyRequest req = mReqList.get(position);
holder.number.setText(req.getNumber());
holder.shortDescription.setText(req.getShortDescription());
holder.shortDescription.setText(req.getShortDescription().getDisplayValue());
if(!req.getApproval().isEmpty()) {
if (req.getApproval().equalsIgnoreCase("requested")) {
......
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(30, 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(30, TimeUnit.SECONDS);
// add your other interceptors
Interceptor interceptor = new Interceptor() {
@Override
......
......@@ -6,10 +6,12 @@ import com.vsoft.uoflservicenow.utils.Constants;
import java.util.Map;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.POST;
import retrofit2.http.Query;
import retrofit2.http.QueryMap;
......@@ -39,6 +41,18 @@ public interface CatalogueVariableApi {
// Get Reference API
@GET
Call<ResponseBody> getReference(@Url String url, @QueryMap Map<String, String> options);
// Post attachment API
@POST(Constants.URL_POST_ATTACHMENT)
Call<ResponseBody> postAttachment(@Header("Content-Type") String contentType,
@Query(Constants.URL_PARAM_TABLE_SYS_ID) String tableSysId,
@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);
}
......@@ -16,8 +16,8 @@ import retrofit2.http.Query;
public interface MyRequestApi {
// Get Catalogue API
@GET(Constants.URL_GET_MYREQUEST)
Call<ResponseBody> getMyrequest(@Query(Constants.URL_PARAM_SYSPRM_QUERY) String sysparmQuery);
Call<ResponseBody> getMyRequest(@Query(Constants.URL_PARAM_SYSPRM_QUERY) String sysparmQuery,
@Query(Constants.URL_PARAM_SYSPRM_DISPLAY_VALUE) String sysparmDisplayValue);
}
......
......@@ -11,4 +11,5 @@ import java.util.List;
*/
public interface GetCatalogueApiListener {
void onDoneApiCall(List<Catalogue> catalogueList);
void onFailApiCall();
}
......@@ -11,4 +11,5 @@ import java.util.List;
*/
public interface GetCatalogueItemApiListener {
void onDoneApiCall(List<CatalogueItem> catalogueItemList);
void onFailApiCall();
}
......@@ -11,4 +11,5 @@ import java.util.List;
*/
public interface GetCatalogueOrderApiListener {
void onDoneApiCall(List<CatalogueOrder> catalogueOrderList);
void onFailApiCall();
}
package com.vsoft.uoflservicenow.api.listeners.get;
import com.vsoft.uoflservicenow.db.models.CatalogueVariable;
import com.vsoft.uoflservicenow.db.models.CatalogueVariableSet;
import java.util.List;
......@@ -10,5 +11,6 @@ import java.util.List;
*
*/
public interface GetCatalogueVariableApiListener {
void onDoneApiCall(List<CatalogueVariable> variableList);
void onDoneApiCall(List<CatalogueVariableSet> variableSetList, List<CatalogueVariable> variableList);
void onFailApiCall();
}
......@@ -11,4 +11,5 @@ import java.util.List;
*/
public interface GetIncidentApiListener {
void onDoneApiCall(List<Incident> incidentList);
void onFailApiCall();
}
......@@ -11,4 +11,5 @@ import java.util.List;
*/
public interface GetMyRequestApiListener {
void onDoneApiCall(List<MyRequest> catalogueList);
void onFailApiCall();
}
......@@ -11,4 +11,5 @@ import java.util.List;
*/
public interface GetReferenceApiListener {
void onDoneApiCall(List<Reference> referenceList);
void onFailApiCall();
}
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);
void onFailApiCall();
}
......@@ -9,6 +9,7 @@ import java.util.List;
* @author Kunj on 11/8/16
*
*/
public interface GetUserApiListener {
public interface GetUserDetailApiListener {
void onDoneApiCall(List<UserApiValues> userValues);
void onFailApiCall();
}
package com.vsoft.uoflservicenow.api.listeners.get;
/**
* @since 1.0
* @author Kunj on 11/8/16
*
*/
public interface GetUserLoginApiListener {
void onDoneApiCall();
void onFailApiCall();
}
......@@ -11,4 +11,5 @@ import java.util.List;
*/
public interface GetVariableChoiceApiListener {
void onDoneApiCall(List<VariableChoice> variableChoiceList);
void onFailApiCall();
}
package com.vsoft.uoflservicenow.api.listeners.post;
/**
* @since 1.0
* @author Kunj on 11/8/16
*
*/
public interface PostAttachmentApiListener {
void onDoneApiCall();
void onFailApiCall();
}
package com.vsoft.uoflservicenow.api.listeners.post;
/**
* @since 1.0
* @author Kunj on 11/8/16
*
*/
public interface PostIncidentApiListener {
void onDoneApiCall(String incidentNumber);
void onFailApiCall();
}
package com.vsoft.uoflservicenow.api.listeners.post;
/**
* @since 1.0
* @author Kunj on 11/8/16
*
*/
public interface PostVariableFormApiListener {
void onDoneApiCall(String variableFromSysId);
void onFailApiCall();
}
......@@ -12,7 +12,6 @@ import com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueOrderApiListener;
import com.vsoft.uoflservicenow.db.models.Catalogue;
import com.vsoft.uoflservicenow.db.models.CatalogueOrder;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants;
......@@ -38,7 +37,7 @@ import retrofit2.Retrofit;
*/
public class CatalogueApiManager {
public static SyncStatus getCatalogues(GetCatalogueApiListener listener) {
public static void getCatalogues(final GetCatalogueApiListener listener) {
CatalogueLog.d("CatalogueApiManager: getCatalogues: ");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(Catalogue.Json.URL_PARAM_CATALOGUE_SYSPRM_QUERY_VALUE);
......@@ -101,8 +100,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()) {
......@@ -119,38 +118,42 @@ public class CatalogueApiManager {
}
}
}
listener.onDoneApiCall(finalCatalogueList);
}
@Override
public void onFailApiCall() {
listener.onFailApiCall();
}
});
listener.onDoneApiCall(finalCatalogueList);
} else {
listener.onDoneApiCall(new ArrayList<Catalogue>(0));
}
} else {
listener.onDoneApiCall(new ArrayList<Catalogue>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogues: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogues: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogues: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogues: NullPointerException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
public static SyncStatus getCatalogueOrder(GetCatalogueOrderApiListener listener) {
public static void getCatalogueOrder(GetCatalogueOrderApiListener listener) {
CatalogueLog.d("CatalogueApiManager: getCatalogueOrder: ");
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
......@@ -208,8 +211,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);
}
......@@ -225,25 +228,24 @@ public class CatalogueApiManager {
} else {
listener.onDoneApiCall(new ArrayList<CatalogueOrder>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogueOrder: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogueOrder: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogueOrder: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogueOrder: NullPointerException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
}
\ No newline at end of file
......@@ -10,7 +10,6 @@ import com.vsoft.uoflservicenow.api.RestClient;
import com.vsoft.uoflservicenow.api.interfaces.CatalogueCategoryItemApi;
import com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueItemApiListener;
import com.vsoft.uoflservicenow.db.models.CatalogueItem;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants;
......@@ -34,7 +33,7 @@ import retrofit2.Retrofit;
*/
public class CatalogueItemApiManager {
public static SyncStatus getCatalogueItems(String catalogueSysId, GetCatalogueItemApiListener listener) {
public static void getCatalogueItems(String catalogueSysId, GetCatalogueItemApiListener listener) {
CatalogueLog.d("CatalogueItemApiManager: getCatalogueItems: ");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(CatalogueItem.Json.URL_PARAM_CATALOGUE_SYSPRM_QUERY_VALUE);
......@@ -97,33 +96,32 @@ 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);
} else {
listener.onDoneApiCall(new ArrayList<CatalogueItem>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("CatalogueItemApiManager: getCatalogueItems: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("CatalogueItemApiManager: getCatalogueItems: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("CatalogueItemApiManager: getCatalogueItems: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueItemApiManager: getCatalogueItems: NullPointerException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
}
\ No newline at end of file
......@@ -9,9 +9,13 @@ 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.PostAttachmentApiListener;
import com.vsoft.uoflservicenow.api.listeners.post.PostVariableFormApiListener;
import com.vsoft.uoflservicenow.db.models.CatalogueVariable;
import com.vsoft.uoflservicenow.db.models.CatalogueVariableSet;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.db.models.UiPolicyAction;
import com.vsoft.uoflservicenow.db.models.UiPolicyItem;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants;
......@@ -26,6 +30,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;
......@@ -37,7 +42,7 @@ import retrofit2.Retrofit;
*/
public class CatalogueVariableApiManager {
public static SyncStatus getCatalogueVariable(String catalogueItemSysId, GetCatalogueVariableApiListener listener) {
public static void getCatalogueVariable(String catalogueItemSysId, GetCatalogueVariableApiListener listener) {
CatalogueLog.d("CatalogueVariableApiManager: getCatalogueVariable: ");
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).getVariable(catalogueItemSysId);
......@@ -91,7 +96,7 @@ public class CatalogueVariableApiManager {
})
.create();
JSONObject catalogueJsonObject = jsonArray.getJSONObject(0);
/*JSONObject catalogueJsonObject = jsonArray.getJSONObject(0);
JSONArray variableSetJsonArray = catalogueJsonObject.getJSONArray(Constants.RESPONSE_VARIABLE_SET_OBJECT_NAME);
List<CatalogueVariableSet> variableSetList = new ArrayList<>(variableSetJsonArray.length());
List<CatalogueVariable> finalVariableList = new ArrayList<>();
......@@ -142,60 +147,237 @@ public class CatalogueVariableApiManager {
}
});
/*For variableset */
*//*For variableset *//*
for (int i = 0; i < variableSetList.size(); i++) {
CatalogueVariableSet catalogueVariableSet = variableSetList.get(i);
finalVariableList.addAll(catalogueVariableSet.getVariables());
}
/*For variable list*/
*//*For variable list*//*
finalVariableList.addAll(variableList);
listener.onDoneApiCall(finalVariableList);
} else {
listener.onDoneApiCall(new ArrayList<CatalogueVariable>(0));
listener.onDoneApiCall(new ArrayList<CatalogueVariable>(0));*/
JSONObject catalogueJsonObject = jsonArray.getJSONObject(0);
JSONArray variableSetJsonArray = catalogueJsonObject.getJSONArray(Constants.RESPONSE_VARIABLE_SET_OBJECT_NAME);
List<CatalogueVariableSet> variableSetList = new ArrayList<>(variableSetJsonArray.length());
for (int i = 0; i < variableSetJsonArray.length(); i++) {
JSONObject variableSetJsonObject = variableSetJsonArray.getJSONObject(i);
CatalogueVariableSet catalogueVariableSet = gson.fromJson(variableSetJsonObject.toString(), CatalogueVariableSet.class);
JSONArray variableJsonArray = variableSetJsonObject.getJSONArray(Constants.RESPONSE_VARIABLES_OBJECT_NAME);
List<CatalogueVariable> variableList = new ArrayList<>(variableJsonArray.length());
for (int j = 0; j < variableJsonArray.length(); j++) {
JSONObject variableJsonObject = variableJsonArray.getJSONObject(j);
CatalogueVariable catalogueVariable = gson.fromJson(variableJsonObject.toString(), CatalogueVariable.class);
catalogueVariable.parseJson(variableJsonObject);
variableList.add(catalogueVariable);
}
Collections.sort(variableList, new Comparator<CatalogueVariable>() {
@Override
public int compare(CatalogueVariable lhs, CatalogueVariable rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
catalogueVariableSet.setVariables(variableList);
variableSetList.add(catalogueVariableSet);
}
Collections.sort(variableSetList, new Comparator<CatalogueVariableSet>() {
@Override
public int compare(CatalogueVariableSet lhs, CatalogueVariableSet rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
JSONArray variableJsonArray = catalogueJsonObject.getJSONArray(Constants.RESPONSE_VARIABLES_OBJECT_NAME);
List<CatalogueVariable> variableList = new ArrayList<>(variableJsonArray.length());
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
public int compare(CatalogueVariable lhs, CatalogueVariable rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
listener.onDoneApiCall(variableSetList, variableList);
} else {
listener.onDoneApiCall(new ArrayList<CatalogueVariableSet>(0), new ArrayList<CatalogueVariable>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("CatalogueVariableApiManager: getCatalogueVariable: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: getCatalogueVariable: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: getCatalogueVariable: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueVariableApiManager: getCatalogueVariable: NullPointerException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
public static void getUiPolicy(String catalogueItemSysId, GetUiPolicyApiListener listener) {
CatalogueLog.d("CatalogueVariableApiManager: getUiPolicy: ");
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).getUiPolicy(catalogueItemSysId);
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);
public static SyncStatus submitVariableForm(String catalogueItemSysId, JSONArray catalogueJsonArray) {
CatalogueLog.d("submitVariableForm: " + catalogueJsonArray);
String expenseJsonString = catalogueJsonArray.toString();
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 {
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(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, expenseJsonString);
Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).postCatalogueItem(catalogueItemSysId, catalogueJsonString);
try {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) {
return SyncStatus.SUCCESS;
try {
JSONObject jsonObject = new JSONObject(response.body().string());
JSONObject error = jsonObject.optJSONObject(Constants.RESPONSE_ERROR_OBJECT_NAME);
if (error == null) {
String resultSysId = jsonObject.getString(Constants.RESPONSE_RESULT_OBJECT_NAME);
listener.onDoneApiCall(resultSysId);
}
} catch (JSONException e) {
e.printStackTrace();
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: submitVariableForm: IOException: ", e);
return SyncStatus.FAIL;
} catch (NullPointerException e){
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueVariableApiManager: submitVariableForm: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
public static void postAttachment(String contentType, String tableSysId, String attachmentName, RequestBody requestBody, PostAttachmentApiListener listener) {
CatalogueLog.d("postAttachment: tableSysId: " + tableSysId);
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).postAttachment(contentType, tableSysId, CatalogueVariable.Json.TABLE_NAME_VALUE, attachmentName, requestBody);
try {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) {
listener.onDoneApiCall();
} else {
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: postAttachment: IOException: ", e);
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueVariableApiManager: postAttachment: IOException: ", e);
listener.onFailApiCall();
}
}
}
\ No newline at end of file
......@@ -9,8 +9,8 @@ import com.google.gson.JsonParseException;
import com.vsoft.uoflservicenow.api.RestClient;
import com.vsoft.uoflservicenow.api.interfaces.IncidentApi;
import com.vsoft.uoflservicenow.api.listeners.get.GetIncidentApiListener;
import com.vsoft.uoflservicenow.api.listeners.post.PostIncidentApiListener;
import com.vsoft.uoflservicenow.db.models.Incident;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants;
......@@ -34,7 +34,7 @@ import retrofit2.Retrofit;
*/
public class IncidentApiManager {
public static SyncStatus getIncident(GetIncidentApiListener listener) {
public static void getIncident(GetIncidentApiListener listener) {
CatalogueLog.d("IncidentApiManager: getIncident: ");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("caller_id=javascript:gs.getUserID()");
......@@ -94,56 +94,76 @@ 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);
} else {
listener.onDoneApiCall(new ArrayList<Incident>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("IncidentApiManager: getIncident: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("IncidentApiManager: getIncident: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("IncidentApiManager: getIncident: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("IncidentApiManager: getIncident: NullPointerException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
public static SyncStatus submitIncidentForm(String incidentJsonString) {
public static void submitIncidentForm(Incident incident, String userId, PostIncidentApiListener listener) {
CatalogueLog.d("submitIncidentForm: incidentJson" + incident);
Gson gson = new GsonBuilder()
.excludeFieldsWithoutExposeAnnotation()
.create();
JSONObject incidentJson = incident.toJson(gson.toJson(incident));
try {
incidentJson.put(Incident.Json.OPENED_AT, userId);
incidentJson.put(Incident.Json.CALLER_ID, userId);
} catch (JSONException e) {
CatalogueLog.e(e.toString());
}
CatalogueLog.d("submitIncidentForm: incidentJson" + incidentJsonString);
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(IncidentApi.class).submitIncident(incidentJsonString);
Call<ResponseBody> call = retrofit.create(IncidentApi.class).submitIncident(incidentJson.toString());
try {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) {
return SyncStatus.SUCCESS;
try {
JSONObject jsonObject = new JSONObject(response.body().string());
JSONObject error = jsonObject.optJSONObject(Constants.RESPONSE_ERROR_OBJECT_NAME);
if (error == null) {
JSONObject result = jsonObject.getJSONObject(Constants.RESPONSE_RESULT_OBJECT_NAME);
String incidentNumber = result.getString(Incident.Json.NUMBER);
listener.onDoneApiCall(incidentNumber);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("IncidentApiManager: submitIncidentForm: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e){
CatalogueLog.e("IncidentApiManager: submitIncidentForm: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@ package com.vsoft.uoflservicenow.api.managers;
import com.vsoft.uoflservicenow.api.RestClient;
import com.vsoft.uoflservicenow.api.interfaces.LoginApi;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.api.listeners.get.GetUserLoginApiListener;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import java.io.IOException;
......@@ -17,7 +17,7 @@ import retrofit2.Retrofit;
*/
public class LoginApiManger {
public static SyncStatus submitLoginValues(String garntType, String clientId, String clientSecret, String userName, String password) {
public static void submitLoginValues(String garntType, String clientId, String clientSecret, String userName, String password, GetUserLoginApiListener listener) {
final Retrofit retrofit = RestClient.getInitializedRestAdapterWithOutAuthorizationHeader();
Call<ResponseBody> call = retrofit.create(LoginApi.class).postLoginValues(garntType, clientId, clientSecret, userName, password);
try {
......@@ -27,20 +27,20 @@ public class LoginApiManger {
if (body != null) {
if (body.contentLength() != -1) {
return SyncStatus.SUCCESS;
listener.onDoneApiCall();
} else {
return SyncStatus.SERVICEDOWN;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("LoginApiManger: submitLoginValues: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("LoginApiManger: submitLoginValues: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
}
......@@ -36,7 +36,7 @@ public class MyRequestApiManager {
stringBuilder.append(MyRequest.Json.URL_PARAM_CATALOGUE_SYSPRM_QUERY_VALUE);
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(MyRequestApi.class).getMyrequest(stringBuilder.toString());
Call<ResponseBody> call = retrofit.create(MyRequestApi.class).getMyRequest(stringBuilder.toString(), "true");
try {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
......
......@@ -8,9 +8,8 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.vsoft.uoflservicenow.api.RestClient;
import com.vsoft.uoflservicenow.api.interfaces.UserApi;
import com.vsoft.uoflservicenow.api.listeners.get.GetUserApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetUserDetailApiListener;
import com.vsoft.uoflservicenow.db.models.UserApiValues;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants;
......@@ -32,7 +31,7 @@ import retrofit2.Retrofit;
* Created by kvemulavada on 8/31/2016.
*/
public class UserApiManager {
public static SyncStatus getUserDetailResponse(String userName, GetUserApiListener listener) {
public static void getUserDetailResponse(String userName, GetUserDetailApiListener listener) {
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(UserApi.class).getuserDetails(userName);
......@@ -88,29 +87,28 @@ 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);
} else {
listener.onDoneApiCall(new ArrayList<UserApiValues>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (JSONException e) {
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (IOException e) {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
......
......@@ -12,7 +12,6 @@ import com.vsoft.uoflservicenow.api.listeners.get.GetReferenceApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetVariableChoiceApiListener;
import com.vsoft.uoflservicenow.db.models.Reference;
import com.vsoft.uoflservicenow.db.models.VariableChoice;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants;
......@@ -37,7 +36,7 @@ import retrofit2.Retrofit;
*/
public class VariableChoiceApiManager {
public static SyncStatus getVariableChoice(String variableSysId, GetVariableChoiceApiListener listener) {
public static void getVariableChoice(String variableSysId, GetVariableChoiceApiListener listener) {
CatalogueLog.d("VariableChoiceApiManager: getVariableChoice: ");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(VariableChoice.Json.URL_PARAM_VARIABLE_CHOICE_SYSPRM_QUERY_VALUE);
......@@ -107,29 +106,28 @@ public class VariableChoiceApiManager {
} else {
listener.onDoneApiCall(new ArrayList<VariableChoice>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("VariableChoiceApiManager: getVariableChoice: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("VariableChoiceApiManager: getVariableChoice: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("VariableChoiceApiManager: getVariableChoice: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("VariableChoiceApiManager: getVariableChoice: NullPointerException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
public static SyncStatus getReference(String tableName, Map<String,String> queryMap, GetReferenceApiListener listener) {
public static void getReference(String tableName, Map<String,String> queryMap, GetReferenceApiListener listener) {
CatalogueLog.d("VariableChoiceApiManager: getReference: tableName: "+tableName);
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
......@@ -194,25 +192,24 @@ public class VariableChoiceApiManager {
} else {
listener.onDoneApiCall(new ArrayList<Reference>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("VariableChoiceApiManager: getReference: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("VariableChoiceApiManager: getReference: onResponse: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} else {
return SyncStatus.FAIL;
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("VariableChoiceApiManager: getReference: IOException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("VariableChoiceApiManager: getReference: NullPointerException: ", e);
return SyncStatus.FAIL;
listener.onFailApiCall();
}
}
}
\ No newline at end of file
......@@ -33,6 +33,11 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
createVariableChoiceTable(db);
createMyIncidentTable(db);
createMyRequestTable(db);
createUiPolicyItemTable(db);
createUiPolicyActionTable(db);
createCatalogueItemInputTable(db);
createAttachmentTable(db);
createIncidentInputTable(db);
}
@Override
......@@ -82,6 +87,8 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
+ CATALOGUE_VARIABLE_REFERENCE_TABLE + " text, "
+ CATALOGUE_VARIABLE_ORDER + " text, "
+ CATALOGUE_VARIABLE_REFERENCE_COLUMN_NAME + " text, "
+ CATALOGUE_VARIABLE_ACTIVE + " integer, "
+ CATALOGUE_VARIABLE_DEFAULT_VALUE + " text, "
+ CATALOGUE_VARIABLE_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE
+ ");");
}
......@@ -115,4 +122,52 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
+ REQUEST_APPROVAL + " text, "
+ REQUEST_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");");
}
private void createUiPolicyItemTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_UI_POLICY_ITEM + "("
+ UI_POLICY_ITEM_ID + " integer primary key autoincrement, "
+ UI_POLICY_ITEM_CATALOGUE_ITEM_ID + " integer default -1, "
+ UI_POLICY_ITEM_CONDITION + " text, "
+ UI_POLICY_ITEM_SYS_ID + " text, "
+ UI_POLICY_ITEM_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");");
}
private void createUiPolicyActionTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_UI_POLICY_ACTION + "("
+ UI_POLICY_ACTION_ID + " integer primary key autoincrement, "
+ UI_POLICY_ACTION_POLICY_ITEM_ID + " integer default -1, "
+ UI_POLICY_ACTION_VISIBLE + " text, "
+ UI_POLICY_ACTION_MANDATORY + " text, "
+ UI_POLICY_ACTION_VARIABLE + " text, "
+ UI_POLICY_ACTION_DISABLED + " text, "
+ UI_POLICY_ACTION_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");");
}
private void createCatalogueItemInputTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_CATALOGUE_ITEM_INPUT + "("
+ CATALOGUE_ITEM_INPUT_ID + " integer primary key autoincrement, "
+ CATALOGUE_ITEM_INPUT_CATALOGUE_ITEM_ID + " integer default -1, "
+ CATALOGUE_ITEM_INPUT_DATA + " text, "
+ CATALOGUE_ITEM_INPUT_SYS_ID + " text, "
+ CATALOGUE_ITEM_INPUT_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");");
}
private void createAttachmentTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_ATTACHMENT + "("
+ ATTACHMENT_ID + " integer primary key autoincrement, "
+ ATTACHMENT_ITEM_INPUT_ID + " integer default -1, "
+ ATTACHMENT_PATH + " text, "
+ ATTACHMENT_MIME_TYPE + " text, "
+ ATTACHMENT_NAME + " text, "
+ ATTACHMENT_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");");
}
private void createIncidentInputTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_INCIDENT_INPUT + "("
+ INCIDENT_INPUT_ID + " integer primary key autoincrement, "
+ INCIDENT_INPUT_NUMBER + " text, "
+ INCIDENT_INPUT_IMPACT + " integer default -1, "
+ INCIDENT_INPUT_SHORT_DESCRIPTION + " text, "
+ INCIDENT_INPUT_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");");
}
}
package com.vsoft.uoflservicenow.db.managers;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.Attachment;
import com.vsoft.uoflservicenow.utils.DBConstants;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Kunj on 11-08-2016.
*/
public class AttachmentManager implements DBConstants {
public static long save(Attachment attachment, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
attachment.setSyncDirty(syncDirty);
long id = db.insert(TABLE_ATTACHMENT, null, getContentValues(attachment));
attachment.setId(id);
return id;
} else {
return -1;
}
}
public static int delete(Attachment attachment) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
return db.delete(TABLE_ATTACHMENT, ATTACHMENT_ID + "=" + attachment.getId(), null);
}
return -1;
}
public static int update(Attachment attachment, int syncDirty) {
return update(attachment, null, syncDirty);
}
public static int update(Attachment attachment, List<String> column, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
attachment.setSyncDirty(syncDirty);
if (column == null || column.size() == 0) {
return db.update(TABLE_ATTACHMENT, getContentValues(attachment), ATTACHMENT_ID + "=" + attachment.getId(), null);
} else {
ContentValues contentValues = new ContentValues(column.size());
contentValues.put(ATTACHMENT_SYNC_DIRTY, attachment.getSyncDirty());
for (int i = 0; i < column.size(); i++) {
String columnName = column.get(i);
if (ATTACHMENT_ITEM_INPUT_ID.equals(columnName)) {
contentValues.put(ATTACHMENT_ITEM_INPUT_ID, attachment.getItemInputId());
} else if (ATTACHMENT_PATH.equals(columnName)) {
contentValues.put(ATTACHMENT_PATH, attachment.getPath());
} else if (ATTACHMENT_NAME.equals(columnName)) {
contentValues.put(ATTACHMENT_NAME, attachment.getName());
} else if (ATTACHMENT_MIME_TYPE.equals(columnName)) {
contentValues.put(ATTACHMENT_MIME_TYPE, attachment.getMimeType());
}
}
return db.update(TABLE_ATTACHMENT, contentValues, ATTACHMENT_ID + "=" + attachment.getId(), null);
}
} else {
return -1;
}
}
public static List<Attachment> getAllIAttachment(long inputItemId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_ATTACHMENT
+ " where " + ATTACHMENT_ITEM_INPUT_ID + "=" + inputItemId
+ " and " + ATTACHMENT_SYNC_DIRTY + "!=" + DBConstants.SYNC_FLAG_DELETE, null);
ArrayList<Attachment> attachmentList;
if (c.getCount() > 0) {
attachmentList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
Attachment.AttachmentBuilder builder = Attachment.AttachmentBuilder.anAttachment();
fillAllAttachmentDetails(c, builder);
attachmentList.add(builder.build());
}
} else {
attachmentList = new ArrayList<>(0);
}
c.close();
return attachmentList;
} else {
return new ArrayList<>(0);
}
}
public static Attachment get(long attachmentId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
Attachment attachment = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_ATTACHMENT + " where " + ATTACHMENT_ID + "=" + attachmentId, null);
if (c.moveToFirst()) {
Attachment.AttachmentBuilder builder = Attachment.AttachmentBuilder.anAttachment();
fillAllAttachmentDetails(c, builder);
attachment = builder.build();
}
c.close();
}
return attachment;
}
public static List<Attachment> getDirtyAttachment(long itemInputId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if(db!=null) {
Cursor c = db.rawQuery("select * from " + TABLE_ATTACHMENT
+ " where " + ATTACHMENT_ITEM_INPUT_ID + "=" + itemInputId
+ " and " + ATTACHMENT_SYNC_DIRTY + ">" + SYNC_FLAG_NONE , null);
ArrayList<Attachment> attachmentList;
if (c.getCount() > 0) {
attachmentList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
Attachment.AttachmentBuilder builder = Attachment.AttachmentBuilder.anAttachment();
fillAllAttachmentDetails(c, builder);
attachmentList.add(builder.build());
}
} else {
attachmentList = new ArrayList<>(0);
}
c.close();
return attachmentList;
} else {
return new ArrayList<>(0);
}
}
private static void fillAllAttachmentDetails(Cursor c, Attachment.AttachmentBuilder builder) {
builder.setId(c.getLong(INDEX_ATTACHMENT_ID));
builder.setItemInputId(c.getLong(INDEX_ATTACHMENT_ITEM_INPUT_ID));
builder.setPath(c.getString(INDEX_ATTACHMENT_PATH));
builder.setName(c.getString(INDEX_ATTACHMENT_NAME));
builder.setMimeType(c.getString(INDEX_ATTACHMENT_MIME_TYPE));
builder.setSyncDirty(c.getInt(INDEX_ATTACHMENT_SYNC_DIRTY));
}
private static ContentValues getContentValues(Attachment attachment) {
ContentValues cv = new ContentValues(ATTACHMENT_COLUMN_COUNT - 1);
cv.put(ATTACHMENT_ITEM_INPUT_ID, attachment.getItemInputId());
cv.put(ATTACHMENT_PATH, attachment.getPath());
cv.put(ATTACHMENT_NAME, attachment.getName());
cv.put(ATTACHMENT_MIME_TYPE, attachment.getMimeType());
cv.put(ATTACHMENT_SYNC_DIRTY, attachment.getSyncDirty());
return cv;
}
}
\ No newline at end of file
package com.vsoft.uoflservicenow.db.managers;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.CatalogueItemInput;
import com.vsoft.uoflservicenow.utils.DBConstants;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Kunj on 11-08-2016.
*/
public class CatalogueItemInputManager implements DBConstants {
public static long save(CatalogueItemInput catalogueItemInput, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
catalogueItemInput.setSyncDirty(syncDirty);
long id = db.insert(TABLE_CATALOGUE_ITEM_INPUT, null, getContentValues(catalogueItemInput));
catalogueItemInput.setId(id);
return id;
} else {
return -1;
}
}
public static int delete(CatalogueItemInput catalogueItemInput) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
if (catalogueItemInput.getSysId() == null || catalogueItemInput.getSysId().isEmpty()) {
return db.delete(TABLE_CATALOGUE_ITEM_INPUT, CATALOGUE_ITEM_INPUT_ID + "=" + catalogueItemInput.getId(), null);
} else {
return update(catalogueItemInput, SYNC_FLAG_DELETE);
}
}
return -1;
}
public static int update(CatalogueItemInput catalogueItemInput, int syncDirty) {
return update(catalogueItemInput, null, syncDirty);
}
public static int update(CatalogueItemInput catalogueItemInput, List<String> column, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
catalogueItemInput.setSyncDirty(syncDirty);
if (column == null || column.size() == 0) {
return db.update(TABLE_CATALOGUE_ITEM_INPUT, getContentValues(catalogueItemInput), CATALOGUE_ITEM_INPUT_ID + "=" + catalogueItemInput.getId(), null);
} else {
ContentValues contentValues = new ContentValues(column.size());
contentValues.put(CATALOGUE_VARIABLE_SYNC_DIRTY, catalogueItemInput.getSyncDirty());
for (int i = 0; i < column.size(); i++) {
String columnName = column.get(i);
if (CATALOGUE_ITEM_INPUT_CATALOGUE_ITEM_ID.equals(columnName)) {
contentValues.put(CATALOGUE_ITEM_INPUT_CATALOGUE_ITEM_ID, catalogueItemInput.getCatalogueItemId());
} else if (CATALOGUE_ITEM_INPUT_DATA.equals(columnName)) {
contentValues.put(CATALOGUE_ITEM_INPUT_DATA, catalogueItemInput.getData());
} else if (CATALOGUE_ITEM_INPUT_SYS_ID.equals(columnName)) {
contentValues.put(CATALOGUE_ITEM_INPUT_SYS_ID, catalogueItemInput.getSysId());
} else if (CATALOGUE_ITEM_INPUT_SYNC_DIRTY.equals(columnName)) {
contentValues.put(CATALOGUE_ITEM_INPUT_SYNC_DIRTY, catalogueItemInput.getSyncDirty());
}
}
return db.update(TABLE_CATALOGUE_ITEM_INPUT, contentValues, CATALOGUE_ITEM_INPUT_ID + "=" + catalogueItemInput.getId(), null);
}
} else {
return -1;
}
}
public static List<CatalogueItemInput> getAllItemInput(long catalogueItemId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_CATALOGUE_ITEM_INPUT
+ " where " + CATALOGUE_ITEM_INPUT_CATALOGUE_ITEM_ID + "=" + catalogueItemId
+ " and " + CATALOGUE_ITEM_INPUT_SYNC_DIRTY + "!=" + DBConstants.SYNC_FLAG_DELETE, null);
ArrayList<CatalogueItemInput> itemInputList;
if (c.getCount() > 0) {
itemInputList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
CatalogueItemInput.CatalogueItemInputBuilder builder = CatalogueItemInput.CatalogueItemInputBuilder.aCatalogueItemInput();
fillAllItemInputDetails(c, builder);
itemInputList.add(builder.build());
}
} else {
itemInputList = new ArrayList<>(0);
}
c.close();
return itemInputList;
} else {
return new ArrayList<>(0);
}
}
public static CatalogueItemInput get(long catalogueId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
CatalogueItemInput catalogueItemInput = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_CATALOGUE_ITEM_INPUT + " where " + CATALOGUE_ITEM_INPUT_ID + "=" + catalogueId, null);
if (c.moveToFirst()) {
CatalogueItemInput.CatalogueItemInputBuilder builder = CatalogueItemInput.CatalogueItemInputBuilder.aCatalogueItemInput();
fillAllItemInputDetails(c, builder);
catalogueItemInput = builder.build();
}
c.close();
}
return catalogueItemInput;
}
public static CatalogueItemInput getItemInputFromSysId(String sysId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
CatalogueItemInput catalogueItemInput = null;
if(db!=null) {
Cursor c = db.rawQuery("select * from " + TABLE_CATALOGUE_ITEM_INPUT + " where " + CATALOGUE_ITEM_INPUT_SYS_ID + "='" + sysId + "'", null);
if (c.moveToFirst()) {
CatalogueItemInput.CatalogueItemInputBuilder builder = CatalogueItemInput.CatalogueItemInputBuilder.aCatalogueItemInput();
fillAllItemInputDetails(c, builder);
catalogueItemInput = builder.build();
}
c.close();
}
return catalogueItemInput;
}
public static void handleSaveServerResponse(CatalogueItemInput catalogueItemInput, List<String> column, int syncFlag) {
update(catalogueItemInput, column, syncFlag);
}
public static List<CatalogueItemInput> getDirtyItemInput() {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if(db!=null) {
Cursor c = db.rawQuery("select * from " + TABLE_CATALOGUE_ITEM_INPUT
+ " where " + CATALOGUE_ITEM_INPUT_SYNC_DIRTY + ">" + SYNC_FLAG_NONE , null);
ArrayList<CatalogueItemInput> itemInputList;
if (c.getCount() > 0) {
itemInputList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
CatalogueItemInput.CatalogueItemInputBuilder builder = CatalogueItemInput.CatalogueItemInputBuilder.aCatalogueItemInput();
fillAllItemInputDetails(c, builder);
itemInputList.add(builder.build());
}
} else {
itemInputList = new ArrayList<>(0);
}
c.close();
return itemInputList;
} else {
return new ArrayList<>(0);
}
}
private static void fillAllItemInputDetails(Cursor c, CatalogueItemInput.CatalogueItemInputBuilder builder) {
builder.setId(c.getLong(INDEX_CATALOGUE_ITEM_INPUT_ID));
builder.setCatalogueItemId(c.getLong(INDEX_CATALOGUE_ITEM_INPUT_CATALOGUE_ITEM_ID));
builder.setSysId(c.getString(INDEX_CATALOGUE_ITEM_INPUT_SYS_ID));
builder.setData(c.getString(INDEX_CATALOGUE_ITEM_INPUT_DATA));
builder.setSyncDirty(c.getInt(INDEX_CATALOGUE_ITEM_INPUT_SYNC_DIRTY));
}
private static ContentValues getContentValues(CatalogueItemInput catalogueItemInput) {
ContentValues cv = new ContentValues(CATALOGUE_ITEM_INPUT_COLUMN_COUNT - 1);
cv.put(CATALOGUE_ITEM_INPUT_CATALOGUE_ITEM_ID, catalogueItemInput.getCatalogueItemId());
cv.put(CATALOGUE_ITEM_INPUT_SYS_ID, catalogueItemInput.getSysId());
cv.put(CATALOGUE_ITEM_INPUT_DATA, catalogueItemInput.getData());
cv.put(CATALOGUE_ITEM_INPUT_SYNC_DIRTY, catalogueItemInput.getSyncDirty());
return cv;
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.CatalogueVariable;
import com.vsoft.uoflservicenow.enums.ViewType;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.DBConstants;
import java.util.ArrayList;
......@@ -20,6 +21,7 @@ import java.util.List;
public class CatalogueVariableManager implements DBConstants {
public static long save(CatalogueVariable catalogueVariable, int syncDirty) {
CatalogueLog.e("CatalogueVariableManager: save");
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
catalogueVariable.setSyncDirty(syncDirty);
......@@ -32,6 +34,7 @@ public class CatalogueVariableManager implements DBConstants {
}
public static int delete(CatalogueVariable catalogueVariable) {
CatalogueLog.e("CatalogueVariableManager: delete");
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
if (catalogueVariable.getSysId() == null || catalogueVariable.getSysId().isEmpty()) {
......@@ -48,6 +51,7 @@ public class CatalogueVariableManager implements DBConstants {
}
public static int update(CatalogueVariable catalogueVariable, List<String> column, int syncDirty) {
CatalogueLog.e("CatalogueVariableManager: update");
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
catalogueVariable.setSyncDirty(syncDirty);
......@@ -78,6 +82,10 @@ public class CatalogueVariableManager implements DBConstants {
contentValues.put(CATALOGUE_VARIABLE_ORDER, catalogueVariable.getOrder());
} else if (CATALOGUE_VARIABLE_REFERENCE_COLUMN_NAME.equals(columnName)) {
contentValues.put(CATALOGUE_VARIABLE_REFERENCE_COLUMN_NAME, catalogueVariable.getReferenceColumnName());
} else if (CATALOGUE_VARIABLE_ACTIVE.equals(columnName)) {
contentValues.put(CATALOGUE_VARIABLE_ACTIVE, catalogueVariable.getActive());
} else if (CATALOGUE_VARIABLE_DEFAULT_VALUE.equals(columnName)) {
contentValues.put(CATALOGUE_VARIABLE_DEFAULT_VALUE, catalogueVariable.getDefaultValue());
} else if (CATALOGUE_VARIABLE_SYNC_DIRTY.equals(columnName)) {
contentValues.put(CATALOGUE_VARIABLE_SYNC_DIRTY, catalogueVariable.getSyncDirty());
}
......@@ -224,6 +232,8 @@ public class CatalogueVariableManager implements DBConstants {
builder.setReferenceTable(c.getString(INDEX_CATALOGUE_VARIABLE_REFERENCE));
builder.setOrder(c.getInt(INDEX_CATALOGUE_VARIABLE_ORDER));
builder.setReferenceColumnName(c.getString(INDEX_CATALOGUE_VARIABLE_REFERENCE_COLUMN_NAME));
builder.setActive(c.getInt(INDEX_CATALOGUE_VARIABLE_ACTIVE) == 1);
builder.setDefaultValue(c.getString(INDEX_CATALOGUE_VARIABLE_DEFAULT_VALUE));
builder.setSyncDirty(c.getInt(INDEX_CATALOGUE_VARIABLE_SYNC_DIRTY));
}
......@@ -239,6 +249,8 @@ public class CatalogueVariableManager implements DBConstants {
cv.put(CATALOGUE_VARIABLE_REFERENCE_TABLE, catalogueVariable.getReferenceTable());
cv.put(CATALOGUE_VARIABLE_ORDER, catalogueVariable.getOrder());
cv.put(CATALOGUE_VARIABLE_REFERENCE_COLUMN_NAME, catalogueVariable.getReferenceColumnName());
cv.put(CATALOGUE_VARIABLE_ACTIVE, catalogueVariable.getActive() ? 1 : 0);
cv.put(CATALOGUE_VARIABLE_DEFAULT_VALUE, catalogueVariable.getDefaultValue());
cv.put(CATALOGUE_VARIABLE_SYNC_DIRTY, catalogueVariable.getSyncDirty());
return cv;
}
......
package com.vsoft.uoflservicenow.db.managers;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.CatalogueVariable;
import com.vsoft.uoflservicenow.enums.ViewType;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.DBConstants;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Kunj on 11-08-2016.
*/
public class CatalogueVariableValueManager implements DBConstants {
public static long save(String tableName, List<String> columnNameList, List<String> valueList, int syncDirty) {
CatalogueLog.e("CatalogueVariableValueManager: save");
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
ContentValues contentValues = new ContentValues(columnNameList.size());
contentValues.put(CATALOGUE_VARIABLE_SYNC_DIRTY, syncDirty);
for (int i = 0; i < columnNameList.size(); i++) {
String columnName = columnNameList.get(i);
String value = valueList.get(i);
if(columnName!=null && value!=null)
contentValues.put(columnName, value);
}
long id = db.insert(tableName, null, contentValues);
return id;
} else {
return -1;
}
}
public static int delete(CatalogueVariable catalogueVariable) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
if (catalogueVariable.getSysId() == null || catalogueVariable.getSysId().isEmpty()) {
return db.delete(TABLE_CATALOGUE_VARIABLES, CATALOGUE_VARIABLE_ID + "=" + catalogueVariable.getId(), null);
} else {
return update(catalogueVariable, SYNC_FLAG_DELETE);
}
}
return -1;
}
public static int update(CatalogueVariable catalogueVariable, int syncDirty) {
return update(catalogueVariable, null, syncDirty);
}
public static int update(CatalogueVariable catalogueVariable, List<String> column, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
catalogueVariable.setSyncDirty(syncDirty);
if (column == null || column.size() == 0) {
return db.update(TABLE_CATALOGUE_VARIABLES, getContentValues(catalogueVariable), CATALOGUE_VARIABLE_ID + "=" + catalogueVariable.getId(), null);
} else {
ContentValues contentValues = new ContentValues(column.size());
contentValues.put(CATALOGUE_VARIABLE_SYNC_DIRTY, catalogueVariable.getSyncDirty());
for (int i = 0; i < column.size(); i++) {
String columnName = column.get(i);
if (CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID.equals(columnName)) {
contentValues.put(CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID, catalogueVariable.getCatalogueItemId());
} else if (CATALOGUE_VARIABLE_NAME.equals(columnName)) {
contentValues.put(CATALOGUE_VARIABLE_NAME, catalogueVariable.getName());
} else if (CATALOGUE_VARIABLE_QUESTION_TEXT.equals(columnName)) {
contentValues.put(CATALOGUE_VARIABLE_QUESTION_TEXT, catalogueVariable.getQuestionText());
} else if (CATALOGUE_VARIABLE_TYPE.equals(columnName)) {
contentValues.put(CATALOGUE_VARIABLE_TYPE, ViewType.getId(catalogueVariable.getType()));
} else if (CATALOGUE_VARIABLE_SYS_ID.equals(columnName)) {
contentValues.put(CATALOGUE_VARIABLE_SYS_ID, catalogueVariable.getSysId());
} else if (CATALOGUE_VARIABLE_SYNC_DIRTY.equals(columnName)) {
contentValues.put(CATALOGUE_VARIABLE_SYNC_DIRTY, catalogueVariable.getSyncDirty());
}
}
return db.update(TABLE_CATALOGUE_VARIABLES, contentValues, CATALOGUE_VARIABLE_ID + "=" + catalogueVariable.getId(), null);
}
} else {
return -1;
}
}
public static List<CatalogueVariable> getAllVariable(long catalogueItemId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_CATALOGUE_VARIABLES
+ " where " + CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID + "=" + catalogueItemId
+ " and " + CATALOGUE_VARIABLE_SYNC_DIRTY + "!=" + DBConstants.SYNC_FLAG_DELETE, null);
ArrayList<CatalogueVariable> variableList;
if (c.getCount() > 0) {
variableList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
CatalogueVariable.CatalogueVariableBuilder builder = CatalogueVariable.CatalogueVariableBuilder.aCatalogueVariable();
fillAllVariableDetails(c, builder);
variableList.add(builder.build());
}
} else {
variableList = new ArrayList<>(0);
}
c.close();
return variableList;
} else {
return new ArrayList<>(0);
}
}
public static CatalogueVariable get(long catalogueId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
CatalogueVariable catalogueVariable = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_CATALOGUE_VARIABLES + " where " + CATALOGUE_VARIABLE_ID + "=" + catalogueId, null);
if (c.moveToFirst()) {
CatalogueVariable.CatalogueVariableBuilder builder = CatalogueVariable.CatalogueVariableBuilder.aCatalogueVariable();
fillAllVariableDetails(c, builder);
catalogueVariable = builder.build();
}
c.close();
}
return catalogueVariable;
}
public static CatalogueVariable getVariableFromSysId(String sysId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
CatalogueVariable catalogueVariable = null;
if(db!=null) {
Cursor c = db.rawQuery("select * from " + TABLE_CATALOGUE_VARIABLES + " where " + CATALOGUE_VARIABLE_SYS_ID + "='" + sysId + "'", null);
if (c.moveToFirst()) {
CatalogueVariable.CatalogueVariableBuilder builder = CatalogueVariable.CatalogueVariableBuilder.aCatalogueVariable();
fillAllVariableDetails(c, builder);
catalogueVariable = builder.build();
}
c.close();
}
return catalogueVariable;
}
private static void fillAllVariableDetails(Cursor c, CatalogueVariable.CatalogueVariableBuilder builder) {
builder.setId(c.getLong(INDEX_CATALOGUE_VARIABLE_ID));
builder.setCatalogueItemId(c.getLong(INDEX_CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID));
builder.setSysId(c.getString(INDEX_CATALOGUE_VARIABLE_SYS_ID));
builder.setName(c.getString(INDEX_CATALOGUE_VARIABLE_NAME));
builder.setQuestionText(c.getString(INDEX_CATALOGUE_VARIABLE_QUESTION_TEXT));
builder.setType(ViewType.from(c.getInt(INDEX_CATALOGUE_VARIABLE_TYPE)));
builder.setSyncDirty(c.getInt(INDEX_CATALOGUE_VARIABLE_SYNC_DIRTY));
}
private static ContentValues getContentValues(CatalogueVariable catalogueVariable) {
ContentValues cv = new ContentValues(CATALOGUE_VARIABLE_COLUMN_COUNT - 1);
cv.put(CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID, catalogueVariable.getCatalogueItemId());
cv.put(CATALOGUE_VARIABLE_SYS_ID, catalogueVariable.getSysId());
cv.put(CATALOGUE_VARIABLE_NAME, catalogueVariable.getName());
cv.put(CATALOGUE_VARIABLE_QUESTION_TEXT, catalogueVariable.getQuestionText());
cv.put(CATALOGUE_VARIABLE_TYPE, catalogueVariable.getType().getId());
cv.put(CATALOGUE_VARIABLE_SYNC_DIRTY, catalogueVariable.getSyncDirty());
return cv;
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.MyRequest;
import com.vsoft.uoflservicenow.db.models.MyRequestShortDes;
import com.vsoft.uoflservicenow.utils.DBConstants;
import java.util.ArrayList;
......@@ -60,7 +61,7 @@ public class MyRequestsManager implements DBConstants {
if (REQUEST_NUMBER.equals(columnName)) {
contentValues.put(REQUEST_NUMBER, myRequest.getNumber());
} else if (REQUEST_SHORT_DESCRIPTION.equals(columnName)) {
contentValues.put(REQUEST_SHORT_DESCRIPTION, myRequest.getShortDescription());
contentValues.put(REQUEST_SHORT_DESCRIPTION, myRequest.getShortDescription().getDisplayValue());
} else if (REQUEST_SYS_UPDATED_ON.equals(columnName)) {
contentValues.put(REQUEST_SYS_UPDATED_ON, myRequest.getUpdateOn());
} else if (REQUEST_APPROVAL.equals(columnName)) {
......@@ -194,9 +195,11 @@ public class MyRequestsManager implements DBConstants {
}
private static void fillAllRequestDetails(Cursor c, MyRequest.MyRequestBuilder builder) {
MyRequestShortDes myRequestShortDes = new MyRequestShortDes();
myRequestShortDes.setDisplayValue(c.getString(INDEX_REQUEST_SHORT_DESCRIPTION));
builder.setId(c.getLong(INDEX_REQUEST_ID));
builder.setNumber(c.getString(INDEX_REQUEST_NUMBER));
builder.setShortDescription(c.getString(INDEX_REQUEST_SHORT_DESCRIPTION));
builder.setShortDescription(myRequestShortDes);
builder.setUpdateOn(c.getLong(INDEX_REQUEST_SYS_UPDATED_ON));
builder.setApproval(c.getString(INDEX_REQUEST_APPROVAL));
builder.setSyncDirty(c.getInt(INDEX_REQUEST_SYNC_DIRTY));
......@@ -205,7 +208,7 @@ public class MyRequestsManager implements DBConstants {
private static ContentValues getContentValues(MyRequest myRequest) {
ContentValues cv = new ContentValues(REQUEST_COLUMN_COUNT - 1);
cv.put(REQUEST_NUMBER, myRequest.getNumber());
cv.put(REQUEST_SHORT_DESCRIPTION, myRequest.getShortDescription());
cv.put(REQUEST_SHORT_DESCRIPTION, myRequest.getShortDescription().getDisplayValue());
cv.put(REQUEST_SYS_UPDATED_ON, myRequest.getUpdateOn());
cv.put(REQUEST_APPROVAL, myRequest.getApproval());
cv.put(REQUEST_SYNC_DIRTY, myRequest.getSyncDirty());
......
......@@ -9,6 +9,9 @@ import com.vsoft.uoflservicenow.db.models.Incident;
import com.vsoft.uoflservicenow.enums.Impact;
import com.vsoft.uoflservicenow.utils.DBConstants;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Kunj on 16-09-2016.
......@@ -19,19 +22,61 @@ public class ReportIncidentValueManager implements DBConstants {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
incident.setSyncDirty(syncDirty);
long id = db.insert(TABLE_INCIDENT_FORM, null, getContentValues(incident));
long id = db.insert(TABLE_INCIDENT_INPUT, null, getContentValues(incident));
return id;
} else {
return -1;
}
}
public static int delete(Incident incident) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
if (incident.getNumber() == null || incident.getNumber().isEmpty()) {
return db.delete(TABLE_INCIDENT_INPUT, INCIDENT_INPUT_ID + "=" + incident.getId(), null);
} else {
return update(incident, SYNC_FLAG_DELETE);
}
}
return -1;
}
public static int update(Incident incident, int syncDirty) {
return update(incident, null, syncDirty);
}
public static int update(Incident incident, List<String> column, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
incident.setSyncDirty(syncDirty);
if (column == null || column.size() == 0) {
return db.update(TABLE_INCIDENT_INPUT, getContentValues(incident), INCIDENT_INPUT_ID + "=" + incident.getId(), null);
} else {
ContentValues contentValues = new ContentValues(column.size());
contentValues.put(INCIDENT_INPUT_SYNC_DIRTY, incident.getSyncDirty());
for (int i = 0; i < column.size(); i++) {
String columnName = column.get(i);
if (INCIDENT_INPUT_NUMBER.equals(columnName)) {
contentValues.put(INCIDENT_INPUT_NUMBER, incident.getNumber());
} else if (INCIDENT_INPUT_IMPACT.equals(columnName)) {
contentValues.put(INCIDENT_INPUT_IMPACT, Impact.getId(incident.getImpact()));
} else if (INCIDENT_INPUT_SHORT_DESCRIPTION.equals(columnName)) {
contentValues.put(INCIDENT_INPUT_SHORT_DESCRIPTION, incident.getShortDescription());
}
}
return db.update(TABLE_INCIDENT_INPUT, contentValues, INCIDENT_INPUT_ID + "=" + incident.getId(), null);
}
} else {
return -1;
}
}
public static Incident get(long incidentId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
Incident incident = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_INCIDENT_FORM + " where " + INCIDENT_FORM_ID + "=" + incidentId, null);
Cursor c = db.rawQuery("select * from " + TABLE_INCIDENT_INPUT + " where " + INCIDENT_INPUT_ID + "=" + incidentId, null);
if (c.moveToFirst()) {
Incident.IncidentBuilder builder = Incident.IncidentBuilder.anIncident();
fillAllIncidentFormDetails(c, builder);
......@@ -42,34 +87,48 @@ public class ReportIncidentValueManager implements DBConstants {
return incident;
}
public static Incident getIncidentFromSysId(String sysId) {
public static void handleSaveServerResponse(Incident incident, List<String> column, int syncFlag) {
update(incident, column, syncFlag);
}
public static List<Incident> getDirtyIncident() {
SQLiteDatabase db = CatalogueApplication.getDatabase();
Incident incident = null;
if(db!=null) {
Cursor c = db.rawQuery("select * from " + TABLE_INCIDENT_FORM + " where " + CATALOGUE_VARIABLE_SYS_ID + "='" + sysId + "'", null);
if (c.moveToFirst()) {
Cursor c = db.rawQuery("select * from " + TABLE_INCIDENT_INPUT
+ " where " + INCIDENT_INPUT_SYNC_DIRTY + ">" + SYNC_FLAG_NONE , null);
ArrayList<Incident> incidentInputList;
if (c.getCount() > 0) {
incidentInputList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
Incident.IncidentBuilder builder = Incident.IncidentBuilder.anIncident();
fillAllIncidentFormDetails(c, builder);
incident = builder.build();
incidentInputList.add(builder.build());
}
} else {
incidentInputList = new ArrayList<>(0);
}
c.close();
return incidentInputList;
} else {
return new ArrayList<>(0);
}
return incident;
}
private static void fillAllIncidentFormDetails(Cursor c, Incident.IncidentBuilder builder) {
builder.setId(c.getLong(INDEX_INCIDENT_FORM_ID));
builder.setImpact(Impact.from(c.getInt(INDEX_INCIDENT_FORM_IMPACT)));
builder.setShortDescription(c.getString(INDEX_INCIDENT_FORM_SHORT_DESCRIPTION));
builder.setSyncDirty(c.getInt(INDEX_INCIDENT_FORM_SYNC_DIRTY));
builder.setId(c.getLong(INDEX_INCIDENT_INPUT_ID));
builder.setImpact(Impact.from(c.getInt(INDEX_INCIDENT_INPUT_IMPACT)));
builder.setNumber(c.getString(INDEX_INCIDENT_INPUT_NUMBER));
builder.setShortDescription(c.getString(INDEX_INCIDENT_INPUT_SHORT_DESCRIPTION));
builder.setSyncDirty(c.getInt(INDEX_INCIDENT_INPUT_SYNC_DIRTY));
}
private static ContentValues getContentValues(Incident incident) {
ContentValues cv = new ContentValues(INCIDENT_FORM_COLUMN_COUNT - 1);
cv.put(INCIDENT_FORM_IMPACT, Impact.getId(incident.getImpact()));
cv.put(INCIDENT_FORM_SHORT_DESCRIPTION, incident.getShortDescription());
cv.put(INCIDENT_FORM_SYNC_DIRTY, incident.getSyncDirty());
ContentValues cv = new ContentValues(INCIDENT_INPUT_COLUMN_COUNT - 1);
cv.put(INCIDENT_INPUT_IMPACT, Impact.getId(incident.getImpact()));
cv.put(INCIDENT_INPUT_NUMBER, incident.getNumber());
cv.put(INCIDENT_INPUT_SHORT_DESCRIPTION, incident.getShortDescription());
cv.put(INCIDENT_INPUT_SYNC_DIRTY, incident.getSyncDirty());
return cv;
}
}
\ No newline at end of file
package com.vsoft.uoflservicenow.db.managers;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.UiPolicyAction;
import com.vsoft.uoflservicenow.utils.DBConstants;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Kunj on 18-11-2016.
*/
public class UiPolicyActionManager implements DBConstants {
public static long save(UiPolicyAction uiPolicyAction, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
uiPolicyAction.setSyncDirty(syncDirty);
long id = db.insert(TABLE_UI_POLICY_ACTION, null, getContentValues(uiPolicyAction));
uiPolicyAction.setId(id);
return id;
} else {
return -1;
}
}
public static int delete(UiPolicyAction uiPolicyAction) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
return db.delete(TABLE_UI_POLICY_ACTION, UI_POLICY_ACTION_ID + "=" + uiPolicyAction.getId(), null);
}
return -1;
}
public static int update(UiPolicyAction uiPolicyAction, int syncDirty) {
return update(uiPolicyAction, null, syncDirty);
}
public static int update(UiPolicyAction uiPolicyAction, List<String> column, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
uiPolicyAction.setSyncDirty(syncDirty);
if (column == null || column.size() == 0) {
return db.update(TABLE_UI_POLICY_ACTION, getContentValues(uiPolicyAction), UI_POLICY_ACTION_ID + "=" + uiPolicyAction.getId(), null);
} else {
ContentValues contentValues = new ContentValues(column.size());
contentValues.put(UI_POLICY_ACTION_SYNC_DIRTY, uiPolicyAction.getSyncDirty());
for (int i = 0; i < column.size(); i++) {
String columnName = column.get(i);
if (UI_POLICY_ACTION_POLICY_ITEM_ID.equals(columnName)) {
contentValues.put(UI_POLICY_ACTION_POLICY_ITEM_ID, uiPolicyAction.getUiPolicyItemId());
} else if (UI_POLICY_ACTION_MANDATORY.equals(columnName)) {
contentValues.put(UI_POLICY_ACTION_MANDATORY, uiPolicyAction.getMandatory());
} else if (UI_POLICY_ACTION_DISABLED.equals(columnName)) {
contentValues.put(UI_POLICY_ACTION_DISABLED, uiPolicyAction.getDisabled());
} else if (UI_POLICY_ACTION_VISIBLE.equals(columnName)) {
contentValues.put(UI_POLICY_ACTION_VISIBLE, uiPolicyAction.getVisible());
} else if (UI_POLICY_ACTION_VARIABLE.equals(columnName)) {
contentValues.put(UI_POLICY_ACTION_VARIABLE, uiPolicyAction.getVariableName());
}
}
return db.update(TABLE_UI_POLICY_ACTION, contentValues, UI_POLICY_ACTION_ID + "=" + uiPolicyAction.getId(), null);
}
} else {
return -1;
}
}
public static void handleGetUiPolicyAction(List<UiPolicyAction> uiPolicyActionList, long uiPolicyItemId) {
if(uiPolicyActionList != null && !uiPolicyActionList.isEmpty()) {
/*Check this UiPolicyItem is exist in local DB or not
* If doesn't exist in local, save it
* If exist in local, update the local item with data from server item.
* */
for (int i = 0; i < uiPolicyActionList.size(); i++) {
UiPolicyAction uiPolicyAction = uiPolicyActionList.get(i);
uiPolicyAction.setUiPolicyItemId(uiPolicyItemId);
save(uiPolicyAction, DBConstants.SYNC_FLAG_NONE);
}
} else {
/*That means there is no UiPolicyAction in server response, then all local items should be deleted those are contain sys_id*/
/*localPolicyActionList is contain all local Catalogues */
List<UiPolicyAction> localPolicyActionList = getAllUiPolicyActions(uiPolicyItemId);
if (localPolicyActionList != null && !localPolicyActionList.isEmpty()) {
for (int i = 0; i < localPolicyActionList.size(); i++) {
UiPolicyAction localUiPolicyAction = localPolicyActionList.get(i);
delete(localUiPolicyAction);
}
}
}
}
public static List<UiPolicyAction> getAllUiPolicyActions(long uiPolicyItemId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_UI_POLICY_ACTION
+ " where " + UI_POLICY_ACTION_POLICY_ITEM_ID + "=" + uiPolicyItemId
+ " and " + UI_POLICY_ACTION_SYNC_DIRTY
+ "!=" + DBConstants.SYNC_FLAG_DELETE, null);
ArrayList<UiPolicyAction> uiPolicyActionList;
if (c.getCount() > 0) {
uiPolicyActionList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
UiPolicyAction.UiPolicyActionBuilder builder = UiPolicyAction.UiPolicyActionBuilder.anUiPolicyAction();
fillAllUiPolicyActionDetails(c, builder);
uiPolicyActionList.add(builder.build());
}
} else {
uiPolicyActionList = new ArrayList<>(0);
}
c.close();
return uiPolicyActionList;
} else {
return new ArrayList<>(0);
}
}
public static UiPolicyAction get(long uiPolicyActionId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
UiPolicyAction uiPolicyAction = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_UI_POLICY_ACTION + " where " + UI_POLICY_ACTION_ID + "=" + uiPolicyActionId, null);
if (c.moveToFirst()) {
UiPolicyAction.UiPolicyActionBuilder builder = UiPolicyAction.UiPolicyActionBuilder.anUiPolicyAction();
fillAllUiPolicyActionDetails(c, builder);
uiPolicyAction = builder.build();
}
c.close();
}
return uiPolicyAction;
}
private static void fillAllUiPolicyActionDetails(Cursor c, UiPolicyAction.UiPolicyActionBuilder builder) {
builder.setId(c.getLong(INDEX_UI_POLICY_ACTION_ID));
builder.setUiPolicyItemId(c.getLong(INDEX_UI_POLICY_ACTION_POLICY_ITEM_ID));
builder.setVisible(c.getString(INDEX_UI_POLICY_ACTION_VISIBLE));
builder.setMandatory(c.getString(INDEX_UI_POLICY_ACTION_MANDATORY));
builder.setVariableName(c.getString(INDEX_UI_POLICY_ACTION_VARIABLE));
builder.setDisabled(c.getString(INDEX_UI_POLICY_ACTION_DISABLED));
builder.setSyncDirty(c.getInt(INDEX_UI_POLICY_ACTION_SYNC_DIRTY));
}
private static ContentValues getContentValues(UiPolicyAction uiPolicyAction) {
ContentValues cv = new ContentValues(UI_POLICY_ACTION_COLUMN_COUNT - 1);
cv.put(UI_POLICY_ACTION_POLICY_ITEM_ID, uiPolicyAction.getUiPolicyItemId());
cv.put(UI_POLICY_ACTION_VISIBLE, uiPolicyAction.getVisible());
cv.put(UI_POLICY_ACTION_MANDATORY, uiPolicyAction.getMandatory());
cv.put(UI_POLICY_ACTION_VARIABLE, uiPolicyAction.getVariableName());
cv.put(UI_POLICY_ACTION_DISABLED, uiPolicyAction.getDisabled());
cv.put(UI_POLICY_ITEM_SYNC_DIRTY, uiPolicyAction.getSyncDirty());
return cv;
}
}
\ No newline at end of file
package com.vsoft.uoflservicenow.db.managers;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.UiPolicyItem;
import com.vsoft.uoflservicenow.utils.DBConstants;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
*
* @author Kunj on 18-11-2016.
*/
public class UiPolicyItemManager implements DBConstants {
public static long save(UiPolicyItem uiPolicyItem, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
uiPolicyItem.setSyncDirty(syncDirty);
long id = db.insert(TABLE_UI_POLICY_ITEM, null, getContentValues(uiPolicyItem));
uiPolicyItem.setId(id);
return id;
} else {
return -1;
}
}
public static int delete(UiPolicyItem uiPolicyItem) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
if (uiPolicyItem.getSysId() == null || uiPolicyItem.getSysId().isEmpty()) {
return db.delete(TABLE_UI_POLICY_ITEM, UI_POLICY_ITEM_ID + "=" + uiPolicyItem.getId(), null);
} else {
return update(uiPolicyItem, SYNC_FLAG_DELETE);
}
}
return -1;
}
public static int update(UiPolicyItem uiPolicyItem, int syncDirty) {
return update(uiPolicyItem, null, syncDirty);
}
public static int update(UiPolicyItem uiPolicyItem, List<String> column, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
uiPolicyItem.setSyncDirty(syncDirty);
if (column == null || column.size() == 0) {
return db.update(TABLE_UI_POLICY_ITEM, getContentValues(uiPolicyItem), UI_POLICY_ITEM_ID + "=" + uiPolicyItem.getId(), null);
} else {
ContentValues contentValues = new ContentValues(column.size());
contentValues.put(UI_POLICY_ITEM_SYNC_DIRTY, uiPolicyItem.getSyncDirty());
for (int i = 0; i < column.size(); i++) {
String columnName = column.get(i);
if (UI_POLICY_ITEM_SYS_ID.equals(columnName)) {
contentValues.put(UI_POLICY_ITEM_SYS_ID, uiPolicyItem.getSysId());
} else if (UI_POLICY_ITEM_CATALOGUE_ITEM_ID.equals(columnName)) {
contentValues.put(UI_POLICY_ITEM_CATALOGUE_ITEM_ID, uiPolicyItem.getCatalogueItemId());
} else if (UI_POLICY_ITEM_CONDITION.equals(columnName)) {
contentValues.put(UI_POLICY_ITEM_CONDITION, uiPolicyItem.getCondition());
}
}
return db.update(TABLE_UI_POLICY_ITEM, contentValues, UI_POLICY_ITEM_ID + "=" + uiPolicyItem.getId(), null);
}
} else {
return -1;
}
}
public static void handleGetUiPolicyItem(List<UiPolicyItem> uiPolicyItemList, long catalogueItemId) {
if(uiPolicyItemList != null && !uiPolicyItemList.isEmpty()) {
/*uiPolicyItemSysIdMap contain all server response uiPolicyItem Sys Id*/
HashMap<String, Integer> uiPolicyItemSysIdMap = new HashMap<>(0);
Integer intObj = Integer.valueOf(1);
for (int i = 0; i < uiPolicyItemList.size(); i++) {
String sysId = uiPolicyItemList.get(i).getSysId();
uiPolicyItemSysIdMap.put(sysId, intObj);
}
/*localUiPolicyItemList is contain all local uiPolicyItem */
List<UiPolicyItem> localUiPolicyItemList = getAllUiPolicyItems(catalogueItemId);
if (localUiPolicyItemList != null && !localUiPolicyItemList.isEmpty()) {
for (int i = 0; i < localUiPolicyItemList.size(); i++) {
UiPolicyItem localUiPolicyItem = localUiPolicyItemList.get(i);
String localUiPolicySysId = localUiPolicyItem.getSysId();
if (localUiPolicySysId != null
&& !localUiPolicySysId.isEmpty()
&& !uiPolicyItemSysIdMap.containsKey(localUiPolicySysId)) {
//Update sys_id with empty string because required to delete locally
localUiPolicyItem.setSysId("");
delete(localUiPolicyItem);
}
}
}
/*Check this UiPolicyItem is exist in local DB or not
* If doesn't exist in local, save it
* If exist in local, update the local item with data from server item.
* */
for (int i = 0; i < uiPolicyItemList.size(); i++) {
UiPolicyItem uiPolicyItem = uiPolicyItemList.get(i);
UiPolicyItem localUiPolicyItem = getUiPolicyItemFromSysId(uiPolicyItem.getSysId());
if (localUiPolicyItem == null) {
uiPolicyItem.setCatalogueItemId(catalogueItemId);
save(uiPolicyItem, DBConstants.SYNC_FLAG_NONE);
} else {
/*Update complete local UiPolicyItem object with response UiPolicyItem object*/
uiPolicyItem.setId(localUiPolicyItem.getId());
uiPolicyItem.setCatalogueItemId(catalogueItemId);
update(uiPolicyItem, DBConstants.SYNC_FLAG_NONE);
}
}
} else {
/*That means there is no UiPolicyItem in server response, then all local items should be deleted those are contain sys_id*/
/*localPolicyItemList is contain all local Catalogues */
List<UiPolicyItem> localPolicyItemList = getAllUiPolicyItems(catalogueItemId);
if (localPolicyItemList != null && !localPolicyItemList.isEmpty()) {
for (int i = 0; i < localPolicyItemList.size(); i++) {
UiPolicyItem localUiPolicyItem = localPolicyItemList.get(i);
String localUiPolicyItemSysId = localUiPolicyItem.getSysId();
if (localUiPolicyItemSysId != null
&& !localUiPolicyItemSysId.isEmpty()) {
//Update sys_id with empty string because required to delete locally
localUiPolicyItem.setSysId("");
delete(localUiPolicyItem);
}
}
}
}
}
public static List<UiPolicyItem> getAllUiPolicyItems(long catalogueItemId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_UI_POLICY_ITEM
+ " where " + UI_POLICY_ITEM_CATALOGUE_ITEM_ID + "=" + catalogueItemId
+ " and " + UI_POLICY_ITEM_SYNC_DIRTY
+ "!=" + DBConstants.SYNC_FLAG_DELETE, null);
ArrayList<UiPolicyItem> uiPolicyItemList;
if (c.getCount() > 0) {
uiPolicyItemList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
UiPolicyItem.UiPolicyItemBuilder builder = UiPolicyItem.UiPolicyItemBuilder.anUiPolicyItem();
fillAllUiPolicyItemDetails(c, builder);
uiPolicyItemList.add(builder.build());
}
} else {
uiPolicyItemList = new ArrayList<>(0);
}
c.close();
return uiPolicyItemList;
} else {
return new ArrayList<>(0);
}
}
public static UiPolicyItem get(long uiPolicyItemId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
UiPolicyItem uiPolicyItem = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_UI_POLICY_ITEM + " where " + UI_POLICY_ITEM_ID + "=" + uiPolicyItemId, null);
if (c.moveToFirst()) {
UiPolicyItem.UiPolicyItemBuilder builder = UiPolicyItem.UiPolicyItemBuilder.anUiPolicyItem();
fillAllUiPolicyItemDetails(c, builder);
uiPolicyItem = builder.build();
}
c.close();
}
return uiPolicyItem;
}
public static UiPolicyItem getUiPolicyItemFromSysId(String sysId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
UiPolicyItem uiPolicyItem = null;
if(db!=null) {
Cursor c = db.rawQuery("select * from " + TABLE_UI_POLICY_ITEM + " where " + UI_POLICY_ITEM_SYS_ID + "='" + sysId + "'", null);
if (c.moveToFirst()) {
UiPolicyItem.UiPolicyItemBuilder builder = UiPolicyItem.UiPolicyItemBuilder.anUiPolicyItem();
fillAllUiPolicyItemDetails(c, builder);
uiPolicyItem = builder.build();
}
c.close();
}
return uiPolicyItem;
}
private static void fillAllUiPolicyItemDetails(Cursor c, UiPolicyItem.UiPolicyItemBuilder builder) {
builder.setId(c.getLong(INDEX_UI_POLICY_ITEM_ID));
builder.setCatalogueItemId(c.getLong(INDEX_UI_POLICY_ITEM_CATALOGUE_ITEM_ID));
builder.setCondition(c.getString(INDEX_UI_POLICY_ITEM_CONDITION));
builder.setSysId(c.getString(INDEX_UI_POLICY_ITEM_SYS_ID));
builder.setSyncDirty(c.getInt(INDEX_UI_POLICY_ITEM_SYNC_DIRTY));
}
private static ContentValues getContentValues(UiPolicyItem uiPolicyItem) {
ContentValues cv = new ContentValues(UI_POLICY_ITEM_COLUMN_COUNT - 1);
cv.put(UI_POLICY_ITEM_CATALOGUE_ITEM_ID, uiPolicyItem.getCatalogueItemId());
cv.put(UI_POLICY_ITEM_CONDITION, uiPolicyItem.getCondition());
cv.put(UI_POLICY_ITEM_SYS_ID, uiPolicyItem.getSysId());
cv.put(UI_POLICY_ITEM_SYNC_DIRTY, uiPolicyItem.getSyncDirty());
return cv;
}
}
\ No newline at end of file
package com.vsoft.uoflservicenow.db.models;
/**
* Created by Kunj on 11/8/16.
*/
public class Attachment {
private long id = -1;
private long itemInputId;
private String path;
private String name;
private String mimeType;
private int syncDirty;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getItemInputId() {
return itemInputId;
}
public void setItemInputId(long itemInputId) {
this.itemInputId = itemInputId;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMimeType() {
return mimeType;
}
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
public int getSyncDirty() {
return syncDirty;
}
public void setSyncDirty(int syncDirty) {
this.syncDirty = syncDirty;
}
public static final class AttachmentBuilder {
private long id = -1;
private long itemInputId;
private String path;
private String name;
private String mimeType;
private int syncDirty;
private AttachmentBuilder() {
}
public static AttachmentBuilder anAttachment() {
return new AttachmentBuilder();
}
public AttachmentBuilder setId(long id) {
this.id = id;
return this;
}
public AttachmentBuilder setItemInputId(long itemInputId) {
this.itemInputId = itemInputId;
return this;
}
public AttachmentBuilder setPath(String path) {
this.path = path;
return this;
}
public AttachmentBuilder setName(String name) {
this.name = name;
return this;
}
public AttachmentBuilder setMimeType(String mimeType) {
this.mimeType = mimeType;
return this;
}
public AttachmentBuilder setSyncDirty(int syncDirty) {
this.syncDirty = syncDirty;
return this;
}
public AttachmentBuilder but() {
return anAttachment().setId(id).setItemInputId(itemInputId).setPath(path).setName(name).setMimeType(mimeType).setSyncDirty(syncDirty);
}
public Attachment build() {
Attachment attachment = new Attachment();
attachment.setId(id);
attachment.setItemInputId(itemInputId);
attachment.setPath(path);
attachment.setName(name);
attachment.setMimeType(mimeType);
attachment.setSyncDirty(syncDirty);
return attachment;
}
}
@Override
public String toString() {
return "Attachment{" +
"id=" + id +
", itemInputId=" + itemInputId +
", path='" + path + '\'' +
", name='" + name + '\'' +
", mimeType='" + mimeType + '\'' +
", syncDirty=" + syncDirty +
'}';
}
}
\ No newline at end of file
package com.vsoft.uoflservicenow.db.models;
/**
* Created by Kunj on 11/8/16.
*/
public class CatalogueItemInput {
private long id = -1;
private long catalogueItemId;
private String data;
private String sysId;
private int syncDirty;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getCatalogueItemId() {
return catalogueItemId;
}
public void setCatalogueItemId(long catalogueItemId) {
this.catalogueItemId = catalogueItemId;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public String getSysId() {
return sysId;
}
public void setSysId(String sysId) {
this.sysId = sysId;
}
public int getSyncDirty() {
return syncDirty;
}
public void setSyncDirty(int syncDirty) {
this.syncDirty = syncDirty;
}
public static final class CatalogueItemInputBuilder {
private long id = -1;
private long catalogueItemId;
private String data;
private String sysId;
private int syncDirty;
private CatalogueItemInputBuilder() {
}
public static CatalogueItemInputBuilder aCatalogueItemInput() {
return new CatalogueItemInputBuilder();
}
public CatalogueItemInputBuilder setId(long id) {
this.id = id;
return this;
}
public CatalogueItemInputBuilder setCatalogueItemId(long catalogueItemId) {
this.catalogueItemId = catalogueItemId;
return this;
}
public CatalogueItemInputBuilder setData(String data) {
this.data = data;
return this;
}
public CatalogueItemInputBuilder setSysId(String sysId) {
this.sysId = sysId;
return this;
}
public CatalogueItemInputBuilder setSyncDirty(int syncDirty) {
this.syncDirty = syncDirty;
return this;
}
public CatalogueItemInputBuilder but() {
return aCatalogueItemInput().setId(id).setCatalogueItemId(catalogueItemId).setData(data).setSysId(sysId).setSyncDirty(syncDirty);
}
public CatalogueItemInput build() {
CatalogueItemInput catalogueItemInput = new CatalogueItemInput();
catalogueItemInput.setId(id);
catalogueItemInput.setCatalogueItemId(catalogueItemId);
catalogueItemInput.setData(data);
catalogueItemInput.setSysId(sysId);
catalogueItemInput.setSyncDirty(syncDirty);
return catalogueItemInput;
}
}
@Override
public String toString() {
return "CatalogueItemInput{" +
"id=" + id +
", catalogueItemId=" + catalogueItemId +
", data='" + data + '\'' +
", sysId='" + sysId + '\'' +
", syncDirty=" + syncDirty +
'}';
}
}
......@@ -45,6 +45,12 @@ public class CatalogueVariable {
@SerializedName("reference_display_column")
@Expose
private String referenceColumnName;
@SerializedName("Active")
@Expose
private boolean active;
@SerializedName("default_value")
@Expose
private String defaultValue;
// @SerializedName("type")
// @Expose
......@@ -181,6 +187,26 @@ public class CatalogueVariable {
this.referenceColumnName = referenceColumnName;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public boolean getActive() {
return active;
}
public String getDefaultValue() {
return defaultValue;
}
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}
public int getSyncDirty() {
return syncDirty;
}
......@@ -197,9 +223,23 @@ public class CatalogueVariable {
this.mVariableChoiceList = mVariableChoiceList;
}
public String[] getDisplayChoiceText(Context context, boolean isNoneRequired) {
public String[] getDisplayChoiceText(Context context) {
String[] choiceText;
if(isNoneRequired) {
if(defaultValue!=null) {
choiceText = new String[mVariableChoiceList.size() + 1];
choiceText[0] = defaultValue;
for (int i = 0; i < mVariableChoiceList.size(); i++) {
VariableChoice variableChoice = mVariableChoiceList.get(i);
/*(i+1) for add None text as a first Element*/
if(variableChoice.getMisc() > 0) {
choiceText[i + 1] = String.format(context.getString(R.string.variable_form_misc_info_string),
variableChoice.getText(),
variableChoice.getMisc());
} else {
choiceText[i + 1] = variableChoice.getText();
}
}
} else if(isNoneRequired) {
choiceText = new String[mVariableChoiceList.size() + 1];
choiceText[0] = context.getString(R.string.none_string);
for (int i = 0; i < mVariableChoiceList.size(); i++) {
......@@ -229,6 +269,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 {
......@@ -246,11 +296,13 @@ public class CatalogueVariable {
private String name;
private String questionText;
private String sysId;
private boolean isNoneRequired;
private boolean mandatory;
private String referenceTable;
private boolean isNoneRequired;
private int order;
private String referenceColumnName;
private boolean active;
private String defaultValue;
private ViewType type;
private int syncDirty;
......@@ -266,8 +318,8 @@ public class CatalogueVariable {
return this;
}
public CatalogueVariableBuilder setCatalogueItemId(long catalogue_item_id) {
this.catalogue_item_id = catalogue_item_id;
public CatalogueVariableBuilder setCatalogueItemId(long catalogueItemId) {
this.catalogue_item_id = catalogueItemId;
return this;
}
......@@ -286,17 +338,22 @@ public class CatalogueVariable {
return this;
}
public CatalogueVariableBuilder setMandatory(boolean mandatory) {
this.mandatory = mandatory;
return this;
}
public CatalogueVariableBuilder setNoneRequired(boolean noneRequired) {
this.isNoneRequired = noneRequired;
return this;
}
public CatalogueVariableBuilder setMandatory(boolean mandatory) {
this.mandatory = mandatory;
public CatalogueVariableBuilder setReferenceTable(String referenceTable) {
this.referenceTable = referenceTable;
return this;
}
public CatalogueVariableBuilder setReferenceTable(String referenceTable) {
public CatalogueVariableBuilder setNo(String referenceTable) {
this.referenceTable = referenceTable;
return this;
}
......@@ -311,6 +368,16 @@ public class CatalogueVariable {
return this;
}
public CatalogueVariableBuilder setActive(boolean active) {
this.active = active;
return this;
}
public CatalogueVariableBuilder setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
return this;
}
public CatalogueVariableBuilder setType(ViewType type) {
this.type = type;
return this;
......@@ -322,7 +389,7 @@ public class CatalogueVariable {
}
public CatalogueVariableBuilder but() {
return aCatalogueVariable().setId(id).setCatalogueItemId(catalogue_item_id).setName(name).setQuestionText(questionText).setSysId(sysId).setNoneRequired(isNoneRequired).setMandatory(mandatory).setReferenceTable(referenceTable).setOrder(order).setReferenceColumnName(referenceColumnName).setType(type).setSyncDirty(syncDirty);
return aCatalogueVariable().setId(id).setName(name).setQuestionText(questionText).setSysId(sysId).setMandatory(mandatory).setReferenceTable(referenceTable).setOrder(order).setReferenceColumnName(referenceColumnName).setActive(active).setDefaultValue(defaultValue).setType(type).setSyncDirty(syncDirty);
}
public CatalogueVariable build() {
......@@ -332,11 +399,13 @@ public class CatalogueVariable {
catalogueVariable.setName(name);
catalogueVariable.setQuestionText(questionText);
catalogueVariable.setSysId(sysId);
catalogueVariable.setNoneRequired(isNoneRequired);
catalogueVariable.setMandatory(mandatory);
catalogueVariable.setNoneRequired(isNoneRequired);
catalogueVariable.setReferenceTable(referenceTable);
catalogueVariable.setOrder(order);
catalogueVariable.setReferenceColumnName(referenceColumnName);
catalogueVariable.setActive(active);
catalogueVariable.setDefaultValue(defaultValue);
catalogueVariable.setType(type);
catalogueVariable.setSyncDirty(syncDirty);
return catalogueVariable;
......@@ -346,7 +415,9 @@ public class CatalogueVariable {
public static class Json {
public static final String SYS_ID = "sys_id";
public static final String TYPE = "type";
public static final String ORDER = "order";
/*Variable form attachment*/
public static final String TABLE_NAME_VALUE = "sc_req_item";
}
@Override
......@@ -362,6 +433,8 @@ public class CatalogueVariable {
", referenceTable='" + referenceTable + '\'' +
", order=" + order +
", referenceColumnName='" + referenceColumnName + '\'' +
", active=" + active +
", defaultValue='" + defaultValue + '\'' +
", type=" + type +
", syncDirty=" + syncDirty +
", mVariableChoiceList=" + mVariableChoiceList +
......
......@@ -90,6 +90,17 @@ public class Incident {
this.setImpact(Impact.from(impact));
}
public JSONObject toJson(String jsonString) {
try {
JSONObject jsonObject = new JSONObject(jsonString);
jsonObject.put(Json.IMPACT, impact.getServerString());
return jsonObject;
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
public static final class IncidentBuilder {
private long id = -1;
private String number;
......@@ -158,7 +169,7 @@ public class Incident {
public static final String OPENED_AT = "opened_at";
public static final String SHORT_DESCRIPTION = "short_description";
public static final String CALLER_ID = "caller_id";
public static final String OPENED_ID = "opened_by";
public static final String NUMBER = "number";
}
@Override
......
......@@ -20,14 +20,21 @@ public class MyRequest {
@SerializedName("sys_updated_on")
// @Expose
private long updateOn;
@SerializedName("short_description")
@Expose
private String shortDescription;
@SerializedName("approval")
@Expose
String approval;
@SerializedName("cat_item")
@Expose
MyRequestShortDes shortDescription;
@SerializedName("request")
@Expose
MyRequestRequest request;
@SerializedName("opened_by")
@Expose
MyRequestRequest openedBy;
@SerializedName("stage")
@Expose
String stage;
private int syncDirty;
......@@ -38,7 +45,6 @@ public class MyRequest {
public void setId(long id) {
this.id = id;
}
public String getNumber() {
return number;
}
......@@ -55,11 +61,11 @@ public class MyRequest {
this.updateOn = updateOn;
}
public String getShortDescription() {
public MyRequestShortDes getShortDescription() {
return shortDescription;
}
public void setShortDescription(String shortDescription) {
public void setShortDescription(MyRequestShortDes shortDescription) {
this.shortDescription = shortDescription;
}
......@@ -71,6 +77,30 @@ public class MyRequest {
this.approval = approval;
}
public MyRequestRequest getRequest() {
return request;
}
public void setRequest(MyRequestRequest request) {
this.request = request;
}
public MyRequestRequest getOpenedBy() {
return openedBy;
}
public void setOpenedBy(MyRequestRequest openedBy) {
this.openedBy = openedBy;
}
public String getStage() {
return stage;
}
public void setStage(String stage) {
this.stage = stage;
}
public int getSyncDirty() {
return syncDirty;
}
......@@ -95,7 +125,7 @@ public class MyRequest {
private long id = -1;
private String number;
private long updateOn;
private String shortDescription;
private MyRequestShortDes shortDescription;
private int syncDirty;
private MyRequestBuilder() {
......@@ -120,7 +150,7 @@ public class MyRequest {
return this;
}
public MyRequestBuilder setShortDescription(String shortDescription) {
public MyRequestBuilder setShortDescription(MyRequestShortDes shortDescription) {
this.shortDescription = shortDescription;
return this;
}
......@@ -156,15 +186,4 @@ public class MyRequest {
public static final String DUE_DATE = "sys_updated_on";
}
@Override
public String toString() {
return "MyRequest{" +
"id=" + id +
", number='" + number + '\'' +
", updateOn=" + updateOn +
", shortDescription='" + shortDescription + '\'' +
", approval='" + approval + '\'' +
", syncDirty=" + syncDirty +
'}';
}
}
package com.vsoft.uoflservicenow.db.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* Created by kvemulavada on 8/30/2016.
*/
public class MyRequestOpenedBy {
@SerializedName("display_value")
@Expose
private String displayValue;
@SerializedName("link")
@Expose
private String link;
public String getDisplayValue() {
return displayValue;
}
public void setDisplayValue(String displayValue) {
this.displayValue = displayValue;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
}
package com.vsoft.uoflservicenow.db.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* Created by kvemulavada on 8/30/2016.
*/
public class MyRequestRequest {
@SerializedName("display_value")
@Expose
private String displayValue;
@SerializedName("link")
@Expose
private String link;
public String getDisplayValue() {
return displayValue;
}
public void setDisplayValue(String displayValue) {
this.displayValue = displayValue;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
}
package com.vsoft.uoflservicenow.db.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* Created by kvemulavada on 8/30/2016.
*/
public class MyRequestShortDes {
@SerializedName("display_value")
@Expose
private String displayValue;
@SerializedName("link")
@Expose
private String link;
public String getDisplayValue() {
return displayValue;
}
public void setDisplayValue(String displayValue) {
this.displayValue = displayValue;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
}
package com.vsoft.uoflservicenow.db.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class UiPolicyAction {
private long id = -1;
private long uiPolicyItemId = -1;
@SerializedName("visible")
@Expose
private String visible;
@SerializedName("mandatory")
@Expose
private String mandatory;
@SerializedName("variable")
@Expose
private String variableName;
@SerializedName("disabled")
@Expose
private String disabled;
private int syncDirty;
public long getUiPolicyItemId() {
return uiPolicyItemId;
}
public void setUiPolicyItemId(long uiPolicyItemId) {
this.uiPolicyItemId = uiPolicyItemId;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
/**
*
* @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;
}
public int getSyncDirty() {
return syncDirty;
}
public void setSyncDirty(int syncDirty) {
this.syncDirty = syncDirty;
}
public static final class UiPolicyActionBuilder {
private long id = -1;
private long uiPolicyItemId = -1;
private String visible;
private String mandatory;
private String variableName;
private String disabled;
private int syncDirty;
private UiPolicyActionBuilder() {
}
public static UiPolicyActionBuilder anUiPolicyAction() {
return new UiPolicyActionBuilder();
}
public UiPolicyActionBuilder setId(long id) {
this.id = id;
return this;
}
public UiPolicyActionBuilder setUiPolicyItemId(long uiPolicyItemId) {
this.uiPolicyItemId = uiPolicyItemId;
return this;
}
public UiPolicyActionBuilder setVisible(String visible) {
this.visible = visible;
return this;
}
public UiPolicyActionBuilder setMandatory(String mandatory) {
this.mandatory = mandatory;
return this;
}
public UiPolicyActionBuilder setVariableName(String variableName) {
this.variableName = variableName;
return this;
}
public UiPolicyActionBuilder setDisabled(String disabled) {
this.disabled = disabled;
return this;
}
public UiPolicyActionBuilder setSyncDirty(int syncDirty) {
this.syncDirty = syncDirty;
return this;
}
public UiPolicyActionBuilder but() {
return anUiPolicyAction().setId(id).setUiPolicyItemId(uiPolicyItemId).setVisible(visible).setMandatory(mandatory).setVariableName(variableName).setDisabled(disabled).setSyncDirty(syncDirty);
}
public UiPolicyAction build() {
UiPolicyAction uiPolicyAction = new UiPolicyAction();
uiPolicyAction.setId(id);
uiPolicyAction.setUiPolicyItemId(uiPolicyItemId);
uiPolicyAction.setVisible(visible);
uiPolicyAction.setMandatory(mandatory);
uiPolicyAction.setVariableName(variableName);
uiPolicyAction.setDisabled(disabled);
uiPolicyAction.setSyncDirty(syncDirty);
return uiPolicyAction;
}
}
@Override
public String toString() {
return "UiPolicyAction{" +
"id=" + id +
", uiPolicyItemId=" + uiPolicyItemId +
", visible='" + visible + '\'' +
", mandatory='" + mandatory + '\'' +
", variableName='" + variableName + '\'' +
", disabled='" + disabled + '\'' +
", syncDirty=" + syncDirty +
'}';
}
}
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 long id = -1;
private long catalogueItemId = -1;
private List<UiPolicyAction> uiPolicyActions;
private List<PartialCondition> partialConditions;
@SerializedName("condition")
@Expose
private String condition;
@SerializedName("sys_id")
@Expose
private String sysId;
private int syncDirty;
public int getSyncDirty() {
return syncDirty;
}
public void setSyncDirty(int syncDirty) {
this.syncDirty = syncDirty;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getCatalogueItemId() {
return catalogueItemId;
}
public void setCatalogueItemId(long catalogueItemId) {
this.catalogueItemId = catalogueItemId;
}
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;
}
/**
*
* @return
* The sysId
*/
public String getSysId() {
return sysId;
}
/**
*
* @param sysId
* The sysId
*/
public void setSysId(String sysId) {
this.sysId = sysId;
}
public static final class UiPolicyItemBuilder {
private long catalogueItemId = -1;
private long id = -1;
private String condition;
private String sysId;
private int syncDirty;
private UiPolicyItemBuilder() {
}
public static UiPolicyItemBuilder anUiPolicyItem() {
return new UiPolicyItemBuilder();
}
public UiPolicyItemBuilder setCatalogueItemId(long catalogueItemId) {
this.catalogueItemId = catalogueItemId;
return this;
}
public UiPolicyItemBuilder setId(long id) {
this.id = id;
return this;
}
public UiPolicyItemBuilder setCondition(String condition) {
this.condition = condition;
return this;
}
public UiPolicyItemBuilder setSysId(String sysId) {
this.sysId = sysId;
return this;
}
public UiPolicyItemBuilder setSyncDirty(int syncDirty) {
this.syncDirty = syncDirty;
return this;
}
public UiPolicyItemBuilder but() {
return anUiPolicyItem().setCatalogueItemId(catalogueItemId).setId(id).setCondition(condition).setSysId(sysId).setSyncDirty(syncDirty);
}
public UiPolicyItem build() {
UiPolicyItem uiPolicyItem = new UiPolicyItem();
uiPolicyItem.setCatalogueItemId(catalogueItemId);
uiPolicyItem.setId(id);
uiPolicyItem.setCondition(condition);
uiPolicyItem.setSysId(sysId);
uiPolicyItem.setSyncDirty(syncDirty);
return uiPolicyItem;
}
}
@Override
public String toString() {
return "UiPolicyItem{" +
"id=" + id +
", catalogueItemId=" + catalogueItemId +
", uiPolicyActions=" + uiPolicyActions +
", partialConditions=" + partialConditions +
", condition='" + condition + '\'' +
", sysId='" + sysId + '\'' +
", syncDirty='" + syncDirty + '\'' +
'}';
}
}
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;
}
}
......@@ -14,6 +14,7 @@ import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.ArrayAdapter;
import android.widget.EditText;
......@@ -27,6 +28,7 @@ import com.vsoft.uoflservicenow.api.managers.VariableChoiceApiManager;
import com.vsoft.uoflservicenow.db.models.Reference;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.listeners.ReferenceListener;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.Util;
......@@ -49,12 +51,10 @@ import butterknife.Unbinder;
*/
public class SelectReferenceDialog extends DialogFragment {
@BindView(R.id.dialog_list_view)
ListView mListView;
@BindView(R.id.dialog_title)
TextView mTitleTextView;
@BindView(R.id.dialog_edit_text)
EditText mEditText;
@BindView(R.id.reference_search_dialog_list_view) ListView mListView;
@BindView(R.id.reference_search_dialog_title) TextView mTitleTextView;
@BindView(R.id.reference_search_dialog_no_result_tv) TextView mNoResultTextView;
@BindView(R.id.reference_search_dialog_edit_text) EditText mEditText;
private ReferenceListener mListener;
private Unbinder mUnbinder;
......@@ -63,7 +63,6 @@ public class SelectReferenceDialog extends DialogFragment {
private CatalogueApplication mApplication;
public SelectReferenceDialog() {
}
public void setListener(ReferenceListener listener) {
......@@ -106,7 +105,7 @@ public class SelectReferenceDialog extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.custom_dialog, container, false);
View rootView = inflater.inflate(R.layout.reference_search_dialog, container, false);
mUnbinder = ButterKnife.bind(this, rootView);
mTitleTextView.setText(String.format(getString(R.string.variable_form_reference_dialog_title_string), mReferenceTitle));
......@@ -115,7 +114,13 @@ public class SelectReferenceDialog extends DialogFragment {
return rootView;
}
@OnTouch(R.id.dialog_edit_text)
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
@OnTouch(R.id.reference_search_dialog_edit_text)
boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_RIGHT = 2;
Drawable drawable = mEditText.getCompoundDrawables()[DRAWABLE_RIGHT];
......@@ -136,9 +141,10 @@ public class SelectReferenceDialog extends DialogFragment {
getDialog().dismiss();
}
@OnItemClick(R.id.dialog_list_view)
@OnItemClick(R.id.reference_search_dialog_list_view)
void listViewItemClick(int position) {
Reference reference = mReferenceList.get(position);
CatalogueLog.e("SelectReferenceDialog: mListener: "+mListener);
if (reference != null)
mListener.positiveButtonClick(reference);
else
......@@ -146,7 +152,7 @@ public class SelectReferenceDialog extends DialogFragment {
getDialog().dismiss();
}
@OnEditorAction(R.id.dialog_edit_text)
@OnEditorAction(R.id.reference_search_dialog_edit_text)
boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
Util.hideSoftKeyboard(getActivity(), v);
......@@ -164,6 +170,7 @@ public class SelectReferenceDialog extends DialogFragment {
class FetchReference extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
private SyncStatus syncStatus;
@Override
protected void onPreExecute() {
......@@ -177,13 +184,21 @@ public class SelectReferenceDialog extends DialogFragment {
@Override
protected SyncStatus doInBackground(String... params) {
Map<String, String> stringMap = new HashMap<>(1);
stringMap.put(mReferenceColumnName, params[0]);
return VariableChoiceApiManager.getReference(mReferenceTableName, stringMap, new GetReferenceApiListener() {
stringMap.put(Constants.URL_PARAM_SYSPRM_FIELDS, "sys_id,"+mReferenceColumnName);
stringMap.put(Constants.URL_PARAM_SYSPRM_QUERY, mReferenceColumnName+"LIKE"+params[0]);
VariableChoiceApiManager.getReference(mReferenceTableName, stringMap, new GetReferenceApiListener() {
@Override
public void onDoneApiCall(List<Reference> referenceList) {
syncStatus = SyncStatus.SUCCESS;
mReferenceList = referenceList;
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
}
@Override
......@@ -193,11 +208,19 @@ public class SelectReferenceDialog extends DialogFragment {
progressDialog.dismiss();
}
if (syncStatus == SyncStatus.SUCCESS) {
List<String> stringList = getReferenceForDisplay();
if(stringList.isEmpty()) {
mNoResultTextView.setVisibility(View.VISIBLE);
mListView.setVisibility(View.GONE);
} else {
mListView.setVisibility(View.VISIBLE);
mNoResultTextView.setVisibility(View.GONE);
ArrayAdapter<String> adapter = new ArrayAdapter(getActivity(),
android.R.layout.simple_list_item_1,
android.R.id.text1,
getReferenceForDisplay());
mListView.setAdapter(adapter);
}
} else {
showErrorDialog(R.string.failed_to_fetch_reference_string);
}
......
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;
}
}
......@@ -7,8 +7,7 @@ package com.vsoft.uoflservicenow.enums;
*/
public enum SyncStatus {
SUCCESS (1),
FAIL (2),
SERVICEDOWN (3);
FAIL (2);
int id;
......
package com.vsoft.uoflservicenow.service;
import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import com.vsoft.uoflservicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.api.listeners.post.PostAttachmentApiListener;
import com.vsoft.uoflservicenow.api.listeners.post.PostIncidentApiListener;
import com.vsoft.uoflservicenow.api.listeners.post.PostVariableFormApiListener;
import com.vsoft.uoflservicenow.api.managers.CatalogueVariableApiManager;
import com.vsoft.uoflservicenow.api.managers.IncidentApiManager;
import com.vsoft.uoflservicenow.db.managers.AttachmentManager;
import com.vsoft.uoflservicenow.db.managers.CatalogueItemInputManager;
import com.vsoft.uoflservicenow.db.managers.CatalogueItemManager;
import com.vsoft.uoflservicenow.db.managers.ReportIncidentValueManager;
import com.vsoft.uoflservicenow.db.models.Attachment;
import com.vsoft.uoflservicenow.db.models.CatalogueItem;
import com.vsoft.uoflservicenow.db.models.CatalogueItemInput;
import com.vsoft.uoflservicenow.db.models.Incident;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DBConstants;
import com.vsoft.uoflservicenow.utils.PrefManager;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import static com.vsoft.uoflservicenow.db.managers.CatalogueItemInputManager.getDirtyItemInput;
import static com.vsoft.uoflservicenow.utils.DBConstants.CATALOGUE_ITEM_INPUT_SYS_ID;
import static com.vsoft.uoflservicenow.utils.DBConstants.INCIDENT_INPUT_NUMBER;
import static com.vsoft.uoflservicenow.utils.DBConstants.SYNC_FLAG_NONE;
/**
* @author Kunj
*/
public class SyncService extends IntentService {
private SyncStatus syncStatus = SyncStatus.FAIL;
public SyncService() {
super(SyncService.class.getSimpleName());
}
@Override
protected void onHandleIntent(Intent intent) {
CatalogueApplication mApplication = (CatalogueApplication) getApplication();
if(!mApplication.isNetConnected()) {
CatalogueLog.e("SyncService: onHandleIntent(): Not connected to net. Exit.");
return;
}
startSync();
}
private void startSync() {
CatalogueLog.d("---- START SyncService START ----");
SyncStatus result;
/*First we will work on dirty variable form*/
List<CatalogueItemInput> catalogueItemInputList = getDirtyItemInput();
if(Constants.DEBUG) CatalogueLog.d("startSync: catalogue form to sync: "+catalogueItemInputList.size());
for (int i = 0; i < catalogueItemInputList.size(); i++) {
CatalogueItemInput catalogueItemInput = catalogueItemInputList.get(i);
result = syncVariableForm(catalogueItemInput);
if(Constants.DEBUG) CatalogueLog.d("startSync: result of syncing catalogueItemInput "+i+": "+result);
}
/*Then we will work on dirty incident form*/
List<Incident> incidentInputList = ReportIncidentValueManager.getDirtyIncident();
if(Constants.DEBUG) CatalogueLog.d("startSync: incident form to sync: "+incidentInputList.size());
for (int i = 0; i < incidentInputList.size(); i++) {
Incident incident = incidentInputList.get(i);
result = syncIncidentForm(incident);
if(Constants.DEBUG) CatalogueLog.d("startSync: result of syncing incidentInput "+i+": "+result);
}
}
/**
* Sync VariableForm
**/
private SyncStatus syncVariableForm(final CatalogueItemInput catalogueItemInput) {
CatalogueLog.d( "syncVariableForm");
if(catalogueItemInput.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE || catalogueItemInput.getSysId() == null || catalogueItemInput.getSysId().isEmpty()) {
final CatalogueItem catalogueItem = CatalogueItemManager.get(catalogueItemInput.getCatalogueItemId());
CatalogueVariableApiManager.submitVariableForm(catalogueItem.getSysId(), catalogueItemInput.getData(), new PostVariableFormApiListener() {
@Override
public void onDoneApiCall(String variableFromSysId) {
syncStatus = SyncStatus.SUCCESS;
CatalogueLog.e("syncVariableForm: saveVariableForm: result is SUCCESS");
catalogueItemInput.setSysId(variableFromSysId);
CatalogueItemInputManager.handleSaveServerResponse(catalogueItemInput, Collections.singletonList(CATALOGUE_ITEM_INPUT_SYS_ID), SYNC_FLAG_NONE);
CatalogueItemInput localCatalogueItemInput = CatalogueItemInputManager.getItemInputFromSysId(variableFromSysId);
List<Attachment> attachmentList = AttachmentManager.getDirtyAttachment(localCatalogueItemInput.getId());
for (int i = 0; i < attachmentList.size(); i++) {
Attachment attachment = attachmentList.get(i);
syncAttachment(attachment, variableFromSysId);
}
}
@Override
public void onFailApiCall() {
CatalogueLog.e("syncVariableForm: saveVariableForm: result is FAIL");
syncStatus = SyncStatus.FAIL;
}
});
}
return syncStatus;
}
/**
* Sync Attachment
**/
private SyncStatus syncAttachment(final Attachment attachment, String itemInputSysId) {
CatalogueLog.d( "syncAttachment");
if(attachment.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE) {
if (attachment.getMimeType() != null) {
InputStream in = null;
try {
in = new FileInputStream(new File(attachment.getPath()));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
byte[] buf = null;
try {
buf = new byte[in.available()];
while (in.read(buf) != -1) ;
} catch (IOException e) {
e.printStackTrace();
}
RequestBody requestBody = RequestBody.create(MediaType.parse(attachment.getMimeType()), buf);
CatalogueVariableApiManager.postAttachment(attachment.getMimeType(), itemInputSysId,
attachment.getName(), requestBody, new PostAttachmentApiListener() {
@Override
public void onDoneApiCall() {
syncStatus = SyncStatus.SUCCESS;
CatalogueLog.e("syncVariableForm: postAttachment: result is SUCCESS");
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
CatalogueLog.e("syncVariableForm: postAttachment: result is FAIL");
}
});
}
}
return syncStatus;
}
/**
* Sync Incident form
**/
private SyncStatus syncIncidentForm(final Incident incident) {
CatalogueLog.d( "syncVariableForm");
SharedPreferences sharedPreferences = getSharedPreferences(PrefManager.PREFERENCES_USER_VALUES_KEY, Context.MODE_PRIVATE);
String userSysId = sharedPreferences.getString(PrefManager.PREFERENCE_SYS_ID, "");
if(incident.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE || incident.getNumber() == null || incident.getNumber().isEmpty()) {
IncidentApiManager.submitIncidentForm(incident, userSysId, new PostIncidentApiListener() {
@Override
public void onDoneApiCall(String incidentNumber) {
syncStatus = SyncStatus.SUCCESS;
CatalogueLog.e("syncIncidentForm: saveIncidentForm: result is SUCCESS");
incident.setNumber(incidentNumber);
ReportIncidentValueManager.handleSaveServerResponse(incident, Collections.singletonList(INCIDENT_INPUT_NUMBER), SYNC_FLAG_NONE);
}
@Override
public void onFailApiCall() {
CatalogueLog.e("syncVariableForm: saveIncidentForm: result is FAIL");
syncStatus = SyncStatus.FAIL;
}
});
}
return syncStatus;
}
}
......@@ -31,6 +31,8 @@ import com.vsoft.uoflservicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.Util;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import butterknife.BindView;
......@@ -56,16 +58,17 @@ public class CatalogueItemScreen extends AppCompatActivity {
ButterKnife.bind(this);
CatalogueApplication application = (CatalogueApplication) getApplication();
Bundle extras = getIntent().getExtras();
String catalogueSysId = null;
if (extras != null) {
catalogueSysId = extras.getString(Constants.DATA_KEY_SYS_ID);
//The key argument here must match that used in the other activity
String catalogueSysId = getIntent().getExtras().getString(Constants.DATA_KEY_SYS_ID);
String catalogueTitle = getIntent().getExtras().getString(Constants.DATA_KEY_CATALOGUE_TITLE);
if (catalogueSysId == null) {
CatalogueLog.e("CatalogueItemScreen: catalogueSysId is null");
}
mCatalogue = CatalogueManager.getCatalogueFromSysId(catalogueSysId);
if(mCatalogue == null) {
CatalogueLog.e("CatalogueItemScreen: onCreate: mCatalogue is null");
finish();
return;
}
......@@ -74,7 +77,7 @@ public class CatalogueItemScreen extends AppCompatActivity {
if(actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setElevation(0);
actionBar.setTitle(mCatalogue.getTitle());
actionBar.setTitle(catalogueTitle);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
}
......@@ -97,6 +100,7 @@ public class CatalogueItemScreen extends AppCompatActivity {
class FetchCatalogueItem extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
private SyncStatus syncStatus;
@Override
protected void onPreExecute() {
......@@ -109,13 +113,20 @@ public class CatalogueItemScreen extends AppCompatActivity {
@Override
protected SyncStatus doInBackground(String... params) {
return CatalogueItemApiManager.getCatalogueItems(mCatalogue.getSysId(), new GetCatalogueItemApiListener() {
CatalogueItemApiManager.getCatalogueItems(mCatalogue.getSysId(), new GetCatalogueItemApiListener() {
@Override
public void onDoneApiCall(List<CatalogueItem> catalogueItemList) {
syncStatus = SyncStatus.SUCCESS;
CatalogueLog.e("Data: catalogueItemList: "+catalogueItemList);
CatalogueItemManager.handleGetCatalogueItem(mCatalogue.getId(), catalogueItemList);
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
}
@Override
......@@ -133,6 +144,15 @@ public class CatalogueItemScreen extends AppCompatActivity {
}
private void setData(final List<CatalogueItem> catalogueItemList) {
if (!catalogueItemList.isEmpty()) {
/*Sort catalogue items list alphabetically*/
Collections.sort(catalogueItemList, new Comparator<CatalogueItem>() {
@Override
public int compare(CatalogueItem lhs, CatalogueItem rhs) {
return lhs.getName().compareToIgnoreCase(rhs.getName());
}
});
}
if(!catalogueItemList.isEmpty()) {
mListView.setVisibility(View.VISIBLE);
mEmptyTextView.setVisibility(View.GONE);
......@@ -145,9 +165,12 @@ public class CatalogueItemScreen extends AppCompatActivity {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
CatalogueLog.e("OnItemClickListener: position: " + position + ", Catalogue: " + catalogueItemList.get(position));
CatalogueItem catalogueItem = catalogueItemList.get(position);
Intent intent = new Intent(CatalogueItemScreen.this, CatalogueVariableScreen.class);
intent.putExtra(Constants.DATA_KEY_SYS_ID, catalogueItemList.get(position).getSysId());
intent.putExtra(Constants.DATA_KEY_SYS_ID, catalogueItem.getSysId());
intent.putExtra(Constants.DATA_KEY_CATALOGUE_ITEM_DESCRIPTION, catalogueItem.getDescription());
intent.putExtra(Constants.DATA_KEY_CATALOGUE_ITEM_SHORT_DESCRIPTION, catalogueItem.getShortDescription());
intent.putExtra(Constants.DATA_KEY_CATALOGUE_TITLE, catalogueItem.getName());
startActivity(intent);
}
});
......
......@@ -28,6 +28,8 @@ import com.vsoft.uoflservicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.Util;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import butterknife.BindView;
......@@ -79,6 +81,7 @@ public class CatalogueScreen extends AppCompatActivity {
class FetchCatalogue extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
private SyncStatus syncStatus = SyncStatus.FAIL;
@Override
protected void onPreExecute() {
......@@ -91,13 +94,20 @@ public class CatalogueScreen extends AppCompatActivity {
@Override
protected SyncStatus doInBackground(String... params) {
return CatalogueApiManager.getCatalogues(new GetCatalogueApiListener() {
CatalogueApiManager.getCatalogues(new GetCatalogueApiListener() {
@Override
public void onDoneApiCall(List<Catalogue> catalogueList) {
syncStatus = SyncStatus.SUCCESS;
CatalogueLog.e("Data: catalogueList: "+catalogueList);
CatalogueManager.handleGetCatalogue(catalogueList);
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
}
@Override
......@@ -115,6 +125,13 @@ public class CatalogueScreen extends AppCompatActivity {
}
private void setData(final List<Catalogue> catalogueList) {
/*Sort catalogue list alphabetically*/
Collections.sort(catalogueList, new Comparator<Catalogue>() {
@Override
public int compare(Catalogue lhs, Catalogue rhs) {
return lhs.getTitle().compareToIgnoreCase(rhs.getTitle());
}
});
CatalogueCategoryAdapter adapter = new CatalogueCategoryAdapter(CatalogueScreen.this);
adapter.setCatalogueList(catalogueList);
mListView.setAdapter(adapter);
......@@ -127,6 +144,7 @@ public class CatalogueScreen extends AppCompatActivity {
CatalogueLog.e("OnItemClickListener: position: "+position + ", Catalogue: "+catalogueList.get(position));
Intent intent = new Intent(CatalogueScreen.this, CatalogueItemScreen.class);
intent.putExtra(Constants.DATA_KEY_SYS_ID, catalogueList.get(position).getSysId());
intent.putExtra(Constants.DATA_KEY_CATALOGUE_TITLE, catalogueList.get(position).getTitle());
startActivity(intent);
}
});
......
package com.vsoft.uoflservicenow.ui;
import android.Manifest;
import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.app.TimePickerDialog;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
......@@ -16,14 +31,21 @@ import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
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;
......@@ -32,18 +54,32 @@ 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.PostAttachmentApiListener;
import com.vsoft.uoflservicenow.api.listeners.post.PostVariableFormApiListener;
import com.vsoft.uoflservicenow.api.managers.CatalogueVariableApiManager;
import com.vsoft.uoflservicenow.api.managers.VariableChoiceApiManager;
import com.vsoft.uoflservicenow.api.managers.VariableChoiceManager;
import com.vsoft.uoflservicenow.db.managers.AttachmentManager;
import com.vsoft.uoflservicenow.db.managers.CatalogueItemManager;
import com.vsoft.uoflservicenow.db.managers.CatalogueVariableManager;
import com.vsoft.uoflservicenow.db.managers.CatalogueVariableValueManager;
import com.vsoft.uoflservicenow.db.managers.CatalogueItemInputManager;
import com.vsoft.uoflservicenow.db.managers.UiPolicyActionManager;
import com.vsoft.uoflservicenow.db.managers.UiPolicyItemManager;
import com.vsoft.uoflservicenow.db.models.Attachment;
import com.vsoft.uoflservicenow.db.models.Catalogue;
import com.vsoft.uoflservicenow.db.models.CatalogueItem;
import com.vsoft.uoflservicenow.db.models.CatalogueItemInput;
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;
......@@ -52,15 +88,20 @@ import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DBConstants;
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;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
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;
......@@ -72,15 +113,21 @@ import butterknife.OnClick;
public class CatalogueVariableScreen extends AppCompatActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.variable_screen_back_text_view) TextView mBackTextView;
@BindView(R.id.variable_screen_submit_text_view) TextView mSubmitTextView;
@BindView(R.id.variable_screen_container_layout) LinearLayout mContainerLayout;
@BindView(R.id.variable_screen_bottom_layout) RelativeLayout mBottomLayout;
private CatalogueItem mCatalogueItem;
private List<CatalogueVariable> mCatalogueVariableList;
private JSONArray mJsonArray;
private List<CatalogueVariable> mCatalogueVariableList = new ArrayList<>();
private CatalogueApplication mApplication;
private String mCatalogueItemDescription, mCatalogueItemShortDescription, mCatalogueItemTitle;
private HashMap<CatalogueVariable, VariableViewContainer> mVariableViewMap;
private static final int WRITE_EXTERNAL_STORAGE = 1;
private static final int FILE_SELECT_CODE = 0;
private TextView mAttachmentTextView;
private SyncStatus mSyncStatus;
private CatalogueItem mCatalogueItem;
private Attachment mAttachment;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -97,12 +144,16 @@ public class CatalogueVariableScreen extends AppCompatActivity {
String catalogueItemSysId = null;
if (extras != null) {
catalogueItemSysId = extras.getString(Constants.DATA_KEY_SYS_ID);
mCatalogueItemDescription = extras.getString(Constants.DATA_KEY_CATALOGUE_ITEM_DESCRIPTION);
mCatalogueItemShortDescription = extras.getString(Constants.DATA_KEY_CATALOGUE_ITEM_SHORT_DESCRIPTION);
mCatalogueItemTitle = extras.getString(Constants.DATA_KEY_CATALOGUE_TITLE);
//The key argument here must match that used in the other activity
}
mCatalogueItem = CatalogueItemManager.getCatalogueItemFromSysId(catalogueItemSysId);
if (mCatalogueItem == null) {
CatalogueLog.e("CatalogueVariableScreen: onCreate: mCatalogueItem is null");
finish();
return;
}
......@@ -111,32 +162,31 @@ public class CatalogueVariableScreen extends AppCompatActivity {
if(actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setElevation(0);
actionBar.setTitle(mCatalogueItem.getName());
actionBar.setTitle(R.string.variable_form_header_string);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
}
Tracker tracker = mApplication.getDefaultTracker();
// Send initial screen view hit.
Util.sendScreenName(tracker, actionBar.getTitle().toString());
mCatalogueVariableList = CatalogueVariableManager.getAllVariable(mCatalogueItem.getId());
setVariableChoices();
if (mCatalogueVariableList.isEmpty()) {
if(mApplication.isNetConnected()) {
if (mApplication.isNetConnected()) {
new FetchCatalogueVariable().execute();
} else {
DialogUtils.showNoConnectionDialogWithCloseActivity(CatalogueVariableScreen.this);
}
} else {
createView();
runUIPolicyActions(null);
}
Tracker tracker = mApplication.getDefaultTracker();
// Send initial screen view hit.
Util.sendScreenName(tracker, actionBar.getTitle().toString());
}
class FetchCatalogueVariable extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
SyncStatus syncStatus;
@Override
protected void onPreExecute() {
......@@ -148,31 +198,76 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
@Override
protected SyncStatus doInBackground(String... params) {
syncStatus = CatalogueVariableApiManager.getCatalogueVariable(mCatalogueItem.getSysId(), new GetCatalogueVariableApiListener() {
protected SyncStatus doInBackground(final String... params) {
CatalogueVariableApiManager.getCatalogueVariable(mCatalogueItem.getSysId(), new GetCatalogueVariableApiListener() {
@Override
public void onDoneApiCall(List<CatalogueVariable> catalogueVariableList) {
CatalogueVariableManager.handleGetVariable(mCatalogueItem.getId(), catalogueVariableList);
if(!catalogueVariableList.isEmpty()) {
for (int i = 0; i < catalogueVariableList.size(); i++) {
final CatalogueVariable catalogueVariable = catalogueVariableList.get(i);
if (catalogueVariable.getType() == ViewType.MULTIPLE_CHOICE
|| catalogueVariable.getType() == ViewType.SELECT_BOX) {
/*Fetch multi choice variable values*/
VariableChoiceApiManager.getVariableChoice(catalogueVariable.getSysId(), new GetVariableChoiceApiListener() {
public void onDoneApiCall(List<CatalogueVariableSet> variableSetList, List<CatalogueVariable> variableList) {
mSyncStatus = SyncStatus.SUCCESS;
/*For variableset */
/*completeCatalogueVariableList is temporary list for getting all catalogue variable in a single list for local DB.*/
List<CatalogueVariable> completeCatalogueVariableList = new ArrayList<>();
for (int i = 0; i < variableSetList.size(); i++) {
CatalogueVariableSet catalogueVariableSet = variableSetList.get(i);
/*First we will add variableList from variableSet*/
completeCatalogueVariableList.addAll(catalogueVariableSet.getVariables());
mSyncStatus = fetchVariableChoiceData(catalogueVariableSet.getVariables());
if(mSyncStatus == SyncStatus.FAIL)
break;
}
/*After added first variableList then we will add other variableList*/
completeCatalogueVariableList.addAll(variableList);
CatalogueVariableManager.handleGetVariable(mCatalogueItem.getId(), completeCatalogueVariableList);
if(mSyncStatus != SyncStatus.FAIL) {
/*For variable list*/
mSyncStatus = fetchVariableChoiceData(variableList);
if(mSyncStatus != SyncStatus.FAIL) {
CatalogueVariableApiManager.getUiPolicy(mCatalogueItem.getSysId(), new GetUiPolicyApiListener() {
@Override
public void onDoneApiCall(List<VariableChoice> variableChoiceList) {
CatalogueLog.e("Data: variableChoiceList: " + variableChoiceList);
catalogueVariable.setVariableChoiceList(variableChoiceList);
VariableChoiceManager.handleGetVariableChoice(catalogueVariable.getId(), variableChoiceList);
public void onDoneApiCall(List<UiPolicyItem> uiPolicyItemList) {
/*Save UiPolicyItem in local DB*/
UiPolicyItemManager.handleGetUiPolicyItem(uiPolicyItemList, mCatalogueItem.getId());
/*Get all recently saved all items because we need local id of each item for save UiPolicyAction with respect to UiPolicyItem*/
List<UiPolicyItem> localUiPolicyItemList = UiPolicyItemManager.getAllUiPolicyItems(mCatalogueItem.getId());
for (int i = 0; i < uiPolicyItemList.size(); i++) {
UiPolicyItem uiPolicyItem = uiPolicyItemList.get(i);
for(int j = 0; j < localUiPolicyItemList.size(); j++) {
UiPolicyItem localUiPolicyItem = localUiPolicyItemList.get(j);
if(localUiPolicyItem.getSysId().equals(uiPolicyItem.getSysId())) {
localUiPolicyItem.setUiPolicyActions(uiPolicyItem.getUiPolicyActions());
}
}
}
mSyncStatus = SyncStatus.SUCCESS;
for (int i = 0; i < localUiPolicyItemList.size(); i++) {
UiPolicyItem uiPolicyItem = localUiPolicyItemList.get(i);
/*Save UiPolicyAction in local DB*/
UiPolicyActionManager.handleGetUiPolicyAction(uiPolicyItem.getUiPolicyActions(), uiPolicyItem.getId());
String condition = uiPolicyItem.getCondition();
if (condition != null) {
List<PartialCondition> partialConditionList = setPartialCondition(condition);
uiPolicyItem.setPartialConditions(partialConditionList);
}
}
}
@Override
public void onFailApiCall() {
mSyncStatus = SyncStatus.FAIL;
}
});
}
}
}
@Override
public void onFailApiCall() {
mSyncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
return mSyncStatus;
}
@Override
......@@ -183,12 +278,44 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
if(syncStatus == SyncStatus.SUCCESS) {
mCatalogueVariableList = CatalogueVariableManager.getAllVariable(mCatalogueItem.getId());
if (mCatalogueVariableList != null) {
setVariableChoices();
createView();
runUIPolicyActions(null);
}
} else {
showFetchVariableErrorDialog(R.string.failed_to_fetch_catalogue_form_string);
}
}
}
private List<PartialCondition> setPartialCondition(String condition) {
String[] splitStrings = condition.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 {
showErrorDialog(R.string.failed_to_fetch_catalogue_form_string);
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);
}
return partialConditionList;
}
private void setVariableChoices() {
......@@ -198,54 +325,111 @@ public class CatalogueVariableScreen extends AppCompatActivity {
if (catalogueVariable.getType() == ViewType.MULTIPLE_CHOICE
|| catalogueVariable.getType() == ViewType.SELECT_BOX) {
List<VariableChoice> variableChoiceList = VariableChoiceManager.getAllVariableChoices(catalogueVariable.getId());
/*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);
}
}
}
}
private SyncStatus fetchVariableChoiceData(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(catalogueVariable.getSysId(), new GetVariableChoiceApiListener() {
@Override
public void onDoneApiCall(List<VariableChoice> variableChoiceList) {
VariableChoiceManager.handleGetVariableChoice(catalogueVariable.getId(), variableChoiceList);
mSyncStatus = SyncStatus.SUCCESS;
}
@Override
public void onFailApiCall() {
mSyncStatus = SyncStatus.FAIL;
}
});
if(mSyncStatus == SyncStatus.FAIL)
break;
}
}
mCatalogueVariableList.addAll(variableList);
}
return mSyncStatus;
}
private void createView() {
if(!mCatalogueVariableList.isEmpty()) {
mBottomLayout.setVisibility(View.VISIBLE);
/*For variable list */
getCustomLayout();
if(!mCatalogueVariableList.isEmpty()) {
mBottomLayout.setVisibility(View.VISIBLE);
} else {
mBottomLayout.setVisibility(View.GONE);
}
}
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);
LinearLayout.LayoutParams childLabelViewLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
if(mCatalogueItemTitle != null && !mCatalogueItemTitle.isEmpty()) {
TextView headerView = new TextView(CatalogueVariableScreen.this);
headerView.setPadding(0, 0, 0, (int)getResources().getDimension(R.dimen.normal_margin));
headerView.setTypeface(null, Typeface.BOLD);
headerView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.normal_text_size));
headerView.setTextColor(ContextCompat.getColor(CatalogueVariableScreen.this, android.R.color.black));
headerView.setText(mCatalogueItemTitle);
mContainerLayout.addView(headerView, childControlViewLayoutParams);
}
/*Added item Description in form*/
if(mCatalogueItem.getShortDescription() != null && !mCatalogueItem.getShortDescription().isEmpty()) {
if(mCatalogueItemShortDescription != null && !mCatalogueItemShortDescription.isEmpty()) {
TextView shortDescriptionView = new TextView(CatalogueVariableScreen.this);
shortDescriptionView.setPadding(0, 0, 0, (int)getResources().getDimension(R.dimen.normal_margin));
shortDescriptionView.setTypeface(null, Typeface.BOLD);
shortDescriptionView.setTextColor(ContextCompat.getColor(CatalogueVariableScreen.this, android.R.color.black));
shortDescriptionView.setMovementMethod(LinkMovementMethod.getInstance());
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
shortDescriptionView.setText(Html.fromHtml(mCatalogueItem.getShortDescription(), Html.FROM_HTML_MODE_LEGACY));
shortDescriptionView.setText(Html.fromHtml(mCatalogueItemShortDescription, Html.FROM_HTML_MODE_LEGACY));
} else {
shortDescriptionView.setText(Html.fromHtml(mCatalogueItem.getShortDescription()));
shortDescriptionView.setText(Html.fromHtml(mCatalogueItemShortDescription));
}
mContainerLayout.addView(shortDescriptionView, childControlViewLayoutParams);
}
if(mCatalogueItem.getDescription() != null && !mCatalogueItem.getDescription().isEmpty()) {
if(mCatalogueItemDescription != null && !mCatalogueItemDescription.isEmpty()) {
/*Replace /r/n with blank string*/
StringBuilder builder = new StringBuilder();
builder.append(mCatalogueItemDescription.replaceAll("\r\n", "<br />"));
builder.append("\n");
builder.append(getString(R.string.Variable_form_short_description_anchor_line_break_css));
WebView descriptionView = new WebView(CatalogueVariableScreen.this);
descriptionView.loadData(mCatalogueItem.getDescription(), "text/html; charset=utf-8", "utf-8");
descriptionView.loadData(builder.toString(), "text/html; charset=UTF-8", "UTF-8");
mContainerLayout.addView(descriptionView, childControlViewLayoutParams);
}
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*/
if(catalogueVariable.isActive()) {
ViewType viewType = catalogueVariable.getType();
CatalogueLog.e("viewType: " + viewType + ", Question: "+catalogueVariable.getQuestionText() + ", Order: "+catalogueVariable.getOrder());
if (catalogueVariable.getName() == null) {
TextView nameNullView = new TextView(CatalogueVariableScreen.this);
nameNullView.setText(R.string.name_null_view_string);
......@@ -256,58 +440,76 @@ 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 if(viewType == ViewType.CONTAINER_END) {
/*In Container End, we need to add view for rendering*/
LinearLayout popLinearLayout;
if(stack!=null && !stack.isEmpty()) {
popLinearLayout = stack.pop();
if (popLinearLayout != null) {
if(stack!=null && !stack.isEmpty()) {
LinearLayout peekLinearLayout = stack.peek();
if (peekLinearLayout != null)
peekLinearLayout.addView(popLinearLayout);
} else {
/*Create label with mandatory value*/
LinearLayout labelLayout = new LinearLayout(CatalogueVariableScreen.this);
labelLayout.setOrientation(LinearLayout.HORIZONTAL);
TextView label = new TextView(CatalogueVariableScreen.this);
label.setText(catalogueVariable.getQuestionText());
childLabelViewLayoutParams.topMargin = (int) getResources().getDimension(R.dimen.small_margin);
labelLayout.addView(label, childLabelViewLayoutParams);
TextView mandatory = new TextView(CatalogueVariableScreen.this);
mandatory.setText("*");
mandatory.setTextColor(ContextCompat.getColor(CatalogueVariableScreen.this, R.color.error_color));
labelLayout.addView(mandatory);
mContainerLayout.addView(labelLayout);
mContainerLayout.addView(popLinearLayout);
}
}
}
} 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) {
controlView.setOnClickListener(dateTimeListener);
} else if (viewType == ViewType.REFERENCE) {
controlView.setOnTouchListener(referenceListener);
} 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()));
......@@ -319,55 +521,78 @@ 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)
void submitOnClicked() {
void submitOnClicked(View v) {
Util.hideSoftKeyboard(CatalogueVariableScreen.this, v);
saveFormData();
}
@OnClick(R.id.variable_screen_back_text_view)
void backOnClicked() {
finish();
showNavigationBackDialog();
}
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;
}
View view = mContainerLayout.findViewWithTag(tempTagObj);
if(skipInvisibleItem && catalogueVariable.getType() != ViewType.CONTAINER_END) {
continue;
}
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) {
jsonColumnValue = Util.getDateFromLong(Long.parseLong(value));
} else if(viewType == ViewType.DATE_AND_TIME) {
jsonColumnValue = Util.getDateTimeFromLong(Long.parseLong(value));
if (viewType == ViewType.DATE) {
jsonColumnValue = Util.getDateFromLong(Util.getDateFromString(value));
} else if (viewType == ViewType.DATE_AND_TIME) {
jsonColumnValue = Util.getDateTime(Util.getDateTimeFromString(value));
}
if(viewType != ViewType.SELECT_BOX) {
if (catalogueVariable.isMandatory()) {
if (viewType != ViewType.SELECT_BOX && viewType != ViewType.UI_PAGE) {
if (TextUtils.isEmpty(jsonColumnValue)) {
hasErrors = true;
// show error view
......@@ -390,14 +615,12 @@ public class CatalogueVariableScreen extends AppCompatActivity {
errorView.setVisibility(View.GONE);
}
}
}
try {
jsonObject.put(catalogueVariable.getName(), jsonColumnValue);
} catch (JSONException e) {
e.printStackTrace();
}
mJsonArray.put(jsonObject);
valueList.add(value);
}
}
}
......@@ -405,14 +628,30 @@ public class CatalogueVariableScreen extends AppCompatActivity {
if(hasErrors)
return;
/*Create Dynamic table for CatalogueVariable Values*/
Util.createDynamicTableForVariableFormValues(mCatalogueItem.getSysId(), mCatalogueVariableList);
jsonArray = new JSONArray();
jsonArray.put(jsonObject);
/*Save data in local DB*/
long id = CatalogueVariableValueManager.save("t_" + mCatalogueItem.getSysId(), columnList, valueList, DBConstants.SYNC_FLAG_CREATE);
CatalogueItemInput.CatalogueItemInputBuilder builder = CatalogueItemInput.CatalogueItemInputBuilder.aCatalogueItemInput();
builder.setData(jsonArray.toString());
builder.setCatalogueItemId(mCatalogueItem.getId());
long id = CatalogueItemInputManager.save(builder.build(), DBConstants.SYNC_FLAG_CREATE);
if(id != -1) {
Toast.makeText(CatalogueVariableScreen.this, "Data Saved in Local DB", Toast.LENGTH_LONG).show();
finish();
if(mAttachment != null) {
mAttachment.setItemInputId(id);
AttachmentManager.save(mAttachment, DBConstants.SYNC_FLAG_CREATE);
}
showSubmissionDialog();
} else {
CatalogueLog.e("CatalogueVariableScreen: saveFormData: input data is not saved.");
showSubmitErrorDialog(R.string.failed_to_submit_form_string);
}
/*Send broadcast to start SyncService*/
Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT);
intent.putExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION, Constants.ACTION_SYNC);
LocalBroadcastManager.getInstance(CatalogueVariableScreen.this).sendBroadcast(intent);
}
View.OnClickListener dateListener = new View.OnClickListener() {
......@@ -438,14 +677,20 @@ public class CatalogueVariableScreen extends AppCompatActivity {
DatePickerDialog.OnDateSetListener dateListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
((TextView)v).setText(String.format(getString(R.string.date_string), (dayOfMonth < 10 ? "0" + dayOfMonth : dayOfMonth), getMonth(monthOfYear), year));
((Button)v).setText(String.format(getString(R.string.date_string), (dayOfMonth < 10 ? "0" + dayOfMonth : dayOfMonth), getMonth(monthOfYear), year));
}
};
TimePickerDialog.OnTimeSetListener timeListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
((TextView)v).append(String.format(getString(R.string.date_and_time_string), (hourOfDay < 10 ? "0" + hourOfDay : hourOfDay), (minute < 10 ? "0" + minute : minute)));
Button button = (Button)v;
String existText = button.getText().toString();
StringBuilder builder = new StringBuilder();
builder.append(existText);
builder.append(" ");
builder.append(String.format(getString(R.string.date_and_time_string), (hourOfDay < 10 ? "0" + hourOfDay : hourOfDay), (minute < 10 ? "0" + minute : minute)));
button.setText(builder.toString());
}
};
......@@ -468,8 +713,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
......@@ -478,8 +722,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();
......@@ -492,43 +735,74 @@ public class CatalogueVariableScreen extends AppCompatActivity {
}
};
class SubmitForm extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
View.OnClickListener attachmentListener = new View.OnClickListener() {
@Override
public void onClick(final View v) {
int permissionCheck = ContextCompat.checkSelfPermission(CatalogueVariableScreen.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
CatalogueVariableScreen.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_EXTERNAL_STORAGE);
} else {
showFileChooser();
}
}
};
CompoundButton.OnCheckedChangeListener checkedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(CatalogueVariableScreen.this);
progressDialog.setMessage(getString(R.string.loading_string));
progressDialog.show();
progressDialog.setCancelable(false);
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
CatalogueVariable catalogueVariable = getVariableForView(compoundButton);
runUIPolicyActions(catalogueVariable.getSysId());
}
};
RadioGroup.OnCheckedChangeListener radioGroupCheckedChangeListener = new RadioGroup.OnCheckedChangeListener() {
@Override
protected SyncStatus doInBackground(String... params) {
return CatalogueVariableApiManager.submitVariableForm(mCatalogueItem.getSysId(), mJsonArray);
public void onCheckedChanged(RadioGroup radioGroup, int i) {
CatalogueVariable catalogueVariable = getVariableForView(radioGroup);
runUIPolicyActions(catalogueVariable.getSysId());
}
};
AdapterView.OnItemSelectedListener spinnerItemSelectedListener = new AdapterView.OnItemSelectedListener() {
@Override
protected void onPostExecute(SyncStatus syncStatus) {
super.onPostExecute(syncStatus);
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
CatalogueVariable catalogueVariable = getVariableForView(adapterView);
runUIPolicyActions(catalogueVariable.getSysId());
}
if(syncStatus == SyncStatus.SUCCESS) {
finish();
} else {
showErrorDialog(R.string.failed_to_submit_form_string);
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
};
public String getMimeType(Uri uri) {
ContentResolver cR = getContentResolver();
return cR.getType(uri);
}
private void showSubmissionDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.variable_form_order_successful_submission_string)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
AlertDialog alert = builder.create();
alert.show();
}
private void showErrorDialog(int message) {
private void showFetchVariableErrorDialog(int message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
finish();
}
});
......@@ -536,6 +810,19 @@ public class CatalogueVariableScreen extends AppCompatActivity {
alert.show();
}
private void showSubmitErrorDialog(int message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
private String getMonth(int month) {
return Constants.month[month];
}
......@@ -543,8 +830,428 @@ public class CatalogueVariableScreen extends AppCompatActivity {
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == android.R.id.home) {
finish();
showNavigationBackDialog();
}
return super.onOptionsItemSelected(menuItem);
}
private void showFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(
Intent.createChooser(intent, "Select a File to Upload"),
FILE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
// Potentially direct the user to the Market with a Dialog
Toast.makeText(this, "Please install a File Manager.",
Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
Uri attachmentUri = data.getData();
String attachmentPath = getPath(this, attachmentUri);
File attachmentFile = new File(attachmentPath);
Attachment.AttachmentBuilder builder = Attachment.AttachmentBuilder.anAttachment();
builder.setPath(getPath(this, attachmentUri));
builder.setName(attachmentFile.getName());
builder.setMimeType(getMimeType(attachmentUri));
builder.setSyncDirty(DBConstants.SYNC_FLAG_CREATE);
mAttachment = builder.build();
if(mAttachmentTextView!=null) {
mAttachmentTextView.setText(mAttachment.getName());
}
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
/**
* Get a file path from a Uri. This will get the the path for Storage Access
* Framework Documents, as well as the _data field for the MediaStore and
* other file-based ContentProviders.
*
* @param context The context.
* @param uri The Uri to query.
* @author paulburke
*/
public static String getPath(final Context context, final Uri uri) {
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
// DocumentProvider
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/" + split[1];
}
// TODO handle non-primary volumes
}
// DownloadsProvider
else if (isDownloadsDocument(uri)) {
final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
return getDataColumn(context, contentUri, null, null);
}
// MediaProvider
else if (isMediaDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
Uri contentUri = null;
if ("image".equals(type)) {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
final String selection = "_id=?";
final String[] selectionArgs = new String[] {
split[1]
};
return getDataColumn(context, contentUri, selection, selectionArgs);
}
}
// MediaStore (and general)
else if ("content".equalsIgnoreCase(uri.getScheme())) {
// Return the remote address
if (isGooglePhotosUri(uri))
return uri.getLastPathSegment();
return getDataColumn(context, uri, null, null);
}
// File
else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
return null;
}
/**
* Get the value of the data column for this Uri. This is useful for
* MediaStore Uris, and other file-based ContentProviders.
*
* @param context The context.
* @param uri The Uri to query.
* @param selection (Optional) Filter used in the query.
* @param selectionArgs (Optional) Selection arguments used in the query.
* @return The value of the _data column, which is typically a file path.
*/
public static String getDataColumn(Context context, Uri uri, String selection,
String[] selectionArgs) {
Cursor cursor = null;
final String column = "_data";
final String[] projection = {
column
};
try {
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
null);
if (cursor != null && cursor.moveToFirst()) {
final int index = cursor.getColumnIndexOrThrow(column);
return cursor.getString(index);
}
} finally {
if (cursor != null)
cursor.close();
}
return null;
}
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is ExternalStorageProvider.
*/
public static boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is DownloadsProvider.
*/
public static boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is MediaProvider.
*/
public static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is Google Photos.
*/
public static boolean isGooglePhotosUri(Uri uri) {
return "com.google.android.apps.photos.content".equals(uri.getAuthority());
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case WRITE_EXTERNAL_STORAGE:
// If request is cancelled, the result arrays are empty.
for (int i = 0; i < permissions.length; i++) {
if (permissions[0].equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
showFileChooser();
} else if (!ActivityCompat.shouldShowRequestPermissionRationale(CatalogueVariableScreen.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// user denied flagging NEVER ASK AGAIN.
showCustomSettingPermissionDialog();
}
/*Break for loop*/
break;
}
}
break;
default:
break;
}
}
private void showCustomSettingPermissionDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(String.format(getString(R.string.custom_setting_storage_permission_dialog_msg_string), getString(R.string.app_name)))
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
@Override
public void onBackPressed() {
showNavigationBackDialog();
}
private void showNavigationBackDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.variable_form_back_navigation_string)
.setCancelable(false)
.setPositiveButton(R.string.yes_string, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
private void runUIPolicyActions(String sysId) {
List<UiPolicyItem> uiPolicyItemList = UiPolicyItemManager.getAllUiPolicyItems(mCatalogueItem.getId());
if(uiPolicyItemList == null)
return;
for(int i=0; i<uiPolicyItemList.size(); i++) {
UiPolicyItem item = uiPolicyItemList.get(i);
String condition = item.getCondition();
if (condition != null) {
List<PartialCondition> partialConditionList = setPartialCondition(condition);
item.setPartialConditions(partialConditionList);
}
/*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 partialCondition = item.getPartialConditions().get(j);
CatalogueVariable variable = getVariableForSysId(partialCondition.getViewSysId());
VariableViewContainer variableViewContainer = mVariableViewMap.get(variable);
if(variableViewContainer == null || variableViewContainer.getInputView() == null) {
continue;
}
String value = Util.getVariableViewValueForUIPolicy(variableViewContainer.getInputView(), variable);
switch(partialCondition.getOperator()) {
case EQUAL:
conditionsSatisfied = conditionsSatisfied && value.equals(partialCondition.getOperatorValue());
break;
case IS_NOT_EMPTY:
conditionsSatisfied = conditionsSatisfied && !TextUtils.isEmpty(value);
break;
}
}
/*Get UiPolicyAction from local DB*/
List<UiPolicyAction> uiPolicyActionList = UiPolicyActionManager.getAllUiPolicyActions(item.getId());
if(conditionsSatisfied) {
for(int j=0; j<uiPolicyActionList.size(); j++) {
UiPolicyAction action = uiPolicyActionList.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<uiPolicyActionList.size(); j++) {
UiPolicyAction action = uiPolicyActionList.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
......@@ -7,6 +7,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
......@@ -16,11 +17,11 @@ import android.widget.Toast;
import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.R;
import com.vsoft.uoflservicenow.api.listeners.get.GetUserApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetUserDetailApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetUserLoginApiListener;
import com.vsoft.uoflservicenow.api.managers.LoginApiManger;
import com.vsoft.uoflservicenow.api.managers.UserApiManager;
import com.vsoft.uoflservicenow.db.models.UserApiValues;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.KeyboardUtil;
......@@ -38,14 +39,18 @@ import butterknife.OnClick;
*/
public class LoginScreen extends Activity {
@BindView(R.id.login_screen_username_edit_text)
EditText mUserNameEditText;
@BindView(R.id.login_screen_password_edit_text)
EditText mPasswordEditText;
@BindView(R.id.login_screen_username_edit_text) EditText mUserNameEditText;
@BindView(R.id.login_screen_password_edit_text) EditText mPasswordEditText;
private List<UserApiValues> mUserDetails;
private CatalogueApplication mApplication;
private static final int API_SUCCESS_USER_LOGIN = 1;
private static final int API_FAIL_USER_LOGIN = 2;
private static final int API_SUCCESS_USER_DETAIL = 3;
private static final int API_FAIL_USER_DETAIL = 4;
private int apiStatus;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
......@@ -84,6 +89,11 @@ public class LoginScreen extends Activity {
SharedPreferences sharedPreferences = getSharedPreferences(PrefManager.PREFERENCES_USER_VALUES_KEY, Context.MODE_PRIVATE);
String sysId = sharedPreferences.getString(PrefManager.PREFERENCE_SYS_ID, "");
if (!TextUtils.isEmpty(sysId)) {
/*Send broadcast to start SyncService*/
Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT);
intent.putExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION, Constants.ACTION_SYNC);
LocalBroadcastManager.getInstance(LoginScreen.this).sendBroadcast(intent);
startActivity(new Intent(LoginScreen.this, HomeScreen.class));
finish();
}
......@@ -114,78 +124,86 @@ public class LoginScreen extends Activity {
callLoginAPI();
}
private class LoginDetailsSendToServer extends AsyncTask<String, Void, SyncStatus> {
private class LoginDetailsSendToServer extends AsyncTask<String, Integer, Integer> {
private ProgressDialog progressDialog;
private static final int USER_DETAIL = 1;
private String userName;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(LoginScreen.this);
progressDialog.setMessage(getString(R.string.loading_string));
progressDialog.setMessage(getString(R.string.login_screen_logging_in_loading_string));
progressDialog.show();
progressDialog.setCancelable(false);
}
@Override
protected SyncStatus doInBackground(String... params) {
SyncStatus syncStatus = null;
protected Integer doInBackground(String... params) {
userName = params[0];//"a0kuma18";
String password = params[1];//"v$0ftA$win";
try {
syncStatus = LoginApiManger.submitLoginValues(Constants.GRANT_TYPE, Constants.CLIENT_ID, Constants
.CLIENT_SECRET, userName, password);
if (syncStatus != null) {
if (syncStatus == SyncStatus.SUCCESS) {
return UserApiManager.getUserDetailResponse(userName, new GetUserApiListener() {
LoginApiManger.submitLoginValues(Constants.GRANT_TYPE, Constants.CLIENT_ID, Constants
.CLIENT_SECRET, userName, password, new GetUserLoginApiListener() {
@Override
public void onDoneApiCall() {
apiStatus = API_SUCCESS_USER_LOGIN;
publishProgress(USER_DETAIL);
UserApiManager.getUserDetailResponse(userName, new GetUserDetailApiListener() {
@Override
public void onDoneApiCall(List<UserApiValues> userValues) {
apiStatus = API_SUCCESS_USER_DETAIL;
mUserDetails = userValues;
}
});
} else if (syncStatus == SyncStatus.SERVICEDOWN) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(LoginScreen.this, R.string.server_not_reachable, Toast.LENGTH_LONG).show();
public void onFailApiCall() {
apiStatus = API_FAIL_USER_DETAIL;
}
});
} else if (syncStatus == SyncStatus.FAIL) {
runOnUiThread(new Runnable() {
}
@Override
public void run() {
Toast.makeText(LoginScreen.this, R.string.login_screen_invalid_usernane_and_password_string, Toast.LENGTH_LONG).show();
public void onFailApiCall() {
apiStatus = API_FAIL_USER_LOGIN;
}
});
}
return apiStatus;
}
} catch (Exception e) {
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
if(values[0] == USER_DETAIL) {
progressDialog.setMessage(getString(R.string.login_screen_getting_user_detail_loading_string));
}
return syncStatus;
}
@Override
protected void onPostExecute(SyncStatus syncStatus) {
protected void onPostExecute(Integer syncStatus) {
super.onPostExecute(syncStatus);
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if (syncStatus != null && syncStatus == SyncStatus.SUCCESS) {
if (syncStatus == API_SUCCESS_USER_DETAIL) {
if (mUserDetails != null) {
String firstName = mUserDetails.get(0).getFirstName();
String lastName = mUserDetails.get(0).getLastName();
String sysid = mUserDetails.get(0).getSysId();
PrefManager.saveUserDetailsInPreferences(LoginScreen.this, firstName, lastName, sysid);
/*Send broadcast to start SyncService*/
Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT);
intent.putExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION, Constants.ACTION_SYNC);
LocalBroadcastManager.getInstance(LoginScreen.this).sendBroadcast(intent);
startActivity(new Intent(LoginScreen.this, HomeScreen.class));
finish();
} else {
Toast.makeText(LoginScreen.this, R.string.user_detail_not_available, Toast.LENGTH_LONG).show();
}
} else if (syncStatus == API_FAIL_USER_LOGIN) {
Toast.makeText(LoginScreen.this, R.string.login_screen_invalid_username_and_password_string, Toast.LENGTH_LONG).show();
} else if (syncStatus == API_FAIL_USER_DETAIL) {
Toast.makeText(LoginScreen.this, R.string.failed_to_fetch_user_detail_string, Toast.LENGTH_LONG).show();
}
}
}
......
......@@ -8,6 +8,7 @@ import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.view.MenuItem;
import android.widget.ListView;
......@@ -81,18 +82,12 @@ public class MyIncidentScreen extends AppCompatActivity {
@OnItemClick(R.id.my_incidents_screen_list_view)
void listViewOnClicked(int position) {
Incident incident = mIncidentList.get(position);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Number: ");
stringBuilder.append(incident.getNumber());
stringBuilder.append("\n\n");
stringBuilder.append("Opened At: ");
stringBuilder.append(incident.getOpenedAt());
stringBuilder.append("\n\n");
stringBuilder.append("Short Description: ");
stringBuilder.append(incident.getShortDescription());
String messageString = String.format(getResources().getString(R.string.incident_item_text_string),
incident.getNumber(), Util.getDateTimeFromLong(incident.getOpenedAt()), incident.getShortDescription());
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(stringBuilder.toString())
builder.setMessage(Html.fromHtml(messageString))
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
......@@ -105,6 +100,7 @@ public class MyIncidentScreen extends AppCompatActivity {
class FetchIncident extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
private SyncStatus syncStatus = SyncStatus.FAIL;
@Override
protected void onPreExecute() {
......@@ -117,13 +113,20 @@ public class MyIncidentScreen extends AppCompatActivity {
@Override
protected SyncStatus doInBackground(String... params) {
return IncidentApiManager.getIncident(new GetIncidentApiListener() {
IncidentApiManager.getIncident(new GetIncidentApiListener() {
@Override
public void onDoneApiCall(List<Incident> incidentList) {
syncStatus = SyncStatus.SUCCESS;
CatalogueLog.e("Data: incidentList: "+incidentList);
MyIncidentsManager.handleGetIncident(incidentList);
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
}
@Override
......
......@@ -8,6 +8,7 @@ import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.view.MenuItem;
import android.widget.ListView;
......@@ -29,6 +30,7 @@ import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnItemClick;
/**
* Created by kvemulavada on 8/30/2016.
......@@ -38,6 +40,9 @@ public class MyRequestActivity extends AppCompatActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.request_screen_list_view) ListView mListView;
private List<MyRequest> mMyRequestList;
private MyRequestAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
......@@ -60,6 +65,9 @@ public class MyRequestActivity extends AppCompatActivity {
// Send initial screen view hit.
Util.sendScreenName(tracker, actionBar.getTitle().toString());
mAdapter = new MyRequestAdapter(MyRequestActivity.this);
mListView.setAdapter(mAdapter);
List<MyRequest> myRequestList = MyRequestsManager.getAllRequests();
if(myRequestList.isEmpty()) {
if(application.isNetConnected()) {
......@@ -71,8 +79,10 @@ public class MyRequestActivity extends AppCompatActivity {
setData(myRequestList);
}
}
class FetchMyRequestData extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
private SyncStatus syncStatus = SyncStatus.FAIL;
@Override
protected void onPreExecute() {
......@@ -85,13 +95,20 @@ public class MyRequestActivity extends AppCompatActivity {
@Override
protected SyncStatus doInBackground(String... params) {
return MyRequestApiManager.getMyrequests(new GetMyRequestApiListener() {
MyRequestApiManager.getMyrequests(new GetMyRequestApiListener() {
@Override
public void onDoneApiCall(List<MyRequest> requestList) {
Collections.sort(requestList, new StringDateComparator());
MyRequestsManager.handleGetRequest(requestList);
syncStatus = SyncStatus.SUCCESS;
mMyRequestList = requestList;
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
}
@Override
......@@ -108,11 +125,39 @@ public class MyRequestActivity extends AppCompatActivity {
}
}
@OnItemClick(R.id.request_screen_list_view)
void listViewOnClicked(int position) {
MyRequest myRequest = mMyRequestList.get(position);
String messageString = String.format(getResources().getString(R.string.my_incidents_item_text_string),
myRequest.getNumber(),
myRequest.getShortDescription().getDisplayValue(),
Util.getDateTimeFromLong(myRequest.getUpdateOn()),
myRequest.getRequest().getDisplayValue(),
myRequest.getOpenedBy().getDisplayValue(),
myRequest.getStage());
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(Html.fromHtml(messageString))
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
private void setData(final List<MyRequest> reqList) {
MyRequestAdapter adapter = new MyRequestAdapter(MyRequestActivity.this);
Collections.sort(reqList, new StringDateComparator());
if(mAdapter == null) {
mAdapter = new MyRequestAdapter(MyRequestActivity.this);
mListView.setAdapter(mAdapter);
}
mAdapter.setRequestList(reqList);
adapter.setRequestList(reqList);
mListView.setAdapter(adapter);
}
class StringDateComparator implements Comparator<MyRequest> {
......
package com.vsoft.uoflservicenow.ui;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.Html;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
......@@ -21,19 +24,14 @@ import android.widget.TextView;
import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.R;
import com.vsoft.uoflservicenow.api.managers.IncidentApiManager;
import com.vsoft.uoflservicenow.db.managers.ReportIncidentValueManager;
import com.vsoft.uoflservicenow.db.models.Incident;
import com.vsoft.uoflservicenow.enums.Impact;
import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DBConstants;
import com.vsoft.uoflservicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.PrefManager;
import com.vsoft.uoflservicenow.utils.Util;
import org.json.JSONException;
import org.json.JSONObject;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
......@@ -48,6 +46,8 @@ public class ReportIncidentScreen extends AppCompatActivity {
@BindView(R.id.incident_short_description_edit_text) EditText mShortDesEditText;
@BindView(R.id.incident_impact_error_tv) TextView mImpactErrorTextView;
@BindView(R.id.incident_short_des_error_tv) TextView mShortDesErrorTextView;
@BindView(R.id.incident_impact_header_text_view) TextView mImpactHeaderTextView;
@BindView(R.id.incident_short_description_header_tv) TextView mShortDescriptionHeaderTextView;
private CatalogueApplication mApplication;
private Impact mImpact;
......@@ -61,7 +61,43 @@ public class ReportIncidentScreen extends AppCompatActivity {
setContentView(R.layout.incidents_form_screen);
ButterKnife.bind(this);
final int shortDescriptionTextLimit = getResources().getInteger(R.integer.incident_from_short_description_text_limit);
mApplication = (CatalogueApplication) getApplication();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
mImpactHeaderTextView.setText(Html.fromHtml(getString(R.string.incident_form_impact_text_string), Html.FROM_HTML_MODE_LEGACY));
mShortDescriptionHeaderTextView.setText(
Html.fromHtml(String.format(getString(R.string.incident_form_describe_your_issue_text_string), shortDescriptionTextLimit),
Html.FROM_HTML_MODE_LEGACY));
} else {
mImpactHeaderTextView.setText(Html.fromHtml(getString(R.string.incident_form_impact_text_string)));
mShortDescriptionHeaderTextView.setText(Html.fromHtml(
String.format(getString(R.string.incident_form_describe_your_issue_text_string),
shortDescriptionTextLimit)));
}
mShortDesEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if(charSequence.length() > shortDescriptionTextLimit) {
mShortDesErrorTextView.setVisibility(View.VISIBLE);
mShortDesErrorTextView.setText(String.format(getString(R.string.incident_form_short_description_limit_error_text_string),
(charSequence.length() - shortDescriptionTextLimit)));
} else {
if(mShortDesErrorTextView.getVisibility() == View.VISIBLE)
mShortDesErrorTextView.setVisibility(View.GONE);
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
setSupportActionBar(mToolbar);
ActionBar actionBar = getSupportActionBar();
......@@ -92,7 +128,6 @@ public class ReportIncidentScreen extends AppCompatActivity {
@OnClick(R.id.incident_submit_text_view)
void submitOnClicked(View view) {
if(mApplication.isNetConnected()) {
if (!hasValidateForm()) {
SharedPreferences sharedPreferences = getSharedPreferences(PrefManager.PREFERENCES_USER_VALUES_KEY, Context.MODE_PRIVATE);
String userSysId = sharedPreferences.getString(PrefManager.PREFERENCE_SYS_ID, "");
......@@ -105,53 +140,13 @@ public class ReportIncidentScreen extends AppCompatActivity {
.build();
long id = ReportIncidentValueManager.save(incident, DBConstants.SYNC_FLAG_CREATE);
if(id != -1) {
showSuccessDialog();
}
// new submitIncident().execute(userSysId);
} else {
showErrorDialog(R.string.failed_to_submit_form_string);
}
}
} else {
DialogUtils.showNoConnectionDialogWithCloseActivity(ReportIncidentScreen.this);
}
}
class submitIncident extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(ReportIncidentScreen.this);
progressDialog.setMessage(getString(R.string.loading_string));
progressDialog.show();
progressDialog.setCancelable(false);
}
@Override
protected SyncStatus doInBackground(String... params) {
String userSysId = params[0];
JSONObject incidentJsonObject = new JSONObject();
try {
incidentJsonObject.put(Incident.Json.IMPACT, mImpact.getServerString());
incidentJsonObject.put(Incident.Json.SHORT_DESCRIPTION, mShortDescription);
incidentJsonObject.put(Incident.Json.OPENED_AT, userSysId);
incidentJsonObject.put(Incident.Json.CALLER_ID, userSysId);
} catch (JSONException e) {
e.printStackTrace();
}
return IncidentApiManager.submitIncidentForm(incidentJsonObject.toString());
}
/*Send broadcast to start SyncService*/
Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT);
intent.putExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION, Constants.ACTION_SYNC);
LocalBroadcastManager.getInstance(ReportIncidentScreen.this).sendBroadcast(intent);
@Override
protected void onPostExecute(SyncStatus syncStatus) {
super.onPostExecute(syncStatus);
if(progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
showSuccessDialog(getString(R.string.incident_form_incident_successful_submission_string));
}
if(syncStatus == SyncStatus.SUCCESS) {
showSuccessDialog();
} else {
showErrorDialog(R.string.failed_to_submit_form_string);
}
......@@ -179,10 +174,15 @@ public class ReportIncidentScreen extends AppCompatActivity {
}
if (!TextUtils.isEmpty(mShortDescription)) {
if(mShortDesErrorTextView.getVisibility() == View.VISIBLE) {
hasError = true;
} else {
mShortDesErrorTextView.setVisibility(View.GONE);
}
} else {
hasError = true;
mShortDesErrorTextView.setVisibility(View.VISIBLE);
mShortDesErrorTextView.setText(R.string.error_string);
}
return hasError;
}
......@@ -206,9 +206,9 @@ public class ReportIncidentScreen extends AppCompatActivity {
alert.show();
}
private void showSuccessDialog() {
private void showSuccessDialog(String message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.incident_form_incident_successful_submission_string)
builder.setMessage(message)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
......
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;
}
}
......@@ -29,6 +29,16 @@ public class Constants {
public static final String DATA_KEY_REFERENCE_TABLE_NAME = "table_name";
public static final String DATA_KEY_REFERENCE_TABLE_COLUMN_NAME = "table_column_name";
public static final String DATA_KEY_REFERENCE_TITLE = "title";
public static final String DATA_KEY_CATALOGUE_TITLE = "catalogue_title";
public static final String DATA_KEY_CATALOGUE_ITEM_DESCRIPTION = "catalogue_item_des";
public static final String DATA_KEY_CATALOGUE_ITEM_SHORT_DESCRIPTION = "catalogue_item_short_des";
/**
* Broadcast custom intent
*/
public static final String APPLICATION_BROADCAST_INTENT = "application_broadcast";
public static final String APPLICATION_BROADCAST_DATA_ACTION = "action";
public static final String ACTION_SYNC = "action_sync";
/**
* Catalogue services post parameters
......@@ -38,6 +48,9 @@ public class Constants {
public static final String URL_PARAM_SYSPRM_DISPLAY_VALUE = "sysparm_display_value";
public static final String URL_PARAM_SYSPRM_USERNAME = "user_name";
public static final String URL_PARAM_SYSPRM_LIMIT = "sysparm_limit";
public static final String URL_PARAM_TABLE_SYS_ID = "table_sys_id";
public static final String URL_PARAM_TABLE_NAME = "table_name";
public static final String URL_PARAM_FILE_NAME = "file_name";
/**
* Debug logs
......@@ -117,6 +130,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,9 +147,11 @@ 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;
public static final String URL_POST_ATTACHMENT = DOMAIN + "api/now/v1/attachment/file";
/*Request API*/
public static final String URL_GET_MYREQUEST = API_PATH + "sc_req_item";
......
......@@ -8,7 +8,11 @@ public interface DBConstants {
String TABLE_VARIABLE_CHOICES = "variable_choices";
String TABLE_MY_INCIDENT = "my_incidents";
String TABLE_MY_REQUEST = "my_requests";
String TABLE_INCIDENT_FORM = "incident_form";
String TABLE_INCIDENT_INPUT = "incident_input";
String TABLE_UI_POLICY_ITEM = "ui_policy_item";
String TABLE_UI_POLICY_ACTION = "ui_policy_action";
String TABLE_CATALOGUE_ITEM_INPUT = "catalogue_item_input";
String TABLE_ATTACHMENT = "attachment";
String ID = "_id";
String SYS_ID = "sys_id";
......@@ -81,6 +85,8 @@ public interface DBConstants {
String CATALOGUE_VARIABLE_REFERENCE_TABLE = "reference_table";
String CATALOGUE_VARIABLE_ORDER= "variable_order";
String CATALOGUE_VARIABLE_REFERENCE_COLUMN_NAME = "reference_column_name";
String CATALOGUE_VARIABLE_ACTIVE = "active";
String CATALOGUE_VARIABLE_DEFAULT_VALUE = "default_value";
String CATALOGUE_VARIABLE_SYNC_DIRTY = SYNC_DIRTY;
/**
......@@ -97,9 +103,11 @@ public interface DBConstants {
int INDEX_CATALOGUE_VARIABLE_REFERENCE = 8;
int INDEX_CATALOGUE_VARIABLE_ORDER = 9;
int INDEX_CATALOGUE_VARIABLE_REFERENCE_COLUMN_NAME = 10;
int INDEX_CATALOGUE_VARIABLE_SYNC_DIRTY = 11;
int INDEX_CATALOGUE_VARIABLE_ACTIVE = 11;
int INDEX_CATALOGUE_VARIABLE_DEFAULT_VALUE = 12;
int INDEX_CATALOGUE_VARIABLE_SYNC_DIRTY = 13;
int CATALOGUE_VARIABLE_COLUMN_COUNT = 12;
int CATALOGUE_VARIABLE_COLUMN_COUNT = 14;
/**
* Variables Choice table
......@@ -170,18 +178,107 @@ public interface DBConstants {
/**
* Incident Form table
*/
String INCIDENT_FORM_ID = ID;
String INCIDENT_FORM_IMPACT = "number";
String INCIDENT_FORM_SHORT_DESCRIPTION = "short_description";
String INCIDENT_FORM_SYNC_DIRTY = SYNC_DIRTY;
String INCIDENT_INPUT_ID = ID;
String INCIDENT_INPUT_NUMBER = "number";
String INCIDENT_INPUT_IMPACT = "impact";
String INCIDENT_INPUT_SHORT_DESCRIPTION = "short_description";
String INCIDENT_INPUT_SYNC_DIRTY = SYNC_DIRTY;
/**
* Request for Incident Form table. *Use these only if you fetch all columns*
*/
int INDEX_INCIDENT_FORM_ID = 0;
int INDEX_INCIDENT_FORM_IMPACT = 1;
int INDEX_INCIDENT_FORM_SHORT_DESCRIPTION = 2;
int INDEX_INCIDENT_FORM_SYNC_DIRTY = 3;
int INDEX_INCIDENT_INPUT_ID = 0;
int INDEX_INCIDENT_INPUT_NUMBER = 1;
int INDEX_INCIDENT_INPUT_IMPACT = 2;
int INDEX_INCIDENT_INPUT_SHORT_DESCRIPTION = 3;
int INDEX_INCIDENT_INPUT_SYNC_DIRTY = 4;
int INCIDENT_FORM_COLUMN_COUNT = 6;
int INCIDENT_INPUT_COLUMN_COUNT = 5;
/**
* UiPolicyItem table
*/
String UI_POLICY_ITEM_ID = ID;
String UI_POLICY_ITEM_CATALOGUE_ITEM_ID = "catalogue_item_id";
String UI_POLICY_ITEM_CONDITION = "condition";
String UI_POLICY_ITEM_SYS_ID = "sys_id";
String UI_POLICY_ITEM_SYNC_DIRTY = SYNC_DIRTY;
/**
* UiPolicyItem table. *Use these only if you fetch all columns*
*/
int INDEX_UI_POLICY_ITEM_ID = 0;
int INDEX_UI_POLICY_ITEM_CATALOGUE_ITEM_ID = 1;
int INDEX_UI_POLICY_ITEM_CONDITION = 2;
int INDEX_UI_POLICY_ITEM_SYS_ID = 3;
int INDEX_UI_POLICY_ITEM_SYNC_DIRTY = 4;
int UI_POLICY_ITEM_COLUMN_COUNT = 5;
/**
* UiPolicyAction table
*/
String UI_POLICY_ACTION_ID = ID;
String UI_POLICY_ACTION_POLICY_ITEM_ID = "ui_policy_item_id";
String UI_POLICY_ACTION_VISIBLE = "visible";
String UI_POLICY_ACTION_MANDATORY = "mandatory";
String UI_POLICY_ACTION_VARIABLE = "variable";
String UI_POLICY_ACTION_DISABLED = "disabled";
String UI_POLICY_ACTION_SYNC_DIRTY = SYNC_DIRTY;
/**
* UiPolicyAction table. *Use these only if you fetch all columns*
*/
int INDEX_UI_POLICY_ACTION_ID = 0;
int INDEX_UI_POLICY_ACTION_POLICY_ITEM_ID = 1;
int INDEX_UI_POLICY_ACTION_VISIBLE = 2;
int INDEX_UI_POLICY_ACTION_MANDATORY = 3;
int INDEX_UI_POLICY_ACTION_VARIABLE = 4;
int INDEX_UI_POLICY_ACTION_DISABLED = 5;
int INDEX_UI_POLICY_ACTION_SYNC_DIRTY = 6;
int UI_POLICY_ACTION_COLUMN_COUNT = 7;
/**
* catalogueItemInput table
*/
String CATALOGUE_ITEM_INPUT_ID = ID;
String CATALOGUE_ITEM_INPUT_CATALOGUE_ITEM_ID = "catalogue_item_id";
String CATALOGUE_ITEM_INPUT_DATA = "data";
String CATALOGUE_ITEM_INPUT_SYS_ID = "sys_id";
String CATALOGUE_ITEM_INPUT_SYNC_DIRTY = SYNC_DIRTY;
/**
* catalogueItemInput table. *Use these only if you fetch all columns*
*/
int INDEX_CATALOGUE_ITEM_INPUT_ID = 0;
int INDEX_CATALOGUE_ITEM_INPUT_CATALOGUE_ITEM_ID = 1;
int INDEX_CATALOGUE_ITEM_INPUT_DATA = 2;
int INDEX_CATALOGUE_ITEM_INPUT_SYS_ID = 3;
int INDEX_CATALOGUE_ITEM_INPUT_SYNC_DIRTY = 4;
int CATALOGUE_ITEM_INPUT_COLUMN_COUNT = 5;
/**
* Attachment table
*/
String ATTACHMENT_ID = ID;
String ATTACHMENT_ITEM_INPUT_ID = "item_input_id";
String ATTACHMENT_PATH = "attachment_path";
String ATTACHMENT_MIME_TYPE = "mime_type";
String ATTACHMENT_NAME = "name";
String ATTACHMENT_SYNC_DIRTY = SYNC_DIRTY;
/**
* Attachment table. *Use these only if you fetch all columns*
*/
int INDEX_ATTACHMENT_ID = 0;
int INDEX_ATTACHMENT_ITEM_INPUT_ID = 1;
int INDEX_ATTACHMENT_PATH = 2;
int INDEX_ATTACHMENT_MIME_TYPE = 3;
int INDEX_ATTACHMENT_NAME = 4;
int INDEX_ATTACHMENT_SYNC_DIRTY = 5;
int ATTACHMENT_COLUMN_COUNT = 6;
}
\ No newline at end of file
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 + '\'' +
'}';
}
}
......@@ -4,7 +4,9 @@ import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
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;
import android.view.Gravity;
import android.view.View;
......@@ -27,20 +29,68 @@ 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;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
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);
......@@ -51,70 +101,183 @@ 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);
multiLineEditText.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
multiLineEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
multiLineEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
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);
htmlEditText.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
htmlEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
htmlEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
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);
return singleLineEditText;
singleLineEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
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);
return wideSingleLineEditText;
wideSingleLineEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
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(getDefaultDate() + " " + getDefaultTime());
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);
referenceEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
referenceEditText.setSingleLine(true);
referenceEditText.setFocusable(false);
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 +286,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,14 +294,28 @@ 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);
maskedEditText.setLines(1);
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);
......@@ -160,23 +338,95 @@ 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),
0, (int) context.getResources().getDimension(R.dimen.normal_margin));
ArrayAdapter<String> selectBoxSpinnerArrayAdapter =
new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, catalogueVariable.getDisplayChoiceText(context, catalogueVariable.isNoneRequired()));
new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, catalogueVariable.getDisplayChoiceText(context));
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);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
Button attachmentButton = new Button(context);
attachmentButton.setText(R.string.variable_form_ui_page_button_label_string);
attachmentButton.setLines(1);
attachmentButton.setSingleLine(true);
attachmentButton.setEllipsize(TextUtils.TruncateAt.END);
uiPageLayout.addView(attachmentButton, layoutParams);
TextView attachmentTextView = new TextView(context);
attachmentTextView.setGravity(Gravity.CENTER);
attachmentTextView.setSingleLine(true);
attachmentTextView.setLines(1);
attachmentTextView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
attachmentTextView.setText(R.string.variable_form_ui_page_no_selected_attachment_string);
uiPageLayout.addView(attachmentTextView, layoutParams);
container.setInputView(uiPageLayout);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
return null;
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 container;
}
public static String getVariableViewValue(View view, ViewType viewType) {
......@@ -202,7 +452,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();
......@@ -211,13 +461,12 @@ public class Util {
return wideSingleLineEditText.getText().toString();
case DATE:
Button dateTextButton = (Button) view;
return ""+ getDateFromString(dateTextButton.getText().toString());
return dateTextButton.getText().toString();
case DATE_AND_TIME:
Button dateTimeButton = (Button) view;
return ""+ getDateTimeFromString(dateTimeButton.getText().toString());
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 {
......@@ -227,15 +476,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;
......@@ -245,21 +491,41 @@ 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());
/*value = null mean selected value is none or default value.*/
value = value != null ? value : "";
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", Locale.US);
SimpleDateFormat df = new SimpleDateFormat("dd MMM, yyyy");
return df.format(c.getTime());
}
public static String getDefaultTime() {
public static String getDefaultDateTime() {
Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int min = c.get(Calendar.MINUTE);
return (hour < 10 ? ("0" + hour) : hour) + ":" + (min < 10 ? ("0" + min) : min);
SimpleDateFormat df = new SimpleDateFormat("dd MMM, yyyy HH:mm");
return df.format(c.getTime());
}
public static long getDateFromString(String strDate) {
SimpleDateFormat df = new SimpleDateFormat("dd MMM, yyyy", Locale.US);
SimpleDateFormat df = new SimpleDateFormat("dd MMM, yyyy");
Date date = null;
try {
date = df.parse(strDate);
......@@ -269,14 +535,8 @@ public class Util {
return date.getTime();
}
public static String getDateFromLong(long timeStamp) {
SimpleDateFormat dateFormat = new SimpleDateFormat
("yyyy-MM-dd", Locale.US);
return dateFormat.format(timeStamp);
}
public static long getDateTimeFromString(String strDate) {
SimpleDateFormat df = new SimpleDateFormat("dd MMM, yyyy HH:mm", Locale.US);
SimpleDateFormat df = new SimpleDateFormat("dd MMM, yyyy HH:mm");
Date date = null;
try {
date = df.parse(strDate);
......@@ -286,14 +546,24 @@ public class Util {
return date.getTime();
}
public static String getDateFromLong(long timeStamp) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
return dateFormat.format(timeStamp);
}
public static String getDateTime(long timeStamp) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
return dateFormat.format(timeStamp);
}
public static String getDateTimeFromLong(long timeStamp) {
SimpleDateFormat dateFormat = new SimpleDateFormat
("dd MMM, yyyy HH:mm", Locale.US);
("dd MMM, yyyy HH:mm");
return dateFormat.format(timeStamp);
}
public static long getDateTimeForMyIncidentFromString(String strDate) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = df.parse(strDate);
......@@ -304,7 +574,7 @@ public class Util {
}
public static long getDateTimeForMyRequestFromString(String strDate) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Date date = null;
try {
date = df.parse(strDate);
......@@ -314,41 +584,6 @@ public class Util {
return date.getTime();
}
public static void createDynamicTableForVariableFormValues(String catalogueItemSysId, List<CatalogueVariable> catalogueVariableList) {
StringBuilder queryString = new StringBuilder();
//Opens database in writable mode.
SQLiteDatabase database = CatalogueApplication.getDatabase();
queryString.append("CREATE TABLE IF NOT EXISTS t_");
queryString.append(catalogueItemSysId);
queryString.append(" (");
queryString.append(DBConstants.ID);
queryString.append(" integer primary key autoincrement, ");
CatalogueVariable catalogueVariable = catalogueVariableList.get(0);
if(catalogueVariable.getName() != null) {
queryString.append(catalogueVariable.getName());
queryString.append(" text, ");
}
for(int i = 1; i < catalogueVariableList.size(); i++) {
catalogueVariable = catalogueVariableList.get(i);
if(catalogueVariable.getName()!=null) {
queryString.append(catalogueVariable.getName());
queryString.append(" text, ");
}
}
queryString.append(DBConstants.CATALOGUE_VARIABLE_SYNC_DIRTY);
queryString.append(" integer default ");
queryString.append(DBConstants.SYNC_FLAG_NONE);
queryString.append(");");
System.out.println("createDynamicTableForVariableFormValues: Create Table Stmt : "+ queryString);
database.execSQL(queryString.toString());
}
public static void createDynamicTableForIncidentFormValues() {
StringBuilder queryString = new StringBuilder();
......@@ -356,19 +591,19 @@ public class Util {
SQLiteDatabase database = CatalogueApplication.getDatabase();
queryString.append("CREATE TABLE IF NOT EXISTS ");
queryString.append(DBConstants.TABLE_INCIDENT_FORM);
queryString.append(DBConstants.TABLE_INCIDENT_INPUT);
queryString.append(" (");
queryString.append(DBConstants.ID);
queryString.append(" integer primary key autoincrement, ");
queryString.append(DBConstants.INCIDENT_FORM_IMPACT);
queryString.append(DBConstants.INCIDENT_INPUT_IMPACT);
queryString.append(" integer, ");
queryString.append(DBConstants.INCIDENT_FORM_SHORT_DESCRIPTION);
queryString.append(DBConstants.INCIDENT_INPUT_SHORT_DESCRIPTION);
queryString.append(" text, ");
queryString.append(DBConstants.INCIDENT_FORM_SYNC_DIRTY);
queryString.append(DBConstants.INCIDENT_INPUT_SYNC_DIRTY);
queryString.append(" integer default ");
queryString.append(DBConstants.SYNC_FLAG_NONE);
queryString.append(");");
......
......@@ -29,8 +29,7 @@
android:layout_height="wrap_content"
android:ellipsize="end"
android:textSize="@dimen/normal_text_size"
android:textStyle="bold"
android:lines="1" />
android:textStyle="bold"/>
<TextView
android:id="@+id/catalogue_category_adapter_des_tv"
......
......@@ -29,8 +29,7 @@
android:layout_height="wrap_content"
android:ellipsize="end"
android:textSize="@dimen/normal_text_size"
android:textStyle="bold"
android:lines="1" />
android:textStyle="bold"/>
<TextView
android:id="@+id/catalogue_category_item_adapter_des_tv"
......
......@@ -11,6 +11,16 @@
android:layout_height="match_parent"
android:background="@color/screen_bg_color">
<TextView
android:id="@+id/catalogue_item_screen_empty_text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:gravity="center"
android:visibility="gone"
android:text="@string/no_catalogue_item_string"
android:textSize="@dimen/extra_normal_text_size" />
<ListView
android:id="@+id/catalogue_item_screen_list_view"
android:layout_width="match_parent"
......@@ -20,16 +30,6 @@
android:divider="@android:color/white"
android:dividerHeight="@dimen/catalogue_category_and_item_list_view_divider_height"
android:padding="@dimen/normal_margin"
android:scrollbars="none"
android:visibility="gone" />
<TextView
android:id="@+id/catalogue_item_screen_empty_text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:gravity="center"
android:text="@string/no_catalogue_item_string"
android:textSize="@dimen/extra_normal_text_size" />
android:scrollbars="none"/>
</FrameLayout>
</LinearLayout>
\ No newline at end of file
......@@ -18,7 +18,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:requiresFadingEdge="vertical">
android:requiresFadingEdge="vertical"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="match_parent"
......
......@@ -31,11 +31,11 @@
android:textSize="@dimen/normal_text_size" />
<TextView
android:id="@+id/incident_impact_header_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/normal_margin"
android:layout_marginTop="@dimen/normal_margin"
android:text="@string/incident_form_impact_text_string"
android:textSize="@dimen/normal_text_size"
android:textStyle="bold" />
......@@ -43,7 +43,9 @@
android:id="@+id/incident_impact_spinner"
android:layout_width="match_parent"
android:layout_height="@dimen/impact_spinner_drop_down_height"
android:layout_margin="@dimen/normal_margin"
android:layout_marginTop="@dimen/normal_margin"
android:layout_marginLeft="@dimen/normal_margin"
android:layout_marginRight="@dimen/normal_margin"
android:background="@drawable/spinner_bg"
style="@style/OverflowMenu"/>
......@@ -57,10 +59,10 @@
android:textColor="@color/error_color"/>
<TextView
android:id="@+id/incident_short_description_header_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/normal_margin"
android:text="@string/incident_form_describe_your_issue_text_string"
android:textSize="@dimen/normal_text_size"
android:textStyle="bold" />
......@@ -68,7 +70,6 @@
android:id="@+id/incident_short_description_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/normal_margin"
android:layout_marginLeft="@dimen/normal_margin"
android:layout_marginRight="@dimen/normal_margin"
android:background="@drawable/list_view_item_bg_with_border"
......@@ -92,6 +93,7 @@
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginRight="@dimen/normal_margin"
android:layout_marginTop="@dimen/normal_margin"
android:background="@drawable/submit_button_bg_with_border"
android:paddingBottom="@dimen/normal_margin"
android:paddingLeft="@dimen/large_margin"
......
......@@ -7,13 +7,13 @@
android:weightSum="10">
<TextView
android:id="@+id/dialog_title"
android:id="@+id/reference_search_dialog_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="@dimen/normal_margin"
android:paddingTop="@dimen/normal_margin"
android:textSize="@dimen/large_text_size"/>
android:textSize="@dimen/large_text_size" />
<View
android:layout_width="match_parent"
......@@ -21,7 +21,7 @@
android:background="@android:color/black" />
<EditText
android:id="@+id/dialog_edit_text"
android:id="@+id/reference_search_dialog_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/large_margin"
......@@ -32,15 +32,29 @@
android:hint="@string/search_for_reference_string"
android:imeOptions="actionSearch"
android:singleLine="true"
android:textColor="@android:color/black"/>
android:textColor="@android:color/black" />
<ListView
android:id="@+id/dialog_list_view"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:layout_weight="10">
<TextView
android:id="@+id/reference_search_dialog_no_result_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/variable_form_reference_no_result_string"
android:textSize="@dimen/large_text_size"
android:visibility="gone" />
<ListView
android:id="@+id/reference_search_dialog_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@android:color/black"
android:dividerHeight="0.5dp"/>
android:dividerHeight="0.5dp" />
</FrameLayout>
<View
android:layout_width="match_parent"
......@@ -56,5 +70,5 @@
android:orientation="horizontal"
android:paddingBottom="@dimen/normal_margin"
android:paddingTop="@dimen/normal_margin"
android:text="@android:string/cancel"/>
android:text="@android:string/cancel" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="incident_from_short_description_text_limit">160</integer>
</resources>
\ No newline at end of file
......@@ -25,21 +25,23 @@
<string name="rejected">Rejected</string>
<string name="date_string">%1$s %2$s, %3$s</string>
<string name="date_and_time_string"> %1$s:%2$s</string>
<string name="date_and_time_string">%1$s:%2$s</string>
<!--Failed to fetch-->
<string name="failed_to_fetch_catalogue_category_string">Failed to fetch Catalogue Category.</string>
<string name="failed_to_fetch_my_request_string">Failed to fetch MyRequest</string>
<string name="failed_to_fetch_my_request_string">Failed to fetch requests</string>
<string name="failed_to_fetch_catalogue_category_items_string">Failed to fetch Catalogue Category Items.</string>
<string name="failed_to_fetch_catalogue_form_string">Failed to fetch Form.</string>
<string name="failed_to_fetch_reference_string">Failed to fetch References.</string>
<string name="failed_to_submit_form_string">Failed to submit form.</string>
<string name="failed_to_fetch_incident_string">Failed to fetch incidents.</string>
<string name="failed_to_fetch_user_detail_string">Failed to fetch User Details.</string>
<!--Login Screen-->
<string name="login_screen_login_string">Login</string>
<string name="login_screen_invalid_usernane_and_password_string">Invalid username and password</string>
<string name="server_not_reachable">Unable to connect to server. Please try again later.</string>
<string name="login_screen_logging_in_loading_string">Logging in&#8230;</string>
<string name="login_screen_getting_user_detail_loading_string">Getting user details&#8230;</string>
<string name="login_screen_invalid_username_and_password_string">Invalid username and password</string>
<string name="user_detail_not_available">Unable to fetch user details.</string>
<string name="user_error">Please enter username</string>
......@@ -48,27 +50,44 @@
<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>
<string name="variable_form_radio_text_string">%d</string>
<string name="variable_form_ui_page_button_label_string">Add Attachment</string>
<string name="variable_form_ui_page_no_selected_attachment_string">Not Selected</string>
<string name="custom_setting_storage_permission_dialog_msg_string">To use this feature, please go to Settings -> Apps -> %s -> Permissions and enable \'Storage\' permission</string>
<string name="variable_form_back_navigation_string">Are you sure you want to navigate away?</string>
<string name="variable_form_order_successful_submission_string">Your Order has been submitted successfully</string>
<string name="variable_form_reference_no_result_string">No Result</string>
<string name="Variable_form_short_description_anchor_line_break_css"><![CDATA[
<style>
a {
word-break: break-all;
}
</style>
]]></string>
<!--Catalogue Item Screen-->
<string name="no_catalogue_item_string">No Catalogue Items&#8230;</string>
<!--Catalogue Screen-->
<string name="catalogue_category_string">Catalogue Category</string>
<string name="catalogue_category_string">Order Services</string>
<string name="my_reques_string">My Requests</string>
<!--Incident screen-->
<string name="incident_form_report_incident_text_string">Report Incident</string>
<string name="incident_form_top_text_string">Create an Incident record to report and request assistance with an issue you are having\n\nRequest assistance with an issue you are having. An incident record will be created and managed through to successful resolution. You will also be notified of progress.</string>
<string name="incident_form_impact_text_string">Impact</string>
<string name="incident_form_incident_successful_submission_string">Your Incident has been reported successfully</string>
<string name="incident_form_describe_your_issue_text_string">Please Describe Your Issue below</string>
<string name="incident_form_impact_text_string">Impact &lt;font color="#FF0000"&gt;*&lt;/font&gt;</string>
<string name="incident_form_incident_successful_submission_string">Incident has been reported successfully</string>
<string name="incident_form_describe_your_issue_text_string">Please Describe Your Issue below &lt;font color="#FF0000"&gt;*&lt;/font&gt;(Max %d)</string>
<string name="incident_item_text_string"><![CDATA[<b>Number: </b>%1$s<br><br><b>Opened: </b>%2$s<br><br><b>Short Description: </b>%3$s]]></string>
<string name="incident_form_short_description_limit_error_text_string">Max limit exceeded by %d</string>
<!--My Incidents-->
<string name="my_incidents_text_string">My Incidents</string>
<string name="my_incidents_item_text_string"><![CDATA[<b>Number: </b>%1$s<br><br><b>Item: </b>%2$s<br><br><b>Updated: </b>%3$s<br><br><b>Request: </b>%4$s<br><br><b>Opened by: </b>%5$s<br><br><b>Stage: </b>%6$s]]></string>
<string name="connection_alert_dialog_title">No Connection Available</string>
<string name="connection_alert_dialog_message">Please check your device settings to ensure you have a working internet connection.</string>
......
......@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.google.gms:google-services:3.0.0'
......
......@@ -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