Skip to content

Commit

Permalink
Merge branch 'master' into async_tasks_refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
SebaMutuku authored Oct 26, 2022
2 parents b9063ac + 3a96e30 commit 9820a39
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ public void getOptionsOpenMRSAttributes(JSONObject item, JSONArray valueOpenMRSA
if ((JsonFormConstants.NATIVE_RADIO_BUTTON.equals(item.getString(JsonFormConstants.TYPE)) ||
JsonFormConstants.EXTENDED_RADIO_BUTTON.equals(item.getString(JsonFormConstants.TYPE))) &&
item.has(JsonFormConstants.VALUE)) {
String value = item.optString(JsonFormConstants.VALUE);
String value = Utils.extractValueFromJson(item.optString(JsonFormConstants.VALUE));
if (itemOption.has(JsonFormConstants.KEY) && value.equals(itemOption.getString(JsonFormConstants.KEY))) {
extractOptionOpenMRSAttributes(valueOpenMRSAttributes, itemOption,
item.getString(JsonFormConstants.KEY));
Expand Down Expand Up @@ -1725,6 +1725,15 @@ protected void extractOptionOpenMRSAttributes(JSONArray valueOpenMRSAttributes,
valueOpenMRSObject.put(JsonFormConstants.OPENMRS_ENTITY_PARENT, openmrsEntityParent);
valueOpenMRSObject.put(JsonFormConstants.OPENMRS_ENTITY, openmrsEntity);
valueOpenMRSObject.put(JsonFormConstants.OPENMRS_ENTITY_ID, openmrsEntityId);
if(itemOption.has(JsonFormConstants.TEXT) && itemOption.has(JsonFormConstants.KEY)) {
valueOpenMRSObject.put(JsonFormConstants.VALUE, itemOption.getString(JsonFormConstants.KEY));
valueOpenMRSObject.put(JsonFormConstants.TEXT, itemOption.getString(JsonFormConstants.TEXT));
JSONArray options = new JSONArray();
options.put(itemOption);
// adds the selected option as an option array to fill the human readable value;
valueOpenMRSObject.put(JsonFormConstants.OPTIONS_FIELD_NAME,options);
}


valueOpenMRSAttributes.put(valueOpenMRSObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,21 @@ public void enableExpansionPanelViews(LinearLayout linearLayout) {
okButton.setClickable(true);
}

public static String extractValueFromJson(String value)
{
try{
if(!StringUtils.isEmpty(value) && value.startsWith("{") && value.endsWith("}")) {
JSONObject object = new JSONObject(value);
return object.optString(VALUE);
}
}
catch (Exception e)
{
Timber.e(e);
}
return value;
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -520,5 +520,19 @@ public void testGenerateTranslatableValueWithoutOptionsField () throws Exception
JSONObject item = new JSONObject(jsonForm);
Assert.assertEquals(expectedJson.toString(), Utils.generateTranslatableValue(item.optString(JsonFormConstants.KEY), item).toString());
}
@Test
public void testExtractValueFromJson() throws JSONException
{
String value = JsonFormConstants.VALUE;
JSONObject object = new JSONObject();
object.put(JsonFormConstants.VALUE, value);

String result = Utils.extractValueFromJson(object.toString());
Assert.assertEquals(result,JsonFormConstants.VALUE);

String result2 = Utils.extractValueFromJson(value);
Assert.assertEquals(result2,value);

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import android.view.View;
import android.widget.RadioButton;


import com.vijay.jsonwizard.BaseTest;
import com.vijay.jsonwizard.R;
import com.vijay.jsonwizard.activities.JsonFormActivity;
import com.vijay.jsonwizard.constants.JsonFormConstants;
import com.vijay.jsonwizard.fragments.JsonFormFragment;
import com.vijay.jsonwizard.interfaces.CommonListener;
import com.vijay.jsonwizard.utils.FormUtils;
Expand Down Expand Up @@ -107,9 +109,13 @@ public void testGetSecondaryDateValueWithEmptyValues() throws Exception {
public void testGetOptionTextWithSecondaryValue() throws Exception {
JSONObject jsonObject = new JSONObject("{\"key\":\"user_sub_form\",\"openmrs_entity_parent\":\"\",\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"type\":\"native_radio\",\"label\":\"User sub forms?\",\"label_text_style\":\"bold\",\"text_color\":\"#000000\",\"extra_rel\":true,\"has_extra_rel\":\"yes\",\"options\":[{\"key\":\"yes\",\"text\":\"Yes\",\"value\":false,\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"specify_info\":\"User sub specify...\",\"specify_widget\":\"normal_edit_text\",\"specify_info_color\":\"#8C8C8C\",\"secondary_suffix\":\"bpm\",\"content_form\":\"user_native_sub_form\",\"secondary_value\":[{\"key\":\"yes\",\"type\":\"date_picker\",\"values\":[\"24-09-2020\"]}]},{\"key\":\"no\",\"text\":\"No\",\"value\":false,\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\"}],\"value\":\"yes\",\"v_required\":{\"value\":true,\"err\":\"Please specify user native form.\"}}");
JSONObject item = new JSONObject("{\"key\":\"yes\",\"text\":\"Yes\",\"value\":false,\"openmrs_entity\":\"\",\"openmrs_entity_id\":\"\",\"specify_info\":\"User sub specify...\",\"specify_widget\":\"normal_edit_text\",\"specify_info_color\":\"#8C8C8C\",\"secondary_suffix\":\"bpm\",\"content_form\":\"user_native_sub_form\",\"secondary_value\":[{\"key\":\"yes\",\"type\":\"date_picker\",\"values\":[\"24-09-2020\"]}]}");
JSONObject valueObject = new JSONObject();
valueObject.put(JsonFormConstants.VALUE,"yes");
valueObject.put(JsonFormConstants.TEXT,"");

jsonObject.put(JsonFormConstants.VALUE, valueObject);
String optionText = Whitebox.invokeMethod(new NativeRadioButtonFactory(), "getOptionTextWithSecondaryValue", item, jsonObject);
Assert.assertEquals("Yes", optionText);
Assert.assertEquals("Yes:24-09-2020", optionText);
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=3.0.2-SNAPSHOT
VERSION_NAME=3.1.1-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Native Form Json Wizard
Expand Down

0 comments on commit 9820a39

Please sign in to comment.