Skip to content

Commit

Permalink
Merge pull request #288 from OpenSRP/enable-multiple-column-mappings
Browse files Browse the repository at this point in the history
Enable multiple values to map to one column in ec_client_fields.json
  • Loading branch information
ekigamba authored Sep 27, 2019
2 parents d552685 + 77ffc96 commit 0769238
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 15 additions & 4 deletions opensrp-app/src/main/java/org/smartregister/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,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;
Expand Down Expand Up @@ -1007,12 +1008,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<String> 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<String> 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) {
Expand Down

0 comments on commit 0769238

Please sign in to comment.