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
3141cb84
authored
Sep 16, 2016
by
Kunj Gupta
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Added Local DB table for storing Report Incident form values.
parent
8cfa8b19
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
142 additions
and
10 deletions
app/src/main/java/com/vsoft/uoflservicenow/db/managers/ReportIncidentValueManager.java
app/src/main/java/com/vsoft/uoflservicenow/ui/CatalogueVariableScreen.java
app/src/main/java/com/vsoft/uoflservicenow/ui/ReportIncidentScreen.java
app/src/main/java/com/vsoft/uoflservicenow/utils/DBConstants.java
app/src/main/java/com/vsoft/uoflservicenow/utils/Util.java
app/src/main/java/com/vsoft/uoflservicenow/db/managers/ReportIncidentValueManager.java
0 → 100644
View file @
3141cb84
package
com
.
vsoft
.
uoflservicenow
.
db
.
managers
;
import
android.content.ContentValues
;
import
android.database.Cursor
;
import
android.database.sqlite.SQLiteDatabase
;
import
com.vsoft.uoflservicenow.CatalogueApplication
;
import
com.vsoft.uoflservicenow.db.models.Incident
;
import
com.vsoft.uoflservicenow.enums.Impact
;
import
com.vsoft.uoflservicenow.utils.DBConstants
;
/**
*
* @author Kunj on 16-09-2016.
*/
public
class
ReportIncidentValueManager
implements
DBConstants
{
public
static
long
save
(
Incident
incident
,
int
syncDirty
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
incident
.
setSyncDirty
(
syncDirty
);
long
id
=
db
.
insert
(
TABLE_INCIDENT_FORM
,
null
,
getContentValues
(
incident
));
return
id
;
}
else
{
return
-
1
;
}
}
public
static
Incident
get
(
long
incidentId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
Incident
incident
=
null
;
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_INCIDENT_FORM
+
" where "
+
INCIDENT_FORM_ID
+
"="
+
incidentId
,
null
);
if
(
c
.
moveToFirst
())
{
Incident
.
IncidentBuilder
builder
=
Incident
.
IncidentBuilder
.
anIncident
();
fillAllIncidentFormDetails
(
c
,
builder
);
incident
=
builder
.
build
();
}
c
.
close
();
}
return
incident
;
}
public
static
Incident
getIncidentFromSysId
(
String
sysId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
Incident
incident
=
null
;
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_INCIDENT_FORM
+
" where "
+
CATALOGUE_VARIABLE_SYS_ID
+
"='"
+
sysId
+
"'"
,
null
);
if
(
c
.
moveToFirst
())
{
Incident
.
IncidentBuilder
builder
=
Incident
.
IncidentBuilder
.
anIncident
();
fillAllIncidentFormDetails
(
c
,
builder
);
incident
=
builder
.
build
();
}
c
.
close
();
}
return
incident
;
}
private
static
void
fillAllIncidentFormDetails
(
Cursor
c
,
Incident
.
IncidentBuilder
builder
)
{
builder
.
setId
(
c
.
getLong
(
INDEX_INCIDENT_FORM_ID
));
builder
.
setImpact
(
Impact
.
from
(
c
.
getInt
(
INDEX_INCIDENT_FORM_IMPACT
)));
builder
.
setShortDescription
(
c
.
getString
(
INDEX_INCIDENT_FORM_SHORT_DESCRIPTION
));
builder
.
setSyncDirty
(
c
.
getInt
(
INDEX_INCIDENT_FORM_SYNC_DIRTY
));
}
private
static
ContentValues
getContentValues
(
Incident
incident
)
{
ContentValues
cv
=
new
ContentValues
(
INCIDENT_FORM_COLUMN_COUNT
-
1
);
cv
.
put
(
INCIDENT_FORM_IMPACT
,
Impact
.
getId
(
incident
.
getImpact
()));
cv
.
put
(
INCIDENT_FORM_SHORT_DESCRIPTION
,
incident
.
getShortDescription
());
cv
.
put
(
INCIDENT_FORM_SYNC_DIRTY
,
incident
.
getSyncDirty
());
return
cv
;
}
}
\ No newline at end of file
app/src/main/java/com/vsoft/uoflservicenow/ui/CatalogueVariableScreen.java
View file @
3141cb84
...
...
@@ -406,13 +406,12 @@ public class CatalogueVariableScreen extends AppCompatActivity {
return
;
/*Create Dynamic table for CatalogueVariable Values*/
Util
.
createDynamicTable
(
mCatalogueItem
.
getSysId
(),
mCatalogueVariableList
);
Util
.
createDynamicTable
ForVariableFormValues
(
mCatalogueItem
.
getSysId
(),
mCatalogueVariableList
);
/*Save data in local DB*/
long
id
=
CatalogueVariableValueManager
.
save
(
"t_"
+
mCatalogueItem
.
getSysId
(),
columnList
,
valueList
,
DBConstants
.
SYNC_FLAG_CREATE
);
if
(
id
==
-
1
)
{
Toast
.
makeText
(
CatalogueVariableScreen
.
this
,
"Not saved: id: "
+
id
,
Toast
.
LENGTH_LONG
).
show
();
}
else
{
Toast
.
makeText
(
CatalogueVariableScreen
.
this
,
"Saved: id: "
+
id
,
Toast
.
LENGTH_LONG
).
show
();
if
(
id
!=
-
1
)
{
Toast
.
makeText
(
CatalogueVariableScreen
.
this
,
"Data Saved in Local DB"
,
Toast
.
LENGTH_LONG
).
show
();
finish
();
}
}
...
...
app/src/main/java/com/vsoft/uoflservicenow/ui/ReportIncidentScreen.java
View file @
3141cb84
...
...
@@ -22,9 +22,11 @@ import com.google.android.gms.analytics.Tracker;
import
com.vsoft.uoflservicenow.CatalogueApplication
;
import
com.vsoft.uoflservicenow.R
;
import
com.vsoft.uoflservicenow.api.managers.IncidentApiManager
;
import
com.vsoft.uoflservicenow.db.managers.ReportIncidentValueManager
;
import
com.vsoft.uoflservicenow.db.models.Incident
;
import
com.vsoft.uoflservicenow.enums.Impact
;
import
com.vsoft.uoflservicenow.enums.SyncStatus
;
import
com.vsoft.uoflservicenow.utils.DBConstants
;
import
com.vsoft.uoflservicenow.utils.DialogUtils
;
import
com.vsoft.uoflservicenow.utils.PrefManager
;
import
com.vsoft.uoflservicenow.utils.Util
;
...
...
@@ -96,7 +98,16 @@ public class ReportIncidentScreen extends AppCompatActivity {
String
userSysId
=
sharedPreferences
.
getString
(
PrefManager
.
PREFERENCE_SYS_ID
,
""
);
if
(!
userSysId
.
isEmpty
())
{
Util
.
hideSoftKeyboard
(
ReportIncidentScreen
.
this
,
view
);
new
submitIncident
().
execute
(
userSysId
);
Util
.
createDynamicTableForIncidentFormValues
();
Incident
incident
=
Incident
.
IncidentBuilder
.
anIncident
()
.
setImpact
(
mImpact
)
.
setShortDescription
(
mShortDescription
)
.
build
();
long
id
=
ReportIncidentValueManager
.
save
(
incident
,
DBConstants
.
SYNC_FLAG_CREATE
);
if
(
id
!=
-
1
)
{
showSuccessDialog
();
}
// new submitIncident().execute(userSysId);
}
else
{
showErrorDialog
(
R
.
string
.
failed_to_submit_form_string
);
}
...
...
app/src/main/java/com/vsoft/uoflservicenow/utils/DBConstants.java
View file @
3141cb84
...
...
@@ -8,6 +8,7 @@ public interface DBConstants {
String
TABLE_VARIABLE_CHOICES
=
"variable_choices"
;
String
TABLE_MY_INCIDENT
=
"my_incidents"
;
String
TABLE_MY_REQUEST
=
"my_requests"
;
String
TABLE_INCIDENT_FORM
=
"incident_form"
;
String
ID
=
"_id"
;
String
SYS_ID
=
"sys_id"
;
...
...
@@ -165,4 +166,22 @@ public interface DBConstants {
int
INDEX_REQUEST_SYNC_DIRTY
=
5
;
int
REQUEST_COLUMN_COUNT
=
6
;
/**
* Incident Form table
*/
String
INCIDENT_FORM_ID
=
ID
;
String
INCIDENT_FORM_IMPACT
=
"number"
;
String
INCIDENT_FORM_SHORT_DESCRIPTION
=
"short_description"
;
String
INCIDENT_FORM_SYNC_DIRTY
=
SYNC_DIRTY
;
/**
* Request for Incident Form table. *Use these only if you fetch all columns*
*/
int
INDEX_INCIDENT_FORM_ID
=
0
;
int
INDEX_INCIDENT_FORM_IMPACT
=
1
;
int
INDEX_INCIDENT_FORM_SHORT_DESCRIPTION
=
2
;
int
INDEX_INCIDENT_FORM_SYNC_DIRTY
=
3
;
int
INCIDENT_FORM_COLUMN_COUNT
=
6
;
}
\ No newline at end of file
app/src/main/java/com/vsoft/uoflservicenow/utils/Util.java
View file @
3141cb84
...
...
@@ -314,7 +314,7 @@ public class Util {
return
date
.
getTime
();
}
public
static
void
createDynamicTable
(
String
catalogueItemSysId
,
List
<
CatalogueVariable
>
catalogueVariableList
)
{
public
static
void
createDynamicTable
ForVariableFormValues
(
String
catalogueItemSysId
,
List
<
CatalogueVariable
>
catalogueVariableList
)
{
StringBuilder
queryString
=
new
StringBuilder
();
//Opens database in writable mode.
...
...
@@ -345,7 +345,35 @@ public class Util {
queryString
.
append
(
DBConstants
.
SYNC_FLAG_NONE
);
queryString
.
append
(
");"
);
System
.
out
.
println
(
"Create Table Stmt : "
+
queryString
);
System
.
out
.
println
(
"createDynamicTableForVariableFormValues: Create Table Stmt : "
+
queryString
);
database
.
execSQL
(
queryString
.
toString
());
}
public
static
void
createDynamicTableForIncidentFormValues
()
{
StringBuilder
queryString
=
new
StringBuilder
();
//Opens database in writable mode.
SQLiteDatabase
database
=
CatalogueApplication
.
getDatabase
();
queryString
.
append
(
"CREATE TABLE IF NOT EXISTS "
);
queryString
.
append
(
DBConstants
.
TABLE_INCIDENT_FORM
);
queryString
.
append
(
" ("
);
queryString
.
append
(
DBConstants
.
ID
);
queryString
.
append
(
" integer primary key autoincrement, "
);
queryString
.
append
(
DBConstants
.
INCIDENT_FORM_IMPACT
);
queryString
.
append
(
" integer, "
);
queryString
.
append
(
DBConstants
.
INCIDENT_FORM_SHORT_DESCRIPTION
);
queryString
.
append
(
" text, "
);
queryString
.
append
(
DBConstants
.
INCIDENT_FORM_SYNC_DIRTY
);
queryString
.
append
(
" integer default "
);
queryString
.
append
(
DBConstants
.
SYNC_FLAG_NONE
);
queryString
.
append
(
");"
);
System
.
out
.
println
(
"createDynamicTableForIncidentFormValues: Create Table Stmt : "
+
queryString
);
database
.
execSQL
(
queryString
.
toString
());
}
...
...
@@ -359,6 +387,4 @@ public class Util {
InputMethodManager
imm
=(
InputMethodManager
)
context
.
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
imm
.
hideSoftInputFromWindow
(
view
.
getWindowToken
(),
0
);
}
}
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