From 281b1986d39ad8703691422670e09556feea9037 Mon Sep 17 00:00:00 2001 From: malinowskikam Date: Tue, 30 Aug 2022 17:27:11 +0200 Subject: [PATCH] OTC-683 Fixed no InsureePolicy after Policy --- app/build.gradle | 8 +++- app/src/main/assets/pages/Insuree.js | 5 +-- .../imispolicies/ClientAndroidInterface.java | 37 +------------------ .../org/openimis/imispolicies/Enquire.java | 31 +++++----------- .../openimis/imispolicies/util/JsonUtils.java | 19 ++++++++++ 5 files changed, 39 insertions(+), 61 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 2292a585..a760b7cf 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,7 +39,6 @@ android { versionCode gitVersionCode versionName gitVersionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - useLibrary('org.apache.http.legacy') vectorDrawables { useSupportLibrary = true } @@ -206,6 +205,10 @@ android { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 } + + packagingOptions { + exclude 'META-INF/DEPENDENCIES' + } } dependencies { @@ -219,6 +222,9 @@ dependencies { implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'org.apache.commons:commons-lang3:3.12.0' implementation 'org.jetbrains:annotations:15.0' + implementation 'org.apache.httpcomponents:httpclient:4.5.9' + implementation 'org.apache.httpcomponents:httpcore:4.4.11' + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { diff --git a/app/src/main/assets/pages/Insuree.js b/app/src/main/assets/pages/Insuree.js index d3744785..d0bf9c3c 100644 --- a/app/src/main/assets/pages/Insuree.js +++ b/app/src/main/assets/pages/Insuree.js @@ -98,19 +98,18 @@ $(document).ready(function () { var ExceedThreshold = -1; if (PolicyId > 0 && IsNewIns == 0) { - var PolicyStatus = Android.getPolicyStatus(PolicyId); if (TotalIns >= MemberCount) { ExceedThreshold = 0; Android.ShowDialog(Android.getString('ExceedMemberCount')); } else if (TotalIns >= Threshold) { ExceedThreshold = 1; - } else if (PolicyStatus == 2) { + } else { ExceedThreshold = 0; } } var InsureeId = Android.SaveInsuree(jsonInsuree, FamilyId, 0, parseInt(ExceedThreshold), PolicyId); - if (InsureeId == 7 || InsureeId == 6) { + if (TotalIns >= MemberCount) { $("#divProgress").hide(); } else { $("#divProgress").hide(); diff --git a/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java b/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java index 4744a7d1..8615f036 100644 --- a/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java +++ b/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java @@ -947,8 +947,6 @@ public int SaveInsuree(String InsureeData, int FamilyId, int isHead, int ExceedT int isOffline = 1; int insureeIsOffline = 1; int MaxInsureeId = 0; - Boolean res = false; - int newInsureeId = 0; try { global = (Global) mContext.getApplicationContext(); HashMap data = jsonToTable(InsureeData); @@ -1061,7 +1059,6 @@ public int SaveInsuree(String InsureeData, int FamilyId, int isHead, int ExceedT if (global.isNetworkAvailable()) { //if (isOffline == 0){ MaxInsureeId = -MaxInsureeId; - newInsureeId = MaxInsureeId; //} values.put("InsureeId", MaxInsureeId); @@ -1116,41 +1113,11 @@ else if (ExceedThreshold == 0) values.put("isOffline", insureeIsOffline); sqlHandler.updateData("tblInsuree", values, "InsureeId = ? AND (isOffline = ?)", new String[]{String.valueOf(InsureeId), String.valueOf(insureeIsOffline)}); } - if (global.isNetworkAvailable()) { - if (isOffline == 0 || isOffline == 2) { - if (isOffline == 2) isOffline = 0; - if (global.getUserId() > 0) { - if (rtInsureeId > 0) { - newInsureeId = -rtInsureeId; - } else { - newInsureeId = rtInsureeId; - } - if (rtInsureeId == 0 && res) { - inProgress = false; - } else { - } - inProgress = false; - } - inProgress = false; - } else { - inProgress = false; - } - inProgress = false; - } else { - inProgress = false; - } - - - } catch (NumberFormatException e) { - e.printStackTrace(); - throw new Exception(e.getMessage()); - } catch (UserException e) { + } catch (NumberFormatException | UserException e) { e.printStackTrace(); throw new Exception(e.getMessage()); } - while (inProgress) { - } - inProgress = false; + return rtInsureeId; } diff --git a/app/src/main/java/org/openimis/imispolicies/Enquire.java b/app/src/main/java/org/openimis/imispolicies/Enquire.java index 99ecaa3a..47a0298c 100644 --- a/app/src/main/java/org/openimis/imispolicies/Enquire.java +++ b/app/src/main/java/org/openimis/imispolicies/Enquire.java @@ -276,30 +276,19 @@ private void getInsureeInfo() { jsonArray = jsonObject.getJSONArray("details"); for (i = 0; i < jsonArray.length(); i++) { - jsonObject = jsonArray.getJSONObject(i); - - HashMap Policy = new HashMap<>(); jsonObject = jsonArray.getJSONObject(i); - double iDedType = 0; - if (!jsonObject.getString("dedType").equalsIgnoreCase("null")) - iDedType = Double.parseDouble(jsonObject.getString("dedType")); + double iDedType = Double.parseDouble(JsonUtils.getStringOrDefault(jsonObject, "dedType", "0", true)); String Ded = "", Ded1 = "", Ded2 = ""; String Ceiling = "", Ceiling1 = "", Ceiling2 = ""; - String jDed1 = "", jDed2 = "", jCeiling1 = "", jCeiling2 = ""; + String jDed1, jDed2, jCeiling1, jCeiling2; - if (jsonObject.getString("ded1").equalsIgnoreCase("null")) jDed1 = ""; - else jDed1 = jsonObject.getString("ded1"); - if (jsonObject.getString("ded2").equalsIgnoreCase("null")) jDed2 = ""; - else jDed2 = jsonObject.getString("ded2"); - if (jsonObject.getString("ceiling1").equalsIgnoreCase("null")) - jCeiling1 = ""; - else jCeiling1 = jsonObject.getString("ceiling1"); - if (jsonObject.getString("ceiling2").equalsIgnoreCase("null")) - jCeiling2 = ""; - else jCeiling2 = jsonObject.getString("ceiling2"); + jDed1 = JsonUtils.getStringOrDefault(jsonObject, "ded1", "", true); + jDed2 = JsonUtils.getStringOrDefault(jsonObject, "ded2", "", true); + jCeiling1 = JsonUtils.getStringOrDefault(jsonObject, "ceiling1", "", true); + jCeiling2 = JsonUtils.getStringOrDefault(jsonObject, "ceiling2", "", true); //Get the type @@ -325,12 +314,11 @@ private void getInsureeInfo() { } - if (jsonObject.getString("expiryDate").equals("null")){ + if (JsonUtils.isStringEmpty(jsonObject, "expiryDate", true)) { Policy.put("Heading", getResources().getString(R.string.EnquireNoPolicies)); - } - else{ + } else { Policy.put("Heading", jsonObject.getString("productCode")); - Policy.put("Heading1", jsonObject.getString("expiryDate") + " " + jsonObject.getString("status")); + Policy.put("Heading1", JsonUtils.getStringOrDefault(jsonObject, "expiryDate", "", true) + " " + jsonObject.getString("status")); Policy.put("SubItem1", jsonObject.getString("productName")); Policy.put("SubItem2", Ded); Policy.put("SubItem3", Ceiling); @@ -404,7 +392,6 @@ private void getInsureeInfo() { result = ""; } }); - } protected String buildEnquireValue(JSONObject jsonObject, String jsonKey, int labelId) throws JSONException { diff --git a/app/src/main/java/org/openimis/imispolicies/util/JsonUtils.java b/app/src/main/java/org/openimis/imispolicies/util/JsonUtils.java index aab05b94..38ef09ab 100644 --- a/app/src/main/java/org/openimis/imispolicies/util/JsonUtils.java +++ b/app/src/main/java/org/openimis/imispolicies/util/JsonUtils.java @@ -30,4 +30,23 @@ public static boolean isStringEmpty(JSONObject object, @NonNull String field, bo return true; } } + + /** + * @param object Json object + * @param field field to be checked + * @param defaultValue default value to be used if requested value does not exists + * @param checkNullString Should "null" string be considered empty + * @return value of the specified field if exists, default value otherwise + */ + public static String getStringOrDefault(@NonNull JSONObject object, @NonNull String field, String defaultValue, boolean checkNullString) { + try { + if (!isStringEmpty(object, field, checkNullString)) { + return object.getString(field); + } else { + return defaultValue; + } + } catch (JSONException e) { + return defaultValue; + } + } }