From 405b57fc6343c1a25dbe8be39807eede36fd311f Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Thu, 1 Aug 2019 19:01:32 +0300 Subject: [PATCH 1/2] Enable multiple values to map to one column in ec_client_fields.json This will enable having different registers each with it's own identifier but all mapping to the same field on the table --- .../main/java/org/smartregister/Context.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/opensrp-app/src/main/java/org/smartregister/Context.java b/opensrp-app/src/main/java/org/smartregister/Context.java index e62907a9b..29d02d5df 100755 --- a/opensrp-app/src/main/java/org/smartregister/Context.java +++ b/opensrp-app/src/main/java/org/smartregister/Context.java @@ -108,6 +108,7 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import static android.preference.PreferenceManager.getDefaultSharedPreferences; @@ -996,12 +997,22 @@ public void getEcBindtypes() { JSONObject columnDefinitionObject = bindtypeObjects.getJSONObject(i); String bindname = columnDefinitionObject.getString("name"); JSONArray columnsJsonArray = columnDefinitionObject.getJSONArray("columns"); - String[] columnNames = new String[columnsJsonArray.length()]; - for (int j = 0; j < columnNames.length; j++) { + ArrayList columnNames = new ArrayList<>(); + + // This adds the ability to have multiple mappings for one column and at the same time + // Prevents the app from crashing when creating the common repository + HashSet uniqueColumnNames = new HashSet<>(); + + for (int j = 0; j < columnsJsonArray.length(); j++) { JSONObject columnObject = columnsJsonArray.getJSONObject(j); - columnNames[j] = columnObject.getString("column_name"); + String colName = columnObject.getString("column_name"); + + if (!uniqueColumnNames.contains(colName)) { + uniqueColumnNames.add(colName); + columnNames.add(colName); + } } - bindtypes.add(new CommonRepositoryInformationHolder(bindname, columnNames)); + bindtypes.add(new CommonRepositoryInformationHolder(bindname, columnNames.toArray(new String[0]))); Log.v("bind type logs", bindname); } } catch (Exception e) { From 77ffc96074c14d5208e4edb72eb289d299ce8aad Mon Sep 17 00:00:00 2001 From: ekigamba <31766075+ekigamba@users.noreply.github.com> Date: Thu, 26 Sep 2019 18:06:33 +0300 Subject: [PATCH 2/2] Increment SNAPSHOT version to 1.7.27 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 92d76fb94..65c55b4d6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=1.7.26-SNAPSHOT +VERSION_NAME=1.7.27-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Core Application