Commit 57a1b936 by Kunj Gupta

UOFLMA-98: Integrate api to send attachment.

parent f9ea4e6a
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<supports-screens <supports-screens
android:anyDensity="true" android:anyDensity="true"
android:largeScreens="true" android:largeScreens="true"
......
...@@ -6,10 +6,12 @@ import com.vsoft.uoflservicenow.utils.Constants; ...@@ -6,10 +6,12 @@ import com.vsoft.uoflservicenow.utils.Constants;
import java.util.Map; import java.util.Map;
import okhttp3.RequestBody;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.http.Body; import retrofit2.http.Body;
import retrofit2.http.GET; import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.POST; import retrofit2.http.POST;
import retrofit2.http.Query; import retrofit2.http.Query;
import retrofit2.http.QueryMap; import retrofit2.http.QueryMap;
...@@ -39,6 +41,14 @@ public interface CatalogueVariableApi { ...@@ -39,6 +41,14 @@ public interface CatalogueVariableApi {
// Get Reference API // Get Reference API
@GET @GET
Call<ResponseBody> getReference(@Url String url, @QueryMap Map<String, String> options); 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);
} }
package com.vsoft.uoflservicenow.api.listeners.post;
/**
* @since 1.0
* @author Kunj on 11/8/16
*
*/
public interface PostVariableFormApiListener {
void onDoneApiCall(String variableFromSysId);
}
...@@ -9,6 +9,7 @@ import com.google.gson.JsonParseException; ...@@ -9,6 +9,7 @@ import com.google.gson.JsonParseException;
import com.vsoft.uoflservicenow.api.RestClient; import com.vsoft.uoflservicenow.api.RestClient;
import com.vsoft.uoflservicenow.api.interfaces.CatalogueVariableApi; import com.vsoft.uoflservicenow.api.interfaces.CatalogueVariableApi;
import com.vsoft.uoflservicenow.api.listeners.get.GetCatalogueVariableApiListener; 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.CatalogueVariable;
import com.vsoft.uoflservicenow.db.models.CatalogueVariableSet; import com.vsoft.uoflservicenow.db.models.CatalogueVariableSet;
import com.vsoft.uoflservicenow.enums.SyncStatus; import com.vsoft.uoflservicenow.enums.SyncStatus;
...@@ -26,6 +27,7 @@ import java.util.Collections; ...@@ -26,6 +27,7 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import okhttp3.RequestBody;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Response; import retrofit2.Response;
...@@ -166,7 +168,7 @@ public class CatalogueVariableApiManager { ...@@ -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); CatalogueLog.d("submitVariableForm: " + catalogueJsonArray);
String expenseJsonString = catalogueJsonArray.toString(); String expenseJsonString = catalogueJsonArray.toString();
final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD); final Retrofit retrofit = RestClient.getInitializedRestAdapter(Constants.API_AUTH_PARAM_USER_NAME, Constants.API_AUTH_PARAM_PASSWORD);
...@@ -175,6 +177,16 @@ public class CatalogueVariableApiManager { ...@@ -175,6 +177,16 @@ public class CatalogueVariableApiManager {
//Retrofit synchronous call //Retrofit synchronous call
Response<ResponseBody> response = call.execute(); Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) { 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; return SyncStatus.SUCCESS;
} else { } else {
return SyncStatus.FAIL; return SyncStatus.FAIL;
...@@ -187,4 +199,25 @@ public class CatalogueVariableApiManager { ...@@ -187,4 +199,25 @@ public class CatalogueVariableApiManager {
return SyncStatus.FAIL; 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
...@@ -227,7 +227,9 @@ public class CatalogueVariable { ...@@ -227,7 +227,9 @@ public class CatalogueVariable {
public static class Json { public static class Json {
public static final String SYS_ID = "sys_id"; public static final String SYS_ID = "sys_id";
public static final String TYPE = "type"; 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 @Override
......
...@@ -35,6 +35,9 @@ public class Constants { ...@@ -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_DISPLAY_VALUE = "sysparm_display_value";
public static final String URL_PARAM_SYSPRM_USERNAME = "user_name"; 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_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 * Debug logs
...@@ -133,6 +136,7 @@ public class Constants { ...@@ -133,6 +136,7 @@ public class Constants {
public static final String URL_GET_VARIABLE_CHOICE = API_PATH + "question_choice"; 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_POST_CATALOGUE_ITEM = "api/uno33/uofl_mobile";
public static final String URL_GET_REFERENCE = API_PATH; public static final String URL_GET_REFERENCE = API_PATH;
public static final String URL_POST_ATTACHMENT = DOMAIN + "api/now/v1/attachment/file";
/*Request API*/ /*Request API*/
public static final String URL_GET_MYREQUEST = API_PATH + "sc_req_item"; public static final String URL_GET_MYREQUEST = API_PATH + "sc_req_item";
......
...@@ -4,6 +4,7 @@ import android.content.Context; ...@@ -4,6 +4,7 @@ import android.content.Context;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.text.InputType; import android.text.InputType;
import android.text.TextUtils;
import android.text.method.PasswordTransformationMethod; import android.text.method.PasswordTransformationMethod;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
...@@ -171,6 +172,27 @@ public class Util { ...@@ -171,6 +172,27 @@ public class Util {
breakView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1)); breakView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1));
breakView.setBackgroundColor(ContextCompat.getColor(context, android.R.color.black)); breakView.setBackgroundColor(ContextCompat.getColor(context, android.R.color.black));
return breakView; 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; return null;
} }
...@@ -323,6 +345,4 @@ public class Util { ...@@ -323,6 +345,4 @@ public class Util {
InputMethodManager imm =(InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm =(InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0); imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
} }
} }
...@@ -53,7 +53,9 @@ ...@@ -53,7 +53,9 @@
<string name="variable_form_misc_info_string">%1$s [add %2$s]</string> <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_reference_dialog_title_string">Search \'%s\'</string>
<string name="variable_form_radio_text_string">%d</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--> <!--Catalogue Item Screen-->
<string name="no_catalogue_item_string">No Catalogue Items&#8230;</string> <string name="no_catalogue_item_string">No Catalogue Items&#8230;</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment