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
3af6f1d6
authored
Sep 15, 2016
by
Kunj Gupta
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Delete unused file.
parent
7b78b272
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
211 deletions
app/src/main/java/com/vsoft/uoflservicenow/db/models/managers/CatalogueManager.java
app/src/main/java/com/vsoft/uoflservicenow/db/models/managers/CatalogueManager.java
deleted
100644 → 0
View file @
7b78b272
package
com
.
vsoft
.
uoflservicenow
.
db
.
models
.
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.Catalogue
;
import
com.vsoft.uoflservicenow.utils.DBConstants
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
/**
*
* @author Kunj on 11-08-2016.
*/
public
class
CatalogueManager
implements
DBConstants
{
public
static
long
save
(
Catalogue
catalogue
,
int
syncDirty
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
catalogue
.
setSyncDirty
(
syncDirty
);
long
id
=
db
.
insert
(
TABLE_CATALOGUE
,
null
,
getContentValues
(
catalogue
));
catalogue
.
setId
(
id
);
return
id
;
}
else
{
return
-
1
;
}
}
public
static
int
delete
(
Catalogue
catalogue
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
if
(
catalogue
.
getSysId
()
==
null
||
catalogue
.
getSysId
().
isEmpty
())
{
return
db
.
delete
(
TABLE_CATALOGUE
,
CATALOGUE_ID
+
"="
+
catalogue
.
getId
(),
null
);
}
else
{
return
update
(
catalogue
,
SYNC_FLAG_DELETE
);
}
}
return
-
1
;
}
public
static
int
update
(
Catalogue
catalogue
,
int
syncDirty
)
{
return
update
(
catalogue
,
null
,
syncDirty
);
}
public
static
int
update
(
Catalogue
catalogue
,
List
<
String
>
column
,
int
syncDirty
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
catalogue
.
setSyncDirty
(
syncDirty
);
if
(
column
==
null
||
column
.
size
()
==
0
)
{
return
db
.
update
(
TABLE_CATALOGUE
,
getContentValues
(
catalogue
),
CATALOGUE_ID
+
"="
+
catalogue
.
getId
(),
null
);
}
else
{
ContentValues
contentValues
=
new
ContentValues
(
column
.
size
());
contentValues
.
put
(
CATALOGUE_SYNC_DIRTY
,
catalogue
.
getSyncDirty
());
for
(
int
i
=
0
;
i
<
column
.
size
();
i
++)
{
String
columnName
=
column
.
get
(
i
);
if
(
CATALOGUE_TITLE
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_TITLE
,
catalogue
.
getTitle
());
}
else
if
(
CATALOGUE_DESCRIPTION
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_DESCRIPTION
,
catalogue
.
getDescription
());
}
else
if
(
CATALOGUE_SYS_ID
.
equals
(
columnName
))
{
contentValues
.
put
(
CATALOGUE_SYS_ID
,
catalogue
.
getSysId
());
}
}
return
db
.
update
(
TABLE_CATALOGUE
,
contentValues
,
CATALOGUE_ID
+
"="
+
catalogue
.
getId
(),
null
);
}
}
else
{
return
-
1
;
}
}
public
static
void
handleGetCatalogue
(
List
<
Catalogue
>
serverCatalogueList
)
{
if
(
serverCatalogueList
!=
null
&&
!
serverCatalogueList
.
isEmpty
())
{
/*catalogueSysIdMap contain all server response catalogues Sys Id*/
HashMap
<
String
,
Integer
>
catalogueSysIdMap
=
new
HashMap
<>(
0
);
Integer
intObj
=
Integer
.
valueOf
(
1
);
for
(
int
i
=
0
;
i
<
serverCatalogueList
.
size
();
i
++)
{
String
sysId
=
serverCatalogueList
.
get
(
i
).
getSysId
();
catalogueSysIdMap
.
put
(
sysId
,
intObj
);
}
/*localCatalogueList is contain all local Catalogues */
List
<
Catalogue
>
localCatalogueList
=
getAllCatalogues
();
if
(
localCatalogueList
!=
null
&&
!
localCatalogueList
.
isEmpty
())
{
for
(
int
i
=
0
;
i
<
localCatalogueList
.
size
();
i
++)
{
Catalogue
localCatalogue
=
localCatalogueList
.
get
(
i
);
String
localCatalogueSysId
=
localCatalogue
.
getSysId
();
if
(
localCatalogueSysId
!=
null
&&
!
localCatalogueSysId
.
isEmpty
()
&&
!
catalogueSysIdMap
.
containsKey
(
localCatalogueSysId
))
{
//Update sys_id with empty string because required to delete locally
localCatalogue
.
setSysId
(
""
);
delete
(
localCatalogue
);
}
}
}
/*Check this catalogue is exist in local DB or not
* If doesn't exist in local, save it
* If exist in local, update the local item with data from server item.
* */
for
(
int
i
=
0
;
i
<
serverCatalogueList
.
size
();
i
++)
{
Catalogue
catalogue
=
serverCatalogueList
.
get
(
i
);
Catalogue
localCatalogue
=
getCatalogueFromSysId
(
catalogue
.
getSysId
());
if
(
localCatalogue
==
null
)
{
save
(
catalogue
,
DBConstants
.
SYNC_FLAG_NONE
);
}
else
{
/*Update complete local Catalogue object with response Catalogue object*/
catalogue
.
setId
(
localCatalogue
.
getId
());
update
(
catalogue
,
DBConstants
.
SYNC_FLAG_NONE
);
}
}
}
else
{
/*That means there is no Catalogue category in server response, then all local items should be deleted those are contain sys_id*/
/*localCatalogueList is contain all local Catalogues */
List
<
Catalogue
>
localCatalogueList
=
getAllCatalogues
();
if
(
localCatalogueList
!=
null
&&
!
localCatalogueList
.
isEmpty
())
{
for
(
int
i
=
0
;
i
<
localCatalogueList
.
size
();
i
++)
{
Catalogue
localCatalogue
=
localCatalogueList
.
get
(
i
);
String
localCatalogueSysId
=
localCatalogue
.
getSysId
();
if
(
localCatalogueSysId
!=
null
&&
!
localCatalogueSysId
.
isEmpty
())
{
//Update sys_id with empty string because required to delete locally
localCatalogue
.
setSysId
(
""
);
delete
(
localCatalogue
);
}
}
}
}
}
public
static
List
<
Catalogue
>
getAllCatalogues
()
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE
+
" where "
+
CATALOGUE_SYNC_DIRTY
+
"!="
+
DBConstants
.
SYNC_FLAG_DELETE
,
null
);
ArrayList
<
Catalogue
>
catalogueList
;
if
(
c
.
getCount
()
>
0
)
{
catalogueList
=
new
ArrayList
<>(
c
.
getCount
());
while
(
c
.
moveToNext
())
{
Catalogue
.
CatalogueBuilder
builder
=
Catalogue
.
CatalogueBuilder
.
aCatalogue
();
fillAllCatalogueDetails
(
c
,
builder
);
catalogueList
.
add
(
builder
.
build
());
}
}
else
{
catalogueList
=
new
ArrayList
<>(
0
);
}
c
.
close
();
return
catalogueList
;
}
else
{
return
new
ArrayList
<>(
0
);
}
}
public
static
Catalogue
get
(
long
catalogueId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
Catalogue
catalogue
=
null
;
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE
+
" where "
+
CATALOGUE_ID
+
"="
+
catalogueId
,
null
);
if
(
c
.
moveToFirst
())
{
Catalogue
.
CatalogueBuilder
builder
=
Catalogue
.
CatalogueBuilder
.
aCatalogue
();
fillAllCatalogueDetails
(
c
,
builder
);
catalogue
=
builder
.
build
();
}
c
.
close
();
}
return
catalogue
;
}
public
static
Catalogue
getCatalogueFromSysId
(
String
sysId
)
{
SQLiteDatabase
db
=
CatalogueApplication
.
getDatabase
();
Catalogue
catalogue
=
null
;
if
(
db
!=
null
)
{
Cursor
c
=
db
.
rawQuery
(
"select * from "
+
TABLE_CATALOGUE
+
" where "
+
CATALOGUE_SYS_ID
+
"='"
+
sysId
+
"'"
,
null
);
if
(
c
.
moveToFirst
())
{
Catalogue
.
CatalogueBuilder
builder
=
Catalogue
.
CatalogueBuilder
.
aCatalogue
();
fillAllCatalogueDetails
(
c
,
builder
);
catalogue
=
builder
.
build
();
}
c
.
close
();
}
return
catalogue
;
}
private
static
void
fillAllCatalogueDetails
(
Cursor
c
,
Catalogue
.
CatalogueBuilder
builder
)
{
builder
.
setId
(
c
.
getLong
(
INDEX_CATALOGUE_ID
));
builder
.
setTitle
(
c
.
getString
(
INDEX_CATALOGUE_TITLE
));
builder
.
setDescription
(
c
.
getString
(
INDEX_CATALOGUE_DESCRIPTION
));
builder
.
setSysId
(
c
.
getString
(
INDEX_CATALOGUE_SYS_ID
));
builder
.
setSyncDirty
(
c
.
getInt
(
INDEX_CATALOGUE_SYNC_DIRTY
));
}
private
static
ContentValues
getContentValues
(
Catalogue
catalogue
)
{
ContentValues
cv
=
new
ContentValues
(
CATALOGUE_COLUMN_COUNT
-
1
);
cv
.
put
(
CATALOGUE_TITLE
,
catalogue
.
getTitle
());
cv
.
put
(
CATALOGUE_DESCRIPTION
,
catalogue
.
getDescription
());
cv
.
put
(
CATALOGUE_SYS_ID
,
catalogue
.
getSysId
());
cv
.
put
(
CATALOGUE_SYNC_DIRTY
,
catalogue
.
getSyncDirty
());
return
cv
;
}
}
\ No newline at end of file
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