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
52366a4b
authored
Sep 16, 2016
by
Kunj Gupta
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Added Local DB table for storing Variable form input values.
parent
b1352af9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
176 additions
and
5 deletions
app/src/main/java/com/vsoft/uoflservicenow/db/managers/CatalogueVariableValueManager.java
app/src/main/java/com/vsoft/uoflservicenow/ui/CatalogueVariableScreen.java
app/src/main/java/com/vsoft/uoflservicenow/db/managers/CatalogueVariableValueManager.java
0 → 100644
View file @
52366a4b
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.CatalogueVariable
;
import
com.vsoft.uoflservicenow.enums.ViewType
;
import
com.vsoft.uoflservicenow.utils.CatalogueLog
;
import
com.vsoft.uoflservicenow.utils.DBConstants
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
*
* @author Kunj on 11-08-2016.
*/
public
class
CatalogueVariableValueManager
implements
DBConstants
{
public
static
long
save
(
String
tableName
,
List
<
String
>
columnNameList
,
List
<
String
>
valueList
,
int
syncDirty
)
{
CatalogueLog
.
e
(
"CatalogueVariableValueManager: save"
);
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
ContentValues
contentValues
=
new
ContentValues
(
columnNameList
.
size
());
contentValues
.
put
(
CATALOGUE_VARIABLE_SYNC_DIRTY
,
syncDirty
);
for
(
int
i
=
0
;
i
<
columnNameList
.
size
();
i
++)
{
String
columnName
=
columnNameList
.
get
(
i
);
String
value
=
valueList
.
get
(
i
);
if
(
columnName
!=
null
&&
value
!=
null
)
contentValues
.
put
(
columnName
,
value
);
}
long
id
=
db
.
insert
(
tableName
,
null
,
contentValues
);
return
id
;
}
else
{
return
-
1
;
}
}
public
static
int
delete
(
CatalogueVariable
catalogueVariable
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
if
(
catalogueVariable
.
getSysId
()
==
null
||
catalogueVariable
.
getSysId
().
isEmpty
())
{
return
db
.
delete
(
TABLE_CATALOGUE_VARIABLES
,
CATALOGUE_VARIABLE_ID
+
"="
+
catalogueVariable
.
getId
(),
null
);
}
else
{
return
update
(
catalogueVariable
,
SYNC_FLAG_DELETE
);
}
}
return
-
1
;
}
public
static
int
update
(
CatalogueVariable
catalogueVariable
,
int
syncDirty
)
{
return
update
(
catalogueVariable
,
null
,
syncDirty
);
}
public
static
int
update
(
CatalogueVariable
catalogueVariable
,
List
<
String
>
column
,
int
syncDirty
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
catalogueVariable
.
setSyncDirty
(
syncDirty
);
if
(
column
==
null
||
column
.
size
()
==
0
)
{
return
db
.
update
(
TABLE_CATALOGUE_VARIABLES
,
getContentValues
(
catalogueVariable
),
CATALOGUE_VARIABLE_ID
+
"="
+
catalogueVariable
.
getId
(),
null
);
}
else
{
ContentValues
contentValues
=
new
ContentValues
(
column
.
size
());
contentValues
.
put
(
CATALOGUE_VARIABLE_SYNC_DIRTY
,
catalogueVariable
.
getSyncDirty
());
for
(
int
i
=
0
;
i
<
column
.
size
();
i
++)
{
String
columnName
=
column
.
get
(
i
);
if
(
CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
,
catalogueVariable
.
getCatalogueItemId
());
}
else
if
(
CATALOGUE_VARIABLE_NAME
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_NAME
,
catalogueVariable
.
getName
());
}
else
if
(
CATALOGUE_VARIABLE_QUESTION_TEXT
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_QUESTION_TEXT
,
catalogueVariable
.
getQuestionText
());
}
else
if
(
CATALOGUE_VARIABLE_TYPE
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_TYPE
,
ViewType
.
getId
(
catalogueVariable
.
getType
()));
}
else
if
(
CATALOGUE_VARIABLE_SYS_ID
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_SYS_ID
,
catalogueVariable
.
getSysId
());
}
else
if
(
CATALOGUE_VARIABLE_SYNC_DIRTY
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_VARIABLE_SYNC_DIRTY
,
catalogueVariable
.
getSyncDirty
());
}
}
return
db
.
update
(
TABLE_CATALOGUE_VARIABLES
,
contentValues
,
CATALOGUE_VARIABLE_ID
+
"="
+
catalogueVariable
.
getId
(),
null
);
}
}
else
{
return
-
1
;
}
}
public
static
List
<
CatalogueVariable
>
getAllVariable
(
long
catalogueItemId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE_VARIABLES
+
" where "
+
CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
+
"="
+
catalogueItemId
+
" and "
+
CATALOGUE_VARIABLE_SYNC_DIRTY
+
"!="
+
DBConstants
.
SYNC_FLAG_DELETE
,
null
);
ArrayList
<
CatalogueVariable
>
variableList
;
if
(
c
.
getCount
()
>
0
)
{
variableList
=
new
ArrayList
<>(
c
.
getCount
());
while
(
c
.
moveToNext
())
{
CatalogueVariable
.
CatalogueVariableBuilder
builder
=
CatalogueVariable
.
CatalogueVariableBuilder
.
aCatalogueVariable
();
fillAllVariableDetails
(
c
,
builder
);
variableList
.
add
(
builder
.
build
());
}
}
else
{
variableList
=
new
ArrayList
<>(
0
);
}
c
.
close
();
return
variableList
;
}
else
{
return
new
ArrayList
<>(
0
);
}
}
public
static
CatalogueVariable
get
(
long
catalogueId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
CatalogueVariable
catalogueVariable
=
null
;
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE_VARIABLES
+
" where "
+
CATALOGUE_VARIABLE_ID
+
"="
+
catalogueId
,
null
);
if
(
c
.
moveToFirst
())
{
CatalogueVariable
.
CatalogueVariableBuilder
builder
=
CatalogueVariable
.
CatalogueVariableBuilder
.
aCatalogueVariable
();
fillAllVariableDetails
(
c
,
builder
);
catalogueVariable
=
builder
.
build
();
}
c
.
close
();
}
return
catalogueVariable
;
}
public
static
CatalogueVariable
getVariableFromSysId
(
String
sysId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
CatalogueVariable
catalogueVariable
=
null
;
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE_VARIABLES
+
" where "
+
CATALOGUE_VARIABLE_SYS_ID
+
"='"
+
sysId
+
"'"
,
null
);
if
(
c
.
moveToFirst
())
{
CatalogueVariable
.
CatalogueVariableBuilder
builder
=
CatalogueVariable
.
CatalogueVariableBuilder
.
aCatalogueVariable
();
fillAllVariableDetails
(
c
,
builder
);
catalogueVariable
=
builder
.
build
();
}
c
.
close
();
}
return
catalogueVariable
;
}
private
static
void
fillAllVariableDetails
(
Cursor
c
,
CatalogueVariable
.
CatalogueVariableBuilder
builder
)
{
builder
.
setId
(
c
.
getLong
(
INDEX_CATALOGUE_VARIABLE_ID
));
builder
.
setCatalogueItemId
(
c
.
getLong
(
INDEX_CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
));
builder
.
setSysId
(
c
.
getString
(
INDEX_CATALOGUE_VARIABLE_SYS_ID
));
builder
.
setName
(
c
.
getString
(
INDEX_CATALOGUE_VARIABLE_NAME
));
builder
.
setQuestionText
(
c
.
getString
(
INDEX_CATALOGUE_VARIABLE_QUESTION_TEXT
));
builder
.
setType
(
ViewType
.
from
(
c
.
getInt
(
INDEX_CATALOGUE_VARIABLE_TYPE
)));
builder
.
setSyncDirty
(
c
.
getInt
(
INDEX_CATALOGUE_VARIABLE_SYNC_DIRTY
));
}
private
static
ContentValues
getContentValues
(
CatalogueVariable
catalogueVariable
)
{
ContentValues
cv
=
new
ContentValues
(
CATALOGUE_VARIABLE_COLUMN_COUNT
-
1
);
cv
.
put
(
CATALOGUE_VARIABLE_CATALOGUE_ITEM_ID
,
catalogueVariable
.
getCatalogueItemId
());
cv
.
put
(
CATALOGUE_VARIABLE_SYS_ID
,
catalogueVariable
.
getSysId
());
cv
.
put
(
CATALOGUE_VARIABLE_NAME
,
catalogueVariable
.
getName
());
cv
.
put
(
CATALOGUE_VARIABLE_QUESTION_TEXT
,
catalogueVariable
.
getQuestionText
());
cv
.
put
(
CATALOGUE_VARIABLE_TYPE
,
catalogueVariable
.
getType
().
getId
());
cv
.
put
(
CATALOGUE_VARIABLE_SYNC_DIRTY
,
catalogueVariable
.
getSyncDirty
());
return
cv
;
}
}
\ No newline at end of file
app/src/main/java/com/vsoft/uoflservicenow/ui/CatalogueVariableScreen.java
View file @
52366a4b
...
@@ -26,6 +26,7 @@ import android.widget.LinearLayout;
...
@@ -26,6 +26,7 @@ import android.widget.LinearLayout;
import
android.widget.RelativeLayout
;
import
android.widget.RelativeLayout
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
android.widget.TimePicker
;
import
android.widget.TimePicker
;
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.uoflservicenow.CatalogueApplication
;
...
@@ -37,6 +38,7 @@ import com.vsoft.uoflservicenow.api.managers.VariableChoiceApiManager;
...
@@ -37,6 +38,7 @@ import com.vsoft.uoflservicenow.api.managers.VariableChoiceApiManager;
import
com.vsoft.uoflservicenow.api.managers.VariableChoiceManager
;
import
com.vsoft.uoflservicenow.api.managers.VariableChoiceManager
;
import
com.vsoft.uoflservicenow.db.managers.CatalogueItemManager
;
import
com.vsoft.uoflservicenow.db.managers.CatalogueItemManager
;
import
com.vsoft.uoflservicenow.db.managers.CatalogueVariableManager
;
import
com.vsoft.uoflservicenow.db.managers.CatalogueVariableManager
;
import
com.vsoft.uoflservicenow.db.managers.CatalogueVariableValueManager
;
import
com.vsoft.uoflservicenow.db.models.CatalogueItem
;
import
com.vsoft.uoflservicenow.db.models.CatalogueItem
;
import
com.vsoft.uoflservicenow.db.models.CatalogueVariable
;
import
com.vsoft.uoflservicenow.db.models.CatalogueVariable
;
import
com.vsoft.uoflservicenow.db.models.Reference
;
import
com.vsoft.uoflservicenow.db.models.Reference
;
...
@@ -48,6 +50,7 @@ import com.vsoft.uoflservicenow.listeners.ReferenceListener;
...
@@ -48,6 +50,7 @@ import com.vsoft.uoflservicenow.listeners.ReferenceListener;
import
com.vsoft.uoflservicenow.ui.supportviews.DateAndTimePickerFragment
;
import
com.vsoft.uoflservicenow.ui.supportviews.DateAndTimePickerFragment
;
import
com.vsoft.uoflservicenow.utils.CatalogueLog
;
import
com.vsoft.uoflservicenow.utils.CatalogueLog
;
import
com.vsoft.uoflservicenow.utils.Constants
;
import
com.vsoft.uoflservicenow.utils.Constants
;
import
com.vsoft.uoflservicenow.utils.DBConstants
;
import
com.vsoft.uoflservicenow.utils.DialogUtils
;
import
com.vsoft.uoflservicenow.utils.DialogUtils
;
import
com.vsoft.uoflservicenow.utils.TagObject
;
import
com.vsoft.uoflservicenow.utils.TagObject
;
import
com.vsoft.uoflservicenow.utils.Util
;
import
com.vsoft.uoflservicenow.utils.Util
;
...
@@ -166,8 +169,6 @@ public class CatalogueVariableScreen extends AppCompatActivity {
...
@@ -166,8 +169,6 @@ public class CatalogueVariableScreen extends AppCompatActivity {
});
});
}
}
}
}
/*Create Dynamic table for CatalogueVariable*/
Util
.
createDynamicTable
(
mCatalogueItem
.
getSysId
(),
catalogueVariableList
);
}
}
}
}
});
});
...
@@ -404,10 +405,14 @@ public class CatalogueVariableScreen extends AppCompatActivity {
...
@@ -404,10 +405,14 @@ public class CatalogueVariableScreen extends AppCompatActivity {
if
(
hasErrors
)
if
(
hasErrors
)
return
;
return
;
if
(
mApplication
.
isNetConnected
())
{
/*Create Dynamic table for CatalogueVariable Values*/
new
SubmitForm
().
execute
();
Util
.
createDynamicTable
(
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
{
}
else
{
DialogUtils
.
showNoConnectionDialogWithCloseActivity
(
CatalogueVariableScreen
.
this
);
Toast
.
makeText
(
CatalogueVariableScreen
.
this
,
"Saved: id: "
+
id
,
Toast
.
LENGTH_LONG
).
show
(
);
}
}
}
}
...
...
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