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
ef377686
authored
Aug 31, 2016
by
Kunj Gupta
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
UOFLMA-37: Integrated submit Incident POST API.
parent
ed08d6e6
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
223 additions
and
17 deletions
app/src/main/java/com/vsoft/uofl_catalogue/api/interfaces/IncidentApi.java
app/src/main/java/com/vsoft/uofl_catalogue/api/managers/IncidentApiManager.java
app/src/main/java/com/vsoft/uofl_catalogue/db/models/Incident.java
app/src/main/java/com/vsoft/uofl_catalogue/enums/Impact.java
app/src/main/java/com/vsoft/uofl_catalogue/enums/ViewType.java
app/src/main/java/com/vsoft/uofl_catalogue/ui/ReportIncidentScreen.java
app/src/main/java/com/vsoft/uofl_catalogue/utils/Constants.java
app/src/main/res/layout/incidents_form_screen.xml
app/src/main/java/com/vsoft/uofl_catalogue/api/interfaces/IncidentApi.java
View file @
ef377686
...
@@ -4,7 +4,9 @@ import com.vsoft.uofl_catalogue.utils.Constants;
...
@@ -4,7 +4,9 @@ import com.vsoft.uofl_catalogue.utils.Constants;
import
okhttp3.ResponseBody
;
import
okhttp3.ResponseBody
;
import
retrofit2.Call
;
import
retrofit2.Call
;
import
retrofit2.http.Body
;
import
retrofit2.http.GET
;
import
retrofit2.http.GET
;
import
retrofit2.http.POST
;
import
retrofit2.http.Query
;
import
retrofit2.http.Query
;
...
@@ -18,6 +20,10 @@ public interface IncidentApi {
...
@@ -18,6 +20,10 @@ public interface IncidentApi {
@GET
(
Constants
.
URL_GET_INCIDENTS
)
@GET
(
Constants
.
URL_GET_INCIDENTS
)
Call
<
ResponseBody
>
getIncident
(
@Query
(
Constants
.
URL_PARAM_SYSPRM_QUERY
)
String
sysParmQuery
,
Call
<
ResponseBody
>
getIncident
(
@Query
(
Constants
.
URL_PARAM_SYSPRM_QUERY
)
String
sysParmQuery
,
@Query
(
Constants
.
URL_PARAM_SYSPRM_LIMIT
)
String
sysParmLimits
);
@Query
(
Constants
.
URL_PARAM_SYSPRM_LIMIT
)
String
sysParmLimits
);
// Post Incident API
@POST
(
Constants
.
URL_POST_INCIDENT
)
Call
<
ResponseBody
>
submitIncident
(
@Body
String
incidentJson
);
}
}
app/src/main/java/com/vsoft/uofl_catalogue/api/managers/IncidentApiManager.java
View file @
ef377686
...
@@ -124,4 +124,26 @@ public class IncidentApiManager {
...
@@ -124,4 +124,26 @@ public class IncidentApiManager {
return
SyncStatus
.
FAIL
;
return
SyncStatus
.
FAIL
;
}
}
}
}
public
static
SyncStatus
submitIncidentForm
(
String
incidentJsonString
)
{
CatalogueLog
.
d
(
"submitIncidentForm: incidentJson"
+
incidentJsonString
);
final
Retrofit
retrofit
=
RestClient
.
getInitializedRestAdapter
(
Constants
.
API_AUTH_PARAM_USER_NAME
,
Constants
.
API_AUTH_PARAM_PASSWORD
);
Call
<
ResponseBody
>
call
=
retrofit
.
create
(
IncidentApi
.
class
).
submitIncident
(
incidentJsonString
);
try
{
//Retrofit synchronous call
Response
<
ResponseBody
>
response
=
call
.
execute
();
if
(
response
.
isSuccessful
())
{
return
SyncStatus
.
SUCCESS
;
}
else
{
return
SyncStatus
.
FAIL
;
}
}
catch
(
IOException
e
)
{
CatalogueLog
.
e
(
"IncidentApiManager: submitIncidentForm: IOException: "
,
e
);
return
SyncStatus
.
FAIL
;
}
catch
(
NullPointerException
e
){
CatalogueLog
.
e
(
"IncidentApiManager: submitIncidentForm: IOException: "
,
e
);
return
SyncStatus
.
FAIL
;
}
}
}
}
\ No newline at end of file
app/src/main/java/com/vsoft/uofl_catalogue/db/models/Incident.java
View file @
ef377686
...
@@ -122,6 +122,9 @@ public class Incident {
...
@@ -122,6 +122,9 @@ public class Incident {
public
static
class
Json
{
public
static
class
Json
{
public
static
final
String
IMPACT
=
"impact"
;
public
static
final
String
IMPACT
=
"impact"
;
public
static
final
String
OPENED_AT
=
"opened_at"
;
public
static
final
String
OPENED_AT
=
"opened_at"
;
public
static
final
String
SHORT_DESCRIPTION
=
"short_description"
;
public
static
final
String
CALLER_ID
=
"caller_id"
;
public
static
final
String
OPENED_ID
=
"opened_by"
;
}
}
@Override
@Override
...
...
app/src/main/java/com/vsoft/uofl_catalogue/enums/Impact.java
View file @
ef377686
...
@@ -6,25 +6,46 @@ package com.vsoft.uofl_catalogue.enums;
...
@@ -6,25 +6,46 @@ package com.vsoft.uofl_catalogue.enums;
*
*
*/
*/
public
enum
Impact
{
public
enum
Impact
{
UNKNOWN
(-
1
),
UNKNOWN
(-
1
,
"unknown"
,
"-1"
),
HIGH
(
1
),
HIGH
(
1
,
"High"
,
"1"
),
MEDIUM
(
2
),
MEDIUM
(
2
,
"Medium"
,
"2"
),
LOW
(
3
);
LOW
(
3
,
"Low"
,
"3"
);
int
id
;
private
int
id
;
private
String
displayString
;
private
String
serverString
;
Impact
(
int
id
)
{
Impact
(
int
id
,
String
displayString
,
String
serverString
)
{
this
.
id
=
id
;
this
.
id
=
id
;
this
.
displayString
=
displayString
;
this
.
serverString
=
serverString
;
}
}
public
static
int
getSyncStatus
(
Impact
status
)
{
/* getters */
return
status
.
id
;
public
static
int
getId
(
Impact
impact
)
{
return
impact
.
id
;
}
}
public
int
getId
()
{
public
int
getId
()
{
return
this
.
id
;
return
this
.
id
;
}
}
public
static
String
getDisplayString
(
Impact
impact
)
{
return
impact
.
displayString
;
}
public
String
getDisplayString
()
{
return
this
.
displayString
;
}
public
String
getServerString
()
{
return
serverString
;
}
public
void
setServerString
(
String
serverString
)
{
this
.
serverString
=
serverString
;
}
public
static
Impact
from
(
int
id
)
{
public
static
Impact
from
(
int
id
)
{
for
(
int
i
=
0
;
i
<
Impact
.
values
().
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
Impact
.
values
().
length
;
i
++)
{
Impact
impact
=
Impact
.
values
()[
i
];
Impact
impact
=
Impact
.
values
()[
i
];
...
@@ -33,4 +54,13 @@ public enum Impact {
...
@@ -33,4 +54,13 @@ public enum Impact {
}
}
return
UNKNOWN
;
return
UNKNOWN
;
}
}
public
static
Impact
from
(
String
string
)
{
for
(
int
i
=
0
;
i
<
Impact
.
values
().
length
;
i
++)
{
Impact
impact
=
Impact
.
values
()[
i
];
if
(
impact
.
displayString
.
equals
(
string
))
return
Impact
.
values
()[
i
];
}
return
UNKNOWN
;
}
}
}
app/src/main/java/com/vsoft/uofl_catalogue/enums/ViewType.java
View file @
ef377686
...
@@ -37,16 +37,16 @@ public enum ViewType {
...
@@ -37,16 +37,16 @@ public enum ViewType {
}
}
/* getters */
/* getters */
public
static
int
getId
(
ViewType
expense
Type
)
{
public
static
int
getId
(
ViewType
view
Type
)
{
return
expense
Type
.
id
;
return
view
Type
.
id
;
}
}
public
int
getId
()
{
public
int
getId
()
{
return
this
.
id
;
return
this
.
id
;
}
}
public
static
String
getDisplayString
(
ViewType
expense
Type
)
{
public
static
String
getDisplayString
(
ViewType
view
Type
)
{
return
expense
Type
.
displayString
;
return
view
Type
.
displayString
;
}
}
public
String
getDisplayString
()
{
public
String
getDisplayString
()
{
...
@@ -55,8 +55,8 @@ public enum ViewType {
...
@@ -55,8 +55,8 @@ public enum ViewType {
public
static
ViewType
from
(
int
id
)
{
public
static
ViewType
from
(
int
id
)
{
for
(
int
i
=
0
;
i
<
ViewType
.
values
().
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
ViewType
.
values
().
length
;
i
++)
{
ViewType
expense
Type
=
ViewType
.
values
()[
i
];
ViewType
view
Type
=
ViewType
.
values
()[
i
];
if
(
expense
Type
.
id
==
id
)
if
(
view
Type
.
id
==
id
)
return
ViewType
.
values
()[
i
];
return
ViewType
.
values
()[
i
];
}
}
return
UNKNOWN
;
return
UNKNOWN
;
...
@@ -64,8 +64,8 @@ public enum ViewType {
...
@@ -64,8 +64,8 @@ public enum ViewType {
public
static
ViewType
from
(
String
string
)
{
public
static
ViewType
from
(
String
string
)
{
for
(
int
i
=
0
;
i
<
ViewType
.
values
().
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
ViewType
.
values
().
length
;
i
++)
{
ViewType
expense
Type
=
ViewType
.
values
()[
i
];
ViewType
view
Type
=
ViewType
.
values
()[
i
];
if
(
expense
Type
.
displayString
.
equals
(
string
))
if
(
view
Type
.
displayString
.
equals
(
string
))
return
ViewType
.
values
()[
i
];
return
ViewType
.
values
()[
i
];
}
}
return
UNKNOWN
;
return
UNKNOWN
;
...
...
app/src/main/java/com/vsoft/uofl_catalogue/ui/ReportIncidentScreen.java
View file @
ef377686
package
com
.
vsoft
.
uofl_catalogue
.
ui
;
package
com
.
vsoft
.
uofl_catalogue
.
ui
;
import
android.app.ProgressDialog
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.content.SharedPreferences
;
import
android.os.AsyncTask
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.v7.app.ActionBar
;
import
android.support.v7.app.ActionBar
;
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.text.TextUtils
;
import
android.view.MenuItem
;
import
android.view.MenuItem
;
import
android.view.View
;
import
android.widget.ArrayAdapter
;
import
android.widget.ArrayAdapter
;
import
android.widget.EditText
;
import
android.widget.Spinner
;
import
android.widget.Spinner
;
import
android.widget.TextView
;
import
com.vsoft.uofl_catalogue.CatalogueApplication
;
import
com.vsoft.uofl_catalogue.CatalogueApplication
;
import
com.vsoft.uofl_catalogue.R
;
import
com.vsoft.uofl_catalogue.R
;
import
com.vsoft.uofl_catalogue.api.managers.IncidentApiManager
;
import
com.vsoft.uofl_catalogue.db.models.Incident
;
import
com.vsoft.uofl_catalogue.enums.Impact
;
import
com.vsoft.uofl_catalogue.enums.SyncStatus
;
import
com.vsoft.uofl_catalogue.utils.PrefManager
;
import
com.vsoft.uofl_catalogue.utils.Util
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
butterknife.BindView
;
import
butterknife.BindView
;
import
butterknife.ButterKnife
;
import
butterknife.ButterKnife
;
import
butterknife.OnClick
;
/**
/**
* Created by kunj on 30/8/16.
* Created by kunj on 30/8/16.
...
@@ -21,8 +41,13 @@ public class ReportIncidentScreen extends AppCompatActivity {
...
@@ -21,8 +41,13 @@ 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_impact_error_tv
)
TextView
mImpactErrorTextView
;
@BindView
(
R
.
id
.
incident_short_des_error_tv
)
TextView
mShortDesErrorTextView
;
private
CatalogueApplication
mApplication
;
private
CatalogueApplication
mApplication
;
private
Impact
mImpact
;
private
String
mShortDescription
;
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
@@ -54,6 +79,66 @@ public class ReportIncidentScreen extends AppCompatActivity {
...
@@ -54,6 +79,66 @@ public class ReportIncidentScreen extends AppCompatActivity {
mImpactSpinner
.
setAdapter
(
dataAdapter
);
mImpactSpinner
.
setAdapter
(
dataAdapter
);
}
}
@OnClick
(
R
.
id
.
incident_submit_text_view
)
void
submitOnClicked
(
View
view
)
{
if
(
mApplication
.
isNetConnected
())
{
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
);
new
submitIncident
().
execute
(
userSysId
);
}
else
{
showErrorDialog
(
R
.
string
.
failed_to_submit_form_string
);
}
}
}
else
{
showErrorDialog
(
R
.
string
.
internet_validation_string
);
}
}
class
submitIncident
extends
AsyncTask
<
String
,
Void
,
SyncStatus
>
{
private
ProgressDialog
progressDialog
;
@Override
protected
void
onPreExecute
()
{
super
.
onPreExecute
();
progressDialog
=
new
ProgressDialog
(
ReportIncidentScreen
.
this
);
progressDialog
.
setMessage
(
getString
(
R
.
string
.
loading_string
));
progressDialog
.
show
();
progressDialog
.
setCancelable
(
false
);
}
@Override
protected
SyncStatus
doInBackground
(
String
...
params
)
{
String
userSysId
=
params
[
0
];
JSONObject
incidentJsonObject
=
new
JSONObject
();
try
{
incidentJsonObject
.
put
(
Incident
.
Json
.
IMPACT
,
mImpact
.
getServerString
());
incidentJsonObject
.
put
(
Incident
.
Json
.
SHORT_DESCRIPTION
,
mShortDescription
);
incidentJsonObject
.
put
(
Incident
.
Json
.
OPENED_AT
,
userSysId
);
incidentJsonObject
.
put
(
Incident
.
Json
.
CALLER_ID
,
userSysId
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
SyncStatus
syncStatus
=
IncidentApiManager
.
submitIncidentForm
(
incidentJsonObject
.
toString
());
return
syncStatus
;
}
@Override
protected
void
onPostExecute
(
SyncStatus
syncStatus
)
{
super
.
onPostExecute
(
syncStatus
);
if
(
progressDialog
!=
null
&&
progressDialog
.
isShowing
())
{
progressDialog
.
dismiss
();
}
if
(
syncStatus
==
SyncStatus
.
SUCCESS
)
{
finish
();
}
else
{
showErrorDialog
(
R
.
string
.
failed_to_submit_form_string
);
}
}
}
@Override
@Override
public
boolean
onOptionsItemSelected
(
MenuItem
menuItem
)
{
public
boolean
onOptionsItemSelected
(
MenuItem
menuItem
)
{
if
(
menuItem
.
getItemId
()
==
android
.
R
.
id
.
home
)
{
if
(
menuItem
.
getItemId
()
==
android
.
R
.
id
.
home
)
{
...
@@ -61,4 +146,44 @@ public class ReportIncidentScreen extends AppCompatActivity {
...
@@ -61,4 +146,44 @@ public class ReportIncidentScreen extends AppCompatActivity {
}
}
return
super
.
onOptionsItemSelected
(
menuItem
);
return
super
.
onOptionsItemSelected
(
menuItem
);
}
}
private
boolean
hasValidateForm
()
{
boolean
hasError
=
false
;
/*Get all edit text values in member variables*/
getAllFromValues
();
if
(
mImpact
!=
Impact
.
UNKNOWN
)
{
mImpactErrorTextView
.
setVisibility
(
View
.
GONE
);
}
else
{
hasError
=
true
;
mImpactErrorTextView
.
setVisibility
(
View
.
VISIBLE
);
}
if
(!
TextUtils
.
isEmpty
(
mShortDescription
))
{
mShortDesErrorTextView
.
setVisibility
(
View
.
GONE
);
}
else
{
hasError
=
true
;
mShortDesErrorTextView
.
setVisibility
(
View
.
VISIBLE
);
}
return
hasError
;
}
private
void
getAllFromValues
()
{
/*Form values*/
mImpact
=
Impact
.
from
((
String
)
mImpactSpinner
.
getSelectedItem
());
mShortDescription
=
mShortDesEditText
.
getText
().
toString
();
}
private
void
showErrorDialog
(
int
message
)
{
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
this
);
builder
.
setMessage
(
message
)
.
setCancelable
(
false
)
.
setPositiveButton
(
android
.
R
.
string
.
ok
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialog
,
int
id
)
{
dialog
.
dismiss
();
}
});
AlertDialog
alert
=
builder
.
create
();
alert
.
show
();
}
}
}
app/src/main/java/com/vsoft/uofl_catalogue/utils/Constants.java
View file @
ef377686
...
@@ -126,4 +126,5 @@ public class Constants {
...
@@ -126,4 +126,5 @@ public class Constants {
public
static
final
String
URL_GET_USERDETAILS
=
API_PATH
+
"sys_user"
;
public
static
final
String
URL_GET_USERDETAILS
=
API_PATH
+
"sys_user"
;
/*Incident API */
/*Incident API */
public
static
final
String
URL_GET_INCIDENTS
=
API_PATH
+
"incident"
;
public
static
final
String
URL_GET_INCIDENTS
=
API_PATH
+
"incident"
;
public
static
final
String
URL_POST_INCIDENT
=
API_PATH
+
"incident"
;
}
}
app/src/main/res/layout/incidents_form_screen.xml
View file @
ef377686
...
@@ -63,6 +63,15 @@
...
@@ -63,6 +63,15 @@
android:paddingBottom=
"@dimen/small_margin"
/>
android:paddingBottom=
"@dimen/small_margin"
/>
<TextView
<TextView
android:id=
"@+id/incident_impact_error_tv"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"@string/error_string"
android:visibility=
"gone"
android:layout_marginLeft=
"@dimen/normal_margin"
android:textColor=
"@color/error_color"
/>
<TextView
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_margin=
"@dimen/normal_margin"
android:layout_margin=
"@dimen/normal_margin"
...
@@ -71,7 +80,7 @@
...
@@ -71,7 +80,7 @@
android:textStyle=
"bold"
/>
android:textStyle=
"bold"
/>
<EditText
<EditText
android:id=
"@+id/incident_
describe_issue
_edit_text"
android:id=
"@+id/incident_
short_description
_edit_text"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginBottom=
"@dimen/normal_margin"
android:layout_marginBottom=
"@dimen/normal_margin"
...
@@ -83,6 +92,15 @@
...
@@ -83,6 +92,15 @@
android:lines=
"4"
/>
android:lines=
"4"
/>
<TextView
<TextView
android:id=
"@+id/incident_short_des_error_tv"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"@string/error_string"
android:visibility=
"gone"
android:layout_marginLeft=
"@dimen/normal_margin"
android:textColor=
"@color/error_color"
/>
<TextView
android:id=
"@+id/incident_submit_text_view"
android:id=
"@+id/incident_submit_text_view"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
...
...
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