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
57a1b936
authored
Sep 27, 2016
by
Kunj Gupta
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
UOFLMA-98: Integrate api to send attachment.
parent
f9ea4e6a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
88 additions
and
5 deletions
app/src/main/AndroidManifest.xml
app/src/main/java/com/vsoft/uoflservicenow/api/interfaces/CatalogueVariableApi.java
app/src/main/java/com/vsoft/uoflservicenow/api/listeners/post/PostVariableFormApiListener.java
app/src/main/java/com/vsoft/uoflservicenow/api/managers/CatalogueVariableApiManager.java
app/src/main/java/com/vsoft/uoflservicenow/db/models/CatalogueVariable.java
app/src/main/java/com/vsoft/uoflservicenow/ui/CatalogueVariableScreen.java
app/src/main/java/com/vsoft/uoflservicenow/utils/Constants.java
app/src/main/java/com/vsoft/uoflservicenow/utils/Util.java
app/src/main/res/values/strings.xml
app/src/main/AndroidManifest.xml
View file @
57a1b936
...
...
@@ -3,6 +3,7 @@
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.ACCESS_NETWORK_STATE"
/>
<uses-permission
android:name=
"android.permission.WRITE_EXTERNAL_STORAGE"
/>
<supports-screens
android:anyDensity=
"true"
android:largeScreens=
"true"
...
...
app/src/main/java/com/vsoft/uoflservicenow/api/interfaces/CatalogueVariableApi.java
View file @
57a1b936
...
...
@@ -6,10 +6,12 @@ import com.vsoft.uoflservicenow.utils.Constants;
import
java.util.Map
;
import
okhttp3.RequestBody
;
import
okhttp3.ResponseBody
;
import
retrofit2.Call
;
import
retrofit2.http.Body
;
import
retrofit2.http.GET
;
import
retrofit2.http.Header
;
import
retrofit2.http.POST
;
import
retrofit2.http.Query
;
import
retrofit2.http.QueryMap
;
...
...
@@ -39,6 +41,14 @@ public interface CatalogueVariableApi {
// Get Reference API
@GET
Call
<
ResponseBody
>
getReference
(
@Url
String
url
,
@QueryMap
Map
<
String
,
String
>
options
);
// Post attachment API
@POST
(
Constants
.
URL_POST_ATTACHMENT
)
Call
<
ResponseBody
>
postAttachment
(
@Header
(
"Content-Type"
)
String
contentType
,
@Query
(
Constants
.
URL_PARAM_TABLE_SYS_ID
)
String
tableSysId
,
@Query
(
Constants
.
URL_PARAM_TABLE_NAME
)
String
tableName
,
@Query
(
Constants
.
URL_PARAM_FILE_NAME
)
String
fileName
,
@Body
RequestBody
attachmentRequestBody
);
}
app/src/main/java/com/vsoft/uoflservicenow/api/listeners/post/PostVariableFormApiListener.java
0 → 100644
View file @
57a1b936
package
com
.
vsoft
.
uoflservicenow
.
api
.
listeners
.
post
;
/**
* @since 1.0
* @author Kunj on 11/8/16
*
*/
public
interface
PostVariableFormApiListener
{
void
onDoneApiCall
(
String
variableFromSysId
);
}
app/src/main/java/com/vsoft/uoflservicenow/api/managers/CatalogueVariableApiManager.java
View file @
57a1b936
...
...
@@ -9,6 +9,7 @@ import com.google.gson.JsonParseException;
import
com.vsoft.uoflservicenow.api.RestClient
;
import
com.vsoft.uoflservicenow.api.interfaces.CatalogueVariableApi
;
import
com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueVariableApiListener
;
import
com.vsoft.uoflservicenow.api.listeners.post.PostVariableFormApiListener
;
import
com.vsoft.uoflservicenow.db.models.CatalogueVariable
;
import
com.vsoft.uoflservicenow.db.models.CatalogueVariableSet
;
import
com.vsoft.uoflservicenow.enums.SyncStatus
;
...
...
@@ -26,6 +27,7 @@ import java.util.Collections;
import
java.util.Comparator
;
import
java.util.List
;
import
okhttp3.RequestBody
;
import
okhttp3.ResponseBody
;
import
retrofit2.Call
;
import
retrofit2.Response
;
...
...
@@ -166,7 +168,7 @@ public class CatalogueVariableApiManager {
}
}
public
static
SyncStatus
submitVariableForm
(
String
catalogueItemSysId
,
JSONArray
catalogueJsonArray
)
{
public
static
SyncStatus
submitVariableForm
(
String
catalogueItemSysId
,
JSONArray
catalogueJsonArray
,
PostVariableFormApiListener
listener
)
{
CatalogueLog
.
d
(
"submitVariableForm: "
+
catalogueJsonArray
);
String
expenseJsonString
=
catalogueJsonArray
.
toString
();
final
Retrofit
retrofit
=
RestClient
.
getInitializedRestAdapter
(
Constants
.
API_AUTH_PARAM_USER_NAME
,
Constants
.
API_AUTH_PARAM_PASSWORD
);
...
...
@@ -175,6 +177,16 @@ public class CatalogueVariableApiManager {
//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
)
{
String
resultSysId
=
jsonObject
.
getString
(
Constants
.
RESPONSE_RESULT_OBJECT_NAME
);
listener
.
onDoneApiCall
(
resultSysId
);
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
return
SyncStatus
.
SUCCESS
;
}
else
{
return
SyncStatus
.
FAIL
;
...
...
@@ -187,4 +199,25 @@ public class CatalogueVariableApiManager {
return
SyncStatus
.
FAIL
;
}
}
public
static
SyncStatus
postAttachment
(
String
contentType
,
String
tableSysId
,
String
attachmentName
,
RequestBody
requestBody
/*String attachmentJsonString*/
)
{
CatalogueLog
.
d
(
"postAttachment: tableSysId: "
+
tableSysId
);
final
Retrofit
retrofit
=
RestClient
.
getInitializedRestAdapter
(
Constants
.
API_AUTH_PARAM_USER_NAME
,
Constants
.
API_AUTH_PARAM_PASSWORD
);
Call
<
ResponseBody
>
call
=
retrofit
.
create
(
CatalogueVariableApi
.
class
).
postAttachment
(
contentType
,
tableSysId
,
CatalogueVariable
.
Json
.
TABLE_NAME_VALUE
,
attachmentName
,
requestBody
);
try
{
//Retrofit synchronous call
Response
<
ResponseBody
>
response
=
call
.
execute
();
if
(
response
.
isSuccessful
())
{
return
SyncStatus
.
SUCCESS
;
}
else
{
return
SyncStatus
.
FAIL
;
}
}
catch
(
IOException
e
)
{
CatalogueLog
.
e
(
"CatalogueVariableApiManager: postAttachment: IOException: "
,
e
);
return
SyncStatus
.
FAIL
;
}
catch
(
NullPointerException
e
){
CatalogueLog
.
e
(
"CatalogueVariableApiManager: postAttachment: IOException: "
,
e
);
return
SyncStatus
.
FAIL
;
}
}
}
\ No newline at end of file
app/src/main/java/com/vsoft/uoflservicenow/db/models/CatalogueVariable.java
View file @
57a1b936
...
...
@@ -227,7 +227,9 @@ public class CatalogueVariable {
public
static
class
Json
{
public
static
final
String
SYS_ID
=
"sys_id"
;
public
static
final
String
TYPE
=
"type"
;
public
static
final
String
ORDER
=
"order"
;
/*Variable form attachment*/
public
static
final
String
TABLE_NAME_VALUE
=
"sc_req_item"
;
}
@Override
...
...
app/src/main/java/com/vsoft/uoflservicenow/ui/CatalogueVariableScreen.java
View file @
57a1b936
This diff is collapsed.
Click to expand it.
app/src/main/java/com/vsoft/uoflservicenow/utils/Constants.java
View file @
57a1b936
...
...
@@ -35,6 +35,9 @@ public class Constants {
public
static
final
String
URL_PARAM_SYSPRM_DISPLAY_VALUE
=
"sysparm_display_value"
;
public
static
final
String
URL_PARAM_SYSPRM_USERNAME
=
"user_name"
;
public
static
final
String
URL_PARAM_SYSPRM_LIMIT
=
"sysparm_limit"
;
public
static
final
String
URL_PARAM_TABLE_SYS_ID
=
"table_sys_id"
;
public
static
final
String
URL_PARAM_TABLE_NAME
=
"table_name"
;
public
static
final
String
URL_PARAM_FILE_NAME
=
"file_name"
;
/**
* Debug logs
...
...
@@ -133,6 +136,7 @@ public class Constants {
public
static
final
String
URL_GET_VARIABLE_CHOICE
=
API_PATH
+
"question_choice"
;
public
static
final
String
URL_POST_CATALOGUE_ITEM
=
"api/uno33/uofl_mobile"
;
public
static
final
String
URL_GET_REFERENCE
=
API_PATH
;
public
static
final
String
URL_POST_ATTACHMENT
=
DOMAIN
+
"api/now/v1/attachment/file"
;
/*Request API*/
public
static
final
String
URL_GET_MYREQUEST
=
API_PATH
+
"sc_req_item"
;
...
...
app/src/main/java/com/vsoft/uoflservicenow/utils/Util.java
View file @
57a1b936
...
...
@@ -4,6 +4,7 @@ import android.content.Context;
import
android.graphics.Typeface
;
import
android.support.v4.content.ContextCompat
;
import
android.text.InputType
;
import
android.text.TextUtils
;
import
android.text.method.PasswordTransformationMethod
;
import
android.view.Gravity
;
import
android.view.View
;
...
...
@@ -171,6 +172,27 @@ public class Util {
breakView
.
setLayoutParams
(
new
LinearLayout
.
LayoutParams
(
LinearLayout
.
LayoutParams
.
MATCH_PARENT
,
1
));
breakView
.
setBackgroundColor
(
ContextCompat
.
getColor
(
context
,
android
.
R
.
color
.
black
));
return
breakView
;
case
UI_PAGE:
LinearLayout
uiPageLayout
=
new
LinearLayout
(
context
);
uiPageLayout
.
setOrientation
(
LinearLayout
.
HORIZONTAL
);
LinearLayout
.
LayoutParams
layoutParams
=
new
LinearLayout
.
LayoutParams
(
0
,
LinearLayout
.
LayoutParams
.
WRAP_CONTENT
,
1.0f
);
Button
attachmentButton
=
new
Button
(
context
);
attachmentButton
.
setText
(
R
.
string
.
variable_form_ui_page_button_label_string
);
attachmentButton
.
setLines
(
1
);
attachmentButton
.
setSingleLine
(
true
);
attachmentButton
.
setEllipsize
(
TextUtils
.
TruncateAt
.
END
);
uiPageLayout
.
addView
(
attachmentButton
,
layoutParams
);
TextView
attachmentTextView
=
new
TextView
(
context
);
attachmentTextView
.
setGravity
(
Gravity
.
CENTER
);
attachmentTextView
.
setSingleLine
(
true
);
attachmentTextView
.
setLines
(
1
);
attachmentTextView
.
setEllipsize
(
TextUtils
.
TruncateAt
.);
attachmentTextView
.
setText
(
R
.
string
.
variable_form_ui_page_no_selected_attachment_string
);
uiPageLayout
.
addView
(
attachmentTextView
,
layoutParams
);
return
uiPageLayout
;
}
return
null
;
}
...
...
@@ -323,6 +345,4 @@ public class Util {
InputMethodManager
imm
=(
InputMethodManager
)
context
.
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
imm
.
hideSoftInputFromWindow
(
view
.
getWindowToken
(),
0
);
}
}
app/src/main/res/values/strings.xml
View file @
57a1b936
...
...
@@ -53,7 +53,9 @@
<string
name=
"variable_form_misc_info_string"
>
%1$s [add %2$s]
</string>
<string
name=
"variable_form_reference_dialog_title_string"
>
Search \'%s\'
</string>
<string
name=
"variable_form_radio_text_string"
>
%d
</string>
<string
name=
"variable_form_ui_page_button_label_string"
>
Add Attachment
</string>
<string
name=
"variable_form_ui_page_no_selected_attachment_string"
>
Not Selected
</string>
<string
name=
"custom_setting_storage_permission_dialog_msg_string"
>
To use this feature, please go to Settings -> Apps -> %s -> Permissions and enable \'Storage\' permission
</string>
<!--Catalogue Item Screen-->
<string
name=
"no_catalogue_item_string"
>
No Catalogue Items
…
</string>
...
...
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