Skip to content

Commit 1b06cb2

Browse files
authored
Merge pull request #79 from openimis/feature/OP-940
OP-940 Test mobiles apps on release server (22.10 Release)
2 parents f6bc3d6 + da3aa20 commit 1b06cb2

5 files changed

Lines changed: 61 additions & 60 deletions

File tree

claimManagement/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ android {
7272
demoRelease {
7373
applicationIdSuffix ".demoRelease"
7474
resValue "string", "app_name_claims", "Claims Release"
75-
buildConfigField "String", "API_BASE_URL", '"https://legacy-release.s1.openimis.org/rest/"'
75+
buildConfigField "String", "API_BASE_URL", '"https://release.openimis.org/rest/"'
7676
dimension 'std'
7777
}
7878

claimManagement/src/main/java/org/openimis/imisclaims/EnquireActivity.java

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
import static org.openimis.imisclaims.BuildConfig.API_BASE_URL;
4444

4545
public class EnquireActivity extends ImisActivity {
46-
public static final String LOG_TAG = "ENQUIRE";
47-
public static final int REQUEST_QR_SCAN_CODE = 1;
46+
private static final String LOG_TAG = "ENQUIRE";
47+
private static final int REQUEST_QR_SCAN_CODE = 1;
4848

4949
private Picasso picasso;
5050

@@ -277,7 +277,7 @@ private void getInsureeInfo() {
277277
} else if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
278278
runOnUiThread(() -> showDialog(getResources().getString(R.string.RecordNotFound)));
279279
} else {
280-
runOnUiThread(() -> showDialog(rest.getHttpError(this, responseCode)));
280+
runOnUiThread(() -> showDialog(rest.getHttpError(this, responseCode, response.getStatusLine().getReasonPhrase())));
281281
}
282282
} catch (Exception e) {
283283
Log.e(LOG_TAG, "Fetching online enquire failed", e);
@@ -312,39 +312,24 @@ public void renderResult() {
312312
tvDOB.setText(jsonObject.getString("dob"));//Adjust
313313
tvGender.setText(jsonObject.getString("gender"));
314314

315-
if (global.isNetworkAvailable()) {
316-
if (JsonUtils.isStringEmpty(jsonObject, "photoBase64", true)) {
317-
try {
318-
byte[] imageBytes = Base64.decode(jsonObject.getString("photoBase64").getBytes(), Base64.DEFAULT);
319-
Bitmap image = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
320-
iv.setImageBitmap(image);
321-
} catch (Exception e) {
322-
Log.e(LOG_TAG, "Error while processing Base64 image", e);
323-
iv.setImageDrawable(getResources().getDrawable(R.drawable.person));
324-
}
325-
} else if (JsonUtils.isStringEmpty(jsonObject, "photoPath", true)) {
326-
String photo_url_str = API_BASE_URL + jsonObject.getString("photoPath");
327-
iv.setImageResource(R.drawable.person);
328-
picasso.load(photo_url_str)
329-
.placeholder(R.drawable.person)
330-
.error(R.drawable.person)
331-
.into(iv);
332-
} else {
315+
if (!JsonUtils.isStringEmpty(jsonObject, "photoBase64", true)) {
316+
try {
317+
byte[] imageBytes = Base64.decode(jsonObject.getString("photoBase64").getBytes(), Base64.DEFAULT);
318+
Bitmap image = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
319+
iv.setImageBitmap(image);
320+
} catch (Exception e) {
321+
Log.e(LOG_TAG, "Error while processing Base64 image", e);
333322
iv.setImageDrawable(getResources().getDrawable(R.drawable.person));
334323
}
324+
} else if (!JsonUtils.isStringEmpty(jsonObject, "photoPath", true) && global.isNetworkAvailable()) {
325+
String photo_url_str = API_BASE_URL + jsonObject.getString("photoPath");
326+
iv.setImageResource(R.drawable.person);
327+
picasso.load(photo_url_str)
328+
.placeholder(R.drawable.person)
329+
.error(R.drawable.person)
330+
.into(iv);
335331
} else {
336-
if (theImage != null) {
337-
iv.setImageBitmap(theImage);
338-
} else {
339-
byte[] photo = jsonObject.getString("photoPath").getBytes();
340-
ByteArrayInputStream is = new ByteArrayInputStream(photo);
341-
theImage = BitmapFactory.decodeStream(is);
342-
if (theImage != null) {
343-
iv.setImageBitmap(theImage);
344-
} else {
345-
iv.setImageResource(R.drawable.person);
346-
}
347-
}
332+
iv.setImageDrawable(getResources().getDrawable(R.drawable.person));
348333
}
349334

350335
jsonArray = new JSONArray(jsonObject.getString("details"));

claimManagement/src/main/java/org/openimis/imisclaims/SearchClaimsActivity.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@
1414
import org.apache.http.HttpResponse;
1515
import org.json.JSONException;
1616
import org.json.JSONObject;
17+
import org.openimis.imisclaims.tools.Log;
1718

19+
import java.net.HttpURLConnection;
1820
import java.text.SimpleDateFormat;
1921
import java.util.ArrayList;
2022
import java.util.Calendar;
2123
import java.util.List;
2224
import java.util.Locale;
2325

2426
public class SearchClaimsActivity extends ImisActivity {
27+
private static final String LOG_TAG = "SEARCHCLAIMS";
2528
ProgressDialog pd;
2629

2730
ToRestApi toRestApi;
@@ -138,35 +141,32 @@ public void updateLabel(Calendar calendar, TextView view) {
138141

139142
private void getClaims(final JSONObject object) {
140143
pd = ProgressDialog.show(this, getResources().getString(R.string.DownLoad), getResources().getString(R.string.getClaims) + "...");
141-
Thread thread = new Thread() {
142-
public void run() {
143-
144-
String functionName = "claim/GetClaims/";
145-
try {
146-
HttpResponse response = toRestApi.postToRestApiToken(object, functionName);
147-
String content = toRestApi.getContent(response);
148-
int code = response.getStatusLine().getStatusCode();
149-
150-
if (code < 400) {
151-
runOnUiThread(() -> pd.dismiss());
152-
JSONObject jsonObject = new JSONObject(content);
153-
String data = jsonObject.getString("data");
154-
if (data.length() != 0) {
155-
openClaimReview(content);
156-
} else {
157-
runOnUiThread(() -> Toast.makeText(getContext(), response.getStatusLine().getStatusCode() + "-" + getResources().getString(R.string.NoClaim), Toast.LENGTH_LONG).show());
158-
}
144+
new Thread(() -> {
145+
String functionName = "claim/GetClaims/";
146+
try {
147+
HttpResponse response = toRestApi.postToRestApiToken(object, functionName);
148+
String content = toRestApi.getContent(response);
149+
int code = response.getStatusLine().getStatusCode();
150+
151+
if (code == HttpURLConnection.HTTP_OK) {
152+
runOnUiThread(() -> pd.dismiss());
153+
JSONObject jsonObject = new JSONObject(content);
154+
String data = jsonObject.getString("data");
155+
if (data.length() != 0) {
156+
openClaimReview(content);
159157
} else {
160-
pd.dismiss();
161-
runOnUiThread(() -> Toast.makeText(getContext(), getResources().getString(R.string.AccessDenied), Toast.LENGTH_LONG).show());
158+
runOnUiThread(() -> Toast.makeText(getContext(), getResources().getString(R.string.NoClaim), Toast.LENGTH_LONG).show());
162159
}
163-
} catch (Exception e) {
160+
} else {
164161
pd.dismiss();
165-
runOnUiThread(() -> Toast.makeText(getContext(), getResources().getString(R.string.AccessDenied), Toast.LENGTH_LONG).show());
162+
runOnUiThread(() -> Toast.makeText(getContext(), toRestApi.getHttpError(this, code, response.getStatusLine().getReasonPhrase()), Toast.LENGTH_LONG).show());
166163
}
164+
} catch (Exception e) {
165+
pd.dismiss();
166+
Log.e(LOG_TAG, "Error while fetching claims", e);
167+
runOnUiThread(() -> Toast.makeText(getContext(), getResources().getString(R.string.ErrorOccurred), Toast.LENGTH_LONG).show());
167168
}
168-
};
169-
thread.start();
169+
}).start();
170170
}
171171

172172
public void openClaimReview(String claims) {

claimManagement/src/main/java/org/openimis/imisclaims/ToRestApi.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.apache.http.impl.client.DefaultHttpClient;
1010
import org.apache.http.util.EntityUtils;
1111
import org.json.JSONArray;
12+
import org.json.JSONException;
1213
import org.json.JSONObject;
1314
import org.openimis.imisclaims.tools.Log;
1415

@@ -116,7 +117,7 @@ public String getContent(HttpResponse response) {
116117
}
117118
}
118119

119-
public String getHttpError(Context context, int httpResponseCode) {
120+
public String getHttpError(Context context, int httpResponseCode, String httpReason) {
120121
if (httpResponseCode == HttpURLConnection.HTTP_OK || httpResponseCode == HttpURLConnection.HTTP_CREATED) {
121122
return null;
122123
} else if (httpResponseCode == HttpURLConnection.HTTP_NOT_FOUND) {
@@ -126,8 +127,22 @@ public String getHttpError(Context context, int httpResponseCode) {
126127
} else if (httpResponseCode == HttpURLConnection.HTTP_FORBIDDEN) {
127128
return context.getResources().getString(R.string.Forbidden);
128129
} else {
129-
return context.getResources().getString(R.string.SomethingWentWrongServer);
130+
return context.getResources().getString(R.string.HttpResponse, httpResponseCode, httpReason);
130131
}
131132
}
132133

134+
public String getPayloadError(String responseContent) {
135+
String payloadError = null;
136+
137+
try {
138+
JSONObject response = new JSONObject(responseContent);
139+
if (response.optBoolean("error_occured", false)) {
140+
payloadError = response.getString("error_messagge");
141+
}
142+
} catch (JSONException e) {
143+
Log.e(LOG_TAG, "Error while parsing payload error", e);
144+
}
145+
return payloadError;
146+
}
147+
133148
}

claimManagement/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,5 @@
224224
<string name="Forbidden">You are not allowed to take this action.</string>
225225
<string name="UnknownError">Unknown Error.</string>
226226
<string name="NotFound">Entry does not exist.</string>
227+
<string name="HttpResponse">HTTP response: %1$d — %2$s</string>
227228
</resources>

0 commit comments

Comments
 (0)