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 1897 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();
}
...@@ -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.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.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 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);
} }
}); });
......
...@@ -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
...@@ -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