Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Krishna Vemulavada
/
vera_2.1_app
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
93aa5d9e
authored
May 04, 2018
by
Kunj Gupta
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Worked on the code qualitiy for ChatServer API call.
parent
b3fc35a5
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
272 additions
and
75 deletions
app/src/main/java/com/vsoft/servicenow/CatalogueApplication.java
app/src/main/java/com/vsoft/servicenow/api/interfaces/ChatServerApi.java
app/src/main/java/com/vsoft/servicenow/api/listeners/get/GetChatServerApiListener.java
app/src/main/java/com/vsoft/servicenow/api/managers/ChatServerApiManager.java
app/src/main/java/com/vsoft/servicenow/api/pojos/ChatServerApiResponse.java
app/src/main/java/com/vsoft/servicenow/service/SyncService.java
app/src/main/java/com/vsoft/servicenow/ui/ChatActivity.java
app/src/main/java/com/vsoft/servicenow/ui/LoginScreen.java
app/src/main/java/com/vsoft/servicenow/utils/Constants.java
app/src/main/java/com/vsoft/servicenow/utils/PrefManager.java
app/src/vportal/java/com/vsoft/servicenow/AppConfig.java
app/src/main/java/com/vsoft/servicenow/CatalogueApplication.java
View file @
93aa5d9e
package
com
.
vsoft
.
servicenow
;
import
android.app.Application
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
...
...
@@ -10,11 +9,10 @@ import android.net.ConnectivityManager;
import
android.net.NetworkInfo
;
import
android.support.multidex.MultiDexApplication
;
import
android.support.v4.content.LocalBroadcastManager
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.widget.Toast
;
import
com.androidquery.AQuery
;
import
com.androidquery.callback.AjaxStatus
;
import
com.crashlytics.android.Crashlytics
;
import
com.github.nkzawa.socketio.client.IO
;
import
com.github.nkzawa.socketio.client.Socket
;
...
...
@@ -26,11 +24,6 @@ import com.vsoft.servicenow.service.SyncService;
import
com.vsoft.servicenow.ui.LoginScreen
;
import
com.vsoft.servicenow.utils.Constants
;
import
com.vsoft.servicenow.utils.PrefManager
;
import
com.vsoft.servicenow.utils.Util
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.net.URISyntaxException
;
import
io.fabric.sdk.android.Fabric
;
...
...
@@ -93,8 +86,18 @@ public class CatalogueApplication extends MultiDexApplication {
/*Database is created*/
initializeDatabase
();
configureURL
();
if
(
mSocket
==
null
)
{
Constants
.
CHAT_SERVER_URL
=
PrefManager
.
getSharedPref
(
mContext
,
PrefManager
.
PREFERENCE_CHAT_SERVER_URL
);
if
(!
TextUtils
.
isEmpty
(
Constants
.
CHAT_SERVER_URL
))
{
initializeSocket
();
}
}
IntentFilter
intentFilter
=
new
IntentFilter
();
intentFilter
.
addAction
(
ConnectivityManager
.
CONNECTIVITY_ACTION
);
mNetworkChangeReceiver
=
new
NetworkChangeReceiver
();
registerReceiver
(
mNetworkChangeReceiver
,
intentFilter
);
}
@Override
...
...
@@ -140,38 +143,15 @@ public class CatalogueApplication extends MultiDexApplication {
return
netInfo
!=
null
&&
netInfo
.
isConnected
();
}
p
rivate
void
initializeSocket
()
{
p
ublic
void
initializeSocket
()
{
try
{
mSocket
=
IO
.
socket
(
Constants
.
CHAT_SERVER_URL
);
}
catch
(
URISyntaxException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
Socket
getSocket
()
{
return
mSocket
;
}
private
void
configureURL
(){
AQuery
aq
;
aq
=
new
AQuery
(
this
);
aq
.
ajax
(
"http://ai.test.vsoftconsulting.com:3000/?env=test"
,
JSONObject
.
class
,
this
,
"jsonCallback"
);
}
public
void
jsonCallback
(
String
url
,
JSONObject
json
,
AjaxStatus
status
)
{
//When JSON is not null
try
{
if
(
json
!=
null
)
{
AppConfig
.
CHAT_SERVER_URL_STAGING
=
json
.
getString
(
"chatbot_url"
);
if
(
Util
.
isChatItemEnabled
())
{
initializeSocket
();
}
IntentFilter
intentFilter
=
new
IntentFilter
();
intentFilter
.
addAction
(
ConnectivityManager
.
CONNECTIVITY_ACTION
);
mNetworkChangeReceiver
=
new
NetworkChangeReceiver
();
registerReceiver
(
mNetworkChangeReceiver
,
intentFilter
);
}
}
catch
(
JSONException
e
)
{
Log
.
i
(
"Exception e"
,
e
+
""
);
}
}
}
app/src/main/java/com/vsoft/servicenow/api/interfaces/ChatServerApi.java
0 → 100644
View file @
93aa5d9e
package
com
.
vsoft
.
servicenow
.
api
.
interfaces
;
import
com.vsoft.servicenow.utils.Constants
;
import
okhttp3.ResponseBody
;
import
retrofit2.Call
;
import
retrofit2.http.GET
;
/**
* @since 1.0
* @author Kunj on 04/05/18.
*
*/
public
interface
ChatServerApi
{
// Get chat server detail
@GET
(
Constants
.
URL_GET_API_CHAT_SERVER
)
Call
<
ResponseBody
>
getChatServerUrl
();
}
app/src/main/java/com/vsoft/servicenow/api/listeners/get/GetChatServerApiListener.java
0 → 100644
View file @
93aa5d9e
package
com
.
vsoft
.
servicenow
.
api
.
listeners
.
get
;
import
com.vsoft.servicenow.api.pojos.ChatServerApiResponse
;
/**
* @since 1.0
* @author Kunj on 04/05/2018
*
*/
public
interface
GetChatServerApiListener
{
void
onDoneApiCall
(
ChatServerApiResponse
chatServerApiResponse
);
void
onFailApiCall
();
}
app/src/main/java/com/vsoft/servicenow/api/managers/ChatServerApiManager.java
0 → 100644
View file @
93aa5d9e
package
com
.
vsoft
.
servicenow
.
api
.
managers
;
import
android.content.Context
;
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.ChatServerApi
;
import
com.vsoft.servicenow.api.listeners.get.GetChatServerApiListener
;
import
com.vsoft.servicenow.api.pojos.ChatServerApiResponse
;
import
com.vsoft.servicenow.enums.SyncStatus
;
import
com.vsoft.servicenow.utils.CatalogueLog
;
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 Kunj on 04/05/2018.
*/
public
class
ChatServerApiManager
{
public
static
SyncStatus
getChatServerUrl
(
GetChatServerApiListener
listener
)
{
final
Retrofit
retrofit
=
RestClient
.
getInitializedRestAdapterWithOutAuthorizationHeader
();
Call
<
ResponseBody
>
call
=
retrofit
.
create
(
ChatServerApi
.
class
).
getChatServerUrl
();
try
{
//Retrofit synchronous call
Response
<
ResponseBody
>
response
=
call
.
execute
();
if
(
response
.
isSuccessful
())
{
try
{
JSONObject
jsonObject
=
new
JSONObject
(
response
.
body
().
string
());
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
(
"ChatServerApiManager: getChatServerUrl: 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
(
"ChatServerApiManager: getChatServerUrl: 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
(
"ChatServerApiManager: getChatServerUrl: deserialize: float.class: NumberFormatException: "
,
e
);
}
return
value
;
}
})
.
create
();
ChatServerApiResponse
chatServerApiResponse
=
gson
.
fromJson
(
jsonObject
.
toString
(),
ChatServerApiResponse
.
class
);
listener
.
onDoneApiCall
(
chatServerApiResponse
);
return
SyncStatus
.
SUCCESS
;
}
catch
(
JSONException
e
)
{
CatalogueLog
.
e
(
"ChatServerApiManager: getChatServerUrl: onResponse: "
,
e
);
return
SyncStatus
.
FAIL
;
}
catch
(
IOException
e
)
{
CatalogueLog
.
e
(
"ChatServerApiManager: getChatServerUrl: onResponse: "
,
e
);
return
SyncStatus
.
FAIL
;
}
}
else
{
CatalogueLog
.
d
(
"getChatServerUrl: getChatServerUrl: response is not success"
);
listener
.
onFailApiCall
();
return
SyncStatus
.
FAIL
;
}
}
catch
(
IOException
e
)
{
CatalogueLog
.
e
(
"ChatServerApiManager: getChatServerUrl: IOException: "
,
e
);
return
SyncStatus
.
FAIL
;
}
catch
(
NullPointerException
e
)
{
CatalogueLog
.
e
(
"ChatServerApiManager: getChatServerUrl: NullPointerException: "
,
e
);
return
SyncStatus
.
FAIL
;
}
}
}
app/src/main/java/com/vsoft/servicenow/api/pojos/ChatServerApiResponse.java
0 → 100644
View file @
93aa5d9e
package
com
.
vsoft
.
servicenow
.
api
.
pojos
;
import
com.google.gson.annotations.Expose
;
import
com.google.gson.annotations.SerializedName
;
/**
* Created by Kunj on 05/04/18.
*/
public
class
ChatServerApiResponse
{
@SerializedName
(
"sn_base_url"
)
@Expose
private
String
snBaseUrl
;
@SerializedName
(
"chatbot_url"
)
@Expose
private
String
chatbotUrl
;
@SerializedName
(
"env"
)
@Expose
private
String
env
;
public
String
getSnBaseUrl
()
{
return
snBaseUrl
;
}
public
void
setSnBaseUrl
(
String
snBaseUrl
)
{
this
.
snBaseUrl
=
snBaseUrl
;
}
public
String
getChatbotUrl
()
{
return
chatbotUrl
;
}
public
void
setChatbotUrl
(
String
chatbotUrl
)
{
this
.
chatbotUrl
=
chatbotUrl
;
}
public
String
getEnv
()
{
return
env
;
}
public
void
setEnv
(
String
env
)
{
this
.
env
=
env
;
}
}
app/src/main/java/com/vsoft/servicenow/service/SyncService.java
View file @
93aa5d9e
...
...
@@ -4,14 +4,17 @@ import android.app.IntentService;
import
android.content.Intent
;
import
com.vsoft.servicenow.CatalogueApplication
;
import
com.vsoft.servicenow.api.listeners.get.GetChatServerApiListener
;
import
com.vsoft.servicenow.api.listeners.post.PostAttachmentApiListener
;
import
com.vsoft.servicenow.api.listeners.post.PostHRCaseAttachmentApiListener
;
import
com.vsoft.servicenow.api.listeners.post.PostHRCaseVariableFormApiListener
;
import
com.vsoft.servicenow.api.listeners.post.PostIncidentApiListener
;
import
com.vsoft.servicenow.api.listeners.post.PostVariableFormApiListener
;
import
com.vsoft.servicenow.api.managers.CatalogueVariableApiManager
;
import
com.vsoft.servicenow.api.managers.ChatServerApiManager
;
import
com.vsoft.servicenow.api.managers.HRCaseVariableApiManager
;
import
com.vsoft.servicenow.api.managers.IncidentApiManager
;
import
com.vsoft.servicenow.api.pojos.ChatServerApiResponse
;
import
com.vsoft.servicenow.api.pojos.HRCaseVariableSubmitApiResponse
;
import
com.vsoft.servicenow.db.DBConstants
;
import
com.vsoft.servicenow.db.managers.AttachmentManager
;
...
...
@@ -69,14 +72,47 @@ public class SyncService extends IntentService {
@Override
protected
void
onHandleIntent
(
Intent
intent
)
{
CatalogueApplication
mA
pplication
=
(
CatalogueApplication
)
getApplication
();
if
(!
mA
pplication
.
isNetConnected
())
{
CatalogueApplication
a
pplication
=
(
CatalogueApplication
)
getApplication
();
if
(!
a
pplication
.
isNetConnected
())
{
CatalogueLog
.
e
(
"SyncService: onHandleIntent(): Not connected to net. Exit."
);
return
;
}
if
(
Util
.
isChatItemEnabled
())
{
if
(
application
.
getSocket
()
==
null
)
{
getChatServerUrl
();
}
}
startSync
();
}
/**
* Get Chatserver Url.
**/
private
SyncStatus
getChatServerUrl
()
{
CatalogueLog
.
d
(
"getChatServerUrl"
);
ChatServerApiManager
.
getChatServerUrl
(
new
GetChatServerApiListener
()
{
@Override
public
void
onDoneApiCall
(
ChatServerApiResponse
chatServerApiResponse
)
{
CatalogueLog
.
e
(
"getChatServerUrl: result is SUCCESS"
);
syncStatus
=
SyncStatus
.
SUCCESS
;
PrefManager
.
setSharedPref
(
SyncService
.
this
,
PrefManager
.
PREFERENCE_CHAT_SERVER_URL
,
chatServerApiResponse
.
getChatbotUrl
());
Constants
.
CHAT_SERVER_URL
=
chatServerApiResponse
.
getChatbotUrl
();
CatalogueApplication
application
=
(
CatalogueApplication
)
getApplication
();
application
.
initializeSocket
();
}
@Override
public
void
onFailApiCall
()
{
syncStatus
=
SyncStatus
.
FAIL
;
CatalogueLog
.
e
(
"getChatServerUrl: result is FAIL"
);
}
});
return
syncStatus
;
}
private
void
startSync
()
{
CatalogueLog
.
d
(
"---- START SyncService START ----"
);
SyncStatus
result
;
...
...
app/src/main/java/com/vsoft/servicenow/ui/ChatActivity.java
View file @
93aa5d9e
...
...
@@ -150,6 +150,11 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
CatalogueApplication
app
=
(
CatalogueApplication
)
getApplication
();
mSocket
=
app
.
getSocket
();
if
(
mSocket
==
null
)
{
CatalogueLog
.
e
(
"mSocket is null"
);
finish
();
return
;
}
mSocket
.
on
(
Socket
.
EVENT_CONNECT
,
onConnect
);
mSocket
.
on
(
Socket
.
EVENT_DISCONNECT
,
onDisconnect
);
mSocket
.
on
(
Socket
.
EVENT_CONNECT_ERROR
,
onConnectError
);
...
...
app/src/main/java/com/vsoft/servicenow/ui/LoginScreen.java
View file @
93aa5d9e
...
...
@@ -221,23 +221,25 @@ public class LoginScreen extends Activity {
String
userId
=
mUserDetails
.
get
(
0
).
getUserId
();
String
userEmailId
=
mUserDetails
.
get
(
0
).
getUserEmailId
();
/*Start Chat Local DB Part*/
//Here we'll save logged in user detail in local DB for chat history.
ChatBotUser
localChatBotUser
=
ChatBotUserManager
.
getChatBotUsersByUserSysId
(
sysid
);
if
(
localChatBotUser
==
null
)
{
/*Clears all data from CHAT_BOT_HISTORY and CHAT_BOT_USER tables*/
ChatBotHistoryManager
.
deleteAllRows
();
ChatBotUserManager
.
deleteAllRows
();
/*Save Logged in user in local db for chat screen*/
ChatBotUser
chatBotUser
=
ChatBotUser
.
ChatBotUserBuilder
.
aChatBotUser
()
.
setUserSysId
(
sysid
)
.
setName
(
firstName
)
.
build
();
ChatBotUserManager
.
save
(
chatBotUser
);
}
else
{
//Update the name of user
localChatBotUser
.
setName
(
firstName
);
ChatBotUserManager
.
update
(
localChatBotUser
);
if
(
Util
.
isChatItemEnabled
())
{
/*Start Chat Local DB Part*/
//Here we'll save logged in user detail in local DB for chat history.
ChatBotUser
localChatBotUser
=
ChatBotUserManager
.
getChatBotUsersByUserSysId
(
sysid
);
if
(
localChatBotUser
==
null
)
{
/*Clears all data from CHAT_BOT_HISTORY and CHAT_BOT_USER tables*/
ChatBotHistoryManager
.
deleteAllRows
();
ChatBotUserManager
.
deleteAllRows
();
/*Save Logged in user in local db for chat screen*/
ChatBotUser
chatBotUser
=
ChatBotUser
.
ChatBotUserBuilder
.
aChatBotUser
()
.
setUserSysId
(
sysid
)
.
setName
(
firstName
)
.
build
();
ChatBotUserManager
.
save
(
chatBotUser
);
}
else
{
//Update the name of user
localChatBotUser
.
setName
(
firstName
);
ChatBotUserManager
.
update
(
localChatBotUser
);
}
}
/*End Chat Local DB Part*/
...
...
app/src/main/java/com/vsoft/servicenow/utils/Constants.java
View file @
93aa5d9e
...
...
@@ -199,21 +199,12 @@ public class Constants {
public
static
final
String
URL_GET_ALL_PENDING_APPROVALS
=
DOMAIN
+
"api/vsng2/uofl_mobile/manager_approval"
;
public
static
final
String
URL_PUT_PENDING_APPROVAL_STATE
=
API_PATH
+
"sysapproval_approver/{"
+
PendingApprovalsApi
.
SYS_ID_OF_APPROVAL_RECORD
+
"}"
;
public
static
final
String
URL_GET_API_CHAT_SERVER
=
(
BUILD_TYPE_RELEASE
==
BuildConfig
.
BUILD_TYPE_INT
?
AppConfig
.
CHAT_SERVER_API_URL_RELEASE
:
(
BUILD_TYPE_DEBUG
==
BuildConfig
.
BUILD_TYPE_INT
?
AppConfig
.
CHAT_SERVER_API_URL_DEBUG
:
AppConfig
.
CHAT_SERVER_API_URL_STAGING
));
/**
* Chat Server URL
* */
public
static
final
String
CHAT_SERVER_URL
=
(
BUILD_TYPE_RELEASE
==
BuildConfig
.
BUILD_TYPE_INT
?
AppConfig
.
CHAT_SERVER_URL_RELEASE
:
(
BUILD_TYPE_DEBUG
==
BuildConfig
.
BUILD_TYPE_INT
?
AppConfig
.
CHAT_SERVER_URL_DEBUG
:
AppConfig
.
CHAT_SERVER_URL_STAGING
));
/**
* Category API - Hardcode value.
* We are using category api for getting catalogue category and HR case category.
* For both, We're passing hardcode sysId.
*
* For both part, We're using same screens and same API calls also, But we need to make only one change.
* We need to pass different-2 sysid for getting different category.
**/
public
static
final
String
CATELOGUE_CATEGORY_SYS_ID
=
"e0d08b13c3330100c8b837659bba8fb4"
;
public
static
final
String
HR_CASE_CATEGORY_SYS_ID
=
"9a6a1d924f8286005e1a3d728110c75b"
;
public
static
String
CHAT_SERVER_URL
;
}
app/src/main/java/com/vsoft/servicenow/utils/PrefManager.java
View file @
93aa5d9e
...
...
@@ -15,6 +15,9 @@ public class PrefManager {
public
static
final
String
PREFERENCE_USER_ID
=
"user_id"
;
public
static
final
String
PREFERENCE_USER_EMAIL_ID
=
"user_email_id"
;
//Chat Server Url
public
static
final
String
PREFERENCE_CHAT_SERVER_URL
=
"chat_server_url"
;
/*Access Token */
public
static
final
String
PREFERENCE_ACCESS_TOKEN
=
"access_token"
;
public
static
final
String
PREFERENCE_REFRESH_TOKEN
=
"refresh_token"
;
...
...
app/src/vportal/java/com/vsoft/servicenow/AppConfig.java
View file @
93aa5d9e
...
...
@@ -53,14 +53,10 @@ public class AppConfig {
public
static
final
String
URL_POST_HR_CASE_ITEM
=
"/api/sn_sc/servicecatalog/items/{sys_id}/submit_producer"
;
/**
* Socket Chat server URLs - Urls given by Ravi
* develop - http://111.93.6.218:12911/
* test - http://111.93.6.218:12912/
* demo - http://111.93.6.218:12913/
* release - http://111.93.6.218:12914/
* We will hit the below url to get the chat server url.
* */
public
static
final
String
CHAT_SERVER_
URL_RELEASE
=
"http://111.93.6.218:12914/
"
;
public
static
final
String
CHAT_SERVER_
URL_DEBUG
=
"http://111.93.6.218:12911/
"
;
public
static
String
CHAT_SERVER_URL_STAGING
=
"
"
;
public
static
final
String
CHAT_SERVER_
API_URL_RELEASE
=
"http://ai.test.vsoftconsulting.com:3000/?env=release
"
;
public
static
final
String
CHAT_SERVER_
API_URL_DEBUG
=
"http://ai.test.vsoftconsulting.com:3000/?env=dev
"
;
public
static
final
String
CHAT_SERVER_API_URL_STAGING
=
"http://ai.test.vsoftconsulting.com:3000/?env=test
"
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment