Commit d094cfdb by Kunj Gupta

Added some items

Added HRCase flow in App with local db and sync functionality.
Fixed - Syncing is not working after getting network.
parent 04b8e06f
Showing with 5338 additions and 62 deletions
...@@ -91,15 +91,6 @@ ...@@ -91,15 +91,6 @@
<service android:name=".service.SyncService" /> <service android:name=".service.SyncService" />
<receiver
android:name=".receiver.NetworkChangeReceiver"
android:label="NetworkChangeReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
</intent-filter>
</receiver>
<meta-data <meta-data
android:name="io.fabric.ApiKey" android:name="io.fabric.ApiKey"
android:value="2b0a6e9db28d607fbcf71b8b25f1a0795e3f5b22" /> android:value="2b0a6e9db28d607fbcf71b8b25f1a0795e3f5b22" />
......
...@@ -18,6 +18,7 @@ import com.github.nkzawa.socketio.client.Socket; ...@@ -18,6 +18,7 @@ import com.github.nkzawa.socketio.client.Socket;
import com.google.android.gms.analytics.GoogleAnalytics; import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker; import com.google.android.gms.analytics.Tracker;
import com.vsoft.servicenow.db.DBManager; import com.vsoft.servicenow.db.DBManager;
import com.vsoft.servicenow.receiver.NetworkChangeReceiver;
import com.vsoft.servicenow.service.SyncService; import com.vsoft.servicenow.service.SyncService;
import com.vsoft.servicenow.ui.LoginScreen; import com.vsoft.servicenow.ui.LoginScreen;
import com.vsoft.servicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
...@@ -35,6 +36,7 @@ public class CatalogueApplication extends Application { ...@@ -35,6 +36,7 @@ public class CatalogueApplication extends Application {
private static Context mContext; private static Context mContext;
private Tracker mTracker; private Tracker mTracker;
private Socket mSocket; private Socket mSocket;
private NetworkChangeReceiver mNetworkChangeReceiver;
private BroadcastReceiver mSyncBroadCastSyncReceiver = new BroadcastReceiver() { private BroadcastReceiver mSyncBroadCastSyncReceiver = new BroadcastReceiver() {
@Override @Override
...@@ -89,6 +91,11 @@ public class CatalogueApplication extends Application { ...@@ -89,6 +91,11 @@ public class CatalogueApplication extends Application {
if(Util.isChatItemEnabled()) { if(Util.isChatItemEnabled()) {
initializeSocket(); initializeSocket();
} }
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
mNetworkChangeReceiver = new NetworkChangeReceiver();
registerReceiver(mNetworkChangeReceiver, intentFilter);
} }
@Override @Override
...@@ -96,6 +103,7 @@ public class CatalogueApplication extends Application { ...@@ -96,6 +103,7 @@ public class CatalogueApplication extends Application {
super.onTerminate(); super.onTerminate();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadCastLoginReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadCastLoginReceiver);
LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadCastSyncReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadCastSyncReceiver);
unregisterReceiver(mNetworkChangeReceiver);
} }
public static Context getContext() { public static Context getContext() {
......
package com.vsoft.servicenow.api.interfaces;
import com.vsoft.servicenow.db.models.CatalogueItem;
import com.vsoft.servicenow.db.models.CatalogueVariable;
import com.vsoft.servicenow.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;
import retrofit2.http.Url;
/**
* @since 1.0
* @author Kunj on 11/8/16.
*
*/
public interface HRCaseVariableApi {
// Get HRCase Variable API
@GET(Constants.URL_GET_HR_CASE_VARIABLE)
Call<ResponseBody> getVariable(@Query(CatalogueVariable.Json.SYS_ID) String sysId);
// Get HRCase Variable Choices API
@GET(Constants.URL_GET_HR_CASE_VARIABLE_CHOICE)
Call<ResponseBody> getVariableChoice(@Query(Constants.URL_PARAM_SYS_ID) String sysId);
// Post HRCase item API
@POST(Constants.URL_POST_HR_CASE_ITEM)
Call<ResponseBody> postHRCaseItem(@Query(CatalogueItem.Json.SYS_ID) String sysId,
@Body String catalogueItemJson);
// Get HRCase Reference API
@GET
Call<ResponseBody> getReference(@Url String url, @QueryMap Map<String, String> options);
// Post HRCase attachment API
@POST(Constants.URL_POST_HR_CASE_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 HRCase Variable API
@GET(Constants.URL_GET_HR_CASE_UI_POLICY)
Call<ResponseBody> getUiPolicy(@Query(CatalogueVariable.Json.SYS_ID) String sysId);
}
package com.vsoft.servicenow.api.listeners.get;
import com.vsoft.servicenow.db.models.HRCaseVariableResponse;
/**
* @since 1.0
* @author Kunj on 11/8/16
*
*/
public interface GetHRCaseVariableApiListener {
void onDoneApiCall(HRCaseVariableResponse catalogueVariableResponse);
void onFailApiCall();
}
package com.vsoft.servicenow.api.listeners.get;
import com.vsoft.servicenow.db.models.HRCaseVariableChoice;
import com.vsoft.servicenow.db.models.VariableChoice;
import java.util.List;
/**
* @since 1.0
* @author Kunj on 11/8/16
*
*/
public interface GetHRCaseVariableChoiceApiListener {
void onDoneApiCall(List<HRCaseVariableChoice> hrCaseVariableChoiceList);
void onFailApiCall();
}
package com.vsoft.servicenow.api.listeners.post;
/**
* @since 1.0
* @author Kunj on 11/8/16
*
*/
public interface PostHRCaseAttachmentApiListener {
void onDoneApiCall();
void onFailApiCall();
}
package com.vsoft.servicenow.api.listeners.post;
/**
* @since 1.0
* @author Kunj on 11/8/16
*
*/
public interface PostHRCaseVariableFormApiListener {
void onDoneApiCall(String hrCaseVariableFromSysId);
void onFailApiCall();
}
package com.vsoft.servicenow.api.managers;
import android.content.Context;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.vsoft.servicenow.api.RestClient;
import com.vsoft.servicenow.api.interfaces.HRCaseVariableApi;
import com.vsoft.servicenow.api.listeners.get.GetHRCaseVariableApiListener;
import com.vsoft.servicenow.api.listeners.post.PostHRCaseAttachmentApiListener;
import com.vsoft.servicenow.api.listeners.post.PostHRCaseVariableFormApiListener;
import com.vsoft.servicenow.db.models.CatalogueVariable;
import com.vsoft.servicenow.db.models.HRCaseVariable;
import com.vsoft.servicenow.db.models.HRCaseVariableChoice;
import com.vsoft.servicenow.db.models.HRCaseVariableResponse;
import com.vsoft.servicenow.db.models.HRCaseVariableSet;
import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.PrefManager;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.Comparator;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
/**
* @author Kunj on 11/8/16.
*
*/
public class HRCaseVariableApiManager {
public static void getHRCaseVariable(Context context, String hrCaseItemSysId, GetHRCaseVariableApiListener listener) {
CatalogueLog.d("HRCaseVariableApiManager: getHRCaseVariable: ");
String accessToken = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
if(accessToken.isEmpty()) {
listener.onFailApiCall();
return;
}
final Retrofit retrofit = RestClient.getInitializedRestAdapter(accessToken);
Call<ResponseBody> call = retrofit.create(HRCaseVariableApi.class).getVariable(hrCaseItemSysId);
try {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) {
try {
JSONObject jsonObject = new JSONObject(response.body().string());
JSONObject error = jsonObject.optJSONObject(Constants.RESPONSE_ERROR_OBJECT_NAME);
if (error == null) {
JSONArray jsonArray = jsonObject.getJSONArray(Constants.RESPONSE_RESULT_OBJECT_NAME);
if(jsonArray.length() > 0) {
Gson gson = new GsonBuilder()
.excludeFieldsWithoutExposeAnnotation()
.registerTypeAdapter(long.class, new JsonDeserializer<Long>() {
@Override
public Long deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
long value = 0;
try {
value = json.getAsLong();
} catch (NumberFormatException e) {
CatalogueLog.d("HRCaseVariableApiManager: getHRCaseVariable: deserialize: long.class: NumberFormatException: ");
}
return value;
}
})
.registerTypeAdapter(int.class, new JsonDeserializer<Integer>() {
@Override
public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
int value = 0;
try {
value = json.getAsInt();
} catch (NumberFormatException e) {
CatalogueLog.d("HRCaseVariableApiManager: getHRCaseVariable: deserialize: int.class: NumberFormatException: ");
}
return value;
}
})
.registerTypeAdapter(float.class, new JsonDeserializer<Float>() {
@Override
public Float deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
float value = 0;
try {
value = json.getAsFloat();
} catch (NumberFormatException e) {
CatalogueLog.e("HRCaseVariableApiManager: getHRCaseVariable: deserialize: float.class: NumberFormatException: ", e);
}
return value;
}
})
.create();
JSONObject hrCaseJsonObject = jsonArray.getJSONObject(0);
JSONArray hrCaseVariableJsonArray = hrCaseJsonObject.getJSONArray(Constants.RESPONSE_VARIABLES_OBJECT_NAME);
JSONArray hrCaseVariableSetJsonArray = hrCaseJsonObject.getJSONArray(Constants.RESPONSE_VARIABLE_SET_OBJECT_NAME);
HRCaseVariableResponse hrCaseVariableResponse = gson.fromJson(hrCaseJsonObject.toString(), HRCaseVariableResponse.class);
for (int i = 0; i < hrCaseVariableJsonArray.length(); i++) {
HRCaseVariable hrCaseVariable = hrCaseVariableResponse.getVariables().get(i);
JSONObject hrCaseVariableJsonObject = hrCaseVariableJsonArray.getJSONObject(i);
hrCaseVariable.parseJson(hrCaseVariableJsonObject);
if(hrCaseVariable.getVariableChoiceList() != null && !hrCaseVariable.getVariableChoiceList().isEmpty()) {
Collections.sort(hrCaseVariable.getVariableChoiceList(), new Comparator<HRCaseVariableChoice>() {
@Override
public int compare(HRCaseVariableChoice lhs, HRCaseVariableChoice rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
}
}
for (int i = 0; i < hrCaseVariableSetJsonArray.length(); i++) {
HRCaseVariableSet hrCaseVariableSet = hrCaseVariableResponse.getVariablesets().get(i);
JSONObject variableSetJsonObject = hrCaseVariableSetJsonArray.getJSONObject(i);
JSONArray variableJsonArray = variableSetJsonObject.getJSONArray(Constants.RESPONSE_VARIABLES_OBJECT_NAME);
for (int j = 0; j < variableJsonArray.length(); j++) {
JSONObject variableJsonObject = variableJsonArray.getJSONObject(j);
HRCaseVariable hrCaseVariable = hrCaseVariableSet.getVariables().get(j);
hrCaseVariable.parseJson(variableJsonObject);
if(!hrCaseVariable.getVariableChoiceList().isEmpty()) {
Collections.sort(hrCaseVariable.getVariableChoiceList(), new Comparator<HRCaseVariableChoice>() {
@Override
public int compare(HRCaseVariableChoice lhs, HRCaseVariableChoice rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
}
}
}
/*Sort Variable set*/
Collections.sort(hrCaseVariableResponse.getVariablesets(), new Comparator<HRCaseVariableSet>() {
@Override
public int compare(HRCaseVariableSet lhs, HRCaseVariableSet rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
/*Sort Variables*/
Collections.sort(hrCaseVariableResponse.getVariables(), new Comparator<HRCaseVariable>() {
@Override
public int compare(HRCaseVariable lhs, HRCaseVariable rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
/*Sort Variables of Variable sets*/
for (int i = 0; i < hrCaseVariableResponse.getVariablesets().size() ; i++) {
HRCaseVariableSet catalogueVariableSet = hrCaseVariableResponse.getVariablesets().get(i);
Collections.sort(catalogueVariableSet.getVariables(), new Comparator<HRCaseVariable>() {
@Override
public int compare(HRCaseVariable lhs, HRCaseVariable rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
}
listener.onDoneApiCall(hrCaseVariableResponse);
} else {
listener.onDoneApiCall(null);
}
} else
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("HRCaseVariableApiManager: getHRCaseVariable: onResponse: ", e);
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("HRCaseVariableApiManager: getHRCaseVariable: onResponse: ", e);
listener.onFailApiCall();
}
} else {
CatalogueLog.d("HRCaseVariableApiManager: getHRCaseVariable: : response is not success");
if (response.code() == 401) {
Log.d(Constants.TAG, "-- is 401, try refresh token...");
Log.d(Constants.TAG, "refresh token: " + PrefManager.getSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN));
SyncStatus status = LoginApiManager.refreshLogin(context, PrefManager.getSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN));
if (status == SyncStatus.SUCCESS) {
CatalogueLog.d("refresh token success, retry same...");
getHRCaseVariable(context, hrCaseItemSysId, listener);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
}
} else {
listener.onFailApiCall();
}
}
} catch (IOException e) {
CatalogueLog.e("HRCaseVariableApiManager: getHRCaseVariable: IOException: ", e);
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("HRCaseVariableApiManager: getHRCaseVariable: NullPointerException: ", e);
listener.onFailApiCall();
}
}
public static void submitHRCaseVariableForm(Context context, String hrCaseItemSysId, String hrCaseJsonString, PostHRCaseVariableFormApiListener listener) {
CatalogueLog.d("submitHRCaseVariableForm: " + hrCaseJsonString);
String accessToken = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
if(accessToken.isEmpty()) {
listener.onFailApiCall();
return;
}
final Retrofit retrofit = RestClient.getInitializedRestAdapter(accessToken);
Call<ResponseBody> call = retrofit.create(HRCaseVariableApi.class).postHRCaseItem(hrCaseItemSysId, hrCaseJsonString);
try {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) {
try {
JSONObject jsonObject = new JSONObject(response.body().string());
JSONObject error = jsonObject.optJSONObject(Constants.RESPONSE_ERROR_OBJECT_NAME);
if (error == null) {
String resultSysId = jsonObject.getString(Constants.RESPONSE_RESULT_OBJECT_NAME);
listener.onDoneApiCall(resultSysId);
}
} catch (JSONException e) {
e.printStackTrace();
listener.onFailApiCall();
}
} else {
CatalogueLog.d("HRCaseVariableApiManager: submitHRCaseVariableForm: response is not success");
if (response.code() == 401) {
Log.d(Constants.TAG, "-- is 401, try refresh token...");
Log.d(Constants.TAG, "refresh token: " + PrefManager.getSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN));
SyncStatus status = LoginApiManager.refreshLogin(context, PrefManager.getSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN));
if (status == SyncStatus.SUCCESS) {
CatalogueLog.d("refresh token success, retry same...");
submitHRCaseVariableForm(context, hrCaseItemSysId, hrCaseJsonString, listener);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
}
} else {
listener.onFailApiCall();
}
}
} catch (IOException e) {
CatalogueLog.e("HRCaseVariableApiManager: submitHRCaseVariableForm: IOException: ", e);
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("HRCaseVariableApiManager: submitHRCaseVariableForm: IOException: ", e);
listener.onFailApiCall();
}
}
public static void postHRCaseAttachment(Context context, String contentType, String tableSysId, String attachmentName, RequestBody requestBody, PostHRCaseAttachmentApiListener listener) {
CatalogueLog.d("postHRCaseAttachment: tableSysId: " + tableSysId);
String accessToken = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
if(accessToken.isEmpty()) {
listener.onFailApiCall();
return;
}
final Retrofit retrofit = RestClient.getInitializedRestAdapter(accessToken);
Call<ResponseBody> call = retrofit.create(HRCaseVariableApi.class).postAttachment(contentType, tableSysId, CatalogueVariable.Json.TABLE_NAME_VALUE, attachmentName, requestBody);
try {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) {
listener.onDoneApiCall();
} else {
CatalogueLog.d("HRCaseVariableApiManager: postHRCaseAttachment: response is not success");
if (response.code() == 401) {
Log.d(Constants.TAG, "-- is 401, try refresh token...");
Log.d(Constants.TAG, "refresh token: " + PrefManager.getSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN));
SyncStatus status = LoginApiManager.refreshLogin(context, PrefManager.getSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN));
if (status == SyncStatus.SUCCESS) {
CatalogueLog.d("refresh token success, retry same...");
postHRCaseAttachment(context, contentType, tableSysId, attachmentName, requestBody, listener);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
}
} else {
listener.onFailApiCall();
}
}
} catch (IOException e) {
CatalogueLog.e("HRCaseVariableApiManager: postHRCaseAttachment: IOException: ", e);
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("HRCaseVariableApiManager: postHRCaseAttachment: IOException: ", e);
listener.onFailApiCall();
}
}
}
package com.vsoft.servicenow.api.managers;
import android.content.Context;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.vsoft.servicenow.api.RestClient;
import com.vsoft.servicenow.api.interfaces.HRCaseVariableApi;
import com.vsoft.servicenow.api.listeners.get.GetHRCaseVariableChoiceApiListener;
import com.vsoft.servicenow.api.listeners.get.GetReferenceApiListener;
import com.vsoft.servicenow.db.models.HRCaseVariableChoice;
import com.vsoft.servicenow.db.models.Reference;
import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.PrefManager;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
/**
* @author Kunj on 11/8/16.
*bkunj@vscbkunj@vsc
*/
public class HRCaseVariableChoiceApiManager {
public static void getHRCaseVariableChoice(Context context, String hrCaseVariableSysId, GetHRCaseVariableChoiceApiListener listener) {
CatalogueLog.d("HRCaseVariableChoiceApiManager: getHRCaseVariableChoice: ");
String accessToken = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
if(accessToken.isEmpty()) {
listener.onFailApiCall();
return;
}
final Retrofit retrofit = RestClient.getInitializedRestAdapter(accessToken);
Call<ResponseBody> call = retrofit.create(HRCaseVariableApi.class).getVariableChoice(hrCaseVariableSysId);
try {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) {
try {
JSONObject jsonObject = new JSONObject(response.body().string());
JSONObject error = jsonObject.optJSONObject(Constants.RESPONSE_ERROR_OBJECT_NAME);
if (error == null) {
JSONArray hrCaseVariableChoiceJsonArray = jsonObject.getJSONArray(Constants.RESPONSE_RESULT_OBJECT_NAME);
if(hrCaseVariableChoiceJsonArray.length() > 0) {
Gson gson = new GsonBuilder()
.excludeFieldsWithoutExposeAnnotation()
.registerTypeAdapter(long.class, new JsonDeserializer<Long>() {
@Override
public Long deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
long value = 0;
try {
value = json.getAsLong();
} catch (NumberFormatException e) {
CatalogueLog.d("HRCaseVariableChoiceApiManager: getHRCaseVariableChoice: deserialize: long.class: NumberFormatException: ");
}
return value;
}
})
.registerTypeAdapter(int.class, new JsonDeserializer<Integer>() {
@Override
public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
int value = 0;
try {
value = json.getAsInt();
} catch (NumberFormatException e) {
CatalogueLog.d("HRCaseVariableChoiceApiManager: getHRCaseVariableChoice: deserialize: int.class: NumberFormatException: ");
}
return value;
}
})
.registerTypeAdapter(float.class, new JsonDeserializer<Float>() {
@Override
public Float deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
float value = 0;
try {
value = json.getAsFloat();
} catch (NumberFormatException e) {
CatalogueLog.e("HRCaseVariableChoiceApiManager: getHRCaseVariableChoice: deserialize: float.class: NumberFormatException: ", e);
}
return value;
}
})
.create();
List<HRCaseVariableChoice> hrCaseVariableChoiceItemList = new ArrayList<>(hrCaseVariableChoiceJsonArray.length());
for (int i = 0; i < hrCaseVariableChoiceJsonArray.length(); i++) {
JSONObject hrCaseVariableChoiceJsonObject = hrCaseVariableChoiceJsonArray.getJSONObject(i);
HRCaseVariableChoice hrCaseVariableChoice = gson.fromJson(hrCaseVariableChoiceJsonObject.toString(), HRCaseVariableChoice.class);
hrCaseVariableChoiceItemList.add(hrCaseVariableChoice);
}
listener.onDoneApiCall(hrCaseVariableChoiceItemList);
} else {
listener.onDoneApiCall(new ArrayList<HRCaseVariableChoice>(0));
}
} else
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("HRCaseVariableChoiceApiManager: getHRCaseVariableChoice: onResponse: ", e);
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("HRCaseVariableChoiceApiManager: getHRCaseVariableChoice: onResponse: ", e);
listener.onFailApiCall();
}
} else {
CatalogueLog.d("HRCaseVariableChoiceApiManager: getHRCaseVariableChoice: response is not success");
if(response.code() == 401) {
Log.d(Constants.TAG, "-- is 401, try refresh token...");
SyncStatus status = LoginApiManager.refreshLogin(context, PrefManager.getSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN));
if(status == SyncStatus.SUCCESS) {
CatalogueLog.d("refresh token success, retry same...");
getHRCaseVariableChoice(context, hrCaseVariableSysId, listener);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
listener.onFailApiCall();
}
} else {
listener.onFailApiCall();
}
}
} catch (IOException e) {
CatalogueLog.e("HRCaseVariableChoiceApiManager: getHRCaseVariableChoice: IOException: ", e);
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("HRCaseVariableChoiceApiManager: getHRCaseVariableChoice: NullPointerException: ", e);
listener.onFailApiCall();
}
}
public static void getHRCaseReference(Context context, String tableName, Map<String,String> queryMap, GetReferenceApiListener listener) {
CatalogueLog.d("HRCaseVariableChoiceApiManager: getHRCaseReference: tableName: "+tableName);
String accessToken = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
if(accessToken.isEmpty()) {
listener.onFailApiCall();
return;
}
final Retrofit retrofit = RestClient.getInitializedRestAdapter(accessToken);
Call<ResponseBody> call = retrofit.create(HRCaseVariableApi.class).getReference(Constants.URL_GET_HR_CASE_REFERENCE + tableName, queryMap);
try {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) {
try {
JSONObject jsonObject = new JSONObject(response.body().string());
JSONObject error = jsonObject.optJSONObject(Constants.RESPONSE_ERROR_OBJECT_NAME);
if (error == null) {
JSONArray hrCaseReferenceJsonArray = jsonObject.getJSONArray(Constants.RESPONSE_RESULT_OBJECT_NAME);
if(hrCaseReferenceJsonArray.length() > 0) {
Gson gson = new GsonBuilder()
.excludeFieldsWithoutExposeAnnotation()
.registerTypeAdapter(long.class, new JsonDeserializer<Long>() {
@Override
public Long deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
long value = 0;
try {
value = json.getAsLong();
} catch (NumberFormatException e) {
CatalogueLog.d("HRCaseVariableChoiceApiManager: getHRCaseReference: deserialize: long.class: NumberFormatException: ");
}
return value;
}
})
.registerTypeAdapter(int.class, new JsonDeserializer<Integer>() {
@Override
public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
int value = 0;
try {
value = json.getAsInt();
} catch (NumberFormatException e) {
CatalogueLog.d("HRCaseVariableChoiceApiManager: getHRCaseReference: deserialize: int.class: NumberFormatException: ");
}
return value;
}
})
.registerTypeAdapter(float.class, new JsonDeserializer<Float>() {
@Override
public Float deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
float value = 0;
try {
value = json.getAsFloat();
} catch (NumberFormatException e) {
CatalogueLog.e("HRCaseVariableChoiceApiManager: getHRCaseReference: deserialize: float.class: NumberFormatException: ", e);
}
return value;
}
})
.create();
List<Reference> referenceList = new ArrayList<>(hrCaseReferenceJsonArray.length());
for (int i = 0; i < hrCaseReferenceJsonArray.length(); i++) {
JSONObject referenceJsonObject = hrCaseReferenceJsonArray.getJSONObject(i);
Reference reference = gson.fromJson(referenceJsonObject.toString(), Reference.class);
referenceList.add(reference);
}
listener.onDoneApiCall(referenceList);
} else {
listener.onDoneApiCall(new ArrayList<Reference>(0));
}
} else
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("HRCaseVariableChoiceApiManager: getHRCaseReference: onResponse: ", e);
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("HRCaseVariableChoiceApiManager: getHRCaseReference: onResponse: ", e);
listener.onFailApiCall();
}
} else {
CatalogueLog.d("HRCaseVariableChoiceApiManager: getHRCaseReference: response is not success");
if(response.code() == 401) {
Log.d(Constants.TAG, "-- is 401, try refresh token...");
SyncStatus status = LoginApiManager.refreshLogin(context, PrefManager.getSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN));
if(status == SyncStatus.SUCCESS) {
CatalogueLog.d("refresh token success, retry same...");
getHRCaseReference(context, tableName, queryMap, listener);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
listener.onFailApiCall();
}
} else {
listener.onFailApiCall();
}
}
} catch (IOException e) {
CatalogueLog.e("HRCaseVariableChoiceApiManager: getHRCaseReference: IOException: ", e);
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("HRCaseVariableChoiceApiManager: getHRCaseReference: NullPointerException: ", e);
listener.onFailApiCall();
}
}
}
...@@ -20,7 +20,13 @@ public interface DBConstants { ...@@ -20,7 +20,13 @@ public interface DBConstants {
String TABLE_CHAT_BOT_HISTORY = "chat_bot_history"; String TABLE_CHAT_BOT_HISTORY = "chat_bot_history";
String TABLE_CHAT_BOT_USER = "chat_bot_user"; String TABLE_CHAT_BOT_USER = "chat_bot_user";
String TABLE_HR_CASE = "hr_case_category"; String TABLE_HR_CASE = "hr_case_category";
String TABLE_HR_CASE_ITEM = "hr_case__category_item"; String TABLE_HR_CASE_ITEM = "hr_case_category_item";
String TABLE_HR_CASE_ATTACHMENT = "hr_case_attachment";
String TABLE_HR_CASE_ITEM_INPUT = "hr_case_input_item";
String TABLE_HR_CASE_VARIABLES = "hr_case_variable";
String TABLE_HR_CASE_UI_POLICY_ACTION = "hr_case_ui_policy_action";
String TABLE_HR_CASE_UI_POLICY_ITEM = "hr_case_ui_policy_item";
String TABLE_HR_CASE_VARIABLE_CHOICES = "hr_case_variable_choices";
String ID = "_id"; String ID = "_id";
String SYS_ID = "sys_id"; String SYS_ID = "sys_id";
...@@ -79,8 +85,6 @@ public interface DBConstants { ...@@ -79,8 +85,6 @@ public interface DBConstants {
int CATALOGUE_ITEM_COLUMN_COUNT = 8; int CATALOGUE_ITEM_COLUMN_COUNT = 8;
/** /**
* Catalogue variables table * Catalogue variables table
*/ */
...@@ -458,4 +462,150 @@ public interface DBConstants { ...@@ -458,4 +462,150 @@ public interface DBConstants {
int INDEX_HR_CASE_ITEM_SYNC_DIRTY = 7; int INDEX_HR_CASE_ITEM_SYNC_DIRTY = 7;
int HR_CASE_ITEM_COLUMN_COUNT = 8; int HR_CASE_ITEM_COLUMN_COUNT = 8;
/**
* HR Case Attachment table
*/
String HR_CASE_ATTACHMENT_ID = ID;
String HR_CASE_ATTACHMENT_ITEM_INPUT_ID = "item_input_id";
String HR_CASE_ATTACHMENT_PATH = "attachment_path";
String HR_CASE_ATTACHMENT_MIME_TYPE = "mime_type";
String HR_CASE_ATTACHMENT_NAME = "name";
String HR_CASE_ATTACHMENT_SYNC_DIRTY = SYNC_DIRTY;
/**
* Attachment table. *Use these only if you fetch all columns*
*/
int INDEX_HR_CASE_ATTACHMENT_ID = 0;
int INDEX_HR_CASE_ATTACHMENT_ITEM_INPUT_ID = 1;
int INDEX_HR_CASE_ATTACHMENT_PATH = 2;
int INDEX_HR_CASE_ATTACHMENT_MIME_TYPE = 3;
int INDEX_HR_CASE_ATTACHMENT_NAME = 4;
int INDEX_HR_CASE_ATTACHMENT_SYNC_DIRTY = 5;
int HR_CASE_ATTACHMENT_COLUMN_COUNT = 6;
/**
* HRCaseItemInput table
*/
String HR_CASE_ITEM_INPUT_ID = ID;
String HR_CASE_ITEM_INPUT_HR_CASE_ITEM_ID = "hr_case_item_id";
String HR_CASE_ITEM_INPUT_DATA = "data";
String HR_CASE_ITEM_INPUT_SYS_ID = "sys_id";
String HR_CASE_ITEM_INPUT_SYNC_DIRTY = SYNC_DIRTY;
/**
* HRCaseItemInput table. *Use these only if you fetch all columns*
*/
int INDEX_HR_CASE_ITEM_INPUT_ID = 0;
int INDEX_HR_CASE_ITEM_INPUT_CATALOGUE_ITEM_ID = 1;
int INDEX_HR_CASE_ITEM_INPUT_DATA = 2;
int INDEX_HR_CASE_ITEM_INPUT_SYS_ID = 3;
int INDEX_HR_CASE_ITEM_INPUT_SYNC_DIRTY = 4;
int HR_CASE_ITEM_INPUT_COLUMN_COUNT = 5;
/**
* HR Case variables table
*/
String HR_CASE_VARIABLE_ID = ID;
String HR_CASE_VARIABLE_HR_CASE_ITEM_ID = "hr_case_item_id";
String HR_CASE_VARIABLE_SYS_ID = SYS_ID;
String HR_CASE_VARIABLE_NAME = "name";
String HR_CASE_VARIABLE_QUESTION_TEXT = "question_text";
String HR_CASE_VARIABLE_TYPE = "type";
String HR_CASE_VARIABLE_MANDATORY = "mandatory";
String HR_CASE_VARIABLE_NONE_REQUIRED = "none_required";
String HR_CASE_VARIABLE_REFERENCE_TABLE = "reference_table";
String HR_CASE_VARIABLE_ORDER= "variable_order";
String HR_CASE_VARIABLE_REFERENCE_COLUMN_NAME = "reference_column_name";
String HR_CASE_VARIABLE_ACTIVE = "active";
String HR_CASE_VARIABLE_DEFAULT_VALUE = "default_value";
String HR_CASE_VARIABLE_SYNC_DIRTY = SYNC_DIRTY;
/**
* Indices for HR Case variables table. *Use these only if you fetch all columns*
*/
int INDEX_HR_CASE_VARIABLE_ID = 0;
int INDEX_HR_CASE_VARIABLE_CATALOGUE_ITEM_ID = 1;
int INDEX_HR_CASE_VARIABLE_SYS_ID = 2;
int INDEX_HR_CASE_VARIABLE_NAME = 3;
int INDEX_HR_CASE_VARIABLE_QUESTION_TEXT = 4;
int INDEX_HR_CASE_VARIABLE_TYPE = 5;
int INDEX_HR_CASE_VARIABLE_MANDATORY = 6;
int INDEX_HR_CASE_VARIABLE_NONE_REQUIRED = 7;
int INDEX_HR_CASE_VARIABLE_REFERENCE = 8;
int INDEX_HR_CASE_VARIABLE_ORDER = 9;
int INDEX_HR_CASE_VARIABLE_REFERENCE_COLUMN_NAME = 10;
int INDEX_HR_CASE_VARIABLE_ACTIVE = 11;
int INDEX_HR_CASE_VARIABLE_DEFAULT_VALUE = 12;
int INDEX_HR_CASE_VARIABLE_SYNC_DIRTY = 13;
int HR_CASE_VARIABLE_COLUMN_COUNT = 14;
/**
* HRCaseUiPolicyAction table
*/
String HR_CASE_UI_POLICY_ACTION_ID = ID;
String HR_CASE_UI_POLICY_ACTION_POLICY_ITEM_ID = "hr_case_ui_policy_item_id";
String HR_CASE_UI_POLICY_ACTION_VISIBLE = "visible";
String HR_CASE_UI_POLICY_ACTION_MANDATORY = "mandatory";
String HR_CASE_UI_POLICY_ACTION_VARIABLE = "variable";
String HR_CASE_UI_POLICY_ACTION_DISABLED = "disabled";
String HR_CASE_UI_POLICY_ACTION_SYNC_DIRTY = SYNC_DIRTY;
/**
* HRCaseUiPolicyAction table. *Use these only if you fetch all columns*
*/
int INDEX_HR_CASE_UI_POLICY_ACTION_ID = 0;
int INDEX_HR_CASE_UI_POLICY_ACTION_POLICY_ITEM_ID = 1;
int INDEX_HR_CASE_UI_POLICY_ACTION_VISIBLE = 2;
int INDEX_HR_CASE_UI_POLICY_ACTION_MANDATORY = 3;
int INDEX_HR_CASE_UI_POLICY_ACTION_VARIABLE = 4;
int INDEX_HR_CASE_UI_POLICY_ACTION_DISABLED = 5;
int INDEX_HR_CASE_UI_POLICY_ACTION_SYNC_DIRTY = 6;
int HR_CASE_UI_POLICY_ACTION_COLUMN_COUNT = 7;
/**
* HRCaseUiPolicyItem table
*/
String HR_CASE_UI_POLICY_ITEM_ID = ID;
String HR_CASE_UI_POLICY_ITEM_HR_CASE_ITEM_ID = "hr_case_item_id";
String HR_CASE_UI_POLICY_ITEM_CONDITION = "condition";
String HR_CASE_UI_POLICY_ITEM_SYS_ID = "sys_id";
String HR_CASE_UI_POLICY_ITEM_SYNC_DIRTY = SYNC_DIRTY;
/**
* HRCaseUiPolicyItem table. *Use these only if you fetch all columns*
*/
int INDEX_HR_CASE_UI_POLICY_ITEM_ID = 0;
int INDEX_HR_CASE_UI_POLICY_ITEM_HR_CASE_ITEM_ID = 1;
int INDEX_HR_CASE_UI_POLICY_ITEM_CONDITION = 2;
int INDEX_HR_CASE_UI_POLICY_ITEM_SYS_ID = 3;
int INDEX_HR_CASE_UI_POLICY_ITEM_SYNC_DIRTY = 4;
int HR_CASE_UI_POLICY_ITEM_COLUMN_COUNT = 5;
/**
* HR Case Variables Choice table
*/
String HR_CASE_VARIABLE_CHOICE_ID = ID;
String HR_CASE_VARIABLE_CHOICE_VARIABLE_ID = "variable_id";
String HR_CASE_VARIABLE_CHOICE_TEXT = "text";
String HR_CASE_VARIABLE_CHOICE_VALUE = "value";
String HR_CASE_VARIABLE_CHOICE_ORDER = "choice_order";
String HR_CASE_VARIABLE_CHOICE_MISC = "misc";
/**
* Indices for HR Case Variables Choice table. *Use these only if you fetch all columns*
*/
int INDEX_HR_CASE_VARIABLE_CHOICE_ID = 0;
int INDEX_HR_CASE_VARIABLE_CHOICE_VARIABLE_ID = 1;
int INDEX_HR_CASE_VARIABLE_CHOICE_TEXT = 2;
int INDEX_HR_CASE_VARIABLE_CHOICE_VALUE = 3;
int INDEX_HR_CASE_VARIABLE_CHOICE_ORDER = 4;
int INDEX_HR_CASE_VARIABLE_CHOICE_MISC = 5;
int HR_CASE_VARIABLE_CHOICE_COLUMN_COUNT = 6;
} }
\ No newline at end of file
...@@ -53,6 +53,12 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants { ...@@ -53,6 +53,12 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
if(Util.isHrCaseEnabled()) { if(Util.isHrCaseEnabled()) {
createHRCaseTable(db); createHRCaseTable(db);
createHRCaseItemsTable(db); createHRCaseItemsTable(db);
createHRCaseAttachmentTable(db);
createHRCaseItemInputTable(db);
createHRCaseVariableTable(db);
createHRCaseUiPolicyActionTable(db);
createHRCaseUiPolicyItemTable(db);
createHRCaseVariableChoiceTable(db);
} }
} }
...@@ -264,4 +270,73 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants { ...@@ -264,4 +270,73 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
+ HR_CASE_ITEM_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + HR_CASE_ITEM_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE
+ ");"); + ");");
} }
private void createHRCaseAttachmentTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_HR_CASE_ATTACHMENT + "("
+ HR_CASE_ATTACHMENT_ID + " integer primary key autoincrement, "
+ HR_CASE_ATTACHMENT_ITEM_INPUT_ID + " integer default -1, "
+ HR_CASE_ATTACHMENT_PATH + " text, "
+ HR_CASE_ATTACHMENT_MIME_TYPE + " text, "
+ HR_CASE_ATTACHMENT_NAME + " text, "
+ HR_CASE_ATTACHMENT_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");");
}
private void createHRCaseItemInputTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_HR_CASE_ITEM_INPUT + "("
+ HR_CASE_ITEM_INPUT_ID + " integer primary key autoincrement, "
+ HR_CASE_ITEM_INPUT_HR_CASE_ITEM_ID + " integer default -1, "
+ HR_CASE_ITEM_INPUT_DATA + " text, "
+ HR_CASE_ITEM_INPUT_SYS_ID + " text, "
+ HR_CASE_ITEM_INPUT_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");");
}
private void createHRCaseVariableTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_HR_CASE_VARIABLES + "("
+ HR_CASE_VARIABLE_ID + " integer primary key autoincrement, "
+ HR_CASE_VARIABLE_HR_CASE_ITEM_ID + " integer default -1, "
+ HR_CASE_VARIABLE_SYS_ID + " text, "
+ HR_CASE_VARIABLE_NAME + " text, "
+ HR_CASE_VARIABLE_QUESTION_TEXT + " text, "
+ HR_CASE_VARIABLE_TYPE + " integer, "
+ HR_CASE_VARIABLE_MANDATORY + " integer, "
+ HR_CASE_VARIABLE_NONE_REQUIRED + " integer, "
+ HR_CASE_VARIABLE_REFERENCE_TABLE + " text, "
+ HR_CASE_VARIABLE_ORDER + " text, "
+ HR_CASE_VARIABLE_REFERENCE_COLUMN_NAME + " text, "
+ HR_CASE_VARIABLE_ACTIVE + " integer, "
+ HR_CASE_VARIABLE_DEFAULT_VALUE + " text, "
+ HR_CASE_VARIABLE_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE
+ ");");
}
private void createHRCaseUiPolicyActionTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_HR_CASE_UI_POLICY_ACTION + "("
+ HR_CASE_UI_POLICY_ACTION_ID + " integer primary key autoincrement, "
+ HR_CASE_UI_POLICY_ACTION_POLICY_ITEM_ID + " integer default -1, "
+ HR_CASE_UI_POLICY_ACTION_VISIBLE + " text, "
+ HR_CASE_UI_POLICY_ACTION_MANDATORY + " text, "
+ HR_CASE_UI_POLICY_ACTION_VARIABLE + " text, "
+ HR_CASE_UI_POLICY_ACTION_DISABLED + " text, "
+ HR_CASE_UI_POLICY_ACTION_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");");
}
private void createHRCaseUiPolicyItemTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_HR_CASE_UI_POLICY_ITEM + "("
+ HR_CASE_UI_POLICY_ITEM_ID + " integer primary key autoincrement, "
+ HR_CASE_UI_POLICY_ITEM_HR_CASE_ITEM_ID + " integer default -1, "
+ HR_CASE_UI_POLICY_ITEM_CONDITION + " text, "
+ HR_CASE_UI_POLICY_ITEM_SYS_ID + " text, "
+ HR_CASE_UI_POLICY_ITEM_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");");
}
private void createHRCaseVariableChoiceTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_HR_CASE_VARIABLE_CHOICES + "("
+ HR_CASE_VARIABLE_CHOICE_ID + " integer primary key autoincrement, "
+ HR_CASE_VARIABLE_CHOICE_VARIABLE_ID + " integer default -1, "
+ HR_CASE_VARIABLE_CHOICE_TEXT + " text, "
+ HR_CASE_VARIABLE_CHOICE_VALUE + " integer, "
+ HR_CASE_VARIABLE_CHOICE_ORDER + " integer, "
+ HR_CASE_VARIABLE_CHOICE_MISC + " real);");
}
} }
package com.vsoft.servicenow.db.managers;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.DBConstants;
import com.vsoft.servicenow.db.models.Attachment;
import com.vsoft.servicenow.db.models.HRCaseAttachment;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Kunj on 11-08-2016.
*/
public class HRCaseAttachmentManager implements DBConstants {
public static long save(HRCaseAttachment hrCaseAttachment, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
hrCaseAttachment.setSyncDirty(syncDirty);
long id = db.insert(TABLE_HR_CASE_ATTACHMENT, null, getContentValues(hrCaseAttachment));
hrCaseAttachment.setId(id);
return id;
} else {
return -1;
}
}
public static int delete(HRCaseAttachment hrCaseAttachment) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
return db.delete(TABLE_HR_CASE_ATTACHMENT, HR_CASE_ATTACHMENT_ID + "=" + hrCaseAttachment.getId(), null);
}
return -1;
}
public static int update(HRCaseAttachment hrCaseAttachment, int syncDirty) {
return update(hrCaseAttachment, null, syncDirty);
}
public static int update(HRCaseAttachment hrCaseAttachment, List<String> column, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
hrCaseAttachment.setSyncDirty(syncDirty);
if (column == null || column.size() == 0) {
return db.update(TABLE_HR_CASE_ATTACHMENT, getContentValues(hrCaseAttachment), HR_CASE_ATTACHMENT_ID + "=" + hrCaseAttachment.getId(), null);
} else {
ContentValues contentValues = new ContentValues(column.size());
contentValues.put(HR_CASE_ATTACHMENT_SYNC_DIRTY, hrCaseAttachment.getSyncDirty());
for (int i = 0; i < column.size(); i++) {
String columnName = column.get(i);
if (HR_CASE_ATTACHMENT_ITEM_INPUT_ID.equals(columnName)) {
contentValues.put(HR_CASE_ATTACHMENT_ITEM_INPUT_ID, hrCaseAttachment.getItemInputId());
} else if (HR_CASE_ATTACHMENT_PATH.equals(columnName)) {
contentValues.put(HR_CASE_ATTACHMENT_PATH, hrCaseAttachment.getPath());
} else if (HR_CASE_ATTACHMENT_NAME.equals(columnName)) {
contentValues.put(HR_CASE_ATTACHMENT_NAME, hrCaseAttachment.getName());
} else if (HR_CASE_ATTACHMENT_MIME_TYPE.equals(columnName)) {
contentValues.put(HR_CASE_ATTACHMENT_MIME_TYPE, hrCaseAttachment.getMimeType());
}
}
return db.update(TABLE_HR_CASE_ATTACHMENT, contentValues, HR_CASE_ATTACHMENT_ID + "=" + hrCaseAttachment.getId(), null);
}
} else {
return -1;
}
}
public static List<HRCaseAttachment> getAllHRCaseAttachment(long inputItemId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_HR_CASE_ATTACHMENT
+ " where " + HR_CASE_ATTACHMENT_ITEM_INPUT_ID + "=" + inputItemId
+ " and " + HR_CASE_ATTACHMENT_SYNC_DIRTY + "!=" + DBConstants.SYNC_FLAG_DELETE, null);
ArrayList<HRCaseAttachment> hrCaseAttachmentList;
if (c.getCount() > 0) {
hrCaseAttachmentList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
HRCaseAttachment.HRCaseAttachmentBuilder builder = HRCaseAttachment.HRCaseAttachmentBuilder.aHRCaseAttachment();
fillAllHRCaseAttachmentDetails(c, builder);
hrCaseAttachmentList.add(builder.build());
}
} else {
hrCaseAttachmentList = new ArrayList<>(0);
}
c.close();
return hrCaseAttachmentList;
} else {
return new ArrayList<>(0);
}
}
public static HRCaseAttachment get(long hrCaseAttachmentId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
HRCaseAttachment hrCaseAttachment = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_HR_CASE_ATTACHMENT + " where " + HR_CASE_ATTACHMENT_ID + "=" + hrCaseAttachmentId, null);
if (c.moveToFirst()) {
HRCaseAttachment.HRCaseAttachmentBuilder builder = HRCaseAttachment.HRCaseAttachmentBuilder.aHRCaseAttachment();
fillAllHRCaseAttachmentDetails(c, builder);
hrCaseAttachment = builder.build();
}
c.close();
}
return hrCaseAttachment;
}
public static List<HRCaseAttachment> getDirtyHRCaseAttachment() {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if(db!=null) {
Cursor c = db.rawQuery("select * from " + TABLE_HR_CASE_ATTACHMENT
+ " where " + HR_CASE_ATTACHMENT_SYNC_DIRTY + ">" + SYNC_FLAG_NONE , null);
ArrayList<HRCaseAttachment> hrCaseAttachmentList;
if (c.getCount() > 0) {
hrCaseAttachmentList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
HRCaseAttachment.HRCaseAttachmentBuilder builder = HRCaseAttachment.HRCaseAttachmentBuilder.aHRCaseAttachment();
fillAllHRCaseAttachmentDetails(c, builder);
hrCaseAttachmentList.add(builder.build());
}
} else {
hrCaseAttachmentList = new ArrayList<>(0);
}
c.close();
return hrCaseAttachmentList;
} else {
return new ArrayList<>(0);
}
}
private static void fillAllHRCaseAttachmentDetails(Cursor c, HRCaseAttachment.HRCaseAttachmentBuilder builder) {
builder.setId(c.getLong(INDEX_HR_CASE_ATTACHMENT_ID));
builder.setItemInputId(c.getLong(INDEX_HR_CASE_ATTACHMENT_ITEM_INPUT_ID));
builder.setPath(c.getString(INDEX_HR_CASE_ATTACHMENT_PATH));
builder.setName(c.getString(INDEX_HR_CASE_ATTACHMENT_NAME));
builder.setMimeType(c.getString(INDEX_HR_CASE_ATTACHMENT_MIME_TYPE));
builder.setSyncDirty(c.getInt(INDEX_HR_CASE_ATTACHMENT_SYNC_DIRTY));
}
private static ContentValues getContentValues(HRCaseAttachment hrCaseAttachment) {
ContentValues cv = new ContentValues(HR_CASE_ATTACHMENT_COLUMN_COUNT - 1);
cv.put(HR_CASE_ATTACHMENT_ITEM_INPUT_ID, hrCaseAttachment.getItemInputId());
cv.put(HR_CASE_ATTACHMENT_PATH, hrCaseAttachment.getPath());
cv.put(HR_CASE_ATTACHMENT_NAME, hrCaseAttachment.getName());
cv.put(HR_CASE_ATTACHMENT_MIME_TYPE, hrCaseAttachment.getMimeType());
cv.put(HR_CASE_ATTACHMENT_SYNC_DIRTY, hrCaseAttachment.getSyncDirty());
return cv;
}
}
\ No newline at end of file
package com.vsoft.servicenow.db.managers;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.DBConstants;
import com.vsoft.servicenow.db.models.CatalogueItemInput;
import com.vsoft.servicenow.db.models.HRCaseItemInput;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Kunj on 11-08-2016.
*/
public class HRCaseItemInputManager implements DBConstants {
public static long save(HRCaseItemInput hrCaseItemInput, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
hrCaseItemInput.setSyncDirty(syncDirty);
long id = db.insert(TABLE_HR_CASE_ITEM_INPUT, null, getContentValues(hrCaseItemInput));
hrCaseItemInput.setId(id);
return id;
} else {
return -1;
}
}
public static int delete(HRCaseItemInput hrCaseItemInput) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
if (hrCaseItemInput.getSysId() == null || hrCaseItemInput.getSysId().isEmpty()) {
return db.delete(TABLE_HR_CASE_ITEM_INPUT, HR_CASE_ITEM_INPUT_ID + "=" + hrCaseItemInput.getId(), null);
} else {
return update(hrCaseItemInput, SYNC_FLAG_DELETE);
}
}
return -1;
}
public static int update(HRCaseItemInput hrCaseItemInput, int syncDirty) {
return update(hrCaseItemInput, null, syncDirty);
}
public static int update(HRCaseItemInput hrCaseItemInput, List<String> column, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
hrCaseItemInput.setSyncDirty(syncDirty);
if (column == null || column.size() == 0) {
return db.update(TABLE_HR_CASE_ITEM_INPUT, getContentValues(hrCaseItemInput), HR_CASE_ITEM_INPUT_ID + "=" + hrCaseItemInput.getId(), null);
} else {
ContentValues contentValues = new ContentValues(column.size());
contentValues.put(CATALOGUE_VARIABLE_SYNC_DIRTY, hrCaseItemInput.getSyncDirty());
for (int i = 0; i < column.size(); i++) {
String columnName = column.get(i);
if (HR_CASE_ITEM_INPUT_HR_CASE_ITEM_ID.equals(columnName)) {
contentValues.put(HR_CASE_ITEM_INPUT_HR_CASE_ITEM_ID, hrCaseItemInput.getHRCaseItemId());
} else if (HR_CASE_ITEM_INPUT_DATA.equals(columnName)) {
contentValues.put(HR_CASE_ITEM_INPUT_DATA, hrCaseItemInput.getData());
} else if (HR_CASE_ITEM_INPUT_SYS_ID.equals(columnName)) {
contentValues.put(HR_CASE_ITEM_INPUT_SYS_ID, hrCaseItemInput.getSysId());
} else if (HR_CASE_ITEM_INPUT_SYNC_DIRTY.equals(columnName)) {
contentValues.put(HR_CASE_ITEM_INPUT_SYNC_DIRTY, hrCaseItemInput.getSyncDirty());
}
}
return db.update(TABLE_HR_CASE_ITEM_INPUT, contentValues, HR_CASE_ITEM_INPUT_ID + "=" + hrCaseItemInput.getId(), null);
}
} else {
return -1;
}
}
public static List<HRCaseItemInput> getAllItemInput(long hrCaseItemId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_HR_CASE_ITEM_INPUT
+ " where " + HR_CASE_ITEM_INPUT_HR_CASE_ITEM_ID + "=" + hrCaseItemId
+ " and " + HR_CASE_ITEM_INPUT_SYNC_DIRTY + "!=" + DBConstants.SYNC_FLAG_DELETE, null);
ArrayList<HRCaseItemInput> itemInputList;
if (c.getCount() > 0) {
itemInputList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
HRCaseItemInput.HRCaseItemInputBuilder builder = HRCaseItemInput.HRCaseItemInputBuilder.aHRCaseItemInput();
fillAllItemInputDetails(c, builder);
itemInputList.add(builder.build());
}
} else {
itemInputList = new ArrayList<>(0);
}
c.close();
return itemInputList;
} else {
return new ArrayList<>(0);
}
}
public static HRCaseItemInput get(long catalogueInputId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
HRCaseItemInput hrCaseItemInput = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_HR_CASE_ITEM_INPUT + " where " + HR_CASE_ITEM_INPUT_ID + "=" + catalogueInputId, null);
if (c.moveToFirst()) {
HRCaseItemInput.HRCaseItemInputBuilder builder = HRCaseItemInput.HRCaseItemInputBuilder.aHRCaseItemInput();
fillAllItemInputDetails(c, builder);
hrCaseItemInput = builder.build();
}
c.close();
}
return hrCaseItemInput;
}
public static HRCaseItemInput getItemInputFromSysId(String sysId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
HRCaseItemInput hrCaseItemInput = null;
if(db!=null) {
Cursor c = db.rawQuery("select * from " + TABLE_HR_CASE_ITEM_INPUT + " where " + HR_CASE_ITEM_INPUT_SYS_ID + "='" + sysId + "'", null);
if (c.moveToFirst()) {
HRCaseItemInput.HRCaseItemInputBuilder builder = HRCaseItemInput.HRCaseItemInputBuilder.aHRCaseItemInput();
fillAllItemInputDetails(c, builder);
hrCaseItemInput = builder.build();
}
c.close();
}
return hrCaseItemInput;
}
public static void handleSaveServerResponse(HRCaseItemInput hrCaseItemInput, List<String> column, int syncFlag) {
update(hrCaseItemInput, column, syncFlag);
}
public static List<HRCaseItemInput> getDirtyItemInput() {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if(db!=null) {
Cursor c = db.rawQuery("select * from " + TABLE_HR_CASE_ITEM_INPUT
+ " where " + HR_CASE_ITEM_INPUT_SYNC_DIRTY + ">" + SYNC_FLAG_NONE , null);
ArrayList<HRCaseItemInput> itemInputList;
if (c.getCount() > 0) {
itemInputList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
HRCaseItemInput.HRCaseItemInputBuilder builder = HRCaseItemInput.HRCaseItemInputBuilder.aHRCaseItemInput();
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, HRCaseItemInput.HRCaseItemInputBuilder builder) {
builder.setId(c.getLong(INDEX_HR_CASE_ITEM_INPUT_ID));
builder.setHRCaseItemId(c.getLong(INDEX_HR_CASE_ITEM_INPUT_CATALOGUE_ITEM_ID));
builder.setSysId(c.getString(INDEX_HR_CASE_ITEM_INPUT_SYS_ID));
builder.setData(c.getString(INDEX_HR_CASE_ITEM_INPUT_DATA));
builder.setSyncDirty(c.getInt(INDEX_HR_CASE_ITEM_INPUT_SYNC_DIRTY));
}
private static ContentValues getContentValues(HRCaseItemInput hrCaseItemInput) {
ContentValues cv = new ContentValues(HR_CASE_ITEM_INPUT_COLUMN_COUNT - 1);
cv.put(HR_CASE_ITEM_INPUT_HR_CASE_ITEM_ID, hrCaseItemInput.getHRCaseItemId());
cv.put(HR_CASE_ITEM_INPUT_SYS_ID, hrCaseItemInput.getSysId());
cv.put(HR_CASE_ITEM_INPUT_DATA, hrCaseItemInput.getData());
cv.put(HR_CASE_ITEM_INPUT_SYNC_DIRTY, hrCaseItemInput.getSyncDirty());
return cv;
}
}
\ No newline at end of file
package com.vsoft.servicenow.db.managers;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.DBConstants;
import com.vsoft.servicenow.db.models.HRCaseUiPolicyAction;
import com.vsoft.servicenow.db.models.UiPolicyAction;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Kunj on 18-11-2016.
*/
public class HRCaseUiPolicyActionManager implements DBConstants {
public static long save(HRCaseUiPolicyAction hrCaseUiPolicyAction, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
hrCaseUiPolicyAction.setSyncDirty(syncDirty);
long id = db.insert(TABLE_HR_CASE_UI_POLICY_ACTION, null, getContentValues(hrCaseUiPolicyAction));
hrCaseUiPolicyAction.setId(id);
return id;
} else {
return -1;
}
}
public static int delete(HRCaseUiPolicyAction hrCaseUiPolicyAction) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
return db.delete(TABLE_HR_CASE_UI_POLICY_ACTION, HR_CASE_UI_POLICY_ACTION_ID + "=" + hrCaseUiPolicyAction.getId(), null);
}
return -1;
}
public static int update(HRCaseUiPolicyAction hrCaseUiPolicyAction, int syncDirty) {
return update(hrCaseUiPolicyAction, null, syncDirty);
}
public static int update(HRCaseUiPolicyAction hrCaseUiPolicyAction, List<String> column, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
hrCaseUiPolicyAction.setSyncDirty(syncDirty);
if (column == null || column.size() == 0) {
return db.update(TABLE_HR_CASE_UI_POLICY_ACTION, getContentValues(hrCaseUiPolicyAction), HR_CASE_UI_POLICY_ACTION_ID + "=" + hrCaseUiPolicyAction.getId(), null);
} else {
ContentValues contentValues = new ContentValues(column.size());
contentValues.put(HR_CASE_UI_POLICY_ACTION_SYNC_DIRTY, hrCaseUiPolicyAction.getSyncDirty());
for (int i = 0; i < column.size(); i++) {
String columnName = column.get(i);
if (HR_CASE_UI_POLICY_ACTION_POLICY_ITEM_ID.equals(columnName)) {
contentValues.put(HR_CASE_UI_POLICY_ACTION_POLICY_ITEM_ID, hrCaseUiPolicyAction.getHRCaseUiPolicyItemId());
} else if (HR_CASE_UI_POLICY_ACTION_MANDATORY.equals(columnName)) {
contentValues.put(HR_CASE_UI_POLICY_ACTION_MANDATORY, hrCaseUiPolicyAction.getMandatory());
} else if (HR_CASE_UI_POLICY_ACTION_DISABLED.equals(columnName)) {
contentValues.put(HR_CASE_UI_POLICY_ACTION_DISABLED, hrCaseUiPolicyAction.getDisabled());
} else if (HR_CASE_UI_POLICY_ACTION_VISIBLE.equals(columnName)) {
contentValues.put(HR_CASE_UI_POLICY_ACTION_VISIBLE, hrCaseUiPolicyAction.getVisible());
} else if (HR_CASE_UI_POLICY_ACTION_VARIABLE.equals(columnName)) {
contentValues.put(HR_CASE_UI_POLICY_ACTION_VARIABLE, hrCaseUiPolicyAction.getVariableName());
}
}
return db.update(TABLE_HR_CASE_UI_POLICY_ACTION, contentValues, HR_CASE_UI_POLICY_ACTION_ID + "=" + hrCaseUiPolicyAction.getId(), null);
}
} else {
return -1;
}
}
public static boolean handleGetUiPolicyAction(List<HRCaseUiPolicyAction> serverHRCaseUiPolicyActionList, long hrCaseUiPolicyItemId) {
boolean hasChanged = false;
if(serverHRCaseUiPolicyActionList != null && !serverHRCaseUiPolicyActionList.isEmpty()) {
/*localHRCaseUiPolicyActionList is contain all local HRCaseUiPolicyAction */
List<HRCaseUiPolicyAction> localHRCaseUiPolicyActionList = getAllUiPolicyActions(hrCaseUiPolicyItemId);
if(!localHRCaseUiPolicyActionList.isEmpty()) {
for (int i = 0; i < serverHRCaseUiPolicyActionList.size(); i++) {
HRCaseUiPolicyAction serverUiPolicyAction = serverHRCaseUiPolicyActionList.get(i);
for (int j = 0; j < localHRCaseUiPolicyActionList.size(); j++) {
HRCaseUiPolicyAction localUiPolicyAction = localHRCaseUiPolicyActionList.get(j);
if (serverUiPolicyAction.getHRCaseUiPolicyItemId() != localUiPolicyAction.getHRCaseUiPolicyItemId()) {
continue;
} else {
if (!localUiPolicyAction.getMandatory().equals(serverUiPolicyAction.getMandatory())) {
hasChanged = true;
continue;
}
if (!localUiPolicyAction.getDisabled().equals(serverUiPolicyAction.getDisabled())) {
hasChanged = true;
continue;
}
if (!localUiPolicyAction.getVisible().equals(serverUiPolicyAction.getVisible())) {
hasChanged = true;
continue;
}
if (!localUiPolicyAction.getVariableName().equals(serverUiPolicyAction.getVariableName())) {
hasChanged = true;
continue;
}
}
}
}
} else {
hasChanged = true;
}
/*Check this HRCaseUiPolicyItem 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 < serverHRCaseUiPolicyActionList.size(); i++) {
HRCaseUiPolicyAction uiPolicyAction = serverHRCaseUiPolicyActionList.get(i);
uiPolicyAction.setHRCaseUiPolicyItemId(hrCaseUiPolicyItemId);
save(uiPolicyAction, DBConstants.SYNC_FLAG_NONE);
}
} else {
/*That means there is no HRCaseUiPolicyAction in server response, then all local items should be deleted those are contain sys_id*/
/*localPolicyActionList is contain all local Catalogues */
List<HRCaseUiPolicyAction> localPolicyActionList = getAllUiPolicyActions(hrCaseUiPolicyItemId);
if (localPolicyActionList != null && !localPolicyActionList.isEmpty()) {
for (int i = 0; i < localPolicyActionList.size(); i++) {
HRCaseUiPolicyAction localUiPolicyAction = localPolicyActionList.get(i);
delete(localUiPolicyAction);
}
}
}
return hasChanged;
}
public static List<HRCaseUiPolicyAction> getAllUiPolicyActions(long uiPolicyItemId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_HR_CASE_UI_POLICY_ACTION
+ " where " + HR_CASE_UI_POLICY_ACTION_POLICY_ITEM_ID + "=" + uiPolicyItemId
+ " and " + HR_CASE_UI_POLICY_ACTION_SYNC_DIRTY
+ "!=" + DBConstants.SYNC_FLAG_DELETE, null);
ArrayList<HRCaseUiPolicyAction> uiPolicyActionList;
if (c.getCount() > 0) {
uiPolicyActionList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
HRCaseUiPolicyAction.HRCaseUiPolicyActionBuilder builder = HRCaseUiPolicyAction.HRCaseUiPolicyActionBuilder.aHRCaseUiPolicyAction();
fillAllHRCaseUiPolicyActionDetails(c, builder);
uiPolicyActionList.add(builder.build());
}
} else {
uiPolicyActionList = new ArrayList<>(0);
}
c.close();
return uiPolicyActionList;
} else {
return new ArrayList<>(0);
}
}
public static HRCaseUiPolicyAction get(long uiPolicyActionId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
HRCaseUiPolicyAction hrCaseUiPolicyAction = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_HR_CASE_UI_POLICY_ACTION + " where " + HR_CASE_UI_POLICY_ACTION_ID + "=" + uiPolicyActionId, null);
if (c.moveToFirst()) {
HRCaseUiPolicyAction.HRCaseUiPolicyActionBuilder builder = HRCaseUiPolicyAction.HRCaseUiPolicyActionBuilder.aHRCaseUiPolicyAction();
fillAllHRCaseUiPolicyActionDetails(c, builder);
hrCaseUiPolicyAction = builder.build();
}
c.close();
}
return hrCaseUiPolicyAction;
}
private static void fillAllHRCaseUiPolicyActionDetails(Cursor c, HRCaseUiPolicyAction.HRCaseUiPolicyActionBuilder builder) {
builder.setId(c.getLong(INDEX_HR_CASE_UI_POLICY_ACTION_ID));
builder.setHRCaseUiPolicyItemId(c.getLong(INDEX_HR_CASE_UI_POLICY_ACTION_POLICY_ITEM_ID));
builder.setVisible(c.getString(INDEX_HR_CASE_UI_POLICY_ACTION_VISIBLE));
builder.setMandatory(c.getString(INDEX_HR_CASE_UI_POLICY_ACTION_MANDATORY));
builder.setVariableName(c.getString(INDEX_HR_CASE_UI_POLICY_ACTION_VARIABLE));
builder.setDisabled(c.getString(INDEX_HR_CASE_UI_POLICY_ACTION_DISABLED));
builder.setSyncDirty(c.getInt(INDEX_HR_CASE_UI_POLICY_ACTION_SYNC_DIRTY));
}
private static ContentValues getContentValues(HRCaseUiPolicyAction hrCaseUiPolicyAction) {
ContentValues cv = new ContentValues(HR_CASE_UI_POLICY_ACTION_COLUMN_COUNT - 1);
cv.put(HR_CASE_UI_POLICY_ACTION_POLICY_ITEM_ID, hrCaseUiPolicyAction.getHRCaseUiPolicyItemId());
cv.put(HR_CASE_UI_POLICY_ACTION_VISIBLE, hrCaseUiPolicyAction.getVisible());
cv.put(HR_CASE_UI_POLICY_ACTION_MANDATORY, hrCaseUiPolicyAction.getMandatory());
cv.put(HR_CASE_UI_POLICY_ACTION_VARIABLE, hrCaseUiPolicyAction.getVariableName());
cv.put(HR_CASE_UI_POLICY_ACTION_DISABLED, hrCaseUiPolicyAction.getDisabled());
cv.put(UI_POLICY_ITEM_SYNC_DIRTY, hrCaseUiPolicyAction.getSyncDirty());
return cv;
}
}
\ No newline at end of file
package com.vsoft.servicenow.db.managers;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.DBConstants;
import com.vsoft.servicenow.db.models.HRCaseUiPolicyItem;
import com.vsoft.servicenow.db.models.UiPolicyItem;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
*
* @author Kunj on 18-11-2016.
*/
public class HRCaseUiPolicyItemManager implements DBConstants {
public static long save(HRCaseUiPolicyItem hrCaseUiPolicyItem, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
hrCaseUiPolicyItem.setSyncDirty(syncDirty);
long id = db.insert(TABLE_HR_CASE_UI_POLICY_ITEM, null, getContentValues(hrCaseUiPolicyItem));
hrCaseUiPolicyItem.setId(id);
return id;
} else {
return -1;
}
}
public static int delete(HRCaseUiPolicyItem hrCaseUiPolicyItem) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
if (hrCaseUiPolicyItem.getSysId() == null || hrCaseUiPolicyItem.getSysId().isEmpty()) {
return db.delete(TABLE_HR_CASE_UI_POLICY_ITEM, HR_CASE_UI_POLICY_ITEM_ID + "=" + hrCaseUiPolicyItem.getId(), null);
} else {
return update(hrCaseUiPolicyItem, SYNC_FLAG_DELETE);
}
}
return -1;
}
public static int update(HRCaseUiPolicyItem hrCaseUiPolicyItem, int syncDirty) {
return update(hrCaseUiPolicyItem, null, syncDirty);
}
public static int update(HRCaseUiPolicyItem hrCaseUiPolicyItem, List<String> column, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
hrCaseUiPolicyItem.setSyncDirty(syncDirty);
if (column == null || column.size() == 0) {
return db.update(TABLE_HR_CASE_UI_POLICY_ITEM, getContentValues(hrCaseUiPolicyItem), HR_CASE_UI_POLICY_ITEM_ID + "=" + hrCaseUiPolicyItem.getId(), null);
} else {
ContentValues contentValues = new ContentValues(column.size());
contentValues.put(HR_CASE_UI_POLICY_ITEM_SYNC_DIRTY, hrCaseUiPolicyItem.getSyncDirty());
for (int i = 0; i < column.size(); i++) {
String columnName = column.get(i);
if (HR_CASE_UI_POLICY_ITEM_SYS_ID.equals(columnName)) {
contentValues.put(HR_CASE_UI_POLICY_ITEM_SYS_ID, hrCaseUiPolicyItem.getSysId());
} else if (HR_CASE_UI_POLICY_ITEM_HR_CASE_ITEM_ID.equals(columnName)) {
contentValues.put(HR_CASE_UI_POLICY_ITEM_HR_CASE_ITEM_ID, hrCaseUiPolicyItem.getHRCaseItemId());
} else if (HR_CASE_UI_POLICY_ITEM_CONDITION.equals(columnName)) {
contentValues.put(HR_CASE_UI_POLICY_ITEM_CONDITION, hrCaseUiPolicyItem.getCondition());
}
}
return db.update(TABLE_HR_CASE_UI_POLICY_ITEM, contentValues, HR_CASE_UI_POLICY_ITEM_ID + "=" + hrCaseUiPolicyItem.getId(), null);
}
} else {
return -1;
}
}
public static boolean handleGetUiPolicyItem(List<HRCaseUiPolicyItem> serverHRCaseUiPolicyItemList, long hrCaseItemId) {
boolean hasChanged = false;
if(serverHRCaseUiPolicyItemList != null && !serverHRCaseUiPolicyItemList.isEmpty()) {
/*localHRCaseUiPolicyItemList is contain all local uiPolicyItem */
List<HRCaseUiPolicyItem> localHRCaseUiPolicyItemList = getAllUiPolicyItems(hrCaseItemId);
if(!localHRCaseUiPolicyItemList.isEmpty()) {
for (int i = 0; i < serverHRCaseUiPolicyItemList.size(); i++) {
HRCaseUiPolicyItem serverHrCaseUiPolicyItem = serverHRCaseUiPolicyItemList.get(i);
for (int j = 0; j < localHRCaseUiPolicyItemList.size(); j++) {
HRCaseUiPolicyItem localHrCaseUiPolicyItem = localHRCaseUiPolicyItemList.get(j);
if (!serverHrCaseUiPolicyItem.getSysId().equals(localHrCaseUiPolicyItem.getSysId())) {
continue;
} else {
if (!localHrCaseUiPolicyItem.getCondition().equals(serverHrCaseUiPolicyItem.getCondition())) {
hasChanged = true;
continue;
}
}
}
}
} else {
hasChanged = true;
}
/*uiPolicyItemSysIdMap contain all server response uiPolicyItem Sys Id*/
HashMap<String, Integer> uiPolicyItemSysIdMap = new HashMap<>(0);
Integer intObj = Integer.valueOf(1);
for (int i = 0; i < serverHRCaseUiPolicyItemList.size(); i++) {
String sysId = serverHRCaseUiPolicyItemList.get(i).getSysId();
uiPolicyItemSysIdMap.put(sysId, intObj);
}
if (localHRCaseUiPolicyItemList != null && !localHRCaseUiPolicyItemList.isEmpty()) {
for (int i = 0; i < localHRCaseUiPolicyItemList.size(); i++) {
HRCaseUiPolicyItem localHrCaseUiPolicyItem = localHRCaseUiPolicyItemList.get(i);
String localUiPolicySysId = localHrCaseUiPolicyItem.getSysId();
if (localUiPolicySysId != null
&& !localUiPolicySysId.isEmpty()
&& !uiPolicyItemSysIdMap.containsKey(localUiPolicySysId)) {
//Update sys_id with empty string because required to delete locally
localHrCaseUiPolicyItem.setSysId("");
delete(localHrCaseUiPolicyItem);
}
}
}
/*Check this HRCaseUiPolicyItem 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 < serverHRCaseUiPolicyItemList.size(); i++) {
HRCaseUiPolicyItem hrCaseUiPolicyItem = serverHRCaseUiPolicyItemList.get(i);
HRCaseUiPolicyItem localUiPolicyItem = getUiPolicyItemFromSysId(hrCaseUiPolicyItem.getSysId());
if (localUiPolicyItem == null) {
hrCaseUiPolicyItem.setHRCaseItemId(hrCaseItemId);
save(hrCaseUiPolicyItem, DBConstants.SYNC_FLAG_NONE);
} else {
/*Update complete local HRCaseUiPolicyItem object with response HRCaseUiPolicyItem object*/
hrCaseUiPolicyItem.setId(localUiPolicyItem.getId());
hrCaseUiPolicyItem.setHRCaseItemId(hrCaseItemId);
update(hrCaseUiPolicyItem, DBConstants.SYNC_FLAG_NONE);
}
}
} else {
/*That means there is no HRCaseUiPolicyItem in server response, then all local items should be deleted those are contain sys_id*/
/*localPolicyItemList is contain all local Catalogues */
List<HRCaseUiPolicyItem> localPolicyItemList = getAllUiPolicyItems(hrCaseItemId);
if (localPolicyItemList != null && !localPolicyItemList.isEmpty()) {
for (int i = 0; i < localPolicyItemList.size(); i++) {
HRCaseUiPolicyItem localUiPolicyItem = localPolicyItemList.get(i);
String localUiPolicyItemSysId = localUiPolicyItem.getSysId();
if (localUiPolicyItemSysId != null
&& !localUiPolicyItemSysId.isEmpty()) {
//Update sys_id with empty string because required to delete locally
localUiPolicyItem.setSysId("");
delete(localUiPolicyItem);
}
}
}
}
return hasChanged;
}
public static List<HRCaseUiPolicyItem> getAllUiPolicyItems(long hrCaseItemId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_HR_CASE_UI_POLICY_ITEM
+ " where " + HR_CASE_UI_POLICY_ITEM_HR_CASE_ITEM_ID + "=" + hrCaseItemId
+ " and " + HR_CASE_UI_POLICY_ITEM_SYNC_DIRTY
+ "!=" + DBConstants.SYNC_FLAG_DELETE, null);
ArrayList<HRCaseUiPolicyItem> uiPolicyItemList;
if (c.getCount() > 0) {
uiPolicyItemList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
HRCaseUiPolicyItem.HRCaseUiPolicyItemBuilder builder = HRCaseUiPolicyItem.HRCaseUiPolicyItemBuilder.aHRCaseUiPolicyItem();
fillAllUiPolicyItemDetails(c, builder);
uiPolicyItemList.add(builder.build());
}
} else {
uiPolicyItemList = new ArrayList<>(0);
}
c.close();
return uiPolicyItemList;
} else {
return new ArrayList<>(0);
}
}
public static HRCaseUiPolicyItem get(long uiPolicyItemId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
HRCaseUiPolicyItem hrCaseUiPolicyItem = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_HR_CASE_UI_POLICY_ITEM + " where " + HR_CASE_UI_POLICY_ITEM_ID + "=" + uiPolicyItemId, null);
if (c.moveToFirst()) {
HRCaseUiPolicyItem.HRCaseUiPolicyItemBuilder builder = HRCaseUiPolicyItem.HRCaseUiPolicyItemBuilder.aHRCaseUiPolicyItem();
fillAllUiPolicyItemDetails(c, builder);
hrCaseUiPolicyItem = builder.build();
}
c.close();
}
return hrCaseUiPolicyItem;
}
public static HRCaseUiPolicyItem getUiPolicyItemFromSysId(String sysId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
HRCaseUiPolicyItem hrCaseUiPolicyItem = null;
if(db!=null) {
Cursor c = db.rawQuery("select * from " + TABLE_HR_CASE_UI_POLICY_ITEM + " where " + HR_CASE_UI_POLICY_ITEM_SYS_ID + "='" + sysId + "'", null);
if (c.moveToFirst()) {
HRCaseUiPolicyItem.HRCaseUiPolicyItemBuilder builder = HRCaseUiPolicyItem.HRCaseUiPolicyItemBuilder.aHRCaseUiPolicyItem();
fillAllUiPolicyItemDetails(c, builder);
hrCaseUiPolicyItem = builder.build();
}
c.close();
}
return hrCaseUiPolicyItem;
}
private static void fillAllUiPolicyItemDetails(Cursor c, HRCaseUiPolicyItem.HRCaseUiPolicyItemBuilder builder) {
builder.setId(c.getLong(INDEX_HR_CASE_UI_POLICY_ITEM_ID));
builder.setHRCaseItemId(c.getLong(INDEX_HR_CASE_UI_POLICY_ITEM_HR_CASE_ITEM_ID));
builder.setCondition(c.getString(INDEX_HR_CASE_UI_POLICY_ITEM_CONDITION));
builder.setSysId(c.getString(INDEX_HR_CASE_UI_POLICY_ITEM_SYS_ID));
builder.setSyncDirty(c.getInt(INDEX_HR_CASE_UI_POLICY_ITEM_SYNC_DIRTY));
}
private static ContentValues getContentValues(HRCaseUiPolicyItem hrCaseUiPolicyItem) {
ContentValues cv = new ContentValues(HR_CASE_UI_POLICY_ITEM_COLUMN_COUNT - 1);
cv.put(HR_CASE_UI_POLICY_ITEM_HR_CASE_ITEM_ID, hrCaseUiPolicyItem.getHRCaseItemId());
cv.put(HR_CASE_UI_POLICY_ITEM_CONDITION, hrCaseUiPolicyItem.getCondition());
cv.put(HR_CASE_UI_POLICY_ITEM_SYS_ID, hrCaseUiPolicyItem.getSysId());
cv.put(HR_CASE_UI_POLICY_ITEM_SYNC_DIRTY, hrCaseUiPolicyItem.getSyncDirty());
return cv;
}
}
\ No newline at end of file
package com.vsoft.servicenow.db.managers;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.DBConstants;
import com.vsoft.servicenow.db.models.HRCaseVariableChoice;
import com.vsoft.servicenow.db.models.VariableChoice;
import java.util.ArrayList;
import java.util.List;
/**
* Created by kunj on 21/02/17.
*/
public class HRCaseVariableChoiceManager implements DBConstants {
public static long save(HRCaseVariableChoice hrCaseVariableChoice) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
long id = db.insert(TABLE_HR_CASE_VARIABLE_CHOICES, null, getContentValues(hrCaseVariableChoice));
hrCaseVariableChoice.setId(id);
return id;
} else {
return -1;
}
}
public static int delete(HRCaseVariableChoice hrCaseVariableChoice) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
return db.delete(TABLE_HR_CASE_VARIABLE_CHOICES, HR_CASE_VARIABLE_CHOICE_ID + "=" + hrCaseVariableChoice.getId(), null);
}
return -1;
}
public static void deleteAll(long variableId) {
List<HRCaseVariableChoice> localVariableChoiceList = getAllVariableChoices(variableId);
if(!localVariableChoiceList.isEmpty()) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
for (int i = 0; i < localVariableChoiceList.size(); i++) {
delete(localVariableChoiceList.get(i));
}
}
}
}
public static boolean handleGetVariableChoice(long variableId, List<HRCaseVariableChoice> serverVariableChoiceList) {
boolean hasChanged = false;
if(serverVariableChoiceList != null && !serverVariableChoiceList.isEmpty()) {
List<HRCaseVariableChoice> localVariableChoiceList = getAllVariableChoices(variableId);
if(!localVariableChoiceList.isEmpty()) {
for (int i = 0; i < serverVariableChoiceList.size(); i++) {
HRCaseVariableChoice serverVariableChoice = serverVariableChoiceList.get(i);
for (int j = 0; j < localVariableChoiceList.size(); j++) {
HRCaseVariableChoice localVariableChoice = localVariableChoiceList.get(j);
if (serverVariableChoice.getHRCaseVariableId() != localVariableChoice.getHRCaseVariableId()) {
continue;
} else {
if (!localVariableChoice.getValue().equals(serverVariableChoice.getValue())) {
hasChanged = true;
continue;
}
if (!localVariableChoice.getText().equals(serverVariableChoice.getText())) {
hasChanged = true;
continue;
}
if (localVariableChoice.getMisc() != serverVariableChoice.getMisc()) {
hasChanged = true;
continue;
}
if (localVariableChoice.getOrder() != serverVariableChoice.getOrder()) {
hasChanged = true;
continue;
}
}
}
}
} else {
hasChanged = true;
}
/*First delete all existing variable choice for particular variable then we will save*/
deleteAll(variableId);
for (int i = 0; i < serverVariableChoiceList.size(); i++) {
HRCaseVariableChoice variableChoice = serverVariableChoiceList.get(i);
variableChoice.setHRCaseVariableId(variableId);
save(variableChoice);
}
} else {
/*That means there is no HRCaseVariableChoice in server response,
*then all local items should be deleted those are contain that variable id*/
/*localVariableChoiceList is contain all local Catalogues */
deleteAll(variableId);
}
return hasChanged;
}
public static List<HRCaseVariableChoice> getAllVariableChoices(long variableId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_HR_CASE_VARIABLE_CHOICES
+ " where " + HR_CASE_VARIABLE_CHOICE_VARIABLE_ID + "=" + variableId
+ " ORDER BY " + HR_CASE_VARIABLE_CHOICE_ORDER + " ASC", null);
ArrayList<HRCaseVariableChoice> variableChoiceList;
if (c.getCount() > 0) {
variableChoiceList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
HRCaseVariableChoice.HRCaseVariableChoiceBuilder builder = HRCaseVariableChoice.HRCaseVariableChoiceBuilder.aHRCaseVariableChoice();
fillAllHRCaseVariableChoiceDetails(c, builder);
variableChoiceList.add(builder.build());
}
} else {
variableChoiceList = new ArrayList<>(0);
}
c.close();
return variableChoiceList;
} else {
return new ArrayList<>(0);
}
}
public static HRCaseVariableChoice get(long variableChoiceId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
HRCaseVariableChoice variableChoice = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_HR_CASE_VARIABLE_CHOICES + " where " + HR_CASE_VARIABLE_CHOICE_ID + "=" + variableChoiceId, null);
if (c.moveToFirst()) {
HRCaseVariableChoice.HRCaseVariableChoiceBuilder builder = HRCaseVariableChoice.HRCaseVariableChoiceBuilder.aHRCaseVariableChoice();
fillAllHRCaseVariableChoiceDetails(c, builder);
variableChoice = builder.build();
}
c.close();
}
return variableChoice;
}
private static void fillAllHRCaseVariableChoiceDetails(Cursor c, HRCaseVariableChoice.HRCaseVariableChoiceBuilder builder) {
builder.setId(c.getLong(INDEX_HR_CASE_VARIABLE_CHOICE_ID));
builder.setHRCaseVariableId((c.getLong(INDEX_HR_CASE_VARIABLE_CHOICE_VARIABLE_ID)));
builder.setText(c.getString(INDEX_HR_CASE_VARIABLE_CHOICE_TEXT));
builder.setValue(c.getString(INDEX_HR_CASE_VARIABLE_CHOICE_VALUE));
builder.setOrder(c.getInt(INDEX_HR_CASE_VARIABLE_CHOICE_ORDER));
builder.setMisc(c.getFloat(INDEX_HR_CASE_VARIABLE_CHOICE_MISC));
}
private static ContentValues getContentValues(HRCaseVariableChoice hrCaseVariableChoice) {
ContentValues cv = new ContentValues(HR_CASE_VARIABLE_CHOICE_COLUMN_COUNT - 1);
cv.put(HR_CASE_VARIABLE_CHOICE_VARIABLE_ID, hrCaseVariableChoice.getHRCaseVariableId());
cv.put(HR_CASE_VARIABLE_CHOICE_TEXT, hrCaseVariableChoice.getText());
cv.put(HR_CASE_VARIABLE_CHOICE_VALUE, hrCaseVariableChoice.getValue());
cv.put(HR_CASE_VARIABLE_CHOICE_ORDER, hrCaseVariableChoice.getOrder());
cv.put(HR_CASE_VARIABLE_CHOICE_MISC, hrCaseVariableChoice.getMisc());
return cv;
}
}
package com.vsoft.servicenow.db.managers;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.DBConstants;
import com.vsoft.servicenow.db.models.HRCaseVariable;
import com.vsoft.servicenow.enums.ViewType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
*
* @author Kunj on 11-08-2016.
*/
public class HRCaseVariableManager implements DBConstants {
public static long save(HRCaseVariable hrCaseVariable, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
hrCaseVariable.setSyncDirty(syncDirty);
long id = db.insert(TABLE_HR_CASE_VARIABLES, null, getContentValues(hrCaseVariable));
hrCaseVariable.setId(id);
return id;
} else {
return -1;
}
}
public static int delete(HRCaseVariable hrCaseVariable) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
if (hrCaseVariable.getSysId() == null || hrCaseVariable.getSysId().isEmpty()) {
return db.delete(TABLE_HR_CASE_VARIABLES, HR_CASE_VARIABLE_ID + "=" + hrCaseVariable.getId(), null);
} else {
return update(hrCaseVariable, SYNC_FLAG_DELETE);
}
}
return -1;
}
public static int update(HRCaseVariable hrCaseVariable, int syncDirty) {
return update(hrCaseVariable, null, syncDirty);
}
public static int update(HRCaseVariable hrCaseVariable, List<String> column, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
hrCaseVariable.setSyncDirty(syncDirty);
if (column == null || column.size() == 0) {
return db.update(TABLE_HR_CASE_VARIABLES, getContentValues(hrCaseVariable), HR_CASE_VARIABLE_ID + "=" + hrCaseVariable.getId(), null);
} else {
ContentValues contentValues = new ContentValues(column.size());
contentValues.put(HR_CASE_VARIABLE_SYNC_DIRTY, hrCaseVariable.getSyncDirty());
for (int i = 0; i < column.size(); i++) {
String columnName = column.get(i);
if (HR_CASE_VARIABLE_HR_CASE_ITEM_ID.equals(columnName)) {
contentValues.put(HR_CASE_VARIABLE_HR_CASE_ITEM_ID, hrCaseVariable.getHRCaseItemId());
} else if (HR_CASE_VARIABLE_SYS_ID.equals(columnName)) {
contentValues.put(HR_CASE_VARIABLE_SYS_ID, hrCaseVariable.getSysId());
} else if (HR_CASE_VARIABLE_NAME.equals(columnName)) {
contentValues.put(HR_CASE_VARIABLE_NAME, hrCaseVariable.getName());
} else if (HR_CASE_VARIABLE_QUESTION_TEXT.equals(columnName)) {
contentValues.put(HR_CASE_VARIABLE_QUESTION_TEXT, hrCaseVariable.getQuestionText());
} else if (HR_CASE_VARIABLE_TYPE.equals(columnName)) {
contentValues.put(HR_CASE_VARIABLE_TYPE, ViewType.getId(hrCaseVariable.getType()));
} else if (HR_CASE_VARIABLE_MANDATORY.equals(columnName)) {
contentValues.put(HR_CASE_VARIABLE_MANDATORY, hrCaseVariable.isMandatory() ? 1 : 0);
} else if (HR_CASE_VARIABLE_NONE_REQUIRED.equals(columnName)) {
contentValues.put(HR_CASE_VARIABLE_NONE_REQUIRED, hrCaseVariable.isNoneRequired() ? 1 : 0);
} else if (HR_CASE_VARIABLE_REFERENCE_TABLE.equals(columnName)) {
contentValues.put(HR_CASE_VARIABLE_REFERENCE_TABLE, hrCaseVariable.getReferenceTable());
} else if (HR_CASE_VARIABLE_ORDER.equals(columnName)) {
contentValues.put(HR_CASE_VARIABLE_ORDER, hrCaseVariable.getOrder());
} else if (HR_CASE_VARIABLE_REFERENCE_COLUMN_NAME.equals(columnName)) {
contentValues.put(HR_CASE_VARIABLE_REFERENCE_COLUMN_NAME, hrCaseVariable.getReferenceColumnName());
} else if (HR_CASE_VARIABLE_ACTIVE.equals(columnName)) {
contentValues.put(HR_CASE_VARIABLE_ACTIVE, hrCaseVariable.getActive());
} else if (HR_CASE_VARIABLE_DEFAULT_VALUE.equals(columnName)) {
contentValues.put(HR_CASE_VARIABLE_DEFAULT_VALUE, hrCaseVariable.getDefaultValue());
} else if (HR_CASE_VARIABLE_SYNC_DIRTY.equals(columnName)) {
contentValues.put(HR_CASE_VARIABLE_SYNC_DIRTY, hrCaseVariable.getSyncDirty());
}
}
return db.update(TABLE_HR_CASE_VARIABLES, contentValues, HR_CASE_VARIABLE_ID + "=" + hrCaseVariable.getId(), null);
}
} else {
return -1;
}
}
public static boolean handleGetVariable(long hrCaseItemId, List<HRCaseVariable> serverVariableList) {
boolean hasChanged = false;
if(serverVariableList != null && !serverVariableList.isEmpty()) {
/*localVariableList is contain all local HRCaseVariable */
List<HRCaseVariable> localVariableList = getAllHRCaseVariable(hrCaseItemId);
if(!localVariableList.isEmpty()) {
for (int i = 0; i < serverVariableList.size(); i++) {
HRCaseVariable serverCatalogueVariable = serverVariableList.get(i);
for (int j = 0; j < localVariableList.size(); j++) {
HRCaseVariable localCatalogueVariable = localVariableList.get(j);
if (!serverCatalogueVariable.getSysId().equals(localCatalogueVariable.getSysId())) {
continue;
} else {
if (!localCatalogueVariable.getName().equals(serverCatalogueVariable.getName())) {
hasChanged = true;
continue;
}
if (!localCatalogueVariable.getQuestionText().equals(serverCatalogueVariable.getQuestionText())) {
hasChanged = true;
continue;
}
if (localCatalogueVariable.getOrder() != serverCatalogueVariable.getOrder()) {
hasChanged = true;
continue;
}
if (localCatalogueVariable.getActive() != serverCatalogueVariable.getActive()) {
hasChanged = true;
continue;
}
if (localCatalogueVariable.getType().getId() != serverCatalogueVariable.getType().getId()) {
hasChanged = true;
continue;
}
if (localCatalogueVariable.getDefaultValue() != null
&& serverCatalogueVariable.getDefaultValue() != null
&& !localCatalogueVariable.getDefaultValue().equals(serverCatalogueVariable.getDefaultValue())) {
hasChanged = true;
continue;
}
if (localCatalogueVariable.getReferenceColumnName() != null
&& serverCatalogueVariable.getReferenceColumnName() != null
&& !localCatalogueVariable.getReferenceColumnName().equals(serverCatalogueVariable.getReferenceColumnName())) {
hasChanged = true;
continue;
}
if (localCatalogueVariable.getReferenceTable() != null
&& serverCatalogueVariable.getReferenceTable() != null
&& !localCatalogueVariable.getReferenceTable().equals(serverCatalogueVariable.getReferenceTable())) {
hasChanged = true;
continue;
}
}
}
}
} else {
hasChanged =true;
}
/*variableSysIdMap contain all server response HRCaseVariable Sys Id*/
HashMap<String, Integer> variableSysIdMap = new HashMap<>(0);
Integer intObj = Integer.valueOf(1);
for (int i = 0; i < serverVariableList.size(); i++) {
String sysId = serverVariableList.get(i).getSysId();
variableSysIdMap.put(sysId, intObj);
}
if (localVariableList != null && !localVariableList.isEmpty()) {
for (int i = 0; i < localVariableList.size(); i++) {
HRCaseVariable localVariable = localVariableList.get(i);
String localVariableSysId = localVariable.getSysId();
if (localVariableSysId != null
&& !localVariableSysId.isEmpty()
&& !variableSysIdMap.containsKey(localVariableSysId)) {
//Update sys_id with empty string because required to delete locally
localVariable.setSysId("");
delete(localVariable);
}
}
}
/*Check this HRCaseVariable 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 < serverVariableList.size(); i++) {
HRCaseVariable hrCaseVariable = serverVariableList.get(i);
HRCaseVariable localVariable = getVariableFromSysId(hrCaseItemId, hrCaseVariable.getSysId());
if (localVariable == null) {
hrCaseVariable.setHRCaseItemId(hrCaseItemId);
save(hrCaseVariable, DBConstants.SYNC_FLAG_NONE);
} else {
/*Update complete local HRCaseVariable object with response HRCaseVariable object*/
hrCaseVariable.setId(localVariable.getId());
hrCaseVariable.setHRCaseItemId(hrCaseItemId);
update(hrCaseVariable, DBConstants.SYNC_FLAG_NONE);
}
}
} else {
/*That means there is no HRCaseVariable in server response, then all local items should be deleted those are contain sys_id*/
/*localVariableList is contain all local HRCaseVariables */
List<HRCaseVariable> localVariableList = getAllHRCaseVariable(hrCaseItemId);
if (localVariableList != null && !localVariableList.isEmpty()) {
for (int i = 0; i < localVariableList.size(); i++) {
HRCaseVariable localVariable = localVariableList.get(i);
String localVariableSysId = localVariable.getSysId();
if (localVariableSysId != null
&& !localVariableSysId.isEmpty()) {
//Update sys_id with empty string because required to delete locally
localVariable.setSysId("");
delete(localVariable);
}
}
}
}
return hasChanged;
}
public static List<HRCaseVariable> getAllHRCaseVariable(long hrCaseItemId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_HR_CASE_VARIABLES
+ " where " + HR_CASE_VARIABLE_HR_CASE_ITEM_ID + "=" + hrCaseItemId
+ " and " + HR_CASE_VARIABLE_SYNC_DIRTY + "!=" + DBConstants.SYNC_FLAG_DELETE, null);
ArrayList<HRCaseVariable> variableList;
if (c.getCount() > 0) {
variableList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
HRCaseVariable.HRCaseVariableBuilder builder = HRCaseVariable.HRCaseVariableBuilder.aHRCaseVariable();
fillAllHRCaseVariableDetails(c, builder);
variableList.add(builder.build());
}
} else {
variableList = new ArrayList<>(0);
}
c.close();
return variableList;
} else {
return new ArrayList<>(0);
}
}
public static HRCaseVariable get(long hrCaseId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
HRCaseVariable hrCaseVariable = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_HR_CASE_VARIABLES + " where " + HR_CASE_VARIABLE_ID + "=" + hrCaseId, null);
if (c.moveToFirst()) {
HRCaseVariable.HRCaseVariableBuilder builder = HRCaseVariable.HRCaseVariableBuilder.aHRCaseVariable();
fillAllHRCaseVariableDetails(c, builder);
hrCaseVariable = builder.build();
}
c.close();
}
return hrCaseVariable;
}
public static HRCaseVariable getVariableFromSysId(long hrCaseItemId, String sysId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
HRCaseVariable hrCaseVariable = null;
if(db!=null) {
Cursor c = db.rawQuery("select * from " + TABLE_HR_CASE_VARIABLES
+ " where " + HR_CASE_VARIABLE_HR_CASE_ITEM_ID + "=" + hrCaseItemId
+ " and " + HR_CASE_VARIABLE_SYS_ID + "='" + sysId + "'", null);
if (c.moveToFirst()) {
HRCaseVariable.HRCaseVariableBuilder builder = HRCaseVariable.HRCaseVariableBuilder.aHRCaseVariable();
fillAllHRCaseVariableDetails(c, builder);
hrCaseVariable = builder.build();
}
c.close();
}
return hrCaseVariable;
}
private static void fillAllHRCaseVariableDetails(Cursor c, HRCaseVariable.HRCaseVariableBuilder builder) {
builder.setId(c.getLong(INDEX_HR_CASE_VARIABLE_ID));
builder.setHRCaseItemId(c.getLong(INDEX_HR_CASE_VARIABLE_CATALOGUE_ITEM_ID));
builder.setSysId(c.getString(INDEX_HR_CASE_VARIABLE_SYS_ID));
builder.setName(c.getString(INDEX_HR_CASE_VARIABLE_NAME));
builder.setQuestionText(c.getString(INDEX_HR_CASE_VARIABLE_QUESTION_TEXT));
builder.setType(ViewType.from(c.getInt(INDEX_HR_CASE_VARIABLE_TYPE)));
builder.setMandatory(c.getInt(INDEX_HR_CASE_VARIABLE_MANDATORY) == 1);
builder.setNoneRequired(c.getInt(INDEX_HR_CASE_VARIABLE_NONE_REQUIRED) == 1);
builder.setReferenceTable(c.getString(INDEX_HR_CASE_VARIABLE_REFERENCE));
builder.setOrder(c.getInt(INDEX_HR_CASE_VARIABLE_ORDER));
builder.setReferenceColumnName(c.getString(INDEX_HR_CASE_VARIABLE_REFERENCE_COLUMN_NAME));
builder.setActive(c.getInt(INDEX_HR_CASE_VARIABLE_ACTIVE) == 1);
builder.setDefaultValue(c.getString(INDEX_HR_CASE_VARIABLE_DEFAULT_VALUE));
builder.setSyncDirty(c.getInt(INDEX_HR_CASE_VARIABLE_SYNC_DIRTY));
}
private static ContentValues getContentValues(HRCaseVariable hrCaseVariable) {
ContentValues cv = new ContentValues(HR_CASE_VARIABLE_COLUMN_COUNT - 1);
cv.put(HR_CASE_VARIABLE_HR_CASE_ITEM_ID, hrCaseVariable.getHRCaseItemId());
cv.put(HR_CASE_VARIABLE_SYS_ID, hrCaseVariable.getSysId());
cv.put(HR_CASE_VARIABLE_NAME, hrCaseVariable.getName());
cv.put(HR_CASE_VARIABLE_QUESTION_TEXT, hrCaseVariable.getQuestionText());
cv.put(HR_CASE_VARIABLE_TYPE, hrCaseVariable.getType().getId());
cv.put(HR_CASE_VARIABLE_MANDATORY, hrCaseVariable.isMandatory() ? 1 : 0);
cv.put(HR_CASE_VARIABLE_NONE_REQUIRED, hrCaseVariable.isNoneRequired() ? 1 : 0);
cv.put(HR_CASE_VARIABLE_REFERENCE_TABLE, hrCaseVariable.getReferenceTable());
cv.put(HR_CASE_VARIABLE_ORDER, hrCaseVariable.getOrder());
cv.put(HR_CASE_VARIABLE_REFERENCE_COLUMN_NAME, hrCaseVariable.getReferenceColumnName());
cv.put(HR_CASE_VARIABLE_ACTIVE, hrCaseVariable.getActive() ? 1 : 0);
cv.put(HR_CASE_VARIABLE_DEFAULT_VALUE, hrCaseVariable.getDefaultValue());
cv.put(HR_CASE_VARIABLE_SYNC_DIRTY, hrCaseVariable.getSyncDirty());
return cv;
}
}
\ No newline at end of file
package com.vsoft.servicenow.db.models;
/**
* Created by Kunj on 11/8/16.
*/
public class HRCaseAttachment {
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 HRCaseAttachmentBuilder {
private long id = -1;
private long itemInputId;
private String path;
private String name;
private String mimeType;
private int syncDirty;
private HRCaseAttachmentBuilder() {
}
public static HRCaseAttachmentBuilder aHRCaseAttachment() {
return new HRCaseAttachmentBuilder();
}
public HRCaseAttachmentBuilder setId(long id) {
this.id = id;
return this;
}
public HRCaseAttachmentBuilder setItemInputId(long itemInputId) {
this.itemInputId = itemInputId;
return this;
}
public HRCaseAttachmentBuilder setPath(String path) {
this.path = path;
return this;
}
public HRCaseAttachmentBuilder setName(String name) {
this.name = name;
return this;
}
public HRCaseAttachmentBuilder setMimeType(String mimeType) {
this.mimeType = mimeType;
return this;
}
public HRCaseAttachmentBuilder setSyncDirty(int syncDirty) {
this.syncDirty = syncDirty;
return this;
}
public HRCaseAttachmentBuilder but() {
return aHRCaseAttachment().setId(id).setItemInputId(itemInputId).setPath(path).setName(name).setMimeType(mimeType).setSyncDirty(syncDirty);
}
public HRCaseAttachment build() {
HRCaseAttachment attachment = new HRCaseAttachment();
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 "HRCaseAttachment{" +
"id=" + id +
", itemInputId=" + itemInputId +
", path='" + path + '\'' +
", name='" + name + '\'' +
", mimeType='" + mimeType + '\'' +
", syncDirty=" + syncDirty +
'}';
}
}
\ No newline at end of file
package com.vsoft.servicenow.db.models;
/**
* Created by Kunj on 11/8/16.
*/
public class HRCaseItemInput {
private long id = -1;
private long hrCaseItemId;
private String data;
private String sysId;
private int syncDirty;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getHRCaseItemId() {
return hrCaseItemId;
}
public void setHRCaseItemId(long hrCaseItemId) {
this.hrCaseItemId = hrCaseItemId;
}
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 HRCaseItemInputBuilder {
private long id = -1;
private long hrCaseItemId;
private String data;
private String sysId;
private int syncDirty;
private HRCaseItemInputBuilder() {
}
public static HRCaseItemInputBuilder aHRCaseItemInput() {
return new HRCaseItemInputBuilder();
}
public HRCaseItemInputBuilder setId(long id) {
this.id = id;
return this;
}
public HRCaseItemInputBuilder setHRCaseItemId(long hrCaseItemId) {
this.hrCaseItemId = hrCaseItemId;
return this;
}
public HRCaseItemInputBuilder setData(String data) {
this.data = data;
return this;
}
public HRCaseItemInputBuilder setSysId(String sysId) {
this.sysId = sysId;
return this;
}
public HRCaseItemInputBuilder setSyncDirty(int syncDirty) {
this.syncDirty = syncDirty;
return this;
}
public HRCaseItemInputBuilder but() {
return aHRCaseItemInput().setId(id).setHRCaseItemId(hrCaseItemId).setData(data).setSysId(sysId).setSyncDirty(syncDirty);
}
public HRCaseItemInput build() {
HRCaseItemInput hrCaseItemInput = new HRCaseItemInput();
hrCaseItemInput.setId(id);
hrCaseItemInput.setHRCaseItemId(hrCaseItemId);
hrCaseItemInput.setData(data);
hrCaseItemInput.setSysId(sysId);
hrCaseItemInput.setSyncDirty(syncDirty);
return hrCaseItemInput;
}
}
@Override
public String toString() {
return "HRCaseItemInput{" +
"id=" + id +
", hrCaseItemId=" + hrCaseItemId +
", data='" + data + '\'' +
", sysId='" + sysId + '\'' +
", syncDirty=" + syncDirty +
'}';
}
}
package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class HRCaseUiPolicyAction {
private long id = -1;
private long hrCaseUiPolicyItemId = -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 getHRCaseUiPolicyItemId() {
return hrCaseUiPolicyItemId;
}
public void setHRCaseUiPolicyItemId(long hrCaseUiPolicyItemId) {
this.hrCaseUiPolicyItemId = hrCaseUiPolicyItemId;
}
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 HRCaseUiPolicyActionBuilder {
private long id = -1;
private long hrCaseUiPolicyItemId = -1;
private String visible;
private String mandatory;
private String variableName;
private String disabled;
private int syncDirty;
private HRCaseUiPolicyActionBuilder() {
}
public static HRCaseUiPolicyActionBuilder aHRCaseUiPolicyAction() {
return new HRCaseUiPolicyActionBuilder();
}
public HRCaseUiPolicyActionBuilder setId(long id) {
this.id = id;
return this;
}
public HRCaseUiPolicyActionBuilder setHRCaseUiPolicyItemId(long hrCaseUiPolicyItemId) {
this.hrCaseUiPolicyItemId = hrCaseUiPolicyItemId;
return this;
}
public HRCaseUiPolicyActionBuilder setVisible(String visible) {
this.visible = visible;
return this;
}
public HRCaseUiPolicyActionBuilder setMandatory(String mandatory) {
this.mandatory = mandatory;
return this;
}
public HRCaseUiPolicyActionBuilder setVariableName(String variableName) {
this.variableName = variableName;
return this;
}
public HRCaseUiPolicyActionBuilder setDisabled(String disabled) {
this.disabled = disabled;
return this;
}
public HRCaseUiPolicyActionBuilder setSyncDirty(int syncDirty) {
this.syncDirty = syncDirty;
return this;
}
public HRCaseUiPolicyActionBuilder but() {
return aHRCaseUiPolicyAction().setId(id).setHRCaseUiPolicyItemId(hrCaseUiPolicyItemId).setVisible(visible).setMandatory(mandatory).setVariableName(variableName).setDisabled(disabled).setSyncDirty(syncDirty);
}
public HRCaseUiPolicyAction build() {
HRCaseUiPolicyAction uiPolicyAction = new HRCaseUiPolicyAction();
uiPolicyAction.setId(id);
uiPolicyAction.setHRCaseUiPolicyItemId(hrCaseUiPolicyItemId);
uiPolicyAction.setVisible(visible);
uiPolicyAction.setMandatory(mandatory);
uiPolicyAction.setVariableName(variableName);
uiPolicyAction.setDisabled(disabled);
uiPolicyAction.setSyncDirty(syncDirty);
return uiPolicyAction;
}
}
@Override
public String toString() {
return "HRCaseUiPolicyAction{" +
"id=" + id +
", hrCaseUiPolicyItemId=" + hrCaseUiPolicyItemId +
", visible='" + visible + '\'' +
", mandatory='" + mandatory + '\'' +
", variableName='" + variableName + '\'' +
", disabled='" + disabled + '\'' +
", syncDirty=" + syncDirty +
'}';
}
}
package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.vsoft.servicenow.utils.PartialCondition;
import java.util.List;
/**
* Created by chaukadev on 6/10/16.
*/
public class HRCaseUiPolicyItem {
private long id = -1;
private long hrCaseItemId = -1;
private List<PartialCondition> partialConditions;
@SerializedName("condition")
@Expose
private String condition;
@SerializedName("sys_id")
@Expose
private String sysId;
@SerializedName("ui_policy_actions")
@Expose
private List<HRCaseUiPolicyAction> uiPolicyActions;
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 getHRCaseItemId() {
return hrCaseItemId;
}
public void setHRCaseItemId(long hrCaseItemId) {
this.hrCaseItemId = hrCaseItemId;
}
public List<HRCaseUiPolicyAction> getUiPolicyActions() {
return uiPolicyActions;
}
public void setUiPolicyActions(List<HRCaseUiPolicyAction> 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 sys_id
*/
public String getSysId() {
return sysId;
}
/**
*
* @param sysId
* The sys_id
*/
public void setSysId(String sysId) {
this.sysId = sysId;
}
public static final class HRCaseUiPolicyItemBuilder {
private long hrCaseItemId = -1;
private long id = -1;
private String condition;
private String sysId;
private int syncDirty;
private HRCaseUiPolicyItemBuilder() {
}
public static HRCaseUiPolicyItemBuilder aHRCaseUiPolicyItem() {
return new HRCaseUiPolicyItemBuilder();
}
public HRCaseUiPolicyItemBuilder setHRCaseItemId(long hrCaseItemId) {
this.hrCaseItemId = hrCaseItemId;
return this;
}
public HRCaseUiPolicyItemBuilder setId(long id) {
this.id = id;
return this;
}
public HRCaseUiPolicyItemBuilder setCondition(String condition) {
this.condition = condition;
return this;
}
public HRCaseUiPolicyItemBuilder setSysId(String sysId) {
this.sysId = sysId;
return this;
}
public HRCaseUiPolicyItemBuilder setSyncDirty(int syncDirty) {
this.syncDirty = syncDirty;
return this;
}
public HRCaseUiPolicyItemBuilder but() {
return aHRCaseUiPolicyItem().setHRCaseItemId(hrCaseItemId).setId(id).setCondition(condition).setSysId(sysId).setSyncDirty(syncDirty);
}
public HRCaseUiPolicyItem build() {
HRCaseUiPolicyItem uiPolicyItem = new HRCaseUiPolicyItem();
uiPolicyItem.setHRCaseItemId(hrCaseItemId);
uiPolicyItem.setId(id);
uiPolicyItem.setCondition(condition);
uiPolicyItem.setSysId(sysId);
uiPolicyItem.setSyncDirty(syncDirty);
return uiPolicyItem;
}
}
}
package com.vsoft.servicenow.db.models;
import android.content.Context;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.vsoft.servicenow.R;
import com.vsoft.servicenow.enums.ViewType;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.List;
/**
* Created by Kunj on 12/8/16.
*/
public class HRCaseVariable {
private long id = -1;
private long hr_case_item_id = -1;
@SerializedName("name")
@Expose
private String name;
@SerializedName("question_text")
@Expose
private String questionText;
@SerializedName("sys_id")
@Expose
private String sysId;
@SerializedName("mandatory")
@Expose
private boolean mandatory;
@SerializedName("none_required")
@Expose
private boolean isNoneRequired;
@SerializedName("reference_table")
@Expose
private String referenceTable;
@SerializedName("order")
@Expose
private int order;
@SerializedName("reference_display_column")
@Expose
private String referenceColumnName;
@SerializedName("Active")
@Expose
private boolean active;
@SerializedName("default_value")
@Expose
private String defaultValue;
@SerializedName("question_choice")
@Expose
private List<HRCaseVariableChoice> questionChoice = null;
private ViewType type;
private int syncDirty;
private List<HRCaseVariableChoice> mVariableChoiceList;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getHRCaseItemId() {
return hr_case_item_id;
}
public void setHRCaseItemId(long hr_case_item_id) {
this.hr_case_item_id = hr_case_item_id;
}
/**
*
* @return
* The name
*/
public String getName() {
return name;
}
/**
*
* @param name
* The name
*/
public void setName(String name) {
this.name = name;
}
/**
*
* @return
* The questionText
*/
public String getQuestionText() {
return questionText;
}
/**
*
* @param questionText
* The question_text
*/
public void setQuestionText(String questionText) {
this.questionText = questionText;
}
/**
*
* @return
* The sysId
*/
public String getSysId() {
return sysId;
}
/**
*
* @param sysId
* The sys_id
*/
public void setSysId(String sysId) {
this.sysId = sysId;
}
/**
*
* @return
* The type
*/
public ViewType getType() {
return type;
}
/**
*
* @param type
* The type
*/
public void setType(ViewType type) {
this.type = type;
}
public boolean isMandatory() {
return mandatory;
}
public void setMandatory(boolean mandatory) {
this.mandatory = mandatory;
}
public boolean isNoneRequired() {
return isNoneRequired;
}
public void setNoneRequired(boolean noneRequired) {
isNoneRequired = noneRequired;
}
public String getReferenceTable() {
return referenceTable;
}
public void setReferenceTable(String referenceTable) {
this.referenceTable = referenceTable;
}
public int getOrder() {
return order;
}
public void setOrder(int order) {
this.order = order;
}
public String getReferenceColumnName() {
return referenceColumnName;
}
public void setReferenceColumnName(String referenceColumnName) {
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;
}
public void setSyncDirty(int syncDirty) {
this.syncDirty = syncDirty;
}
public List<HRCaseVariableChoice> getVariableChoiceList() {
return questionChoice;
}
public void setVariableChoiceList(List<HRCaseVariableChoice> mVariableChoiceList) {
this.questionChoice = mVariableChoiceList;
}
public String[] getDisplayChoiceText(Context context) {
String[] choiceText;
if(defaultValue!=null) {
choiceText = new String[questionChoice.size() + 1];
choiceText[0] = defaultValue;
for (int i = 0; i < questionChoice.size(); i++) {
HRCaseVariableChoice variableChoice = questionChoice.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[questionChoice.size() + 1];
choiceText[0] = context.getString(R.string.none_string);
for (int i = 0; i < questionChoice.size(); i++) {
HRCaseVariableChoice variableChoice = questionChoice.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 {
choiceText = new String[questionChoice.size()];
for (int i = 0; i < questionChoice.size(); i++) {
HRCaseVariableChoice variableChoice = questionChoice.get(i);
if(variableChoice.getMisc() > 0) {
choiceText[i] = String.format(context.getString(R.string.variable_form_misc_info_string),
variableChoice.getText(),
variableChoice.getMisc());
} else {
choiceText[i] = variableChoice.getText();
}
}
}
return choiceText;
}
public String getDisplayChoiceText(String text) {
for (int i = 0; i < questionChoice.size(); i++) {
HRCaseVariableChoice variableChoice = questionChoice.get(i);
if(variableChoice.getText().equals(text)) {
return variableChoice.getValue();
}
}
return null;
}
public void parseJson(JSONObject jsonObject) {
String viewType = null;
try {
viewType = jsonObject.getString(Json.TYPE);
} catch (JSONException e) {
e.printStackTrace();
}
this.setType(ViewType.from(viewType));
}
public static final class HRCaseVariableBuilder {
private long id = -1;
private long hr_case_item_id = -1;
private String name;
private String questionText;
private String sysId;
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;
private HRCaseVariableBuilder() {
}
public static HRCaseVariableBuilder aHRCaseVariable() {
return new HRCaseVariableBuilder();
}
public HRCaseVariableBuilder setId(long id) {
this.id = id;
return this;
}
public HRCaseVariableBuilder setHRCaseItemId(long hrCaseItemId) {
this.hr_case_item_id = hrCaseItemId;
return this;
}
public HRCaseVariableBuilder setName(String name) {
this.name = name;
return this;
}
public HRCaseVariableBuilder setQuestionText(String questionText) {
this.questionText = questionText;
return this;
}
public HRCaseVariableBuilder setSysId(String sysId) {
this.sysId = sysId;
return this;
}
public HRCaseVariableBuilder setMandatory(boolean mandatory) {
this.mandatory = mandatory;
return this;
}
public HRCaseVariableBuilder setNoneRequired(boolean noneRequired) {
this.isNoneRequired = noneRequired;
return this;
}
public HRCaseVariableBuilder setReferenceTable(String referenceTable) {
this.referenceTable = referenceTable;
return this;
}
public HRCaseVariableBuilder setNo(String referenceTable) {
this.referenceTable = referenceTable;
return this;
}
public HRCaseVariableBuilder setOrder(int order) {
this.order = order;
return this;
}
public HRCaseVariableBuilder setReferenceColumnName(String referenceColumnName) {
this.referenceColumnName = referenceColumnName;
return this;
}
public HRCaseVariableBuilder setActive(boolean active) {
this.active = active;
return this;
}
public HRCaseVariableBuilder setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
return this;
}
public HRCaseVariableBuilder setType(ViewType type) {
this.type = type;
return this;
}
public HRCaseVariableBuilder setSyncDirty(int syncDirty) {
this.syncDirty = syncDirty;
return this;
}
public HRCaseVariableBuilder but() {
return aHRCaseVariable().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 HRCaseVariable build() {
HRCaseVariable hrCaseVariable = new HRCaseVariable();
hrCaseVariable.setId(id);
hrCaseVariable.setHRCaseItemId(hr_case_item_id);
hrCaseVariable.setName(name);
hrCaseVariable.setQuestionText(questionText);
hrCaseVariable.setSysId(sysId);
hrCaseVariable.setMandatory(mandatory);
hrCaseVariable.setNoneRequired(isNoneRequired);
hrCaseVariable.setReferenceTable(referenceTable);
hrCaseVariable.setOrder(order);
hrCaseVariable.setReferenceColumnName(referenceColumnName);
hrCaseVariable.setActive(active);
hrCaseVariable.setDefaultValue(defaultValue);
hrCaseVariable.setType(type);
hrCaseVariable.setSyncDirty(syncDirty);
return hrCaseVariable;
}
}
public static class Json {
public static final String TYPE = "type";
}
@Override
public String toString() {
return "HRCaseVariable{" +
"id=" + id +
", hr_case_item_id=" + hr_case_item_id +
", name='" + name + '\'' +
", questionText='" + questionText + '\'' +
", sysId='" + sysId + '\'' +
", mandatory=" + mandatory +
", isNoneRequired=" + isNoneRequired +
", referenceTable='" + referenceTable + '\'' +
", order=" + order +
", referenceColumnName='" + referenceColumnName + '\'' +
", active=" + active +
", defaultValue='" + defaultValue + '\'' +
", questionChoice=" + questionChoice +
", type=" + type +
", syncDirty=" + syncDirty +
", mVariableChoiceList=" + mVariableChoiceList +
'}';
}
}
package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class HRCaseVariableChoice {
private long id;
private long hr_case_variable_id;
@SerializedName("text")
@Expose
private String text;
@SerializedName("value")
@Expose
private String value;
@SerializedName("order")
@Expose
private int order;
@SerializedName("misc")
@Expose
private float misc;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getHRCaseVariableId() {
return hr_case_variable_id;
}
public void setHRCaseVariableId(long hr_case_variable_id) {
this.hr_case_variable_id = hr_case_variable_id;
}
/**
*
* @return
* The text
*/
public String getText() {
return text;
}
/**
*
* @param text
* The text
*/
public void setText(String text) {
this.text = text;
}
/**
*
* @return
* The value
*/
public String getValue() {
return value;
}
/**
*
* @param value
* The value
*/
public void setValue(String value) {
this.value = value;
}
/**
*
* @return
* The order
*/
public int getOrder() {
return order;
}
/**
*
* @param order
* The order
*/
public void setOrder(int order) {
this.order = order;
}
public float getMisc() {
return misc;
}
public void setMisc(float misc) {
this.misc = misc;
}
public static final class HRCaseVariableChoiceBuilder {
private long id;
private long hr_case_variable_id;
private String text;
private String value;
private int order;
private float misc;
private HRCaseVariableChoiceBuilder() {
}
public static HRCaseVariableChoiceBuilder aHRCaseVariableChoice() {
return new HRCaseVariableChoiceBuilder();
}
public HRCaseVariableChoiceBuilder setId(long id) {
this.id = id;
return this;
}
public HRCaseVariableChoiceBuilder setHRCaseVariableId(long hr_case_variable_id) {
this.hr_case_variable_id = hr_case_variable_id;
return this;
}
public HRCaseVariableChoiceBuilder setText(String text) {
this.text = text;
return this;
}
public HRCaseVariableChoiceBuilder setValue(String value) {
this.value = value;
return this;
}
public HRCaseVariableChoiceBuilder setOrder(int order) {
this.order = order;
return this;
}
public HRCaseVariableChoiceBuilder setMisc(float misc) {
this.misc = misc;
return this;
}
public HRCaseVariableChoiceBuilder but() {
return aHRCaseVariableChoice().setId(id).setHRCaseVariableId(hr_case_variable_id).setText(text).setValue(value).setOrder(order).setMisc(misc);
}
public HRCaseVariableChoice build() {
HRCaseVariableChoice variableChoice = new HRCaseVariableChoice();
variableChoice.setId(id);
variableChoice.setHRCaseVariableId(hr_case_variable_id);
variableChoice.setText(text);
variableChoice.setValue(value);
variableChoice.setOrder(order);
variableChoice.setMisc(misc);
return variableChoice;
}
}
}
package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.List;
/**
* Created by kunj on 16/02/17.
*/
public class HRCaseVariableResponse {
@SerializedName("variables")
@Expose
private List<HRCaseVariable> variables = null;
@SerializedName("ui_policy")
@Expose
private List<HRCaseUiPolicyItem> uiPolicy = null;
@SerializedName("variablesets")
@Expose
private List<HRCaseVariableSet> variablesets = null;
public List<HRCaseVariable> getVariables() {
return variables;
}
public void setVariables(List<HRCaseVariable> variables) {
this.variables = variables;
}
public List<HRCaseUiPolicyItem> getUiPolicy() {
return uiPolicy;
}
public void setUiPolicy(List<HRCaseUiPolicyItem> uiPolicy) {
this.uiPolicy = uiPolicy;
}
public List<HRCaseVariableSet> getVariablesets() {
return variablesets;
}
public void setVariablesets(List<HRCaseVariableSet> variablesets) {
this.variablesets = variablesets;
}
}
package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Kunj on 12/8/16.
*/
public class HRCaseVariableSet {
@SerializedName("order")
@Expose
private int order;
@SerializedName("show_on_true")
@Expose
private Object showOnTrue;
@SerializedName("variables")
@Expose
private List<HRCaseVariable> variables = new ArrayList();
/**
*
* @return
* The order
*/
public int getOrder() {
return order;
}
/**
*
* @param order
* The order
*/
public void setOrder(int order) {
this.order = order;
}
/**
*
* @return
* The showOnTrue
*/
public Object getShowOnTrue() {
return showOnTrue;
}
/**
*
* @param showOnTrue
* The show_on_true
*/
public void setShowOnTrue(Object showOnTrue) {
this.showOnTrue = showOnTrue;
}
/**
*
* @return
* The variables
*/
public List<HRCaseVariable> getVariables() {
return variables;
}
/**
*
* @param variables
* The variables
*/
public void setVariables(List<HRCaseVariable> variables) {
this.variables = variables;
}
}
...@@ -10,26 +10,28 @@ import com.vsoft.servicenow.utils.CatalogueLog; ...@@ -10,26 +10,28 @@ import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.NetworkUtil; import com.vsoft.servicenow.utils.NetworkUtil;
/** /**
*@author Kunj *@author Kunj
* 22-11-2016 11:30 * 22-11-2016 11:30
* */ * */
public class NetworkChangeReceiver extends BroadcastReceiver { public class NetworkChangeReceiver extends BroadcastReceiver {
private static boolean firstConnect = true;
@Override @Override
public void onReceive(final Context context, Intent intent) { public void onReceive(final Context context, Intent intent) {
CatalogueLog.d("NetworkChangeReceiver : Received notification about network status"); CatalogueLog.d("NetworkChangeReceiver : Received notification about network status: ");
Handler handler = new Handler(); Handler handler = new Handler();
handler.postDelayed(new Runnable() { handler.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
int status = NetworkUtil.getConnectivityStatus(context); boolean status = NetworkUtil.getConnectivityStatus(context);
if(status != NetworkUtil.TYPE_NOT_CONNECTED) { if(status && firstConnect) {
firstConnect = false;
Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT); Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT);
intent.putExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION, Constants.ACTION_SYNC); intent.putExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION, Constants.ACTION_SYNC);
LocalBroadcastManager.getInstance(context). LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
sendBroadcast(intent); } else {
firstConnect = true;
} }
} }
}, 10000); }, 10000);
......
...@@ -5,17 +5,27 @@ import android.content.Intent; ...@@ -5,17 +5,27 @@ import android.content.Intent;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.api.listeners.post.PostAttachmentApiListener; import com.vsoft.servicenow.api.listeners.post.PostAttachmentApiListener;
import com.vsoft.servicenow.api.listeners.post.PostHRCaseAttachmentApiListener;
import com.vsoft.servicenow.api.listeners.post.PostHRCaseVariableFormApiListener;
import com.vsoft.servicenow.api.listeners.post.PostIncidentApiListener; import com.vsoft.servicenow.api.listeners.post.PostIncidentApiListener;
import com.vsoft.servicenow.api.listeners.post.PostVariableFormApiListener; import com.vsoft.servicenow.api.listeners.post.PostVariableFormApiListener;
import com.vsoft.servicenow.api.managers.CatalogueVariableApiManager; import com.vsoft.servicenow.api.managers.CatalogueVariableApiManager;
import com.vsoft.servicenow.api.managers.HRCaseItemApiManager;
import com.vsoft.servicenow.api.managers.HRCaseVariableApiManager;
import com.vsoft.servicenow.api.managers.IncidentApiManager; import com.vsoft.servicenow.api.managers.IncidentApiManager;
import com.vsoft.servicenow.db.managers.AttachmentManager; import com.vsoft.servicenow.db.managers.AttachmentManager;
import com.vsoft.servicenow.db.managers.CatalogueItemInputManager; import com.vsoft.servicenow.db.managers.CatalogueItemInputManager;
import com.vsoft.servicenow.db.managers.CatalogueItemManager; import com.vsoft.servicenow.db.managers.CatalogueItemManager;
import com.vsoft.servicenow.db.managers.HRCaseAttachmentManager;
import com.vsoft.servicenow.db.managers.HRCaseItemInputManager;
import com.vsoft.servicenow.db.managers.HRCaseItemManager;
import com.vsoft.servicenow.db.managers.ReportIncidentValueManager; import com.vsoft.servicenow.db.managers.ReportIncidentValueManager;
import com.vsoft.servicenow.db.models.Attachment; import com.vsoft.servicenow.db.models.Attachment;
import com.vsoft.servicenow.db.models.CatalogueItem; import com.vsoft.servicenow.db.models.CatalogueItem;
import com.vsoft.servicenow.db.models.CatalogueItemInput; import com.vsoft.servicenow.db.models.CatalogueItemInput;
import com.vsoft.servicenow.db.models.HRCaseAttachment;
import com.vsoft.servicenow.db.models.HRCaseItem;
import com.vsoft.servicenow.db.models.HRCaseItemInput;
import com.vsoft.servicenow.db.models.Incident; import com.vsoft.servicenow.db.models.Incident;
import com.vsoft.servicenow.enums.SyncStatus; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.servicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.CatalogueLog;
...@@ -86,6 +96,24 @@ public class SyncService extends IntentService { ...@@ -86,6 +96,24 @@ public class SyncService extends IntentService {
if(Constants.DEBUG) CatalogueLog.d("startSync: result of syncing attachment "+i+": "+result); if(Constants.DEBUG) CatalogueLog.d("startSync: result of syncing attachment "+i+": "+result);
} }
/*Then we will work on dirty variable form*/
List<HRCaseItemInput> hrCaseItemInputList = HRCaseItemInputManager.getDirtyItemInput();
if(Constants.DEBUG) CatalogueLog.d("startSync: HRCase form to sync: "+hrCaseItemInputList.size());
for (int i = 0; i < hrCaseItemInputList.size(); i++) {
HRCaseItemInput hrCaseItemInput = hrCaseItemInputList.get(i);
result = syncHRCaseVariableForm(hrCaseItemInput);
if(Constants.DEBUG) CatalogueLog.d("startSync: result of syncing hrCaseItemInput "+i+": "+result);
}
/*Then we will work on dirty HRCase attachment*/
List<HRCaseAttachment> hrCaseAttachmentList = HRCaseAttachmentManager.getDirtyHRCaseAttachment();
if(Constants.DEBUG) CatalogueLog.d("startSync: HRCaseAttachment to sync: "+hrCaseAttachmentList.size());
for (int i = 0; i < hrCaseAttachmentList.size(); i++) {
HRCaseAttachment hrCaseAttachment = hrCaseAttachmentList.get(i);
result = syncHRCaseAttachment(hrCaseAttachment);
if(Constants.DEBUG) CatalogueLog.d("startSync: result of syncing hrCaseAttachment "+i+": "+result);
}
/*Then we will work on dirty incident form*/ /*Then we will work on dirty incident form*/
List<Incident> incidentInputList = ReportIncidentValueManager.getDirtyIncident(); List<Incident> incidentInputList = ReportIncidentValueManager.getDirtyIncident();
if(Constants.DEBUG) CatalogueLog.d("startSync: incident form to sync: "+incidentInputList.size()); if(Constants.DEBUG) CatalogueLog.d("startSync: incident form to sync: "+incidentInputList.size());
...@@ -203,4 +231,76 @@ public class SyncService extends IntentService { ...@@ -203,4 +231,76 @@ public class SyncService extends IntentService {
} }
return syncStatus; return syncStatus;
} }
/**
* Sync HRCase VariableForm
**/
private SyncStatus syncHRCaseVariableForm(final HRCaseItemInput hrCaseItemInput) {
CatalogueLog.d( "syncHRCaseVariableForm");
if(hrCaseItemInput.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE || hrCaseItemInput.getSysId() == null || hrCaseItemInput.getSysId().isEmpty()) {
final HRCaseItem hrCaseItem = HRCaseItemManager.get(hrCaseItemInput.getHRCaseItemId());
HRCaseVariableApiManager.submitHRCaseVariableForm(SyncService.this, hrCaseItem.getSysId(),
hrCaseItemInput.getData(),
new PostHRCaseVariableFormApiListener() {
@Override
public void onDoneApiCall(String variableFromSysId) {
syncStatus = SyncStatus.SUCCESS;
CatalogueLog.e("syncHRCaseVariableForm: saveHRCaseVariableForm: result is SUCCESS");
hrCaseItemInput.setSysId(variableFromSysId);
HRCaseItemInputManager.handleSaveServerResponse(hrCaseItemInput, Collections.singletonList(CATALOGUE_ITEM_INPUT_SYS_ID), SYNC_FLAG_NONE);
}
@Override
public void onFailApiCall() {
CatalogueLog.e("syncHRCaseVariableForm: saveHRCaseVariableForm: result is FAIL");
syncStatus = SyncStatus.FAIL;
}
});
}
return syncStatus;
}
/**
* Sync HRCase Attachment
**/
private SyncStatus syncHRCaseAttachment(final HRCaseAttachment hrCaseAttachment) {
CatalogueLog.d( "syncHRCaseAttachment");
if(hrCaseAttachment.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE) {
if (hrCaseAttachment.getMimeType() != null) {
InputStream in = null;
try {
in = new FileInputStream(new File(hrCaseAttachment.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();
}
HRCaseItemInput hrCaseItemInput = HRCaseItemInputManager.get(hrCaseAttachment.getItemInputId());
RequestBody requestBody = RequestBody.create(MediaType.parse(hrCaseAttachment.getMimeType()), buf);
HRCaseVariableApiManager.postHRCaseAttachment(SyncService.this, hrCaseAttachment.getMimeType(),
hrCaseItemInput.getSysId(),
hrCaseAttachment.getName(), requestBody, new PostHRCaseAttachmentApiListener() {
@Override
public void onDoneApiCall() {
syncStatus = SyncStatus.SUCCESS;
HRCaseAttachmentManager.update(hrCaseAttachment, SYNC_FLAG_NONE);
CatalogueLog.e("syncVariableForm: postHRCaseAttachment: result is SUCCESS");
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
CatalogueLog.e("syncVariableForm: postHRCaseAttachment: result is FAIL");
}
});
}
}
return syncStatus;
}
} }
...@@ -125,8 +125,6 @@ public class CatalogueVariableScreen extends HandleNotificationActivity { ...@@ -125,8 +125,6 @@ public class CatalogueVariableScreen extends HandleNotificationActivity {
private TextView mAttachmentTextView; private TextView mAttachmentTextView;
private CatalogueItem mCatalogueItem; private CatalogueItem mCatalogueItem;
private Uri mAttachmentUri;
private File mAttachmentFile;
private Attachment mAttachment; private Attachment mAttachment;
...@@ -900,18 +898,12 @@ public class CatalogueVariableScreen extends HandleNotificationActivity { ...@@ -900,18 +898,12 @@ public class CatalogueVariableScreen extends HandleNotificationActivity {
case FILE_SELECT_CODE: case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
// Get the Uri of the selected file // Get the Uri of the selected file
mAttachmentUri = data.getData(); Uri attachmentUri = data.getData();
mAttachmentFile = new File(getPath(this, mAttachmentUri)); File attachmentFile = new File(getPath(this, attachmentUri));
if(mAttachmentTextView!=null) { if(mAttachmentTextView!=null) {
mAttachmentTextView.setText(mAttachmentFile.getName()); mAttachmentTextView.setText(attachmentFile.getName());
} }
// Get the Uri of the selected file
Uri attachmentUri = data.getData();
String attachmentPath = getPath(this, attachmentUri);
File attachmentFile = new File(attachmentPath);
Attachment.AttachmentBuilder builder = Attachment.AttachmentBuilder.anAttachment(); Attachment.AttachmentBuilder builder = Attachment.AttachmentBuilder.anAttachment();
builder.setPath(getPath(this, attachmentUri)); builder.setPath(getPath(this, attachmentUri));
builder.setName(attachmentFile.getName()); builder.setName(attachmentFile.getName());
......
...@@ -190,11 +190,11 @@ public class HRCaseItemScreen extends HandleNotificationActivity { ...@@ -190,11 +190,11 @@ public class HRCaseItemScreen extends HandleNotificationActivity {
public void onItemClick(AdapterView<?> parent, View view, public void onItemClick(AdapterView<?> parent, View view,
int position, long id) { int position, long id) {
HRCaseItem hrCaseItem = hrCaseItemList.get(position); HRCaseItem hrCaseItem = hrCaseItemList.get(position);
Intent intent = new Intent(HRCaseItemScreen.this, CatalogueVariableScreen.class); Intent intent = new Intent(HRCaseItemScreen.this, HRCaseVariableScreen.class);
intent.putExtra(Constants.DATA_KEY_SYS_ID, hrCaseItem.getSysId()); intent.putExtra(Constants.DATA_KEY_SYS_ID, hrCaseItem.getSysId());
intent.putExtra(Constants.DATA_KEY_CATALOGUE_ITEM_DESCRIPTION, hrCaseItem.getDescription()); intent.putExtra(Constants.DATA_KEY_HR_CASE_ITEM_DESCRIPTION, hrCaseItem.getDescription());
intent.putExtra(Constants.DATA_KEY_CATALOGUE_ITEM_SHORT_DESCRIPTION, hrCaseItem.getShortDescription()); intent.putExtra(Constants.DATA_KEY_HR_CASE_ITEM_SHORT_DESCRIPTION, hrCaseItem.getShortDescription());
intent.putExtra(Constants.DATA_KEY_CATALOGUE_TITLE, hrCaseItem.getName()); intent.putExtra(Constants.DATA_KEY_HR_CASE_TITLE, hrCaseItem.getName());
startActivity(intent); startActivity(intent);
} }
}); });
......
package com.vsoft.servicenow.ui;
import android.Manifest;
import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.app.TimePickerDialog;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.TypedValue;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
import com.google.android.gms.analytics.Tracker;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.R;
import com.vsoft.servicenow.api.listeners.get.GetHRCaseVariableApiListener;
import com.vsoft.servicenow.api.managers.HRCaseVariableApiManager;
import com.vsoft.servicenow.db.DBConstants;
import com.vsoft.servicenow.db.managers.HRCaseAttachmentManager;
import com.vsoft.servicenow.db.managers.HRCaseItemInputManager;
import com.vsoft.servicenow.db.managers.HRCaseItemManager;
import com.vsoft.servicenow.db.managers.HRCaseUiPolicyActionManager;
import com.vsoft.servicenow.db.managers.HRCaseUiPolicyItemManager;
import com.vsoft.servicenow.db.managers.HRCaseVariableChoiceManager;
import com.vsoft.servicenow.db.managers.HRCaseVariableManager;
import com.vsoft.servicenow.db.models.HRCaseAttachment;
import com.vsoft.servicenow.db.models.HRCaseItem;
import com.vsoft.servicenow.db.models.HRCaseItemInput;
import com.vsoft.servicenow.db.models.HRCaseUiPolicyAction;
import com.vsoft.servicenow.db.models.HRCaseUiPolicyItem;
import com.vsoft.servicenow.db.models.HRCaseVariable;
import com.vsoft.servicenow.db.models.HRCaseVariableChoice;
import com.vsoft.servicenow.db.models.HRCaseVariableResponse;
import com.vsoft.servicenow.db.models.HRCaseVariableSet;
import com.vsoft.servicenow.db.models.Reference;
import com.vsoft.servicenow.db.models.VariableViewContainer;
import com.vsoft.servicenow.dialog.SelectReferenceDialog;
import com.vsoft.servicenow.enums.Operator;
import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.servicenow.enums.ViewType;
import com.vsoft.servicenow.listeners.ReferenceListener;
import com.vsoft.servicenow.ui.supportviews.DateAndTimePickerFragment;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.DialogUtils;
import com.vsoft.servicenow.utils.PartialCondition;
import com.vsoft.servicenow.utils.PrefManager;
import com.vsoft.servicenow.utils.Util;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Stack;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
* Created by Kunj on 11/8/16.
*/
public class HRCaseVariableScreen extends HandleNotificationActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.variable_screen_container_layout) LinearLayout mContainerLayout;
@BindView(R.id.variable_screen_bottom_layout) RelativeLayout mBottomLayout;
@BindView(R.id.toolbar_refresh_icon) ImageView mRefreshIcon;
@BindView(R.id.toolbar_progress_icon) ProgressBar mProgressBar;
private List<HRCaseVariable> mHRCaseVariableList = new ArrayList<>();
private CatalogueApplication mApplication;
private String mHRCaseItemDescription, mHRCaseItemShortDescription, mHRCaseItemTitle;
private HashMap<String, VariableViewContainer> mVariableViewMap;
private static final int WRITE_EXTERNAL_STORAGE = 1;
private static final int FILE_SELECT_CODE = 0;
private TextView mAttachmentTextView;
private HRCaseItem mHRCaseItem;
private File mAttachmentFile;
private HRCaseAttachment mHRCaseAttachment;
/*isProgressRequire variable is use for showing progress bar in middle of screen during fetch data from server*/
private boolean isProgressRequire;
private boolean mFormHasChanged;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.catalogue_variable_screen);
ButterKnife.bind(this);
mApplication = (CatalogueApplication) getApplication();
Bundle extras = getIntent().getExtras();
String hrCaseItemSysId = null;
if (extras != null) {
hrCaseItemSysId = extras.getString(Constants.DATA_KEY_SYS_ID);
mHRCaseItemDescription = extras.getString(Constants.DATA_KEY_HR_CASE_ITEM_DESCRIPTION);
mHRCaseItemShortDescription = extras.getString(Constants.DATA_KEY_HR_CASE_ITEM_SHORT_DESCRIPTION);
mHRCaseItemTitle = extras.getString(Constants.DATA_KEY_HR_CASE_TITLE);
//The key argument here must match that used in the other activity
}
mHRCaseItem = HRCaseItemManager.getHRCaseItemFromSysId(hrCaseItemSysId);
if (mHRCaseItem == null) {
CatalogueLog.e("HRCaseVariableScreen: onCreate: mHRCaseItem is null");
finish();
return;
}
setSupportActionBar(mToolbar);
ActionBar actionBar = getSupportActionBar();
if(actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setElevation(0);
actionBar.setTitle(R.string.variable_form_header_string);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
}
Tracker tracker = mApplication.getDefaultTracker();
// Send initial screen view hit.
Util.sendScreenName(tracker, actionBar.getTitle().toString());
mHRCaseVariableList = HRCaseVariableManager.getAllHRCaseVariable(mHRCaseItem.getId());
if(!mHRCaseVariableList.isEmpty()) {
/*Create dynamic layout and set Ui Policy*/
setVariableChoices();
createView();
runUIPolicyActions(null);
}
if (mApplication.isNetConnected()) {
isProgressRequire = mHRCaseVariableList.isEmpty();
new FetchCatalogueVariable().execute();
}
}
@OnClick(R.id.toolbar_refresh_icon)
void onRefreshClicked() {
if(mApplication.isNetConnected()) {
/*Reset variable*/
mFormHasChanged = false;
new FetchCatalogueVariable().execute();
} else {
DialogUtils.showNoConnectionDialogWithCloseActivity(HRCaseVariableScreen.this);
}
}
private void setVariableChoices() {
if(!mHRCaseVariableList.isEmpty()) {
for (int i = 0; i < mHRCaseVariableList.size(); i++) {
HRCaseVariable catalogueVariable = mHRCaseVariableList.get(i);
if (catalogueVariable.getType() == ViewType.MULTIPLE_CHOICE
|| catalogueVariable.getType() == ViewType.SELECT_BOX) {
List<HRCaseVariableChoice> variableChoiceList = HRCaseVariableChoiceManager.getAllVariableChoices(catalogueVariable.getId());
/*Sort List of CatalogueOrder*/
Collections.sort(variableChoiceList, new Comparator<HRCaseVariableChoice>() {
@Override
public int compare(HRCaseVariableChoice lhs, HRCaseVariableChoice rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
catalogueVariable.setVariableChoiceList(variableChoiceList);
}
}
}
}
class FetchCatalogueVariable extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog;
private SyncStatus syncStatus = SyncStatus.FAIL;
@Override
protected void onPreExecute() {
super.onPreExecute();
if(isProgressRequire) {
progressDialog = new ProgressDialog(HRCaseVariableScreen.this);
progressDialog.setMessage(getString(R.string.loading_string));
progressDialog.show();
progressDialog.setCancelable(false);
} else {
mRefreshIcon.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE);
}
}
@Override
protected SyncStatus doInBackground(final String... params) {
HRCaseVariableApiManager.getHRCaseVariable(HRCaseVariableScreen.this, mHRCaseItem.getSysId(), new
GetHRCaseVariableApiListener() {
@Override
public void onDoneApiCall(HRCaseVariableResponse hrCaseVariableResponse) {
syncStatus = SyncStatus.SUCCESS;
/*For variableset */
/*completeHRCaseVariableList is temporary list for getting all catalogue variable in a single list for local DB.*/
List<HRCaseVariable> completeHRCaseVariableList = new ArrayList<>();
for (int i = 0; i <hrCaseVariableResponse.getVariablesets().size(); i++) {
HRCaseVariableSet hrCaseVariableSet = hrCaseVariableResponse.getVariablesets().get(i);
completeHRCaseVariableList.addAll(hrCaseVariableSet.getVariables());
}
/*For variable list*/
completeHRCaseVariableList.addAll(hrCaseVariableResponse.getVariables());
boolean variableHasChanged = HRCaseVariableManager.handleGetVariable(mHRCaseItem.getId(), completeHRCaseVariableList);
mFormHasChanged = variableHasChanged ? variableHasChanged : mFormHasChanged;
/*Save HRCaseUiPolicyItem in local DB*/
boolean uiPolicyItemHasChanged = HRCaseUiPolicyItemManager.handleGetUiPolicyItem
(hrCaseVariableResponse.getUiPolicy(),
mHRCaseItem.getId());
mFormHasChanged = uiPolicyItemHasChanged ? uiPolicyItemHasChanged : mFormHasChanged;
for (int i = 0; i < completeHRCaseVariableList.size(); i++) {
HRCaseVariable catalogueVariable = completeHRCaseVariableList.get(i);
if( catalogueVariable.getVariableChoiceList()!=null && !catalogueVariable.getVariableChoiceList().isEmpty()) {
HRCaseVariableChoiceManager.handleGetVariableChoice(catalogueVariable.getId(), catalogueVariable
.getVariableChoiceList());
}
}
/*Get all recently saved all items because we need local id of each item for save HRCaseUiPolicyAction with respect to UiPolicyItem*/
List<HRCaseUiPolicyItem> localUiPolicyItemList = HRCaseUiPolicyItemManager.getAllUiPolicyItems(mHRCaseItem.getId());
if(hrCaseVariableResponse !=null &&hrCaseVariableResponse.getUiPolicy() !=null && hrCaseVariableResponse.getUiPolicy().size()>0){
for (int i = 0; i < hrCaseVariableResponse.getUiPolicy().size(); i++) {
HRCaseUiPolicyItem uiPolicyItem = hrCaseVariableResponse.getUiPolicy().get(i);
for(int j = 0; j < localUiPolicyItemList.size(); j++) {
HRCaseUiPolicyItem localUiPolicyItem = localUiPolicyItemList.get(j);
if(localUiPolicyItem.getSysId().equals(uiPolicyItem.getSysId())) {
localUiPolicyItem.setUiPolicyActions(uiPolicyItem.getUiPolicyActions());
}
}
}
for (int i = 0; i < localUiPolicyItemList.size(); i++) {
HRCaseUiPolicyItem uiPolicyItem = localUiPolicyItemList.get(i);
/*Save HRCaseUiPolicyAction in local DB*/
boolean uiPolicyActionHasChanged = HRCaseUiPolicyActionManager.handleGetUiPolicyAction(uiPolicyItem.getUiPolicyActions(), uiPolicyItem.getId());
mFormHasChanged = uiPolicyActionHasChanged ? uiPolicyActionHasChanged : mFormHasChanged;
setPartialCondition(uiPolicyItem);
}
}}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
}
@Override
protected void onPostExecute(SyncStatus syncStatus) {
super.onPostExecute(syncStatus);
if(progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
} else {
mRefreshIcon.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);
}
if(syncStatus == SyncStatus.SUCCESS) {
mHRCaseVariableList = HRCaseVariableManager.getAllHRCaseVariable(mHRCaseItem.getId());
setVariableChoices();
/*This if condition is use for, when variable form will load very first time
* Other wise according to our logic we have to show dialog because we will get mFormHasChanged is "true"
* Reason behind is getting "true" is -
* Very first time, locally we don't have data and compare server response with locally so mFormHasChanged is always true.*/
if(isProgressRequire) {
isProgressRequire = mHRCaseVariableList.isEmpty();
/*Create dynamic layout and set Ui Policy*/
/*-----------------------------*/
setVariableChoices();
createView();
runUIPolicyActions(null);
} else if(mFormHasChanged && !isProgressRequire) {
AlertDialog.Builder builder = new AlertDialog.Builder(HRCaseVariableScreen.this);
builder.setMessage("Do you want to update your form with server changes?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mContainerLayout.removeAllViews();
/*Create dynamic layout and set Ui Policy*/
/*-----------------------------*/
createView();
runUIPolicyActions(null);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
} else {
showFetchVariableErrorDialog(R.string.failed_to_fetch_catalogue_form_string);
}
}
}
private void setPartialCondition(HRCaseUiPolicyItem uiPolicyItem) {
String condition = uiPolicyItem.getCondition();
if (condition != null) {
String[] splitStrings = uiPolicyItem.getCondition().split("\\^");
List<PartialCondition> partialConditionList = new ArrayList<>(splitStrings.length - 1);
for (int j = 0; j < splitStrings.length - 1; j++) {
PartialCondition partialCondition = new PartialCondition();
String value = splitStrings[j].replace("IO:", "");
String sysId = value.substring(0, 32);
String operatorAndValue = value.substring(32);
partialCondition.setViewSysId(sysId);
if (!operatorAndValue.contains("=")) {
partialCondition.setOperator(Operator.from(operatorAndValue));
} else {
String[] strings = operatorAndValue.split("=");
partialCondition.setOperator(Operator.EQUAL);
/*Below condition is use for condition=empty,
*we need to handle empty condition in else statement*/
if (strings.length >= 2) {
partialCondition.setOperatorValue(strings[1]);
} else {
partialCondition.setOperatorValue("");
}
}
partialConditionList.add(partialCondition);
}
uiPolicyItem.setPartialConditions(partialConditionList);
}
}
private void createView() {
/*For variable list */
getCustomLayout();
if(!mHRCaseVariableList.isEmpty()) {
mBottomLayout.setVisibility(View.VISIBLE);
} else {
mBottomLayout.setVisibility(View.GONE);
}
}
private void getCustomLayout() {
if(mVariableViewMap != null && !mVariableViewMap.isEmpty()) {
mVariableViewMap.clear();
}
mVariableViewMap = new HashMap<>(mHRCaseVariableList.size());
Stack<LinearLayout> stack = null;
/*Child view of scroll view*/
LinearLayout.LayoutParams childControlViewLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams childLabelViewLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
/*This check will prevent to add description and short description text view multiple time when we refresh the screen */
if(mContainerLayout.getChildCount() <= 0) {
if (mHRCaseItemTitle != null && !mHRCaseItemTitle.isEmpty()) {
TextView headerView = new TextView(HRCaseVariableScreen.this);
headerView.setPadding(0, 0, 0, (int) getResources().getDimension(R.dimen.normal_margin));
headerView.setTypeface(null, Typeface.BOLD);
headerView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.normal_text_size));
headerView.setTextColor(ContextCompat.getColor(HRCaseVariableScreen.this, android.R.color.black));
headerView.setText(mHRCaseItemTitle);
mContainerLayout.addView(headerView, childControlViewLayoutParams);
}
/*Added item Description in form*/
if (mHRCaseItemShortDescription != null && !mHRCaseItemShortDescription.isEmpty()) {
TextView shortDescriptionView = new TextView(HRCaseVariableScreen.this);
shortDescriptionView.setPadding(0, 0, 0, (int) getResources().getDimension(R.dimen.normal_margin));
shortDescriptionView.setTypeface(null, Typeface.BOLD);
shortDescriptionView.setTextColor(ContextCompat.getColor(HRCaseVariableScreen.this, android.R.color.black));
shortDescriptionView.setMovementMethod(LinkMovementMethod.getInstance());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
shortDescriptionView.setText(Html.fromHtml(mHRCaseItemShortDescription, Html.FROM_HTML_MODE_LEGACY));
} else {
shortDescriptionView.setText(Html.fromHtml(mHRCaseItemShortDescription));
}
mContainerLayout.addView(shortDescriptionView, childControlViewLayoutParams);
}
if (mHRCaseItemDescription != null && !mHRCaseItemDescription.isEmpty()) {
/*Replace /r/n with blank string*/
StringBuilder builder = new StringBuilder();
builder.append(mHRCaseItemDescription.replaceAll("\r\n", "<br />"));
builder.append("\n");
builder.append(getString(R.string.Variable_form_short_description_anchor_line_break_css));
WebView descriptionView = new WebView(HRCaseVariableScreen.this);
descriptionView.loadData(builder.toString(), "text/html; charset=UTF-8", "UTF-8");
mContainerLayout.addView(descriptionView, childControlViewLayoutParams);
}
}
if(!mHRCaseVariableList.isEmpty()) {
VariableViewContainer container;
for (int i = 0; i < mHRCaseVariableList.size(); i++) {
HRCaseVariable catalogueVariable = mHRCaseVariableList.get(i);
/*If API return active false for a variable, there is no need show that variable*/
if(catalogueVariable.isActive()) {
ViewType viewType = catalogueVariable.getType();
if (catalogueVariable.getName() == null) {
TextView nameNullView = new TextView(HRCaseVariableScreen.this);
nameNullView.setText(R.string.name_null_view_string);
nameNullView.setBackgroundColor(ContextCompat.getColor(HRCaseVariableScreen.this, R.color.name_null_view_color));
childLabelViewLayoutParams.topMargin = (int) getResources().getDimension(R.dimen.small_margin);
nameNullView.setPadding((int) getResources().getDimension(R.dimen.small_margin),
(int) getResources().getDimension(R.dimen.small_margin),
(int) getResources().getDimension(R.dimen.small_margin),
(int) getResources().getDimension(R.dimen.small_margin));
mContainerLayout.addView(nameNullView, childLabelViewLayoutParams);
} else if(viewType == ViewType.CONTAINER_END) {
/*In Container End, we need to add view for rendering*/
LinearLayout popLinearLayout;
if(stack!=null && !stack.isEmpty()) {
popLinearLayout = stack.pop();
if (popLinearLayout != null) {
if(stack!=null && !stack.isEmpty()) {
LinearLayout peekLinearLayout = stack.peek();
if (peekLinearLayout != null)
peekLinearLayout.addView(popLinearLayout);
} else {
mContainerLayout.addView(popLinearLayout);
}
}
}
} else if (viewType != ViewType.MACRO && viewType != ViewType.CONTAINER_SPLIT) {
container = Util.getVariableViewContainer(HRCaseVariableScreen.this,
catalogueVariable, childLabelViewLayoutParams);
mVariableViewMap.put(catalogueVariable.getSysId(), container);
View controlView = container.getInputView();
if (controlView != null) {
/*For set default text in full_name and user_id textView.*/
if(catalogueVariable.getName().equals(getString(R.string.catalogue_user_full_name))) {
String userFullName = PrefManager.getSharedPref(HRCaseVariableScreen.this, PrefManager.PREFERENCE_USER_FULL_NAME);
((EditText)controlView).setText(userFullName);
((EditText)controlView).setEnabled(false);
} else if(catalogueVariable.getName().equals(getString(R.string.catalogue_user_id))) {
String userId = PrefManager.getSharedPref(HRCaseVariableScreen.this, PrefManager.PREFERENCE_USER_ID);
((EditText)controlView).setText(userId);
((EditText)controlView).setEnabled(false);
} else if(catalogueVariable.getName().equals(getString(R.string.catalogue_user_email_id))) {
String emailId = PrefManager.getSharedPref(HRCaseVariableScreen.this, PrefManager.PREFERENCE_USER_EMAIL_ID);
((EditText)controlView).setText(emailId);
((EditText)controlView).setEnabled(false);
}
if (viewType == ViewType.DATE) {
controlView.setOnClickListener(dateListener);
} else if (viewType == ViewType.DATE_AND_TIME) {
controlView.setOnClickListener(dateTimeListener);
} else if (viewType == ViewType.REFERENCE) {
controlView.setOnTouchListener(referenceListener);
} else if (viewType == ViewType.UI_PAGE) {
((LinearLayout)controlView).getChildAt(0).setOnClickListener(attachmentListener);
mAttachmentTextView = (TextView)((LinearLayout)controlView).getChildAt(1);
} else if (viewType == ViewType.CHECK_BOX) {
((CheckBox)controlView).setOnCheckedChangeListener(checkedChangeListener);
// if this checkbox is a trigger of UI action, set a listener for change, and send a broadcast event
} else if (viewType == ViewType.MULTIPLE_CHOICE) {
((RadioGroup)controlView).setOnCheckedChangeListener(radioGroupCheckedChangeListener);
// if this checkbox is a trigger of UI action, set a listener for change, and send a broadcast event
} else if (viewType == ViewType.SELECT_BOX) {
((Spinner)controlView).setOnItemSelectedListener(spinnerItemSelectedListener);
// if this checkbox is a trigger of UI action, set a listener for change, and send a broadcast event
}
LinearLayout containerLinearLayout = null;
if(stack!=null && !stack.isEmpty()) {
containerLinearLayout = stack.peek();
}
if(containerLinearLayout!=null) {
/*That mean, we need to add only in container view*/
if (container.getContainerView() != null)
containerLinearLayout.addView(container.getContainerView());
else
containerLinearLayout.addView(container.getInputView());
} else if (viewType != ViewType.BREAK) { /*Set bottom margin for custom view*/
if(container.getContainerView()!=null)
mContainerLayout.addView(container.getContainerView(), childControlViewLayoutParams);
else
mContainerLayout.addView(container.getInputView(), childControlViewLayoutParams);
} else {
if (container.getContainerView() != null)
mContainerLayout.addView(container.getContainerView());
else
mContainerLayout.addView(container.getInputView());
}
} else if(viewType == ViewType.CONTAINER_START) {
/*For Container start, we need to create a layout, it contain all views until we reach Container End*/
LinearLayout containerLinearLayout = (LinearLayout) container.getContainerView();
if(stack == null)
stack = new Stack();
stack.push(containerLinearLayout);
} else {
TextView viewNotImplemented = new TextView(HRCaseVariableScreen.this);
viewNotImplemented.setText(String.format(getString(R.string.view_not_implemented_string), viewType.getDisplayString()));
viewNotImplemented.setBackgroundColor(ContextCompat.getColor(HRCaseVariableScreen.this, R.color.view_not_implemented_color));
childLabelViewLayoutParams.topMargin = (int) getResources().getDimension(R.dimen.small_margin);
mContainerLayout.addView(viewNotImplemented, childLabelViewLayoutParams);
}
}
}
}
/*This condition is use for where u do not have Container End at the end of loop, then we need to render*/
if(stack != null) {
while (!stack.isEmpty()) {
LinearLayout popLinearLayout = stack.pop();
if(!stack.isEmpty()) {
LinearLayout peekLinearLayout = stack.peek();
peekLinearLayout.addView(popLinearLayout);
} else {
if(popLinearLayout != null)
mContainerLayout.addView(popLinearLayout);
}
}
}
}
}
@OnClick(R.id.variable_screen_submit_text_view)
void submitOnClicked(View v) {
Util.hideSoftKeyboard(HRCaseVariableScreen.this, v);
saveFormData();
}
@OnClick(R.id.variable_screen_back_text_view)
void backOnClicked() {
showNavigationBackDialog();
}
private void saveFormData() {
JSONArray jsonArray;
JSONObject jsonObject = null;
boolean hasErrors = false;
boolean skipInvisibleItem = false;
for (int i = 0; i < mHRCaseVariableList.size(); i++) {
HRCaseVariable catalogueVariable = mHRCaseVariableList.get(i);
VariableViewContainer container = mVariableViewMap.get(catalogueVariable.getSysId());
if(catalogueVariable.getType() == ViewType.CONTAINER_START
&& container != null
&& container.getContainerView() != null
&& container.getContainerView().getVisibility() == View.GONE) {
skipInvisibleItem = true;
}
if(skipInvisibleItem && catalogueVariable.getType() != ViewType.CONTAINER_END) {
continue;
}
if(catalogueVariable.getType() == ViewType.CONTAINER_END) {
skipInvisibleItem = false;
}
if(jsonObject == null) {
jsonObject = new JSONObject();
}
ViewType viewType = catalogueVariable.getType();
if (container != null && viewType != ViewType.LABEL && viewType != ViewType.BREAK) {
View view = container.getInputView();
if (view != null) {
String value = Util.getVariableViewValue(view, viewType);
View errorView = container.getErrorView();
String jsonColumnValue = value;
/*Convert date and time long value to string for server communication*/
if (viewType == ViewType.DATE) {
jsonColumnValue = Util.getDateFromLong(Util.getDateFromString(value));
} else if (viewType == ViewType.DATE_AND_TIME) {
jsonColumnValue = Util.getDateTime(Util.getDateTimeFromString(value));
}
if (catalogueVariable.isMandatory()) {
if (viewType != ViewType.SELECT_BOX && viewType != ViewType.UI_PAGE) {
if (TextUtils.isEmpty(jsonColumnValue)) {
hasErrors = true;
// show error view
if (errorView != null)
errorView.setVisibility(View.VISIBLE);
} else {
// hide error view
if (errorView != null)
errorView.setVisibility(View.GONE);
}
} else {
if (jsonColumnValue.equals(getString(R.string.none_string))) {
hasErrors = true;
// show error view
if (errorView != null)
errorView.setVisibility(View.VISIBLE);
} else {
// hide error view
if (errorView != null)
errorView.setVisibility(View.GONE);
}
}
}
try {
jsonObject.put(catalogueVariable.getName(), jsonColumnValue);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
if(hasErrors)
return;
jsonArray = new JSONArray();
jsonArray.put(jsonObject);
/*Save data in local DB*/
HRCaseItemInput.HRCaseItemInputBuilder builder = HRCaseItemInput.HRCaseItemInputBuilder.aHRCaseItemInput();
builder.setData(jsonArray.toString());
builder.setHRCaseItemId(mHRCaseItem.getId());
long id = HRCaseItemInputManager.save(builder.build(), DBConstants.SYNC_FLAG_CREATE);
if(id != -1) {
if(mHRCaseAttachment != null) {
mHRCaseAttachment.setItemInputId(id);
HRCaseAttachmentManager.save(mHRCaseAttachment, DBConstants.SYNC_FLAG_CREATE);
}
showSubmissionDialog();
} else {
CatalogueLog.e("HRCaseVariableScreen: saveFormData: input data is not saved.");
showSubmitErrorDialog(R.string.failed_to_submit_form_string);
}
/*Send broadcast to start SyncService*/
Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT);
intent.putExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION, Constants.ACTION_SYNC);
LocalBroadcastManager.getInstance(HRCaseVariableScreen.this).sendBroadcast(intent);
}
View.OnClickListener dateListener = new View.OnClickListener() {
@Override
public void onClick(final View v) {
DatePickerDialog.OnDateSetListener listener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
((TextView)v).setText(String.format(getString(R.string.date_string), (dayOfMonth < 10 ? "0" + dayOfMonth : dayOfMonth), getMonth(monthOfYear), year));
}
};
FragmentManager fm = getSupportFragmentManager();
DateAndTimePickerFragment dateAndTimePickerFragment = DateAndTimePickerFragment.newInstance(getString(R.string.select_date_string));
dateAndTimePickerFragment.setDateListener(listener);
dateAndTimePickerFragment.show(fm, "Dialog Fragment");
dateAndTimePickerFragment.setCancelable(false);
}
};
View.OnClickListener dateTimeListener = new View.OnClickListener() {
@Override
public void onClick(final View v) {
DatePickerDialog.OnDateSetListener dateListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
((Button)v).setText(String.format(getString(R.string.date_string), (dayOfMonth < 10 ? "0" + dayOfMonth : dayOfMonth), getMonth(monthOfYear), year));
}
};
TimePickerDialog.OnTimeSetListener timeListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
Button button = (Button)v;
String existText = button.getText().toString();
StringBuilder builder = new StringBuilder();
builder.append(existText);
builder.append(" ");
builder.append(String.format(getString(R.string.date_and_time_string), (hourOfDay < 10 ? "0" + hourOfDay : hourOfDay), (minute < 10 ? "0" + minute : minute)));
button.setText(builder.toString());
}
};
FragmentManager fm = getSupportFragmentManager();
DateAndTimePickerFragment dateAndTimePickerFragment = DateAndTimePickerFragment.newInstance(getString(R.string.select_date_and_time_string));
dateAndTimePickerFragment.setDateListener(dateListener);
dateAndTimePickerFragment.setmTimeListener(timeListener);
dateAndTimePickerFragment.show(fm, "Dialog Fragment");
dateAndTimePickerFragment.setCancelable(false);
}
};
View.OnTouchListener referenceListener = new View.OnTouchListener() {
@Override
public boolean onTouch(final View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP) {
final EditText editText = (EditText)v;
ReferenceListener listener = new ReferenceListener() {
@Override
public void positiveButtonClick(Reference reference) {
editText.setText(reference.getName());
v.setTag(reference);
}
@Override
public void negativeButtonClick() {
}
};
FragmentManager fm = getSupportFragmentManager();
HRCaseVariable catalogueVariable = getVariableForView(v);
String tableName = catalogueVariable.getReferenceTable();
String columnName = catalogueVariable.getReferenceColumnName();
String title = catalogueVariable.getQuestionText();
SelectReferenceDialog spinnerDialog = SelectReferenceDialog.newInstance(tableName, columnName, title);
spinnerDialog.setListener(listener);
spinnerDialog.show(fm, "");
return true;
}
return false;
}
};
View.OnClickListener attachmentListener = new View.OnClickListener() {
@Override
public void onClick(final View v) {
int permissionCheck = ContextCompat.checkSelfPermission(HRCaseVariableScreen.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
HRCaseVariableScreen.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_EXTERNAL_STORAGE);
} else {
showFileChooser();
}
}
};
CompoundButton.OnCheckedChangeListener checkedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
HRCaseVariable catalogueVariable = getVariableForView(compoundButton);
runUIPolicyActions(catalogueVariable.getSysId());
}
};
RadioGroup.OnCheckedChangeListener radioGroupCheckedChangeListener = new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
HRCaseVariable catalogueVariable = getVariableForView(radioGroup);
runUIPolicyActions(catalogueVariable.getSysId());
}
};
AdapterView.OnItemSelectedListener spinnerItemSelectedListener = new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
HRCaseVariable catalogueVariable = getVariableForView(adapterView);
runUIPolicyActions(catalogueVariable.getSysId());
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
};
public String getMimeType(Uri uri) {
ContentResolver cR = getContentResolver();
return cR.getType(uri);
}
private void showSubmissionDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.variable_form_order_successful_submission_string)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
AlertDialog alert = builder.create();
alert.show();
}
private void showFetchVariableErrorDialog(int message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
finish();
}
});
AlertDialog alert = builder.create();
alert.show();
}
private void showSubmitErrorDialog(int message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
private String getMonth(int month) {
return Constants.month[month];
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == android.R.id.home) {
showNavigationBackDialog();
}
return super.onOptionsItemSelected(menuItem);
}
private void showFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(
Intent.createChooser(intent, "Select a File to Upload"),
FILE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
// Potentially direct the user to the Market with a Dialog
Toast.makeText(this, "Please install a File Manager.",
Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
Uri attachmentUri = data.getData();
File attachmentFile = new File(getPath(this, attachmentUri));
if(mAttachmentTextView!=null) {
mAttachmentTextView.setText(attachmentFile.getName());
}
HRCaseAttachment.HRCaseAttachmentBuilder builder = HRCaseAttachment.HRCaseAttachmentBuilder.aHRCaseAttachment();
builder.setPath(getPath(this, attachmentUri));
builder.setName(attachmentFile.getName());
builder.setMimeType(getMimeType(attachmentUri));
builder.setSyncDirty(DBConstants.SYNC_FLAG_CREATE);
mHRCaseAttachment = builder.build();
if(mAttachmentTextView!=null) {
mAttachmentTextView.setText(mHRCaseAttachment.getName());
}
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
/**
* Get a file path from a Uri. This will get the the path for Storage Access
* Framework Documents, as well as the _data field for the MediaStore and
* other file-based ContentProviders.
*
* @param context The context.
* @param uri The Uri to query.
* @author paulburke
*/
public static String getPath(final Context context, final Uri uri) {
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
// DocumentProvider
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/" + split[1];
}
// TODO handle non-primary volumes
}
// DownloadsProvider
else if (isDownloadsDocument(uri)) {
final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
return getDataColumn(context, contentUri, null, null);
}
// MediaProvider
else if (isMediaDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
Uri contentUri = null;
if ("image".equals(type)) {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
final String selection = "_id=?";
final String[] selectionArgs = new String[] {
split[1]
};
return getDataColumn(context, contentUri, selection, selectionArgs);
}
}
// MediaStore (and general)
else if ("content".equalsIgnoreCase(uri.getScheme())) {
// Return the remote address
if (isGooglePhotosUri(uri))
return uri.getLastPathSegment();
return getDataColumn(context, uri, null, null);
}
// File
else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
return null;
}
/**
* Get the value of the data column for this Uri. This is useful for
* MediaStore Uris, and other file-based ContentProviders.
*
* @param context The context.
* @param uri The Uri to query.
* @param selection (Optional) Filter used in the query.
* @param selectionArgs (Optional) Selection arguments used in the query.
* @return The value of the _data column, which is typically a file path.
*/
public static String getDataColumn(Context context, Uri uri, String selection,
String[] selectionArgs) {
Cursor cursor = null;
final String column = "_data";
final String[] projection = {
column
};
try {
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
null);
if (cursor != null && cursor.moveToFirst()) {
final int index = cursor.getColumnIndexOrThrow(column);
return cursor.getString(index);
}
} finally {
if (cursor != null)
cursor.close();
}
return null;
}
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is ExternalStorageProvider.
*/
public static boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is DownloadsProvider.
*/
public static boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is MediaProvider.
*/
public static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is Google Photos.
*/
public static boolean isGooglePhotosUri(Uri uri) {
return "com.google.android.apps.photos.content".equals(uri.getAuthority());
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case WRITE_EXTERNAL_STORAGE:
// If request is cancelled, the result arrays are empty.
for (int i = 0; i < permissions.length; i++) {
if (permissions[0].equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
showFileChooser();
} else if (!ActivityCompat.shouldShowRequestPermissionRationale(HRCaseVariableScreen.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// user denied flagging NEVER ASK AGAIN.
showCustomSettingPermissionDialog();
}
/*Break for loop*/
break;
}
}
break;
default:
break;
}
}
private void showCustomSettingPermissionDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(String.format(getString(R.string.custom_setting_storage_permission_dialog_msg_string), getString(R.string.app_name)))
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
@Override
public void onBackPressed() {
showNavigationBackDialog();
}
private void showNavigationBackDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.variable_form_back_navigation_string)
.setCancelable(false)
.setPositiveButton(R.string.yes_string, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
private void runUIPolicyActions(String sysId) {
List<HRCaseUiPolicyItem> uiPolicyItemList = HRCaseUiPolicyItemManager.getAllUiPolicyItems(mHRCaseItem.getId());
if(uiPolicyItemList == null)
return;
for(int i=0; i<uiPolicyItemList.size(); i++) {
HRCaseUiPolicyItem item = uiPolicyItemList.get(i);
setPartialCondition(item);
/*UIPolicy condition is null then skip iterator*/
if(item.getPartialConditions()==null)
continue;
boolean needToExecuteUIPolicy = false;
if(sysId != null) {
for (int j = 0; j < item.getPartialConditions().size(); j++) {
if (item.getPartialConditions().get(j).getViewSysId().equals(sysId)) {
needToExecuteUIPolicy = true;
break;
}
}
if (!needToExecuteUIPolicy)
continue;
}
boolean conditionsSatisfied = true;
for(int j=0; j<item.getPartialConditions().size(); j++) {
PartialCondition partialCondition = item.getPartialConditions().get(j);
HRCaseVariable variable = getVariableForSysId(partialCondition.getViewSysId());
VariableViewContainer variableViewContainer = mVariableViewMap.get(variable.getSysId());
if(variableViewContainer == null || variableViewContainer.getInputView() == null) {
continue;
}
String value = Util.getVariableViewValueForUIPolicy(variableViewContainer.getInputView(), variable);
switch(partialCondition.getOperator()) {
case EQUAL:
conditionsSatisfied = conditionsSatisfied && value.equals(partialCondition.getOperatorValue());
break;
case IS_NOT_EMPTY:
conditionsSatisfied = conditionsSatisfied && !TextUtils.isEmpty(value);
break;
}
}
/*Get HRCaseUiPolicyAction from local DB*/
List<HRCaseUiPolicyAction> uiPolicyActionList = HRCaseUiPolicyActionManager.getAllUiPolicyActions(item.getId());
if(conditionsSatisfied) {
for(int j=0; j<uiPolicyActionList.size(); j++) {
HRCaseUiPolicyAction action = uiPolicyActionList.get(j);
HRCaseVariable variable = getVariableForName(action.getVariableName());
VariableViewContainer container = mVariableViewMap.get(variable.getSysId());
if(container!=null) {
if (action.getMandatory().equals(Boolean.toString(true))) {
variable.setMandatory(true);
/*For first time, by default there is no error view
*but after call UIPolicy api we need to create an error view and set it to container.*/
if(container.getErrorView()==null) {
TextView errorView = Util.getErrorView(HRCaseVariableScreen.this);
container.setErrorView(errorView);
container.getContainerView().addView(errorView);
}
setMandatoryView(container, variable.getQuestionText(), true);
} else if (action.getMandatory().equals(Boolean.toString(false))) {
variable.setMandatory(false);
setMandatoryView(container, variable.getQuestionText(), false);
}
if (action.getVisible().equals(Boolean.toString(true))) {
container.getContainerView().setVisibility(View.VISIBLE);
runUIPolicyActions(variable.getSysId());
} else if (action.getVisible().equals(Boolean.toString(false))) {
container.getContainerView().setVisibility(View.GONE);
}
if (action.getDisabled().equals(Boolean.toString(true))) {
container.getContainerView().setEnabled(true);
} else if (action.getDisabled().equals(Boolean.toString(false))) {
container.getContainerView().setEnabled(false);
}
}
}
} else {
for(int j=0; j<uiPolicyActionList.size(); j++) {
HRCaseUiPolicyAction action = uiPolicyActionList.get(j);
HRCaseVariable variable = getVariableForName(action.getVariableName());
VariableViewContainer container = mVariableViewMap.get(variable.getSysId());
if(container!=null) {
if (action.getMandatory().equals(Boolean.toString(true))) {
variable.setMandatory(false);
setMandatoryView(container, variable.getQuestionText(), false);
} else if (action.getMandatory().equals(Boolean.toString(false))) {
/*For first time, by default there is no error view
*but after call UIPolicy api we need to create an error view and set it to container.*/
if(container.getErrorView()==null) {
TextView errorView = Util.getErrorView(HRCaseVariableScreen.this);
container.setErrorView(errorView);
container.getContainerView().addView(errorView);
}
variable.setMandatory(true);
setMandatoryView(container, variable.getQuestionText(), true);
}
if (action.getVisible().equals(Boolean.toString(true))) {
container.getContainerView().setVisibility(View.GONE);
} else if (action.getVisible().equals(Boolean.toString(false))) {
container.getContainerView().setVisibility(View.VISIBLE);
runUIPolicyActions(variable.getSysId());
}
if (action.getDisabled().equals(Boolean.toString(true))) {
container.getContainerView().setEnabled(false);
} else if (action.getDisabled().equals(Boolean.toString(false))) {
container.getContainerView().setEnabled(true);
}
}
}
}
}
}
private HRCaseVariable getVariableForSysId(String sysId) {
for(int i = 0; i< mHRCaseVariableList.size(); i++) {
if(mHRCaseVariableList.get(i).getSysId().equals(sysId))
return mHRCaseVariableList.get(i);
}
return null;
}
private HRCaseVariable getVariableForName(String name) {
for(int i = 0; i< mHRCaseVariableList.size(); i++) {
if(mHRCaseVariableList.get(i).getName().equals(name))
return mHRCaseVariableList.get(i);
}
return null;
}
private HRCaseVariable getVariableForView(View view) {
for(int i = 0; i< mHRCaseVariableList.size(); i++) {
String sysId = mHRCaseVariableList.get(i).getSysId();
VariableViewContainer container = mVariableViewMap.get(sysId);
if(container == null) {
continue;
}
if(container.getInputView() != null) {
if (container.getInputView() == view)
return mHRCaseVariableList.get(i);
} else if(container.getContainerView() != null) {
if (container.getContainerView() == view)
return mHRCaseVariableList.get(i);
}
}
return null;
}
private void setMandatoryView(VariableViewContainer container, String displayString, boolean isMandatory) {
TextView label = (TextView) container.getLabelView();
if(label!=null) {
if (!isMandatory) {
label.setText(displayString);
} else {
/*Create label with mandatory value*/
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(displayString);
stringBuilder.append(getString(R.string.variable_form_view_mandatory_sign_string));
label = (TextView) container.getLabelView();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
label.setText(Html.fromHtml(stringBuilder.toString(), Html.FROM_HTML_MODE_LEGACY));
} else {
label.setText(Html.fromHtml(stringBuilder.toString()));
}
}
}
}
}
...@@ -34,6 +34,8 @@ public class Constants { ...@@ -34,6 +34,8 @@ public class Constants {
public static final String DATA_KEY_LOGIN_REQUEST_CODE = "login_request_code"; public static final String DATA_KEY_LOGIN_REQUEST_CODE = "login_request_code";
public static final String DATA_KEY_CATEGORY_SYS_ID = "category_sys_id"; public static final String DATA_KEY_CATEGORY_SYS_ID = "category_sys_id";
public static final String DATA_KEY_HR_CASE_TITLE = "hr_case_title"; public static final String DATA_KEY_HR_CASE_TITLE = "hr_case_title";
public static final String DATA_KEY_HR_CASE_ITEM_DESCRIPTION = "catalogue_item_des";
public static final String DATA_KEY_HR_CASE_ITEM_SHORT_DESCRIPTION = "catalogue_item_short_des";
/** /**
* Broadcast custom intent * Broadcast custom intent
...@@ -178,6 +180,14 @@ public class Constants { ...@@ -178,6 +180,14 @@ public class Constants {
/*HRCase Category Items API */ /*HRCase Category Items API */
public static final String URL_GET_HR_CASE_ITEM = DOMAIN + AppConfig.URL_GET_HR_CASE_ITEM; public static final String URL_GET_HR_CASE_ITEM = DOMAIN + AppConfig.URL_GET_HR_CASE_ITEM;
/*HRCase Variable form API */
public static final String URL_GET_HR_CASE_VARIABLE = AppConfig.URL_GET_HR_CASE_VARIABLE;
public static final String URL_GET_HR_CASE_UI_POLICY = AppConfig.URL_GET_HR_CASE_UI_POLICY;
public static final String URL_GET_HR_CASE_VARIABLE_CHOICE = DOMAIN + AppConfig.URL_GET_HR_CASE_VARIABLE_CHOICE;
public static final String URL_POST_HR_CASE_ITEM = AppConfig.URL_POST_HR_CASE_CATALOGUE_ITEM;
public static final String URL_GET_HR_CASE_REFERENCE = API_PATH;
public static final String URL_POST_HR_CASE_ATTACHMENT = DOMAIN + "api/now/v1/attachment/file";
/** /**
* Chat Server URL * Chat Server URL
* */ * */
......
...@@ -10,35 +10,12 @@ import android.net.NetworkInfo; ...@@ -10,35 +10,12 @@ import android.net.NetworkInfo;
public class NetworkUtil { public class NetworkUtil {
public static int TYPE_WIFI = 1; public static boolean getConnectivityStatus(Context context) {
public static int TYPE_MOBILE = 2; ConnectivityManager cm =
public static int TYPE_NOT_CONNECTED = 0; (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
public static int getConnectivityStatus(Context context) {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if (null != activeNetwork) { return activeNetwork != null &&
if(activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) activeNetwork.isConnectedOrConnecting();
return TYPE_WIFI;
if(activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE)
return TYPE_MOBILE;
}
return TYPE_NOT_CONNECTED;
}
public static String getConnectivityStatusString(Context context) {
int conn = NetworkUtil.getConnectivityStatus(context);
String status = null;
if (conn == NetworkUtil.TYPE_WIFI) {
status = "Wifi enabled";
} else if (conn == NetworkUtil.TYPE_MOBILE) {
status = "Mobile data enabled";
} else if (conn == NetworkUtil.TYPE_NOT_CONNECTED) {
status = "Not connected to Internet";
}
return status;
} }
} }
\ No newline at end of file
...@@ -34,6 +34,8 @@ import com.vsoft.servicenow.MenuProvider; ...@@ -34,6 +34,8 @@ import com.vsoft.servicenow.MenuProvider;
import com.vsoft.servicenow.R; import com.vsoft.servicenow.R;
import com.vsoft.servicenow.db.DBConstants; import com.vsoft.servicenow.db.DBConstants;
import com.vsoft.servicenow.db.models.CatalogueVariable; import com.vsoft.servicenow.db.models.CatalogueVariable;
import com.vsoft.servicenow.db.models.HRCaseVariable;
import com.vsoft.servicenow.db.models.HRCaseVariableChoice;
import com.vsoft.servicenow.db.models.Reference; import com.vsoft.servicenow.db.models.Reference;
import com.vsoft.servicenow.db.models.VariableChoice; import com.vsoft.servicenow.db.models.VariableChoice;
import com.vsoft.servicenow.db.models.VariableViewContainer; import com.vsoft.servicenow.db.models.VariableViewContainer;
...@@ -515,6 +517,403 @@ public class Util { ...@@ -515,6 +517,403 @@ public class Util {
} }
} }
private static TextView getLabelView(Context context, HRCaseVariable hrCaseVariable, LinearLayout.LayoutParams childLabelViewLayoutParams) {
ViewType viewType = hrCaseVariable.getType();
if (hrCaseVariable.getQuestionText() != null && viewType != ViewType.MACRO && viewType != ViewType.CONTAINER_START
&& viewType != ViewType.CONTAINER_END && viewType != ViewType.CONTAINER_SPLIT
&& viewType != ViewType.LABEL && viewType != CHECK_BOX && viewType != BREAK) {
/*For MACRO, CONTAINER_START, CONTAINER_END and CONTAINER_SPLIT, there is no need to render any view*/
/*Create label for every type*/
if (!hrCaseVariable.isMandatory()) {
TextView label = new TextView(context);
label.setText(hrCaseVariable.getQuestionText());
childLabelViewLayoutParams.topMargin = (int) context.getResources().getDimension(R.dimen.small_margin);
return label;
} else {
/*Create label with mandatory value*/
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(hrCaseVariable.getQuestionText());
stringBuilder.append(context.getString(R.string.variable_form_view_mandatory_sign_string));
TextView label = new TextView(context);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
label.setText(Html.fromHtml(stringBuilder.toString(), Html.FROM_HTML_MODE_LEGACY));
} else {
label.setText(Html.fromHtml(stringBuilder.toString()));
}
return label;
}
} else {
return null;
}
}
public static VariableViewContainer getVariableViewContainer(Context context, HRCaseVariable hrCaseVariable, LinearLayout.LayoutParams childLabelViewLayoutParams) {
VariableViewContainer container = new VariableViewContainer();
/*Label View*/
TextView label = getLabelView(context, hrCaseVariable, childLabelViewLayoutParams);
container.setLabelView(label);
/*Error View*/
TextView errorView = null;
if (hrCaseVariable.isMandatory()) {
errorView = getErrorView(context);
}
container.setErrorView(errorView);
ViewType viewType = hrCaseVariable.getType();
LinearLayout linearLayout;
switch (viewType) {
case YES_NO:
Spinner spinner = new Spinner(context);
ArrayAdapter<String> spinnerArrayAdapter =
new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, new String[] {
context.getResources().getString(R.string.none_string),
context.getResources().getString(R.string.yes_string),
context.getResources().getString(R.string.no_string)});
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spinnerArrayAdapter);
container.setInputView(spinner);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(spinner);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case MULTI_LINE_TEXT:
EditText multiLineEditText = new EditText(context);
multiLineEditText.setSingleLine(false);
multiLineEditText.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
multiLineEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
multiLineEditText.setLines(3);
multiLineEditText.setVerticalScrollBarEnabled(true);
multiLineEditText.setGravity(Gravity.START);
container.setInputView(multiLineEditText);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(multiLineEditText);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case HTML:
EditText htmlEditText = new EditText(context);
htmlEditText.setSingleLine(false);
htmlEditText.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
htmlEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
htmlEditText.setLines(3);
htmlEditText.setVerticalScrollBarEnabled(true);
htmlEditText.setGravity(Gravity.START);
container.setInputView(htmlEditText);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(htmlEditText);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case NUMERIC_SCALE:
LinearLayout numericScaleLayout = new LinearLayout(context);
numericScaleLayout.setOrientation(LinearLayout.VERTICAL);
RadioButton[] radioButtons = new RadioButton[5];
RadioGroup rg = new RadioGroup(context); //create the RadioGroup
rg.setOrientation(RadioGroup.HORIZONTAL);//or RadioGroup.VERTICAL
for(int i = 0; i < 5; i++){
radioButtons[i] = new RadioButton(context);
radioButtons[i].setText(String.format(context.getString(R.string.variable_form_radio_text_string), (i+1)));
rg.addView(radioButtons[i]);
}
container.setInputView(rg);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(numericScaleLayout);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case CHECK_BOX:
CheckBox checkBox = new CheckBox(context);
checkBox.setText(hrCaseVariable.getQuestionText());
container.setInputView(checkBox);
break;
case SINGLE_LINE_TEXT:
EditText singleLineEditText = new EditText(context);
singleLineEditText.setSingleLine(true);
singleLineEditText.setLines(1);
singleLineEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
container.setInputView(singleLineEditText);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(singleLineEditText);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case WIDE_SINGLE_LINE_TEXT:
EditText wideSingleLineEditText = new EditText(context);
wideSingleLineEditText.setSingleLine(true);
wideSingleLineEditText.setLines(1);
wideSingleLineEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
container.setInputView(wideSingleLineEditText);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(wideSingleLineEditText);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case DATE:
Button dateTextButton = new Button(context);
dateTextButton.setText(getDefaultDate());
dateTextButton.setGravity(Gravity.CENTER_VERTICAL);
container.setInputView(dateTextButton);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(dateTextButton);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case DATE_AND_TIME:
Button dateTimeButton = new Button(context);
dateTimeButton.setText(getDefaultDateTime()/* + " " + getDefaultTime()*/);
dateTimeButton.setGravity(Gravity.CENTER_VERTICAL);
container.setInputView(dateTimeButton);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(dateTimeButton);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case REFERENCE:
EditText referenceEditText = new EditText(context);
referenceEditText.setLines(1);
referenceEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
referenceEditText.setSingleLine(true);
referenceEditText.setFocusable(false);
referenceEditText.setFocusableInTouchMode(false);
referenceEditText.setClickable(false);
referenceEditText.setCompoundDrawablesWithIntrinsicBounds(0, 0, android.R.drawable.ic_menu_search, 0);
container.setInputView(referenceEditText);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(referenceEditText);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case LABEL:
LinearLayout labelLayout = new LinearLayout(context);
labelLayout.setOrientation(LinearLayout.VERTICAL);
TextView labelTextView = new TextView(context);
labelTextView.setText(hrCaseVariable.getQuestionText());
labelTextView.setTypeface(null, Typeface.BOLD);
labelLayout.addView(labelTextView);
container.setInputView(labelTextView);
View view = new View(context);
view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1));
view.setBackgroundColor(ContextCompat.getColor(context, android.R.color.black));
labelLayout.addView(view);
labelLayout.setPadding(0, 0, 0, (int)context.getResources().getDimension(R.dimen.small_margin));
container.setContainerView(labelLayout);
break;
case MASKED:
EditText maskedEditText = new EditText(context);
maskedEditText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
maskedEditText.setLines(1);
maskedEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
maskedEditText.setSingleLine(true);
maskedEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
container.setInputView(maskedEditText);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(maskedEditText);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case MULTIPLE_CHOICE:
LinearLayout multiChoiceLinearLayout = new LinearLayout(context);
multiChoiceLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
RadioButton[] multiChoiceRadioButtons = new RadioButton[hrCaseVariable.getVariableChoiceList().size()];
RadioGroup radioGroup = new RadioGroup(context); //create the RadioGroup
radioGroup.setOrientation(RadioGroup.VERTICAL);//or RadioGroup.HORIZONTAL
for(int i = 0; i < hrCaseVariable.getVariableChoiceList().size(); i++) {
multiChoiceRadioButtons[i] = new RadioButton(context);
HRCaseVariableChoice variableChoice = hrCaseVariable.getVariableChoiceList().get(i);
if(variableChoice.getMisc() > 0) {
multiChoiceRadioButtons[i].setText(
String.format(context.getString(R.string.variable_form_misc_info_string),
variableChoice.getText(),
variableChoice.getMisc()));
} else {
multiChoiceRadioButtons[i].setText(variableChoice.getText());
}
multiChoiceRadioButtons[i].setTag(hrCaseVariable.getVariableChoiceList().get(i).getValue());
radioGroup.addView(multiChoiceRadioButtons[i]);
}
multiChoiceLinearLayout.addView(radioGroup);
container.setInputView(radioGroup);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(multiChoiceLinearLayout);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case SELECT_BOX:
Spinner selectBoxSpinner = new Spinner(context);
selectBoxSpinner.setPadding(0, (int) context.getResources().getDimension(R.dimen.normal_margin),
0, (int) context.getResources().getDimension(R.dimen.normal_margin));
ArrayAdapter<String> selectBoxSpinnerArrayAdapter =
new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, hrCaseVariable.getDisplayChoiceText(context));
selectBoxSpinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
selectBoxSpinner.setAdapter(selectBoxSpinnerArrayAdapter);
container.setInputView(selectBoxSpinner);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(selectBoxSpinner);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case BREAK:
View breakView = new View(context);
breakView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1));
breakView.setBackgroundColor(ContextCompat.getColor(context, android.R.color.black));
container.setInputView(breakView);
break;
case UI_PAGE:
LinearLayout uiPageLayout = new LinearLayout(context);
uiPageLayout.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
Button attachmentButton = new Button(context);
attachmentButton.setText(R.string.variable_form_ui_page_button_label_string);
attachmentButton.setLines(1);
attachmentButton.setSingleLine(true);
attachmentButton.setEllipsize(TextUtils.TruncateAt.END);
uiPageLayout.addView(attachmentButton, layoutParams);
TextView attachmentTextView = new TextView(context);
attachmentTextView.setGravity(Gravity.CENTER);
attachmentTextView.setSingleLine(true);
attachmentTextView.setLines(1);
attachmentTextView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
attachmentTextView.setText(R.string.variable_form_ui_page_no_selected_attachment_string);
uiPageLayout.addView(attachmentTextView, layoutParams);
container.setInputView(uiPageLayout);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(uiPageLayout);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
case CONTAINER_START:
LinearLayout containerLinearLayout = new LinearLayout(context);
containerLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if(label!=null) {
linearLayout.addView(label, childLabelViewLayoutParams);
}
linearLayout.addView(containerLinearLayout);
if (errorView != null) {
linearLayout.addView(errorView);
}
container.setContainerView(linearLayout);
break;
}
return container;
}
public static String getVariableViewValueForUIPolicy(View view, HRCaseVariable hrCaseVariable) {
switch (hrCaseVariable.getType()) {
case SELECT_BOX:
Spinner selectBoxSpinner = (Spinner) view;
String value = hrCaseVariable.getDisplayChoiceText(selectBoxSpinner.getSelectedItem().toString());
/*value = null mean selected value is none or default value.*/
value = value != null ? value : "";
return value;
default:
return getVariableViewValue(view, hrCaseVariable.getType());
}
}
public static TextView getErrorView(Context context) { public static TextView getErrorView(Context context) {
TextView textView = new TextView(context); TextView textView = new TextView(context);
textView.setTextColor(ContextCompat.getColor(context, R.color.error_color)); textView.setTextColor(ContextCompat.getColor(context, R.color.error_color));
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
<string name="requested">Requested</string> <string name="requested">Requested</string>
<string name="rejected">Rejected</string> <string name="rejected">Rejected</string>
<string name="date_string">%1$s %2$s, %3$s</string> <string name="date_string">%1$s %2$s, %3$d</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--> <!--Failed to fetch-->
......
...@@ -28,6 +28,10 @@ ...@@ -28,6 +28,10 @@
android:name="com.vsoft.servicenow.ui.HRCaseItemScreen" android:name="com.vsoft.servicenow.ui.HRCaseItemScreen"
android:screenOrientation="portrait"/> android:screenOrientation="portrait"/>
<activity
android:name="com.vsoft.servicenow.ui.HRCaseVariableScreen"
android:screenOrientation="portrait"/>
<service android:name=".service.NotificationInstanceIdService" <service android:name=".service.NotificationInstanceIdService"
android:exported="false"> android:exported="false">
<intent-filter> <intent-filter>
......
...@@ -46,6 +46,12 @@ public class AppConfig { ...@@ -46,6 +46,12 @@ public class AppConfig {
/*Catalogue Category Items API */ /*Catalogue Category Items API */
public static final String URL_GET_HR_CASE_ITEM = "api/vsng2/uofl_mobile/catalog_item"; public static final String URL_GET_HR_CASE_ITEM = "api/vsng2/uofl_mobile/catalog_item";
/*HRCase Variable form API */
public static final String URL_GET_HR_CASE_VARIABLE = "api/vsng2/uofl_mobile/catalogue_variable_screen";
public static final String URL_GET_HR_CASE_UI_POLICY = "/api/vsng2/uofl_mobile/uipolicy";
public static final String URL_GET_HR_CASE_VARIABLE_CHOICE = "/api/vsng2/uofl_mobile/question_choice";
public static final String URL_POST_HR_CASE_CATALOGUE_ITEM = "api/vsng2/uofl_mobile";
/** /**
* Socket Chat server URLs - Urls given by Ravi * Socket Chat server URLs - Urls given by Ravi
* develop - http://111.93.6.218:12911/ * develop - http://111.93.6.218:12911/
......
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