Commit 44225f97 by Kunj Gupta

UOFLMA-114: Fixed - Show incident number in success message after reporting incident.

parent 2fbee62a
package com.vsoft.uoflservicenow.api.listeners.post;
/**
* @since 1.0
* @author Kunj on 11/8/16
*
*/
public interface PostIncidentApiListener {
void onDoneApiCall(String incidentNumber);
}
...@@ -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.IncidentApi; import com.vsoft.uoflservicenow.api.interfaces.IncidentApi;
import com.vsoft.uoflservicenow.api.listeners.get.GetIncidentApiListener; import com.vsoft.uoflservicenow.api.listeners.get.GetIncidentApiListener;
import com.vsoft.uoflservicenow.api.listeners.post.PostIncidentApiListener;
import com.vsoft.uoflservicenow.db.models.Incident; import com.vsoft.uoflservicenow.db.models.Incident;
import com.vsoft.uoflservicenow.enums.SyncStatus; import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog; import com.vsoft.uoflservicenow.utils.CatalogueLog;
...@@ -125,7 +126,7 @@ public class IncidentApiManager { ...@@ -125,7 +126,7 @@ public class IncidentApiManager {
} }
} }
public static SyncStatus submitIncidentForm(String incidentJsonString) { public static SyncStatus submitIncidentForm(String incidentJsonString, PostIncidentApiListener listener) {
CatalogueLog.d("submitIncidentForm: incidentJson" + incidentJsonString); CatalogueLog.d("submitIncidentForm: incidentJson" + incidentJsonString);
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);
...@@ -134,6 +135,17 @@ public class IncidentApiManager { ...@@ -134,6 +135,17 @@ public class IncidentApiManager {
//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) {
JSONObject result = jsonObject.getJSONObject(Constants.RESPONSE_RESULT_OBJECT_NAME);
String incidentNumber = result.getString(Incident.Json.NUMBER);
listener.onDoneApiCall(incidentNumber);
}
} catch (JSONException e) {
e.printStackTrace();
}
return SyncStatus.SUCCESS; return SyncStatus.SUCCESS;
} else { } else {
return SyncStatus.FAIL; return SyncStatus.FAIL;
......
...@@ -77,7 +77,7 @@ public class Incident { ...@@ -77,7 +77,7 @@ public class Incident {
public static final String OPENED_AT = "opened_at"; public static final String OPENED_AT = "opened_at";
public static final String SHORT_DESCRIPTION = "short_description"; public static final String SHORT_DESCRIPTION = "short_description";
public static final String CALLER_ID = "caller_id"; public static final String CALLER_ID = "caller_id";
public static final String OPENED_ID = "opened_by"; public static final String NUMBER = "number";
} }
@Override @Override
......
...@@ -24,6 +24,7 @@ import android.widget.TextView; ...@@ -24,6 +24,7 @@ import android.widget.TextView;
import com.google.android.gms.analytics.Tracker; import com.google.android.gms.analytics.Tracker;
import com.vsoft.uoflservicenow.CatalogueApplication; import com.vsoft.uoflservicenow.CatalogueApplication;
import com.vsoft.uoflservicenow.R; import com.vsoft.uoflservicenow.R;
import com.vsoft.uoflservicenow.api.listeners.post.PostIncidentApiListener;
import com.vsoft.uoflservicenow.api.managers.IncidentApiManager; import com.vsoft.uoflservicenow.api.managers.IncidentApiManager;
import com.vsoft.uoflservicenow.db.models.Incident; import com.vsoft.uoflservicenow.db.models.Incident;
import com.vsoft.uoflservicenow.enums.Impact; import com.vsoft.uoflservicenow.enums.Impact;
...@@ -149,6 +150,7 @@ public class ReportIncidentScreen extends AppCompatActivity { ...@@ -149,6 +150,7 @@ public class ReportIncidentScreen extends AppCompatActivity {
class submitIncident extends AsyncTask<String, Void, SyncStatus> { class submitIncident extends AsyncTask<String, Void, SyncStatus> {
private ProgressDialog progressDialog; private ProgressDialog progressDialog;
private String number;
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
...@@ -171,7 +173,13 @@ public class ReportIncidentScreen extends AppCompatActivity { ...@@ -171,7 +173,13 @@ public class ReportIncidentScreen extends AppCompatActivity {
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
return IncidentApiManager.submitIncidentForm(incidentJsonObject.toString());
return IncidentApiManager.submitIncidentForm(incidentJsonObject.toString(), new PostIncidentApiListener() {
@Override
public void onDoneApiCall(String incidentNumber) {
number = incidentNumber;
}
});
} }
@Override @Override
...@@ -181,7 +189,7 @@ public class ReportIncidentScreen extends AppCompatActivity { ...@@ -181,7 +189,7 @@ public class ReportIncidentScreen extends AppCompatActivity {
progressDialog.dismiss(); progressDialog.dismiss();
} }
if(syncStatus == SyncStatus.SUCCESS) { if(syncStatus == SyncStatus.SUCCESS) {
showSuccessDialog(); showSuccessDialog(number);
} else { } else {
showErrorDialog(R.string.failed_to_submit_form_string); showErrorDialog(R.string.failed_to_submit_form_string);
} }
...@@ -241,9 +249,9 @@ public class ReportIncidentScreen extends AppCompatActivity { ...@@ -241,9 +249,9 @@ public class ReportIncidentScreen extends AppCompatActivity {
alert.show(); alert.show();
} }
private void showSuccessDialog() { private void showSuccessDialog(String number) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.incident_form_incident_successful_submission_string) builder.setMessage(String.format(getString(R.string.incident_form_incident_successful_submission_string), number))
.setCancelable(false) .setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
......
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
<string name="incident_form_report_incident_text_string">Report Incident</string> <string name="incident_form_report_incident_text_string">Report Incident</string>
<string name="incident_form_top_text_string">Create an Incident record to report and request assistance with an issue you are having\n\nRequest assistance with an issue you are having. An incident record will be created and managed through to successful resolution. You will also be notified of progress.</string> <string name="incident_form_top_text_string">Create an Incident record to report and request assistance with an issue you are having\n\nRequest assistance with an issue you are having. An incident record will be created and managed through to successful resolution. You will also be notified of progress.</string>
<string name="incident_form_impact_text_string">Impact &lt;font color="#FF0000"&gt;*&lt;/font&gt;</string> <string name="incident_form_impact_text_string">Impact &lt;font color="#FF0000"&gt;*&lt;/font&gt;</string>
<string name="incident_form_incident_successful_submission_string">Your Incident has been reported successfully</string> <string name="incident_form_incident_successful_submission_string">Incident No. %s has been reported successfully</string>
<string name="incident_form_describe_your_issue_text_string">Please Describe Your Issue below &lt;font color="#FF0000"&gt;*&lt;/font&gt;(Max %d)</string> <string name="incident_form_describe_your_issue_text_string">Please Describe Your Issue below &lt;font color="#FF0000"&gt;*&lt;/font&gt;(Max %d)</string>
<string name="incident_item_text_string"><![CDATA[<b>Number: </b>%1$s<br><br><b>Opened: </b>%2$s<br><br><b>Short Description: </b>%3$s]]></string> <string name="incident_item_text_string"><![CDATA[<b>Number: </b>%1$s<br><br><b>Opened: </b>%2$s<br><br><b>Short Description: </b>%3$s]]></string>
<string name="incident_form_short_description_limit_error_text_string">Max limit exceeded by %d</string> <string name="incident_form_short_description_limit_error_text_string">Max limit exceeded by %d</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