Commit 37ce0acf by Kunj Gupta

Local database configuration with existing code.

parents 3141cb84 df26a011
Showing with 2836 additions and 611 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,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()) {
Incident.IncidentBuilder builder = Incident.IncidentBuilder.anIncident();
fillAllIncidentFormDetails(c, builder);
incident = builder.build();
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);
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.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) {
ArrayAdapter<String> adapter = new ArrayAdapter(getActivity(),
android.R.layout.simple_list_item_1,
android.R.id.text1,
getReferenceForDisplay());
mListView.setAdapter(adapter);
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);
}
});
......
......@@ -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() {
@Override
public void onDoneApiCall(List<UserApiValues> userValues) {
mUserDetails = userValues;
}
});
} else if (syncStatus == SyncStatus.SERVICEDOWN) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(LoginScreen.this, R.string.server_not_reachable, Toast.LENGTH_LONG).show();
}
});
} else if (syncStatus == SyncStatus.FAIL) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(LoginScreen.this, R.string.login_screen_invalid_usernane_and_password_string, Toast.LENGTH_LONG).show();
}
});
}
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;
}
@Override
public void onFailApiCall() {
apiStatus = API_FAIL_USER_DETAIL;
}
});
}
} catch (Exception e) {
@Override
public void onFailApiCall() {
apiStatus = API_FAIL_USER_LOGIN;
}
});
return apiStatus;
}
@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.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 + '\'' +
'}';
}
}
......@@ -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:divider="@android:color/black"
android:dividerHeight="0.5dp"/>
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" />
</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>
......
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