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
4335aee8
authored
Sep 14, 2016
by
Kunj Gupta
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Fix - In Order Service Screen, implement api for showing items in order.
parent
3fb83923
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
197 additions
and
3 deletions
app/src/main/java/com/vsoft/uoflservicenow/api/interfaces/CatalogueCategoryApi.java
app/src/main/java/com/vsoft/uoflservicenow/api/listeners/get/GetCatalogueOrderApiListener.java
app/src/main/java/com/vsoft/uoflservicenow/api/managers/CatalogueApiManager.java
app/src/main/java/com/vsoft/uoflservicenow/db/models/CatalogueOrder.java
app/src/main/java/com/vsoft/uoflservicenow/utils/Constants.java
app/src/main/java/com/vsoft/uoflservicenow/api/interfaces/CatalogueCategoryApi.java
View file @
4335aee8
...
...
@@ -19,6 +19,10 @@ public interface CatalogueCategoryApi {
Call
<
ResponseBody
>
getCatalogue
(
@Query
(
Constants
.
URL_PARAM_SYSPRM_QUERY
)
String
sysparmQuery
,
@Query
(
Constants
.
URL_PARAM_SYSPRM_FIELDS
)
String
sysParmFields
,
@Query
(
Constants
.
URL_PARAM_SYSPRM_DISPLAY_VALUE
)
String
sysParmDisplayValue
);
// Get Catalogue Order API
@GET
(
Constants
.
URL_GET_CATALOGUE_ORDER
)
Call
<
ResponseBody
>
getCatalogueOrder
();
}
app/src/main/java/com/vsoft/uoflservicenow/api/listeners/get/GetCatalogueOrderApiListener.java
0 → 100644
View file @
4335aee8
package
com
.
vsoft
.
uoflservicenow
.
api
.
listeners
.
get
;
import
com.vsoft.uoflservicenow.db.models.CatalogueOrder
;
import
java.util.List
;
/**
* @since 1.0
* @author Kunj on 14/9/16
*
*/
public
interface
GetCatalogueOrderApiListener
{
void
onDoneApiCall
(
List
<
CatalogueOrder
>
catalogueOrderList
);
}
app/src/main/java/com/vsoft/uoflservicenow/api/managers/CatalogueApiManager.java
View file @
4335aee8
...
...
@@ -8,8 +8,10 @@ import com.google.gson.JsonElement;
import
com.google.gson.JsonParseException
;
import
com.vsoft.uoflservicenow.api.RestClient
;
import
com.vsoft.uoflservicenow.api.interfaces.CatalogueCategoryApi
;
import
com.vsoft.uoflservicenow.db.models.Catalogue
;
import
com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueApiListener
;
import
com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueOrderApiListener
;
import
com.vsoft.uoflservicenow.db.models.Catalogue
;
import
com.vsoft.uoflservicenow.db.models.CatalogueOrder
;
import
com.vsoft.uoflservicenow.enums.SyncStatus
;
import
com.vsoft.uoflservicenow.utils.CatalogueLog
;
import
com.vsoft.uoflservicenow.utils.Constants
;
...
...
@@ -21,6 +23,8 @@ import org.json.JSONObject;
import
java.io.IOException
;
import
java.lang.reflect.Type
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
okhttp3.ResponseBody
;
...
...
@@ -94,13 +98,33 @@ public class CatalogueApiManager {
})
.
create
();
List
<
Catalogue
>
catalogueList
=
new
ArrayList
<>(
catalogueJsonArray
.
length
());
final
List
<
Catalogue
>
catalogueList
=
new
ArrayList
<>(
catalogueJsonArray
.
length
());
final
List
<
Catalogue
>
finalCatalogueList
=
new
ArrayList
<>(
catalogueJsonArray
.
length
());
for
(
int
i
=
0
;
i
<
catalogueJsonArray
.
length
();
i
++)
{
JSONObject
expenseJsonObject
=
catalogueJsonArray
.
getJSONObject
(
i
);
Catalogue
catalogue
=
gson
.
fromJson
(
expenseJsonObject
.
toString
(),
Catalogue
.
class
);
catalogueList
.
add
(
catalogue
);
}
listener
.
onDoneApiCall
(
catalogueList
);
if
(!
catalogueList
.
isEmpty
())
{
getCatalogueOrder
(
new
GetCatalogueOrderApiListener
()
{
@Override
public
void
onDoneApiCall
(
List
<
CatalogueOrder
>
catalogueOrderList
)
{
for
(
int
i
=
0
;
i
<
catalogueOrderList
.
size
();
i
++)
{
CatalogueOrder
catalogueOrder
=
catalogueOrderList
.
get
(
i
);
for
(
int
j
=
0
;
j
<
catalogueList
.
size
();
j
++)
{
Catalogue
catalogue
=
catalogueList
.
get
(
j
);
if
(
catalogue
.
getSysId
().
equals
(
catalogueOrder
.
getId
()))
{
finalCatalogueList
.
add
(
catalogue
);
break
;
}
}
}
}
});
listener
.
onDoneApiCall
(
finalCatalogueList
);
}
else
{
listener
.
onDoneApiCall
(
new
ArrayList
<
Catalogue
>(
0
));
}
}
else
{
listener
.
onDoneApiCall
(
new
ArrayList
<
Catalogue
>(
0
));
}
...
...
@@ -125,4 +149,101 @@ public class CatalogueApiManager {
return
SyncStatus
.
FAIL
;
}
}
public
static
SyncStatus
getCatalogueOrder
(
GetCatalogueOrderApiListener
listener
)
{
CatalogueLog
.
d
(
"CatalogueApiManager: getCatalogueOrder: "
);
final
Retrofit
retrofit
=
RestClient
.
getInitializedRestAdapter
(
Constants
.
API_AUTH_PARAM_USER_NAME
,
Constants
.
API_AUTH_PARAM_PASSWORD
);
Call
<
ResponseBody
>
call
=
retrofit
.
create
(
CatalogueCategoryApi
.
class
).
getCatalogueOrder
();
try
{
//Retrofit synchronous call
Response
<
ResponseBody
>
response
=
call
.
execute
();
if
(
response
.
isSuccessful
())
{
try
{
JSONObject
jsonObject
=
new
JSONObject
(
response
.
body
().
string
());
JSONObject
error
=
jsonObject
.
optJSONObject
(
Constants
.
RESPONSE_ERROR_OBJECT_NAME
);
if
(
error
==
null
)
{
JSONObject
resultJsonObject
=
jsonObject
.
getJSONObject
(
Constants
.
RESPONSE_RESULT_OBJECT_NAME
);
JSONArray
catalogueOrderJsonArray
=
resultJsonObject
.
getJSONArray
(
Constants
.
RESPONSE_CATEGORY_OBJECT_NAME
);
if
(
catalogueOrderJsonArray
.
length
()
>
0
)
{
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
(
"CatalogueApiManager: getCatalogueOrder: 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
(
"CatalogueApiManager: getCatalogueOrder: 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
(
"CatalogueApiManager: getCatalogueOrder: deserialize: float.class: NumberFormatException: "
,
e
);
}
return
value
;
}
})
.
create
();
List
<
CatalogueOrder
>
catalogueOrderList
=
new
ArrayList
<>(
catalogueOrderJsonArray
.
length
());
for
(
int
i
=
0
;
i
<
catalogueOrderJsonArray
.
length
();
i
++)
{
JSONObject
expenseJsonObject
=
catalogueOrderJsonArray
.
getJSONObject
(
i
);
CatalogueOrder
catalogueOrder
=
gson
.
fromJson
(
expenseJsonObject
.
toString
(),
CatalogueOrder
.
class
);
catalogueOrderList
.
add
(
catalogueOrder
);
}
/*Sort List of CatalogueOrder*/
Collections
.
sort
(
catalogueOrderList
,
new
Comparator
<
CatalogueOrder
>()
{
@Override
public
int
compare
(
CatalogueOrder
lhs
,
CatalogueOrder
rhs
)
{
return
(
lhs
.
getOrder
()
-
rhs
.
getOrder
());
}
});
listener
.
onDoneApiCall
(
catalogueOrderList
);
}
else
{
listener
.
onDoneApiCall
(
new
ArrayList
<
CatalogueOrder
>(
0
));
}
return
SyncStatus
.
SUCCESS
;
}
else
return
SyncStatus
.
FAIL
;
}
catch
(
JSONException
e
)
{
CatalogueLog
.
e
(
"CatalogueApiManager: getCatalogueOrder: onResponse: "
,
e
);
return
SyncStatus
.
FAIL
;
}
catch
(
IOException
e
)
{
CatalogueLog
.
e
(
"CatalogueApiManager: getCatalogueOrder: onResponse: "
,
e
);
return
SyncStatus
.
FAIL
;
}
}
else
{
return
SyncStatus
.
FAIL
;
}
}
catch
(
IOException
e
)
{
CatalogueLog
.
e
(
"CatalogueApiManager: getCatalogueOrder: IOException: "
,
e
);
return
SyncStatus
.
FAIL
;
}
catch
(
NullPointerException
e
)
{
CatalogueLog
.
e
(
"CatalogueApiManager: getCatalogueOrder: NullPointerException: "
,
e
);
return
SyncStatus
.
FAIL
;
}
}
}
\ No newline at end of file
app/src/main/java/com/vsoft/uoflservicenow/db/models/CatalogueOrder.java
0 → 100644
View file @
4335aee8
package
com
.
vsoft
.
uoflservicenow
.
db
.
models
;
import
com.google.gson.annotations.Expose
;
import
com.google.gson.annotations.SerializedName
;
/**
* Created by Kunj on 14/9/16.
*/
public
class
CatalogueOrder
{
@SerializedName
(
"id"
)
@Expose
private
String
id
;
@SerializedName
(
"order"
)
@Expose
private
Integer
order
;
/**
*
* @return
* The id
*/
public
String
getId
()
{
return
id
;
}
/**
*
* @param id
* The id
*/
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
/**
*
* @return
* The order
*/
public
Integer
getOrder
()
{
return
order
;
}
/**
*
* @param order
* The order
*/
public
void
setOrder
(
Integer
order
)
{
this
.
order
=
order
;
}
}
app/src/main/java/com/vsoft/uoflservicenow/utils/Constants.java
View file @
4335aee8
...
...
@@ -113,6 +113,7 @@ public class Constants {
public
static
final
String
RESPONSE_ERROR_OBJECT_NAME
=
"error"
;
public
static
final
String
RESPONSE_VARIABLE_SET_OBJECT_NAME
=
"variablesets"
;
public
static
final
String
RESPONSE_VARIABLES_OBJECT_NAME
=
"variables"
;
public
static
final
String
RESPONSE_CATEGORY_OBJECT_NAME
=
"Category"
;
/**
* Catalogue web services urls
...
...
@@ -122,6 +123,7 @@ public class Constants {
/*Catalogue Category API */
public
static
final
String
URL_GET_CATALOGUE
=
API_PATH
+
"sc_category"
;
public
static
final
String
URL_GET_CATALOGUE_ORDER
=
DOMAIN
+
"api/uno33/uofl_mobile/catalohhome"
;
/*Catalogue Category Items API */
public
static
final
String
URL_GET_CATALOGUE_ITEM
=
API_PATH
+
"sc_cat_item"
;
...
...
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