Commit 043807a8 by Kunj

Added offline functionality for complete app.

parents 2d8285a1 b7a69aa5
Showing with 2981 additions and 1303 deletions
...@@ -30,11 +30,11 @@ android { ...@@ -30,11 +30,11 @@ android {
buildToolsVersion "24.0.1" buildToolsVersion "24.0.1"
defaultConfig { defaultConfig {
applicationId "com.vsoft.uoflservicenow" applicationId "com.vsoft.servicenow"
minSdkVersion 9 minSdkVersion 9
targetSdkVersion 24 targetSdkVersion 24
versionCode 1 versionCode 1
versionName "0.0.20" versionName "0.0.29"
multiDexEnabled true multiDexEnabled true
} }
buildTypes { buildTypes {
...@@ -50,6 +50,15 @@ android { ...@@ -50,6 +50,15 @@ android {
signingConfig signingConfigs.config signingConfig signingConfigs.config
} }
} }
productFlavors {
uofl{
applicationId "com.vsoft.servicenow.uofl"
}
citrix {
applicationId "com.vsoft.servicenow.citrix"
}
}
} }
dependencies { dependencies {
......
package com.vsoft.servicenow;
/**
* @author Kunj on 05/01/17.
*/
public class AppConfig {
public static final String APP_INTERNAL_NAME = "Citrix";
public static final String DOMAIN_PRODUCTION = "https://ven01199.service-now.com/";
public static final String DOMAIN_TEST = "https://ven01199.service-now.com/";
public static final String LOGIN_CLIENT_ID_PRODUCTION = "ac0dd3408c1031006907010c2cc6ef6d";
public static final String LOGIN_CLIENT_SECRET_PRODUCTION = "oklj6znxv3o9jmyn2mlp";
public static final String LOGIN_CLIENT_ID_TEST = "ac0dd3408c1031006907010c2cc6ef6d";
public static final String LOGIN_CLIENT_SECRET_TEST = "dh85bcz3vx4dvgqys610";
/**
* Web services urls
*/
/*Catalogue Category API */
public static final String URL_GET_CATALOGUE = "api/vsng2/app_apis/category";
/*Catalogue Category Items API */
public static final String URL_GET_CATALOGUE_ITEM = "api/vsng2/app_apis/catalog_item";
/*Variable form API */
public static final String URL_GET_VARIABLE = "/api/vsng2/app_apis/variables";
public static final String URL_GET_UI_POLICY = "/api/vsng2/app_apis/uipolicy";
public static final String URL_GET_VARIABLE_CHOICE = "/api/vsng2/app_apis/question_choice";
public static final String URL_POST_CATALOGUE_ITEM = "api/vsng2/app_apis";
}
package com.vsoft.servicenow.ui;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import com.google.android.gms.analytics.Tracker;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.R;
import com.vsoft.servicenow.utils.PrefManager;
import com.vsoft.servicenow.utils.Util;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
* Created by Kunj on 11/8/16.
*/
public class HomeScreen extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.home_screen);
ButterKnife.bind(this);
CatalogueApplication application = (CatalogueApplication) getApplication();
Tracker tracker = application.getDefaultTracker();
// Send initial screen view hit.
Util.sendScreenName(tracker, getString(R.string.home_screen_string));
}
@OnClick(R.id.home_screen_order_service)
void orderServiceClicked() {
startActivity(new Intent(HomeScreen.this, CatalogueScreen.class));
}
@OnClick(R.id.home_screen_my_incident)
void myIncidentClicked() {
startActivity(new Intent(HomeScreen.this, MyIncidentScreen.class));
}
@OnClick(R.id.home_screen_my_request)
void myRequestClicked() {
startActivity(new Intent(HomeScreen.this, MyRequestActivity.class));
}
@OnClick(R.id.home_screen_report_incident)
void reportIncidentClicked() {
startActivity(new Intent(HomeScreen.this, ReportIncidentScreen.class));
}
@OnClick(R.id.home_screen_logout_image_view)
void logoutOnClicked() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.home_screen_logout_confirmation_msg_string)
.setCancelable(false)
.setPositiveButton(R.string.ok_string, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_ACCESS_TOKEN, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_REFRESH_TOKEN, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_LAST_NAME, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_SYS_ID, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_FIRST_NAME, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_USER_ID, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_USER_FULL_NAME, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_USER_EMAIL_ID, "");
Intent loginIntent = new Intent(HomeScreen.this, LoginScreen.class);
loginIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(loginIntent);
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="5dp" />
<solid
android:color="@color/back_button_bg_color"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@color/login_screen_login_button_background_color" />
<corners android:radius="10dp" />
</shape>
\ No newline at end of file
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="5dp" />
<solid
android:color="@color/login_screen_login_button_background_color"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/login_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbarStyle="insideOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/login_screen_top_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/login_screen_top_image" />
<LinearLayout
android:layout_below="@id/login_screen_top_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/login_screen_username_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/extra_large_margin"
android:layout_marginRight="@dimen/extra_large_margin"
android:background="@drawable/username_under_bg_box"
android:drawableLeft="@mipmap/ic_user_icon"
android:hint="@string/username_string"
android:lines="1"
android:padding="@dimen/normal_margin"
android:singleLine="true" />
<EditText
android:id="@+id/login_screen_password_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/extra_large_margin"
android:layout_marginRight="@dimen/extra_large_margin"
android:background="@drawable/username_under_bg_box"
android:drawableLeft="@mipmap/ic_password_icon"
android:hint="@string/password_string"
android:inputType="textPassword"
android:lines="1"
android:padding="@dimen/normal_margin"
android:singleLine="true" />
<TextView
android:id="@+id/login_screen_login_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/large_margin"
android:layout_marginLeft="@dimen/extra_large_margin"
android:layout_marginRight="@dimen/extra_large_margin"
android:layout_marginTop="@dimen/normal_margin"
android:background="@drawable/login_bg"
android:gravity="center"
android:paddingBottom="@dimen/normal_margin"
android:paddingTop="@dimen/normal_margin"
android:text="@string/login_screen_login_string"
android:textColor="@android:color/white"
android:textSize="@dimen/large_text_size" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_alignParentBottom="true"
android:background="@color/login_screen_bottom_color"/>
</RelativeLayout>
</ScrollView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
style = "@style/LightBackgroundStyle"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/tool_bar_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:minHeight="?attr/actionBarSize"
app:titleTextColor="@color/tool_bar_title_color"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/small_margin"
android:layout_marginRight="@dimen/small_margin">
<ImageView
android:id="@+id/nav_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/home_icon" />
<TextView
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text="@string/app_name"
android:textColor="@android:color/white" />
<ImageView
android:id="@+id/home_screen_logout_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/logout_icon" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="@dimen/extra_large_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/home_screen_report_incident"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/report_incident"/>
<ImageView
android:id="@+id/home_screen_order_service"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/order_services"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="@dimen/extra_large_margin">
<ImageView
android:id="@+id/home_screen_my_incident"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/my_incidents"/>
<ImageView
android:id="@+id/home_screen_my_request"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/my_requests"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
style="@style/LightBackgroundStyle">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:src="@drawable/splash_citrix_text_image"/>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tool_bar_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:minHeight="?attr/actionBarSize"
android:padding="0dp"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:theme="@style/ToolBarStyle"
style="@style/BlackBackgroundStyle"/>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="home_screen_icon_array">
<item>@drawable/report_incident</item>
<item>@drawable/order_services</item>
<item>@drawable/my_incidents</item>
<item>@drawable/my_requests</item>
</array>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="login_screen_login_button_background_color">#187cba</color>
<color name="login_screen_bottom_color">#ff9d1c</color>
<color name="screen_bg_color">#393e4f</color>
<color name="back_button_bg_color">#e01d24</color>
</resources>
<resources>
<string name="app_name">Citrix ServiceNow</string>
</resources>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="actionOverflowMenuStyle">@style/OverflowMenu</item>
</style>
<style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
<!-- Required for pre-Lollipop. -->
<item name="overlapAnchor">false</item>
<!-- Required for Lollipop. -->
<item name="android:overlapAnchor">false</item>
</style>
<style name="BlackBackgroundStyle" parent="@style/Theme.AppCompat">
<item name="android:background">@android:color/black</item>
</style>
<!-- ToolBar -->
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:textColorSecondary">@android:color/white</item>
<item name="actionMenuTextColor">@android:color/white</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Replace placeholder ID with your tracking ID -->
<string name="ga_trackingId">UA-83545030-1</string>
<!-- Enable automatic activity tracking -->
<bool name="ga_autoActivityTracking">true</bool>
<!-- Enable automatic exception tracking -->
<bool name="ga_reportUncaughtExceptions">true</bool>
</resources>
\ No newline at end of file
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vsoft.uoflservicenow"> package="com.vsoft.servicenow">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<supports-screens <supports-screens
android:anyDensity="true" android:anyDensity="true"
android:largeScreens="true" android:largeScreens="true"
...@@ -43,14 +45,14 @@ ...@@ -43,14 +45,14 @@
android:screenSize="xlarge" /> android:screenSize="xlarge" />
</compatible-screens> </compatible-screens>
<application <application
android:name="com.vsoft.uoflservicenow.CatalogueApplication" android:name="com.vsoft.servicenow.CatalogueApplication"
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity <activity
android:name="com.vsoft.uoflservicenow.ui.LoginScreen" android:name="com.vsoft.servicenow.ui.SplashScreen"
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|stateHidden"> android:windowSoftInputMode="adjustResize|stateHidden">
...@@ -60,27 +62,31 @@ ...@@ -60,27 +62,31 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name="com.vsoft.uoflservicenow.ui.HomeScreen" android:name="com.vsoft.servicenow.ui.LoginScreen"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|stateHidden"/>
<activity
android:name="com.vsoft.servicenow.ui.HomeScreen"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity <activity
android:name="com.vsoft.uoflservicenow.ui.CatalogueScreen" android:name="com.vsoft.servicenow.ui.CatalogueScreen"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity <activity
android:name="com.vsoft.uoflservicenow.ui.CatalogueItemScreen" android:name="com.vsoft.servicenow.ui.CatalogueItemScreen"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity <activity
android:name="com.vsoft.uoflservicenow.ui.CatalogueVariableScreen" android:name="com.vsoft.servicenow.ui.CatalogueVariableScreen"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize" /> android:windowSoftInputMode="stateHidden|adjustResize" />
<activity <activity
android:name="com.vsoft.uoflservicenow.ui.ReportIncidentScreen" android:name="com.vsoft.servicenow.ui.ReportIncidentScreen"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize"/> android:windowSoftInputMode="stateHidden|adjustResize"/>
<activity <activity
android:name="com.vsoft.uoflservicenow.ui.MyRequestActivity" android:name="com.vsoft.servicenow.ui.MyRequestActivity"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity <activity
android:name="com.vsoft.uoflservicenow.ui.MyIncidentScreen" android:name="com.vsoft.servicenow.ui.MyIncidentScreen"
android:screenOrientation="portrait"/> android:screenOrientation="portrait"/>
<service android:name=".service.SyncService" /> <service android:name=".service.SyncService" />
......
package com.vsoft.uoflservicenow; package com.vsoft.servicenow;
import android.app.Application; import android.app.Application;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
...@@ -10,13 +10,16 @@ import android.net.ConnectivityManager; ...@@ -10,13 +10,16 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import com.crashlytics.android.Crashlytics; import com.crashlytics.android.Crashlytics;
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.uoflservicenow.db.DBManager; import com.vsoft.servicenow.db.DBManager;
import com.vsoft.uoflservicenow.service.SyncService; import com.vsoft.servicenow.service.SyncService;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.ui.LoginScreen;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.PrefManager;
import io.fabric.sdk.android.Fabric; import io.fabric.sdk.android.Fabric;
...@@ -27,7 +30,7 @@ public class CatalogueApplication extends Application { ...@@ -27,7 +30,7 @@ public class CatalogueApplication extends Application {
private static Context mContext; private static Context mContext;
private Tracker mTracker; private Tracker mTracker;
private BroadcastReceiver mSyncBroadCastReceiver = new BroadcastReceiver() { private BroadcastReceiver mSyncBroadCastSyncReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
String action = intent.getStringExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION); String action = intent.getStringExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION);
...@@ -40,13 +43,37 @@ public class CatalogueApplication extends Application { ...@@ -40,13 +43,37 @@ public class CatalogueApplication extends Application {
} }
}; };
private BroadcastReceiver mSyncBroadCastLoginReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getStringExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION);
Log.d(Constants.TAG, "CatalogueApplication: onReceive: action: "+action);
if(Constants.ACTION_PROMPT_LOGIN.equals(action)) {
Toast.makeText(CatalogueApplication.this, R.string.prompt_relogin_login_expired, Toast.LENGTH_SHORT).show();
PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_ACCESS_TOKEN, "");
PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_REFRESH_TOKEN, "");
PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_LAST_NAME, "");
PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_SYS_ID, "");
PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_FIRST_NAME, "");
PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_USER_ID, "");
PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_USER_FULL_NAME, "");
PrefManager.setSharedPref(CatalogueApplication.this, PrefManager.PREFERENCE_USER_EMAIL_ID, "");
Intent loginIntent = new Intent(CatalogueApplication.this, LoginScreen.class);
loginIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(loginIntent);
}
}
};
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
Fabric.with(this, new Crashlytics()); Fabric.with(this, new Crashlytics());
mContext = getApplicationContext(); mContext = getApplicationContext();
LocalBroadcastManager.getInstance(this).registerReceiver(mSyncBroadCastReceiver, LocalBroadcastManager.getInstance(this).registerReceiver(mSyncBroadCastLoginReceiver,
new IntentFilter(Constants.APPLICATION_BROADCAST_INTENT));
LocalBroadcastManager.getInstance(this).registerReceiver(mSyncBroadCastSyncReceiver,
new IntentFilter(Constants.APPLICATION_BROADCAST_INTENT)); new IntentFilter(Constants.APPLICATION_BROADCAST_INTENT));
/*Database is created*/ /*Database is created*/
...@@ -56,7 +83,8 @@ public class CatalogueApplication extends Application { ...@@ -56,7 +83,8 @@ public class CatalogueApplication extends Application {
@Override @Override
public void onTerminate() { public void onTerminate() {
super.onTerminate(); super.onTerminate();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadCastReceiver); LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadCastLoginReceiver);
LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadCastSyncReceiver);
} }
public static Context getContext() { public static Context getContext() {
......
package com.vsoft.uoflservicenow.adapters; package com.vsoft.servicenow.adapters;
import android.content.Context; import android.content.Context;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -9,9 +9,9 @@ import android.widget.ImageView; ...@@ -9,9 +9,9 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.R;
import com.vsoft.uoflservicenow.db.models.Catalogue; import com.vsoft.servicenow.db.models.Catalogue;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
package com.vsoft.uoflservicenow.adapters; package com.vsoft.servicenow.adapters;
import android.content.Context; import android.content.Context;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -9,9 +9,9 @@ import android.widget.ImageView; ...@@ -9,9 +9,9 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.R;
import com.vsoft.uoflservicenow.db.models.CatalogueItem; import com.vsoft.servicenow.db.models.CatalogueItem;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
package com.vsoft.uoflservicenow.adapters; package com.vsoft.servicenow.adapters;
import android.content.Context; import android.content.Context;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -7,9 +7,9 @@ import android.view.ViewGroup; ...@@ -7,9 +7,9 @@ import android.view.ViewGroup;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.TextView; import android.widget.TextView;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.utils.Util;
import com.vsoft.uoflservicenow.db.models.Incident; import com.vsoft.servicenow.R;
import com.vsoft.uoflservicenow.utils.Util; import com.vsoft.servicenow.db.models.Incident;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
package com.vsoft.uoflservicenow.adapters; package com.vsoft.servicenow.adapters;
import android.content.Context; import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
...@@ -10,8 +10,8 @@ import android.widget.BaseAdapter; ...@@ -10,8 +10,8 @@ import android.widget.BaseAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.R;
import com.vsoft.uoflservicenow.db.models.MyRequest; import com.vsoft.servicenow.db.models.MyRequest;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
package com.vsoft.uoflservicenow.api; package com.vsoft.servicenow.api;
import java.io.IOException; import java.io.IOException;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
......
package com.vsoft.uoflservicenow.api; package com.vsoft.servicenow.api;
import android.util.Base64; import android.text.TextUtils;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -22,8 +22,7 @@ import retrofit2.converter.gson.GsonConverterFactory; ...@@ -22,8 +22,7 @@ import retrofit2.converter.gson.GsonConverterFactory;
public class RestClient { public class RestClient {
public static Retrofit getInitializedRestAdapter(String username, String password) { public static Retrofit getInitializedRestAdapter(final String accessToken) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
// set your desired log level // set your desired log level
logging.setLevel(HttpLoggingInterceptor.Level.BODY); logging.setLevel(HttpLoggingInterceptor.Level.BODY);
...@@ -31,17 +30,19 @@ public class RestClient { ...@@ -31,17 +30,19 @@ public class RestClient {
.connectTimeout(10, TimeUnit.SECONDS) .connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS) .writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS); .readTimeout(30, TimeUnit.SECONDS);
String credentials = username + ":" + password;
final String basic =
"Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
// add your other interceptors // add your other interceptors
Interceptor interceptor = new Interceptor() { Interceptor interceptor = new Interceptor() {
@Override @Override
public Response intercept(Chain chain) { public Response intercept(Chain chain) {
Request original = chain.request(); Request original = chain.request();
Request.Builder requestBuilder = original.newBuilder() Request.Builder requestBuilder = original.newBuilder();
.header(Constants.API_HEADER_PARAM_AUTHORIZATION, basic);
if(!TextUtils.isEmpty(accessToken)) {
final String bearer = "Bearer " + accessToken;
requestBuilder.header(Constants.API_HEADER_PARAM_AUTHORIZATION, bearer);
}
requestBuilder.header("Accept", "application/json"); requestBuilder.header("Accept", "application/json");
requestBuilder.header("Content-Type", "application/json"); requestBuilder.header("Content-Type", "application/json");
requestBuilder.method(original.method(), original.body()); requestBuilder.method(original.method(), original.body());
......
package com.vsoft.uoflservicenow.api.interfaces; package com.vsoft.servicenow.api.interfaces;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import retrofit2.Call; import retrofit2.Call;
...@@ -16,13 +16,7 @@ import retrofit2.http.Query; ...@@ -16,13 +16,7 @@ import retrofit2.http.Query;
public interface CatalogueCategoryApi { public interface CatalogueCategoryApi {
// Get Catalogue API // Get Catalogue API
@GET(Constants.URL_GET_CATALOGUE) @GET(Constants.URL_GET_CATALOGUE)
Call<ResponseBody> getCatalogue(@Query(Constants.URL_PARAM_SYSPRM_QUERY) String sysparmQuery, Call<ResponseBody> getCatalogue(@Query(Constants.URL_PARAM_SYS_ID) String sysId);
@Query(Constants.URL_PARAM_SYSPRM_FIELDS) String sysParmFields,
@Query(Constants.URL_PARAM_SYSPRM_DISPLAY_VALUE) String sysParmDisplayValue);
// Get Catalogue Order API
@GET(Constants.URL_GET_CATALOGUE_ORDER)
Call<ResponseBody> getCatalogueOrder();
} }
package com.vsoft.uoflservicenow.api.interfaces; package com.vsoft.servicenow.api.interfaces;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import retrofit2.Call; import retrofit2.Call;
...@@ -16,9 +16,7 @@ import retrofit2.http.Query; ...@@ -16,9 +16,7 @@ import retrofit2.http.Query;
public interface CatalogueCategoryItemApi { public interface CatalogueCategoryItemApi {
// Get Catalogue Item API // Get Catalogue Item API
@GET(Constants.URL_GET_CATALOGUE_ITEM) @GET(Constants.URL_GET_CATALOGUE_ITEM)
Call<ResponseBody> getCatalogueItem(@Query(Constants.URL_PARAM_SYSPRM_QUERY) String sysparmQuery, Call<ResponseBody> getCatalogueItem(@Query(Constants.URL_PARAM_SYS_ID) String sysId);
@Query(Constants.URL_PARAM_SYSPRM_FIELDS) String sysParmFields,
@Query(Constants.URL_PARAM_SYSPRM_DISPLAY_VALUE) String sysParmDisplayValue);
} }
package com.vsoft.uoflservicenow.api.interfaces; package com.vsoft.servicenow.api.interfaces;
import com.vsoft.uoflservicenow.db.models.CatalogueItem; import com.vsoft.servicenow.db.models.CatalogueVariable;
import com.vsoft.uoflservicenow.db.models.CatalogueVariable; import com.vsoft.servicenow.db.models.CatalogueItem;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import java.util.Map; import java.util.Map;
...@@ -30,8 +30,7 @@ public interface CatalogueVariableApi { ...@@ -30,8 +30,7 @@ public interface CatalogueVariableApi {
// Get Variable Choices API // Get Variable Choices API
@GET(Constants.URL_GET_VARIABLE_CHOICE) @GET(Constants.URL_GET_VARIABLE_CHOICE)
Call<ResponseBody> getVariableChoice(@Query(Constants.URL_PARAM_SYSPRM_QUERY) String sysparmQuery, Call<ResponseBody> getVariableChoice(@Query(Constants.URL_PARAM_SYS_ID) String sysId);
@Query(Constants.URL_PARAM_SYSPRM_FIELDS) String sysParmFields);
// Post catalogue item API // Post catalogue item API
@POST(Constants.URL_POST_CATALOGUE_ITEM) @POST(Constants.URL_POST_CATALOGUE_ITEM)
......
package com.vsoft.uoflservicenow.api.interfaces; package com.vsoft.servicenow.api.interfaces;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import retrofit2.Call; import retrofit2.Call;
......
package com.vsoft.uoflservicenow.api.interfaces; package com.vsoft.servicenow.api.interfaces;
import com.vsoft.uoflservicenow.db.models.LoginItem; import com.vsoft.servicenow.api.pojos.LoginApiResponse;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import retrofit2.Call; import retrofit2.Call;
...@@ -20,9 +20,19 @@ public interface LoginApi { ...@@ -20,9 +20,19 @@ public interface LoginApi {
// Post Login item API // Post Login item API
@FormUrlEncoded @FormUrlEncoded
@POST(Constants.URL_POST_LOGIN_ITEM) @POST(Constants.URL_POST_LOGIN_ITEM)
Call<ResponseBody> postLoginValues(@Field(LoginItem.Json.GRANT_TYPE) String grantType, @Field(LoginItem.Json.CLIENT_ID) String clientId, Call<ResponseBody> postLoginValues(@Field(LoginApiResponse.Json.GRANT_TYPE) String grantType,
@Field(LoginItem.Json.CLIENT_CECRET) String clientSecret, @Field(LoginItem.Json.USER_NAME) String userName, @Field(LoginApiResponse.Json.CLIENT_ID) String clientId,
@Field(LoginItem.Json.PASSWORD) String password); @Field(LoginApiResponse.Json.CLIENT_SECRET) String clientSecret,
@Field(LoginApiResponse.Json.USER_NAME) String userName,
@Field(LoginApiResponse.Json.PASSWORD) String password);
@FormUrlEncoded
@POST(Constants.URL_REFRESH_LOGIN)
Call<ResponseBody> refreshLogin(@Field(LoginApiResponse.Json.GRANT_TYPE) String grantType,
@Field(LoginApiResponse.Json.CLIENT_ID) String clientId,
@Field(LoginApiResponse.Json.CLIENT_SECRET) String clientSecret,
@Field(LoginApiResponse.Json.REFRESH_TOKEN) String refreshToken);
} }
package com.vsoft.uoflservicenow.api.interfaces; package com.vsoft.servicenow.api.interfaces;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import retrofit2.Call; import retrofit2.Call;
......
package com.vsoft.uoflservicenow.api.interfaces; package com.vsoft.servicenow.api.interfaces;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import retrofit2.Call; import retrofit2.Call;
......
package com.vsoft.uoflservicenow.api.listeners.get; package com.vsoft.servicenow.api.listeners.get;
import com.vsoft.uoflservicenow.db.models.Catalogue; import com.vsoft.servicenow.db.models.Catalogue;
import java.util.List; import java.util.List;
......
package com.vsoft.uoflservicenow.api.listeners.get; package com.vsoft.servicenow.api.listeners.get;
import com.vsoft.uoflservicenow.db.models.CatalogueItem; import com.vsoft.servicenow.db.models.CatalogueItem;
import java.util.List; import java.util.List;
......
package com.vsoft.uoflservicenow.api.listeners.get; package com.vsoft.servicenow.api.listeners.get;
import com.vsoft.uoflservicenow.db.models.CatalogueOrder; import com.vsoft.servicenow.db.models.CatalogueOrder;
import java.util.List; import java.util.List;
......
package com.vsoft.uoflservicenow.api.listeners.get; package com.vsoft.servicenow.api.listeners.get;
import com.vsoft.uoflservicenow.db.models.CatalogueVariable; import com.vsoft.servicenow.db.models.CatalogueVariableResponse;
import com.vsoft.uoflservicenow.db.models.CatalogueVariableSet;
import java.util.List;
/** /**
* @since 1.0 * @since 1.0
...@@ -11,6 +8,6 @@ import java.util.List; ...@@ -11,6 +8,6 @@ import java.util.List;
* *
*/ */
public interface GetCatalogueVariableApiListener { public interface GetCatalogueVariableApiListener {
void onDoneApiCall(List<CatalogueVariableSet> variableSetList, List<CatalogueVariable> variableList); void onDoneApiCall(CatalogueVariableResponse catalogueVariableResponse);
void onFailApiCall(); void onFailApiCall();
} }
package com.vsoft.uoflservicenow.api.listeners.get; package com.vsoft.servicenow.api.listeners.get;
import com.vsoft.uoflservicenow.db.models.Incident; import com.vsoft.servicenow.db.models.Incident;
import java.util.List; import java.util.List;
......
package com.vsoft.uoflservicenow.api.listeners.get; package com.vsoft.servicenow.api.listeners.get;
import com.vsoft.uoflservicenow.db.models.MyRequest; import com.vsoft.servicenow.db.models.MyRequest;
import java.util.List; import java.util.List;
......
package com.vsoft.uoflservicenow.api.listeners.get; package com.vsoft.servicenow.api.listeners.get;
import com.vsoft.uoflservicenow.db.models.Reference; import com.vsoft.servicenow.db.models.Reference;
import java.util.List; import java.util.List;
......
package com.vsoft.uoflservicenow.api.listeners.get; package com.vsoft.servicenow.api.listeners.get;
import com.vsoft.uoflservicenow.db.models.UiPolicyItem; import com.vsoft.servicenow.db.models.UiPolicyItem;
import java.util.List; import java.util.List;
......
package com.vsoft.uoflservicenow.api.listeners.get; package com.vsoft.servicenow.api.listeners.get;
import com.vsoft.uoflservicenow.db.models.UserApiValues; import com.vsoft.servicenow.db.models.UserApiValues;
import java.util.List; import java.util.List;
......
package com.vsoft.uoflservicenow.api.listeners.get; package com.vsoft.servicenow.api.listeners.get;
import com.vsoft.servicenow.api.pojos.LoginApiResponse;
/** /**
* @since 1.0 * @since 1.0
...@@ -6,6 +8,6 @@ package com.vsoft.uoflservicenow.api.listeners.get; ...@@ -6,6 +8,6 @@ package com.vsoft.uoflservicenow.api.listeners.get;
* *
*/ */
public interface GetUserLoginApiListener { public interface GetUserLoginApiListener {
void onDoneApiCall(); void onDoneApiCall(LoginApiResponse loginApiResponse);
void onFailApiCall(); void onFailApiCall();
} }
package com.vsoft.uoflservicenow.api.listeners.get; package com.vsoft.servicenow.api.listeners.get;
import com.vsoft.uoflservicenow.db.models.VariableChoice; import com.vsoft.servicenow.db.models.VariableChoice;
import java.util.List; import java.util.List;
......
package com.vsoft.uoflservicenow.api.listeners.post; package com.vsoft.servicenow.api.listeners.post;
/** /**
* @since 1.0 * @since 1.0
......
package com.vsoft.uoflservicenow.api.listeners.post; package com.vsoft.servicenow.api.listeners.post;
/** /**
* @since 1.0 * @since 1.0
......
package com.vsoft.uoflservicenow.api.listeners.post; package com.vsoft.servicenow.api.listeners.post;
/** /**
* @since 1.0 * @since 1.0
......
package com.vsoft.uoflservicenow.api.managers; package com.vsoft.servicenow.api.managers;
import android.content.Context;
import android.util.Log;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
...@@ -6,14 +9,14 @@ import com.google.gson.JsonDeserializationContext; ...@@ -6,14 +9,14 @@ import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer; import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.vsoft.uoflservicenow.api.RestClient; import com.vsoft.servicenow.api.RestClient;
import com.vsoft.uoflservicenow.api.interfaces.CatalogueCategoryApi; import com.vsoft.servicenow.api.interfaces.CatalogueCategoryApi;
import com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueApiListener; import com.vsoft.servicenow.api.listeners.get.GetCatalogueApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueOrderApiListener; import com.vsoft.servicenow.db.models.Catalogue;
import com.vsoft.uoflservicenow.db.models.Catalogue; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.db.models.CatalogueOrder; import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.PrefManager;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
...@@ -33,20 +36,19 @@ import retrofit2.Retrofit; ...@@ -33,20 +36,19 @@ import retrofit2.Retrofit;
/** /**
* @author Kunj on 11/8/16. * @author Kunj on 11/8/16.
*
*/ */
public class CatalogueApiManager { public class CatalogueApiManager {
public static void getCatalogues(final GetCatalogueApiListener listener) { public static void getCatalogues(Context context, final GetCatalogueApiListener listener) {
CatalogueLog.d("CatalogueApiManager: getCatalogues: "); CatalogueLog.d("CatalogueApiManager: getCatalogues: ");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(Catalogue.Json.URL_PARAM_CATALOGUE_SYSPRM_QUERY_VALUE);
stringBuilder.append("=e0d08b13c3330100c8b837659bba8fb4");
stringBuilder.append("^active=true");
CatalogueLog.d("CatalogueApiManager: getCatalogues: request parameter: "+stringBuilder.toString());
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD); String accessToken = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
Call<ResponseBody> call = retrofit.create(CatalogueCategoryApi.class).getCatalogue(stringBuilder.toString(), "sys_id,title,description,homepage_image", "true"); if (accessToken.isEmpty()) {
listener.onFailApiCall();
return;
}
final Retrofit retrofit = RestClient.getInitializedRestAdapter(accessToken);
Call<ResponseBody> call = retrofit.create(CatalogueCategoryApi.class).getCatalogue("e0d08b13c3330100c8b837659bba8fb4");
try { try {
//Retrofit synchronous call //Retrofit synchronous call
Response<ResponseBody> response = call.execute(); Response<ResponseBody> response = call.execute();
...@@ -56,7 +58,7 @@ public class CatalogueApiManager { ...@@ -56,7 +58,7 @@ public class CatalogueApiManager {
JSONObject error = jsonObject.optJSONObject(Constants.RESPONSE_ERROR_OBJECT_NAME); JSONObject error = jsonObject.optJSONObject(Constants.RESPONSE_ERROR_OBJECT_NAME);
if (error == null) { if (error == null) {
JSONArray catalogueJsonArray = jsonObject.getJSONArray(Constants.RESPONSE_RESULT_OBJECT_NAME); JSONArray catalogueJsonArray = jsonObject.getJSONArray(Constants.RESPONSE_RESULT_OBJECT_NAME);
if(catalogueJsonArray.length() > 0) { if (catalogueJsonArray.length() > 0) {
Gson gson = new GsonBuilder() Gson gson = new GsonBuilder()
.excludeFieldsWithoutExposeAnnotation() .excludeFieldsWithoutExposeAnnotation()
.registerTypeAdapter(long.class, new JsonDeserializer<Long>() { .registerTypeAdapter(long.class, new JsonDeserializer<Long>() {
...@@ -98,34 +100,19 @@ public class CatalogueApiManager { ...@@ -98,34 +100,19 @@ public class CatalogueApiManager {
.create(); .create();
final List<Catalogue> catalogueList = new ArrayList<>(catalogueJsonArray.length()); final List<Catalogue> catalogueList = new ArrayList<>(catalogueJsonArray.length());
final List<Catalogue> finalCatalogueList = new ArrayList<>(catalogueJsonArray.length());
for (int i = 0; i < catalogueJsonArray.length(); i++) { for (int i = 0; i < catalogueJsonArray.length(); i++) {
JSONObject catalogueJsonObject = catalogueJsonArray.getJSONObject(i); JSONObject catalogueJsonObject = catalogueJsonArray.getJSONObject(i);
Catalogue catalogue = gson.fromJson(catalogueJsonObject.toString(), Catalogue.class); Catalogue catalogue = gson.fromJson(catalogueJsonObject.toString(), Catalogue.class);
catalogueList.add(catalogue); catalogueList.add(catalogue);
} }
if(!catalogueList.isEmpty()) { if (!catalogueList.isEmpty()) {
getCatalogueOrder(new GetCatalogueOrderApiListener() { Collections.sort(catalogueList, new Comparator<Catalogue>() {
@Override @Override
public void onDoneApiCall(List<CatalogueOrder> catalogueOrderList) { public int compare(Catalogue lhs, Catalogue rhs) {
for (int i = 0; i<catalogueOrderList.size(); i++) { return (int) (lhs.getOrder() - rhs.getOrder());
CatalogueOrder catalogueOrder = catalogueOrderList.get(i);
for(int j = 0; j<catalogueList.size(); j++) {
Catalogue catalogue = catalogueList.get(j);
if (catalogue.getSysId().equals(catalogueOrder.getId())) {
finalCatalogueList.add(catalogue);
break;
}
}
}
listener.onDoneApiCall(finalCatalogueList);
}
@Override
public void onFailApiCall() {
listener.onFailApiCall();
} }
}); });
listener.onDoneApiCall(catalogueList);
} else { } else {
listener.onDoneApiCall(new ArrayList<Catalogue>(0)); listener.onDoneApiCall(new ArrayList<Catalogue>(0));
} }
...@@ -142,109 +129,26 @@ public class CatalogueApiManager { ...@@ -142,109 +129,26 @@ public class CatalogueApiManager {
listener.onFailApiCall(); listener.onFailApiCall();
} }
} else { } else {
listener.onFailApiCall(); CatalogueLog.d("CatalogueApiManager: getCatalogues: response is not success");
} if (response.code() == 401) {
} catch (IOException e) { Log.d(Constants.TAG, "-- is 401, try refresh token...");
CatalogueLog.e("CatalogueApiManager: getCatalogues: IOException: ", e); Log.d(Constants.TAG, "refresh token: " + PrefManager.getSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN));
listener.onFailApiCall(); SyncStatus status = LoginApiManager.refreshLogin(context, PrefManager.getSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN));
} catch (NullPointerException e) { if (status == SyncStatus.SUCCESS) {
CatalogueLog.e("CatalogueApiManager: getCatalogues: NullPointerException: ", e); CatalogueLog.d("refresh token success, retry same...");
listener.onFailApiCall(); getCatalogues(context, listener);
}
}
public static void getCatalogueOrder(GetCatalogueOrderApiListener listener) {
CatalogueLog.d("CatalogueApiManager: getCatalogueOrder: ");
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(CatalogueCategoryApi.class).getCatalogueOrder();
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) {
JSONObject resultJsonObject = jsonObject.getJSONObject(Constants.RESPONSE_RESULT_OBJECT_NAME);
JSONArray catalogueOrderJsonArray = resultJsonObject.getJSONArray(Constants.RESPONSE_CATEGORY_OBJECT_NAME);
if(catalogueOrderJsonArray.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("CatalogueApiManager: getCatalogueOrder: 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("CatalogueApiManager: getCatalogueOrder: 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("CatalogueApiManager: getCatalogueOrder: deserialize: float.class: NumberFormatException: ", e);
}
return value;
}
})
.create();
List<CatalogueOrder> catalogueOrderList = new ArrayList<>(catalogueOrderJsonArray.length());
for (int i = 0; i < catalogueOrderJsonArray.length(); i++) {
JSONObject orderJsonObject = catalogueOrderJsonArray.getJSONObject(i);
CatalogueOrder catalogueOrder = gson.fromJson(orderJsonObject.toString(), CatalogueOrder.class);
catalogueOrderList.add(catalogueOrder);
}
/*Sort List of CatalogueOrder*/
Collections.sort(catalogueOrderList, new Comparator<CatalogueOrder>() {
@Override
public int compare(CatalogueOrder lhs, CatalogueOrder rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
listener.onDoneApiCall(catalogueOrderList);
} else { } else {
listener.onDoneApiCall(new ArrayList<CatalogueOrder>(0)); CatalogueLog.d("refresh token failed, return FAIL");
}
} else
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogueOrder: onResponse: ", e);
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogueOrder: onResponse: ", e);
listener.onFailApiCall();
} }
} else { } else {
listener.onFailApiCall(); listener.onFailApiCall();
} }
}
} catch (IOException e) { } catch (IOException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogueOrder: IOException: ", e); CatalogueLog.e("CatalogueApiManager: getCatalogues: IOException: ", e);
listener.onFailApiCall(); listener.onFailApiCall();
} catch (NullPointerException e) { } catch (NullPointerException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogueOrder: NullPointerException: ", e); CatalogueLog.e("CatalogueApiManager: getCatalogues: NullPointerException: ", e);
listener.onFailApiCall(); listener.onFailApiCall();
} }
} }
......
package com.vsoft.uoflservicenow.api.managers; package com.vsoft.servicenow.api.managers;
import android.content.Context;
import android.util.Log;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
...@@ -6,12 +9,14 @@ import com.google.gson.JsonDeserializationContext; ...@@ -6,12 +9,14 @@ import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer; import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.vsoft.uoflservicenow.api.RestClient; import com.vsoft.servicenow.api.RestClient;
import com.vsoft.uoflservicenow.api.interfaces.CatalogueCategoryItemApi; import com.vsoft.servicenow.api.interfaces.CatalogueCategoryItemApi;
import com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueItemApiListener; import com.vsoft.servicenow.api.listeners.get.GetCatalogueItemApiListener;
import com.vsoft.uoflservicenow.db.models.CatalogueItem; import com.vsoft.servicenow.db.models.CatalogueItem;
import com.vsoft.uoflservicenow.utils.CatalogueLog; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.Constants; 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.JSONArray;
import org.json.JSONException; import org.json.JSONException;
...@@ -33,17 +38,16 @@ import retrofit2.Retrofit; ...@@ -33,17 +38,16 @@ import retrofit2.Retrofit;
*/ */
public class CatalogueItemApiManager { public class CatalogueItemApiManager {
public static void getCatalogueItems(String catalogueSysId, GetCatalogueItemApiListener listener) { public static void getCatalogueItems(Context context, String catalogueSysId, GetCatalogueItemApiListener listener) {
CatalogueLog.d("CatalogueItemApiManager: getCatalogueItems: "); CatalogueLog.d("CatalogueItemApiManager: getCatalogueItems: ");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(CatalogueItem.Json.URL_PARAM_CATALOGUE_SYSPRM_QUERY_VALUE);
stringBuilder.append("=");
stringBuilder.append(catalogueSysId);
stringBuilder.append("^active=true");
CatalogueLog.d("CatalogueItemApiManager: getCatalogueItems: request parameter: "+stringBuilder.toString());
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD); String accessToken = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
Call<ResponseBody> call = retrofit.create(CatalogueCategoryItemApi.class).getCatalogueItem(stringBuilder.toString(), "sys_id,short_description,name,description,icon", "true"); if(accessToken.isEmpty()) {
listener.onFailApiCall();
return;
}
final Retrofit retrofit = RestClient.getInitializedRestAdapter(accessToken);
Call<ResponseBody> call = retrofit.create(CatalogueCategoryItemApi.class).getCatalogueItem(catalogueSysId);
try { try {
//Retrofit synchronous call //Retrofit synchronous call
Response<ResponseBody> response = call.execute(); Response<ResponseBody> response = call.execute();
...@@ -114,8 +118,21 @@ public class CatalogueItemApiManager { ...@@ -114,8 +118,21 @@ public class CatalogueItemApiManager {
listener.onFailApiCall(); listener.onFailApiCall();
} }
} else { } else {
CatalogueLog.d("CatalogueItemApiManager: getCatalogueItems: 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...");
getCatalogueItems(context, catalogueSysId, listener);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
}
} else {
listener.onFailApiCall(); listener.onFailApiCall();
} }
}
} catch (IOException e) { } catch (IOException e) {
CatalogueLog.e("CatalogueItemApiManager: getCatalogueItems: IOException: ", e); CatalogueLog.e("CatalogueItemApiManager: getCatalogueItems: IOException: ", e);
listener.onFailApiCall(); listener.onFailApiCall();
......
package com.vsoft.uoflservicenow.api.managers; package com.vsoft.servicenow.api.managers;
import android.content.Context;
import android.util.Log;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
...@@ -6,18 +9,19 @@ import com.google.gson.JsonDeserializationContext; ...@@ -6,18 +9,19 @@ import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer; import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.vsoft.uoflservicenow.api.RestClient; import com.vsoft.servicenow.api.RestClient;
import com.vsoft.uoflservicenow.api.interfaces.CatalogueVariableApi; import com.vsoft.servicenow.api.interfaces.CatalogueVariableApi;
import com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueVariableApiListener; import com.vsoft.servicenow.api.listeners.get.GetCatalogueVariableApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetUiPolicyApiListener; import com.vsoft.servicenow.api.listeners.post.PostAttachmentApiListener;
import com.vsoft.uoflservicenow.api.listeners.post.PostAttachmentApiListener; import com.vsoft.servicenow.api.listeners.post.PostVariableFormApiListener;
import com.vsoft.uoflservicenow.api.listeners.post.PostVariableFormApiListener; import com.vsoft.servicenow.db.models.CatalogueVariable;
import com.vsoft.uoflservicenow.db.models.CatalogueVariable; import com.vsoft.servicenow.db.models.CatalogueVariableResponse;
import com.vsoft.uoflservicenow.db.models.CatalogueVariableSet; import com.vsoft.servicenow.db.models.CatalogueVariableSet;
import com.vsoft.uoflservicenow.db.models.UiPolicyAction; import com.vsoft.servicenow.db.models.VariableChoice;
import com.vsoft.uoflservicenow.db.models.UiPolicyItem; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.PrefManager;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
...@@ -25,10 +29,8 @@ import org.json.JSONObject; ...@@ -25,10 +29,8 @@ import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
...@@ -42,9 +44,16 @@ import retrofit2.Retrofit; ...@@ -42,9 +44,16 @@ import retrofit2.Retrofit;
*/ */
public class CatalogueVariableApiManager { public class CatalogueVariableApiManager {
public static void getCatalogueVariable(String catalogueItemSysId, GetCatalogueVariableApiListener listener) { public static void getCatalogueVariable(Context context, String catalogueItemSysId, GetCatalogueVariableApiListener listener) {
CatalogueLog.d("CatalogueVariableApiManager: getCatalogueVariable: "); CatalogueLog.d("CatalogueVariableApiManager: getCatalogueVariable: ");
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
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(CatalogueVariableApi.class).getVariable(catalogueItemSysId); Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).getVariable(catalogueItemSysId);
try { try {
//Retrofit synchronous call //Retrofit synchronous call
...@@ -95,58 +104,80 @@ public class CatalogueVariableApiManager { ...@@ -95,58 +104,80 @@ public class CatalogueVariableApiManager {
} }
}) })
.create(); .create();
JSONObject catalogueJsonObject = jsonArray.getJSONObject(0); JSONObject catalogueJsonObject = jsonArray.getJSONObject(0);
JSONArray variableSetJsonArray = catalogueJsonObject.getJSONArray(Constants.RESPONSE_VARIABLE_SET_OBJECT_NAME); JSONArray catalogueVariableJsonArray = catalogueJsonObject.getJSONArray(Constants
List<CatalogueVariableSet> variableSetList = new ArrayList<>(variableSetJsonArray.length()); .RESPONSE_VARIABLES_OBJECT_NAME);
for (int i = 0; i < variableSetJsonArray.length(); i++) { JSONArray catalogueVariableSetJsonArray = catalogueJsonObject.getJSONArray(Constants
JSONObject variableSetJsonObject = variableSetJsonArray.getJSONObject(i); .RESPONSE_VARIABLE_SET_OBJECT_NAME);
CatalogueVariableSet catalogueVariableSet = gson.fromJson(variableSetJsonObject.toString(), CatalogueVariableSet.class); CatalogueVariableResponse catalogueVariableResponse = gson.fromJson(catalogueJsonObject.toString(),
CatalogueVariableResponse.class);
for (int i = 0; i < catalogueVariableJsonArray.length(); i++) {
CatalogueVariable catalogueVariable = catalogueVariableResponse.getVariables().get(i);
JSONObject catalogueVariableJsonObject = catalogueVariableJsonArray.getJSONObject(i);
catalogueVariable.parseJson(catalogueVariableJsonObject);
if(!catalogueVariable.getVariableChoiceList().isEmpty()) {
Collections.sort(catalogueVariable.getVariableChoiceList(), new Comparator<VariableChoice>() {
@Override
public int compare(VariableChoice lhs, VariableChoice rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
}
}
JSONArray variableJsonArray = variableSetJsonObject.getJSONArray(Constants.RESPONSE_VARIABLES_OBJECT_NAME); for (int i = 0; i < catalogueVariableSetJsonArray.length(); i++) {
List<CatalogueVariable> variableList = new ArrayList<>(variableJsonArray.length()); CatalogueVariableSet catalogueVariableSet = catalogueVariableResponse.getVariablesets
().get(i);
JSONObject variableSetJsonObject = catalogueVariableSetJsonArray.getJSONObject(i);
JSONArray variableJsonArray = variableSetJsonObject.getJSONArray(Constants
.RESPONSE_VARIABLES_OBJECT_NAME);
for (int j = 0; j < variableJsonArray.length(); j++) { for (int j = 0; j < variableJsonArray.length(); j++) {
JSONObject variableJsonObject = variableJsonArray.getJSONObject(j); JSONObject variableJsonObject = variableJsonArray.getJSONObject(j);
CatalogueVariable catalogueVariable = gson.fromJson(variableJsonObject.toString(), CatalogueVariable.class); CatalogueVariable catalogueVariable = catalogueVariableSet.getVariables().get(j);
catalogueVariable.parseJson(variableJsonObject); catalogueVariable.parseJson(variableJsonObject);
variableList.add(catalogueVariable); if(!catalogueVariable.getVariableChoiceList().isEmpty()) {
} Collections.sort(catalogueVariable.getVariableChoiceList(), new Comparator<VariableChoice>() {
Collections.sort(variableList, new Comparator<CatalogueVariable>() {
@Override @Override
public int compare(CatalogueVariable lhs, CatalogueVariable rhs) { public int compare(VariableChoice lhs, VariableChoice rhs) {
return (lhs.getOrder() - rhs.getOrder()); return (lhs.getOrder() - rhs.getOrder());
} }
}); });
}
catalogueVariableSet.setVariables(variableList); }
variableSetList.add(catalogueVariableSet);
} }
Collections.sort(variableSetList, new Comparator<CatalogueVariableSet>() { /*Sort Variable set*/
Collections.sort(catalogueVariableResponse.getVariablesets(), new Comparator<CatalogueVariableSet>() {
@Override @Override
public int compare(CatalogueVariableSet lhs, CatalogueVariableSet rhs) { public int compare(CatalogueVariableSet lhs, CatalogueVariableSet rhs) {
return (lhs.getOrder() - rhs.getOrder()); return (lhs.getOrder() - rhs.getOrder());
} }
}); });
JSONArray variableJsonArray = catalogueJsonObject.getJSONArray(Constants.RESPONSE_VARIABLES_OBJECT_NAME); /*Sort Variables*/
List<CatalogueVariable> variableList = new ArrayList<>(variableJsonArray.length()); Collections.sort(catalogueVariableResponse.getVariables(), new Comparator<CatalogueVariable>() {
for (int i = 0; i < variableJsonArray.length(); i++) { @Override
JSONObject variableJsonObject = variableJsonArray.getJSONObject(i); public int compare(CatalogueVariable lhs, CatalogueVariable rhs) {
CatalogueVariable catalogueVariable = gson.fromJson(variableJsonObject.toString(), CatalogueVariable.class); return (lhs.getOrder() - rhs.getOrder());
catalogueVariable.parseJson(variableJsonObject);
variableList.add(catalogueVariable);
} }
});
/*Sort Variables of Variable sets*/
for (int i = 0; i < catalogueVariableResponse.getVariablesets().size() ; i++) {
CatalogueVariableSet catalogueVariableSet = catalogueVariableResponse.getVariablesets
().get(i);
Collections.sort(variableList, new Comparator<CatalogueVariable>() { Collections.sort(catalogueVariableSet.getVariables(), new Comparator<CatalogueVariable>() {
@Override @Override
public int compare(CatalogueVariable lhs, CatalogueVariable rhs) { public int compare(CatalogueVariable lhs, CatalogueVariable rhs) {
return (lhs.getOrder() - rhs.getOrder()); return (lhs.getOrder() - rhs.getOrder());
} }
}); });
listener.onDoneApiCall(variableSetList, variableList); }
listener.onDoneApiCall(catalogueVariableResponse);
} else { } else {
listener.onDoneApiCall(new ArrayList<CatalogueVariableSet>(0), new ArrayList<CatalogueVariable>(0)); listener.onDoneApiCall(null);
} }
} else } else
listener.onFailApiCall(); listener.onFailApiCall();
...@@ -158,8 +189,21 @@ public class CatalogueVariableApiManager { ...@@ -158,8 +189,21 @@ public class CatalogueVariableApiManager {
listener.onFailApiCall(); listener.onFailApiCall();
} }
} else { } else {
CatalogueLog.d("CatalogueVariableApiManager: getCatalogueVariable: : 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...");
getCatalogueVariable(context, catalogueItemSysId, listener);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
}
} else {
listener.onFailApiCall(); listener.onFailApiCall();
} }
}
} catch (IOException e) { } catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: getCatalogueVariable: IOException: ", e); CatalogueLog.e("CatalogueVariableApiManager: getCatalogueVariable: IOException: ", e);
listener.onFailApiCall(); listener.onFailApiCall();
...@@ -169,104 +213,15 @@ public class CatalogueVariableApiManager { ...@@ -169,104 +213,15 @@ public class CatalogueVariableApiManager {
} }
} }
public static void getUiPolicy(String catalogueItemSysId, GetUiPolicyApiListener listener) { public static void submitVariableForm(Context context, String catalogueItemSysId, String catalogueJsonString, PostVariableFormApiListener listener) {
CatalogueLog.d("CatalogueVariableApiManager: getUiPolicy: "); CatalogueLog.d("submitVariableForm: " + catalogueJsonString);
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).getUiPolicy(catalogueItemSysId);
try {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) {
try {
JSONObject jsonObject = new JSONObject(response.body().string());
JSONObject error = jsonObject.optJSONObject(Constants.RESPONSE_ERROR_OBJECT_NAME);
if (error == null) {
JSONArray resultJsonArray = jsonObject.getJSONArray(Constants.RESPONSE_RESULT_OBJECT_NAME);
if(resultJsonArray.length() > 0) {
Gson gson = new GsonBuilder()
.excludeFieldsWithoutExposeAnnotation()
.registerTypeAdapter(long.class, new JsonDeserializer<Long>() {
@Override
public Long deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
long value = 0;
try {
value = json.getAsLong();
} catch (NumberFormatException e) {
CatalogueLog.d("CatalogueVariableApiManager: getUiPolicy: deserialize: long.class: NumberFormatException: ");
}
return value;
}
})
.registerTypeAdapter(int.class, new JsonDeserializer<Integer>() {
@Override
public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
int value = 0;
try {
value = json.getAsInt();
} catch (NumberFormatException e) {
CatalogueLog.d("CatalogueVariableApiManager: getUiPolicy: deserialize: int.class: NumberFormatException: ");
}
return value;
}
})
.registerTypeAdapter(float.class, new JsonDeserializer<Float>() {
@Override
public Float deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
float value = 0;
try {
value = json.getAsFloat();
} catch (NumberFormatException e) {
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: deserialize: float.class: NumberFormatException: ", e);
}
return value;
}
})
.create();
JSONArray uiPolicyJsonArray = resultJsonArray.getJSONArray(0);
List<UiPolicyItem> uiPolicyItemList = new ArrayList<>(uiPolicyJsonArray.length());
for (int i = 0; i < uiPolicyJsonArray.length(); i++) {
JSONObject UiPolicyResponseJsonObject = uiPolicyJsonArray.getJSONObject(i);
UiPolicyItem uiPolicyItem = gson.fromJson(UiPolicyResponseJsonObject.toString(), UiPolicyItem.class);
JSONArray UiPolicyActionJsonArray = UiPolicyResponseJsonObject.getJSONArray(Constants.RESPONSE_VARIABLES_UI_POLICY_ACTIONS); String accessToken = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
List<UiPolicyAction> uiPolicyActionList = new ArrayList<>(UiPolicyActionJsonArray.length()); if(accessToken.isEmpty()) {
for (int j = 0; j < UiPolicyActionJsonArray.length(); j++) {
JSONObject UiPolicyActionJsonObject = UiPolicyActionJsonArray.getJSONObject(j);
UiPolicyAction uiPolicyAction = gson.fromJson(UiPolicyActionJsonObject.toString(), UiPolicyAction.class);
uiPolicyActionList.add(uiPolicyAction);
}
uiPolicyItem.setUiPolicyActions(uiPolicyActionList);
uiPolicyItemList.add(uiPolicyItem);
}
listener.onDoneApiCall(uiPolicyItemList);
} else {
listener.onDoneApiCall(new ArrayList<UiPolicyItem>(0));
}
} else
listener.onFailApiCall(); listener.onFailApiCall();
} catch (JSONException e) { return;
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: onResponse: ", e);
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: onResponse: ", e);
listener.onFailApiCall();
}
} else {
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: IOException: ", e);
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("CatalogueVariableApiManager: getUiPolicy: NullPointerException: ", e);
listener.onFailApiCall();
}
} }
final Retrofit retrofit = RestClient.getInitializedRestAdapter(accessToken);
public static void submitVariableForm(String catalogueItemSysId, String catalogueJsonString, PostVariableFormApiListener listener) {
CatalogueLog.d("submitVariableForm: " + catalogueJsonString);
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).postCatalogueItem(catalogueItemSysId, catalogueJsonString); Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).postCatalogueItem(catalogueItemSysId, catalogueJsonString);
try { try {
//Retrofit synchronous call //Retrofit synchronous call
...@@ -284,8 +239,21 @@ public class CatalogueVariableApiManager { ...@@ -284,8 +239,21 @@ public class CatalogueVariableApiManager {
listener.onFailApiCall(); listener.onFailApiCall();
} }
} else { } else {
CatalogueLog.d("CatalogueVariableApiManager: submitVariableForm: 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...");
submitVariableForm(context, catalogueItemSysId, catalogueJsonString, listener);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
}
} else {
listener.onFailApiCall(); listener.onFailApiCall();
} }
}
} catch (IOException e) { } catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: submitVariableForm: IOException: ", e); CatalogueLog.e("CatalogueVariableApiManager: submitVariableForm: IOException: ", e);
listener.onFailApiCall(); listener.onFailApiCall();
...@@ -295,9 +263,15 @@ public class CatalogueVariableApiManager { ...@@ -295,9 +263,15 @@ public class CatalogueVariableApiManager {
} }
} }
public static void postAttachment(String contentType, String tableSysId, String attachmentName, RequestBody requestBody, PostAttachmentApiListener listener) { public static void postAttachment(Context context, String contentType, String tableSysId, String attachmentName, RequestBody requestBody, PostAttachmentApiListener listener) {
CatalogueLog.d("postAttachment: tableSysId: " + tableSysId); CatalogueLog.d("postAttachment: tableSysId: " + tableSysId);
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
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(CatalogueVariableApi.class).postAttachment(contentType, tableSysId, CatalogueVariable.Json.TABLE_NAME_VALUE, attachmentName, requestBody); Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).postAttachment(contentType, tableSysId, CatalogueVariable.Json.TABLE_NAME_VALUE, attachmentName, requestBody);
try { try {
//Retrofit synchronous call //Retrofit synchronous call
...@@ -305,8 +279,21 @@ public class CatalogueVariableApiManager { ...@@ -305,8 +279,21 @@ public class CatalogueVariableApiManager {
if (response.isSuccessful()) { if (response.isSuccessful()) {
listener.onDoneApiCall(); listener.onDoneApiCall();
} else { } else {
CatalogueLog.d("CatalogueVariableApiManager: postAttachment: 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...");
postAttachment(context, contentType, tableSysId, attachmentName, requestBody, listener);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
}
} else {
listener.onFailApiCall(); listener.onFailApiCall();
} }
}
} catch (IOException e) { } catch (IOException e) {
CatalogueLog.e("CatalogueVariableApiManager: postAttachment: IOException: ", e); CatalogueLog.e("CatalogueVariableApiManager: postAttachment: IOException: ", e);
listener.onFailApiCall(); listener.onFailApiCall();
......
package com.vsoft.uoflservicenow.api.managers; package com.vsoft.servicenow.api.managers;
import android.content.Context;
import android.util.Log;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
...@@ -6,13 +9,15 @@ import com.google.gson.JsonDeserializationContext; ...@@ -6,13 +9,15 @@ import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer; import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.vsoft.uoflservicenow.api.RestClient; import com.vsoft.servicenow.api.interfaces.IncidentApi;
import com.vsoft.uoflservicenow.api.interfaces.IncidentApi; import com.vsoft.servicenow.api.listeners.get.GetIncidentApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetIncidentApiListener; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.uoflservicenow.api.listeners.post.PostIncidentApiListener; import com.vsoft.servicenow.api.RestClient;
import com.vsoft.uoflservicenow.db.models.Incident; import com.vsoft.servicenow.api.listeners.post.PostIncidentApiListener;
import com.vsoft.uoflservicenow.utils.CatalogueLog; import com.vsoft.servicenow.db.models.Incident;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.PrefManager;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
...@@ -34,13 +39,19 @@ import retrofit2.Retrofit; ...@@ -34,13 +39,19 @@ import retrofit2.Retrofit;
*/ */
public class IncidentApiManager { public class IncidentApiManager {
public static void getIncident(GetIncidentApiListener listener) { public static void getIncident(Context context, GetIncidentApiListener listener) {
CatalogueLog.d("IncidentApiManager: getIncident: "); CatalogueLog.d("IncidentApiManager: getIncident: ");
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("caller_id=javascript:gs.getUserID()"); stringBuilder.append("caller_id=javascript:gs.getUserID()");
CatalogueLog.d("IncidentApiManager: getIncident: request parameter: "+stringBuilder.toString()); CatalogueLog.d("IncidentApiManager: getIncident: request parameter: "+stringBuilder.toString());
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD); 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(IncidentApi.class).getIncident(stringBuilder.toString(), ""); Call<ResponseBody> call = retrofit.create(IncidentApi.class).getIncident(stringBuilder.toString(), "");
try { try {
//Retrofit synchronous call //Retrofit synchronous call
...@@ -113,8 +124,21 @@ public class IncidentApiManager { ...@@ -113,8 +124,21 @@ public class IncidentApiManager {
listener.onFailApiCall(); listener.onFailApiCall();
} }
} else { } else {
CatalogueLog.d("IncidentApiManager: getIncident: 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...");
getIncident(context, listener);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
}
} else {
listener.onFailApiCall(); listener.onFailApiCall();
} }
}
} catch (IOException e) { } catch (IOException e) {
CatalogueLog.e("IncidentApiManager: getIncident: IOException: ", e); CatalogueLog.e("IncidentApiManager: getIncident: IOException: ", e);
listener.onFailApiCall(); listener.onFailApiCall();
...@@ -124,22 +148,15 @@ public class IncidentApiManager { ...@@ -124,22 +148,15 @@ public class IncidentApiManager {
} }
} }
public static void submitIncidentForm(Incident incident, String userId, PostIncidentApiListener listener) { public static void submitIncidentForm(Context context, String incidentJsonString, PostIncidentApiListener listener) {
CatalogueLog.d("submitIncidentForm: incidentJson" + incident); CatalogueLog.d("submitIncidentForm: incidentJson" + incidentJsonString);
String accessToken = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
Gson gson = new GsonBuilder() if(accessToken.isEmpty()) {
.excludeFieldsWithoutExposeAnnotation() listener.onFailApiCall();
.create(); return;
JSONObject incidentJson = incident.toJson(gson.toJson(incident));
try {
incidentJson.put(Incident.Json.OPENED_AT, userId);
incidentJson.put(Incident.Json.CALLER_ID, userId);
} catch (JSONException e) {
CatalogueLog.e(e.toString());
} }
final Retrofit retrofit = RestClient.getInitializedRestAdapter(accessToken);
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD); Call<ResponseBody> call = retrofit.create(IncidentApi.class).submitIncident(incidentJsonString);
Call<ResponseBody> call = retrofit.create(IncidentApi.class).submitIncident(incidentJson.toString());
try { try {
//Retrofit synchronous call //Retrofit synchronous call
Response<ResponseBody> response = call.execute(); Response<ResponseBody> response = call.execute();
...@@ -156,8 +173,21 @@ public class IncidentApiManager { ...@@ -156,8 +173,21 @@ public class IncidentApiManager {
e.printStackTrace(); e.printStackTrace();
} }
} else { } else {
CatalogueLog.d("IncidentApiManager: submitIncidentForm: 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...");
submitIncidentForm(context, incidentJsonString, listener);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
listener.onFailApiCall(); listener.onFailApiCall();
} }
} else {
listener.onFailApiCall();
}
}
} catch (IOException e) { } catch (IOException e) {
CatalogueLog.e("IncidentApiManager: submitIncidentForm: IOException: ", e); CatalogueLog.e("IncidentApiManager: submitIncidentForm: IOException: ", e);
listener.onFailApiCall(); listener.onFailApiCall();
......
package com.vsoft.servicenow.api.managers;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;
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.LoginApi;
import com.vsoft.servicenow.api.listeners.get.GetUserLoginApiListener;
import com.vsoft.servicenow.api.pojos.LoginApiResponse;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.PrefManager;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.lang.reflect.Type;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
/**
* Created by kvemulavada on 8/29/2016.
*/
public class LoginApiManager {
public static void submitLoginValues(String grantType, String clientId, String clientSecret, String userName, String password, GetUserLoginApiListener listener) {
final Retrofit retrofit = RestClient.getInitializedRestAdapterWithOutAuthorizationHeader();
Call<ResponseBody> call = retrofit.create(LoginApi.class).postLoginValues(grantType, clientId, clientSecret, userName, password);
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) {
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("LoginApiManager: getCatalogues: 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("LoginApiManager: submitLoginValues: 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("LoginApiManager: submitLoginValues: deserialize: float.class: NumberFormatException: ", e);
}
return value;
}
})
.create();
LoginApiResponse loginApiResponse = gson.fromJson(jsonObject.toString(), LoginApiResponse.class);
listener.onDoneApiCall(loginApiResponse);
} else
listener.onFailApiCall();
} catch (JSONException e) {
CatalogueLog.e("LoginApiManager: submitLoginValues: onResponse: ", e);
listener.onFailApiCall();
} catch (IOException e) {
CatalogueLog.e("LoginApiManager: submitLoginValues: onResponse: ", e);
listener.onFailApiCall();
}
} else {
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("LoginApiManager: submitLoginValues: IOException: ", e);
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("LoginApiManager: submitLoginValues: IOException: ", e);
listener.onFailApiCall();
}
}
public static SyncStatus refreshLogin(Context context, String refreshToken) {
CatalogueLog.d("LoginApiManager: refreshLogin");
final Retrofit retrofit = RestClient.getInitializedRestAdapterWithOutAuthorizationHeader();
Call<ResponseBody> call = retrofit.create(LoginApi.class).refreshLogin(LoginApiResponse.Json.REFRESH_TOKEN,
Constants.LOGIN_CLIENT_ID,
Constants.LOGIN_CLIENT_SECRET,
refreshToken);
try {
Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) {
try {
JSONObject jsonObject = new JSONObject(response.body().string());
CatalogueLog.d("refreshLogin: successfully refreshed login.");
PrefManager.setSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN, jsonObject.getString(LoginApiResponse.Json.JSON_ACCESS_TOKEN));
return SyncStatus.SUCCESS;
} catch(JSONException e) {
CatalogueLog.e("refreshLogin: JSONException: ", e);
return SyncStatus.FAIL;
}
} else {
CatalogueLog.d("refreshLogin: failed to refresh token...");
if(response.code() == 401) {
CatalogueLog.d("---- 401, unSetting access and refresh token, prompt user to login again");
PrefManager.setSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN, "");
PrefManager.setSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN, "");
Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT);
intent.putExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION, Constants.ACTION_PROMPT_LOGIN);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
return SyncStatus.FAIL;
}
} catch(IOException e) {
CatalogueLog.e("refreshLogin: IOException: ", e);
return SyncStatus.FAIL;
}
}
}
package com.vsoft.uoflservicenow.api.managers; package com.vsoft.servicenow.api.managers;
import android.content.Context;
import android.util.Log;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
...@@ -6,20 +9,24 @@ import com.google.gson.JsonDeserializationContext; ...@@ -6,20 +9,24 @@ import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer; import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.vsoft.uoflservicenow.api.RestClient; import com.vsoft.servicenow.db.models.MyRequest;
import com.vsoft.uoflservicenow.api.interfaces.MyRequestApi; import com.vsoft.servicenow.api.RestClient;
import com.vsoft.uoflservicenow.api.listeners.get.GetMyRequestApiListener; import com.vsoft.servicenow.api.interfaces.MyRequestApi;
import com.vsoft.uoflservicenow.db.models.MyRequest; import com.vsoft.servicenow.api.listeners.get.GetMyRequestApiListener;
import com.vsoft.uoflservicenow.enums.SyncStatus; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.PrefManager;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Response; import retrofit2.Response;
...@@ -30,12 +37,17 @@ import retrofit2.Retrofit; ...@@ -30,12 +37,17 @@ import retrofit2.Retrofit;
*/ */
public class MyRequestApiManager { public class MyRequestApiManager {
public static SyncStatus getMyrequests(GetMyRequestApiListener listener) { public static SyncStatus getMyRequests(Context context, GetMyRequestApiListener listener) {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(MyRequest.Json.URL_PARAM_CATALOGUE_SYSPRM_QUERY_VALUE); stringBuilder.append(MyRequest.Json.URL_PARAM_CATALOGUE_SYSPRM_QUERY_VALUE);
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD); String accessToken = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
if(accessToken.isEmpty()) {
listener.onFailApiCall();
return SyncStatus.FAIL;
}
final Retrofit retrofit = RestClient.getInitializedRestAdapter(accessToken);
Call<ResponseBody> call = retrofit.create(MyRequestApi.class).getMyRequest(stringBuilder.toString(), "true"); Call<ResponseBody> call = retrofit.create(MyRequestApi.class).getMyRequest(stringBuilder.toString(), "true");
try { try {
//Retrofit synchronous call //Retrofit synchronous call
...@@ -109,8 +121,23 @@ public class MyRequestApiManager { ...@@ -109,8 +121,23 @@ public class MyRequestApiManager {
return SyncStatus.FAIL; return SyncStatus.FAIL;
} }
} else { } else {
CatalogueLog.d("MyRequestApiManager: getMyRequest: 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...");
return getMyRequests(context, listener);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
listener.onFailApiCall();
return SyncStatus.FAIL; return SyncStatus.FAIL;
} }
} else {
listener.onFailApiCall();
return SyncStatus.FAIL;
}
}
} catch (IOException e) { } catch (IOException e) {
CatalogueLog.e("CatalogueApiManager: getCatalogues: IOException: ", e); CatalogueLog.e("CatalogueApiManager: getCatalogues: IOException: ", e);
return SyncStatus.FAIL; return SyncStatus.FAIL;
......
package com.vsoft.uoflservicenow.api.managers; package com.vsoft.servicenow.api.managers;
import android.content.Context;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
...@@ -6,12 +8,13 @@ import com.google.gson.JsonDeserializationContext; ...@@ -6,12 +8,13 @@ import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer; import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.vsoft.uoflservicenow.api.RestClient; import com.vsoft.servicenow.api.interfaces.UserApi;
import com.vsoft.uoflservicenow.api.interfaces.UserApi; import com.vsoft.servicenow.api.listeners.get.GetUserDetailApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetUserDetailApiListener; import com.vsoft.servicenow.api.RestClient;
import com.vsoft.uoflservicenow.db.models.UserApiValues; import com.vsoft.servicenow.db.models.UserApiValues;
import com.vsoft.uoflservicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.PrefManager;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
...@@ -31,9 +34,14 @@ import retrofit2.Retrofit; ...@@ -31,9 +34,14 @@ import retrofit2.Retrofit;
* Created by kvemulavada on 8/31/2016. * Created by kvemulavada on 8/31/2016.
*/ */
public class UserApiManager { public class UserApiManager {
public static void getUserDetailResponse(String userName, GetUserDetailApiListener listener) { public static void getUserDetailResponse(Context context, String userName, GetUserDetailApiListener listener) {
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD); 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(UserApi.class).getuserDetails(userName); Call<ResponseBody> call = retrofit.create(UserApi.class).getuserDetails(userName);
try { try {
//Retrofit synchronous call //Retrofit synchronous call
......
package com.vsoft.uoflservicenow.api.managers; package com.vsoft.servicenow.api.managers;
import android.content.Context;
import android.util.Log;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
...@@ -6,14 +9,16 @@ import com.google.gson.JsonDeserializationContext; ...@@ -6,14 +9,16 @@ import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer; import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.vsoft.uoflservicenow.api.RestClient; import com.vsoft.servicenow.api.interfaces.CatalogueVariableApi;
import com.vsoft.uoflservicenow.api.interfaces.CatalogueVariableApi; import com.vsoft.servicenow.api.listeners.get.GetReferenceApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetReferenceApiListener; import com.vsoft.servicenow.api.listeners.get.GetVariableChoiceApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetVariableChoiceApiListener; import com.vsoft.servicenow.db.models.VariableChoice;
import com.vsoft.uoflservicenow.db.models.Reference; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.uoflservicenow.db.models.VariableChoice; import com.vsoft.servicenow.api.RestClient;
import com.vsoft.uoflservicenow.utils.CatalogueLog; import com.vsoft.servicenow.db.models.Reference;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.PrefManager;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
...@@ -32,20 +37,21 @@ import retrofit2.Retrofit; ...@@ -32,20 +37,21 @@ import retrofit2.Retrofit;
/** /**
* @author Kunj on 11/8/16. * @author Kunj on 11/8/16.
* *bkunj@vscbkunj@vsc
*/ */
public class VariableChoiceApiManager { public class VariableChoiceApiManager {
public static void getVariableChoice(String variableSysId, GetVariableChoiceApiListener listener) { public static void getVariableChoice(Context context, String variableSysId, GetVariableChoiceApiListener listener) {
CatalogueLog.d("VariableChoiceApiManager: getVariableChoice: "); CatalogueLog.d("VariableChoiceApiManager: getVariableChoice: ");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(VariableChoice.Json.URL_PARAM_VARIABLE_CHOICE_SYSPRM_QUERY_VALUE);
stringBuilder.append("=");
stringBuilder.append(variableSysId);
CatalogueLog.d("VariableChoiceApiManager: getVariableChoice: request parameter: "+stringBuilder.toString());
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD); String accessToken = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).getVariableChoice(stringBuilder.toString(), "text,value,order,misc"); if(accessToken.isEmpty()) {
listener.onFailApiCall();
return;
}
final Retrofit retrofit = RestClient.getInitializedRestAdapter(accessToken);
Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).getVariableChoice(variableSysId);
try { try {
//Retrofit synchronous call //Retrofit synchronous call
Response<ResponseBody> response = call.execute(); Response<ResponseBody> response = call.execute();
...@@ -116,8 +122,21 @@ public class VariableChoiceApiManager { ...@@ -116,8 +122,21 @@ public class VariableChoiceApiManager {
listener.onFailApiCall(); listener.onFailApiCall();
} }
} else { } else {
CatalogueLog.d("VariableChoiceApiManager: getVariableChoice: 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...");
getVariableChoice(context, variableSysId, listener);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
listener.onFailApiCall(); listener.onFailApiCall();
} }
} else {
listener.onFailApiCall();
}
}
} catch (IOException e) { } catch (IOException e) {
CatalogueLog.e("VariableChoiceApiManager: getVariableChoice: IOException: ", e); CatalogueLog.e("VariableChoiceApiManager: getVariableChoice: IOException: ", e);
listener.onFailApiCall(); listener.onFailApiCall();
...@@ -127,10 +146,16 @@ public class VariableChoiceApiManager { ...@@ -127,10 +146,16 @@ public class VariableChoiceApiManager {
} }
} }
public static void getReference(String tableName, Map<String,String> queryMap, GetReferenceApiListener listener) { public static void getReference(Context context, String tableName, Map<String,String> queryMap, GetReferenceApiListener listener) {
CatalogueLog.d("VariableChoiceApiManager: getReference: tableName: "+tableName); CatalogueLog.d("VariableChoiceApiManager: getReference: tableName: "+tableName);
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD); 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(CatalogueVariableApi.class).getReference(Constants.URL_GET_REFERENCE + tableName, queryMap); Call<ResponseBody> call = retrofit.create(CatalogueVariableApi.class).getReference(Constants.URL_GET_REFERENCE + tableName, queryMap);
try { try {
//Retrofit synchronous call //Retrofit synchronous call
...@@ -202,8 +227,21 @@ public class VariableChoiceApiManager { ...@@ -202,8 +227,21 @@ public class VariableChoiceApiManager {
listener.onFailApiCall(); listener.onFailApiCall();
} }
} else { } else {
CatalogueLog.d("VariableChoiceApiManager: getReference: 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...");
getReference(context, tableName, queryMap, listener);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
listener.onFailApiCall();
}
} else {
listener.onFailApiCall(); listener.onFailApiCall();
} }
}
} catch (IOException e) { } catch (IOException e) {
CatalogueLog.e("VariableChoiceApiManager: getReference: IOException: ", e); CatalogueLog.e("VariableChoiceApiManager: getReference: IOException: ", e);
listener.onFailApiCall(); listener.onFailApiCall();
......
package com.vsoft.servicenow.api.pojos;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* Created by kunj on 14/12/2016.
*/
public class LoginApiResponse {
@SerializedName("access_token")
@Expose
private String accessToken;
@SerializedName("refresh_token")
@Expose
private String refreshToken;
@SerializedName("scope")
@Expose
private String scope;
@SerializedName("token_type")
@Expose
private String tokenType;
@SerializedName("expires_in")
@Expose
private Integer expiresIn;
public String getAccessToken() {
return accessToken;
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public String getRefreshToken() {
return refreshToken;
}
public void setRefreshToken(String refreshToken) {
this.refreshToken = refreshToken;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
public String getTokenType() {
return tokenType;
}
public void setTokenType(String tokenType) {
this.tokenType = tokenType;
}
public Integer getExpiresIn() {
return expiresIn;
}
public void setExpiresIn(Integer expiresIn) {
this.expiresIn = expiresIn;
}
public static class Json {
public static final String GRANT_TYPE = "grant_type";
public static final String CLIENT_ID = "client_id";
public static final String CLIENT_SECRET = "client_secret";
public static final String USER_NAME = "username";
public static final String PASSWORD = "password";
public static final String REFRESH_TOKEN = "refresh_token";
public static final String JSON_ACCESS_TOKEN = "access_token";
}
}
package com.vsoft.uoflservicenow.db; package com.vsoft.servicenow.db;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
...@@ -6,8 +6,8 @@ import android.database.sqlite.SQLiteDatabase; ...@@ -6,8 +6,8 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DBConstants; import com.vsoft.servicenow.utils.DBConstants;
/** /**
...@@ -33,6 +33,9 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants { ...@@ -33,6 +33,9 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
createVariableChoiceTable(db); createVariableChoiceTable(db);
createMyIncidentTable(db); createMyIncidentTable(db);
createMyRequestTable(db); createMyRequestTable(db);
createMyRequestItemTable(db);
createMyRequestOrderTable(db);
createMyRequestOpenedByTable(db);
createUiPolicyItemTable(db); createUiPolicyItemTable(db);
createUiPolicyActionTable(db); createUiPolicyActionTable(db);
createCatalogueItemInputTable(db); createCatalogueItemInputTable(db);
...@@ -117,12 +120,39 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants { ...@@ -117,12 +120,39 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
db.execSQL("create table " + TABLE_MY_REQUEST + "(" db.execSQL("create table " + TABLE_MY_REQUEST + "("
+ REQUEST_ID + " integer primary key autoincrement, " + REQUEST_ID + " integer primary key autoincrement, "
+ REQUEST_NUMBER + " text, " + REQUEST_NUMBER + " text, "
+ REQUEST_SHORT_DESCRIPTION + " text, " + REQUEST_SHORT_DESCRIPTION + " real, "
+ REQUEST_SYS_UPDATED_ON + " real, " + REQUEST_SYS_UPDATED_ON + " real, "
+ REQUEST_APPROVAL + " text, " + REQUEST_APPROVAL + " text, "
+ REQUEST_STAGE + " text, "
+ REQUEST_OPENED_BY_VALUE + " real, "
+ REQUEST_ORDER_DISPLAY_VALUE + " real, "
+ REQUEST_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");"); + REQUEST_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");");
} }
private void createMyRequestItemTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_MY_REQUEST_DESCRIPTION + "("
+ MY_REQUEST_DESCRIPTION_ID + " integer primary key autoincrement, "
+ MY_REQUEST_DESCRIPTION_DISPLAY_VALUE + " text, "
+ MY_REQUEST_DESCRIPTION_LINK + " real, "
+ MY_REQUEST_DESCRIPTION_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");");
}
private void createMyRequestOpenedByTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_MY_REQUEST_OPENED_BY + "("
+ MY_REQUEST_OPENED_BY_ID + " integer primary key autoincrement, "
+ MY_REQUEST_OPENED_BY_DISPLAY_VALUE + " text, "
+ MY_REQUEST_OPENED_BY_LINK + " real, "
+ MY_REQUEST_OPENED_BY_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");");
}
private void createMyRequestOrderTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_MY_REQUEST_DETAIL + "("
+ MY_REQUEST_ORDER_ID + " integer primary key autoincrement, "
+ MY_REQUEST_ORDER_DISPLAY_VALUE + " text, "
+ MY_REQUEST_ORDER_LINK + " real, "
+ MY_REQUEST_ORDER_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");");
}
private void createUiPolicyItemTable(SQLiteDatabase db) { private void createUiPolicyItemTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_UI_POLICY_ITEM + "(" db.execSQL("create table " + TABLE_UI_POLICY_ITEM + "("
+ UI_POLICY_ITEM_ID + " integer primary key autoincrement, " + UI_POLICY_ITEM_ID + " integer primary key autoincrement, "
......
package com.vsoft.uoflservicenow.db.managers; package com.vsoft.servicenow.db.managers;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.Attachment; import com.vsoft.servicenow.db.models.Attachment;
import com.vsoft.uoflservicenow.utils.DBConstants; import com.vsoft.servicenow.utils.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -109,13 +109,12 @@ public class AttachmentManager implements DBConstants { ...@@ -109,13 +109,12 @@ public class AttachmentManager implements DBConstants {
return attachment; return attachment;
} }
public static List<Attachment> getDirtyAttachment(long itemInputId) { public static List<Attachment> getDirtyAttachment() {
SQLiteDatabase db = CatalogueApplication.getDatabase(); SQLiteDatabase db = CatalogueApplication.getDatabase();
if(db!=null) { if(db!=null) {
Cursor c = db.rawQuery("select * from " + TABLE_ATTACHMENT Cursor c = db.rawQuery("select * from " + TABLE_ATTACHMENT
+ " where " + ATTACHMENT_ITEM_INPUT_ID + "=" + itemInputId + " where " + ATTACHMENT_SYNC_DIRTY + ">" + SYNC_FLAG_NONE , null);
+ " and " + ATTACHMENT_SYNC_DIRTY + ">" + SYNC_FLAG_NONE , null);
ArrayList<Attachment> attachmentList; ArrayList<Attachment> attachmentList;
if (c.getCount() > 0) { if (c.getCount() > 0) {
attachmentList = new ArrayList<>(c.getCount()); attachmentList = new ArrayList<>(c.getCount());
......
package com.vsoft.uoflservicenow.db.managers; package com.vsoft.servicenow.db.managers;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.CatalogueItemInput; import com.vsoft.servicenow.db.models.CatalogueItemInput;
import com.vsoft.uoflservicenow.utils.DBConstants; import com.vsoft.servicenow.utils.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -97,12 +97,12 @@ public class CatalogueItemInputManager implements DBConstants { ...@@ -97,12 +97,12 @@ public class CatalogueItemInputManager implements DBConstants {
} }
} }
public static CatalogueItemInput get(long catalogueId) { public static CatalogueItemInput get(long catalogueInputId) {
SQLiteDatabase db = CatalogueApplication.getDatabase(); SQLiteDatabase db = CatalogueApplication.getDatabase();
CatalogueItemInput catalogueItemInput = null; CatalogueItemInput catalogueItemInput = null;
if (db != null) { if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_CATALOGUE_ITEM_INPUT + " where " + CATALOGUE_ITEM_INPUT_ID + "=" + catalogueId, null); Cursor c = db.rawQuery("select * from " + TABLE_CATALOGUE_ITEM_INPUT + " where " + CATALOGUE_ITEM_INPUT_ID + "=" + catalogueInputId, null);
if (c.moveToFirst()) { if (c.moveToFirst()) {
CatalogueItemInput.CatalogueItemInputBuilder builder = CatalogueItemInput.CatalogueItemInputBuilder.aCatalogueItemInput(); CatalogueItemInput.CatalogueItemInputBuilder builder = CatalogueItemInput.CatalogueItemInputBuilder.aCatalogueItemInput();
fillAllItemInputDetails(c, builder); fillAllItemInputDetails(c, builder);
......
package com.vsoft.uoflservicenow.db.managers; package com.vsoft.servicenow.db.managers;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.CatalogueItem; import com.vsoft.servicenow.db.models.CatalogueItem;
import com.vsoft.uoflservicenow.utils.DBConstants; import com.vsoft.servicenow.utils.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
......
package com.vsoft.uoflservicenow.db.managers; package com.vsoft.servicenow.db.managers;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.Catalogue; import com.vsoft.servicenow.db.models.Catalogue;
import com.vsoft.uoflservicenow.utils.DBConstants; import com.vsoft.servicenow.utils.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
......
package com.vsoft.uoflservicenow.db.managers; package com.vsoft.servicenow.db.managers;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.CatalogueVariable; import com.vsoft.servicenow.db.models.CatalogueVariable;
import com.vsoft.uoflservicenow.enums.ViewType; import com.vsoft.servicenow.enums.ViewType;
import com.vsoft.uoflservicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.DBConstants; import com.vsoft.servicenow.utils.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -50,7 +50,6 @@ public class CatalogueVariableManager implements DBConstants { ...@@ -50,7 +50,6 @@ public class CatalogueVariableManager implements DBConstants {
} }
public static int update(CatalogueVariable catalogueVariable, List<String> column, int syncDirty) { public static int update(CatalogueVariable catalogueVariable, List<String> column, int syncDirty) {
CatalogueLog.e("CatalogueVariableManager: update");
SQLiteDatabase db = CatalogueApplication.getDatabase(); SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) { if (db != null) {
catalogueVariable.setSyncDirty(syncDirty); catalogueVariable.setSyncDirty(syncDirty);
......
package com.vsoft.uoflservicenow.db.managers; package com.vsoft.servicenow.db.managers;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.Incident; import com.vsoft.servicenow.db.models.Incident;
import com.vsoft.uoflservicenow.enums.Impact; import com.vsoft.servicenow.enums.Impact;
import com.vsoft.uoflservicenow.utils.DBConstants; import com.vsoft.servicenow.utils.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
......
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.models.MyRequestDisplayValue;
import com.vsoft.servicenow.utils.DBConstants;
import java.util.List;
/**
*
* @author Kunj on 18-11-2016.
*/
public class MyRequestDescriptionDisplayValueManager implements DBConstants {
public static long save(MyRequestDisplayValue myRequestDisplayValue, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
myRequestDisplayValue.setSyncDirty(syncDirty);
long id = db.insert(TABLE_MY_REQUEST_DESCRIPTION, null, getContentValues(myRequestDisplayValue));
myRequestDisplayValue.setId(id);
return id;
} else {
return -1;
}
}
public static int delete(MyRequestDisplayValue myRequestDisplayValue) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
return db.delete(TABLE_MY_REQUEST_DESCRIPTION, MY_REQUEST_DESCRIPTION_ID + "=" + myRequestDisplayValue.getId(), null);
}
return -1;
}
public static int update(MyRequestDisplayValue myRequestDisplayValue, int syncDirty) {
return update(myRequestDisplayValue, null, syncDirty);
}
public static int update(MyRequestDisplayValue myRequestDisplayValue, List<String> column, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
myRequestDisplayValue.setSyncDirty(syncDirty);
if (column == null || column.size() == 0) {
return db.update(TABLE_MY_REQUEST_DESCRIPTION, getContentValues(myRequestDisplayValue), MY_REQUEST_DESCRIPTION_ID + "=" +
myRequestDisplayValue.getId(), null);
} else {
ContentValues contentValues = new ContentValues(column.size());
contentValues.put(MY_REQUEST_DESCRIPTION_SYNC_DIRTY, myRequestDisplayValue.getSyncDirty());
for (int i = 0; i < column.size(); i++) {
String columnName = column.get(i);
if (MY_REQUEST_DESCRIPTION_LINK.equals(columnName)) {
contentValues.put(MY_REQUEST_DESCRIPTION_LINK, myRequestDisplayValue.getLink());
} else if (MY_REQUEST_DESCRIPTION_DISPLAY_VALUE.equals(columnName)) {
contentValues.put(MY_REQUEST_DESCRIPTION_DISPLAY_VALUE, myRequestDisplayValue.getDisplayValue());
}
}
return db.update(TABLE_MY_REQUEST_DESCRIPTION, contentValues, MY_REQUEST_DESCRIPTION_ID + "=" + myRequestDisplayValue.getId(),
null);
}
} else {
return -1;
}
}
public static void handleGetRequestItem(MyRequestDisplayValue serverMyRequestDisplayValue, long requestId) {
MyRequestDisplayValue localMyRequestDisplayValue = get(requestId);
if (localMyRequestDisplayValue != null) {
delete(localMyRequestDisplayValue);
} else {
save(serverMyRequestDisplayValue, SYNC_FLAG_NONE);
}
}
public static MyRequestDisplayValue get(long id) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
MyRequestDisplayValue myRequestDisplayValue = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_MY_REQUEST_DESCRIPTION + " where " + MY_REQUEST_DESCRIPTION_ID + "=" + id, null);
if (c.moveToFirst()) {
MyRequestDisplayValue.MyRequestDisplayValueBuilder builder = MyRequestDisplayValue.MyRequestDisplayValueBuilder.aMyRequest();
fillAllRequestItemDetails(c, builder);
myRequestDisplayValue = builder.build();
}
c.close();
}
return myRequestDisplayValue;
}
private static void fillAllRequestItemDetails(Cursor c, MyRequestDisplayValue.MyRequestDisplayValueBuilder builder) {
builder.setId(c.getLong(INDEX_MY_REQUEST_DESCRIPTION_ID));
builder.setDisplayValue(c.getString(INDEX_MY_REQUEST_DESCRIPTION_DISPLAY_VALUE));
builder.setLink(c.getString(INDEX_MY_REQUEST_DESCRIPTION_LINK));
builder.setSyncDirty(c.getInt(INDEX_MY_REQUEST_DESCRIPTION_SYNC_DIRTY));
}
private static ContentValues getContentValues(MyRequestDisplayValue myRequestDisplayValue) {
ContentValues cv = new ContentValues(MY_REQUEST_DESCRIPTION_COLUMN_COUNT - 1);
cv.put(MY_REQUEST_DESCRIPTION_DISPLAY_VALUE, myRequestDisplayValue.getDisplayValue());
cv.put(MY_REQUEST_DESCRIPTION_LINK, myRequestDisplayValue.getLink());
cv.put(MY_REQUEST_DESCRIPTION_SYNC_DIRTY, myRequestDisplayValue.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.models.MyRequestDisplayValue;
import com.vsoft.servicenow.utils.DBConstants;
import java.util.List;
/**
*
* @author Kunj on 18-11-2016.
*/
public class MyRequestOpenedByDisplayValueManager implements DBConstants {
public static long save(MyRequestDisplayValue myRequestDisplayValue, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
myRequestDisplayValue.setSyncDirty(syncDirty);
long id = db.insert(TABLE_MY_REQUEST_OPENED_BY, null, getContentValues(myRequestDisplayValue));
myRequestDisplayValue.setId(id);
return id;
} else {
return -1;
}
}
public static int delete(MyRequestDisplayValue myRequestDisplayValue) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
return db.delete(TABLE_MY_REQUEST_OPENED_BY, MY_REQUEST_OPENED_BY_ID + "=" + myRequestDisplayValue.getId(), null);
}
return -1;
}
public static int update(MyRequestDisplayValue myRequestDisplayValue, int syncDirty) {
return update(myRequestDisplayValue, null, syncDirty);
}
public static int update(MyRequestDisplayValue myRequestDisplayValue, List<String> column, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
myRequestDisplayValue.setSyncDirty(syncDirty);
if (column == null || column.size() == 0) {
return db.update(TABLE_MY_REQUEST_OPENED_BY, getContentValues(myRequestDisplayValue), MY_REQUEST_OPENED_BY_ID + "=" +
myRequestDisplayValue.getId(), null);
} else {
ContentValues contentValues = new ContentValues(column.size());
contentValues.put(MY_REQUEST_OPENED_BY_SYNC_DIRTY, myRequestDisplayValue.getSyncDirty());
for (int i = 0; i < column.size(); i++) {
String columnName = column.get(i);
if (MY_REQUEST_OPENED_BY_LINK.equals(columnName)) {
contentValues.put(MY_REQUEST_OPENED_BY_LINK, myRequestDisplayValue.getLink());
} else if (MY_REQUEST_OPENED_BY_DISPLAY_VALUE.equals(columnName)) {
contentValues.put(MY_REQUEST_OPENED_BY_DISPLAY_VALUE, myRequestDisplayValue.getDisplayValue());
}
}
return db.update(TABLE_MY_REQUEST_OPENED_BY, contentValues, MY_REQUEST_OPENED_BY_ID + "=" + myRequestDisplayValue.getId(),
null);
}
} else {
return -1;
}
}
public static void handleGetRequestItem(MyRequestDisplayValue serverMyRequestDisplayValue, long requestId) {
MyRequestDisplayValue localMyRequestDisplayValue = get(requestId);
if (localMyRequestDisplayValue != null) {
delete(localMyRequestDisplayValue);
} else {
save(serverMyRequestDisplayValue, SYNC_FLAG_NONE);
}
}
public static MyRequestDisplayValue get(long uiPolicyActionId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
MyRequestDisplayValue myRequestDisplayValue = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_MY_REQUEST_OPENED_BY + " where " + MY_REQUEST_OPENED_BY_ID + "=" + uiPolicyActionId, null);
if (c.moveToFirst()) {
MyRequestDisplayValue.MyRequestDisplayValueBuilder builder = MyRequestDisplayValue.MyRequestDisplayValueBuilder.aMyRequest();
fillAllRequestItemDetails(c, builder);
myRequestDisplayValue = builder.build();
}
c.close();
}
return myRequestDisplayValue;
}
private static void fillAllRequestItemDetails(Cursor c, MyRequestDisplayValue.MyRequestDisplayValueBuilder builder) {
builder.setId(c.getLong(INDEX_MY_REQUEST_OPENED_BY_ID));
builder.setDisplayValue(c.getString(INDEX_MY_REQUEST_OPENED_BY_DISPLAY_VALUE));
builder.setLink(c.getString(INDEX_MY_REQUEST_OPENED_BY_LINK));
builder.setSyncDirty(c.getInt(INDEX_MY_REQUEST_OPENED_BY_SYNC_DIRTY));
}
private static ContentValues getContentValues(MyRequestDisplayValue myRequestDisplayValue) {
ContentValues cv = new ContentValues(MY_REQUEST_OPENED_BY_COLUMN_COUNT - 1);
cv.put(MY_REQUEST_OPENED_BY_DISPLAY_VALUE, myRequestDisplayValue.getDisplayValue());
cv.put(MY_REQUEST_OPENED_BY_LINK, myRequestDisplayValue.getLink());
cv.put(MY_REQUEST_OPENED_BY_SYNC_DIRTY, myRequestDisplayValue.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.models.MyRequestDisplayValue;
import com.vsoft.servicenow.utils.DBConstants;
import java.util.List;
/**
*
* @author Kunj on 18-11-2016.
*/
public class MyRequestOrderDisplayValueManager implements DBConstants {
public static long save(MyRequestDisplayValue myRequestDisplayValue, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
myRequestDisplayValue.setSyncDirty(syncDirty);
long id = db.insert(TABLE_MY_REQUEST_DETAIL, null, getContentValues(myRequestDisplayValue));
myRequestDisplayValue.setId(id);
return id;
} else {
return -1;
}
}
public static int delete(MyRequestDisplayValue myRequestDisplayValue) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
return db.delete(TABLE_MY_REQUEST_DETAIL, MY_REQUEST_ORDER_ID + "=" + myRequestDisplayValue.getId(), null);
}
return -1;
}
public static int update(MyRequestDisplayValue myRequestDisplayValue, int syncDirty) {
return update(myRequestDisplayValue, null, syncDirty);
}
public static int update(MyRequestDisplayValue myRequestDisplayValue, List<String> column, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
myRequestDisplayValue.setSyncDirty(syncDirty);
if (column == null || column.size() == 0) {
return db.update(TABLE_MY_REQUEST_DETAIL, getContentValues(myRequestDisplayValue), MY_REQUEST_ORDER_ID + "=" +
myRequestDisplayValue.getId(), null);
} else {
ContentValues contentValues = new ContentValues(column.size());
contentValues.put(MY_REQUEST_ORDER_SYNC_DIRTY, myRequestDisplayValue.getSyncDirty());
for (int i = 0; i < column.size(); i++) {
String columnName = column.get(i);
if (MY_REQUEST_ORDER_LINK.equals(columnName)) {
contentValues.put(MY_REQUEST_ORDER_LINK, myRequestDisplayValue.getLink());
} else if (MY_REQUEST_ORDER_DISPLAY_VALUE.equals(columnName)) {
contentValues.put(MY_REQUEST_ORDER_DISPLAY_VALUE, myRequestDisplayValue.getDisplayValue());
}
}
return db.update(TABLE_MY_REQUEST_DETAIL, contentValues, MY_REQUEST_ORDER_ID + "=" + myRequestDisplayValue.getId(),
null);
}
} else {
return -1;
}
}
public static void handleGetRequestItem(MyRequestDisplayValue serverMyRequestDisplayValue, long requestId) {
MyRequestDisplayValue localMyRequestDisplayValue = get(requestId);
if (localMyRequestDisplayValue != null) {
delete(localMyRequestDisplayValue);
} else {
save(serverMyRequestDisplayValue, SYNC_FLAG_NONE);
}
}
public static MyRequestDisplayValue get(long uiPolicyActionId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
MyRequestDisplayValue myRequestDisplayValue = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_MY_REQUEST_DETAIL + " where " + MY_REQUEST_ORDER_ID + "=" + uiPolicyActionId, null);
if (c.moveToFirst()) {
MyRequestDisplayValue.MyRequestDisplayValueBuilder builder = MyRequestDisplayValue.MyRequestDisplayValueBuilder.aMyRequest();
fillAllRequestOrderDetails(c, builder);
myRequestDisplayValue = builder.build();
}
c.close();
}
return myRequestDisplayValue;
}
private static void fillAllRequestOrderDetails(Cursor c, MyRequestDisplayValue.MyRequestDisplayValueBuilder builder) {
builder.setId(c.getLong(INDEX_MY_REQUEST_ORDER_ID));
builder.setDisplayValue(c.getString(INDEX_MY_REQUEST_ORDER_DISPLAY_VALUE));
builder.setLink(c.getString(INDEX_MY_REQUEST_ORDER_LINK));
builder.setSyncDirty(c.getInt(INDEX_MY_REQUEST_ORDER_SYNC_DIRTY));
}
private static ContentValues getContentValues(MyRequestDisplayValue myRequestDisplayValue) {
ContentValues cv = new ContentValues(MY_REQUEST_ORDER_COLUMN_COUNT - 1);
cv.put(MY_REQUEST_ORDER_DISPLAY_VALUE, myRequestDisplayValue.getDisplayValue());
cv.put(MY_REQUEST_ORDER_LINK, myRequestDisplayValue.getLink());
cv.put(MY_REQUEST_ORDER_SYNC_DIRTY, myRequestDisplayValue.getSyncDirty());
return cv;
}
}
\ No newline at end of file
package com.vsoft.uoflservicenow.db.managers; package com.vsoft.servicenow.db.managers;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.MyRequest; import com.vsoft.servicenow.db.models.MyRequest;
import com.vsoft.uoflservicenow.db.models.MyRequestShortDes; import com.vsoft.servicenow.db.models.MyRequestDisplayValue;
import com.vsoft.uoflservicenow.utils.DBConstants; import com.vsoft.servicenow.utils.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -66,6 +66,12 @@ public class MyRequestsManager implements DBConstants { ...@@ -66,6 +66,12 @@ public class MyRequestsManager implements DBConstants {
contentValues.put(REQUEST_SYS_UPDATED_ON, myRequest.getUpdateOn()); contentValues.put(REQUEST_SYS_UPDATED_ON, myRequest.getUpdateOn());
} else if (REQUEST_APPROVAL.equals(columnName)) { } else if (REQUEST_APPROVAL.equals(columnName)) {
contentValues.put(REQUEST_APPROVAL, myRequest.getApproval()); contentValues.put(REQUEST_APPROVAL, myRequest.getApproval());
} else if (REQUEST_STAGE.equals(columnName)) {
contentValues.put(REQUEST_STAGE, myRequest.getStage());
} else if (REQUEST_OPENED_BY_VALUE.equals(columnName)) {
contentValues.put(REQUEST_OPENED_BY_VALUE, myRequest.getRequest().getDisplayValue());
} else if (REQUEST_ORDER_DISPLAY_VALUE.equals(columnName)) {
contentValues.put(REQUEST_ORDER_DISPLAY_VALUE, myRequest.getOpenedBy().getDisplayValue());
} }
} }
return db.update(TABLE_MY_REQUEST, contentValues, REQUEST_ID + "=" + myRequest.getId(), null); return db.update(TABLE_MY_REQUEST, contentValues, REQUEST_ID + "=" + myRequest.getId(), null);
...@@ -97,6 +103,9 @@ public class MyRequestsManager implements DBConstants { ...@@ -97,6 +103,9 @@ public class MyRequestsManager implements DBConstants {
&& !requestSysIdMap.containsKey(localRequestNumber)) { && !requestSysIdMap.containsKey(localRequestNumber)) {
//Update sys_id with empty string because required to delete locally //Update sys_id with empty string because required to delete locally
localRequest.setNumber(""); localRequest.setNumber("");
MyRequestOrderDisplayValueManager.delete(localRequest.getRequest());
MyRequestOpenedByDisplayValueManager.delete(localRequest.getOpenedBy());
MyRequestDescriptionDisplayValueManager.delete(localRequest.getShortDescription());
delete(localRequest); delete(localRequest);
} }
} }
...@@ -111,10 +120,20 @@ public class MyRequestsManager implements DBConstants { ...@@ -111,10 +120,20 @@ public class MyRequestsManager implements DBConstants {
MyRequest localRequest = getRequestFromNumber(myRequest.getNumber()); MyRequest localRequest = getRequestFromNumber(myRequest.getNumber());
if (localRequest == null) { if (localRequest == null) {
MyRequestOrderDisplayValueManager
.save(myRequest.getRequest(), DBConstants.SYNC_FLAG_NONE);
MyRequestOpenedByDisplayValueManager
.save(myRequest.getOpenedBy(), DBConstants.SYNC_FLAG_NONE);
MyRequestDescriptionDisplayValueManager
.save(myRequest.getShortDescription(), DBConstants.SYNC_FLAG_NONE);
save(myRequest, DBConstants.SYNC_FLAG_NONE); save(myRequest, DBConstants.SYNC_FLAG_NONE);
} else { } else {
/*Update complete local MyRequest object with response MyRequest object*/ /*Update complete local MyRequest object with response MyRequest object*/
myRequest.setId(localRequest.getId()); myRequest.setId(localRequest.getId());
myRequest.setRequest(localRequest.getRequest());
myRequest.setShortDescription(localRequest.getShortDescription());
myRequest.setOpenedBy(localRequest.getOpenedBy());
update(myRequest, DBConstants.SYNC_FLAG_NONE); update(myRequest, DBConstants.SYNC_FLAG_NONE);
} }
} }
...@@ -131,6 +150,9 @@ public class MyRequestsManager implements DBConstants { ...@@ -131,6 +150,9 @@ public class MyRequestsManager implements DBConstants {
&& !localIncidentNumber.isEmpty()) { && !localIncidentNumber.isEmpty()) {
//Update number with empty string because required to delete locally //Update number with empty string because required to delete locally
localMyRequest.setNumber(""); localMyRequest.setNumber("");
MyRequestOrderDisplayValueManager.delete(localMyRequest.getRequest());
MyRequestOpenedByDisplayValueManager.delete(localMyRequest.getOpenedBy());
MyRequestDescriptionDisplayValueManager.delete(localMyRequest.getShortDescription());
delete(localMyRequest); delete(localMyRequest);
} }
} }
...@@ -195,22 +217,53 @@ public class MyRequestsManager implements DBConstants { ...@@ -195,22 +217,53 @@ public class MyRequestsManager implements DBConstants {
} }
private static void fillAllRequestDetails(Cursor c, MyRequest.MyRequestBuilder builder) { private static void fillAllRequestDetails(Cursor c, MyRequest.MyRequestBuilder builder) {
MyRequestShortDes myRequestShortDes = new MyRequestShortDes();
myRequestShortDes.setDisplayValue(c.getString(INDEX_REQUEST_SHORT_DESCRIPTION));
builder.setId(c.getLong(INDEX_REQUEST_ID)); builder.setId(c.getLong(INDEX_REQUEST_ID));
builder.setNumber(c.getString(INDEX_REQUEST_NUMBER)); builder.setNumber(c.getString(INDEX_REQUEST_NUMBER));
builder.setShortDescription(myRequestShortDes);
long rowId = c.getLong(INDEX_REQUEST_SHORT_DESCRIPTION);
MyRequestDisplayValue myRequestDisplayValue;
if(rowId == -1) {
myRequestDisplayValue = new MyRequestDisplayValue();
} else {
myRequestDisplayValue =
MyRequestDescriptionDisplayValueManager.get(rowId);
}
builder.setShortDescription(myRequestDisplayValue);
rowId = c.getLong(INDEX_REQUEST_OPENED_BY_VALUE);
if(rowId == -1) {
myRequestDisplayValue = new MyRequestDisplayValue();
} else {
myRequestDisplayValue =
MyRequestOpenedByDisplayValueManager.get(rowId);
}
builder.setOpenedBy(myRequestDisplayValue);
rowId = c.getLong(INDEX_REQUEST_ORDER_DISPLAY_VALUE);
if(rowId == -1) {
myRequestDisplayValue = new MyRequestDisplayValue();
} else {
myRequestDisplayValue =
MyRequestOrderDisplayValueManager.get(rowId);
}
builder.setRequest(myRequestDisplayValue);
builder.setUpdateOn(c.getLong(INDEX_REQUEST_SYS_UPDATED_ON)); builder.setUpdateOn(c.getLong(INDEX_REQUEST_SYS_UPDATED_ON));
builder.setApproval(c.getString(INDEX_REQUEST_APPROVAL)); builder.setApproval(c.getString(INDEX_REQUEST_APPROVAL));
builder.setStage(c.getString(INDEX_REQUEST_STAGE));
builder.setSyncDirty(c.getInt(INDEX_REQUEST_SYNC_DIRTY)); builder.setSyncDirty(c.getInt(INDEX_REQUEST_SYNC_DIRTY));
} }
private static ContentValues getContentValues(MyRequest myRequest) { private static ContentValues getContentValues(MyRequest myRequest) {
ContentValues cv = new ContentValues(REQUEST_COLUMN_COUNT - 1); ContentValues cv = new ContentValues(REQUEST_COLUMN_COUNT - 1);
cv.put(REQUEST_NUMBER, myRequest.getNumber()); cv.put(REQUEST_NUMBER, myRequest.getNumber());
cv.put(REQUEST_SHORT_DESCRIPTION, myRequest.getShortDescription().getDisplayValue()); cv.put(REQUEST_SHORT_DESCRIPTION, myRequest
.getShortDescription().getId());
cv.put(REQUEST_SYS_UPDATED_ON, myRequest.getUpdateOn()); cv.put(REQUEST_SYS_UPDATED_ON, myRequest.getUpdateOn());
cv.put(REQUEST_APPROVAL, myRequest.getApproval()); cv.put(REQUEST_APPROVAL, myRequest.getApproval());
cv.put(REQUEST_STAGE, myRequest.getStage());
cv.put(REQUEST_OPENED_BY_VALUE, myRequest.getRequest().getId());
cv.put(REQUEST_ORDER_DISPLAY_VALUE, myRequest.getOpenedBy().getId());
cv.put(REQUEST_SYNC_DIRTY, myRequest.getSyncDirty()); cv.put(REQUEST_SYNC_DIRTY, myRequest.getSyncDirty());
return cv; return cv;
} }
......
package com.vsoft.uoflservicenow.db.managers; package com.vsoft.servicenow.db.managers;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.Incident; import com.vsoft.servicenow.db.models.Incident;
import com.vsoft.uoflservicenow.enums.Impact; import com.vsoft.servicenow.enums.Impact;
import com.vsoft.uoflservicenow.utils.DBConstants; import com.vsoft.servicenow.utils.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
package com.vsoft.uoflservicenow.db.managers; package com.vsoft.servicenow.db.managers;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.UiPolicyAction; import com.vsoft.servicenow.db.models.UiPolicyAction;
import com.vsoft.uoflservicenow.utils.DBConstants; import com.vsoft.servicenow.utils.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
package com.vsoft.uoflservicenow.db.managers; package com.vsoft.servicenow.db.managers;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.UiPolicyItem; import com.vsoft.servicenow.db.models.UiPolicyItem;
import com.vsoft.uoflservicenow.utils.DBConstants; import com.vsoft.servicenow.utils.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
......
package com.vsoft.uoflservicenow.api.managers; package com.vsoft.servicenow.db.managers;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.db.models.VariableChoice; import com.vsoft.servicenow.db.models.VariableChoice;
import com.vsoft.uoflservicenow.utils.DBConstants; import com.vsoft.servicenow.utils.DBConstants;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* @author Kunj on 11-08-2016. * Created by kunj on 21/02/17.
*/ */
public class VariableChoiceManager implements DBConstants { public class VariableChoiceManager implements DBConstants {
public static long save(VariableChoice variableChoice) { public static long save(VariableChoice variableChoice) {
......
package com.vsoft.uoflservicenow.db.models; package com.vsoft.servicenow.db.models;
/** /**
* Created by Kunj on 11/8/16. * Created by Kunj on 11/8/16.
......
package com.vsoft.uoflservicenow.db.models; package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
...@@ -21,6 +21,9 @@ public class Catalogue { ...@@ -21,6 +21,9 @@ public class Catalogue {
@SerializedName("homepage_image") @SerializedName("homepage_image")
@Expose @Expose
private String icon; private String icon;
@SerializedName("order")
@Expose
private long order;
private int syncDirty; private int syncDirty;
public long getId() { public long getId() {
...@@ -103,6 +106,24 @@ public class Catalogue { ...@@ -103,6 +106,24 @@ public class Catalogue {
this.icon = icon; this.icon = icon;
} }
/**
*
* @param order
* The order
*/
public void setOrder(long order) {
this.order = order;
}
/**
*
* @return
* The order
*/
public long getOrder() {
return order;
}
public int getSyncDirty() { public int getSyncDirty() {
return syncDirty; return syncDirty;
} }
...@@ -178,13 +199,12 @@ public class Catalogue { ...@@ -178,13 +199,12 @@ public class Catalogue {
@Override @Override
public String toString() { public String toString() {
return "Catalogue{" + return "Catalogue{"
"id=" + id + + "title='" + title + '\''
", title='" + title + '\'' + + ", description='" + description + '\''
", description='" + description + '\'' + + ", sysId='" + sysId + '\''
", sysId='" + sysId + '\'' + + ", icon='" + icon + '\''
", icon='" + icon + '\'' + + ", order=" + order
", syncDirty=" + syncDirty + + '}';
'}';
} }
} }
package com.vsoft.uoflservicenow.db.models; package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
......
package com.vsoft.uoflservicenow.db.models; package com.vsoft.servicenow.db.models;
/** /**
* Created by Kunj on 11/8/16. * Created by Kunj on 11/8/16.
......
package com.vsoft.uoflservicenow.db.models; package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
......
package com.vsoft.uoflservicenow.db.models; package com.vsoft.servicenow.db.models;
import android.content.Context; import android.content.Context;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.R;
import com.vsoft.uoflservicenow.enums.ViewType; import com.vsoft.servicenow.enums.ViewType;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -51,6 +51,9 @@ public class CatalogueVariable { ...@@ -51,6 +51,9 @@ public class CatalogueVariable {
@SerializedName("default_value") @SerializedName("default_value")
@Expose @Expose
private String defaultValue; private String defaultValue;
@SerializedName("question_choice")
@Expose
private List<VariableChoice> questionChoice = null;
// @SerializedName("type") // @SerializedName("type")
// @Expose // @Expose
...@@ -74,7 +77,6 @@ public class CatalogueVariable { ...@@ -74,7 +77,6 @@ public class CatalogueVariable {
public void setCatalogueItemId(long catalogue_item_id) { public void setCatalogueItemId(long catalogue_item_id) {
this.catalogue_item_id = catalogue_item_id; this.catalogue_item_id = catalogue_item_id;
} }
/** /**
* *
* @return * @return
...@@ -216,20 +218,20 @@ public class CatalogueVariable { ...@@ -216,20 +218,20 @@ public class CatalogueVariable {
} }
public List<VariableChoice> getVariableChoiceList() { public List<VariableChoice> getVariableChoiceList() {
return mVariableChoiceList; return questionChoice;
} }
public void setVariableChoiceList(List<VariableChoice> mVariableChoiceList) { public void setVariableChoiceList(List<VariableChoice> mVariableChoiceList) {
this.mVariableChoiceList = mVariableChoiceList; this.questionChoice = mVariableChoiceList;
} }
public String[] getDisplayChoiceText(Context context) { public String[] getDisplayChoiceText(Context context) {
String[] choiceText; String[] choiceText;
if(defaultValue!=null) { if(defaultValue!=null) {
choiceText = new String[mVariableChoiceList.size() + 1]; choiceText = new String[questionChoice.size() + 1];
choiceText[0] = defaultValue; choiceText[0] = defaultValue;
for (int i = 0; i < mVariableChoiceList.size(); i++) { for (int i = 0; i < questionChoice.size(); i++) {
VariableChoice variableChoice = mVariableChoiceList.get(i); VariableChoice variableChoice = questionChoice.get(i);
/*(i+1) for add None text as a first Element*/ /*(i+1) for add None text as a first Element*/
if(variableChoice.getMisc() > 0) { if(variableChoice.getMisc() > 0) {
choiceText[i + 1] = String.format(context.getString(R.string.variable_form_misc_info_string), choiceText[i + 1] = String.format(context.getString(R.string.variable_form_misc_info_string),
...@@ -240,10 +242,10 @@ public class CatalogueVariable { ...@@ -240,10 +242,10 @@ public class CatalogueVariable {
} }
} }
} else if(isNoneRequired) { } else if(isNoneRequired) {
choiceText = new String[mVariableChoiceList.size() + 1]; choiceText = new String[questionChoice.size() + 1];
choiceText[0] = context.getString(R.string.none_string); choiceText[0] = context.getString(R.string.none_string);
for (int i = 0; i < mVariableChoiceList.size(); i++) { for (int i = 0; i < questionChoice.size(); i++) {
VariableChoice variableChoice = mVariableChoiceList.get(i); VariableChoice variableChoice = questionChoice.get(i);
/*(i+1) for add None text as a first Element*/ /*(i+1) for add None text as a first Element*/
if(variableChoice.getMisc() > 0) { if(variableChoice.getMisc() > 0) {
choiceText[i + 1] = String.format(context.getString(R.string.variable_form_misc_info_string), choiceText[i + 1] = String.format(context.getString(R.string.variable_form_misc_info_string),
...@@ -254,9 +256,9 @@ public class CatalogueVariable { ...@@ -254,9 +256,9 @@ public class CatalogueVariable {
} }
} }
} else { } else {
choiceText = new String[mVariableChoiceList.size()]; choiceText = new String[questionChoice.size()];
for (int i = 0; i < mVariableChoiceList.size(); i++) { for (int i = 0; i < questionChoice.size(); i++) {
VariableChoice variableChoice = mVariableChoiceList.get(i); VariableChoice variableChoice = questionChoice.get(i);
if(variableChoice.getMisc() > 0) { if(variableChoice.getMisc() > 0) {
choiceText[i] = String.format(context.getString(R.string.variable_form_misc_info_string), choiceText[i] = String.format(context.getString(R.string.variable_form_misc_info_string),
variableChoice.getText(), variableChoice.getText(),
...@@ -270,8 +272,8 @@ public class CatalogueVariable { ...@@ -270,8 +272,8 @@ public class CatalogueVariable {
} }
public String getDisplayChoiceText(String text) { public String getDisplayChoiceText(String text) {
for (int i = 0; i < mVariableChoiceList.size(); i++) { for (int i = 0; i < questionChoice.size(); i++) {
VariableChoice variableChoice = mVariableChoiceList.get(i); VariableChoice variableChoice = questionChoice.get(i);
if(variableChoice.getText().equals(text)) { if(variableChoice.getText().equals(text)) {
return variableChoice.getValue(); return variableChoice.getValue();
} }
...@@ -436,8 +438,7 @@ public class CatalogueVariable { ...@@ -436,8 +438,7 @@ public class CatalogueVariable {
", active=" + active + ", active=" + active +
", defaultValue='" + defaultValue + '\'' + ", defaultValue='" + defaultValue + '\'' +
", type=" + type + ", type=" + type +
", syncDirty=" + syncDirty + ", mVariableChoiceList=" + questionChoice +
", mVariableChoiceList=" + mVariableChoiceList +
'}'; '}';
} }
} }
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 CatalogueVariableResponse {
@SerializedName("variables")
@Expose
private List<CatalogueVariable> variables = null;
@SerializedName("ui_policy")
@Expose
private List<UiPolicyItem> uiPolicy = null;
@SerializedName("variablesets")
@Expose
private List<CatalogueVariableSet> variablesets = null;
public List<CatalogueVariable> getVariables() {
return variables;
}
public void setVariables(List<CatalogueVariable> variables) {
this.variables = variables;
}
public List<UiPolicyItem> getUiPolicy() {
return uiPolicy;
}
public void setUiPolicy(List<UiPolicyItem> uiPolicy) {
this.uiPolicy = uiPolicy;
}
public List<CatalogueVariableSet> getVariablesets() {
return variablesets;
}
public void setVariablesets(List<CatalogueVariableSet> variablesets) {
this.variablesets = variablesets;
}
}
package com.vsoft.uoflservicenow.db.models; package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
......
package com.vsoft.uoflservicenow.db.models; package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.vsoft.uoflservicenow.enums.Impact; import com.vsoft.servicenow.utils.Util;
import com.vsoft.uoflservicenow.utils.Util; import com.vsoft.servicenow.enums.Impact;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
......
package com.vsoft.uoflservicenow.db.models; package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.vsoft.uoflservicenow.utils.Util; import com.vsoft.servicenow.utils.Util;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -25,13 +25,13 @@ public class MyRequest { ...@@ -25,13 +25,13 @@ public class MyRequest {
String approval; String approval;
@SerializedName("cat_item") @SerializedName("cat_item")
@Expose @Expose
MyRequestShortDes shortDescription; MyRequestDisplayValue shortDescription;
@SerializedName("request") @SerializedName("request")
@Expose @Expose
MyRequestRequest request; MyRequestDisplayValue request;
@SerializedName("opened_by") @SerializedName("opened_by")
@Expose @Expose
MyRequestRequest openedBy; MyRequestDisplayValue openedBy;
@SerializedName("stage") @SerializedName("stage")
@Expose @Expose
String stage; String stage;
...@@ -61,14 +61,6 @@ public class MyRequest { ...@@ -61,14 +61,6 @@ public class MyRequest {
this.updateOn = updateOn; this.updateOn = updateOn;
} }
public MyRequestShortDes getShortDescription() {
return shortDescription;
}
public void setShortDescription(MyRequestShortDes shortDescription) {
this.shortDescription = shortDescription;
}
public String getApproval() { public String getApproval() {
return approval; return approval;
} }
...@@ -77,19 +69,27 @@ public class MyRequest { ...@@ -77,19 +69,27 @@ public class MyRequest {
this.approval = approval; this.approval = approval;
} }
public MyRequestRequest getRequest() { public MyRequestDisplayValue getShortDescription() {
return shortDescription;
}
public void setShortDescription(MyRequestDisplayValue shortDescription) {
this.shortDescription = shortDescription;
}
public MyRequestDisplayValue getRequest() {
return request; return request;
} }
public void setRequest(MyRequestRequest request) { public void setRequest(MyRequestDisplayValue request) {
this.request = request; this.request = request;
} }
public MyRequestRequest getOpenedBy() { public MyRequestDisplayValue getOpenedBy() {
return openedBy; return openedBy;
} }
public void setOpenedBy(MyRequestRequest openedBy) { public void setOpenedBy(MyRequestDisplayValue openedBy) {
this.openedBy = openedBy; this.openedBy = openedBy;
} }
...@@ -121,11 +121,14 @@ public class MyRequest { ...@@ -121,11 +121,14 @@ public class MyRequest {
} }
public static final class MyRequestBuilder { public static final class MyRequestBuilder {
String approval;
private long id = -1; private long id = -1;
private String number; private String number;
private long updateOn; private long updateOn;
private MyRequestShortDes shortDescription; private String approval;
private String stage;
private MyRequestDisplayValue request;
private MyRequestDisplayValue requestOpenedBy;
private MyRequestDisplayValue shortDescription;
private int syncDirty; private int syncDirty;
private MyRequestBuilder() { private MyRequestBuilder() {
...@@ -150,7 +153,7 @@ public class MyRequest { ...@@ -150,7 +153,7 @@ public class MyRequest {
return this; return this;
} }
public MyRequestBuilder setShortDescription(MyRequestShortDes shortDescription) { public MyRequestBuilder setShortDescription(MyRequestDisplayValue shortDescription) {
this.shortDescription = shortDescription; this.shortDescription = shortDescription;
return this; return this;
} }
...@@ -160,13 +163,31 @@ public class MyRequest { ...@@ -160,13 +163,31 @@ public class MyRequest {
return this; return this;
} }
public MyRequestBuilder setStage(String stage) {
this.stage = stage;
return this;
}
public MyRequestBuilder setRequest(MyRequestDisplayValue request) {
this.request = request;
return this;
}
public MyRequestBuilder setOpenedBy(MyRequestDisplayValue requestOpenedBy) {
this.requestOpenedBy = requestOpenedBy;
return this;
}
public MyRequestBuilder setSyncDirty(int syncDirty) { public MyRequestBuilder setSyncDirty(int syncDirty) {
this.syncDirty = syncDirty; this.syncDirty = syncDirty;
return this; return this;
} }
public MyRequestBuilder but() { public MyRequestBuilder but() {
return aMyRequest().setId(id).setNumber(number).setUpdateOn(updateOn).setShortDescription(shortDescription).setApproval(approval).setSyncDirty(syncDirty); return aMyRequest().setId(id).setNumber(number).setUpdateOn(updateOn)
.setShortDescription(shortDescription).setApproval(approval)
.setStage(stage).setRequest(request)
.setOpenedBy(requestOpenedBy).setSyncDirty(syncDirty);
} }
public MyRequest build() { public MyRequest build() {
...@@ -176,6 +197,9 @@ public class MyRequest { ...@@ -176,6 +197,9 @@ public class MyRequest {
myRequest.setUpdateOn(updateOn); myRequest.setUpdateOn(updateOn);
myRequest.setShortDescription(shortDescription); myRequest.setShortDescription(shortDescription);
myRequest.setApproval(approval); myRequest.setApproval(approval);
myRequest.setStage(approval);
myRequest.setRequest(request);
myRequest.setOpenedBy(requestOpenedBy);
myRequest.setSyncDirty(syncDirty); myRequest.setSyncDirty(syncDirty);
return myRequest; return myRequest;
} }
......
package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* Created by kvemulavada on 8/30/2016.
*/
public class MyRequestDisplayValue {
private long id = -1;
@SerializedName("display_value")
@Expose
private String displayValue;
@SerializedName("link")
@Expose
private String link;
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 String getDisplayValue() {
return displayValue;
}
public void setDisplayValue(String displayValue) {
this.displayValue = displayValue;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public static final class MyRequestDisplayValueBuilder {
private long id = -1;
private String link;
private String displayValue;
private int syncDirty;
private MyRequestDisplayValueBuilder() {
}
public static MyRequestDisplayValueBuilder aMyRequest() {
return new MyRequestDisplayValueBuilder();
}
public MyRequestDisplayValueBuilder setId(long id) {
this.id = id;
return this;
}
public MyRequestDisplayValueBuilder setDisplayValue(String displayValue) {
this.displayValue = displayValue;
return this;
}
public MyRequestDisplayValueBuilder setLink(String link) {
this.link = link;
return this;
}
public MyRequestDisplayValueBuilder setSyncDirty(int syncDirty) {
this.syncDirty = syncDirty;
return this;
}
public MyRequestDisplayValueBuilder but() {
return aMyRequest().setId(id).setDisplayValue(displayValue)
.setLink(link).setSyncDirty(syncDirty);
}
public MyRequestDisplayValue build() {
MyRequestDisplayValue myRequestDisplayValue = new MyRequestDisplayValue();
myRequestDisplayValue.setId(id);
myRequestDisplayValue.setLink(link);
myRequestDisplayValue.setDisplayValue(displayValue);
myRequestDisplayValue.setSyncDirty(syncDirty);
return myRequestDisplayValue;
}
}
}
package com.vsoft.uoflservicenow.db.models; package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
......
package com.vsoft.uoflservicenow.db.models; package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
......
package com.vsoft.uoflservicenow.db.models; package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.vsoft.uoflservicenow.utils.PartialCondition; import com.vsoft.servicenow.utils.PartialCondition;
import java.util.List; import java.util.List;
...@@ -14,14 +14,20 @@ public class UiPolicyItem { ...@@ -14,14 +14,20 @@ public class UiPolicyItem {
private long id = -1; private long id = -1;
private long catalogueItemId = -1; private long catalogueItemId = -1;
private List<UiPolicyAction> uiPolicyActions;
private List<PartialCondition> partialConditions; private List<PartialCondition> partialConditions;
@SerializedName("condition") @SerializedName("condition")
@Expose @Expose
private String condition; private String condition;
@SerializedName("sys_id") @SerializedName("sys_id")
@Expose @Expose
private String sysId; private String sysId;
@SerializedName("ui_policy_actions")
@Expose
private List<UiPolicyAction> uiPolicyActions;
private int syncDirty; private int syncDirty;
public int getSyncDirty() { public int getSyncDirty() {
...@@ -85,7 +91,7 @@ public class UiPolicyItem { ...@@ -85,7 +91,7 @@ public class UiPolicyItem {
/** /**
* *
* @return * @return
* The sysId * The sys_id
*/ */
public String getSysId() { public String getSysId() {
return sysId; return sysId;
...@@ -94,7 +100,7 @@ public class UiPolicyItem { ...@@ -94,7 +100,7 @@ public class UiPolicyItem {
/** /**
* *
* @param sysId * @param sysId
* The sysId * The sys_id
*/ */
public void setSysId(String sysId) { public void setSysId(String sysId) {
this.sysId = sysId; this.sysId = sysId;
...@@ -153,17 +159,4 @@ public class UiPolicyItem { ...@@ -153,17 +159,4 @@ public class UiPolicyItem {
return uiPolicyItem; return uiPolicyItem;
} }
} }
@Override
public String toString() {
return "UiPolicyItem{" +
"id=" + id +
", catalogueItemId=" + catalogueItemId +
", uiPolicyActions=" + uiPolicyActions +
", partialConditions=" + partialConditions +
", condition='" + condition + '\'' +
", sysId='" + sysId + '\'' +
", syncDirty='" + syncDirty + '\'' +
'}';
}
} }
package com.vsoft.uoflservicenow.db.models; package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
...@@ -20,6 +20,18 @@ public class UserApiValues { ...@@ -20,6 +20,18 @@ public class UserApiValues {
@Expose @Expose
private String sysId; private String sysId;
@SerializedName("name")
@Expose
private String fullName;
@SerializedName("user_name")
@Expose
private String userId;
@SerializedName("email")
@Expose
private String userEmailId;
public String getFirstName() { public String getFirstName() {
return firstName; return firstName;
} }
...@@ -43,4 +55,28 @@ public class UserApiValues { ...@@ -43,4 +55,28 @@ public class UserApiValues {
public void setSysId(String sysId) { public void setSysId(String sysId) {
this.sysId = sysId; this.sysId = sysId;
} }
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getUserEmailId() {
return userEmailId;
}
public void setUserEmailId(String userEmailId) {
this.userEmailId = userEmailId;
}
} }
package com.vsoft.uoflservicenow.db.models; package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
......
package com.vsoft.uoflservicenow.db.models; package com.vsoft.servicenow.db.models;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
......
package com.vsoft.uoflservicenow.dialog; package com.vsoft.servicenow.dialog;
import android.app.Dialog; import android.app.Dialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
...@@ -21,17 +21,16 @@ import android.widget.EditText; ...@@ -21,17 +21,16 @@ import android.widget.EditText;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.utils.Util;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.api.listeners.get.GetReferenceApiListener; import com.vsoft.servicenow.R;
import com.vsoft.uoflservicenow.api.managers.VariableChoiceApiManager; import com.vsoft.servicenow.api.listeners.get.GetReferenceApiListener;
import com.vsoft.uoflservicenow.db.models.Reference; import com.vsoft.servicenow.api.managers.VariableChoiceApiManager;
import com.vsoft.uoflservicenow.enums.SyncStatus; import com.vsoft.servicenow.db.models.Reference;
import com.vsoft.uoflservicenow.listeners.ReferenceListener; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog; import com.vsoft.servicenow.listeners.ReferenceListener;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DialogUtils; import com.vsoft.servicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.Util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -144,7 +143,6 @@ public class SelectReferenceDialog extends DialogFragment { ...@@ -144,7 +143,6 @@ public class SelectReferenceDialog extends DialogFragment {
@OnItemClick(R.id.reference_search_dialog_list_view) @OnItemClick(R.id.reference_search_dialog_list_view)
void listViewItemClick(int position) { void listViewItemClick(int position) {
Reference reference = mReferenceList.get(position); Reference reference = mReferenceList.get(position);
CatalogueLog.e("SelectReferenceDialog: mListener: "+mListener);
if (reference != null) if (reference != null)
mListener.positiveButtonClick(reference); mListener.positiveButtonClick(reference);
else else
...@@ -186,7 +184,7 @@ public class SelectReferenceDialog extends DialogFragment { ...@@ -186,7 +184,7 @@ public class SelectReferenceDialog extends DialogFragment {
Map<String, String> stringMap = new HashMap<>(1); Map<String, String> stringMap = new HashMap<>(1);
stringMap.put(Constants.URL_PARAM_SYSPRM_FIELDS, "sys_id,"+mReferenceColumnName); stringMap.put(Constants.URL_PARAM_SYSPRM_FIELDS, "sys_id,"+mReferenceColumnName);
stringMap.put(Constants.URL_PARAM_SYSPRM_QUERY, mReferenceColumnName+"LIKE"+params[0]); stringMap.put(Constants.URL_PARAM_SYSPRM_QUERY, mReferenceColumnName+"LIKE"+params[0]);
VariableChoiceApiManager.getReference(mReferenceTableName, stringMap, new GetReferenceApiListener() { VariableChoiceApiManager.getReference(getActivity(), mReferenceTableName, stringMap, new GetReferenceApiListener() {
@Override @Override
public void onDoneApiCall(List<Reference> referenceList) { public void onDoneApiCall(List<Reference> referenceList) {
syncStatus = SyncStatus.SUCCESS; syncStatus = SyncStatus.SUCCESS;
......
package com.vsoft.uoflservicenow.enums; package com.vsoft.servicenow.enums;
/** /**
* @since 1.0 * @since 1.0
......
package com.vsoft.uoflservicenow.enums; package com.vsoft.servicenow.enums;
/** /**
* @since 1.0 * @since 1.0
......
package com.vsoft.uoflservicenow.enums; package com.vsoft.servicenow.enums;
/** /**
* @since 1.0 * @since 1.0
......
package com.vsoft.uoflservicenow.enums; package com.vsoft.servicenow.enums;
public enum ViewType { public enum ViewType {
UNKNOWN (-1, "unknown"), UNKNOWN (-1, "unknown"),
......
package com.vsoft.uoflservicenow.listeners; package com.vsoft.servicenow.listeners;
import com.vsoft.uoflservicenow.db.models.Reference; import com.vsoft.servicenow.db.models.Reference;
/** /**
* Created by Kunj on 10/8/16. * Created by Kunj on 10/8/16.
......
package com.vsoft.uoflservicenow.receiver; package com.vsoft.servicenow.receiver;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
...@@ -6,9 +6,9 @@ import android.content.Intent; ...@@ -6,9 +6,9 @@ import android.content.Intent;
import android.os.Handler; import android.os.Handler;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import com.vsoft.uoflservicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.NetworkUtil; import com.vsoft.servicenow.utils.NetworkUtil;
/** /**
......
package com.vsoft.uoflservicenow.service; package com.vsoft.servicenow.service;
import android.app.IntentService; import android.app.IntentService;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.api.listeners.post.PostAttachmentApiListener;
import com.vsoft.uoflservicenow.api.listeners.post.PostAttachmentApiListener; import com.vsoft.servicenow.api.listeners.post.PostIncidentApiListener;
import com.vsoft.uoflservicenow.api.listeners.post.PostIncidentApiListener; import com.vsoft.servicenow.api.listeners.post.PostVariableFormApiListener;
import com.vsoft.uoflservicenow.api.listeners.post.PostVariableFormApiListener; import com.vsoft.servicenow.api.managers.CatalogueVariableApiManager;
import com.vsoft.uoflservicenow.api.managers.CatalogueVariableApiManager; import com.vsoft.servicenow.api.managers.IncidentApiManager;
import com.vsoft.uoflservicenow.api.managers.IncidentApiManager; import com.vsoft.servicenow.db.managers.AttachmentManager;
import com.vsoft.uoflservicenow.db.managers.AttachmentManager; import com.vsoft.servicenow.db.managers.CatalogueItemInputManager;
import com.vsoft.uoflservicenow.db.managers.CatalogueItemInputManager; import com.vsoft.servicenow.db.managers.CatalogueItemManager;
import com.vsoft.uoflservicenow.db.managers.CatalogueItemManager; import com.vsoft.servicenow.db.managers.ReportIncidentValueManager;
import com.vsoft.uoflservicenow.db.managers.ReportIncidentValueManager; import com.vsoft.servicenow.db.models.Attachment;
import com.vsoft.uoflservicenow.db.models.Attachment; import com.vsoft.servicenow.db.models.CatalogueItem;
import com.vsoft.uoflservicenow.db.models.CatalogueItem; import com.vsoft.servicenow.db.models.CatalogueItemInput;
import com.vsoft.uoflservicenow.db.models.CatalogueItemInput; import com.vsoft.servicenow.db.models.Incident;
import com.vsoft.uoflservicenow.db.models.Incident; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.enums.SyncStatus; import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.DBConstants;
import com.vsoft.uoflservicenow.utils.DBConstants; import com.vsoft.servicenow.utils.PrefManager;
import com.vsoft.uoflservicenow.utils.PrefManager;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -36,10 +37,11 @@ import java.util.List; ...@@ -36,10 +37,11 @@ import java.util.List;
import okhttp3.MediaType; import okhttp3.MediaType;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import static com.vsoft.uoflservicenow.db.managers.CatalogueItemInputManager.getDirtyItemInput; import static com.vsoft.servicenow.db.managers.CatalogueItemInputManager.getDirtyItemInput;
import static com.vsoft.uoflservicenow.utils.DBConstants.CATALOGUE_ITEM_INPUT_SYS_ID; import static com.vsoft.servicenow.utils.DBConstants.CATALOGUE_ITEM_INPUT_SYS_ID;
import static com.vsoft.uoflservicenow.utils.DBConstants.INCIDENT_INPUT_NUMBER; import static com.vsoft.servicenow.utils.DBConstants.INCIDENT_INPUT_NUMBER;
import static com.vsoft.uoflservicenow.utils.DBConstants.SYNC_FLAG_NONE; import static com.vsoft.servicenow.utils.DBConstants.SYNC_FLAG_NONE;
/** /**
* @author Kunj * @author Kunj
...@@ -75,6 +77,15 @@ public class SyncService extends IntentService { ...@@ -75,6 +77,15 @@ public class SyncService extends IntentService {
if(Constants.DEBUG) CatalogueLog.d("startSync: result of syncing catalogueItemInput "+i+": "+result); if(Constants.DEBUG) CatalogueLog.d("startSync: result of syncing catalogueItemInput "+i+": "+result);
} }
/*Then we will work on dirty attachment*/
List<Attachment> attachmentList = AttachmentManager.getDirtyAttachment();
if(Constants.DEBUG) CatalogueLog.d("startSync: attachment to sync: "+attachmentList.size());
for (int i = 0; i < attachmentList.size(); i++) {
Attachment attachment = attachmentList.get(i);
result = syncAttachment(attachment);
if(Constants.DEBUG) CatalogueLog.d("startSync: result of syncing attachment "+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());
...@@ -92,20 +103,15 @@ public class SyncService extends IntentService { ...@@ -92,20 +103,15 @@ public class SyncService extends IntentService {
CatalogueLog.d( "syncVariableForm"); CatalogueLog.d( "syncVariableForm");
if(catalogueItemInput.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE || catalogueItemInput.getSysId() == null || catalogueItemInput.getSysId().isEmpty()) { if(catalogueItemInput.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE || catalogueItemInput.getSysId() == null || catalogueItemInput.getSysId().isEmpty()) {
final CatalogueItem catalogueItem = CatalogueItemManager.get(catalogueItemInput.getCatalogueItemId()); final CatalogueItem catalogueItem = CatalogueItemManager.get(catalogueItemInput.getCatalogueItemId());
CatalogueVariableApiManager.submitVariableForm(catalogueItem.getSysId(), catalogueItemInput.getData(), new PostVariableFormApiListener() { CatalogueVariableApiManager.submitVariableForm(SyncService.this, catalogueItem.getSysId(),
catalogueItemInput.getData(),
new PostVariableFormApiListener() {
@Override @Override
public void onDoneApiCall(String variableFromSysId) { public void onDoneApiCall(String variableFromSysId) {
syncStatus = SyncStatus.SUCCESS; syncStatus = SyncStatus.SUCCESS;
CatalogueLog.e("syncVariableForm: saveVariableForm: result is SUCCESS"); CatalogueLog.e("syncVariableForm: saveVariableForm: result is SUCCESS");
catalogueItemInput.setSysId(variableFromSysId); catalogueItemInput.setSysId(variableFromSysId);
CatalogueItemInputManager.handleSaveServerResponse(catalogueItemInput, Collections.singletonList(CATALOGUE_ITEM_INPUT_SYS_ID), SYNC_FLAG_NONE); CatalogueItemInputManager.handleSaveServerResponse(catalogueItemInput, Collections.singletonList(CATALOGUE_ITEM_INPUT_SYS_ID), SYNC_FLAG_NONE);
CatalogueItemInput localCatalogueItemInput = CatalogueItemInputManager.getItemInputFromSysId(variableFromSysId);
List<Attachment> attachmentList = AttachmentManager.getDirtyAttachment(localCatalogueItemInput.getId());
for (int i = 0; i < attachmentList.size(); i++) {
Attachment attachment = attachmentList.get(i);
syncAttachment(attachment, variableFromSysId);
}
} }
@Override @Override
...@@ -121,7 +127,7 @@ public class SyncService extends IntentService { ...@@ -121,7 +127,7 @@ public class SyncService extends IntentService {
/** /**
* Sync Attachment * Sync Attachment
**/ **/
private SyncStatus syncAttachment(final Attachment attachment, String itemInputSysId) { private SyncStatus syncAttachment(final Attachment attachment) {
CatalogueLog.d( "syncAttachment"); CatalogueLog.d( "syncAttachment");
if(attachment.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE) { if(attachment.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE) {
if (attachment.getMimeType() != null) { if (attachment.getMimeType() != null) {
...@@ -138,12 +144,16 @@ public class SyncService extends IntentService { ...@@ -138,12 +144,16 @@ public class SyncService extends IntentService {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
CatalogueItemInput catalogueItemInput = CatalogueItemInputManager.get(attachment.getItemInputId());
RequestBody requestBody = RequestBody.create(MediaType.parse(attachment.getMimeType()), buf); RequestBody requestBody = RequestBody.create(MediaType.parse(attachment.getMimeType()), buf);
CatalogueVariableApiManager.postAttachment(attachment.getMimeType(), itemInputSysId, CatalogueVariableApiManager.postAttachment(SyncService.this, attachment.getMimeType(),
catalogueItemInput.getSysId(),
attachment.getName(), requestBody, new PostAttachmentApiListener() { attachment.getName(), requestBody, new PostAttachmentApiListener() {
@Override @Override
public void onDoneApiCall() { public void onDoneApiCall() {
syncStatus = SyncStatus.SUCCESS; syncStatus = SyncStatus.SUCCESS;
AttachmentManager.update(attachment, SYNC_FLAG_NONE);
CatalogueLog.e("syncVariableForm: postAttachment: result is SUCCESS"); CatalogueLog.e("syncVariableForm: postAttachment: result is SUCCESS");
} }
...@@ -163,10 +173,19 @@ public class SyncService extends IntentService { ...@@ -163,10 +173,19 @@ public class SyncService extends IntentService {
**/ **/
private SyncStatus syncIncidentForm(final Incident incident) { private SyncStatus syncIncidentForm(final Incident incident) {
CatalogueLog.d( "syncVariableForm"); CatalogueLog.d( "syncVariableForm");
SharedPreferences sharedPreferences = getSharedPreferences(PrefManager.PREFERENCES_USER_VALUES_KEY, Context.MODE_PRIVATE); String userSysId = PrefManager.getSharedPref(SyncService.this, PrefManager.PREFERENCE_SYS_ID);
String userSysId = sharedPreferences.getString(PrefManager.PREFERENCE_SYS_ID, "");
if(incident.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE || incident.getNumber() == null || incident.getNumber().isEmpty()) { if(incident.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE || incident.getNumber() == null || incident.getNumber().isEmpty()) {
IncidentApiManager.submitIncidentForm(incident, userSysId, new PostIncidentApiListener() { JSONObject incidentJsonObject = new JSONObject();
try {
incidentJsonObject.put(Incident.Json.IMPACT, incident.getImpact().getServerString());
incidentJsonObject.put(Incident.Json.SHORT_DESCRIPTION, incident.getShortDescription());
incidentJsonObject.put(Incident.Json.OPENED_AT, userSysId);
incidentJsonObject.put(Incident.Json.CALLER_ID, userSysId);
} catch (JSONException e) {
e.printStackTrace();
}
IncidentApiManager.submitIncidentForm(SyncService.this, incidentJsonObject.toString(), new PostIncidentApiListener
() {
@Override @Override
public void onDoneApiCall(String incidentNumber) { public void onDoneApiCall(String incidentNumber) {
syncStatus = SyncStatus.SUCCESS; syncStatus = SyncStatus.SUCCESS;
......
package com.vsoft.uoflservicenow.ui; package com.vsoft.servicenow.ui;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
...@@ -18,20 +18,20 @@ import android.widget.ProgressBar; ...@@ -18,20 +18,20 @@ import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import com.google.android.gms.analytics.Tracker; import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.R;
import com.vsoft.uoflservicenow.adapters.CatalogueCategoryItemAdapter; import com.vsoft.servicenow.adapters.CatalogueCategoryItemAdapter;
import com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueItemApiListener; import com.vsoft.servicenow.api.listeners.get.GetCatalogueItemApiListener;
import com.vsoft.uoflservicenow.api.managers.CatalogueItemApiManager; import com.vsoft.servicenow.api.managers.CatalogueItemApiManager;
import com.vsoft.uoflservicenow.db.managers.CatalogueItemManager; import com.vsoft.servicenow.db.managers.CatalogueItemManager;
import com.vsoft.uoflservicenow.db.managers.CatalogueManager; import com.vsoft.servicenow.db.managers.CatalogueManager;
import com.vsoft.uoflservicenow.db.models.Catalogue; import com.vsoft.servicenow.db.models.Catalogue;
import com.vsoft.uoflservicenow.db.models.CatalogueItem; import com.vsoft.servicenow.db.models.CatalogueItem;
import com.vsoft.uoflservicenow.enums.SyncStatus; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DialogUtils; import com.vsoft.servicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.Util; import com.vsoft.servicenow.utils.Util;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
...@@ -133,7 +133,8 @@ public class CatalogueItemScreen extends AppCompatActivity { ...@@ -133,7 +133,8 @@ public class CatalogueItemScreen extends AppCompatActivity {
@Override @Override
protected SyncStatus doInBackground(String... params) { protected SyncStatus doInBackground(String... params) {
CatalogueItemApiManager.getCatalogueItems(mCatalogue.getSysId(), new GetCatalogueItemApiListener() { CatalogueItemApiManager.getCatalogueItems(CatalogueItemScreen.this, mCatalogue.getSysId(), new
GetCatalogueItemApiListener() {
@Override @Override
public void onDoneApiCall(List<CatalogueItem> catalogueItemList) { public void onDoneApiCall(List<CatalogueItem> catalogueItemList) {
syncStatus = SyncStatus.SUCCESS; syncStatus = SyncStatus.SUCCESS;
......
package com.vsoft.uoflservicenow.ui; package com.vsoft.servicenow.ui;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
...@@ -17,18 +17,18 @@ import android.widget.ListView; ...@@ -17,18 +17,18 @@ import android.widget.ListView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import com.google.android.gms.analytics.Tracker; import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.R;
import com.vsoft.uoflservicenow.adapters.CatalogueCategoryAdapter; import com.vsoft.servicenow.adapters.CatalogueCategoryAdapter;
import com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueApiListener; import com.vsoft.servicenow.api.listeners.get.GetCatalogueApiListener;
import com.vsoft.uoflservicenow.api.managers.CatalogueApiManager; import com.vsoft.servicenow.api.managers.CatalogueApiManager;
import com.vsoft.uoflservicenow.db.managers.CatalogueManager; import com.vsoft.servicenow.db.managers.CatalogueManager;
import com.vsoft.uoflservicenow.db.models.Catalogue; import com.vsoft.servicenow.db.models.Catalogue;
import com.vsoft.uoflservicenow.enums.SyncStatus; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DialogUtils; import com.vsoft.servicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.Util; import com.vsoft.servicenow.utils.Util;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
...@@ -116,7 +116,7 @@ public class CatalogueScreen extends AppCompatActivity { ...@@ -116,7 +116,7 @@ public class CatalogueScreen extends AppCompatActivity {
@Override @Override
protected SyncStatus doInBackground(String... params) { protected SyncStatus doInBackground(String... params) {
CatalogueApiManager.getCatalogues(new GetCatalogueApiListener() { CatalogueApiManager.getCatalogues(CatalogueScreen.this, new GetCatalogueApiListener() {
@Override @Override
public void onDoneApiCall(List<Catalogue> catalogueList) { public void onDoneApiCall(List<Catalogue> catalogueList) {
syncStatus = SyncStatus.SUCCESS; syncStatus = SyncStatus.SUCCESS;
......
package com.vsoft.uoflservicenow.ui; package com.vsoft.servicenow.ui;
import android.Manifest; import android.Manifest;
import android.app.DatePickerDialog; import android.app.DatePickerDialog;
...@@ -53,45 +53,41 @@ import android.widget.TimePicker; ...@@ -53,45 +53,41 @@ import android.widget.TimePicker;
import android.widget.Toast; import android.widget.Toast;
import com.google.android.gms.analytics.Tracker; import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.R;
import com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueVariableApiListener; import com.vsoft.servicenow.api.listeners.get.GetCatalogueVariableApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetUiPolicyApiListener; import com.vsoft.servicenow.api.managers.CatalogueVariableApiManager;
import com.vsoft.uoflservicenow.api.listeners.get.GetVariableChoiceApiListener; import com.vsoft.servicenow.db.managers.AttachmentManager;
import com.vsoft.uoflservicenow.api.listeners.post.PostAttachmentApiListener; import com.vsoft.servicenow.db.managers.CatalogueItemInputManager;
import com.vsoft.uoflservicenow.api.listeners.post.PostVariableFormApiListener; import com.vsoft.servicenow.db.managers.CatalogueItemManager;
import com.vsoft.uoflservicenow.api.managers.CatalogueVariableApiManager; import com.vsoft.servicenow.db.managers.CatalogueVariableManager;
import com.vsoft.uoflservicenow.api.managers.VariableChoiceApiManager; import com.vsoft.servicenow.db.managers.UiPolicyActionManager;
import com.vsoft.uoflservicenow.api.managers.VariableChoiceManager; import com.vsoft.servicenow.db.managers.UiPolicyItemManager;
import com.vsoft.uoflservicenow.db.managers.AttachmentManager; import com.vsoft.servicenow.db.managers.VariableChoiceManager;
import com.vsoft.uoflservicenow.db.managers.CatalogueItemManager; import com.vsoft.servicenow.db.models.Attachment;
import com.vsoft.uoflservicenow.db.managers.CatalogueVariableManager; import com.vsoft.servicenow.db.models.CatalogueItem;
import com.vsoft.uoflservicenow.db.managers.CatalogueItemInputManager; import com.vsoft.servicenow.db.models.CatalogueItemInput;
import com.vsoft.uoflservicenow.db.managers.UiPolicyActionManager; import com.vsoft.servicenow.db.models.CatalogueVariable;
import com.vsoft.uoflservicenow.db.managers.UiPolicyItemManager; import com.vsoft.servicenow.db.models.CatalogueVariableResponse;
import com.vsoft.uoflservicenow.db.models.Attachment; import com.vsoft.servicenow.db.models.CatalogueVariableSet;
import com.vsoft.uoflservicenow.db.models.Catalogue; import com.vsoft.servicenow.db.models.Reference;
import com.vsoft.uoflservicenow.db.models.CatalogueItem; import com.vsoft.servicenow.db.models.UiPolicyAction;
import com.vsoft.uoflservicenow.db.models.CatalogueItemInput; import com.vsoft.servicenow.db.models.UiPolicyItem;
import com.vsoft.uoflservicenow.db.models.CatalogueVariable; import com.vsoft.servicenow.db.models.VariableChoice;
import com.vsoft.uoflservicenow.db.models.CatalogueVariableSet; import com.vsoft.servicenow.db.models.VariableViewContainer;
import com.vsoft.uoflservicenow.db.models.Reference; import com.vsoft.servicenow.dialog.SelectReferenceDialog;
import com.vsoft.uoflservicenow.db.models.UiPolicyAction; import com.vsoft.servicenow.enums.Operator;
import com.vsoft.uoflservicenow.db.models.UiPolicyItem; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.db.models.VariableChoice; import com.vsoft.servicenow.enums.ViewType;
import com.vsoft.uoflservicenow.db.models.VariableViewContainer; import com.vsoft.servicenow.listeners.ReferenceListener;
import com.vsoft.uoflservicenow.dialog.SelectReferenceDialog; import com.vsoft.servicenow.ui.supportviews.DateAndTimePickerFragment;
import com.vsoft.uoflservicenow.enums.Operator; import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.enums.SyncStatus; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.uoflservicenow.enums.ViewType; import com.vsoft.servicenow.utils.DBConstants;
import com.vsoft.uoflservicenow.listeners.ReferenceListener; import com.vsoft.servicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.ui.supportviews.DateAndTimePickerFragment; import com.vsoft.servicenow.utils.PartialCondition;
import com.vsoft.uoflservicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.PrefManager;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Util;
import com.vsoft.uoflservicenow.utils.DBConstants;
import com.vsoft.uoflservicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.PartialCondition;
import com.vsoft.uoflservicenow.utils.Util;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
...@@ -123,14 +119,16 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -123,14 +119,16 @@ public class CatalogueVariableScreen extends AppCompatActivity {
private List<CatalogueVariable> mCatalogueVariableList = new ArrayList<>(); private List<CatalogueVariable> mCatalogueVariableList = new ArrayList<>();
private CatalogueApplication mApplication; private CatalogueApplication mApplication;
private String mCatalogueItemDescription, mCatalogueItemShortDescription, mCatalogueItemTitle; private String mCatalogueItemDescription, mCatalogueItemShortDescription, mCatalogueItemTitle;
private HashMap<CatalogueVariable, VariableViewContainer> mVariableViewMap; private HashMap<String, VariableViewContainer> mVariableViewMap;
private static final int WRITE_EXTERNAL_STORAGE = 1; private static final int WRITE_EXTERNAL_STORAGE = 1;
private static final int FILE_SELECT_CODE = 0; private static final int FILE_SELECT_CODE = 0;
private TextView mAttachmentTextView; private TextView mAttachmentTextView;
private SyncStatus mSyncStatus;
private CatalogueItem mCatalogueItem; private CatalogueItem mCatalogueItem;
private Uri mAttachmentUri;
private File mAttachmentFile;
private Attachment mAttachment; private Attachment mAttachment;
/*isProgressRequire variable is use for showing progress bar in middle of screen during fetch data from server*/ /*isProgressRequire variable is use for showing progress bar in middle of screen during fetch data from server*/
...@@ -179,11 +177,14 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -179,11 +177,14 @@ public class CatalogueVariableScreen extends AppCompatActivity {
// Send initial screen view hit. // Send initial screen view hit.
Util.sendScreenName(tracker, actionBar.getTitle().toString()); Util.sendScreenName(tracker, actionBar.getTitle().toString());
mCatalogueVariableList = CatalogueVariableManager.getAllVariable(mCatalogueItem.getId()); mCatalogueVariableList = CatalogueVariableManager
.getAllVariable(mCatalogueItem.getId());
if(!mCatalogueVariableList.isEmpty()) {
/*Create dynamic layout and set Ui Policy*/ /*Create dynamic layout and set Ui Policy*/
setVariableChoices(); setVariableChoices();
createView(); createView();
runUIPolicyActions(null); runUIPolicyActions(null);
}
if (mApplication.isNetConnected()) { if (mApplication.isNetConnected()) {
isProgressRequire = mCatalogueVariableList.isEmpty(); isProgressRequire = mCatalogueVariableList.isEmpty();
...@@ -202,8 +203,29 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -202,8 +203,29 @@ public class CatalogueVariableScreen extends AppCompatActivity {
} }
} }
private void setVariableChoices() {
if(!mCatalogueVariableList.isEmpty()) {
for (int i = 0; i < mCatalogueVariableList.size(); i++) {
CatalogueVariable catalogueVariable = mCatalogueVariableList.get(i);
if (catalogueVariable.getType() == ViewType.MULTIPLE_CHOICE
|| catalogueVariable.getType() == ViewType.SELECT_BOX) {
List<VariableChoice> variableChoiceList = VariableChoiceManager.getAllVariableChoices(catalogueVariable.getId());
/*Sort List of CatalogueOrder*/
Collections.sort(variableChoiceList, new Comparator<VariableChoice>() {
@Override
public int compare(VariableChoice lhs, VariableChoice rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
catalogueVariable.setVariableChoiceList(variableChoiceList);
}
}
}
}
class FetchCatalogueVariable extends AsyncTask<String, Void, SyncStatus> { class FetchCatalogueVariable extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog; private ProgressDialog progressDialog;
private SyncStatus syncStatus = SyncStatus.FAIL;
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
...@@ -221,40 +243,44 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -221,40 +243,44 @@ public class CatalogueVariableScreen extends AppCompatActivity {
@Override @Override
protected SyncStatus doInBackground(final String... params) { protected SyncStatus doInBackground(final String... params) {
CatalogueVariableApiManager.getCatalogueVariable(mCatalogueItem.getSysId(), new GetCatalogueVariableApiListener() { CatalogueVariableApiManager.getCatalogueVariable(CatalogueVariableScreen.this, mCatalogueItem.getSysId(), new
GetCatalogueVariableApiListener() {
@Override @Override
public void onDoneApiCall(List<CatalogueVariableSet> variableSetList, List<CatalogueVariable> variableList) { public void onDoneApiCall(CatalogueVariableResponse catalogueVariableResponse) {
mSyncStatus = SyncStatus.SUCCESS; syncStatus = SyncStatus.SUCCESS;
/*For variableset */ /*For variableset */
/*completeCatalogueVariableList is temporary list for getting all catalogue variable in a single list for local DB.*/ /*completeCatalogueVariableList is temporary list for getting all catalogue variable in a single list for local DB.*/
List<CatalogueVariable> completeCatalogueVariableList = new ArrayList<>(); List<CatalogueVariable> completeCatalogueVariableList = new ArrayList<>();
for (int i = 0; i < variableSetList.size(); i++) { for (int i = 0; i <catalogueVariableResponse.getVariablesets().size(); i++) {
CatalogueVariableSet catalogueVariableSet = variableSetList.get(i); CatalogueVariableSet catalogueVariableSet = catalogueVariableResponse.getVariablesets().get(i);
/*First we will add variableList from variableSet*/
completeCatalogueVariableList.addAll(catalogueVariableSet.getVariables()); completeCatalogueVariableList.addAll(catalogueVariableSet.getVariables());
mSyncStatus = fetchVariableChoiceData(catalogueVariableSet.getVariables());
if(mSyncStatus == SyncStatus.FAIL)
break;
} }
/*After added first variableList then we will add other variableList*/
completeCatalogueVariableList.addAll(variableList); /*For variable list*/
completeCatalogueVariableList.addAll(catalogueVariableResponse.getVariables());
boolean variableHasChanged = CatalogueVariableManager.handleGetVariable(mCatalogueItem.getId(), completeCatalogueVariableList); boolean variableHasChanged = CatalogueVariableManager.handleGetVariable(mCatalogueItem.getId(), completeCatalogueVariableList);
mFormHasChanged = variableHasChanged ? variableHasChanged : mFormHasChanged; mFormHasChanged = variableHasChanged ? variableHasChanged : mFormHasChanged;
if(mSyncStatus != SyncStatus.FAIL) {
/*For variable list*/
mSyncStatus = fetchVariableChoiceData(variableList);
if(mSyncStatus != SyncStatus.FAIL) {
CatalogueVariableApiManager.getUiPolicy(mCatalogueItem.getSysId(), new GetUiPolicyApiListener() {
@Override
public void onDoneApiCall(List<UiPolicyItem> uiPolicyItemList) {
/*Save UiPolicyItem in local DB*/ /*Save UiPolicyItem in local DB*/
boolean uiPolicyItemHasChanged = UiPolicyItemManager.handleGetUiPolicyItem(uiPolicyItemList, mCatalogueItem.getId()); boolean uiPolicyItemHasChanged = UiPolicyItemManager.handleGetUiPolicyItem
(catalogueVariableResponse.getUiPolicy(),
mCatalogueItem.getId());
mFormHasChanged = uiPolicyItemHasChanged ? uiPolicyItemHasChanged : mFormHasChanged; mFormHasChanged = uiPolicyItemHasChanged ? uiPolicyItemHasChanged : mFormHasChanged;
for (int i = 0; i < completeCatalogueVariableList.size(); i++) {
CatalogueVariable catalogueVariable = completeCatalogueVariableList.get(i);
if(!catalogueVariable.getVariableChoiceList().isEmpty()) {
VariableChoiceManager.handleGetVariableChoice(catalogueVariable.getId(), catalogueVariable
.getVariableChoiceList());
}
}
/*Get all recently saved all items because we need local id of each item for save UiPolicyAction with respect to UiPolicyItem*/ /*Get all recently saved all items because we need local id of each item for save UiPolicyAction with respect to UiPolicyItem*/
List<UiPolicyItem> localUiPolicyItemList = UiPolicyItemManager.getAllUiPolicyItems(mCatalogueItem.getId()); List<UiPolicyItem> localUiPolicyItemList = UiPolicyItemManager.getAllUiPolicyItems(mCatalogueItem.getId());
for (int i = 0; i < uiPolicyItemList.size(); i++) { for (int i = 0; i < catalogueVariableResponse.getUiPolicy().size(); i++) {
UiPolicyItem uiPolicyItem = uiPolicyItemList.get(i); UiPolicyItem uiPolicyItem = catalogueVariableResponse.getUiPolicy().get(i);
for(int j = 0; j < localUiPolicyItemList.size(); j++) { for(int j = 0; j < localUiPolicyItemList.size(); j++) {
UiPolicyItem localUiPolicyItem = localUiPolicyItemList.get(j); UiPolicyItem localUiPolicyItem = localUiPolicyItemList.get(j);
if(localUiPolicyItem.getSysId().equals(uiPolicyItem.getSysId())) { if(localUiPolicyItem.getSysId().equals(uiPolicyItem.getSysId())) {
...@@ -262,36 +288,23 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -262,36 +288,23 @@ public class CatalogueVariableScreen extends AppCompatActivity {
} }
} }
} }
mSyncStatus = SyncStatus.SUCCESS;
for (int i = 0; i < localUiPolicyItemList.size(); i++) { for (int i = 0; i < localUiPolicyItemList.size(); i++) {
UiPolicyItem uiPolicyItem = localUiPolicyItemList.get(i); UiPolicyItem uiPolicyItem = localUiPolicyItemList.get(i);
/*Save UiPolicyAction in local DB*/ /*Save UiPolicyAction in local DB*/
boolean uiPolicyActionHasChanged = UiPolicyActionManager.handleGetUiPolicyAction(uiPolicyItem.getUiPolicyActions(), uiPolicyItem.getId()); boolean uiPolicyActionHasChanged = UiPolicyActionManager.handleGetUiPolicyAction(uiPolicyItem.getUiPolicyActions(), uiPolicyItem.getId());
mFormHasChanged = uiPolicyActionHasChanged ? uiPolicyActionHasChanged : mFormHasChanged; mFormHasChanged = uiPolicyActionHasChanged ? uiPolicyActionHasChanged : mFormHasChanged;
String condition = uiPolicyItem.getCondition(); setPartialCondition(uiPolicyItem);
if (condition != null) {
List<PartialCondition> partialConditionList = setPartialCondition(condition);
uiPolicyItem.setPartialConditions(partialConditionList);
}
}
}
@Override
public void onFailApiCall() {
mSyncStatus = SyncStatus.FAIL;
}
});
}
} }
} }
@Override @Override
public void onFailApiCall() { public void onFailApiCall() {
mSyncStatus = SyncStatus.FAIL; syncStatus = SyncStatus.FAIL;
} }
}); });
return mSyncStatus; return syncStatus;
} }
@Override @Override
...@@ -344,8 +357,10 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -344,8 +357,10 @@ public class CatalogueVariableScreen extends AppCompatActivity {
} }
} }
private List<PartialCondition> setPartialCondition(String condition) { private void setPartialCondition(UiPolicyItem uiPolicyItem) {
String[] splitStrings = condition.split("\\^"); String condition = uiPolicyItem.getCondition();
if (condition != null) {
String[] splitStrings = uiPolicyItem.getCondition().split("\\^");
List<PartialCondition> partialConditionList = new ArrayList<>(splitStrings.length - 1); List<PartialCondition> partialConditionList = new ArrayList<>(splitStrings.length - 1);
for (int j = 0; j < splitStrings.length - 1; j++) { for (int j = 0; j < splitStrings.length - 1; j++) {
PartialCondition partialCondition = new PartialCondition(); PartialCondition partialCondition = new PartialCondition();
...@@ -369,58 +384,8 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -369,58 +384,8 @@ public class CatalogueVariableScreen extends AppCompatActivity {
} }
partialConditionList.add(partialCondition); partialConditionList.add(partialCondition);
} }
uiPolicyItem.setPartialConditions(partialConditionList);
return partialConditionList;
}
private void setVariableChoices() {
if(!mCatalogueVariableList.isEmpty()) {
for (int i = 0; i < mCatalogueVariableList.size(); i++) {
CatalogueVariable catalogueVariable = mCatalogueVariableList.get(i);
if (catalogueVariable.getType() == ViewType.MULTIPLE_CHOICE
|| catalogueVariable.getType() == ViewType.SELECT_BOX) {
List<VariableChoice> variableChoiceList = VariableChoiceManager.getAllVariableChoices(catalogueVariable.getId());
/*Sort List of CatalogueOrder*/
Collections.sort(variableChoiceList, new Comparator<VariableChoice>() {
@Override
public int compare(VariableChoice lhs, VariableChoice rhs) {
return (lhs.getOrder() - rhs.getOrder());
}
});
catalogueVariable.setVariableChoiceList(variableChoiceList);
}
}
}
}
private SyncStatus fetchVariableChoiceData(List<CatalogueVariable> variableList) {
if(!variableList.isEmpty()) {
for (int i = 0; i < variableList.size(); i++) {
final CatalogueVariable catalogueVariable = variableList.get(i);
if (catalogueVariable.getType() == ViewType.MULTIPLE_CHOICE
|| catalogueVariable.getType() == ViewType.SELECT_BOX) {
/*Fetch multi choice variable values*/
VariableChoiceApiManager.getVariableChoice(catalogueVariable.getSysId(), new GetVariableChoiceApiListener() {
@Override
public void onDoneApiCall(List<VariableChoice> variableChoiceList) {
boolean choiceHasChanged = VariableChoiceManager.handleGetVariableChoice(catalogueVariable.getId(), variableChoiceList);
mFormHasChanged = choiceHasChanged ? choiceHasChanged : mFormHasChanged;
mSyncStatus = SyncStatus.SUCCESS;
}
@Override
public void onFailApiCall() {
mSyncStatus = SyncStatus.FAIL;
}
});
if(mSyncStatus == SyncStatus.FAIL)
break;
}
}
mCatalogueVariableList.addAll(variableList);
} }
return mSyncStatus;
} }
private void createView() { private void createView() {
...@@ -434,6 +399,9 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -434,6 +399,9 @@ public class CatalogueVariableScreen extends AppCompatActivity {
} }
private void getCustomLayout() { private void getCustomLayout() {
if(mVariableViewMap != null && !mVariableViewMap.isEmpty()) {
mVariableViewMap.clear();
}
mVariableViewMap = new HashMap<>(mCatalogueVariableList.size()); mVariableViewMap = new HashMap<>(mCatalogueVariableList.size());
Stack<LinearLayout> stack = null; Stack<LinearLayout> stack = null;
...@@ -518,10 +486,24 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -518,10 +486,24 @@ public class CatalogueVariableScreen extends AppCompatActivity {
} else if (viewType != ViewType.MACRO && viewType != ViewType.CONTAINER_SPLIT) { } else if (viewType != ViewType.MACRO && viewType != ViewType.CONTAINER_SPLIT) {
container = Util.getVariableViewContainer(CatalogueVariableScreen.this, container = Util.getVariableViewContainer(CatalogueVariableScreen.this,
catalogueVariable, childLabelViewLayoutParams); catalogueVariable, childLabelViewLayoutParams);
mVariableViewMap.put(catalogueVariable, container); mVariableViewMap.put(catalogueVariable.getSysId(), container);
View controlView = container.getInputView(); View controlView = container.getInputView();
if (controlView != null) { 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(CatalogueVariableScreen.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(CatalogueVariableScreen.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(CatalogueVariableScreen.this, PrefManager.PREFERENCE_USER_EMAIL_ID);
((EditText)controlView).setText(emailId);
((EditText)controlView).setEnabled(false);
}
if (viewType == ViewType.DATE) { if (viewType == ViewType.DATE) {
controlView.setOnClickListener(dateListener); controlView.setOnClickListener(dateListener);
} else if (viewType == ViewType.DATE_AND_TIME) { } else if (viewType == ViewType.DATE_AND_TIME) {
...@@ -616,7 +598,7 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -616,7 +598,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
for (int i = 0; i < mCatalogueVariableList.size(); i++) { for (int i = 0; i < mCatalogueVariableList.size(); i++) {
CatalogueVariable catalogueVariable = mCatalogueVariableList.get(i); CatalogueVariable catalogueVariable = mCatalogueVariableList.get(i);
VariableViewContainer container = mVariableViewMap.get(catalogueVariable); VariableViewContainer container = mVariableViewMap.get(catalogueVariable.getSysId());
if(catalogueVariable.getType() == ViewType.CONTAINER_START if(catalogueVariable.getType() == ViewType.CONTAINER_START
&& container != null && container != null
...@@ -917,6 +899,14 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -917,6 +899,14 @@ public class CatalogueVariableScreen extends AppCompatActivity {
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();
mAttachmentFile = new File(getPath(this, mAttachmentUri));
if(mAttachmentTextView!=null) {
mAttachmentTextView.setText(mAttachmentFile.getName());
}
// Get the Uri of the selected file
Uri attachmentUri = data.getData(); Uri attachmentUri = data.getData();
String attachmentPath = getPath(this, attachmentUri); String attachmentPath = getPath(this, attachmentUri);
File attachmentFile = new File(attachmentPath); File attachmentFile = new File(attachmentPath);
...@@ -1145,12 +1135,7 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -1145,12 +1135,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
return; return;
for(int i=0; i<uiPolicyItemList.size(); i++) { for(int i=0; i<uiPolicyItemList.size(); i++) {
UiPolicyItem item = uiPolicyItemList.get(i); UiPolicyItem item = uiPolicyItemList.get(i);
setPartialCondition(item);
String condition = item.getCondition();
if (condition != null) {
List<PartialCondition> partialConditionList = setPartialCondition(condition);
item.setPartialConditions(partialConditionList);
}
/*UIPolicy condition is null then skip iterator*/ /*UIPolicy condition is null then skip iterator*/
if(item.getPartialConditions()==null) if(item.getPartialConditions()==null)
...@@ -1170,7 +1155,7 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -1170,7 +1155,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
for(int j=0; j<item.getPartialConditions().size(); j++) { for(int j=0; j<item.getPartialConditions().size(); j++) {
PartialCondition partialCondition = item.getPartialConditions().get(j); PartialCondition partialCondition = item.getPartialConditions().get(j);
CatalogueVariable variable = getVariableForSysId(partialCondition.getViewSysId()); CatalogueVariable variable = getVariableForSysId(partialCondition.getViewSysId());
VariableViewContainer variableViewContainer = mVariableViewMap.get(variable); VariableViewContainer variableViewContainer = mVariableViewMap.get(variable.getSysId());
if(variableViewContainer == null || variableViewContainer.getInputView() == null) { if(variableViewContainer == null || variableViewContainer.getInputView() == null) {
continue; continue;
} }
...@@ -1191,7 +1176,7 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -1191,7 +1176,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
for(int j=0; j<uiPolicyActionList.size(); j++) { for(int j=0; j<uiPolicyActionList.size(); j++) {
UiPolicyAction action = uiPolicyActionList.get(j); UiPolicyAction action = uiPolicyActionList.get(j);
CatalogueVariable variable = getVariableForName(action.getVariableName()); CatalogueVariable variable = getVariableForName(action.getVariableName());
VariableViewContainer container = mVariableViewMap.get(variable); VariableViewContainer container = mVariableViewMap.get(variable.getSysId());
if(container!=null) { if(container!=null) {
if (action.getMandatory().equals(Boolean.toString(true))) { if (action.getMandatory().equals(Boolean.toString(true))) {
variable.setMandatory(true); variable.setMandatory(true);
...@@ -1226,7 +1211,7 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -1226,7 +1211,7 @@ public class CatalogueVariableScreen extends AppCompatActivity {
for(int j=0; j<uiPolicyActionList.size(); j++) { for(int j=0; j<uiPolicyActionList.size(); j++) {
UiPolicyAction action = uiPolicyActionList.get(j); UiPolicyAction action = uiPolicyActionList.get(j);
CatalogueVariable variable = getVariableForName(action.getVariableName()); CatalogueVariable variable = getVariableForName(action.getVariableName());
VariableViewContainer container = mVariableViewMap.get(variable); VariableViewContainer container = mVariableViewMap.get(variable.getSysId());
if(container!=null) { if(container!=null) {
if (action.getMandatory().equals(Boolean.toString(true))) { if (action.getMandatory().equals(Boolean.toString(true))) {
variable.setMandatory(false); variable.setMandatory(false);
...@@ -1279,7 +1264,8 @@ public class CatalogueVariableScreen extends AppCompatActivity { ...@@ -1279,7 +1264,8 @@ public class CatalogueVariableScreen extends AppCompatActivity {
private CatalogueVariable getVariableForView(View view) { private CatalogueVariable getVariableForView(View view) {
for(int i=0; i<mCatalogueVariableList.size(); i++) { for(int i=0; i<mCatalogueVariableList.size(); i++) {
VariableViewContainer container = mVariableViewMap.get(mCatalogueVariableList.get(i)); String sysId = mCatalogueVariableList.get(i).getSysId();
VariableViewContainer container = mVariableViewMap.get(sysId);
if(container == null) { if(container == null) {
continue; continue;
} }
......
package com.vsoft.uoflservicenow.ui; package com.vsoft.servicenow.ui;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
...@@ -15,18 +13,19 @@ import android.widget.EditText; ...@@ -15,18 +13,19 @@ import android.widget.EditText;
import android.widget.Toast; import android.widget.Toast;
import com.google.android.gms.analytics.Tracker; import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.api.listeners.get.GetUserDetailApiListener;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.api.listeners.get.GetUserLoginApiListener;
import com.vsoft.uoflservicenow.api.listeners.get.GetUserDetailApiListener; import com.vsoft.servicenow.api.managers.LoginApiManager;
import com.vsoft.uoflservicenow.api.listeners.get.GetUserLoginApiListener; import com.vsoft.servicenow.api.managers.UserApiManager;
import com.vsoft.uoflservicenow.api.managers.LoginApiManger; import com.vsoft.servicenow.api.pojos.LoginApiResponse;
import com.vsoft.uoflservicenow.api.managers.UserApiManager; import com.vsoft.servicenow.db.models.UserApiValues;
import com.vsoft.uoflservicenow.db.models.UserApiValues; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.DialogUtils; import com.vsoft.servicenow.utils.KeyboardUtil;
import com.vsoft.uoflservicenow.utils.KeyboardUtil; import com.vsoft.servicenow.utils.Util;
import com.vsoft.uoflservicenow.utils.PrefManager; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.utils.Util; import com.vsoft.servicenow.R;
import com.vsoft.servicenow.utils.PrefManager;
import java.util.List; import java.util.List;
...@@ -49,7 +48,6 @@ public class LoginScreen extends Activity { ...@@ -49,7 +48,6 @@ public class LoginScreen extends Activity {
private static final int API_FAIL_USER_LOGIN = 2; private static final int API_FAIL_USER_LOGIN = 2;
private static final int API_SUCCESS_USER_DETAIL = 3; private static final int API_SUCCESS_USER_DETAIL = 3;
private static final int API_FAIL_USER_DETAIL = 4; private static final int API_FAIL_USER_DETAIL = 4;
private int apiStatus;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -60,8 +58,6 @@ public class LoginScreen extends Activity { ...@@ -60,8 +58,6 @@ public class LoginScreen extends Activity {
ButterKnife.bind(this); ButterKnife.bind(this);
mApplication = (CatalogueApplication) getApplication(); mApplication = (CatalogueApplication) getApplication();
PrefManager prefManager = PrefManager.getInstance();
prefManager.init(LoginScreen.this);
CheckLoginValues(); CheckLoginValues();
mPasswordEditText.setOnKeyListener(new View.OnKeyListener() { mPasswordEditText.setOnKeyListener(new View.OnKeyListener() {
...@@ -86,8 +82,7 @@ public class LoginScreen extends Activity { ...@@ -86,8 +82,7 @@ public class LoginScreen extends Activity {
} }
private void CheckLoginValues() { private void CheckLoginValues() {
SharedPreferences sharedPreferences = getSharedPreferences(PrefManager.PREFERENCES_USER_VALUES_KEY, Context.MODE_PRIVATE); String sysId = PrefManager.getSharedPref(LoginScreen.this, PrefManager.PREFERENCE_SYS_ID);
String sysId = sharedPreferences.getString(PrefManager.PREFERENCE_SYS_ID, "");
if (!TextUtils.isEmpty(sysId)) { if (!TextUtils.isEmpty(sysId)) {
/*Send broadcast to start SyncService*/ /*Send broadcast to start SyncService*/
Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT); Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT);
...@@ -127,7 +122,7 @@ public class LoginScreen extends Activity { ...@@ -127,7 +122,7 @@ public class LoginScreen extends Activity {
private class LoginDetailsSendToServer extends AsyncTask<String, Integer, Integer> { private class LoginDetailsSendToServer extends AsyncTask<String, Integer, Integer> {
private ProgressDialog progressDialog; private ProgressDialog progressDialog;
private static final int USER_DETAIL = 1; private static final int USER_DETAIL = 1;
private String userName; private int apiStatus;
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
...@@ -140,15 +135,19 @@ public class LoginScreen extends Activity { ...@@ -140,15 +135,19 @@ public class LoginScreen extends Activity {
@Override @Override
protected Integer doInBackground(String... params) { protected Integer doInBackground(String... params) {
userName = params[0];//"a0kuma18"; final String userName = params[0];
String password = params[1];//"v$0ftA$win"; String password = params[1];
LoginApiManger.submitLoginValues(Constants.GRANT_TYPE, Constants.CLIENT_ID, Constants LoginApiManager.submitLoginValues(LoginApiResponse.Json.PASSWORD, Constants.LOGIN_CLIENT_ID, Constants
.CLIENT_SECRET, userName, password, new GetUserLoginApiListener() { .LOGIN_CLIENT_SECRET, userName, password, new GetUserLoginApiListener() {
@Override @Override
public void onDoneApiCall() { public void onDoneApiCall(LoginApiResponse loginApiResponse) {
/*Save access token in Preference*/
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_ACCESS_TOKEN, loginApiResponse.getAccessToken());
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_REFRESH_TOKEN, loginApiResponse.getRefreshToken());
apiStatus = API_SUCCESS_USER_LOGIN; apiStatus = API_SUCCESS_USER_LOGIN;
publishProgress(USER_DETAIL); publishProgress(USER_DETAIL);
UserApiManager.getUserDetailResponse(userName, new GetUserDetailApiListener() { UserApiManager.getUserDetailResponse(LoginScreen.this, userName, new GetUserDetailApiListener() {
@Override @Override
public void onDoneApiCall(List<UserApiValues> userValues) { public void onDoneApiCall(List<UserApiValues> userValues) {
apiStatus = API_SUCCESS_USER_DETAIL; apiStatus = API_SUCCESS_USER_DETAIL;
...@@ -188,7 +187,18 @@ public class LoginScreen extends Activity { ...@@ -188,7 +187,18 @@ public class LoginScreen extends Activity {
String firstName = mUserDetails.get(0).getFirstName(); String firstName = mUserDetails.get(0).getFirstName();
String lastName = mUserDetails.get(0).getLastName(); String lastName = mUserDetails.get(0).getLastName();
String sysid = mUserDetails.get(0).getSysId(); String sysid = mUserDetails.get(0).getSysId();
PrefManager.saveUserDetailsInPreferences(LoginScreen.this, firstName, lastName, sysid);
String userFullName = mUserDetails.get(0).getFullName();
String userId = mUserDetails.get(0).getUserId();
String userEmailId = mUserDetails.get(0).getUserEmailId();
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_FIRST_NAME, firstName);
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_LAST_NAME, lastName);
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_SYS_ID, sysid);
/*For prefill value in variable form*/
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_USER_FULL_NAME, userFullName);
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_USER_ID, userId);
PrefManager.setSharedPref(LoginScreen.this, PrefManager.PREFERENCE_USER_EMAIL_ID, userEmailId);
/*Send broadcast to start SyncService*/ /*Send broadcast to start SyncService*/
Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT); Intent intent = new Intent(Constants.APPLICATION_BROADCAST_INTENT);
......
package com.vsoft.uoflservicenow.ui; package com.vsoft.servicenow.ui;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
...@@ -10,20 +10,22 @@ import android.support.v7.app.AppCompatActivity; ...@@ -10,20 +10,22 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.Html; import android.text.Html;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar;
import com.google.android.gms.analytics.Tracker; import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.R;
import com.vsoft.uoflservicenow.adapters.MyIncidentsAdapter; import com.vsoft.servicenow.adapters.MyIncidentsAdapter;
import com.vsoft.uoflservicenow.api.listeners.get.GetIncidentApiListener; import com.vsoft.servicenow.api.listeners.get.GetIncidentApiListener;
import com.vsoft.uoflservicenow.api.managers.IncidentApiManager; import com.vsoft.servicenow.api.managers.IncidentApiManager;
import com.vsoft.uoflservicenow.db.managers.MyIncidentsManager; import com.vsoft.servicenow.db.managers.MyIncidentsManager;
import com.vsoft.uoflservicenow.db.models.Incident; import com.vsoft.servicenow.db.models.Incident;
import com.vsoft.uoflservicenow.enums.SyncStatus; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog; import com.vsoft.servicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.DialogUtils; import com.vsoft.servicenow.utils.Util;
import com.vsoft.uoflservicenow.utils.Util;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
...@@ -31,6 +33,7 @@ import java.util.List; ...@@ -31,6 +33,7 @@ import java.util.List;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnItemClick; import butterknife.OnItemClick;
/** /**
...@@ -41,7 +44,14 @@ public class MyIncidentScreen extends AppCompatActivity { ...@@ -41,7 +44,14 @@ public class MyIncidentScreen extends AppCompatActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar; @BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.my_incidents_screen_list_view) ListView mListView; @BindView(R.id.my_incidents_screen_list_view) ListView mListView;
@BindView(R.id.toolbar_refresh_icon)
ImageView mRefreshIcon;
@BindView(R.id.toolbar_progress_icon)
ProgressBar mProgressBar;
private List<Incident> mIncidentList; private List<Incident> mIncidentList;
private boolean isProgressRequire;
private CatalogueApplication mApplication;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -51,7 +61,7 @@ public class MyIncidentScreen extends AppCompatActivity { ...@@ -51,7 +61,7 @@ public class MyIncidentScreen extends AppCompatActivity {
setContentView(R.layout.my_incidents_screen); setContentView(R.layout.my_incidents_screen);
ButterKnife.bind(this); ButterKnife.bind(this);
CatalogueApplication application = (CatalogueApplication) getApplication(); mApplication = (CatalogueApplication) getApplication();
setSupportActionBar(mToolbar); setSupportActionBar(mToolbar);
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
...@@ -63,14 +73,19 @@ public class MyIncidentScreen extends AppCompatActivity { ...@@ -63,14 +73,19 @@ public class MyIncidentScreen extends AppCompatActivity {
actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayShowTitleEnabled(true);
} }
Tracker tracker = application.getDefaultTracker(); Tracker tracker = mApplication.getDefaultTracker();
// Send initial screen view hit. // Send initial screen view hit.
Util.sendScreenName(tracker, actionBar.getTitle().toString()); Util.sendScreenName(tracker, actionBar.getTitle().toString());
if (application.isNetConnected()) { mIncidentList = MyIncidentsManager.getAllIncidents();
if(!mIncidentList.isEmpty()) {
setData(mIncidentList);
}
if (mApplication.isNetConnected()) {
isProgressRequire = mIncidentList.isEmpty();
new FetchIncident().execute(); new FetchIncident().execute();
} else { } else {
mIncidentList = MyIncidentsManager.getAllIncidents();
if(mIncidentList.isEmpty()) { if(mIncidentList.isEmpty()) {
DialogUtils.showNoConnectionDialogWithCloseActivity(MyIncidentScreen.this); DialogUtils.showNoConnectionDialogWithCloseActivity(MyIncidentScreen.this);
} else { } else {
...@@ -105,19 +120,23 @@ public class MyIncidentScreen extends AppCompatActivity { ...@@ -105,19 +120,23 @@ public class MyIncidentScreen extends AppCompatActivity {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
super.onPreExecute(); super.onPreExecute();
if(isProgressRequire) {
progressDialog = new ProgressDialog(MyIncidentScreen.this); progressDialog = new ProgressDialog(MyIncidentScreen.this);
progressDialog.setMessage(getString(R.string.loading_string)); progressDialog.setMessage(getString(R.string.loading_string));
progressDialog.show(); progressDialog.show();
progressDialog.setCancelable(false); progressDialog.setCancelable(false);
} else {
mRefreshIcon.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE);
}
} }
@Override @Override
protected SyncStatus doInBackground(String... params) { protected SyncStatus doInBackground(String... params) {
IncidentApiManager.getIncident(new GetIncidentApiListener() { IncidentApiManager.getIncident(MyIncidentScreen.this, new GetIncidentApiListener() {
@Override @Override
public void onDoneApiCall(List<Incident> incidentList) { public void onDoneApiCall(List<Incident> incidentList) {
syncStatus = SyncStatus.SUCCESS; syncStatus = SyncStatus.SUCCESS;
CatalogueLog.e("Data: incidentList: "+incidentList);
MyIncidentsManager.handleGetIncident(incidentList); MyIncidentsManager.handleGetIncident(incidentList);
} }
...@@ -134,9 +153,13 @@ public class MyIncidentScreen extends AppCompatActivity { ...@@ -134,9 +153,13 @@ public class MyIncidentScreen extends AppCompatActivity {
super.onPostExecute(syncStatus); super.onPostExecute(syncStatus);
if(progressDialog != null && progressDialog.isShowing()) { if(progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss(); progressDialog.dismiss();
} else {
mRefreshIcon.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);
} }
if(syncStatus == SyncStatus.SUCCESS) { if(syncStatus == SyncStatus.SUCCESS) {
mIncidentList = MyIncidentsManager.getAllIncidents(); mIncidentList = MyIncidentsManager.getAllIncidents();
isProgressRequire = mIncidentList.isEmpty();
setData(mIncidentList); setData(mIncidentList);
} else { } else {
showErrorDialog(R.string.failed_to_fetch_incident_string); showErrorDialog(R.string.failed_to_fetch_incident_string);
...@@ -144,6 +167,15 @@ public class MyIncidentScreen extends AppCompatActivity { ...@@ -144,6 +167,15 @@ public class MyIncidentScreen extends AppCompatActivity {
} }
} }
@OnClick(R.id.toolbar_refresh_icon)
void onRefreshClicked() {
if(mApplication.isNetConnected()) {
new FetchIncident().execute();
} else {
DialogUtils.showNoConnectionDialogWithCloseActivity(MyIncidentScreen.this);
}
}
private void setData(final List<Incident> catalogueList) { private void setData(final List<Incident> catalogueList) {
MyIncidentsAdapter adapter = new MyIncidentsAdapter(MyIncidentScreen.this); MyIncidentsAdapter adapter = new MyIncidentsAdapter(MyIncidentScreen.this);
......
package com.vsoft.uoflservicenow.ui; package com.vsoft.servicenow.ui;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
...@@ -10,19 +10,22 @@ import android.support.v7.app.AppCompatActivity; ...@@ -10,19 +10,22 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.Html; import android.text.Html;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar;
import com.google.android.gms.analytics.Tracker; import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.R;
import com.vsoft.uoflservicenow.adapters.MyRequestAdapter; import com.vsoft.servicenow.adapters.MyRequestAdapter;
import com.vsoft.uoflservicenow.api.listeners.get.GetMyRequestApiListener; import com.vsoft.servicenow.api.listeners.get.GetMyRequestApiListener;
import com.vsoft.uoflservicenow.api.managers.MyRequestApiManager; import com.vsoft.servicenow.api.managers.MyRequestApiManager;
import com.vsoft.uoflservicenow.db.managers.MyRequestsManager; import com.vsoft.servicenow.db.managers.MyRequestsManager;
import com.vsoft.uoflservicenow.db.models.MyRequest; import com.vsoft.servicenow.db.models.MyRequest;
import com.vsoft.uoflservicenow.enums.SyncStatus; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.DialogUtils; import com.vsoft.servicenow.utils.DialogUtils;
import com.vsoft.uoflservicenow.utils.Util; import com.vsoft.servicenow.utils.Util;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
...@@ -30,6 +33,7 @@ import java.util.List; ...@@ -30,6 +33,7 @@ import java.util.List;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnItemClick; import butterknife.OnItemClick;
/** /**
...@@ -40,8 +44,15 @@ public class MyRequestActivity extends AppCompatActivity { ...@@ -40,8 +44,15 @@ public class MyRequestActivity extends AppCompatActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar; @BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.request_screen_list_view) ListView mListView; @BindView(R.id.request_screen_list_view) ListView mListView;
@BindView(R.id.toolbar_refresh_icon)
ImageView mRefreshIcon;
@BindView(R.id.toolbar_progress_icon)
ProgressBar mProgressBar;
private List<MyRequest> mMyRequestList; private List<MyRequest> mMyRequestList;
private MyRequestAdapter mAdapter; private MyRequestAdapter mAdapter;
private boolean isProgressRequire;
private CatalogueApplication mApplication;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -51,7 +62,7 @@ public class MyRequestActivity extends AppCompatActivity { ...@@ -51,7 +62,7 @@ public class MyRequestActivity extends AppCompatActivity {
setContentView(R.layout.request_list_screen); setContentView(R.layout.request_list_screen);
ButterKnife.bind(this); ButterKnife.bind(this);
CatalogueApplication application = (CatalogueApplication) getApplication(); mApplication = (CatalogueApplication) getApplication();
setSupportActionBar(mToolbar); setSupportActionBar(mToolbar);
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
if(actionBar != null) { if(actionBar != null) {
...@@ -61,21 +72,26 @@ public class MyRequestActivity extends AppCompatActivity { ...@@ -61,21 +72,26 @@ public class MyRequestActivity extends AppCompatActivity {
actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayShowTitleEnabled(true);
} }
Tracker tracker = application.getDefaultTracker(); Tracker tracker = mApplication.getDefaultTracker();
// Send initial screen view hit. // Send initial screen view hit.
Util.sendScreenName(tracker, actionBar.getTitle().toString()); Util.sendScreenName(tracker, actionBar.getTitle().toString());
mAdapter = new MyRequestAdapter(MyRequestActivity.this); mAdapter = new MyRequestAdapter(MyRequestActivity.this);
mListView.setAdapter(mAdapter); mListView.setAdapter(mAdapter);
if(application.isNetConnected()) { mMyRequestList = MyRequestsManager.getAllRequests();
if(!mMyRequestList.isEmpty()) {
setData(mMyRequestList);
}
if(mApplication.isNetConnected()) {
isProgressRequire = mMyRequestList.isEmpty();
new FetchMyRequestData().execute(); new FetchMyRequestData().execute();
} else { } else {
List<MyRequest> myRequestList = MyRequestsManager.getAllRequests(); if(mMyRequestList.isEmpty()) {
if(myRequestList.isEmpty()) {
DialogUtils.showNoConnectionDialogWithCloseActivity(MyRequestActivity.this); DialogUtils.showNoConnectionDialogWithCloseActivity(MyRequestActivity.this);
} else { } else {
setData(myRequestList); setData(mMyRequestList);
} }
} }
} }
...@@ -87,15 +103,20 @@ public class MyRequestActivity extends AppCompatActivity { ...@@ -87,15 +103,20 @@ public class MyRequestActivity extends AppCompatActivity {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
super.onPreExecute(); super.onPreExecute();
if(isProgressRequire) {
progressDialog = new ProgressDialog(MyRequestActivity.this); progressDialog = new ProgressDialog(MyRequestActivity.this);
progressDialog.setMessage(getString(R.string.loading_string)); progressDialog.setMessage(getString(R.string.loading_string));
progressDialog.show(); progressDialog.show();
progressDialog.setCancelable(false); progressDialog.setCancelable(false);
} else {
mRefreshIcon.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE);
}
} }
@Override @Override
protected SyncStatus doInBackground(String... params) { protected SyncStatus doInBackground(String... params) {
MyRequestApiManager.getMyrequests(new GetMyRequestApiListener() { MyRequestApiManager.getMyRequests(MyRequestActivity.this, new GetMyRequestApiListener() {
@Override @Override
public void onDoneApiCall(List<MyRequest> requestList) { public void onDoneApiCall(List<MyRequest> requestList) {
MyRequestsManager.handleGetRequest(requestList); MyRequestsManager.handleGetRequest(requestList);
...@@ -116,9 +137,14 @@ public class MyRequestActivity extends AppCompatActivity { ...@@ -116,9 +137,14 @@ public class MyRequestActivity extends AppCompatActivity {
super.onPostExecute(syncStatus); super.onPostExecute(syncStatus);
if(progressDialog != null && progressDialog.isShowing()) { if(progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss(); progressDialog.dismiss();
} else {
mRefreshIcon.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);
} }
if(syncStatus == SyncStatus.SUCCESS) { if(syncStatus == SyncStatus.SUCCESS) {
setData(MyRequestsManager.getAllRequests()); mMyRequestList = MyRequestsManager.getAllRequests();
isProgressRequire = mMyRequestList.isEmpty();
setData(mMyRequestList);
} else { } else {
showErrorDialog(R.string.failed_to_fetch_my_request_string); showErrorDialog(R.string.failed_to_fetch_my_request_string);
} }
...@@ -149,6 +175,15 @@ public class MyRequestActivity extends AppCompatActivity { ...@@ -149,6 +175,15 @@ public class MyRequestActivity extends AppCompatActivity {
alert.show(); alert.show();
} }
@OnClick(R.id.toolbar_refresh_icon)
void onRefreshClicked() {
if(mApplication.isNetConnected()) {
new FetchMyRequestData().execute();
} else {
DialogUtils.showNoConnectionDialogWithCloseActivity(MyRequestActivity.this);
}
}
private void setData(final List<MyRequest> reqList) { private void setData(final List<MyRequest> reqList) {
Collections.sort(reqList, new StringDateComparator()); Collections.sort(reqList, new StringDateComparator());
......
package com.vsoft.uoflservicenow.ui; package com.vsoft.servicenow.ui;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
...@@ -22,15 +20,15 @@ import android.widget.Spinner; ...@@ -22,15 +20,15 @@ import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import com.google.android.gms.analytics.Tracker; import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.R;
import com.vsoft.uoflservicenow.db.managers.ReportIncidentValueManager; import com.vsoft.servicenow.db.managers.ReportIncidentValueManager;
import com.vsoft.uoflservicenow.db.models.Incident; import com.vsoft.servicenow.db.models.Incident;
import com.vsoft.uoflservicenow.enums.Impact; import com.vsoft.servicenow.enums.Impact;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.DBConstants; import com.vsoft.servicenow.utils.DBConstants;
import com.vsoft.uoflservicenow.utils.PrefManager; import com.vsoft.servicenow.utils.PrefManager;
import com.vsoft.uoflservicenow.utils.Util; import com.vsoft.servicenow.utils.Util;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
...@@ -41,7 +39,8 @@ import butterknife.OnClick; ...@@ -41,7 +39,8 @@ import butterknife.OnClick;
*/ */
public class ReportIncidentScreen extends AppCompatActivity { public class ReportIncidentScreen extends AppCompatActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar; @BindView(R.id.tool_bar_view)
Toolbar mToolbar;
@BindView(R.id.incident_impact_spinner) Spinner mImpactSpinner; @BindView(R.id.incident_impact_spinner) Spinner mImpactSpinner;
@BindView(R.id.incident_short_description_edit_text) EditText mShortDesEditText; @BindView(R.id.incident_short_description_edit_text) EditText mShortDesEditText;
@BindView(R.id.incident_impact_error_tv) TextView mImpactErrorTextView; @BindView(R.id.incident_impact_error_tv) TextView mImpactErrorTextView;
...@@ -128,11 +127,10 @@ public class ReportIncidentScreen extends AppCompatActivity { ...@@ -128,11 +127,10 @@ public class ReportIncidentScreen extends AppCompatActivity {
@OnClick(R.id.incident_submit_text_view) @OnClick(R.id.incident_submit_text_view)
void submitOnClicked(View view) { void submitOnClicked(View view) {
if (!hasValidateForm()) {
SharedPreferences sharedPreferences = getSharedPreferences(PrefManager.PREFERENCES_USER_VALUES_KEY, Context.MODE_PRIVATE);
String userSysId = sharedPreferences.getString(PrefManager.PREFERENCE_SYS_ID, "");
if(!userSysId.isEmpty()) {
Util.hideSoftKeyboard(ReportIncidentScreen.this, view); Util.hideSoftKeyboard(ReportIncidentScreen.this, view);
if (!hasValidateForm()) {
String userSysId = PrefManager.getSharedPref(ReportIncidentScreen.this, PrefManager.PREFERENCE_SYS_ID);
if(userSysId != null && !userSysId.isEmpty()) {
Util.createDynamicTableForIncidentFormValues(); Util.createDynamicTableForIncidentFormValues();
Incident incident = Incident.IncidentBuilder.anIncident() Incident incident = Incident.IncidentBuilder.anIncident()
.setImpact(mImpact) .setImpact(mImpact)
......
package com.vsoft.servicenow.ui;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import com.vsoft.servicenow.R;
import butterknife.ButterKnife;
/**
* Created by kunj on 05/01/17.
*/
public class SplashScreen extends Activity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splash_screen);
ButterKnife.bind(this);
startThread();
}
private void startThread() {
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
@Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(SplashScreen.this, LoginScreen.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
package com.vsoft.uoflservicenow.ui.supportviews; package com.vsoft.servicenow.ui.supportviews;
import android.app.DatePickerDialog; import android.app.DatePickerDialog;
import android.app.TimePickerDialog; import android.app.TimePickerDialog;
...@@ -11,8 +11,8 @@ import android.widget.DatePicker; ...@@ -11,8 +11,8 @@ import android.widget.DatePicker;
import android.widget.TextView; import android.widget.TextView;
import android.widget.TimePicker; import android.widget.TimePicker;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.uoflservicenow.utils.Constants; import com.vsoft.servicenow.R;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
......
package com.vsoft.uoflservicenow.utils; package com.vsoft.servicenow.utils;
import com.vsoft.uoflservicenow.db.models.UiPolicyAction; import com.vsoft.servicenow.db.models.UiPolicyAction;
/** /**
* Created by kunj on 6/10/16. * Created by kunj on 6/10/16.
......
package com.vsoft.uoflservicenow.utils; package com.vsoft.servicenow.utils;
/** /**
* @since 1.0 * @since 1.0
......
package com.vsoft.uoflservicenow.utils; package com.vsoft.servicenow.utils;
import android.util.Log; import android.util.Log;
......
package com.vsoft.uoflservicenow.utils; package com.vsoft.servicenow.utils;
import com.vsoft.uoflservicenow.BuildConfig; import com.vsoft.servicenow.BuildConfig;
import com.vsoft.servicenow.AppConfig;
/** /**
* @author Kunj on 11/8/16. * @author Kunj on 11/8/16.
...@@ -8,11 +9,7 @@ import com.vsoft.uoflservicenow.BuildConfig; ...@@ -8,11 +9,7 @@ import com.vsoft.uoflservicenow.BuildConfig;
*/ */
public class Constants { public class Constants {
public static final String GRANT_TYPE = "password"; public static final String TAG = AppConfig.APP_INTERNAL_NAME;
public static final String CLIENT_ID = "ac0dd3408c1031006907010c2cc6ef6d";
public static final String CLIENT_SECRET = "oklj6znxv3o9jmyn2mlp";
public static final String TAG = "UofLCatalogue";
public static final String[] month = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; public static final String[] month = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
/** /**
...@@ -36,10 +33,14 @@ public class Constants { ...@@ -36,10 +33,14 @@ public class Constants {
/** /**
* Broadcast custom intent * Broadcast custom intent
*/ */
public static final String APPLICATION_BROADCAST_INTENT = "application_broadcast";
public static final String APPLICATION_BROADCAST_DATA_ACTION = "action";
public static final String ACTION_SYNC = "action_sync"; public static final String ACTION_SYNC = "action_sync";
/**
* Broadcast custom intent
*/
public static final String APPLICATION_BROADCAST_INTENT = "application_broadcast";
public static final String APPLICATION_BROADCAST_DATA_ACTION = "action";
public static final String ACTION_PROMPT_LOGIN = "action_prompt_login";
/** /**
* Catalogue services post parameters * Catalogue services post parameters
*/ */
...@@ -51,6 +52,7 @@ public class Constants { ...@@ -51,6 +52,7 @@ public class Constants {
public static final String URL_PARAM_TABLE_SYS_ID = "table_sys_id"; public static final String URL_PARAM_TABLE_SYS_ID = "table_sys_id";
public static final String URL_PARAM_TABLE_NAME = "table_name"; public static final String URL_PARAM_TABLE_NAME = "table_name";
public static final String URL_PARAM_FILE_NAME = "file_name"; public static final String URL_PARAM_FILE_NAME = "file_name";
public static final String URL_PARAM_SYS_ID = "sys_id";
/** /**
* Debug logs * Debug logs
...@@ -60,8 +62,8 @@ public class Constants { ...@@ -60,8 +62,8 @@ public class Constants {
/** /**
* Decides the URLS used * Decides the URLS used
*/ */
private static final String DOMAIN_PRODUCTION = "https://ven01199.service-now.com/"; private static final String DOMAIN_PRODUCTION = AppConfig.DOMAIN_PRODUCTION;
private static final String DOMAIN_TEST = "https://uofltest.service-now.com/"; private static final String DOMAIN_TEST = AppConfig.DOMAIN_TEST;
private static final String API_PATH_PRODUCTION = "/api/now/table/"; private static final String API_PATH_PRODUCTION = "/api/now/table/";
private static final String API_PATH_TEST = "/api/now/table/"; private static final String API_PATH_TEST = "/api/now/table/";
...@@ -69,6 +71,23 @@ public class Constants { ...@@ -69,6 +71,23 @@ public class Constants {
private static final int BUILD_TYPE_DEBUG = 1; private static final int BUILD_TYPE_DEBUG = 1;
private static final int BUILD_TYPE_RELEASE = 2; private static final int BUILD_TYPE_RELEASE = 2;
/**
* Decides the Api auth data used
*/
private static final String API_AUTH_PARAM_USER_NAME_PRODUCTION = "vsoft.admin";
private static final String API_AUTH_PARAM_PASSWORD_PRODUCTION = "v50ft@123456";
private static final String API_AUTH_PARAM_USER_NAME_TEST = "a0kuma18";
private static final String API_AUTH_PARAM_PASSWORD_TEST = "v$0ftA$win";
public static final String API_AUTH_PARAM_USER_NAME = (BUILD_TYPE_RELEASE == BuildConfig.BUILD_TYPE_INT
? API_AUTH_PARAM_USER_NAME_PRODUCTION
: API_AUTH_PARAM_USER_NAME_TEST);
public static final String API_AUTH_PARAM_PASSWORD = (BUILD_TYPE_RELEASE == BuildConfig.BUILD_TYPE_INT
? API_AUTH_PARAM_PASSWORD_PRODUCTION
: API_AUTH_PARAM_PASSWORD_TEST);
private static final String API_PATH = (BUILD_TYPE_RELEASE == BuildConfig.BUILD_TYPE_INT private static final String API_PATH = (BUILD_TYPE_RELEASE == BuildConfig.BUILD_TYPE_INT
? API_PATH_PRODUCTION ? API_PATH_PRODUCTION
: API_PATH_TEST); : API_PATH_TEST);
...@@ -80,11 +99,11 @@ public class Constants { ...@@ -80,11 +99,11 @@ public class Constants {
/** /**
* Decides the Client data used * Decides the Client data used
*/ */
private static final String LOGIN_CLIENT_ID_PRODUCTION = "a40b3f05ae582600433c09623de6cbe4"; private static final String LOGIN_CLIENT_ID_PRODUCTION = AppConfig.LOGIN_CLIENT_ID_PRODUCTION;
private static final String LOGIN_CLIENT_SECRET_PRODUCTION = "t8SdV}crm&"; private static final String LOGIN_CLIENT_SECRET_PRODUCTION = AppConfig.LOGIN_CLIENT_SECRET_PRODUCTION;
private static final String LOGIN_CLIENT_ID_TEST = "8689966b6f8426001fbf10d078fc4cc5"; private static final String LOGIN_CLIENT_ID_TEST = AppConfig.LOGIN_CLIENT_ID_TEST;
private static final String LOGIN_CLIENT_SECRET_TEST = "tGm41IOL6i"; private static final String LOGIN_CLIENT_SECRET_TEST = AppConfig.LOGIN_CLIENT_SECRET_TEST;
public static final String LOGIN_CLIENT_ID = (BUILD_TYPE_RELEASE == BuildConfig.BUILD_TYPE_INT public static final String LOGIN_CLIENT_ID = (BUILD_TYPE_RELEASE == BuildConfig.BUILD_TYPE_INT
? LOGIN_CLIENT_ID_PRODUCTION ? LOGIN_CLIENT_ID_PRODUCTION
...@@ -95,23 +114,6 @@ public class Constants { ...@@ -95,23 +114,6 @@ public class Constants {
: LOGIN_CLIENT_SECRET_TEST); : LOGIN_CLIENT_SECRET_TEST);
/** /**
* Decides the Api auth data used
*/
private static final String API_AUTH_PARAM_USER_NAME_PRODUCTION = "vsoft.admin";
private static final String API_AUTH_PARAM_PASSWORD_PRODUCTION = "v50ft@123456";
private static final String API_AUTH_PARAM_USER_NAME_TEST = "a0kuma18";
private static final String API_AUTH_PARAM_PASSWORD_TEST = "v$0ftA$win";
public static final String API_AUTH_PARAM_USER_NAME = (BUILD_TYPE_RELEASE == BuildConfig.BUILD_TYPE_INT
? API_AUTH_PARAM_USER_NAME_PRODUCTION
: API_AUTH_PARAM_USER_NAME_TEST);
public static final String API_AUTH_PARAM_PASSWORD = (BUILD_TYPE_RELEASE == BuildConfig.BUILD_TYPE_INT
? API_AUTH_PARAM_PASSWORD_PRODUCTION
: API_AUTH_PARAM_PASSWORD_TEST);
/**
* Domain to use * Domain to use
*/ */
public static final String DOMAIN = DOMAIN_FROM_BUILD; public static final String DOMAIN = DOMAIN_FROM_BUILD;
...@@ -133,23 +135,23 @@ public class Constants { ...@@ -133,23 +135,23 @@ public class Constants {
public static final String RESPONSE_VARIABLES_UI_POLICY_ACTIONS = "ui_policy_actions"; public static final String RESPONSE_VARIABLES_UI_POLICY_ACTIONS = "ui_policy_actions";
/** /**
* Catalogue web services urls * Web services urls
*/ */
/*Login API */ /*Login API */
public static final String URL_POST_LOGIN_ITEM = "/oauth_token.do"; public static final String URL_POST_LOGIN_ITEM = "/oauth_token.do";
public static final String URL_REFRESH_LOGIN = URL_POST_LOGIN_ITEM;
/*Catalogue Category API */ /*Catalogue Category API */
public static final String URL_GET_CATALOGUE = API_PATH + "sc_category"; public static final String URL_GET_CATALOGUE = DOMAIN + AppConfig.URL_GET_CATALOGUE;
public static final String URL_GET_CATALOGUE_ORDER = DOMAIN + "api/uno33/uofl_mobile/catalohhome";
/*Catalogue Category Items API */ /*Catalogue Category Items API */
public static final String URL_GET_CATALOGUE_ITEM = API_PATH + "sc_cat_item"; public static final String URL_GET_CATALOGUE_ITEM = DOMAIN + AppConfig.URL_GET_CATALOGUE_ITEM;
/*Variable form API */ /*Variable form API */
public static final String URL_GET_VARIABLE = "/api/uno33/uofl_mobile/variables"; public static final String URL_GET_VARIABLE = AppConfig.URL_GET_VARIABLE;
public static final String URL_GET_UI_POLICY = "/api/uno33/uofl_mobile/uipolicy"; public static final String URL_GET_UI_POLICY = AppConfig.URL_GET_UI_POLICY;
public static final String URL_GET_VARIABLE_CHOICE = API_PATH + "question_choice"; public static final String URL_GET_VARIABLE_CHOICE = DOMAIN + AppConfig.URL_GET_VARIABLE_CHOICE;
public static final String URL_POST_CATALOGUE_ITEM = "api/uno33/uofl_mobile"; public static final String URL_POST_CATALOGUE_ITEM = AppConfig.URL_POST_CATALOGUE_ITEM;
public static final String URL_GET_REFERENCE = API_PATH; public static final String URL_GET_REFERENCE = API_PATH;
public static final String URL_POST_ATTACHMENT = DOMAIN + "api/now/v1/attachment/file"; public static final String URL_POST_ATTACHMENT = DOMAIN + "api/now/v1/attachment/file";
......
package com.vsoft.uoflservicenow.utils; package com.vsoft.servicenow.utils;
public interface DBConstants { public interface DBConstants {
//Tables //Tables
...@@ -8,10 +8,13 @@ public interface DBConstants { ...@@ -8,10 +8,13 @@ public interface DBConstants {
String TABLE_VARIABLE_CHOICES = "variable_choices"; String TABLE_VARIABLE_CHOICES = "variable_choices";
String TABLE_MY_INCIDENT = "my_incidents"; String TABLE_MY_INCIDENT = "my_incidents";
String TABLE_MY_REQUEST = "my_requests"; String TABLE_MY_REQUEST = "my_requests";
String TABLE_INCIDENT_INPUT = "incident_input"; String TABLE_MY_REQUEST_OPENED_BY = "my_request_opened_by";
String TABLE_MY_REQUEST_DETAIL = "my_request_detail";
String TABLE_MY_REQUEST_DESCRIPTION = "my_request_description";
String TABLE_INCIDENT_INPUT = "input_incident";
String TABLE_UI_POLICY_ITEM = "ui_policy_item"; String TABLE_UI_POLICY_ITEM = "ui_policy_item";
String TABLE_UI_POLICY_ACTION = "ui_policy_action"; String TABLE_UI_POLICY_ACTION = "ui_policy_action";
String TABLE_CATALOGUE_ITEM_INPUT = "catalogue_item_input"; String TABLE_CATALOGUE_ITEM_INPUT = "input_catalogue_item";
String TABLE_ATTACHMENT = "attachment"; String TABLE_ATTACHMENT = "attachment";
String ID = "_id"; String ID = "_id";
...@@ -161,6 +164,9 @@ public interface DBConstants { ...@@ -161,6 +164,9 @@ public interface DBConstants {
String REQUEST_SHORT_DESCRIPTION = "short_description"; String REQUEST_SHORT_DESCRIPTION = "short_description";
String REQUEST_SYS_UPDATED_ON = "sys_updated_on"; String REQUEST_SYS_UPDATED_ON = "sys_updated_on";
String REQUEST_APPROVAL = "approval"; String REQUEST_APPROVAL = "approval";
String REQUEST_STAGE = "stage";
String REQUEST_OPENED_BY_VALUE = "opened_by_value";
String REQUEST_ORDER_DISPLAY_VALUE = "request_display_value";
String REQUEST_SYNC_DIRTY = SYNC_DIRTY; String REQUEST_SYNC_DIRTY = SYNC_DIRTY;
/** /**
...@@ -171,9 +177,66 @@ public interface DBConstants { ...@@ -171,9 +177,66 @@ public interface DBConstants {
int INDEX_REQUEST_SHORT_DESCRIPTION = 2; int INDEX_REQUEST_SHORT_DESCRIPTION = 2;
int INDEX_REQUEST_SYS_UPDATED_ON = 3; int INDEX_REQUEST_SYS_UPDATED_ON = 3;
int INDEX_REQUEST_APPROVAL = 4; int INDEX_REQUEST_APPROVAL = 4;
int INDEX_REQUEST_SYNC_DIRTY = 5; int INDEX_REQUEST_STAGE = 5;
int INDEX_REQUEST_OPENED_BY_VALUE = 6;
int INDEX_REQUEST_ORDER_DISPLAY_VALUE = 7;
int INDEX_REQUEST_SYNC_DIRTY = 8;
int REQUEST_COLUMN_COUNT = 6; int REQUEST_COLUMN_COUNT = 9;
/**
* TABLE_MY_REQUEST_ORDER table
*/
String MY_REQUEST_ORDER_ID = ID;
String MY_REQUEST_ORDER_DISPLAY_VALUE = "display_value";
String MY_REQUEST_ORDER_LINK = "link";
String MY_REQUEST_ORDER_SYNC_DIRTY = SYNC_DIRTY;
/**
* TABLE_MY_REQUEST_ORDER table. *Use these only if you fetch all columns*
*/
int INDEX_MY_REQUEST_ORDER_ID = 0;
int INDEX_MY_REQUEST_ORDER_DISPLAY_VALUE = 1;
int INDEX_MY_REQUEST_ORDER_LINK = 2;
int INDEX_MY_REQUEST_ORDER_SYNC_DIRTY = 3;
int MY_REQUEST_ORDER_COLUMN_COUNT = 4;
/**
* TABLE_MY_REQUEST_OPENED_BY table
*/
String MY_REQUEST_OPENED_BY_ID = ID;
String MY_REQUEST_OPENED_BY_DISPLAY_VALUE = "display_value";
String MY_REQUEST_OPENED_BY_LINK = "link";
String MY_REQUEST_OPENED_BY_SYNC_DIRTY = SYNC_DIRTY;
/**
* TABLE_MY_REQUEST_OPENED_BY table. *Use these only if you fetch all columns*
*/
int INDEX_MY_REQUEST_OPENED_BY_ID = 0;
int INDEX_MY_REQUEST_OPENED_BY_DISPLAY_VALUE = 1;
int INDEX_MY_REQUEST_OPENED_BY_LINK = 2;
int INDEX_MY_REQUEST_OPENED_BY_SYNC_DIRTY = 3;
int MY_REQUEST_OPENED_BY_COLUMN_COUNT = 4;
/**
* TABLE_MY_REQUEST_DESCRIPTION table
*/
String MY_REQUEST_DESCRIPTION_ID = ID;
String MY_REQUEST_DESCRIPTION_DISPLAY_VALUE = "display_value";
String MY_REQUEST_DESCRIPTION_LINK = "link";
String MY_REQUEST_DESCRIPTION_SYNC_DIRTY = SYNC_DIRTY;
/**
* TABLE_MY_REQUEST_DESCRIPTION table. *Use these only if you fetch all columns*
*/
int INDEX_MY_REQUEST_DESCRIPTION_ID = 0;
int INDEX_MY_REQUEST_DESCRIPTION_DISPLAY_VALUE = 1;
int INDEX_MY_REQUEST_DESCRIPTION_LINK = 2;
int INDEX_MY_REQUEST_DESCRIPTION_SYNC_DIRTY = 3;
int MY_REQUEST_DESCRIPTION_COLUMN_COUNT = 4;
/** /**
* Incident Form table * Incident Form table
...@@ -215,7 +278,6 @@ public interface DBConstants { ...@@ -215,7 +278,6 @@ public interface DBConstants {
int UI_POLICY_ITEM_COLUMN_COUNT = 5; int UI_POLICY_ITEM_COLUMN_COUNT = 5;
/** /**
* UiPolicyAction table * UiPolicyAction table
*/ */
......
package com.vsoft.uoflservicenow.utils; package com.vsoft.servicenow.utils;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.R;
/** /**
* Created by krishna on 9/7/2016. * Created by krishna on 9/7/2016.
......
package com.vsoft.uoflservicenow.utils; package com.vsoft.servicenow.utils;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
......
package com.vsoft.uoflservicenow.utils; package com.vsoft.servicenow.utils;
import android.content.Context; import android.content.Context;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
......
package com.vsoft.uoflservicenow.utils; package com.vsoft.servicenow.utils;
import com.vsoft.uoflservicenow.enums.Operator; import com.vsoft.servicenow.enums.Operator;
/** /**
* Created by kunj on 6/10/16. * Created by kunj on 6/10/16.
......
package com.vsoft.servicenow.utils;
import android.content.Context;
import android.content.SharedPreferences;
/**
* Created by krishna on 08-31-2016.
*/
public class PrefManager {
//Login Preferences
public static final String PREFERENCE_USER_VALUES_KEY = "UserPrefs";
public static final String PREFERENCE_FIRST_NAME = "firstName";
public static final String PREFERENCE_LAST_NAME = "lastName";
public static final String PREFERENCE_SYS_ID = "sysId";
public static final String PREFERENCE_USER_FULL_NAME = "full_name";
public static final String PREFERENCE_USER_ID = "user_id";
public static final String PREFERENCE_USER_EMAIL_ID = "user_email_id";
/*Access Token */
public static final String PREFERENCE_LOGIN_VALUES_KEY = "LoginPrefs";
public static final String PREFERENCE_ACCESS_TOKEN = "access_token";
public static final String PREFERENCE_REFRESH_TOKEN = "refresh_token";
private static final String SHARED_PREFERENCE_NAME = PrefManager.class.getSimpleName();
public static void setSharedPref(Context context, String key, String data) {
SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCE_NAME,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
if (data == null) {
CatalogueLog.d(": Data is null, cannot save");
return;
}
editor.putString(key, data);
editor.apply();
}
public static String getSharedPref(Context context, String key) {
SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCE_NAME,
Context.MODE_PRIVATE);
return prefs.getString(key, null);
}
}
package com.vsoft.uoflservicenow.utils; package com.vsoft.servicenow.utils;
/** /**
* Created by Kunj on 18/8/16. * Created by Kunj on 18/8/16.
......
package com.vsoft.uoflservicenow.utils; package com.vsoft.servicenow.utils;
import android.content.Context; import android.content.Context;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
...@@ -24,21 +24,21 @@ import android.widget.TextView; ...@@ -24,21 +24,21 @@ import android.widget.TextView;
import com.google.android.gms.analytics.HitBuilders; import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker; import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.R;
import com.vsoft.uoflservicenow.db.models.CatalogueVariable; import com.vsoft.servicenow.db.models.CatalogueVariable;
import com.vsoft.uoflservicenow.db.models.Reference; import com.vsoft.servicenow.db.models.Reference;
import com.vsoft.uoflservicenow.db.models.VariableChoice; import com.vsoft.servicenow.db.models.VariableChoice;
import com.vsoft.uoflservicenow.db.models.VariableViewContainer; import com.vsoft.servicenow.db.models.VariableViewContainer;
import com.vsoft.uoflservicenow.enums.ViewType; import com.vsoft.servicenow.enums.ViewType;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import static com.vsoft.uoflservicenow.enums.ViewType.BREAK; import static com.vsoft.servicenow.enums.ViewType.BREAK;
import static com.vsoft.uoflservicenow.enums.ViewType.CHECK_BOX; import static com.vsoft.servicenow.enums.ViewType.CHECK_BOX;
/** /**
* Created by Kunj on 12/8/16. * Created by Kunj on 12/8/16.
......
package com.vsoft.uoflservicenow.api.managers;
import com.vsoft.uoflservicenow.api.RestClient;
import com.vsoft.uoflservicenow.api.interfaces.LoginApi;
import com.vsoft.uoflservicenow.api.listeners.get.GetUserLoginApiListener;
import com.vsoft.uoflservicenow.utils.CatalogueLog;
import java.io.IOException;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
/**
* Created by kvemulavada on 8/29/2016.
*/
public class LoginApiManger {
public static void submitLoginValues(String garntType, String clientId, String clientSecret, String userName, String password, GetUserLoginApiListener listener) {
final Retrofit retrofit = RestClient.getInitializedRestAdapterWithOutAuthorizationHeader();
Call<ResponseBody> call = retrofit.create(LoginApi.class).postLoginValues(garntType, clientId, clientSecret, userName, password);
try {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
ResponseBody body = response.body();
if (body != null) {
if (body.contentLength() != -1) {
listener.onDoneApiCall();
} else {
listener.onFailApiCall();
}
} else {
listener.onFailApiCall();
}
} catch (IOException e) {
CatalogueLog.e("LoginApiManger: submitLoginValues: IOException: ", e);
listener.onFailApiCall();
} catch (NullPointerException e) {
CatalogueLog.e("LoginApiManger: submitLoginValues: IOException: ", e);
listener.onFailApiCall();
}
}
}
package com.vsoft.uoflservicenow.db.models;
/**
* Created by kvemulavada on 8/29/2016.
*/
public class LoginItem {
public static class Json {
public static final String GRANT_TYPE = "grant_type";
public static final String CLIENT_ID = "client_id";
public static final String CLIENT_CECRET = "client_secret";
public static final String USER_NAME = "username";
public static final String PASSWORD = "password";
}
}
package com.vsoft.uoflservicenow.db.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* Created by kvemulavada on 8/30/2016.
*/
public class MyRequestOpenedBy {
@SerializedName("display_value")
@Expose
private String displayValue;
@SerializedName("link")
@Expose
private String link;
public String getDisplayValue() {
return displayValue;
}
public void setDisplayValue(String displayValue) {
this.displayValue = displayValue;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
}
package com.vsoft.uoflservicenow.db.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* Created by kvemulavada on 8/30/2016.
*/
public class MyRequestRequest {
@SerializedName("display_value")
@Expose
private String displayValue;
@SerializedName("link")
@Expose
private String link;
public String getDisplayValue() {
return displayValue;
}
public void setDisplayValue(String displayValue) {
this.displayValue = displayValue;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
}
package com.vsoft.uoflservicenow.db.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* Created by kvemulavada on 8/30/2016.
*/
public class MyRequestShortDes {
@SerializedName("display_value")
@Expose
private String displayValue;
@SerializedName("link")
@Expose
private String link;
public String getDisplayValue() {
return displayValue;
}
public void setDisplayValue(String displayValue) {
this.displayValue = displayValue;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
}
package com.vsoft.uoflservicenow.utils;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
/**
* Created by krishna on 08-31-2016.
*/
public class PrefManager {
private static volatile PrefManager pSelf = null;
String TAG = PrefManager.class.getSimpleName();
private SharedPreferences sharedPref = null;
private SharedPreferences.Editor editor = null;
//Login Preferences
public static final String PREFERENCES_USER_VALUES_KEY = "UserPrefs";
public static final String PREFERENCES_FIRST_NAME = "firstName";
public static final String PREFERENCE_LAST_NAME = "lastName";
public static final String PREFERENCE_SYS_ID = "sysId";
public static PrefManager getInstance(){
if(pSelf == null){
synchronized(PrefManager.class){
if(pSelf == null){
pSelf = new PrefManager();
}
}
}
return pSelf;
}
/**
* save username and password in shared preferences
* @param context
* @param firstname
* @param lastname
* @param sysid
*/
public static void saveUserDetailsInPreferences(Context context,String firstname,String lastname,String sysid)
{
SharedPreferences sharedPreferences = context.getSharedPreferences(PREFERENCES_USER_VALUES_KEY, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
/**
* some times we are getting a username with white space
* so we just removed here
*/
editor.putString(PREFERENCES_FIRST_NAME, firstname);
editor.putString(PREFERENCE_LAST_NAME, lastname);
editor.putString(PREFERENCE_SYS_ID, sysid);
editor.apply();
}
public void init(Context context){
sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
editor = sharedPref.edit();
}
//! Generic function to get boolean value for specified key.
public boolean getPrefValueBoolean(String mKey,boolean defValue){
return sharedPref.getBoolean(mKey,defValue);
}
//! Generic function to get int value for specified key.
public int getPrefValueInt(String mKey, int defValue){
return sharedPref.getInt(mKey, defValue);
}
//! Generic function to string value for specified key.
public String getPrefValueString(String mKey,String defValue){
return sharedPref.getString(mKey, defValue);
}
public Long getPrefValueLong(String mKey,Long defValue){
return sharedPref.getLong(mKey,defValue);
}
public void putPrefValueBoolean(String mKey,boolean mValue){
editor.putBoolean(mKey,mValue);
editor.commit();
}
public void putPrefValueInt(String mKey,int mValue){
editor.putInt(mKey, mValue);
editor.commit();
}
public void putPrefValueString(String mKey,String mValue){
editor.putString(mKey, mValue);
editor.commit();
}
public void putLong(String mKey,long mValue){
editor.putLong(mKey,mValue);
editor.commit();
}
}
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical"
style="@style/LightBackgroundStyle">
<include layout="@layout/toolbar"/> <include layout="@layout/toolbar_with_refresh_option"/>
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:background="@color/screen_bg_color">
<TextView <TextView
android:id="@+id/catalogue_item_screen_empty_text_view" android:id="@+id/catalogue_item_screen_empty_text_view"
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
style="@style/LightBackgroundStyle"> style="@style/LightBackgroundStyle">
<include layout="@layout/toolbar"/> <include layout="@layout/toolbar_with_refresh_option"/>
<ListView <ListView
android:id="@+id/catalogue_screen_list_view" android:id="@+id/catalogue_screen_list_view"
......
...@@ -3,14 +3,14 @@ ...@@ -3,14 +3,14 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
style="@style/LightBackgroundStyle"
android:weightSum="10"> android:weightSum="10">
<include layout="@layout/toolbar"/> <include layout="@layout/toolbar_with_refresh_option"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/screen_bg_color"
android:orientation="vertical" android:orientation="vertical"
android:padding="@dimen/normal_margin"> android:padding="@dimen/normal_margin">
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" android:gravity="center_vertical"
android:visibility="gone"> android:visibility="visible">
<TextView <TextView
android:id="@+id/variable_screen_submit_text_view" android:id="@+id/variable_screen_submit_text_view"
......
...@@ -11,12 +11,17 @@ ...@@ -11,12 +11,17 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@android:color/white" android:background="@android:color/white"
android:minHeight="?attr/actionBarSize" android:minHeight="?attr/actionBarSize"
app:titleTextColor="@color/tool_bar_title_color"> app:titleTextColor="@color/tool_bar_title_color"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp">
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true"> android:layout_marginLeft="@dimen/small_margin"
android:layout_marginRight="@dimen/small_margin">
<ImageView <ImageView
android:id="@+id/nav_back" android:id="@+id/nav_back"
...@@ -24,7 +29,7 @@ ...@@ -24,7 +29,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:src="@mipmap/ic_home_icon" /> android:src="@drawable/home_icon" />
<TextView <TextView
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title" style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
...@@ -35,6 +40,14 @@ ...@@ -35,6 +40,14 @@
android:text="@string/app_name" android:text="@string/app_name"
android:textColor="@color/tool_bar_title_color" /> android:textColor="@color/tool_bar_title_color" />
<ImageView
android:id="@+id/home_screen_logout_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/logout_icon" />
</RelativeLayout> </RelativeLayout>
</android.support.v7.widget.Toolbar> </android.support.v7.widget.Toolbar>
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
android:orientation="vertical" android:orientation="vertical"
style="@style/LightBackgroundStyle"> style="@style/LightBackgroundStyle">
<include layout="@layout/toolbar"/> <include
layout="@layout/toolbar"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
style="@style/LightBackgroundStyle"> style="@style/LightBackgroundStyle">
<include layout="@layout/toolbar"/> <include layout="@layout/toolbar_with_refresh_option"/>
<ListView <ListView
android:id="@+id/my_incidents_screen_list_view" android:id="@+id/my_incidents_screen_list_view"
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
android:background="@color/screen_bg_color" android:background="@color/screen_bg_color"
android:orientation="vertical"> android:orientation="vertical">
<include layout="@layout/toolbar" /> <include layout="@layout/toolbar_with_refresh_option" />
<ListView <ListView
android:id="@+id/request_screen_list_view" android:id="@+id/request_screen_list_view"
......
...@@ -13,24 +13,4 @@ ...@@ -13,24 +13,4 @@
app:contentInsetRight="0dp" app:contentInsetRight="0dp"
app:contentInsetStart="0dp"> app:contentInsetStart="0dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right">
<ImageView
android:id="@+id/toolbar_refresh_icon"
android:layout_width="@dimen/uofl_tool_bar_refresh_button_width"
android:layout_height="@dimen/uofl_tool_bar_refresh_button_height"
android:src="@drawable/refresh_icon" />
<ProgressBar
android:id="@+id/toolbar_progress_icon"
android:layout_width="@dimen/uofl_tool_bar_refresh_button_width"
android:layout_height="@dimen/uofl_tool_bar_refresh_button_height"
android:indeterminate="false"
android:indeterminateDrawable="@drawable/circular"
android:visibility="gone" />
</RelativeLayout>
</android.support.v7.widget.Toolbar> </android.support.v7.widget.Toolbar>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tool_bar_view"
style="@style/WhiteBackgroundStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:minHeight="?attr/actionBarSize"
android:padding="0dp"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right">
<ImageView
android:id="@+id/toolbar_refresh_icon"
android:layout_width="@dimen/uofl_tool_bar_refresh_button_width"
android:layout_height="@dimen/uofl_tool_bar_refresh_button_height"
android:src="@drawable/refresh_icon" />
<ProgressBar
android:id="@+id/toolbar_progress_icon"
android:layout_width="@dimen/uofl_tool_bar_refresh_button_width"
android:layout_height="@dimen/uofl_tool_bar_refresh_button_height"
android:indeterminate="false"
android:indeterminateDrawable="@drawable/circular"
android:visibility="gone" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
\ No newline at end of file
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<string name="none_string">-None-</string> <string name="none_string">-None-</string>
<string name="yes_string">Yes</string> <string name="yes_string">Yes</string>
<string name="no_string">No</string> <string name="no_string">No</string>
<string name="ok_string">Ok</string>
<string name="search_for_reference_string">Reference</string> <string name="search_for_reference_string">Reference</string>
<string name="home_screen_string">Home Screen</string> <string name="home_screen_string">Home Screen</string>
<string name="login_screen_string">Login Screen</string> <string name="login_screen_string">Login Screen</string>
...@@ -38,6 +39,7 @@ ...@@ -38,6 +39,7 @@
<string name="failed_to_fetch_user_detail_string">Failed to fetch User Details.</string> <string name="failed_to_fetch_user_detail_string">Failed to fetch User Details.</string>
<!--Login Screen--> <!--Login Screen-->
<string name="prompt_relogin_login_expired">Login expired, please login again&#8230;</string>
<string name="login_screen_login_string">Login</string> <string name="login_screen_login_string">Login</string>
<string name="login_screen_logging_in_loading_string">Logging in&#8230;</string> <string name="login_screen_logging_in_loading_string">Logging in&#8230;</string>
<string name="login_screen_getting_user_detail_loading_string">Getting user details&#8230;</string> <string name="login_screen_getting_user_detail_loading_string">Getting user details&#8230;</string>
...@@ -93,4 +95,13 @@ ...@@ -93,4 +95,13 @@
<string name="connection_alert_dialog_message">Please check your device settings to ensure you have a working internet connection.</string> <string name="connection_alert_dialog_message">Please check your device settings to ensure you have a working internet connection.</string>
<string name="cancel">Cancel</string> <string name="cancel">Cancel</string>
<string name="settings">Settings</string> <string name="settings">Settings</string>
<!--Catalogue Variable form screen - key for pre fill value-->
<string name="catalogue_user_full_name">full_name</string>
<string name="catalogue_user_id">user_id</string>
<string name="catalogue_user_email_id">email_address</string>
<!--Home Screen-->
<string name="home_screen_logout_confirmation_msg_string">Are you sure you want to logout?</string>
</resources> </resources>
package com.vsoft.servicenow;
/**
* @author Kunj on 05/01/17.
*/
public class AppConfig {
public static final String APP_INTERNAL_NAME = "UofL ServiceNow";
public static final String DOMAIN_PRODUCTION = "https://ven01199.service-now.com/";
public static final String DOMAIN_TEST = "https://uofltest.service-now.com/";
public static final String LOGIN_CLIENT_ID_PRODUCTION = "ac0dd3408c1031006907010c2cc6ef6d";
public static final String LOGIN_CLIENT_SECRET_PRODUCTION = "oklj6znxv3o9jmyn2mlp";
public static final String LOGIN_CLIENT_ID_TEST = "ac0dd3408c1031006907010c2cc6ef6d";
public static final String LOGIN_CLIENT_SECRET_TEST = "oklj6znxv3o9jmyn2mlp";
/**
* Web services urls
*/
/*Catalogue Category API */
public static final String URL_GET_CATALOGUE = "api/uno33/uofl_mobile/catalogue_screen";
/*Catalogue Category Items API */
public static final String URL_GET_CATALOGUE_ITEM = "api/uno33/uofl_mobile/catalog_item";
/*Variable form API */
public static final String URL_GET_VARIABLE = "api/uno33/uofl_mobile/catalogue_variable_screen";
public static final String URL_GET_UI_POLICY = "/api/uno33/uofl_mobile/uipolicy";
public static final String URL_GET_VARIABLE_CHOICE = "/api/uno33/uofl_mobile/question_choice";
public static final String URL_POST_CATALOGUE_ITEM = "api/uno33/uofl_mobile";
}
package com.vsoft.uoflservicenow.adapters; package com.vsoft.servicenow.adapters;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
...@@ -9,7 +9,7 @@ import android.widget.BaseAdapter; ...@@ -9,7 +9,7 @@ import android.widget.BaseAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.R;
/** /**
* Created by kunj on 18/8/16. * Created by kunj on 18/8/16.
......
package com.vsoft.uoflservicenow.ui; package com.vsoft.servicenow.ui;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.widget.GridView; import android.widget.GridView;
import com.google.android.gms.analytics.Tracker; import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.servicenow.utils.Util;
import com.vsoft.uoflservicenow.R; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.adapters.HomeScreenAdapter; import com.vsoft.servicenow.R;
import com.vsoft.uoflservicenow.utils.Util; import com.vsoft.servicenow.adapters.HomeScreenAdapter;
import com.vsoft.servicenow.utils.PrefManager;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnItemClick; import butterknife.OnItemClick;
/** /**
...@@ -56,4 +60,33 @@ public class HomeScreen extends AppCompatActivity { ...@@ -56,4 +60,33 @@ public class HomeScreen extends AppCompatActivity {
startActivity(new Intent(HomeScreen.this, MyRequestActivity.class)); startActivity(new Intent(HomeScreen.this, MyRequestActivity.class));
} }
} }
@OnClick(R.id.home_screen_logout_image_view)
void logoutOnClicked() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.home_screen_logout_confirmation_msg_string)
.setCancelable(false)
.setPositiveButton(R.string.ok_string, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_ACCESS_TOKEN, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_REFRESH_TOKEN, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_LAST_NAME, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_SYS_ID, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_FIRST_NAME, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_USER_ID, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_USER_FULL_NAME, "");
PrefManager.setSharedPref(HomeScreen.this, PrefManager.PREFERENCE_USER_EMAIL_ID, "");
Intent loginIntent = new Intent(HomeScreen.this, LoginScreen.class);
loginIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(loginIntent);
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
} }
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/splash_screen_background" />
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="home_screen_array">
<item>Report Incident</item>
<item>Order Services</item>
<item>My Incidents</item>
<item>My Requests</item>
</string-array>
<array name="home_screen_icon_array">
<item>@drawable/ic_myincident_icon</item>
<item>@drawable/ic_order_service_icon</item>
<item>@drawable/ic_my_incidents_icon</item>
<item>@drawable/ic_my_requiest_icon</item>
</array>
<string-array name="incident_impact_array">
<item>-None-</item>
<item>1 - High</item>
<item>2 - Medium</item>
<item>3 - Low</item>
</string-array>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#F44336</color>
<color name="colorPrimaryDark">#D32F2F</color>
<color name="colorAccent">#FF5252</color>
<color name="item_gb_color">#000000</color>
<color name="error_color">#FF0000</color>
<color name="name_null_view_color">#88FFA500</color>
<color name="view_not_implemented_color">#88ff0000</color>
<color name="home_screen_bg_color">@color/colorPrimary</color>
<color name="screen_bg_color">#c2d1d3</color>
<color name="bg_border_color">#d6d6d6</color>
<color name="back_button_bg_color">#4f0307</color>
<color name="submit_button_bg_color">#e31b22</color>
<color name="divider_color">#c9c8cc</color>
<color name="tool_bar_title_color">#E41B23</color>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--Margins-->
<dimen name="large_text_size">18sp</dimen>
<!--Text size-->
<dimen name="small_text_size">12sp</dimen>
<dimen name="normal_text_size">16sp</dimen>
<dimen name="extra_normal_text_size">20sp</dimen>
<dimen name="homescreen_text_size">18sp</dimen>
<dimen name="catalogue_category_and_item_list_view_divider_height">5dp</dimen>
<dimen name="list_view_divider_height">1dp</dimen>
<!--Home Screen-->
<dimen name="home_screen_image_margin">10dp</dimen>
<dimen name="home_screen_image_height">70dp</dimen>
<dimen name="list_item_height">100dp</dimen>
<!--Margins-->
<dimen name="small_margin">5dp</dimen>
<dimen name="normal_margin">10dp</dimen>
<dimen name="large_margin">15dp</dimen>
<dimen name="extra_large_margin">20dp</dimen>
<!--Text size-->
<dimen name="ruquest_status_text_size">15sp</dimen>
<dimen name="ruquest_descps_text_size">18sp</dimen>
<!-- MyRequest Activity-->
<dimen name="my_request_top">15dp</dimen>
<dimen name="my_request_left">15dp</dimen>
<dimen name="my_request_right">10dp</dimen>
<dimen name="my_request_new_top">18dp</dimen>
<dimen name="my_request_text_bottom">2dp</dimen>
<!--Report Incident screen-->
<dimen name="impact_spinner_drop_down_height">50dp</dimen>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="incident_from_short_description_text_limit">160</integer>
</resources>
\ No newline at end of file
<resources>
<string name="app_name">UofL ServiceNow</string>
<string name="set_string">Set</string>
<string name="submit_string">Submit</string>
<string name="back_string">Back</string>
<string name="error_string">* Required</string>
<string name="none_string">-None-</string>
<string name="yes_string">Yes</string>
<string name="no_string">No</string>
<string name="ok_string">Ok</string>
<string name="search_for_reference_string">Reference</string>
<string name="home_screen_string">Home Screen</string>
<string name="login_screen_string">Login Screen</string>
<string name="loading_string">Loading&#8230;</string>
<string name="select_date_string">Select Date</string>
<string name="select_date_and_time_string">Select Date &#038; Time</string>
<string name="name_null_view_string">Not rendering (name not available)</string>
<string name="view_not_implemented_string">Not Implemented: %s</string>
<string name="approved">Approved</string>
<string name="notrequest">Not Yet Requested</string>
<string name="requested">Requested</string>
<string name="rejected">Rejected</string>
<string name="date_string">%1$s %2$s, %3$s</string>
<string name="date_and_time_string">%1$s:%2$s</string>
<!--Failed to fetch-->
<string name="failed_to_fetch_catalogue_category_string">Failed to fetch Catalogue Category.</string>
<string name="failed_to_fetch_my_request_string">Failed to fetch requests</string>
<string name="failed_to_fetch_catalogue_category_items_string">Failed to fetch Catalogue Category Items.</string>
<string name="failed_to_fetch_catalogue_form_string">Failed to fetch Form.</string>
<string name="failed_to_fetch_reference_string">Failed to fetch References.</string>
<string name="failed_to_submit_form_string">Failed to submit form.</string>
<string name="failed_to_fetch_incident_string">Failed to fetch incidents.</string>
<string name="failed_to_fetch_user_detail_string">Failed to fetch User Details.</string>
<!--Login Screen-->
<string name="prompt_relogin_login_expired">Login expired, please login again&#8230;</string>
<string name="login_screen_login_string">Login</string>
<string name="login_screen_logging_in_loading_string">Logging in&#8230;</string>
<string name="login_screen_getting_user_detail_loading_string">Getting user details&#8230;</string>
<string name="login_screen_invalid_username_and_password_string">Invalid username and password</string>
<string name="user_detail_not_available">Unable to fetch user details.</string>
<string name="user_error">Please enter username</string>
<string name="pasw_error">Please enter password</string>
<string name="username_string">Username</string>
<string name="password_string">Password</string>
<!--Variable Screen-->
<string name="variable_form_misc_info_string">%1$s [add %2$.2f]</string>
<string name="variable_form_header_string">Submit Order</string>
<string name="variable_form_view_mandatory_sign_string">&lt;font color="#FF0000"&gt;*&lt;/font&gt;</string>
<string name="variable_form_reference_dialog_title_string">Search \'%s\'</string>
<string name="variable_form_radio_text_string">%d</string>
<string name="variable_form_ui_page_button_label_string">Add Attachment</string>
<string name="variable_form_ui_page_no_selected_attachment_string">Not Selected</string>
<string name="custom_setting_storage_permission_dialog_msg_string">To use this feature, please go to Settings -> Apps -> %s -> Permissions and enable \'Storage\' permission</string>
<string name="variable_form_back_navigation_string">Are you sure you want to navigate away?</string>
<string name="variable_form_order_successful_submission_string">Your Order has been submitted successfully</string>
<string name="variable_form_reference_no_result_string">No Result</string>
<string name="Variable_form_short_description_anchor_line_break_css"><![CDATA[
<style>
a {
word-break: break-all;
}
</style>
]]></string>
<!--Catalogue Item Screen-->
<string name="no_catalogue_item_string">No Catalogue Items&#8230;</string>
<!--Catalogue Screen-->
<string name="catalogue_category_string">Order Services</string>
<string name="my_reques_string">My Requests</string>
<!--Incident screen-->
<string name="incident_form_report_incident_text_string">Report Incident</string>
<string name="incident_form_top_text_string">Create an Incident record to report and request assistance with an issue you are having\n\nRequest assistance with an issue you are having. An incident record will be created and managed through to successful resolution. You will also be notified of progress.</string>
<string name="incident_form_impact_text_string">Impact &lt;font color="#FF0000"&gt;*&lt;/font&gt;</string>
<string name="incident_form_describe_your_issue_text_string">Please Describe Your Issue below &lt;font color="#FF0000"&gt;*&lt;/font&gt;(Max %d)</string>
<string name="incident_item_text_string"><![CDATA[<b>Number: </b>%1$s<br><br><b>Opened: </b>%2$s<br><br><b>Short Description: </b>%3$s]]></string>
<string name="incident_form_short_description_limit_error_text_string">Max limit exceeded by %d</string>
<!--My Incidents-->
<string name="my_incidents_text_string">My Incidents</string>
<string name="my_incidents_item_text_string"><![CDATA[<b>Number: </b>%1$s<br><br><b>Item: </b>%2$s<br><br><b>Updated: </b>%3$s<br><br><b>Request: </b>%4$s<br><br><b>Opened by: </b>%5$s<br><br><b>Stage: </b>%6$s]]></string>
<string name="connection_alert_dialog_title">No Connection Available</string>
<string name="connection_alert_dialog_message">Please check your device settings to ensure you have a working internet connection.</string>
<string name="cancel">Cancel</string>
<string name="settings">Settings</string>
<!--Catalogue Variable form screen - key for pre fill value-->
<string name="catalogue_user_full_name">full_name</string>
<string name="catalogue_user_id">user_id</string>
<string name="catalogue_user_email_id">email_address</string>
<!--Home Screen-->
<string name="home_screen_logout_confirmation_msg_string">Are you sure you want to logout?</string>
</resources>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowNoTitle">true</item>
<item name="actionOverflowMenuStyle">@style/OverflowMenu</item>
</style>
<style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
<!-- Required for pre-Lollipop. -->
<item name="overlapAnchor">false</item>
<!-- Required for Lollipop. -->
<item name="android:overlapAnchor">false</item>
</style>
<style name="WhiteBackgroundStyle" parent="@style/Theme.AppCompat">
<item name="android:background">@android:color/white</item>
</style>
<style name="LightBackgroundStyle" parent="@style/Theme.AppCompat">
<item name="android:background">@color/screen_bg_color</item>
</style>
<style name="DatePickerCustomDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/white</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
<item name="editTextStyle">@android:style/Widget.EditText</item>
</style>
<style name="CustomDialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Replace placeholder ID with your tracking ID -->
<string name="ga_trackingId">UA-83545030-1</string>
<!-- Enable automatic activity tracking -->
<bool name="ga_autoActivityTracking">true</bool>
<!-- Enable automatic exception tracking -->
<bool name="ga_reportUncaughtExceptions">true</bool>
</resources>
\ No newline at end of file
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